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