vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HoopShape.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <osg\Referenced>
9 #include <string>
10 #include <xercesc\util\XercesDefs.hpp>
11 #include "Spline.h"
12 #include "Utils.h"
13 #include "LinearInterpolator.h"
14 #include "InterpolatedSpline.h"
15 #include "SampledSpline.h"
16 #include "types.h"
17 #include "RegularPolygonSpline.h"
18 #include "CatmullRomInterpolator.h"
19 #include "SampledSpline.h"
20 
21 namespace APDYNAMICART
22 {
24 #define META_HoopShapeObject(name, menuName) \
25  name(); \
26  name(const name& val); \
27  virtual void createMenu( MenuPtr parent ) const; \
28  virtual bool sliderChanged( const char* sliderID, float sliderPos ); \
29  virtual int load( XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* PoANode ); \
30  virtual void save( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* Document, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* poaNode ); \
31  virtual osg::ref_ptr<HoopShape> clone() { return new name(*this); } \
32  virtual std::string getName() { return (menuName); }
33 
35 class HoopShape : public osg::Referenced
36 {
37 public:
38  HoopShape() : _dirty(false), _spline(NULL) {};
39 
40  //Virtual methods
41  virtual SplinePtr getLeadingSpline() { return _spline; }
42  virtual void setLeadingSpline(SplinePtr val) { _spline = val; _dirty = true; }
43  virtual void createMenu( MenuPtr parent ) const {};
44  virtual bool itemClicked( const char* itemID ) { return false; };
45  virtual bool sliderChanged( const char* sliderID, float sliderPos ) { return false; };
46  virtual int load( XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* PoANode ) = 0;
47  virtual void save( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* Document, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* poaNode ) = 0;
48 
49  //Dirty object
50  virtual void dirty(bool enable = true) { _dirty = enable; }
51  virtual bool isDirty() { return _dirty; }
52 
53  //Copy
54  virtual osg::ref_ptr<HoopShape> clone() = 0;
55 
56  //Name
57  virtual std::string getName() = 0;
58 
59 protected:
60  bool _dirty;
61  SplinePtr _spline;
62  virtual ~HoopShape() {};
63 };
64 
65 typedef osg::ref_ptr<HoopShape> HoopShapePtr;
66 
67 class NullHoopShape : public HoopShape
68 {
69 public:
70  virtual HoopShapePtr clone() { return new NullHoopShape; }
71  virtual std::string getName() { return "NullHoopShape"; }
72  virtual int load( XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* PoANode ) {
73  err("Loading null object!"); return 1;
74  }
75  virtual void save( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* Document, XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* poaNode ) {
76  err("Saving null object!");
77  }
78 };
79 
80 class Rectangle : public HoopShape
81 {
82 public:
83  META_HoopShapeObject(Rectangle, "Rectangle");
84 
85 protected:
86  void init();
87  void updateSamplePoints();
88 
89  double _width;
90  double _height;
91  double _scale;
93 };
94 
95 class Ellipse : public HoopShape
96 {
97 public:
98  META_HoopShapeObject(Ellipse, "Ellipse");
99 
100 protected:
101  void init();
102  void updateSamplePoints();
103 
104  double _a;
105  double _b;
107  unsigned int _detail;
108 };
109 
110 class RegularPolygon : public HoopShape
111 {
112 public:
113  META_HoopShapeObject(RegularPolygon, "Regular polygon");
114 
115 protected:
117  double _scale;
118 
119 };
120 
121 class Line : public HoopShape
122 {
123 public:
124  META_HoopShapeObject(Line, "Rod");
125 
126 protected:
127  void init();
128  void updateSamplePoints();
129 
130  double _length;
133 };
134 
136 {
137 public:
138  META_HoopShapeObject(ElongatedCircle, "Elongated Circle");
139 
140 protected:
141  void init();
142  void updateSamplePoints();
143  void createCircleSide( double step);
144 
145  double _radius;
147  unsigned int _detail;
148  double _distance;
149 };
150 
151 class Painted : public HoopShape
152 {
153 public:
154  META_HoopShapeObject(Painted, "Painted");
155  virtual bool itemClicked( const char* itemID );
157  _points = array;
158  _sampledSpline->setVertexArray(_points);
159  }
160 protected:
163 };
164 
167 {
168 public:
169  static std::vector<std::string> getAvaiableHoopShapes() {
170  std::vector<std::string> shapes;
171  shapes.push_back("Ellipse");
172  shapes.push_back("Rectangle");
173  shapes.push_back("Rod");
174  shapes.push_back("Regular polygon");
175  shapes.push_back("Elongated Circle");
176  return shapes;
177  }
178  static HoopShapePtr getHoopShape(const std::string& name) {
179  if(name == "Ellipse")
180  return new Ellipse;
181  else if(name == "Rectangle")
182  return new Rectangle;
183  else if(name == "Regular polygon")
184  return new RegularPolygon;
185  else if(name == "Rod")
186  return new Line;
187  else if(name == "Elongated Circle")
188  return new ElongatedCircle;
189  else if(name == "Painted")
190  return new Painted;
191  else
192  return new NullHoopShape;
193  }
194 };
195 
196 }