Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BSplineCurveNodeT.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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 //=============================================================================
52 //
53 // CLASS BSplineCurveNodeT
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57 
58 
59 #ifndef ACG_BSPLINECURVENODET_HH
60 #define ACG_BSPLINECURVENODET_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include <ACG/Scenegraph/BaseNode.hh>
66 #include <ACG/Scenegraph/DrawModes.hh>
67 
68 #include <QGLWidget>
69 
70 #include <ACG/GL/globjects.hh>
71 #include <ACG/GL/VertexDeclaration.hh>
72 
73 
74 //== FORWARDDECLARATIONS ======================================================
75 
76 //== NAMESPACES ===============================================================
77 
78 namespace ACG {
79 namespace SceneGraph {
80 
81 //== CLASS DEFINITION =========================================================
82 
90 template <class BSplineCurve>
92 {
93 public:
94 
95  // typedefs for easy access
96  typedef typename BSplineCurve::Point Point;
97 
100  BaseNode* _parent=0,
101  std::string _name="<BSplineCurveNode>" ) :
102  BaseNode(_parent, _name),
103  bsplineCurve_(_bsc),
104  pick_radius_(0.1),
105  resolution_(16),
106  polygon_color_( Vec4f(34.f/255.f, 139.f/255.f, 34.f/255.f, 1.f) ),
107  polygon_highlight_color_( Vec4f(1.f, 1.f, 0.f, 1.f) ),
108  curve_color_( Vec4f(178.f/255.f, 34.f/255.f, 34.f/255.f, 1.f) ),
109  curve_highlight_color_( Vec4f(1.f, 1.f, 1.f, 1.f) ),
110  render_control_polygon_(true),
111  render_bspline_curve_(true),
112  bspline_draw_mode_(NORMAL),
113  bspline_selection_draw_mode_(NONE),
114  pick_texture_idx_(0),
115  pick_texture_res_(256),
116  pick_texture_baseidx_(0),
117  cp_selection_texture_idx_(0),
118  cp_selection_texture_res_(256),
119  knot_selection_texture_idx_(0),
120  knot_selection_texture_res_(256),
121  controlPointSelectionTexture_valid_(false),
122  knotVectorSelectionTexture_valid_(false),
123  curveLineVertices_(0),
124  invalidateCurveLine_(true),
125  controlPointSelCount_(0),
126  controlEdgeSelCount_(0),
127  invalidateControlPointVBO_(true),
128  invalidateControlPointSelIBO_(true),
129  invalidateControlEdgeSelIBO_(true)
130  {
132 
133  cylinder_ = new GLCylinder(16, 1, 1.0f, true, true);
134  sphere_ = new GLSphere(5, 5);
135  fancySphere_ = new GLSphere(16, 16);
136  }
137 
138 
141  {
142  if (cylinder_)
143  delete cylinder_;
144 
145  if (sphere_)
146  delete sphere_;
147 
148  if (fancySphere_)
149  delete fancySphere_;
150  }
151 
152 
153  enum BSplineDrawMode {
154  NORMAL = 0,
155  FANCY = 1
156  };
157 
158  enum BSplineSelectionDrawMode {
159  NONE = 0,
160  CONTROLPOINT = 1,
161  KNOTVECTOR = 2
162  };
163 
164 
165  BSplineCurve& bsplineCurve() { return bsplineCurve_; }
166 
167  void set_pick_radius( double _pr) { pick_radius_ = _pr; }
168 
171 
173  DrawModes::DrawMode availableDrawModes() const;
174 
176  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
177 
179  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
180 
182  void pick(GLState& _state, PickTarget _target);
183 
184  void set_rendering_resolution(int _res){resolution_ = _res;};
185 
186  void render_control_polygon(bool _render) {render_control_polygon_ = _render;};
187  bool render_control_polygon() {return render_control_polygon_; };
188 
189  void render_bspline_curve(bool _render) {render_bspline_curve_ = _render;};
190  bool render_bspline_curve() {return render_bspline_curve_; };
191 
192  void set_selection_draw_mode(BSplineSelectionDrawMode _mode) {bspline_selection_draw_mode_ = _mode;};
193 
194  BSplineSelectionDrawMode get_selection_draw_mode() const { return bspline_selection_draw_mode_; }
195 
196  void set_bspline_draw_mode(BSplineDrawMode _mode) {bspline_draw_mode_ = _mode;};
197 
198  void updateGeometry();
199 
201  int& pick_texture_res( ) { return pick_texture_res_; }
202 
203  void cpSelectionTextureValid (bool _valid){controlPointSelectionTexture_valid_ = _valid;};
204  void knotSelectionTextureValid(bool _valid){knotVectorSelectionTexture_valid_ = _valid;};
205 
206 private:
207 
208  void pick_vertices(GLState& _state);
209  void pick_spline( GLState& _state, unsigned int _offset );
210 
211  void draw_cylinder( const Point& _p0, const Point& _axis, double _r, GLState& _state);
212  void draw_sphere ( const Point& _p0, double _r, GLState& _state, GLSphere* _sphere);
213 
216 
219 
220 
221  void render(GLState& _state, bool _fill, DrawModes::DrawMode _drawMode);
222 
223  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat);
224 
226  void drawControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
227 
229  void drawFancyControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
230 
232  void drawCurve(GLState& _state);
233 
235  void drawFancyCurve(GLState& _state);
236 
238  void drawTexturedCurve(GLState& _state, GLuint _texture_idx);
239 
241  void pick_init_texturing ( );
244  void pick_create_texture( GLState& _state);
245 
246  void updateControlPointSelectionTexture(GLState& _state);
247 
248  void updateKnotVectorSelectionTexture(GLState& _state);
249 
251  void selection_init_texturing(GLuint & _texture_idx);
252 
254  void create_cp_selection_texture(GLState& _state);
256  void create_knot_selection_texture(GLState& _state);
257 
259  void draw_textured_nurbs( GLState& _state);
260 
263 
265  void updateCurveBuffer(int _numVertices = 50);
266 
269 
272 
275 
276 
277 private:
278 
279  BSplineCurve& bsplineCurve_;
280 
281  double pick_radius_;
282 
283  int resolution_;
284 
285  Vec4f polygon_color_;
286  Vec4f polygon_highlight_color_;
287 
288  Vec4f curve_color_;
289  Vec4f curve_highlight_color_;
290 
291  bool render_control_polygon_;
292  bool render_bspline_curve_;
293 
294  BSplineDrawMode bspline_draw_mode_;
295 
296  BSplineSelectionDrawMode bspline_selection_draw_mode_;
297 
298  std::vector< std::pair< Vec3d, Vec4f > > curve_samples_;
299 
300  // texturing stuff for picking
301  QImage pick_texture_image_;
302  GLuint pick_texture_idx_;
303  int pick_texture_res_;
304  // used to only re-create pick_texture_image_ if picking indices changed...
305  unsigned int pick_texture_baseidx_;
306 
307 
308  // texturing stuff for control point selection highlighting
309  QImage cp_selection_texture_image_;
310  GLuint cp_selection_texture_idx_;
311  int cp_selection_texture_res_;
312 
313  // texturing stuff for knot vector selection highlighting
314  QImage knot_selection_texture_image_;
315  GLuint knot_selection_texture_idx_;
316  int knot_selection_texture_res_;
317 
318  bool controlPointSelectionTexture_valid_;
319  bool knotVectorSelectionTexture_valid_;
320 
321  GLCylinder* cylinder_;
322  GLSphere* sphere_;
323  GLSphere* fancySphere_;
324 
325 
326  // curve line buffers
327  GeometryBuffer curveLineVBO_;
328  VertexDeclaration curveLineDecl_;
329  int curveLineVertices_;
330  bool invalidateCurveLine_;
331 
332 
333  // control-point buffers
334  GeometryBuffer controlPointVBO_;
335  VertexDeclaration controlPointDecl_;
336  IndexBuffer controlPointSelIBO_;
337  int controlPointSelCount_;
338  IndexBuffer controlEdgeSelIBO_;
339  int controlEdgeSelCount_;
340  bool invalidateControlPointVBO_;
341  bool invalidateControlPointSelIBO_;
342  bool invalidateControlEdgeSelIBO_;
343 };
344 
345 
346 //=============================================================================
347 } // namespace SceneGraph
348 } // namespace ACG
349 //=============================================================================
350 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_BSPLINECURVENODET_C)
351 #define ACG_BSPLINECURVENODET_TEMPLATES
352 #include "BSplineCurveNodeT.cc"
353 #endif
354 //=============================================================================
355 #endif // ACG_BSPLINECURVENODET_HH defined
356 //=============================================================================
357 
ACG_CLASSNAME(BSplineCurveNodeT)
static name of this class
void updateControlPointSelBuffer()
update control point selection buffer for visualization
void selection_init_texturing(GLuint &_texture_idx)
generate index and setup texture parameters for selection visualization
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void create_cp_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of control point selection ...
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void drawFancyCurve(GLState &_state)
Renders the spline curve by sampling the curve and rendering cylinders in between the samples...
void updateCurveBuffer(int _numVertices=50)
update curve line buffer for drawing
void drawTexturedCurve(GLState &_state, GLuint _texture_idx)
renders a textured cuve using the gluNurbsRenderer to vilualize either the control point ot the knot ...
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
DrawModes::DrawMode availableDrawModes() const
return available draw modes
BSplineCurveNodeT(BSplineCurve &_bsc, BaseNode *_parent=0, std::string _name="<BSplineCurveNode>")
Constructor.
void draw_textured_nurbs(GLState &_state)
draw textured nurbs patch
int & pick_texture_res()
Should be a power of 2.
void pick(GLState &_state, PickTarget _target)
picking
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
Definition: MeshNode2T.cc:406
void create_knot_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of knotvector selection ...
void pick_create_texture(GLState &_state)
create texture image
void drawControlPolygon(DrawModes::DrawMode _drawMode, GLState &_state)
Renders the control polygon.
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:79
void drawFancyControlPolygon(DrawModes::DrawMode _drawMode, GLState &_state)
Renders the control polygon using cylinders and spheres to include shading effects.
ACG::Vec4f generateHighlightColor(ACG::Vec4f _color)
generates a color to highlight the curve from the given color
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:84
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
BSplineCurveNodeT & operator=(const BSplineCurveNodeT &_rhs)
Assignment operator (not used)
void drawCurve(GLState &_state)
Renders the spline curve using gluNurbsRenderer.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw lines and normals
void pick_init_texturing()
generate index and setup texture parameters
void updateControlEdgeSelBuffer()
update control edge selection buffer for visualization
void updateControlPointBuffer()
update control point buffer for visualization