BSplineCurveNodeT.hh 10.6 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

    polygon_color_           = Vec4f(34.0/255.0, 139.0/255.0, 34.0/255.0, 1.0);
104
    polygon_highlight_color_ = Vec4f(1.0, 1.0, 0.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
105
    curve_color_             = Vec4f(178.0/255.0, 34.0/255.0, 34.0/255.0, 1.0);
106
    curve_highlight_color_   = Vec4f(1.0, 1.0, 1.0, 1.0);
Jan Möbius's avatar
 
Jan Möbius committed
107
    
108
109
110
    cp_selection_texture_res_   = 256;
    knot_selection_texture_res_ = 256;
    
111
112
113
    cp_selection_texture_idx_ = 0;
    knot_selection_texture_idx_ = 0;
    pick_texture_idx_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
114
115
116
117
118
  }

  /// Destructor
  ~BSplineCurveNodeT() {}

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

125
126
127
  enum BSplineSelectionDrawMode {
    NONE = 0,
    CONTROLPOINT = 1,
128
    KNOTVECTOR = 2
129
  };
Jan Möbius's avatar
 
Jan Möbius committed
130
131
132
133
134
135
136
137
138
139


  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
Jan Möbius's avatar
   
Jan Möbius committed
140
  DrawModes::DrawMode availableDrawModes();
Jan Möbius's avatar
 
Jan Möbius committed
141
142
143
144
145
  
  /// update bounding box
  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);

  /// draw lines and normals
146
  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
Jan Möbius's avatar
 
Jan Möbius committed
147
148
149
150
151
152
153

  /// 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;};
154
  bool render_control_polygon() {return render_control_polygon_; };
Jan Möbius's avatar
 
Jan Möbius committed
155
156

  void render_bspline_curve(bool _render) {render_bspline_curve_ = _render;};
157
  bool render_bspline_curve() {return render_bspline_curve_; };
Jan Möbius's avatar
 
Jan Möbius committed
158

159
160
  void set_selection_draw_mode(BSplineSelectionDrawMode _mode) {bspline_selection_draw_mode_ = _mode;};
  
Mike Kremer's avatar
Mike Kremer committed
161
162
  BSplineSelectionDrawMode get_selection_draw_mode() const { return bspline_selection_draw_mode_; }

Jan Möbius's avatar
 
Jan Möbius committed
163
164
165
  void set_bspline_draw_mode(BSplineDrawMode _mode) {bspline_draw_mode_ = _mode;};

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

private:

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

178
179
  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
180
181
182
183
184
185
186

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

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

187
188
189
  
  void render(GLState& _state, bool _fill, DrawModes::DrawMode _drawMode);
  
190
191
  /// Renders the control polygon
  void drawControlPolygon(DrawModes::DrawMode _drawMode, GLState& _state);
192
193
194
195
196
  
  /// 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
197
198
  void drawCurve(GLState& _state);
  
199
200
  /// 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
201

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

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

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

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


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