BSplineCurveNodeT.hh 10.7 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 *                           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/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/


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


#ifndef ACG_BSPLINECURVENODET_HH
#define ACG_BSPLINECURVENODET_HH


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

#include <ACG/Scenegraph/MaterialNode.hh>
#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
81
// class BSplineCurveNodeT : public MaterialNode
class BSplineCurveNodeT : public BaseNode
Jan Möbius's avatar
 
Jan Möbius committed
82
83
84
85
86
87
88
89
90
91
{
public:

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

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

    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);
107
    curve_highlight_color_   = Vec4f(1.0, 127.0/255.0, 0.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
108
    
109
110
111
112
    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
113
    pick_init_texturing();
114
115
    selection_init_texturing(cp_selection_texture_idx_);
    selection_init_texturing(knot_selection_texture_idx_);
Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
119
120
  }

  /// Destructor
  ~BSplineCurveNodeT() {}

121
122
123
124
125
//   enum BSplineDrawMode {
//     DIRECT = 0,
//     GLU_NURBS = 1
//   };
  
Jan Möbius's avatar
 
Jan Möbius committed
126
  enum BSplineDrawMode {
127
128
    NORMAL = 0,
    FANCY = 1
Jan Möbius's avatar
 
Jan Möbius committed
129
130
  };

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

  void set_random_color();

  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;};

164
165
  void set_selection_draw_mode(BSplineSelectionDrawMode _mode) {bspline_selection_draw_mode_ = _mode;};
  
Jan Möbius's avatar
 
Jan Möbius committed
166
167
168
  void set_bspline_draw_mode(BSplineDrawMode _mode) {bspline_draw_mode_ = _mode;};

  void updateGeometry();
Ellen Dekkers's avatar
Ellen Dekkers committed
169
  
170
171
  void updateControlPointSelectionTexture(GLState& _state);
  void updateKnotVectorSelectionTexture(GLState& _state);
172
  
Ellen Dekkers's avatar
Ellen Dekkers committed
173
174
  //! Should be a power of 2
  int& pick_texture_res( ) { return pick_texture_res_; }
175
176
177
  
  void cpSelectionTextureValid  (bool _valid){controlPointSelectionTexture_valid_ = _valid;};
  void knotSelectionTextureValid(bool _valid){knotVectorSelectionTexture_valid_   = _valid;};
Jan Möbius's avatar
 
Jan Möbius committed
178
179
180
181
182
183
184

private:

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

185
186
  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
187
188
189
190
191
192
193

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

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

194
195
196
  
  void render(GLState& _state, bool _fill, DrawModes::DrawMode _drawMode);
  
197
198
  /// Renders the control polygon
  void drawControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
199
200
201
202
203
  
  /// 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
204
205
  void drawCurve(GLState& _state);
  
206
207
  /// 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
208

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

Jan Möbius's avatar
 
Jan Möbius committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  
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_;
252
253
  
  BSplineSelectionDrawMode bspline_selection_draw_mode_;
Jan Möbius's avatar
 
Jan Möbius committed
254
255
256

  std::vector< std::pair< Vec3d, Vec4f > > curve_samples_;
  
257
  // texturing stuff for picking
Jan Möbius's avatar
 
Jan Möbius committed
258
259
260
261
262
  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_;
263
264
  
  
265
266
267
268
269
270
271
272
273
  // 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
274

275
276
277
  bool controlPointSelectionTexture_valid_;
  bool knotVectorSelectionTexture_valid_;
  
Jan Möbius's avatar
 
Jan Möbius committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
};


//=============================================================================
} // 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
//=============================================================================