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