Go to the documentation of this file.00001
00002 #ifndef bsol_intrinsic_curve_2d_h_
00003 #define bsol_intrinsic_curve_2d_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <vsol/vsol_curve_2d.h>
00027 #include <vsol/vsol_point_2d.h>
00028 #include <vsol/vsol_point_2d_sptr.h>
00029 #include <vsol/vsol_polyline_2d_sptr.h>
00030 #include <vcl_vector.h>
00031 #include <vcl_iostream.h>
00032 #include <vcl_cassert.h>
00033
00034 #define ZERO_TOLERANCE 1E-1 // used in bsol_intrinsic_curve_2d.cxx
00035
00036
00037
00038 class bsol_intrinsic_curve_2d : public vsol_curve_2d
00039 {
00040 protected:
00041
00042
00043
00044
00045 vcl_vector<vsol_point_2d_sptr> *storage_;
00046
00047 vsol_point_2d_sptr p0_;
00048
00049 vsol_point_2d_sptr p1_;
00050
00051 vcl_vector<double> arcLength_;
00052
00053 vcl_vector<double> s_;
00054
00055
00056 vcl_vector<double> normArcLength_;
00057
00058 double length_;
00059
00060 vcl_vector<double> dx_;
00061
00062 vcl_vector<double> dy_;
00063
00064 vcl_vector<double> curvature_;
00065
00066 vcl_vector<double> angle_;
00067
00068 double totalCurvature_;
00069
00070 double totalAngleChange_;
00071
00072 bool isOpen_;
00073
00074 public:
00075
00076
00077
00078
00079 bsol_intrinsic_curve_2d();
00080
00081 bsol_intrinsic_curve_2d(const vcl_vector<vsol_point_2d_sptr> &new_vertices);
00082
00083 bsol_intrinsic_curve_2d(const vsol_polyline_2d_sptr poly);
00084
00085
00086 bsol_intrinsic_curve_2d(const bsol_intrinsic_curve_2d &other);
00087
00088 virtual ~bsol_intrinsic_curve_2d();
00089
00090
00091 virtual vsol_spatial_object_2d* clone(void) const;
00092
00093
00094 vcl_string is_a() const { return vcl_string("bsol_intrinsic_curve_2d"); }
00095
00096
00097
00098
00099 bool isOpen(void) const { return isOpen_; }
00100
00101 virtual vsol_point_2d_sptr p0() const { return p0_; }
00102
00103 virtual vsol_point_2d_sptr p1() const { return p1_; }
00104
00105 bool valid_index(unsigned int i) const { return i<storage_->size(); }
00106
00107 vsol_point_2d_sptr vertex(const int i) const {
00108 assert(valid_index(i));
00109 return (*storage_)[i];
00110 }
00111
00112 double x (const int i) const {
00113 assert(valid_index(i));
00114 return (*storage_)[i]->x();
00115 }
00116
00117 double y (const int i) const {
00118 assert(valid_index(i));
00119 return (*storage_)[i]->y();
00120 }
00121
00122 int size(void) const { return storage_->size(); }
00123
00124 double arcLength (const int i) const {
00125 assert (valid_index(i));
00126 return arcLength_[i];
00127 }
00128
00129 double s (const int i) const {
00130 assert (valid_index(i));
00131 return s_[i];
00132 }
00133
00134 double normArcLength (const int i) const;
00135
00136 virtual double length (void) const { return length_; }
00137
00138 double dx (const int i) const {
00139 assert(valid_index(i));
00140 return (*storage_)[i]->x() - (*storage_)[i-1]->x();
00141 }
00142
00143 double dy (const int i) const {
00144 assert(valid_index(i));
00145 return (*storage_)[i]->y() - (*storage_)[i-1]->y();
00146 }
00147
00148 double curvature (const int i) const;
00149
00150 double angle (const int i) const;
00151
00152
00153 double totalCurvature (void) const { return totalCurvature_; }
00154
00155 double totalAngleChange (void) const { return totalAngleChange_; }
00156
00157
00158
00159
00160
00161 virtual bool operator==(const bsol_intrinsic_curve_2d &other) const;
00162 virtual bool operator==(const vsol_spatial_object_2d& obj) const;
00163
00164 inline bool operator!=(const bsol_intrinsic_curve_2d &o) const { return !operator==(o); }
00165
00166 protected:
00167
00168
00169
00170
00171 void computeDerivatives();
00172 void computeCurvatures();
00173 void computeArcLength();
00174 void computeAngles();
00175
00176 public:
00177
00178
00179
00180
00181 void setOpen(bool flag) { isOpen_ = flag; }
00182
00183
00184 virtual void set_p0 (const vsol_point_2d_sptr &new_p0);
00185
00186 virtual void set_p1 (const vsol_point_2d_sptr &new_p1);
00187
00188
00189
00190
00191 void computeProperties();
00192
00193
00194 void clear();
00195
00196 void add_vertex (const vsol_point_2d_sptr &new_p, bool bRecomputeProterties=false);
00197
00198 void add_vertex (double x, double y) {
00199 vsol_point_2d_sptr newpoint = new vsol_point_2d (x, y);
00200 add_vertex (newpoint, false);
00201 }
00202
00203 void remove_vertex (const int i, bool bRecomputeProterties=false);
00204
00205 void modify_vertex (const int i, double x, double y, bool bRecomputeProterties=false);
00206
00207
00208 void insert_vertex (int i, double x, double y, bool bRecomputeProterties=false);
00209
00210 void readCONFromFile(vcl_string fileName);
00211
00212
00213 bool upsample(int new_size);
00214
00215
00216
00217
00218
00219 virtual void compute_bounding_box(void) const;
00220
00221
00222 inline void describe(vcl_ostream &strm, int blanking=0) const {
00223 if (blanking < 0) blanking = 0; while (blanking--) strm << ' ';
00224 strm << "<bsol_intrinsic_curve_2d "
00225
00226 << "p0 = " << *p0_ << ", p1 = " << *p1_ << " >\n";
00227 }
00228 };
00229
00230 #endif // bsol_intrinsic_curve_2d_h_