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 
45 //=============================================================================
46 //
47 // BSplineSurface object type - Implementation
48 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
49 //
50 //=============================================================================
51 
52 
53 #define BSPLINESURFACEOBJECT_C
54 
55 
56 //== INCLUDES =================================================================
57 
60 #include "BSplineSurface.hh"
61 
62 //== DEFINES ==================================================================
63 
64 //== TYPEDEFS =================================================================
65 
66 //== CLASS DEFINITION =========================================================
67 
76  splineSurface_(NULL),
77  splineSurfaceNode_(NULL),
78  shaderNode_(0),
79  textureNode_(0)
80 
81 {
83  init();
84 }
85 
86 //-----------------------------------------------------------------------------
87 
92  BaseObjectData(_object)
93 {
94  init(_object.splineSurface_);
95  setName( name() );
96 }
97 
98 //-----------------------------------------------------------------------------
99 
104 {
105  // Delete the data attached to this object ( this will remove all perObject data)
106  // Not the best way to do it but it will work.
107  // This is only necessary if people use references to the curve below and
108  // they do something with the splineCurve in the destructor of their
109  // perObjectData.
110  deleteData();
111 
112  // Delete the Mesh only, if this object contains a mesh
113  if ( splineSurface_ != NULL) {
114  delete splineSurface_;
115  splineSurface_ = NULL;
116  } else {
117  std::cerr << "Destructor error : Spline surface already deleted" << std::endl;
118  }
119 
120  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
121  splineSurfaceNode_ = NULL;
122  textureNode_ = 0;
123  shaderNode_ = 0;
124 }
125 
126 //-----------------------------------------------------------------------------
127 
132  // Delete the spline surface only, if this object contains a surface
133  if ( splineSurface_ != NULL) {
134  delete splineSurface_;
135  splineSurface_ = NULL;
136  } else {
137  std::cerr << "Cleanup error : Spline surface already deleted" << std::endl;
138  }
139 
141 
142  splineSurfaceNode_ = NULL;
143  textureNode_ = 0;
144  shaderNode_ = 0;
145 
147 
148  init();
149 }
150 
151 //-----------------------------------------------------------------------------
152 
157 {
158  BSplineSurfaceObject* object = new BSplineSurfaceObject(*this);
159  return dynamic_cast< BaseObject* >(object);
160 }
161 
162 //-----------------------------------------------------------------------------
163 
168 
169  if (_surface == 0)
171  else
172  splineSurface_ = new BSplineSurface(*_surface);
173 
174  // request default properties
177  // request selection property for both knotvectors
178  splineSurface()->get_knotvector_m_ref()->request_selections();
179  splineSurface()->get_knotvector_n_ref()->request_selections();
180 
181  if ( materialNode() == NULL)
182  std::cerr << "Error when creating BSplineSurface Object! materialNode is NULL!" << std::endl;
183 
184  textureNode_ = new ACG::SceneGraph::EnvMapNode(materialNode(),"NEW TextureNode for ", true, GL_LINEAR_MIPMAP_LINEAR );
185  shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
187 
188 // shaderNode_ = new ACG::SceneGraph::ShaderNode(materialNode() , "NEW ShaderNode for ");
189 // splineSurfaceNode_ = new ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface >(*splineSurface_, shaderNode_ , "NEW BSplineSurfaceNode");
190 
191  QString shaderDir = OpenFlipper::Options::shaderDirStr() +
192  OpenFlipper::Options::dirSeparator();
193 
194  std::string shaderDirectory = std::string( shaderDir.toUtf8() );
195  shaderNode_->setShaderDir( shaderDirectory );
196 }
197 
198 // ===============================================================================
199 // Name/Path Handling
200 // ===============================================================================
201 
205 void BSplineSurfaceObject::setName( QString _name ) {
207 
208  std::string nodename = std::string("BSplineSurfaceNode for BSpline surface " + _name.toUtf8() );
209  splineSurfaceNode_->name( nodename );
210 
211  nodename = std::string("TextureNode for BSpline surface " + _name.toUtf8() );
212  textureNode_->name( nodename );
213 
214  nodename = std::string("ShaderNode for BSpline surface " + _name.toUtf8() );
215  shaderNode_->name( nodename );
216 }
217 
218 // ===============================================================================
219 // Content
220 // ===============================================================================
221 
226  return splineSurface_;
227 }
228 
229 //-----------------------------------------------------------------------------
230 
232 void
235 {
236  if ( _type.contains(UPDATE_ALL))
237  {
238  // mark textures as invalid
239  splineSurfaceNode()->cpSelectionTextureValid(false);
240  splineSurfaceNode()->knotSelectionTextureValid(false);
241 
242  splineSurfaceNode()->updateGeometry();
243 
244  if (textureNode())
245  splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
246  }
247  else
248  {
249  if (_type.contains(UPDATE_GEOMETRY) || _type.contains(UPDATE_SELECTION))
250  {
251  // mark textures as invalid
252  splineSurfaceNode()->cpSelectionTextureValid(false);
253  splineSurfaceNode()->knotSelectionTextureValid(false);
254 
255  if (_type.contains(UPDATE_GEOMETRY))
256  splineSurfaceNode()->updateGeometry();
257  }
258  else if (_type.contains(UPDATE_SELECTION_VERTICES))
259  splineSurfaceNode()->cpSelectionTextureValid(false);
260  else if (_type.contains(UPDATE_SELECTION_KNOTS))
261  splineSurfaceNode()->knotSelectionTextureValid(false);
262  if (_type.contains(UPDATE_TEXTURE) && textureNode())
263  splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
264 
265  }
266 }
267 
268 // ===============================================================================
269 // Visualization
270 // ===============================================================================
271 
276  return splineSurfaceNode_;
277 }
278 
279 
284  return shaderNode_;
285 }
286 
287 
292  return textureNode_;
293 }
294 
295 // ===============================================================================
296 // Object information
297 // ===============================================================================
298 
305  QString output;
306 
307  output += "========================================================================\n";
308  output += BaseObjectData::getObjectinfo();
309 
311  output += "Object Contains BSpline Surface : ";
312  else{
313  output += "Error: Object Contains NO BSpline Surface!";
314  output += "========================================================================\n";
315  return output;
316  }
317 
318  output += QString::number( splineSurface()->n_control_points_m() ) + " control points in m direction, ";
319  output += QString::number( splineSurface()->n_control_points_n() ) + " control points in n direction, ";
320  output += QString::number( splineSurface()->n_knots_m() ) += " knots in m direction";
321  output += QString::number( splineSurface()->n_knots_n() ) += " knots in n direction.\n";
322 
323  output += "========================================================================\n";
324  return output;
325 }
326 
327 // ===============================================================================
328 // Picking
329 // ===============================================================================
330 
337 bool BSplineSurfaceObject::picked( uint _node_idx ) {
338  return ( _node_idx == splineSurfaceNode_->id() );
339 }
340 
341 //-----------------------------------------------------------------------------
342 
344  splineSurfaceNode_->enablePicking( _enable );
345  textureNode_->enablePicking( _enable );
346  shaderNode_->enablePicking( _enable );
347 }
348 
349 //-----------------------------------------------------------------------------
350 
352  return splineSurfaceNode_->pickingEnabled();
353 }
354 
355 //=============================================================================
356 //=============================================================================
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
bool picked(uint _node_idx)
detect if the node has been picked
void request_edge_selections()
request edge selection property
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
void setName(QString _name)
Set the name of the Object.
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
BSplineSurface * splineSurface()
return a pointer to the spline curve
BSplineSurface * splineSurface_
return a pointer to the spline curve
void request_controlpoint_selections()
request control point selection property
virtual void cleanup()
Reset current object, including all related nodes.
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(2048))
Textures have changed.
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
virtual void init(BSplineSurface *_surface=0)
Initialise current object, including all related nodes.
virtual void cleanup() override
#define DATA_BSPLINE_SURFACE
virtual ~BSplineSurfaceObject()
Destructor.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode_
Scenegraph BSplineSurface Node.
QString getObjectinfo()
Get all Info for the Object as a string.
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode (actually its an environment map node) of the bspline surface.
BSplineSurfaceObject()
Constructor.
Update type class.
Definition: UpdateType.hh:59
MaterialNode * materialNode()
get a pointer to the materialnode
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:99
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(512))
Knot selection has changed.
ACG::SceneGraph::ShaderNode * shaderNode_
Scenegraph ShaderNode.
bool pickingEnabled()
Check if picking is enabled for this Object.
ACG::BSplineSurfaceT< ACG::Vec3d > BSplineSurface
Simple Name for BSpline surfaces.
void setDataType(DataType _type)
Definition: BaseObject.cc:233
ACG::SceneGraph::EnvMapNode * textureNode_
Scenegraph TextureNode (whoch is actually an environment node)
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
DataType dataType() const
Definition: BaseObject.cc:229
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(32))
Vertex selection has changed.