Developer Documentation
GlutPrimitiveNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS GlutPrimitiveNode
55 //
56 //=============================================================================
57 
58 
59 #ifndef ACG_GLUT_PRIMITIVE_NODE_HH
60 #define ACG_GLUT_PRIMITIVE_NODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 
66 #include "BaseNode.hh"
67 #include "DrawModes.hh"
68 #include <string>
69 
70 #include <ACG/GL/GLPrimitives.hh>
71 
72 
73 //== NAMESPACES ===============================================================
74 
75 namespace ACG {
76 namespace SceneGraph {
77 
78 
79 //== CLASS DEFINITION =========================================================
80 
81 
88 class ACGDLLEXPORT GlutPrimitiveNode : public BaseNode
89 {
90 
91 public:
92 
95  {
96  CONE=0,
97  CUBE,
98  DODECAHEDRON,
99  ICOSAHEDRON,
100  OCTAHEDRON,
101  SPHERE,
102  TEAPOT,
103  TETRAHEDRON,
104  TORUS
105  };
106 
107 
108  struct Primitive
109  {
110  Vec3d position; // position
111  Vec3d axis; // direction / axis vector
112 
113  GlutPrimitiveType type; // glut primitive type
114 
115  ACG::Vec4f color; // color
116 
117  // glut primitive resolution
118  double size;
119  double innersize; // size of inner loop for torus, height for cone
120  unsigned int slices, stacks;
121 
122  // Constructor
124  {
125  // Set the type
126  type = _t;
127 
128  // default axis is negative z
129  axis = Vec3d(0,0,1);
130 
131  // set default resolution
132  size = 1.0;
133  innersize = 1.0;
134  slices = 20;
135  stacks = 20;
136  }
137 
139  {
140  type = _t;
141  position = _p;
142  axis = _a;
143  color = _c;
144 
145  // set default resolution
146  size = 1.0;
147  innersize = 1.0;
148  slices = 20;
149  stacks = 20;
150  }
151 
152  // Copy Constructor
153  Primitive( const Primitive& _p)
154  {
155  // use defined = operator
156  *this = _p;
157  }
158 
159  // = operator
160  Primitive& operator=(const Primitive& _p)
161  {
162  type = _p.type;
163  position = _p.position;
164  axis = _p.axis;
165  color = _p.color;
166  size = _p.size;
167  innersize = _p.innersize;
168  slices = _p.slices;
169  stacks = _p.stacks;
170 
171  return *this;
172  }
173  };
174 
175 
176  GlutPrimitiveNode( BaseNode* _parent=0,
177  std::string _name="<GlutPrimitive>" );
178 
179 
181  BaseNode* _parent=0,
182  std::string _name="<GlutPrimitive>" );
183 
184 
186  virtual ~GlutPrimitiveNode() {}
187 
193  size_t add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _color);
194 
195  void clear(){primitives_.clear();};
196 
198  void set_position(const Vec3d& _p, int _idx = 0);
200  const Vec3d get_position(int _idx = 0) const;
201 
203  Primitive& get_primitive(int _idx){return primitives_[_idx];};
204 
206  void set_size(double _s, int _idx = 0);
208  double get_size(int _idx = 0) const;
209 
210  ACG_CLASSNAME(GlutPrimitiveNode);
211 
213  DrawModes::DrawMode availableDrawModes() const;
214 
216  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
217 
219  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
220  void draw_obj(int _idx) const;
221 
223  void pick(GLState& _state, PickTarget _target);
224 
230  void setColorInternal(bool _set) { setColor_ = _set; };
231 
239  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat);
240 
241 private:
242 
243  std::vector<Primitive> primitives_;
244 
245  bool setColor_;
246 
247  // Sphere rendering
248  ACG::GLSphere* sphere_;
249 
250 };
251 
252 
253 //=============================================================================
254 } // namespace SceneGraph
255 } // namespace ACG
256 //=============================================================================
257 #endif // ACG_GLUT_PRIMITIVE_NODE_HH
258 //=============================================================================
void setColorInternal(bool _set)
Disable internal color processing.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
GlutPrimitiveType
Lists all available primivites.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
Primitive & get_primitive(int _idx)
get a primitive
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127