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  /** @name segmentation_variable
54  * Set the input array containing a binary segmentation.
55  * See teca_binary_segmentation
56  */
57  ///@{
58  TECA_ALGORITHM_PROPERTY(std::string, segmentation_variable)
59  void get_segmentation_variable(std::string &var) const;
60  ///@}
61 
62  /** @name component_variable
63  * Set the name of the output array to store the component labels in.
64  */
65  ///@{
66  TECA_ALGORITHM_PROPERTY(std::string, component_variable)
67  void get_component_variable(std::string &var) const;
68  ///@}
69 
70 protected:
72 
73 private:
74  using teca_algorithm::get_output_metadata;
75 
76  teca_metadata get_output_metadata(unsigned int port,
77  const std::vector<teca_metadata> &input_md) override;
78 
79  std::vector<teca_metadata> get_upstream_request(
80  unsigned int port, const std::vector<teca_metadata> &input_md,
81  const teca_metadata &request) override;
82 
83  const_p_teca_dataset execute( unsigned int port,
84  const std::vector<const_p_teca_dataset> &input_data,
85  const teca_metadata &request) override;
86 
87 private:
88  std::string component_variable;
89  std::string segmentation_variable;
90 };
91 
92 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
an algorithm that computes connected component labeling
Definition: teca_connected_components.h:46
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.