h o m e d o c u m e n t a t i o n c l a s s h i e r a r c h y

Curve.h

00001 //
00002 //  Filename         : Curve.h
00003 //  Author(s)        : Stephane Grabli
00004 //  Purpose          : Class to define a container for curves
00005 //  Date of creation : 11/01/2003
00006 //
00008 
00009 
00010 //
00011 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
00012 //   with this source distribution. 
00013 //
00014 //  This program is free software; you can redistribute it and/or
00015 //  modify it under the terms of the GNU General Public License
00016 //  as published by the Free Software Foundation; either version 2
00017 //  of the License, or (at your option) any later version.
00018 //
00019 //  This program is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with this program; if not, write to the Free Software
00026 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 //# include "../scene_graph/Material.h"
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                   /*             CurvePoint         */
00049                   /*                                */
00050                   /*                                */
00051                   /**********************************/
00052 
00064 class LIB_STROKE_EXPORT CurvePoint : public Interface0D
00065 {
00066 public: // Implementation of Interface0D
00068   virtual string getExactTypeName() const {
00069     return "CurvePoint";
00070   }
00071 
00072   // Data access methods
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   //float _t3d;
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   // CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d) ;
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   /* accessors */
00209   inline SVertex * A() {return __A;}
00212   inline SVertex * B() {return __B;}
00214   inline float t2d() const {return _t2d;}
00215   //inline const float t3d() const {return _t3d;}
00216 
00217   /* modifiers */
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   //inline void SetT3d(float t) {_t3d = t;}
00230 
00231   /* Information access interface */
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    //Material material() const ;
00238   // Id shape_id() const ;
00239    const SShape * shape() const ;
00240   // float shape_importance() const ;
00241   
00242    //const unsigned qi() const ;
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   //   float local_average_depth() const ;
00252   //   float local_depth_variance() const ;
00253   //   real local_average_density(float sigma = 2.3f) const ;
00254   // Vec3r shaded_color() const ;
00255 //    Vec3r orientation2d() const ; 
00256 //    Vec3r orientation3d() const ;
00257   //  // real curvature2d() const {return viewedge()->curvature2d((_VertexA->point2d()+_VertexB->point2d())/2.0);}  
00258   //   Vec3r curvature2d_as_vector() const ;
00259   //  /*! angle in radians */
00260   //   real curvature2d_as_angle() const ;
00261 
00262   real curvatureFredo () const;
00263   Vec2d directionFredo () const;
00264 };
00265 
00266 
00267                   /**********************************/
00268                   /*                                */
00269                   /*                                */
00270                   /*             Curve              */
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 } // end of namespace CurveInternal
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   /* Iterator to iterate over a vertex edges */
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; // number of segments
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         fredo's curvature storage
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   /* Information access interface */
00386   
00387   
00388   //inline Vec3r shaded_color(int iCombination = 0) const ;
00389   //  inline Vec3r  orientation2d(point_iterator it) const ;
00390    //Vec3r  orientation2d(int iCombination = 0) const ;
00391   //   Vec3r  orientation3d(point_iterator it) const ;
00392    //Vec3r  orientation3d(int iCombination = 0) const ;
00393   // real curvature2d(point_iterator it) const {return (*it)->curvature2d();}
00394   // real curvature2d(int iCombination = 0) const ;
00395    //Material material() const ;
00396    //int qi() const ;
00397    //   occluder_container::const_iterator occluders_begin() const ;
00398    //   occluder_container::const_iterator occluders_end() const ;
00399    //int occluders_size() const;
00400    //bool occluders_empty() const ;
00401   // const Polygon3r& occludee() const {return *(_FEdgeA->aFace());}
00402    //const SShape * occluded_shape() const;
00403    //const bool occludee_empty() const ;
00404    //real z_discontinuity(int iCombination = 0) const ;
00405   // int shape_id() const ;
00406    //const SShape * shape() const ;
00407    //float shape_importance(int iCombination=0) const ;
00408    //float local_average_depth(int iCombination = 0) const;
00409    //float local_depth_variance(int iCombination = 0) const ;
00410    //real local_average_density(float sigma = 2.3f, int iCombination = 0) const ;
00411    //Vec3r curvature2d_as_vector(int iCombination=0) const ;
00413    //real curvature2d_as_angle(int iCombination=0) const ;  
00414   
00415   /* advanced iterators access */
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   // methods given for convenience */
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   // specialized iterators access
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   // Iterators access
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