Developer Documentation
BSplineSurfaceNodeT.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 BSplineSurfaceNodeT
48// Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
49//
50//=============================================================================
51
52
53#ifndef ACG_BSPLINESURFACENODET_HH
54#define ACG_BSPLINESURFACENODET_HH
55
56
57//== INCLUDES =================================================================
58
59#include <ACG/Scenegraph/BaseNode.hh>
60#include <ACG/Scenegraph/DrawModes.hh>
61
62#include <QImage>
63
64
65#include <ACG/GL/globjects.hh>
66#include <ACG/GL/VertexDeclaration.hh>
67#include <ACG/GL/GLPrimitives.hh>
68
69//== FORWARDDECLARATIONS ======================================================
70
71//== NAMESPACES ===============================================================
72
73namespace ACG {
74namespace SceneGraph {
75
76//== CLASS DEFINITION =========================================================
77
78
85template <class BSplineSurfaceType>
87{
88 public:
89
90 // typedefs for easy access
91 typedef typename BSplineSurfaceType::Point Point;
92
94 BSplineSurfaceNodeT(BSplineSurfaceType& _bss,
95 BaseNode* _parent=0,
96 std::string _name="<BSplineSurfaceNode>" ) :
97 BaseNode(_parent, _name),
98 bsplineSurface_(_bss),
99 bspline_draw_mode_(NORMAL),
100 bspline_selection_draw_mode_(NONE),
101 pick_radius_(1.0),
102 resolution_(16),
103 controlnet_color_( Vec4f(34.f/255.f, 139.f/255.f, 34.f/255.f, 1.f) ),
104 controlnet_highlight_color_( Vec4f(1.0f, 1.0f, 1.0f, 1.0f) ),
105 surface_color_( Vec4f(178.0f/255.0f, 34.0f/255.0f, 34.0f/255.0f, 1.0f) ),
106 surface_highlight_color_( Vec4f(1.0f, 1.0f, 1.0f, 1.0f) ),
107 render_control_net_(false),
108 render_bspline_surface_(true),
109 adaptive_sampling_(false),
110 controlPointSelectionTexture_valid_(false),
111 knotVectorSelectionTexture_valid_(false),
112 pick_texture_idx_(0),
113 pick_texture_res_(256),
114 pick_texture_baseidx_(0),
115 cp_selection_texture_idx_(0),
116 cp_selection_texture_res_(256),
117 knot_selection_texture_idx_(0),
118 knot_selection_texture_res_(256),
119 arb_texture_idx_(0),
120 arb_texture_used_(false),
121 arb_texture_repeat_(false),
122 arb_texture_repeat_u_(1.0),
123 arb_texture_repeat_v_(1.0),
124 surfaceIndexCount_(0),
125 invalidateSurfaceMesh_(true),
126 controlNetSelIndices_(0),
127 controlNetLineIndices_(0),
128 invalidateControlNetMesh_(true),
129 invalidateControlNetMeshSel_(true)
130 {
131 cylinder_ = new GLCylinder(16, 1, 1.0f, true, true);
132 sphere_ = new GLSphere(5, 5);
133 fancySphere_ = new GLSphere(16, 16);
134 }
135
138 {
139 delete cylinder_;
140 delete sphere_;
141 delete fancySphere_;
142 }
143
144 enum BSplineDrawMode {
145 NORMAL = 0,
146 FANCY = 1
147 };
148
149 enum BSplineSelectionDrawMode {
150 NONE = 0,
151 CONTROLPOINT = 1,
152 KNOTVECTOR = 2
153 };
154
155
156 BSplineSurfaceType& bsplineSurface() { return bsplineSurface_; }
157
158 void set_pick_radius( double _pr) { pick_radius_ = _pr; }
159
162
165
167 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
168
170 void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
171
173 void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) override;
174
176 void pick(GLState& _state, PickTarget _target) override;
177
179 void updateGeometry();
180
181 void set_rendering_resolution(int _res){resolution_ = _res;};
182
183 void render_control_net(bool _render) {render_control_net_ = _render;};
184
185 bool render_control_net() {return render_control_net_; };
186
187 void render_bspline_surface(bool _render) {render_bspline_surface_ = _render;};
188
189 bool render_bspline_surface() { return render_bspline_surface_; };
190
191 void set_bspline_draw_mode(BSplineDrawMode _mode) {bspline_draw_mode_ = _mode;};
192
193 void set_selection_draw_mode(BSplineSelectionDrawMode _mode) {bspline_selection_draw_mode_ = _mode;};
194
195 BSplineSelectionDrawMode get_selection_draw_mode() const { return bspline_selection_draw_mode_; }
196
197 void adaptive_sampling(bool _adaptive){adaptive_sampling_ = _adaptive;};
198
199 void cpSelectionTextureValid (bool _valid){controlPointSelectionTexture_valid_ = _valid;};
200 void knotSelectionTextureValid(bool _valid){knotVectorSelectionTexture_valid_ = _valid;};
201
202
204 int& pick_texture_res( ) { return pick_texture_res_; }
205
207 void set_arb_texture( const QImage& _texture, bool _repeat = false, float _u_repeat = 1.0f, float _v_repeat = 1.0f);
208 void set_arb_texture(const GLuint _texture) { arb_texture_idx_ = _texture; }
209 void set_repeat_arb_texture(bool _repeat = true, float _urep = 5.0f, float _vrep = 5.0f) { arb_texture_repeat_ = _repeat; arb_texture_repeat_u_ = _urep; arb_texture_repeat_v_ = _vrep; }
210 bool get_repeat_arb_texture( ) { return arb_texture_repeat_; }
211
212
213
214private:
215
216 void pick_vertices( GLState& _state );
217 void pick_spline( GLState& _state );
218 void pick_surface( GLState& _state, unsigned int _offset );
219
220 void draw_cylinder( const Point& _p0, const Point& _axis, double _r, GLState& _state);
221 void draw_sphere ( const Point& _p0, double _r, GLState& _state, GLSphere* _sphere);
222
225
228
229 void render(GLState& _state, bool _fill);
230
231 void drawSurface(GLState& _state, bool _fill = true);
232
233 void drawTexturedSurface(GLState& _state, GLuint _texture_idx);
234
235 void drawControlNet(GLState& _state);
236
237 void drawFancyControlNet(GLState& _state);
238
239 void updateControlPointSelectionTexture(GLState& _state);
240
241 void updateKnotVectorSelectionTexture(GLState& _state);
242
245 void pick_init_texturing ( );
247 void pick_create_texture( GLState& _state);
248
251
253 void selection_init_texturing(GLuint & _texture_idx);
254
259
262
263 ACG::Vec4f generateHighlightColor(ACG::Vec4f _color);
264
266 void updateSurfaceMesh(int _vertexCountU = 50, int _vertexCountV = 50);
267
270
273
275 void updateTexBuffers();
276
277private:
278
279 BSplineSurface& bsplineSurface_;
280
281 BSplineDrawMode bspline_draw_mode_;
282
283 BSplineSelectionDrawMode bspline_selection_draw_mode_;
284
285 double pick_radius_;
286
287 int resolution_;
288
289 Vec4f controlnet_color_;
290 Vec4f controlnet_highlight_color_;
291
292 Vec4f surface_color_;
293 Vec4f surface_highlight_color_;
294
295 bool render_control_net_;
296 bool render_bspline_surface_;
297
298 bool adaptive_sampling_;
299
300 bool controlPointSelectionTexture_valid_;
301 bool knotVectorSelectionTexture_valid_;
302
303 QImage pick_texture_image_;
304 GLuint pick_texture_idx_;
305 int pick_texture_res_;
306 // used to only re-create pick_texture_image_ if picking indices changed...
307 unsigned int pick_texture_baseidx_;
308
309 // texturing stuff for control point selection highlighting
310 QImage cp_selection_texture_image_;
311 GLuint cp_selection_texture_idx_;
312 int cp_selection_texture_res_;
313
314 // texturing stuff for knot vector selection highlighting
315 QImage knot_selection_texture_image_;
316 GLuint knot_selection_texture_idx_;
317 int knot_selection_texture_res_;
318
319 // texturing stuff for using arbitrary textures
320 QImage arb_texture_image_;
321 GLuint arb_texture_idx_;
322 bool arb_texture_used_;
323 bool arb_texture_repeat_;
324 float arb_texture_repeat_u_;
325 float arb_texture_repeat_v_;
326
327 GLCylinder* cylinder_;
328 GLSphere* sphere_;
329 GLSphere* fancySphere_;
330
331
332 // surface mesh
333 GeometryBuffer surfaceVBO_;
334 IndexBuffer surfaceIBO_;
335 VertexDeclaration surfaceDecl_;
336 int surfaceIndexCount_;
337 bool invalidateSurfaceMesh_;
338
339 // control net mesh
340 GeometryBuffer controlNetVBO_;
341 IndexBuffer controlNetSelIBO_;
342 int controlNetSelIndices_;
343 IndexBuffer controlNetLineIBO_;
344 int controlNetLineIndices_;
345 VertexDeclaration controlNetDecl_;
346 bool invalidateControlNetMesh_;
347 bool invalidateControlNetMeshSel_;
348
349 // GPU based evaluation
350 TextureBuffer knotTexBufferU_;
351 TextureBuffer knotTexBufferV_;
352 Texture2D controlPointTex_;
353};
354
355//=============================================================================
356} // namespace SceneGraph
357} // namespace ACG
358//=============================================================================
359#if defined(INCLUDE_TEMPLATES) && !defined(ACG_BSPLINESURFACENODET_C)
360#define ACG_BSPLINESURFACENODET_TEMPLATES
361#include "BSplineSurfaceNodeT_impl.hh"
362#endif
363//=============================================================================
364#endif // ACG_BSPLINESURFACENODET_HH defined
365//=============================================================================
366
void pick_draw_textured_nurbs(GLState &_state)
draw textured nurbs patch
void create_cp_selection_texture(GLState &_state)
creates texture to put onto nurbs curve for visualization of control point selection
BSplineSurfaceNodeT(const BSplineSurfaceNodeT &_rhs)
Copy constructor (not used)
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
void updateControlNetMeshSel()
update index buffer of selected control points
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
create render objects
void updateSurfaceMesh(int _vertexCountU=50, int _vertexCountV=50)
update vertex + index buffer of surface mesh
void set_arb_texture(const QImage &_texture, bool _repeat=false, float _u_repeat=1.0f, float _v_repeat=1.0f)
use arbitrary texture (in SOLID_TEXTURED mode)
void draw_textured_nurbs(GLState &_state)
draw textured nurbs patch
void updateTexBuffers()
update texture resources for gpu-based spline evaluation
void updateGeometry()
update vertex buffer for rendering
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode) override
draw lines and normals
void pick_init_texturing()
generate index and setup texture parameters
void pick(GLState &_state, PickTarget _target) override
picking
BSplineSurfaceNodeT & operator=(const BSplineSurfaceNodeT &_rhs)
Assignment operator (not used)
ACG_CLASSNAME(BSplineSurfaceNodeT)
static name of this class
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 updateControlNetMesh()
update vertex + index buffer of control net mesh
int & pick_texture_res()
Should be a power of 2.
BSplineSurfaceNodeT(BSplineSurfaceType &_bss, BaseNode *_parent=0, std::string _name="<BSplineSurfaceNode>")
Constructor.
void selection_init_texturing(GLuint &_texture_idx)
generate index and setup texture parameters for selection visualization
Class to define the vertex input layout.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:74
Namespace providing different geometric functions concerning angles.