00001
00002
00003
00004
00005
00006
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00029
00030 #ifndef CURVE_H
00031 # define CURVE_H
00032
00033 # include <deque>
00034 # include "../system/BaseIterator.h"
00035 # include "../geometry/Geom.h"
00036
00037 # include "../view_map/Silhouette.h"
00038 # include "../view_map/SilhouetteGeomEngine.h"
00039 # include "../view_map/Interface0D.h"
00040 # include "../view_map/Interface1D.h"
00041
00042 using namespace std;
00043 using namespace Geometry;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00064 class LIB_STROKE_EXPORT CurvePoint : public Interface0D
00065 {
00066 public:
00068 virtual string getExactTypeName() const {
00069 return "CurvePoint";
00070 }
00071
00072
00074 virtual real getX() const {
00075 return _Point3d.x();
00076 }
00078 virtual real getY() const {
00079 return _Point3d.y();
00080 }
00082 virtual real getZ() const {
00083 return _Point3d.z();
00084 }
00086 virtual Vec3f getPoint3D() const {
00087 return _Point3d;
00088 }
00090 virtual real getProjectedX() const {
00091 return _Point2d.x();
00092 }
00094 virtual real getProjectedY() const {
00095 return _Point2d.y();
00096 }
00098 virtual real getProjectedZ() const {
00099 return _Point2d.z();
00100 }
00102 virtual Vec2f getPoint2D() const {
00103 return Vec2f((float)_Point2d.x(),(float)_Point2d.y());
00104 }
00105
00106 virtual FEdge* getFEdge(Interface0D& inter);
00108 virtual Id getId() const {
00109 Id id;
00110 if(_t2d == 0)
00111 return __A->getId();
00112 else if(_t2d == 1)
00113 return __B->getId();
00114 return id;
00115 }
00117 virtual Nature::VertexNature getNature() const {
00118 Nature::VertexNature nature = Nature::POINT;
00119 if(_t2d == 0)
00120 nature |= __A->getNature();
00121 else if(_t2d == 1)
00122 nature |= __B->getNature();
00123 return nature;
00124 }
00125
00127 virtual SVertex * castToSVertex(){
00128 if(_t2d == 0)
00129 return __A;
00130 else if(_t2d == 1)
00131 return __B;
00132 return Interface0D::castToSVertex();
00133 }
00134
00136 virtual ViewVertex * castToViewVertex(){
00137 if(_t2d == 0)
00138 return __A->castToViewVertex();
00139 else if(_t2d == 1)
00140 return __B->castToViewVertex();
00141 return Interface0D::castToViewVertex();
00142 }
00143
00145 virtual NonTVertex * castToNonTVertex(){
00146 if(_t2d == 0)
00147 return __A->castToNonTVertex();
00148 else if(_t2d == 1)
00149 return __B->castToNonTVertex();
00150 return Interface0D::castToNonTVertex();
00151 }
00152
00154 virtual TVertex * castToTVertex(){
00155 if(_t2d == 0)
00156 return __A->castToTVertex();
00157 else if(_t2d == 1)
00158 return __B->castToTVertex();
00159 return Interface0D::castToTVertex();
00160 }
00161 public:
00162 typedef SVertex vertex_type;
00163 protected:
00164 SVertex *__A;
00165 SVertex *__B;
00166 float _t2d;
00167
00168 Vec3r _Point2d;
00169 Vec3r _Point3d;
00170 public:
00172 CurvePoint();
00183 CurvePoint(SVertex *iA, SVertex *iB, float t2d) ;
00193 CurvePoint(CurvePoint *iA, CurvePoint *iB, float t2d) ;
00194
00196 CurvePoint(const CurvePoint& iBrother) ;
00198 CurvePoint& operator=(const CurvePoint& iBrother) ;
00200 virtual ~CurvePoint() {}
00202 bool operator==(const CurvePoint& b){
00203 return ((__A==b.__A) && (__B==b.__B) && (_t2d==b._t2d));
00204 }
00205
00206
00209 inline SVertex * A() {return __A;}
00212 inline SVertex * B() {return __B;}
00214 inline float t2d() const {return _t2d;}
00215
00216
00217
00221 inline void SetA(SVertex *iA) {__A = iA;}
00225 inline void SetB(SVertex *iB) {__B = iB;}
00228 inline void SetT2d(float t) {_t2d = t;}
00229
00230
00231
00232
00233 FEdge *fedge() ;
00234 inline const Vec3r& point2d() const {return _Point2d;}
00235 inline const Vec3r& point3d() const {return _Point3d;}
00236 Vec3r normal() const ;
00237
00238
00239 const SShape * shape() const ;
00240
00241
00242
00243 occluder_container::const_iterator occluders_begin() const ;
00244 occluder_container::const_iterator occluders_end() const ;
00245 bool occluders_empty() const ;
00246 int occluders_size() const ;
00247 const Polygon3r& occludee() const ;
00248 const SShape * occluded_shape() const ;
00249 const bool occludee_empty() const ;
00250 real z_discontinuity() const ;
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 real curvatureFredo () const;
00263 Vec2d directionFredo () const;
00264 };
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 namespace CurveInternal {
00276 class CurvePoint_const_traits;
00277 class CurvePoint_nonconst_traits;
00278 template<class Traits> class __point_iterator;
00279 class CurvePointIterator;
00280 }
00281
00286 class LIB_STROKE_EXPORT Curve : public Interface1D
00287 {
00288 public:
00289 typedef CurvePoint Vertex;
00290 typedef CurvePoint Point;
00291 typedef Point point_type;
00292 typedef Vertex vertex_type;
00293 typedef deque<Vertex*> vertex_container;
00294
00295
00296
00297 typedef CurveInternal::__point_iterator<CurveInternal::CurvePoint_nonconst_traits > point_iterator;
00298 typedef CurveInternal::__point_iterator<CurveInternal::CurvePoint_const_traits > const_point_iterator;
00299 typedef point_iterator vertex_iterator ;
00300 typedef const_point_iterator const_vertex_iterator ;
00301
00302 protected:
00303 vertex_container _Vertices;
00304 double _Length;
00305 Id _Id;
00306 unsigned _nSegments;
00307
00308 public:
00310 Curve() {_Length = 0;_Id = 0;_nSegments=0;}
00312 Curve(const Id& id) {_Length = 0;_Id = id;_nSegments=0;}
00314 Curve(const Curve& iBrother) {_Length = iBrother._Length;_Vertices = iBrother._Vertices;_Id=iBrother._Id;_nSegments=0;}
00316 virtual ~Curve() ;
00317
00318
00319
00320
00321 void computeCurvatureAndOrientation ();
00322
00324 inline void push_vertex_back(Vertex *iVertex)
00325 {
00326 if(!_Vertices.empty())
00327 {
00328 Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
00329 _Length += vec_tmp.norm();
00330 ++_nSegments;
00331 }
00332 Vertex * new_vertex = new Vertex(*iVertex);
00333 _Vertices.push_back(new_vertex);
00334 }
00336 inline void push_vertex_back(SVertex *iVertex)
00337 {
00338 if(!_Vertices.empty())
00339 {
00340 Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
00341 _Length += vec_tmp.norm();
00342 ++_nSegments;
00343 }
00344 Vertex *new_vertex = new Vertex(iVertex, 0,0);
00345 _Vertices.push_back(new_vertex);
00346 }
00348 inline void push_vertex_front(Vertex *iVertex)
00349 {
00350 if(!_Vertices.empty())
00351 {
00352 Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
00353 _Length += vec_tmp.norm();
00354 ++_nSegments;
00355 }
00356 Vertex * new_vertex = new Vertex(*iVertex);
00357 _Vertices.push_front(new_vertex);
00358 }
00360 inline void push_vertex_front(SVertex *iVertex)
00361 {
00362 if(!_Vertices.empty())
00363 {
00364 Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
00365 _Length += vec_tmp.norm();
00366 ++_nSegments;
00367 }
00368 Vertex *new_vertex = new Vertex(iVertex, 0,0);
00369 _Vertices.push_front(new_vertex);
00370 }
00372 inline bool empty() const {return _Vertices.empty();}
00374 inline real getLength2D() const {return _Length;}
00376 virtual Id getId() const {
00377 return _Id;
00378 }
00382 inline unsigned int nSegments() const {return _nSegments;}
00383
00384 inline void setId(const Id& id){_Id = id;}
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00413
00414
00415
00416 point_iterator points_begin(float step = 0);
00417 const_point_iterator points_begin(float step = 0) const;
00418 point_iterator points_end(float step = 0);
00419 const_point_iterator points_end(float step = 0) const;
00420
00421
00422 point_iterator vertices_begin();
00423 const_point_iterator vertices_begin() const;
00424 point_iterator vertices_end();
00425 const_point_iterator vertices_end() const;
00426
00427
00428 CurveInternal::CurvePointIterator curvePointsBegin(float t=0.f);
00429 CurveInternal::CurvePointIterator curvePointsEnd(float t=0.f);
00430
00431 CurveInternal::CurvePointIterator curveVerticesBegin();
00432 CurveInternal::CurvePointIterator curveVerticesEnd();
00433
00434
00439 virtual Interface0DIterator verticesBegin();
00444 virtual Interface0DIterator verticesEnd();
00451 virtual Interface0DIterator pointsBegin(float t=0.f);
00458 virtual Interface0DIterator pointsEnd(float t=0.f);
00459 };
00460
00461
00462
00463 #endif