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
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51 //=============================================================================
52 //
53 // BSplineSurface object type - Implementation
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 //=============================================================================
57
58
59 #define BSPLINESURFACEOBJECT_C
60
61
62 //== INCLUDES =================================================================
63
64 #include <OpenFlipper/common/GlobalOptions.hh>
65 #include <OpenFlipper/common/Types.hh>
66 #include "BSplineSurface.hh"
67
68 //== DEFINES ==================================================================
69
70 //== TYPEDEFS =================================================================
71
72 //== CLASS DEFINITION =========================================================
73
80 BSplineSurfaceObject::BSplineSurfaceObject() :
81 BaseObjectData(),
82 splineSurface_(NULL),
83 splineSurfaceNode_(NULL),
84 shaderNode_(0),
85 textureNode_(0)
86
87 {
88 setDataType(DATA_BSPLINE_SURFACE);
89 init();
90 }
91
92 //-----------------------------------------------------------------------------
93
97 BSplineSurfaceObject::BSplineSurfaceObject(const BSplineSurfaceObject & _object) :
98 BaseObjectData(_object)
99 {
100 init(_object.splineSurface_);
101 setName( name() );
102 }
103
104 //-----------------------------------------------------------------------------
105
109 BSplineSurfaceObject::~BSplineSurfaceObject()
110 {
111 // Delete the data attached to this object ( this will remove all perObject data)
112 // Not the best way to do it but it will work.
113 // This is only necessary if people use references to the curve below and
114 // they do something with the splineCurve in the destructor of their
115 // perObjectData.
116 deleteData();
117
118 // Delete the Mesh only, if this object contains a mesh
119 if ( splineSurface_ != NULL) {
120 delete splineSurface_;
121 splineSurface_ = NULL;
122 } else {
123 std::cerr << "Destructor error : Spline surface already deleted" << std::endl;
124 }
125
126 // No need to delete the scenegraph Nodes as this will be managed by baseplugin
127 splineSurfaceNode_ = NULL;
128 textureNode_ = 0;
129 shaderNode_ = 0;
130 }
131
132 //-----------------------------------------------------------------------------
133
137 void BSplineSurfaceObject::cleanup() {
138 // Delete the spline surface only, if this object contains a surface
139 if ( splineSurface_ != NULL) {
140 delete splineSurface_;
141 splineSurface_ = NULL;
142 } else {
143 std::cerr << "Cleanup error : Spline surface already deleted" << std::endl;
144 }
145
146 BaseObjectData::cleanup();
147
148 splineSurfaceNode_ = NULL;
149 textureNode_ = 0;
150 shaderNode_ = 0;
151
152 setDataType(DATA_BSPLINE_SURFACE);
153
154 init();
155 }
156
157 //-----------------------------------------------------------------------------
158
162 BaseObject* BSplineSurfaceObject::copy()
163 {
164 BSplineSurfaceObject* object = new BSplineSurfaceObject(*this);
165 return dynamic_cast< BaseObject* >(object);
166 }
167
168 //-----------------------------------------------------------------------------
169
173 void BSplineSurfaceObject::init(BSplineSurface* _surface) {
174
175 if (_surface == 0)
176 splineSurface_ = new BSplineSurface();
177 else
178 splineSurface_ = new BSplineSurface(*_surface);
179
180 // request default properties
181 splineSurface()->request_controlpoint_selections();
182 splineSurface()->request_edge_selections();
183 // request selection property for both knotvectors
184 splineSurface()->get_knotvector_m_ref()->request_selections();
185 splineSurface()->get_knotvector_n_ref()->request_selections();
186
187 if ( materialNode() == NULL)
188 std::cerr << "Error when creating BSplineSurface Object! materialNode is NULL!" << std::endl;
189
190 textureNode_ = new ACG::SceneGraph::EnvMapNode(materialNode(),"NEW TextureNode for ", true, GL_LINEAR_MIPMAP_LINEAR );
191 shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
192 splineSurfaceNode_ = new ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface >(*splineSurface_, shaderNode_ , "NEW BSplineSurfaceNode");
193
194 // shaderNode_ = new ACG::SceneGraph::ShaderNode(materialNode() , "NEW ShaderNode for ");
195 // splineSurfaceNode_ = new ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface >(*splineSurface_, shaderNode_ , "NEW BSplineSurfaceNode");
196
197 QString shaderDir = OpenFlipper::Options::shaderDirStr() +
198 OpenFlipper::Options::dirSeparator();
199
200 std::string shaderDirectory = std::string( shaderDir.toUtf8() );
201 shaderNode_->setShaderDir( shaderDirectory );
202 }
203
204 // ===============================================================================
205 // Name/Path Handling
206 // ===============================================================================
207
211 void BSplineSurfaceObject::setName( QString _name ) {
212 BaseObjectData::setName(_name);
213
214 std::string nodename = std::string("BSplineSurfaceNode for BSpline surface " + _name.toUtf8() );
215 splineSurfaceNode_->name( nodename );
216
217 nodename = std::string("TextureNode for BSpline surface " + _name.toUtf8() );
218 textureNode_->name( nodename );
219
220 nodename = std::string("ShaderNode for BSpline surface " + _name.toUtf8() );
221 shaderNode_->name( nodename );
222 }
223
224 // ===============================================================================
225 // Content
226 // ===============================================================================
227
231 BSplineSurface* BSplineSurfaceObject::splineSurface() {
232 return splineSurface_;
233 }
234
235 //-----------------------------------------------------------------------------
236
238 void
239 BSplineSurfaceObject::
240 update(UpdateType _type)
241 {
242 if ( _type.contains(UPDATE_ALL))
243 {
244 // mark textures as invalid
245 splineSurfaceNode()->cpSelectionTextureValid(false);
246 splineSurfaceNode()->knotSelectionTextureValid(false);
247
248 splineSurfaceNode()->updateGeometry();
249
250 if (textureNode())
251 splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
252 }
253 else
254 {
255 if (_type.contains(UPDATE_GEOMETRY) || _type.contains(UPDATE_SELECTION))
256 {
257 // mark textures as invalid
258 splineSurfaceNode()->cpSelectionTextureValid(false);
259 splineSurfaceNode()->knotSelectionTextureValid(false);
260
261 if (_type.contains(UPDATE_GEOMETRY))
262 splineSurfaceNode()->updateGeometry();
263 }
264 else if (_type.contains(UPDATE_SELECTION_VERTICES))
265 splineSurfaceNode()->cpSelectionTextureValid(false);
266 else if (_type.contains(UPDATE_SELECTION_KNOTS))
267 splineSurfaceNode()->knotSelectionTextureValid(false);
268 if (_type.contains(UPDATE_TEXTURE) && textureNode())
269 splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
270
271 }
272 }
273
274 // ===============================================================================
275 // Visualization
276 // ===============================================================================
277
281 ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface >* BSplineSurfaceObject::splineSurfaceNode() {
282 return splineSurfaceNode_;
283 }
284
285
289 ACG::SceneGraph::ShaderNode * BSplineSurfaceObject::shaderNode() {
290 return shaderNode_;
291 }
292
293
297 ACG::SceneGraph::EnvMapNode* BSplineSurfaceObject::textureNode() {
298 return textureNode_;
299 }
300
301 // ===============================================================================
302 // Object information
303 // ===============================================================================
304
310 QString BSplineSurfaceObject::getObjectinfo() {
311 QString output;
312
313 output += "========================================================================\n";
314 output += BaseObjectData::getObjectinfo();
315
316 if ( dataType( DATA_BSPLINE_SURFACE ) )
317 output += "Object Contains BSpline Surface : ";
318 else{
319 output += "Error: Object Contains NO BSpline Surface!";
320 output += "========================================================================\n";
321 return output;
322 }
323
324 output += QString::number( splineSurface()->n_control_points_m() ) + " control points in m direction, ";
325 output += QString::number( splineSurface()->n_control_points_n() ) + " control points in n direction, ";
326 output += QString::number( splineSurface()->n_knots_m() ) += " knots in m direction";
327 output += QString::number( splineSurface()->n_knots_n() ) += " knots in n direction.\n";
328
329 output += "========================================================================\n";
330 return output;
331 }
332
333 // ===============================================================================
334 // Picking
335 // ===============================================================================
336
343 bool BSplineSurfaceObject::picked( uint _node_idx ) {
344 return ( _node_idx == splineSurfaceNode_->id() );
345 }
346
347 //-----------------------------------------------------------------------------
348
349 void BSplineSurfaceObject::enablePicking( bool _enable ) {
350 splineSurfaceNode_->enablePicking( _enable );
351 textureNode_->enablePicking( _enable );
352 shaderNode_->enablePicking( _enable );
353 }
354
355 //-----------------------------------------------------------------------------
356
357 bool BSplineSurfaceObject::pickingEnabled() {
358 return splineSurfaceNode_->pickingEnabled();
359 }
360
361 //=============================================================================
362 //=============================================================================
ACG::BSplineSurfaceT::get_knotvector_n_ref
Knotvector * get_knotvector_n_ref()
Get a reference to the knotvector in n direction.
Definition: BSplineSurfaceT.hh:126
BSplineSurfaceObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: BSplineSurfaceObject.cc:343
BSplineSurfaceObject::shaderNode
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
Definition: BSplineSurfaceObject.cc:289
ShaderNode
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
Definition: SplatCloudTypes.hh:79
BSplineSurfaceObject::copy
BaseObject * copy()
Definition: BSplineSurfaceObject.cc:162
ACG::BSplineSurfaceT::request_edge_selections
void request_edge_selections()
request edge selection property
Definition: BSplineSurfaceT.hh:412
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
UPDATE_SELECTION_VERTICES
const UpdateType UPDATE_SELECTION_VERTICES(UpdateTypeSet(1)<< 5)
Vertex selection has changed.
ACG::BSplineSurfaceT::request_controlpoint_selections
void request_controlpoint_selections()
request control point selection property
Definition: BSplineSurfaceT.hh:410
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
ACG::SceneGraph::EnvMapNode
Definition: EnvMapNode.hh:83
BaseObjectData
Definition: BaseObjectData.hh:105
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
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
BSplineSurfaceObject::textureNode
ACG::SceneGraph::EnvMapNode * textureNode()
Get the TextureNode (actually its an environment map node) of the bspline surface.
Definition: BSplineSurfaceObject.cc:297
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
BSplineSurfaceObject
Definition: BSplineSurfaceObject.hh:86
BSplineSurfaceObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: BSplineSurfaceObject.cc:357
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
BSplineSurfaceObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: BSplineSurfaceObject.cc:137
BSplineSurface
ACG::BSplineSurfaceT< ACG::Vec3d > BSplineSurface
Simple Name for BSpline surfaces.
Definition: BSplineSurfaceTypes.hh:79
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
BSplineSurfaceObject::~BSplineSurfaceObject
virtual ~BSplineSurfaceObject()
Destructor.
Definition: BSplineSurfaceObject.cc:109
BSplineSurface.hh
BSplineSurfaceObject::splineSurface
BSplineSurface * splineSurface()
return a pointer to the spline curve
Definition: BSplineSurfaceObject.cc:231
BSplineSurfaceObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: BSplineSurfaceObject.cc:240
BSplineSurfaceObject::splineSurfaceNode_
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode_
Scenegraph BSplineSurface Node.
Definition: BSplineSurfaceObject.hh:172
BaseObject
Definition: BaseObject.hh:94
BSplineSurfaceObject::splineSurfaceNode
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
Definition: BSplineSurfaceObject.cc:281
ACG::BSplineSurfaceT
Definition: BSplineSurfaceT.hh:88
ACG::BSplineSurfaceT::get_knotvector_m_ref
Knotvector * get_knotvector_m_ref()
Get a reference to the knotvector in m direction.
Definition: BSplineSurfaceT.hh:124
UPDATE_TEXTURE
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
ACG::SceneGraph::BSplineSurfaceNodeT
Definition: BSplineSurfaceNodeT.hh:93
DATA_BSPLINE_SURFACE
#define DATA_BSPLINE_SURFACE
Definition: BSplineSurface.hh:73
UPDATE_SELECTION_KNOTS
const UpdateType UPDATE_SELECTION_KNOTS(UpdateTypeSet(1)<< 9)
Knot selection has changed.
GlobalOptions.hh
BSplineSurfaceObject::shaderNode_
ACG::SceneGraph::ShaderNode * shaderNode_
Scenegraph ShaderNode.
Definition: BSplineSurfaceObject.hh:175
BSplineSurfaceObject::textureNode_
ACG::SceneGraph::EnvMapNode * textureNode_
Scenegraph TextureNode (whoch is actually an environment node)
Definition: BSplineSurfaceObject.hh:178
BSplineSurfaceObject::BSplineSurfaceObject
BSplineSurfaceObject()
Constructor.
Definition: BSplineSurfaceObject.cc:80
ACG::SceneGraph::ShaderNode
Definition: ShaderNode.hh:87
BSplineSurfaceObject::init
virtual void init(BSplineSurface *_surface=0)
Initialise current object, including all related nodes.
Definition: BSplineSurfaceObject.cc:173
Types.hh
BSplineSurfaceObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BSplineSurfaceObject.cc:310
BSplineSurfaceObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: BSplineSurfaceObject.cc:349
BSplineSurfaceObject::splineSurface_
BSplineSurface * splineSurface_
return a pointer to the spline curve
Definition: BSplineSurfaceObject.hh:136
BSplineSurfaceObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: BSplineSurfaceObject.cc:211
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T.cc:241