TECA
teca_binary_segmentation.h
1 #ifndef teca_binary_segmentation_h
2 #define teca_binary_segmentation_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_binary_segmentation)
12 
13 
26 {
27 public:
28  TECA_ALGORITHM_STATIC_NEW(teca_binary_segmentation)
29  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_binary_segmentation)
30  TECA_ALGORITHM_CLASS_NAME(teca_binary_segmentation)
32 
33  // set the name of the output array to store the resulting segmentation in
34  TECA_ALGORITHM_PROPERTY(std::string, segmentation_variable)
35 
36  // set extra metadata for the segmentation variable
37  TECA_ALGORITHM_PROPERTY(teca_metadata, segmentation_variable_attributes)
38 
39  // set the name of the input array to segment
40  TECA_ALGORITHM_PROPERTY(std::string, threshold_variable)
41 
42  // Set the threshold range. The defaults are (-infinity, infinity].
43  TECA_ALGORITHM_PROPERTY(double, low_threshold_value)
44  TECA_ALGORITHM_PROPERTY(double, high_threshold_value)
45 
46  // Set the threshold mode. In BY_PERCENTILE mode low and high thresholds
47  // define the percentiles (0 to 100) between which data is in the
48  // segmentation. default is BY_VALUE.
49  enum {BY_VALUE=0, BY_PERCENTILE=1};
50  TECA_ALGORITHM_PROPERTY(int, threshold_mode);
51 
52  void set_threshold_by_percentile() { set_threshold_mode(BY_PERCENTILE); }
53  void set_threshold_by_value() { set_threshold_mode(BY_VALUE); }
54 
55 protected:
57 
58  int get_segmentation_variable(std::string &segmentation_var);
59  int get_threshold_variable(std::string &threshold_var);
60 
61 private:
62  teca_metadata get_output_metadata(unsigned int port,
63  const std::vector<teca_metadata> &input_md) override;
64 
65  std::vector<teca_metadata> get_upstream_request(
66  unsigned int port, const std::vector<teca_metadata> &input_md,
67  const teca_metadata &request) override;
68 
69  const_p_teca_dataset execute(unsigned int port,
70  const std::vector<const_p_teca_dataset> &input_data,
71  const teca_metadata &request) override;
72 
73 private:
74  std::string segmentation_variable;
75  teca_metadata segmentation_variable_attributes;
76  std::string threshold_variable;
77  double low_threshold_value;
78  double high_threshold_value;
79  int threshold_mode;
80 };
81 
82 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_binary_segmentation
an algorithm that computes a binary segmentation
Definition: teca_binary_segmentation.h:26
teca_algorithm
Definition: teca_algorithm.h:25