Developer Documentation
BSplineCurveObject.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 // BSplineCurve object type - Implementation
48 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
49 //
50 //=============================================================================
51 
52 #define BSPLINECURVEOBJECT_C
53 
54 //== INCLUDES =================================================================
55 
58 #include "BSplineCurve.hh"
59 
60 //== DEFINES ==================================================================
61 
62 //== TYPEDEFS =================================================================
63 
64 //== CLASS DEFINITION =========================================================
65 
74  splineCurve_(NULL),
75  splineCurveNode_(NULL)
76 {
78  init();
79 }
80 
81 //-----------------------------------------------------------------------------
82 
87 BaseObjectData(_object)
88 {
89  init(_object.splineCurve_);
90  setName( name() );
91 }
92 
93 //-----------------------------------------------------------------------------
94 
99 {
100  // Delete the data attached to this object ( this will remove all perObject data)
101  // Not the best way to do it but it will work.
102  // This is only necessary if people use references to the curve below and
103  // they do something with the splineCurve in the destructor of their
104  // perObjectData.
105  deleteData();
106 
107  // Delete the Mesh only, if this object contains a mesh
108  if ( splineCurve_ != NULL) {
109  delete splineCurve_;
110  splineCurve_ = NULL;
111  } else {
112  std::cerr << "Destructor error : Spline curve already deleted" << std::endl;
113  }
114 
115  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
116  splineCurveNode_ = NULL;
117 }
118 
119 //-----------------------------------------------------------------------------
120 
125 {
126  // Delete the spline only, if this object contains a spline
127  if ( splineCurve_ != NULL) {
128  delete splineCurve_;
129  splineCurve_ = NULL;
130  } else {
131  std::cerr << "Cleanup error : Spline already deleted" << std::endl;
132  }
133 
135 
136  splineCurveNode_ = NULL;
137 
139 
140  init();
141 
142 }
143 
144 //-----------------------------------------------------------------------------
145 
150 {
151  BSplineCurveObject* object = new BSplineCurveObject(*this);
152  return dynamic_cast< BaseObject* >(object);
153 }
154 
155 //-----------------------------------------------------------------------------
156 
161 
162  if (_curve == 0)
163  splineCurve_ = new BSplineCurve();
164  else
165  splineCurve_ = new BSplineCurve(*_curve);
166 
167  // request selection properties for control polygon
168  splineCurve()->request_controlpoint_selections();
169  splineCurve()->request_edge_selections();
170  // request selection property for knotvector
171  splineCurve()->get_knotvector_ref()->request_selections();
172 
173  if ( materialNode() == NULL)
174  std::cerr << "Error when creating BSplineCurve Object! materialNode is NULL!" << std::endl;
175 
177 
178  materialNode()->set_color(ACG::Vec4f(178.0f/255.0f, 34.0f/255.0f, 34.0f/255.0f, 1.0f));
179 }
180 
181 // ===============================================================================
182 // Name/Path Handling
183 // ===============================================================================
184 
188 void BSplineCurveObject::setName( QString _name ) {
190 
191  std::string nodename = std::string("BSplineCurveNode for BSpline curves " + _name.toUtf8() );
192  splineCurveNode_->name( nodename );
193 }
194 
195 // ===============================================================================
196 // Content
197 // ===============================================================================
198 
203  return splineCurve_;
204 }
205 
206 //-----------------------------------------------------------------------------
207 
209 void
212 {
213  if ( _type.contains(UPDATE_ALL))
214  {
215  splineCurveNode()->updateGeometry();
216 
217  // mark textures as invalid
218  splineCurveNode()->cpSelectionTextureValid(false);
219  splineCurveNode()->knotSelectionTextureValid(false);
220  }
221  else
222  {
223  if (_type.contains(UPDATE_GEOMETRY) || _type.contains(UPDATE_SELECTION))
224  {
225  splineCurveNode()->updateGeometry();
226 
227  // mark textures as invalid
228  splineCurveNode()->cpSelectionTextureValid(false);
229  splineCurveNode()->knotSelectionTextureValid(false);
230  }
231  else if (_type.contains(UPDATE_SELECTION_VERTICES))
232  {
233  splineCurveNode()->updateGeometry();
234  splineCurveNode()->cpSelectionTextureValid(false);
235  }
236  else if (_type.contains(UPDATE_SELECTION_KNOTS))
237  {
238  splineCurveNode()->updateGeometry();
239  splineCurveNode()->knotSelectionTextureValid(false);
240  }
241  }
242 }
243 
244 
245 // ===============================================================================
246 // Visualization
247 // ===============================================================================
248 
250  return splineCurveNode_;
251 }
252 
253 // ===============================================================================
254 // Object information
255 // ===============================================================================
256 
263  QString output;
264 
265  output += "========================================================================\n";
266  output += BaseObjectData::getObjectinfo();
267 
268  if ( dataType( DATA_BSPLINE_CURVE ) )
269  output += "Object Contains BSpline Curve : ";
270  else{
271  output += "Error: Object Contains NO BSpline Curve!";
272  output += "========================================================================\n";
273  return output;
274  }
275 
276  output += QString::number( splineCurve()->n_control_points() ) + " control points, ";
277  output += QString::number( splineCurve()->n_knots() ) += " knots.\n";
278 
279  output += "========================================================================\n";
280  return output;
281 }
282 
283 // ===============================================================================
284 // Picking
285 // ===============================================================================
286 
293 bool BSplineCurveObject::picked( uint _node_idx ) {
294  return ( _node_idx == splineCurveNode_->id() );
295 }
296 
297 //-----------------------------------------------------------------------------
298 
299 void BSplineCurveObject::enablePicking( bool _enable ) {
300  splineCurveNode_->enablePicking( _enable );
301 }
302 
303 //-----------------------------------------------------------------------------
304 
306  return splineCurveNode_->pickingEnabled();
307 }
308 
309 //=============================================================================
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
Update type class.
Definition: UpdateType.hh:60
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool pickingEnabled()
Check if picking is enabled for this Object.
bool picked(uint _node_idx)
detect if the node has been picked
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
MaterialNode * materialNode()
get a pointer to the materialnode
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
QString getObjectinfo()
Get all Info for the Object as a string.
void setDataType(DataType _type)
Definition: BaseObject.cc:233
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
virtual void cleanup()
void setName(QString _name)
Set the name of the Object.
Knotvector * get_knotvector_ref()
get a reference to the knotvector
virtual ~BSplineCurveObject()
destructor
void enablePicking(bool _enable)
Enable or disable picking for this Object.
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode_
Scenegraph Mesh Node.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
ACG::BSplineCurveT< ACG::Vec3d > BSplineCurve
Simple Name for BSpline curves.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
BSplineCurveObject()
constructor
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:104
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
virtual void cleanup()
Reset current object, including all related nodes.
BSplineCurve * splineCurve_
return a pointer to the spline curve
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
virtual void init(BSplineCurve *_curve=0)
Initialise current object, including all related nodes.
BSplineCurve * splineCurve()
return a pointer to the spline curve
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:67
DataType dataType() const
Definition: BaseObject.cc:229