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 STROKE_H
00031 # define STROKE_H
00032
00033 # include <vector>
00034 # include <map>
00035 # include "../system/FreestyleConfig.h"
00036 # include "../view_map/Silhouette.h"
00037 # include "Curve.h"
00038 # include "../view_map/Interface1D.h"
00039 # include "../system/StringUtils.h"
00040
00041
00042
00043
00045
00050 class LIB_STROKE_EXPORT StrokeAttribute
00051 {
00052 public:
00053
00055 StrokeAttribute();
00057 StrokeAttribute(const StrokeAttribute& iBrother);
00073 StrokeAttribute(float iRColor, float iGColor, float iBColor,
00074 float iAlpha,
00075 float iRThickness, float iLThickness);
00076
00087 StrokeAttribute(const StrokeAttribute& a1, const StrokeAttribute& a2, float t);
00088
00090 virtual ~StrokeAttribute();
00091
00092
00094 StrokeAttribute& operator=(const StrokeAttribute& iBrother);
00095
00096
00101 inline const float* getColor() const { return _color; }
00103 inline const float getColorR() const { return _color[0]; }
00105 inline const float getColorG() const { return _color[1]; }
00107 inline const float getColorB() const { return _color[2]; }
00109 inline Vec3f getColorRGB() const { return Vec3f(_color[0], _color[1], _color[2]); }
00111 inline float getAlpha() const { return _alpha; }
00117 inline const float* getThickness() const { return _thickness; }
00120 inline const float getThicknessR() const { return _thickness[0]; }
00123 inline const float getThicknessL() const { return _thickness[1]; }
00126 inline Vec2f getThicknessRL() const { return Vec2f(_thickness[0], _thickness[1]); }
00127
00129 inline bool isVisible() const {return _visible;}
00130
00135 float getAttributeReal(const char *iName) const;
00140 Vec2f getAttributeVec2f(const char *iName) const;
00145 Vec3f getAttributeVec3f(const char *iName) const;
00146
00148 bool isAttributeAvailableReal(const char *iName) const ;
00150 bool isAttributeAvailableVec2f(const char *iName) const ;
00152 bool isAttributeAvailableVec3f(const char *iName) const ;
00153
00154
00163 inline void setColor(float r, float g, float b) { _color[0]=r; _color[1]=g; _color[2]=b; }
00168 inline void setColor(const Vec3f& iRGB) { _color[0]=iRGB[0]; _color[1]=iRGB[1]; _color[2]=iRGB[2]; }
00173 inline void setAlpha(float alpha) { _alpha = alpha; }
00180 inline void setThickness(float tr, float tl) { _thickness[0]=tr; _thickness[1]=tl; }
00185 inline void setThickness(const Vec2f& tRL) { _thickness[0]=tRL[0]; _thickness[1]=tRL[1]; }
00186
00188 inline void SetVisible(bool iVisible){ _visible = iVisible; }
00189
00198 void setAttributeReal(const char *iName, float att);
00207 void setAttributeVec2f(const char *iName, const Vec2f& att);
00216 void setAttributeVec3f(const char *iName, const Vec3f& att);
00217
00218 private:
00219
00220 typedef std::map<const char*, float, StringUtils::ltstr> realMap ;
00221 typedef std::map<const char*, Vec2f, StringUtils::ltstr> Vec2fMap ;
00222 typedef std::map<const char*, Vec3f, StringUtils::ltstr> Vec3fMap ;
00223
00224 float _color[3];
00225 float _alpha;
00226 float _thickness[2];
00227 bool _visible;
00228 realMap *_userAttributesReal;
00229 Vec2fMap *_userAttributesVec2f;
00230 Vec3fMap *_userAttributesVec3f;
00231 };
00232
00233
00234
00235
00236
00238
00241 class LIB_STROKE_EXPORT StrokeVertex : public CurvePoint
00242 {
00243 public:
00244
00246 virtual string getExactTypeName() const {
00247 return "StrokeVertex";
00248 }
00249
00250 private:
00251
00252 StrokeAttribute _Attribute;
00253 float _CurvilignAbscissa;
00254 float _StrokeLength;
00255
00256 public:
00257
00259 StrokeVertex();
00261 StrokeVertex(const StrokeVertex& iBrother);
00263 StrokeVertex(SVertex *iSVertex);
00265 StrokeVertex(CurvePoint *iPoint);
00267 StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3);
00269 StrokeVertex(SVertex *iSVertex, const StrokeAttribute& iAttribute);
00271 virtual ~StrokeVertex();
00272
00273
00275 StrokeVertex& operator=(const StrokeVertex& iBrother);
00276
00277
00279 inline real x() const { return _Point2d[0]; }
00281 inline real y() const { return _Point2d[1]; }
00283 Vec2f getPoint () {return Vec2f((float)point2d()[0], (float)point2d()[1]);}
00285 inline real operator[](const int i) const { return _Point2d[i]; }
00287 inline const StrokeAttribute& attribute() const { return _Attribute; }
00289 inline StrokeAttribute& attribute() {return _Attribute;}
00291 inline float curvilinearAbscissa() const {return _CurvilignAbscissa;}
00293 inline float strokeLength() const {return _StrokeLength;}
00295 inline float u() const {return _CurvilignAbscissa/_StrokeLength;}
00296
00297
00299 inline void SetX(real x) { _Point2d[0]=x; }
00301 inline void SetY(real y) { _Point2d[1]=y; }
00303 inline void SetPoint(real x, real y) { _Point2d[0]=x; _Point2d[1]=y;}
00305 inline void SetPoint(const Vec2f& p) { _Point2d[0] = p[0];_Point2d[1] = p[1];}
00307 inline real& operator[](const int i) { return _Point2d[i]; }
00309 inline void SetAttribute(const StrokeAttribute& iAttribute) { _Attribute = iAttribute; }
00311 inline void SetCurvilinearAbscissa(float iAbscissa) {_CurvilignAbscissa = iAbscissa;}
00315 inline void SetStrokeLength(float iLength) {_StrokeLength = iLength;}
00316
00317
00318
00319
00320 };
00321
00322
00323
00324
00325
00327
00328 class StrokeRenderer;
00329 class StrokeRep;
00330
00331 namespace StrokeInternal {
00332 class vertex_const_traits ;
00333 class vertex_nonconst_traits ;
00334 template<class Traits> class vertex_iterator_base;
00335 class StrokeVertexIterator;
00336 }
00337
00344 class LIB_STROKE_EXPORT Stroke : public Interface1D
00345 {
00346 public:
00347
00349 virtual string getExactTypeName() const {
00350 return "Stroke";
00351 }
00352
00353
00354
00356 virtual Id getId() const {
00357 return _id;
00358 }
00363 typedef enum{
00364 DRY_MEDIUM,
00365 HUMID_MEDIUM,
00366 OPAQUE_MEDIUM,
00367 } MediumType;
00368
00369
00370 public:
00371 typedef std::deque<StrokeVertex*> vertex_container;
00372 typedef std::vector<ViewEdge*> viewedge_container;
00373 typedef StrokeInternal::vertex_iterator_base<StrokeInternal::vertex_nonconst_traits > vertex_iterator;
00374 typedef StrokeInternal::vertex_iterator_base<StrokeInternal::vertex_const_traits> const_vertex_iterator;
00375
00376 public:
00377
00378 private:
00379 vertex_container _Vertices;
00380 Id _id;
00381 float _Length;
00382 viewedge_container _ViewEdges;
00383 float _sampling;
00384 StrokeRenderer *_renderer;
00385 MediumType _mediumType;
00386 unsigned int _textureId;
00387 bool _tips;
00388 Vec2r _extremityOrientations[2];
00389 StrokeRep *_rep;
00390
00391 public:
00393 Stroke();
00395 Stroke(const Stroke& iBrother);
00405 template<class InputVertexIterator>
00406 Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd);
00407
00409 virtual ~Stroke();
00410
00411
00413 Stroke& operator=(const Stroke& iBrother);
00414
00427 float ComputeSampling(int iNVertices);
00428
00438 void Resample(int iNPoints);
00439
00447 void Resample(float iSampling);
00448
00454 void RemoveVertex(StrokeVertex *iVertex);
00455
00466 void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next);
00467
00468
00469 void Render(const StrokeRenderer *iRenderer );
00470 void RenderBasic(const StrokeRenderer *iRenderer );
00471
00472
00473
00474
00476 inline real getLength2D() const {return _Length;}
00479 inline MediumType getMediumType() const {return _mediumType;}
00483 inline unsigned int getTextureId() {return _textureId;}
00487 inline bool hasTips() const {return _tips;}
00488
00489 inline int vertices_size() const {return _Vertices.size();}
00490 inline viewedge_container::const_iterator viewedges_begin() const {return _ViewEdges.begin();}
00491 inline viewedge_container::iterator viewedges_begin() {return _ViewEdges.begin();}
00492 inline viewedge_container::const_iterator viewedges_end() const {return _ViewEdges.end();}
00493 inline viewedge_container::iterator viewedges_end() {return _ViewEdges.end();}
00494 inline int viewedges_size() const {return _ViewEdges.size();}
00495
00496 inline Vec2r getBeginningOrientation() const {return _extremityOrientations[0];}
00497 inline real getBeginningOrientationX() const {return _extremityOrientations[0].x();}
00498 inline real getBeginningOrientationY() const {return _extremityOrientations[0].y();}
00499 inline Vec2r getEndingOrientation() const {return _extremityOrientations[1];}
00500 inline real getEndingOrientationX() const {return _extremityOrientations[1].x();}
00501 inline real getEndingOrientationY() const {return _extremityOrientations[1].y();}
00502
00503
00504
00506 inline void SetId(const Id& id) {_id = id;}
00508 void SetLength(float iLength);
00510 inline void SetMediumType(MediumType iType) {_mediumType = iType;}
00512 inline void SetTextureId(unsigned int id) {_textureId = id;}
00516 inline void SetTips(bool iTips) {_tips = iTips;}
00517
00518 inline void push_back(StrokeVertex* iVertex) { _Vertices.push_back(iVertex); }
00519 inline void push_front(StrokeVertex* iVertex) { _Vertices.push_front(iVertex); }
00520 inline void AddViewEdge(ViewEdge *iViewEdge) {_ViewEdges.push_back(iViewEdge);}
00521 inline void SetBeginningOrientation(const Vec2r& iOrientation) {_extremityOrientations[0] = iOrientation;}
00522 inline void SetBeginningOrientation(real x, real y) {_extremityOrientations[0] = Vec2r(x,y);}
00523 inline void SetEndingOrientation(const Vec2r& iOrientation) {_extremityOrientations[1] = iOrientation;}
00524 inline void SetEndingOrientation(real x, real y) {_extremityOrientations[1] = Vec2r(x,y);}
00525
00526
00527
00528
00529 const_vertex_iterator vertices_begin() const;
00530 vertex_iterator vertices_begin(float t=0.f);
00531 const_vertex_iterator vertices_end() const;
00532 vertex_iterator vertices_end();
00533
00541 StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t=0.f);
00545 StrokeInternal::StrokeVertexIterator strokeVerticesEnd();
00547 inline unsigned int strokeVerticesSize() const {return _Vertices.size();}
00548
00549
00553 virtual Interface0DIterator verticesBegin();
00557 virtual Interface0DIterator verticesEnd();
00558
00559 virtual Interface0DIterator pointsBegin(float t=0.f);
00560 virtual Interface0DIterator pointsEnd(float t=0.f);
00561 };
00562
00563
00564
00565
00566
00567
00569
00570
00571 template<class InputVertexIterator>
00572 Stroke::Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd)
00573 {
00574 for(InputVertexIterator v=iBegin, vend=iEnd;
00575 v!=vend;
00576 v++)
00577 {
00578 _Vertices.push_back(*v);
00579 }
00580 _Length = 0;
00581 _id = 0;
00582 }
00583
00584 #endif // STROKE_H