BSplineCurveNodeT.hh 10.5 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
Jan Möbius's avatar
 
Jan Möbius committed
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
Jan Möbius's avatar
 
Jan Möbius committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
\*===========================================================================*/


//=============================================================================
//
// CLASS BSplineCurveNodeT
// Author:  Ellen Dekkers <dekkers@cs.rwth-aachen.de>
//
//=============================================================================


#ifndef ACG_BSPLINECURVENODET_HH
#define ACG_BSPLINECURVENODET_HH


//== INCLUDES =================================================================

Ellen Dekkers's avatar
Ellen Dekkers committed
58
#include <ACG/Scenegraph/BaseNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <ACG/Scenegraph/DrawModes.hh>

#include <QGLWidget>

//== FORWARDDECLARATIONS ======================================================

//== NAMESPACES ===============================================================

namespace ACG {
namespace SceneGraph {

//== CLASS DEFINITION =========================================================

/** \class BSPlineCurveNodeT BSplineCurveNodeT.hh <ObjectTypes/BSplineCurve/BSplineCurveNodeT.hh>

    Brief Description.

    A more elaborate description follows.
*/

template <class BSplineCurve>
80
class BSplineCurveNodeT : public BaseNode
Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
85
86
87
88
89
90
{
public:

  // typedefs for easy access
  typedef typename BSplineCurve::Point Point;

  /// Constructor
  BSplineCurveNodeT(BSplineCurve& _bsc,
		    BaseNode*    _parent=0,
		    std::string  _name="<BSplineCurveNode>" ) :
91
92
    BaseNode(_parent, _name),
    bsplineCurve_(_bsc)
Jan Möbius's avatar
 
Jan Möbius committed
93
94
95
96
  {
    drawMode(DrawModes::WIREFRAME | DrawModes::POINTS);
    resolution_  = 16;
    pick_radius_ = 0.1;
97
98
    render_control_polygon_      = true;
    render_bspline_curve_        = true;
99
100
//     bspline_draw_mode_           = DIRECT;
    bspline_draw_mode_           = NORMAL;
101
    bspline_selection_draw_mode_ = NONE;
Jan Möbius's avatar
 
Jan Möbius committed
102
103
104
105

    polygon_color_           = Vec4f(34.0/255.0, 139.0/255.0, 34.0/255.0, 1.0);
    polygon_highlight_color_ = Vec4f(0,1,0,1);
    curve_color_             = Vec4f(178.0/255.0, 34.0/255.0, 34.0/255.0, 1.0);
106
    curve_highlight_color_   = Vec4f(1.0, 127.0/255.0, 0.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
107
    
108
109
110
111
    cp_selection_texture_res_   = 256;
    knot_selection_texture_res_ = 256;
    
    // init texturing for picking and knot and control point selection
Jan Möbius's avatar
 
Jan Möbius committed
112
    pick_init_texturing();
113
114
    selection_init_texturing(cp_selection_texture_idx_);
    selection_init_texturing(knot_selection_texture_idx_);
Jan Möbius's avatar
 
Jan Möbius committed
115
116
117
118
119
  }

  /// Destructor
  ~BSplineCurveNodeT() {}

120
  
Jan Möbius's avatar
 
Jan Möbius committed
121
  enum BSplineDrawMode {
122
123
    NORMAL = 0,
    FANCY = 1
Jan Möbius's avatar
 
Jan Möbius committed
124
125
  };

126
127
128
  enum BSplineSelectionDrawMode {
    NONE = 0,
    CONTROLPOINT = 1,
129
    KNOTVECTOR = 2
130
  };
Jan Möbius's avatar
 
Jan Möbius committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157


  BSplineCurve& bsplineCurve() { return bsplineCurve_; }

  void set_pick_radius( double _pr) { pick_radius_ = _pr; }

  /// static name of this class
  ACG_CLASSNAME(BSplineCurveNodeT);

  /// return available draw modes
  DrawModes::DrawMode availableDrawModes() const;
  
  /// update bounding box
  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);

  /// draw lines and normals
  void draw(GLState& _state, DrawModes::DrawMode _drawMode);

  /// picking
  void pick(GLState& _state, PickTarget _target);

  void set_rendering_resolution(int _res){resolution_ = _res;};

  void render_control_polygon(bool _render) {render_control_polygon_ = _render;};

  void render_bspline_curve(bool _render) {render_bspline_curve_ = _render;};

158
159
  void set_selection_draw_mode(BSplineSelectionDrawMode _mode) {bspline_selection_draw_mode_ = _mode;};
  
Jan Möbius's avatar
 
Jan Möbius committed
160
161
162
  void set_bspline_draw_mode(BSplineDrawMode _mode) {bspline_draw_mode_ = _mode;};

  void updateGeometry();
Ellen Dekkers's avatar
Ellen Dekkers committed
163
    
Ellen Dekkers's avatar
Ellen Dekkers committed
164
165
  //! Should be a power of 2
  int& pick_texture_res( ) { return pick_texture_res_; }
166
167
168
  
  void cpSelectionTextureValid  (bool _valid){controlPointSelectionTexture_valid_ = _valid;};
  void knotSelectionTextureValid(bool _valid){knotVectorSelectionTexture_valid_   = _valid;};
Jan Möbius's avatar
 
Jan Möbius committed
169
170
171
172
173
174
175

private:

  void pick_vertices(GLState& _state);
  void pick_curve( GLState& _state, unsigned int _offset);
  void pick_spline( GLState& _state, unsigned int _offset );

176
177
  void draw_cylinder( const Point& _p0, const Point& _axis, double _r, GLState& _state, unsigned int _slices = 16, unsigned int _stacks = 1);
  void draw_sphere  ( const Point& _p0, double _r, GLState& _state, unsigned int _slices = 5, unsigned int _stacks = 5);
Jan Möbius's avatar
 
Jan Möbius committed
178
179
180
181
182
183
184

  /// Copy constructor (not used)
  BSplineCurveNodeT(const BSplineCurveNodeT& _rhs);

  /// Assignment operator (not used)
  BSplineCurveNodeT& operator=(const BSplineCurveNodeT& _rhs);

185
186
187
  
  void render(GLState& _state, bool _fill, DrawModes::DrawMode _drawMode);
  
188
189
  /// Renders the control polygon
  void drawControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
190
191
192
193
194
  
  /// Renders the control polygon using cylinders and spheres to include shading effects
  void drawFancyControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
  
  /// Renders the spline curve using gluNurbsRenderer
195
196
  void drawCurve(GLState& _state);
  
197
198
  /// Renders the spline curve by sampling the curve and rendering cylinders in between the samples
  void drawFancyCurve(GLState& _state);
Jan Möbius's avatar
 
Jan Möbius committed
199

200
  /// renders a textured cuve using the gluNurbsRenderer to vilualize either the control point ot the knot vector selection
201
  void drawTexturedCurve(GLState& _state, GLuint _texture_idx);
Jan Möbius's avatar
 
Jan Möbius committed
202
203
  
  /** spline curve picking */
204
  /// generate index and setup texture parameters
Jan Möbius's avatar
 
Jan Möbius committed
205
  void pick_init_texturing ( );
206
  /// create texture image
Jan Möbius's avatar
 
Jan Möbius committed
207
  void pick_create_texture( GLState& _state);
208
 
Ellen Dekkers's avatar
Ellen Dekkers committed
209
210
211
  void updateControlPointSelectionTexture(GLState& _state);
  
  void updateKnotVectorSelectionTexture(GLState& _state);
212
213
  
  /// generate index and setup texture parameters for selection visualization
214
215
216
  void selection_init_texturing(GLuint & _texture_idx);
  
  /// creates texture to put onto nurbs curve for visualization of control point selection
217
  void create_cp_selection_texture(GLState& _state);
218
  /// creates texture to put onto nurbs curve for visualization of knotvector selection
219
  void create_knot_selection_texture(GLState& _state);
Jan Möbius's avatar
 
Jan Möbius committed
220
  
221
222
  /// draw textured nurbs patch
  void draw_textured_nurbs( GLState& _state);
223
224
225
  
  /// generates a color to highlight the curve from the given color
  ACG::Vec4f generateHighlightColor(ACG::Vec4f _color);
226

Jan Möbius's avatar
 
Jan Möbius committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
  
private:

  BSplineCurve& bsplineCurve_;

  double pick_radius_;

  int resolution_;

  Vec4f polygon_color_;
  Vec4f polygon_highlight_color_;

  Vec4f curve_color_;
  Vec4f curve_highlight_color_;

  bool render_control_polygon_;
  bool render_bspline_curve_;

  BSplineDrawMode bspline_draw_mode_;
246
247
  
  BSplineSelectionDrawMode bspline_selection_draw_mode_;
Jan Möbius's avatar
 
Jan Möbius committed
248
249
250

  std::vector< std::pair< Vec3d, Vec4f > > curve_samples_;
  
251
  // texturing stuff for picking
Jan Möbius's avatar
 
Jan Möbius committed
252
253
254
255
256
  QImage pick_texture_image_;
  GLuint pick_texture_idx_;
  int    pick_texture_res_;
  // used to only re-create pick_texture_image_ if picking indices changed...
  unsigned int pick_texture_baseidx_;
257
258
  
  
259
260
261
262
263
264
265
266
267
  // texturing stuff for control point selection highlighting
  QImage cp_selection_texture_image_;
  GLuint cp_selection_texture_idx_;
  int    cp_selection_texture_res_;

  // texturing stuff for knot vector selection highlighting
  QImage knot_selection_texture_image_;
  GLuint knot_selection_texture_idx_;
  int    knot_selection_texture_res_;
Jan Möbius's avatar
 
Jan Möbius committed
268

269
270
271
  bool controlPointSelectionTexture_valid_;
  bool knotVectorSelectionTexture_valid_;
  
Jan Möbius's avatar
 
Jan Möbius committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
};


//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_BSPLINECURVENODET_C)
#define ACG_BSPLINECURVENODET_TEMPLATES
#include "BSplineCurveNodeT.cc"
#endif
//=============================================================================
#endif // ACG_BSPLINECURVENODET_HH defined
//=============================================================================