Developer Documentation
BSplineSurfaceObject.cc
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 // BSplineSurface object type - Implementation
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57 
58 
59 #define BSPLINESURFACEOBJECT_C
60 
61 
62 //== INCLUDES =================================================================
63 
66 #include "BSplineSurface.hh"
67 
68 //== DEFINES ==================================================================
69 
70 //== TYPEDEFS =================================================================
71 
72 //== CLASS DEFINITION =========================================================
73 
82  splineSurface_(NULL),
83  splineSurfaceNode_(NULL),
84  shaderNode_(0),
85  textureNode_(0)
86 
87 {
89  init();
90 }
91 
92 //-----------------------------------------------------------------------------
93 
98  BaseObjectData(_object)
99 {
100  init(_object.splineSurface_);
101  setName( name() );
102 }
103 
104 //-----------------------------------------------------------------------------
105 
110 {
111  // Delete the data attached to this object ( this will remove all perObject data)
112  // Not the best way to do it but it will work.
113  // This is only necessary if people use references to the curve below and
114  // they do something with the splineCurve in the destructor of their
115  // perObjectData.
116  deleteData();
117 
118  // Delete the Mesh only, if this object contains a mesh
119  if ( splineSurface_ != NULL) {
120  delete splineSurface_;
121  splineSurface_ = NULL;
122  } else {
123  std::cerr << "Destructor error : Spline surface already deleted" << std::endl;
124  }
125 
126  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
127  splineSurfaceNode_ = NULL;
128  textureNode_ = 0;
129  shaderNode_ = 0;
130 }
131 
132 //-----------------------------------------------------------------------------
133 
138  // Delete the spline surface only, if this object contains a surface
139  if ( splineSurface_ != NULL) {
140  delete splineSurface_;
141  splineSurface_ = NULL;
142  } else {
143  std::cerr << "Cleanup error : Spline surface already deleted" << std::endl;
144  }
145 
147 
148  splineSurfaceNode_ = NULL;
149  textureNode_ = 0;
150  shaderNode_ = 0;
151 
153 
154  init();
155 }
156 
157 //-----------------------------------------------------------------------------
158 
163 {
164  BSplineSurfaceObject* object = new BSplineSurfaceObject(*this);
165  return dynamic_cast< BaseObject* >(object);
166 }
167 
168 //-----------------------------------------------------------------------------
169 
174 
175  if (_surface == 0)
177  else
178  splineSurface_ = new BSplineSurface(*_surface);
179 
180  // request default properties
183  // request selection property for both knotvectors
184  splineSurface()->get_knotvector_m_ref()->request_selections();
185  splineSurface()->get_knotvector_n_ref()->request_selections();
186 
187  if ( materialNode() == NULL)
188  std::cerr << "Error when creating BSplineSurface Object! materialNode is NULL!" << std::endl;
189 
190  textureNode_ = new ACG::SceneGraph::EnvMapNode(materialNode(),"NEW TextureNode for ", true, GL_LINEAR_MIPMAP_LINEAR );
191  shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
193 
194 // shaderNode_ = new ACG::SceneGraph::ShaderNode(materialNode() , "NEW ShaderNode for ");
195 // splineSurfaceNode_ = new ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface >(*splineSurface_, shaderNode_ , "NEW BSplineSurfaceNode");
196 
197  QString shaderDir = OpenFlipper::Options::shaderDirStr() +
198  OpenFlipper::Options::dirSeparator();
199 
200  std::string shaderDirectory = std::string( shaderDir.toUtf8() );
201  shaderNode_->setShaderDir( shaderDirectory );
202 }
203 
204 // ===============================================================================
205 // Name/Path Handling
206 // ===============================================================================
207 
211 void BSplineSurfaceObject::setName( QString _name ) {
213 
214  std::string nodename = std::string("BSplineSurfaceNode for BSpline surface " + _name.toUtf8() );
215  splineSurfaceNode_->name( nodename );
216 
217  nodename = std::string("TextureNode for BSpline surface " + _name.toUtf8() );
218  textureNode_->name( nodename );
219 
220  nodename = std::string("ShaderNode for BSpline surface " + _name.toUtf8() );
221  shaderNode_->name( nodename );
222 }
223 
224 // ===============================================================================
225 // Content
226 // ===============================================================================
227 
232  return splineSurface_;
233 }
234 
235 //-----------------------------------------------------------------------------
236 
238 void
241 {
242  if ( _type.contains(UPDATE_ALL))
243  {
244  // mark textures as invalid
245  splineSurfaceNode()->cpSelectionTextureValid(false);
246  splineSurfaceNode()->knotSelectionTextureValid(false);
247 
248  splineSurfaceNode()->updateGeometry();
249 
250  if (textureNode())
251  splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
252  }
253  else
254  {
255  if (_type.contains(UPDATE_GEOMETRY) || _type.contains(UPDATE_SELECTION))
256  {
257  // mark textures as invalid
258  splineSurfaceNode()->cpSelectionTextureValid(false);
259  splineSurfaceNode()->knotSelectionTextureValid(false);
260 
261  if (_type.contains(UPDATE_GEOMETRY))
262  splineSurfaceNode()->updateGeometry();
263  }
264  else if (_type.contains(UPDATE_SELECTION_VERTICES))
265  splineSurfaceNode()->cpSelectionTextureValid(false);
266  else if (_type.contains(UPDATE_SELECTION_KNOTS))
267  splineSurfaceNode()->knotSelectionTextureValid(false);
268  if (_type.contains(UPDATE_TEXTURE) && textureNode())
269  splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
270 
271  }
272 }
273 
274 // ===============================================================================
275 // Visualization
276 // ===============================================================================
277 
282  return splineSurfaceNode_;
283 }
284 
285 
290  return shaderNode_;
291 }
292 
293 
298  return textureNode_;
299 }
300 
301 // ===============================================================================
302 // Object information
303 // ===============================================================================
304 
311  QString output;
312 
313  output += "========================================================================\n";
314  output += BaseObjectData::getObjectinfo();
315 
317  output += "Object Contains BSpline Surface : ";
318  else{
319  output += "Error: Object Contains NO BSpline Surface!";
320  output += "========================================================================\n";
321  return output;
322  }
323 
324  output += QString::number( splineSurface()->n_control_points_m() ) + " control points in m direction, ";
325  output += QString::number( splineSurface()->n_control_points_n() ) + " control points in n direction, ";
326  output += QString::number( splineSurface()->n_knots_m() ) += " knots in m direction";
327  output += QString::number( splineSurface()->n_knots_n() ) += " knots in n direction.\n";
328 
329  output += "========================================================================\n";
330  return output;
331 }
332 
333 // ===============================================================================
334 // Picking
335 // ===============================================================================
336 
343 bool BSplineSurfaceObject::picked( uint _node_idx ) {
344  return ( _node_idx == splineSurfaceNode_->id() );
345 }
346 
347 //-----------------------------------------------------------------------------
348 
350  splineSurfaceNode_->enablePicking( _enable );
351  textureNode_->enablePicking( _enable );
352  shaderNode_->enablePicking( _enable );
353 }
354 
355 //-----------------------------------------------------------------------------
356 
358  return splineSurfaceNode_->pickingEnabled();
359 }
360 
361 //=============================================================================
362 //=============================================================================
void setDataType(DataType _type)
Definition: BaseObject.cc:244
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
void request_controlpoint_selections()
request control point selection property
virtual void cleanup()
BSplineSurface * splineSurface_
return a pointer to the spline curve
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
void setName(QString _name)
Set the name of the Object.
ACG::BSplineSurfaceT< ACG::Vec3d > BSplineSurface
Simple Name for BSpline surfaces.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
Update type class.
Definition: UpdateType.hh:70
MaterialNode * materialNode()
get a pointer to the materialnode
virtual ~BSplineSurfaceObject()
Destructor.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
virtual void cleanup()
Reset current object, including all related nodes.
ACG::SceneGraph::ShaderNode * shaderNode_
Scenegraph ShaderNode.
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:446
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BSplineSurfaceObject()
Constructor.
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual void init(BSplineSurface *_surface=0)
Initialise current object, including all related nodes.
bool picked(uint _node_idx)
detect if the node has been picked
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode_
Scenegraph BSplineSurface Node.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
#define DATA_BSPLINE_SURFACE
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode (actually its an environment map node) of the bspline surface.
QString getObjectinfo()
Get all Info for the Object as a string.
DataType dataType() const
Definition: BaseObject.cc:240
ACG::SceneGraph::EnvMapNode * textureNode_
Scenegraph TextureNode (whoch is actually an environment node)
BSplineSurface * splineSurface()
return a pointer to the spline curve
void request_edge_selections()
request edge selection property
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.