Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 //=============================================================================
52 //
53 // BSplineCurve object type - Implementation
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57 
58 #define BSPLINECURVEOBJECT_C
59 
60 //== INCLUDES =================================================================
61 
64 #include "BSplineCurve.hh"
65 
66 //== DEFINES ==================================================================
67 
68 //== TYPEDEFS =================================================================
69 
70 //== CLASS DEFINITION =========================================================
71 
80  splineCurve_(NULL),
81  splineCurveNode_(NULL)
82 {
84  init();
85 }
86 
87 //-----------------------------------------------------------------------------
88 
93 BaseObjectData(_object)
94 {
95  init(_object.splineCurve_);
96  setName( name() );
97 }
98 
99 //-----------------------------------------------------------------------------
100 
105 {
106  // Delete the data attached to this object ( this will remove all perObject data)
107  // Not the best way to do it but it will work.
108  // This is only necessary if people use references to the curve below and
109  // they do something with the splineCurve in the destructor of their
110  // perObjectData.
111  deleteData();
112 
113  // Delete the Mesh only, if this object contains a mesh
114  if ( splineCurve_ != NULL) {
115  delete splineCurve_;
116  splineCurve_ = NULL;
117  } else {
118  std::cerr << "Destructor error : Spline curve already deleted" << std::endl;
119  }
120 
121  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
122  splineCurveNode_ = NULL;
123 }
124 
125 //-----------------------------------------------------------------------------
126 
131 {
132  // Delete the spline only, if this object contains a spline
133  if ( splineCurve_ != NULL) {
134  delete splineCurve_;
135  splineCurve_ = NULL;
136  } else {
137  std::cerr << "Cleanup error : Spline already deleted" << std::endl;
138  }
139 
141 
142  splineCurveNode_ = NULL;
143 
145 
146  init();
147 
148 }
149 
150 //-----------------------------------------------------------------------------
151 
156 {
157  BSplineCurveObject* object = new BSplineCurveObject(*this);
158  return dynamic_cast< BaseObject* >(object);
159 }
160 
161 //-----------------------------------------------------------------------------
162 
167 
168  if (_curve == 0)
169  splineCurve_ = new BSplineCurve();
170  else
171  splineCurve_ = new BSplineCurve(*_curve);
172 
173  // request selection properties for control polygon
174  splineCurve()->request_controlpoint_selections();
175  splineCurve()->request_edge_selections();
176  // request selection property for knotvector
177  splineCurve()->get_knotvector_ref()->request_selections();
178 
179  if ( materialNode() == NULL)
180  std::cerr << "Error when creating BSplineCurve Object! materialNode is NULL!" << std::endl;
181 
183 
184  materialNode()->set_color(ACG::Vec4f(178.0f/255.0f, 34.0f/255.0f, 34.0f/255.0f, 1.0f));
185 }
186 
187 // ===============================================================================
188 // Name/Path Handling
189 // ===============================================================================
190 
194 void BSplineCurveObject::setName( QString _name ) {
196 
197  std::string nodename = std::string("BSplineCurveNode for BSpline curves " + _name.toUtf8() );
198  splineCurveNode_->name( nodename );
199 }
200 
201 // ===============================================================================
202 // Content
203 // ===============================================================================
204 
209  return splineCurve_;
210 }
211 
212 //-----------------------------------------------------------------------------
213 
215 void
218 {
219  if ( _type.contains(UPDATE_ALL))
220  {
221  splineCurveNode()->updateGeometry();
222 
223  // mark textures as invalid
224  splineCurveNode()->cpSelectionTextureValid(false);
225  splineCurveNode()->knotSelectionTextureValid(false);
226  }
227  else
228  {
229  if (_type.contains(UPDATE_GEOMETRY) || _type.contains(UPDATE_SELECTION))
230  {
231  splineCurveNode()->updateGeometry();
232 
233  // mark textures as invalid
234  splineCurveNode()->cpSelectionTextureValid(false);
235  splineCurveNode()->knotSelectionTextureValid(false);
236  }
237  else if (_type.contains(UPDATE_SELECTION_VERTICES))
238  {
239  splineCurveNode()->updateGeometry();
240  splineCurveNode()->cpSelectionTextureValid(false);
241  }
242  else if (_type.contains(UPDATE_SELECTION_KNOTS))
243  {
244  splineCurveNode()->updateGeometry();
245  splineCurveNode()->knotSelectionTextureValid(false);
246  }
247  }
248 }
249 
250 
251 // ===============================================================================
252 // Visualization
253 // ===============================================================================
254 
256  return splineCurveNode_;
257 }
258 
259 // ===============================================================================
260 // Object information
261 // ===============================================================================
262 
269  QString output;
270 
271  output += "========================================================================\n";
272  output += BaseObjectData::getObjectinfo();
273 
274  if ( dataType( DATA_BSPLINE_CURVE ) )
275  output += "Object Contains BSpline Curve : ";
276  else{
277  output += "Error: Object Contains NO BSpline Curve!";
278  output += "========================================================================\n";
279  return output;
280  }
281 
282  output += QString::number( splineCurve()->n_control_points() ) + " control points, ";
283  output += QString::number( splineCurve()->n_knots() ) += " knots.\n";
284 
285  output += "========================================================================\n";
286  return output;
287 }
288 
289 // ===============================================================================
290 // Picking
291 // ===============================================================================
292 
299 bool BSplineCurveObject::picked( uint _node_idx ) {
300  return ( _node_idx == splineCurveNode_->id() );
301 }
302 
303 //-----------------------------------------------------------------------------
304 
305 void BSplineCurveObject::enablePicking( bool _enable ) {
306  splineCurveNode_->enablePicking( _enable );
307 }
308 
309 //-----------------------------------------------------------------------------
310 
312  return splineCurveNode_->pickingEnabled();
313 }
314 
315 //=============================================================================
Knotvector * get_knotvector_ref()
get a reference to the knotvector
virtual void cleanup()
Reset current object, including all related nodes.
BSplineCurveObject()
constructor
BSplineCurve * splineCurve()
return a pointer to the spline curve
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
void enablePicking(bool _enable)
Enable or disable picking for this Object.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
Update type class.
Definition: UpdateType.hh:70
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:73
MaterialNode * materialNode()
get a pointer to the materialnode
DataType dataType() const
Definition: BaseObject.cc:240
ACG::BSplineCurveT< ACG::Vec3d > BSplineCurve
Simple Name for BSpline curves.
virtual void init(BSplineCurve *_curve=0)
Initialise current object, including all related nodes.
virtual void cleanup()
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BSplineCurve * splineCurve_
return a pointer to the spline curve
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode_
Scenegraph Mesh Node.
QString getObjectinfo()
Get all Info for the Object as a string.
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
void setDataType(DataType _type)
Definition: BaseObject.cc:244
void setName(QString _name)
Set the name of the Object.
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
virtual ~BSplineCurveObject()
destructor
bool pickingEnabled()
Check if picking is enabled for this Object.
bool picked(uint _node_idx)
detect if the node has been picked