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
56 #include <OpenFlipper/common/Types.hh>
57 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
58 #include "BSplineCurve.hh"
59
60 //== DEFINES ==================================================================
61
62 //== TYPEDEFS =================================================================
63
64 //== CLASS DEFINITION =========================================================
65
72 BSplineCurveObject::BSplineCurveObject() :
73 BaseObjectData(),
74 splineCurve_(NULL),
75 splineCurveNode_(NULL)
76 {
77 setDataType(DATA_BSPLINE_CURVE);
78 init();
79 }
80
81 //-----------------------------------------------------------------------------
82
86 BSplineCurveObject::BSplineCurveObject(const BSplineCurveObject & _object) :
87 BaseObjectData(_object)
88 {
89 init(_object.splineCurve_);
90 setName( name() );
91 }
92
93 //-----------------------------------------------------------------------------
94
98 BSplineCurveObject::~BSplineCurveObject()
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
124 void BSplineCurveObject::cleanup()
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
134 BaseObjectData::cleanup();
135
136 splineCurveNode_ = NULL;
137
138 setDataType(DATA_BSPLINE_CURVE);
139
140 init();
141
142 }
143
144 //-----------------------------------------------------------------------------
145
149 BaseObject* BSplineCurveObject::copy()
150 {
151 BSplineCurveObject* object = new BSplineCurveObject(*this);
152 return dynamic_cast< BaseObject* >(object);
153 }
154
155 //-----------------------------------------------------------------------------
156
160 void BSplineCurveObject::init(BSplineCurve* _curve) {
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
176 splineCurveNode_ = new ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve >(*splineCurve_, materialNode() , "NEW BSplineCurveNode");
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 ) {
189 BaseObjectData::setName(_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
202 BSplineCurve* BSplineCurveObject::splineCurve() {
203 return splineCurve_;
204 }
205
206 //-----------------------------------------------------------------------------
207
209 void
210 BSplineCurveObject::
211 update(UpdateType _type)
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
249 ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve >* BSplineCurveObject::splineCurveNode() {
250 return splineCurveNode_;
251 }
252
253 // ===============================================================================
254 // Object information
255 // ===============================================================================
256
262 QString BSplineCurveObject::getObjectinfo() {
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
305 bool BSplineCurveObject::pickingEnabled() {
306 return splineCurveNode_->pickingEnabled();
307 }
308
309 //=============================================================================
UPDATE_SELECTION_VERTICES
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
UpdateType
Update type class.
Definition: UpdateType.hh:60
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
BSplineCurveObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: BSplineCurveObject.cc:305
BSplineCurveObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: BSplineCurveObject.cc:293
ACG::SceneGraph::MaterialNode::set_color
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
Definition: MaterialNode.hh:411
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BSplineCurveObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BSplineCurveObject.cc:262
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
PluginFunctions.hh
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:102
BSplineCurveObject::copy
BaseObject * copy()
Definition: BSplineCurveObject.cc:149
BSplineCurveObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: BSplineCurveObject.cc:188
ACG::SceneGraph::BSplineCurveNodeT
Definition: BSplineCurveNodeT.hh:88
ACG::BSplineCurveT::get_knotvector_ref
Knotvector * get_knotvector_ref()
get a reference to the knotvector
Definition: BSplineCurveT.hh:106
BSplineCurve.hh
BSplineCurveObject::~BSplineCurveObject
virtual ~BSplineCurveObject()
destructor
Definition: BSplineCurveObject.cc:98
BSplineCurveObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: BSplineCurveObject.cc:299
BSplineCurveObject::splineCurveNode_
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode_
Scenegraph Mesh Node.
Definition: BSplineCurveObject.hh:160
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
BSplineCurve
ACG::BSplineCurveT< ACG::Vec3d > BSplineCurve
Simple Name for BSpline curves.
Definition: BSplineCurveTypes.hh:72
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
ACG::BSplineCurveT
Definition: BSplineCurveT.hh:82
BSplineCurveObject::BSplineCurveObject
BSplineCurveObject()
constructor
Definition: BSplineCurveObject.cc:72
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
UpdateType::contains
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:104
BSplineCurveObject::splineCurveNode
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
Definition: BSplineCurveObject.cc:249
BSplineCurveObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: BSplineCurveObject.cc:124
BSplineCurveObject::splineCurve_
BSplineCurve * splineCurve_
return a pointer to the spline curve
Definition: BSplineCurveObject.hh:127
Types.hh
UPDATE_SELECTION_KNOTS
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
BaseObject
Definition: BaseObject.hh:82
BSplineCurveObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: BSplineCurveObject.cc:211
OpenMesh::VectorT
Definition: Vector11T.hh:83
BSplineCurveObject::init
virtual void init(BSplineCurve *_curve=0)
Initialise current object, including all related nodes.
Definition: BSplineCurveObject.cc:160
BSplineCurveObject
Definition: BSplineCurveObject.hh:78
BSplineCurveObject::splineCurve
BSplineCurve * splineCurve()
return a pointer to the spline curve
Definition: BSplineCurveObject.cc:202
BaseObjectData
Definition: BaseObjectData.hh:102
DATA_BSPLINE_CURVE
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:67
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229