Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
62 #include <OpenFlipper/common/Types.hh>
63 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
64 #include "BSplineCurve.hh"
65
66 //== DEFINES ==================================================================
67
68 //== TYPEDEFS =================================================================
69
70 //== CLASS DEFINITION =========================================================
71
78 BSplineCurveObject::BSplineCurveObject() :
79 BaseObjectData(),
80 splineCurve_(NULL),
81 splineCurveNode_(NULL)
82 {
83 setDataType(DATA_BSPLINE_CURVE);
84 init();
85 }
86
87 //-----------------------------------------------------------------------------
88
92 BSplineCurveObject::BSplineCurveObject(const BSplineCurveObject & _object) :
93 BaseObjectData(_object)
94 {
95 init(_object.splineCurve_);
96 setName( name() );
97 }
98
99 //-----------------------------------------------------------------------------
100
104 BSplineCurveObject::~BSplineCurveObject()
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
130 void BSplineCurveObject::cleanup()
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
140 BaseObjectData::cleanup();
141
142 splineCurveNode_ = NULL;
143
144 setDataType(DATA_BSPLINE_CURVE);
145
146 init();
147
148 }
149
150 //-----------------------------------------------------------------------------
151
155 BaseObject* BSplineCurveObject::copy()
156 {
157 BSplineCurveObject* object = new BSplineCurveObject(*this);
158 return dynamic_cast< BaseObject* >(object);
159 }
160
161 //-----------------------------------------------------------------------------
162
166 void BSplineCurveObject::init(BSplineCurve* _curve) {
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
182 splineCurveNode_ = new ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve >(*splineCurve_, materialNode() , "NEW BSplineCurveNode");
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 ) {
195 BaseObjectData::setName(_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
208 BSplineCurve* BSplineCurveObject::splineCurve() {
209 return splineCurve_;
210 }
211
212 //-----------------------------------------------------------------------------
213
215 void
216 BSplineCurveObject::
217 update(UpdateType _type)
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
255 ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve >* BSplineCurveObject::splineCurveNode() {
256 return splineCurveNode_;
257 }
258
259 // ===============================================================================
260 // Object information
261 // ===============================================================================
262
268 QString BSplineCurveObject::getObjectinfo() {
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
311 bool BSplineCurveObject::pickingEnabled() {
312 return splineCurveNode_->pickingEnabled();
313 }
314
315 //=============================================================================
ACG::BSplineCurveT::get_knotvector_ref
Knotvector * get_knotvector_ref()
get a reference to the knotvector
Definition: BSplineCurveT.hh:112
BSplineCurveObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: BSplineCurveObject.cc:130
BSplineCurveObject::BSplineCurveObject
BSplineCurveObject()
constructor
Definition: BSplineCurveObject.cc:78
BSplineCurveObject::copy
BaseObject * copy()
Definition: BSplineCurveObject.cc:155
BSplineCurveObject::splineCurve
BSplineCurve * splineCurve()
return a pointer to the spline curve
Definition: BSplineCurveObject.cc:208
BSplineCurve.hh
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
UPDATE_SELECTION_VERTICES
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
BSplineCurveObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: BSplineCurveObject.cc:305
BaseObjectData
Definition: BaseObjectData.hh:105
BSplineCurveObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: BSplineCurveObject.cc:217
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
UpdateType::contains
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
ACG::BSplineCurveT
Definition: BSplineCurveT.hh:88
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
UpdateType
Update type class.
Definition: UpdateType.hh:70
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:357
DATA_BSPLINE_CURVE
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:73
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
BSplineCurve
ACG::BSplineCurveT< ACG::Vec3d > BSplineCurve
Simple Name for BSpline curves.
Definition: BSplineCurveTypes.hh:78
BSplineCurveObject::init
virtual void init(BSplineCurve *_curve=0)
Initialise current object, including all related nodes.
Definition: BSplineCurveObject.cc:166
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BSplineCurveObject::splineCurve_
BSplineCurve * splineCurve_
return a pointer to the spline curve
Definition: BSplineCurveObject.hh:133
BSplineCurveObject::splineCurveNode_
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode_
Scenegraph Mesh Node.
Definition: BSplineCurveObject.hh:166
BSplineCurveObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BSplineCurveObject.cc:268
ACG::SceneGraph::MaterialNode::set_color
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
Definition: MaterialNode.hh:394
BaseObject
Definition: BaseObject.hh:94
OpenMesh::VectorT
Definition: Vector11T.hh:83
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
BSplineCurveObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: BSplineCurveObject.cc:194
UPDATE_SELECTION_KNOTS
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
BSplineCurveObject::splineCurveNode
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
Definition: BSplineCurveObject.cc:255
BSplineCurveObject
Definition: BSplineCurveObject.hh:84
PluginFunctions.hh
Types.hh
BSplineCurveObject::~BSplineCurveObject
virtual ~BSplineCurveObject()
destructor
Definition: BSplineCurveObject.cc:104
BSplineCurveObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: BSplineCurveObject.cc:311
BSplineCurveObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: BSplineCurveObject.cc:299
ACG::SceneGraph::BSplineCurveNodeT
Definition: BSplineCurveNodeT.hh:91