Developer Documentation

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