TECA
The Toolkit for Extreme Climate Analysis
teca_connected_components.h
1 #ifndef teca_connected_components_h
2 #define teca_connected_components_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <string>
9 #include <vector>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_connected_components)
12 
13 /// an algorithm that computes connected component labeling
14 /**
15  * an algorithm that computes connected component labeling for 1D, 2D, and 3D
16  * data. The components are computed from a binary segmentation provided on the
17  * input.
18  *
19  * the input binary segmentation is labeled and stored in a variable named by the
20  * component_variable property. the component ids are added to the output
21  * dataset metadata in an key named 'component_ids', and the number of components
22  * is stored in a key named 'number_of_components'. These keys facilitate further
23  * processing as one need not scan the labeled data to get the list of label ids.
24  *
25  * The cells outside of the segmentation (i.e. the background) are always assigned
26  * the label 0. The cells belonging to connected regions inside the segmentation
27  * are labeled starting from 1 up to number_of_components - 1.
28  *
29  * output keys:
30  *
31  * | name | description |
32  * | ---- | ----------- |
33  * | number_of_components | number of component ids found. this will always be |
34  * | | at least 1 long as the cells outside the segmentation |
35  * | | are assigned the label 0. |
36  * | component_ids | a vector containing the label of each component. This is |
37  * | | always starts with 0, where the label 0 identifies cells |
38  * | | out side of the segmentation, and ranges up to |
39  * | | number_of_components - 1, where the labels from 1 up to |
40  * | | number_of_components - 1 identify connected regions of |
41  * | | cells inside the segmentation. |
42  * | background_id | the label used for cells outside of the segmentation, |
43  * | | i.e. the background. always 0. |
44 */
46 {
47 public:
48  TECA_ALGORITHM_STATIC_NEW(teca_connected_components)
49  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_connected_components)
50  TECA_ALGORITHM_CLASS_NAME(teca_connected_components)
52 
53  // set the input array containing a binary segmentation
54  // see teca_binary_segmentation
55  TECA_ALGORITHM_PROPERTY(std::string, segmentation_variable)
56 
57  // set the name of the output array to store the component labels in
58  TECA_ALGORITHM_PROPERTY(std::string, component_variable)
59 
60 
61 protected:
63 
64  std::string get_component_variable(const teca_metadata &request);
65  std::string get_segmentation_variable(const teca_metadata &request);
66 
67 private:
68  teca_metadata get_output_metadata(unsigned int port,
69  const std::vector<teca_metadata> &input_md) override;
70 
71  std::vector<teca_metadata> get_upstream_request(
72  unsigned int port, const std::vector<teca_metadata> &input_md,
73  const teca_metadata &request) override;
74 
75  const_p_teca_dataset execute( unsigned int port,
76  const std::vector<const_p_teca_dataset> &input_data,
77  const teca_metadata &request) override;
78 
79 private:
80  std::string component_variable;
81  std::string segmentation_variable;
82 };
83 
84 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_connected_components
an algorithm that computes connected component labeling
Definition: teca_connected_components.h:45
teca_shared_object.h
teca_algorithm
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237