Go to the documentation of this file.00001
00002 #include "vtol_edge_2d.h"
00003
00004
00005
00006 #include <vtol/vtol_zero_chain.h>
00007 #include <vsol/vsol_curve_2d.h>
00008 #include <vsol/vsol_line_2d.h>
00009 #include <vdgl/vdgl_digital_curve.h>
00010 #include <vcl_cassert.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 vtol_edge_2d::vtol_edge_2d(vtol_vertex_2d_sptr const& new_v1,
00021 vtol_vertex_2d_sptr const& new_v2,
00022 vsol_curve_2d_sptr const& new_curve)
00023 {
00024 assert(new_v1!=0); v1_=new_v1->cast_to_vertex();
00025 assert(new_v2!=0); v2_=new_v2->cast_to_vertex();
00026 if (!new_curve)
00027 curve_=new vsol_line_2d(new_v1->point(),new_v2->point());
00028 else
00029 curve_=new_curve;
00030
00031 link_inferior(new vtol_zero_chain(v1_,v2_));
00032 }
00033
00034 vtol_edge_2d::vtol_edge_2d(vtol_vertex_sptr const& new_v1,
00035 vtol_vertex_sptr const& new_v2,
00036 vsol_curve_2d_sptr const& new_curve)
00037 {
00038 assert(new_v1->cast_to_vertex_2d()); v1_=new_v1;
00039 assert(new_v2->cast_to_vertex_2d()); v2_=new_v2;
00040 if (!new_curve)
00041 curve_=new vsol_line_2d(v1_->cast_to_vertex_2d()->point(),
00042 v2_->cast_to_vertex_2d()->point());
00043 else
00044 curve_=new_curve;
00045
00046 link_inferior(new vtol_zero_chain(v1_,v2_));
00047 }
00048
00049
00050
00051
00052 vtol_edge_2d::vtol_edge_2d(vtol_edge_2d_sptr const& other)
00053 : curve_(0)
00054 {
00055 topology_list::const_iterator i;
00056 for (i=other->inferiors()->begin();i!=other->inferiors()->end();++i)
00057 {
00058 link_inferior((*i)->clone()->cast_to_topology_object()->cast_to_zero_chain());
00059 }
00060 set_vertices_from_zero_chains();
00061
00062 if (other->curve())
00063 {
00064 curve_ = other->curve()->clone()->cast_to_curve();
00065
00066 if (v1_)
00067 {
00068 if (v1_->cast_to_vertex_2d())
00069 {
00070 curve_->set_p0(v1_->cast_to_vertex_2d()->point());
00071 curve_->touch();
00072 }
00073 }
00074 if (v2_)
00075 {
00076 if (v1_->cast_to_vertex_2d())
00077 {
00078 curve_->set_p1(v2_->cast_to_vertex_2d()->point());
00079 curve_->touch();
00080 }
00081 }
00082 }
00083 touch();
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 vtol_edge_2d::vtol_edge_2d(vtol_zero_chain_sptr const& new_zero_chain)
00097 {
00098 link_inferior(new_zero_chain);
00099 set_vertices_from_zero_chains();
00100 if (new_zero_chain->numinf()==2 && v1_->cast_to_vertex_2d() && v2_->cast_to_vertex_2d())
00101
00102 curve_=new vsol_line_2d(v1_->cast_to_vertex_2d()->point(),
00103 v2_->cast_to_vertex_2d()->point());
00104 else
00105
00106
00107
00108 curve_=0;
00109 touch();
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119 vtol_edge_2d::vtol_edge_2d(zero_chain_list const& newchains)
00120 {
00121
00122
00123 for (zero_chain_list::const_iterator i=newchains.begin(); i!=newchains.end(); ++i)
00124 link_inferior(*i);
00125
00126
00127
00128 set_vertices_from_zero_chains();
00129 curve_=0;
00130 }
00131
00132
00133
00134
00135
00136
00137 vtol_edge_2d::vtol_edge_2d(double x1, double y1,
00138 double x2, double y2,
00139 vsol_curve_2d_sptr curve)
00140 {
00141 v1_=new vtol_vertex_2d(x1,y1);
00142 v2_=new vtol_vertex_2d(x2,y2);
00143 if (!curve) {
00144 if (v1_->cast_to_vertex_2d() && v2_->cast_to_vertex_2d())
00145 curve_=new vsol_line_2d(v1_->cast_to_vertex_2d()->point(),
00146 v2_->cast_to_vertex_2d()->point());
00147 }
00148 else
00149 curve_=curve->clone()->cast_to_curve();
00150
00151 link_inferior(new vtol_zero_chain(v1_,v2_));
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 vtol_edge_2d::vtol_edge_2d(vsol_curve_2d &edgecurve)
00161 {
00162 v1_ = new vtol_vertex_2d(*(edgecurve.p0()));
00163 v2_ = new vtol_vertex_2d(*(edgecurve.p1()));
00164 link_inferior(new vtol_zero_chain(v1_,v2_));
00165 }
00166
00167
00168
00169
00170
00171 vsol_spatial_object_2d* vtol_edge_2d::clone() const
00172 {
00173 return new vtol_edge_2d(vtol_edge_2d_sptr(const_cast<vtol_edge_2d*>(this)));
00174 }
00175
00176
00177
00178
00179 void vtol_edge_2d::set_curve(vsol_curve_2d &new_curve)
00180 {
00181 curve_=&new_curve;
00182 touch();
00183 }
00184
00185
00186
00187
00188
00189
00190 bool vtol_edge_2d::operator==(const vtol_edge_2d &other) const
00191 {
00192 if (this==&other) return true;
00193
00194 if ( (curve() && !other.curve()) ||
00195 (!curve() && other.curve()) )
00196 return false;
00197
00198 if (curve() && (*curve())!=(*other.curve()))
00199 return false;
00200
00201 if (!(*v1_==*(other.v1_)) || !(*v2_==*(other.v2_)))
00202 return false;
00203
00204 vtol_zero_chain_sptr zc1=zero_chain();
00205 vtol_zero_chain_sptr zc2=other.zero_chain();
00206 if (!zc1||!zc2)
00207 return false;
00208 return *zc1==*zc2;
00209 }
00210
00211
00212 bool vtol_edge_2d::operator==(const vtol_edge &other) const
00213 {
00214 return other.cast_to_edge_2d() && *this == *other.cast_to_edge_2d();
00215 }
00216
00217
00218 bool vtol_edge_2d::operator==(const vsol_spatial_object_2d& obj) const
00219 {
00220 return
00221 obj.cast_to_topology_object() &&
00222 obj.cast_to_topology_object()->cast_to_edge() &&
00223 *this == *obj.cast_to_topology_object()->cast_to_edge();
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 void vtol_edge_2d::describe(vcl_ostream &strm,
00239 int blanking) const
00240 {
00241 for (int i1=0; i1<blanking; ++i1) strm << ' ';
00242 print(strm);
00243 for (int i2=0; i2<blanking; ++i2) strm << ' ';
00244 if (v1_) {
00245 v1_->print(strm);
00246 }
00247 else {
00248 strm << "Null vertex 1\n";
00249 }
00250 for (int i3=0; i3<blanking; ++i3) strm << ' ';
00251 if (v2_) {
00252 v2_->print(strm);
00253 }
00254 else {
00255 strm << "Null vertex 2\n";
00256 }
00257 }
00258
00259
00260
00261 void vtol_edge_2d::print(vcl_ostream &strm) const
00262 {
00263 strm<<"<vtol_edge_2d "<<(void const *)this <<"> with id "<<get_id()<<'\n';
00264 }
00265
00266
00267
00268 void vtol_edge_2d::copy_geometry(const vtol_edge &other)
00269 {
00270 if (other.cast_to_edge_2d())
00271 curve_ = other.cast_to_edge_2d()->curve();
00272 }
00273
00274 bool vtol_edge_2d::compare_geometry(const vtol_edge &other) const
00275 {
00276
00277
00278 if (other.cast_to_edge_2d())
00279 return (*curve()) == *(other.cast_to_edge_2d()->curve());
00280 else
00281 return false;
00282 }
00283
00284 void vtol_edge_2d::compute_bounding_box() const
00285 {
00286 this->empty_bounding_box();
00287 vsol_curve_2d_sptr c = this->curve();
00288 if (c && c->cast_to_vdgl_digital_curve())
00289 this->set_bounding_box(c->cast_to_vdgl_digital_curve()->get_bounding_box());
00290 else
00291 vtol_topology_object::compute_bounding_box();
00292 }