1 // This is brl/bseg/brec/brec_hierarchy_edge.h 2 #ifndef brec_hierarchy_edge_h_ 3 #define brec_hierarchy_edge_h_ 4 //: 5 // \file 6 // \brief a class to represent part hierarchy edges 7 // 8 // The relative occurrence information of the parts will be stored in the edge 9 // 10 // \author Ozge C Ozcanli (ozge@lems.brown.edu) 11 // \date October 16, 2008 12 // 13 // \verbatim 14 // Modifications 15 // <none yet> 16 // \endverbatim 17 18 #include "brec_part_base.h" 19 #include "brec_part_base_sptr.h" 20 21 #include <bgrl2/bgrl2_edge.h> 22 #include <bsta/bsta_gaussian_sphere.h> 23 #include <vgl/vgl_box_2d.h> 24 #include <bxml/bxml_document.h> 25 26 class brec_hierarchy_edge : public bgrl2_edge<brec_part_base> 27 { 28 public: 29 30 //: edge between v1 in layer i to v2 in layer i-1 31 // If no relative spatial arrangement model then this is an edge to the central part in the previous layer. 32 // Default is the central 33 brec_hierarchy_edge(brec_part_base_sptr v1, brec_part_base_sptr v2, bool to_central = true) : bgrl2_edge<brec_part_base>(v1, v2), to_central_(to_central), weight_(1.0), min_stad_dev_dist_(2.0f), min_stad_dev_angle_(10.0f) {} 34 35 //: this constructor should only be used during parsing brec_hierarchy_edge()36 brec_hierarchy_edge() : bgrl2_edge<brec_part_base>(), to_central_(true), weight_(1.0), min_stad_dev_dist_(2.0f), min_stad_dev_angle_(10.0f) {} 37 38 //: if the model is updated then the to_central flag is made false since the edge becomes a non-central edge 39 void update_dist_model(const float dist); 40 void update_angle_model(const float angle); 41 //void set_model(const bsta_gauss_sf2& mod) { loc_model_ = mod; to_central_ = false; } set_model(const bsta_gaussian_sphere<double,1> & dist_mod,const bsta_gaussian_sphere<double,1> & angle_mod,double weight)42 void set_model(const bsta_gaussian_sphere<double,1>& dist_mod, const bsta_gaussian_sphere<double,1>& angle_mod, double weight) { dist_model_ = dist_mod; angle_model_ = angle_mod; to_central_ = false; weight_ = weight; } 43 44 double prob_density(const float dist, const float angle); //vnl_vector_fixed<float,2>& pt); 45 double prob_density_dist(const float dist); 46 double prob_density_angle(const float angle); 47 //vnl_vector_fixed<float,2> mean() const { return loc_model_.mean(); } mean_dist()48 double mean_dist() const { return dist_model_.mean(); } mean_angle()49 double mean_angle() const { return angle_model_.mean(); } var_dist()50 double var_dist() const { return dist_model_.var(); } var_angle()51 double var_angle() const { return angle_model_.var(); } 52 53 static void calculate_dist_angle(const brec_part_instance_sptr& pi, vnl_vector_fixed<float,2>& dif_to_center, float& dist, float& angle); 54 to_central()55 bool to_central() const { return to_central_; } 56 set_min_stand_dev_dist(float d)57 void set_min_stand_dev_dist(float d) { min_stad_dev_dist_ = d; } set_min_stand_dev_angle(float a)58 void set_min_stand_dev_angle(float a) { min_stad_dev_angle_ = a; } 59 60 vgl_box_2d<float> get_probe_box(const brec_part_instance_sptr& central_p); 61 62 //: samples the position of the part linked with this edge wrt to the position (x,y) 63 vnl_vector_fixed<float,2> sample_position(const brec_part_instance_sptr& central_p, float x, float y, vnl_random& rng); 64 vnl_vector_fixed<float,2> mean_position(const brec_part_instance_sptr& central_p, float x, float y); 65 66 virtual bxml_data_sptr xml_element(); 67 virtual bool xml_parse_element(bxml_data_sptr data); 68 69 public: 70 bool to_central_; 71 72 //: 2 1D gaussian models to model location of v2 wrt central part in v1 73 // (distance between the centers) 74 bsta_gaussian_sphere<double, 1> dist_model_; 75 76 //: model angle in radians 77 // (angle between the centers wrt the orientation of the central model) 78 bsta_gaussian_sphere<double, 1> angle_model_; 79 80 //: the weight/prior prob of the densities 81 double weight_; 82 83 float min_stad_dev_dist_; // default 2 pixels 84 float min_stad_dev_angle_; // default 10 degrees 85 }; 86 87 #endif //brec_hierarchy_edge_h_ 88