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