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
BaseObjectData.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 //=============================================================================
54 //
55 // MyTypes
56 //
57 //=============================================================================
58
59 //== INCLUDES =================================================================
60
61 #include "BaseObjectData.hh"
62 #include "Types.hh"
63 #include <ACG/Scenegraph/SceneGraph.hh>
64 #include <OpenFlipper/common/GlobalOptions.hh>
65 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
66
67
68
69
70 //== TYPEDEFS =================================================================
71
72 //== CLASS DEFINITION =========================================================
73
74 BaseObjectData::BaseObjectData(const BaseObjectData& _object)
75 : BaseObject(_object),
76 manipPlaced_(false),
77 rootNode_(_object.rootNode_),
78 separatorNode_(0),
79 manipulatorNode_(0),
80 materialNode_(0),
81 boundingBoxNode_(0),
82 stencilRefNode_(0)
83 {
85 initializeScenegraphNodes();
86 }
87
88 BaseObjectData::BaseObjectData() :
89 BaseObject(),
90 manipPlaced_(false),
91 rootNode_( dynamic_cast< ACG::SceneGraph::SeparatorNode* > (PluginFunctions::getRootNode()) ),
92 separatorNode_(0),
93 manipulatorNode_(0),
94 materialNode_(0),
95 boundingBoxNode_(0),
96 stencilRefNode_(0)
97 {
98 initializeScenegraphNodes();
99 }
100
101 BaseObjectData::~BaseObjectData() {
102 if ( separatorNode_ != 0 ) {
103 separatorNode_->delete_subtree();
104 }
105
106 }
107
108 void BaseObjectData::cleanup() {
109
110 // Delete everything below the seperator node on top of the object. This will remove the complete subtree.
111 if ( separatorNode_ == 0 )
112 std::cerr << "cleanup : separatorNode_ is already 0" << std::endl;
113 else {
114 separatorNode_->delete_subtree();
115 separatorNode_ = 0;
116 manipulatorNode_ = 0;
117 materialNode_ = 0;
118 boundingBoxNode_ = 0;
119 additionalNodes_.clear();
120 }
121
122 BaseObject::cleanup();
123
124 initializeScenegraphNodes();
125 }
126
127 void BaseObjectData::initializeScenegraphNodes() {
128 // Create seperatorNode for Object only if it does not exist.
129 if ( separatorNode_ == 0 )
130 separatorNode_ = new SeparatorNode((BaseNode*)rootNode_,"NEW Object");
131 else
132 std::cerr << "Separator Node already exists. this should not happen!" << std::endl;
133
134 if ( manipulatorNode_ == 0 ) {
135 manipulatorNode_ = new QtTranslationManipulatorNode(baseNode(),"NEW ManipulatorNode");
136
137 // Bind this manipulator to the current object
138 manipulatorNode_->setIdentifier(id());
139 manipulatorNode_->set_status( ACG::SceneGraph::TranslationManipulatorNode::Active );
140 }
141 else
142 std::cerr << "Manipulator Node already exists. this should not happen!" << std::endl;
143 if ( boundingBoxNode_ == 0)
144 {
145 boundingBoxNode_ = new BoundingBoxNode(manipulatorNode(), "New Bounding Box");
146 boundingBoxNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
147 }
148 if ( stencilRefNode_ == 0 )
149 {
150 stencilRefNode_ = new StencilRefNode(boundingBoxNode(), "New Stencil Reference");
151 stencilRefNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
152 }
153 if ( materialNode_ == 0 ) {
154 materialNode_ = new MaterialNode(stencilRefNode(), "New Material");
155
156 QColor color;
157
158 if ( OpenFlipper::Options::randomDefaultColor() ){
159
160 QColor bckgrnd = OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
161 int diff;
162
163 do{
164 color.setRgb(rand()%255, rand()%255, rand()%255);
165
166 diff = (bckgrnd.red() - color.red()) *(bckgrnd.red() - color.red())
167 +(bckgrnd.green() - color.green())*(bckgrnd.green() - color.green())
168 +(bckgrnd.blue() - color.blue()) *(bckgrnd.blue() - color.blue());
169 } while (diff < 70000);
170 }
171 else{
172 color = OpenFlipper::Options::defaultColor();
173 }
174
175 ACG::Vec4f colorV;
176 colorV[0] = color.redF();
177 colorV[1] = color.greenF();
178 colorV[2] = color.blueF();
179 colorV[3] = color.alphaF();
180
181 materialNode_->set_base_color(colorV);
182 materialNode_->set_color(colorV);
183
184 // We take the brightest color component for overlays to get best contrast
185 materialNode_->set_overlay_color(materialNode_->specular_color());
186 }
187 }
188
189
190 // ===============================================================================
191 // Object visualization
192 // ===============================================================================
193
194 void BaseObjectData::show() {
195 if ( !visible_ ) {
196 separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active );
197 visible_ = true;
198
199 emit visibilityChanged( id() );
200 }
201 }
202
203 void BaseObjectData::hide() {
204 if ( visible_ ) {
205 separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
206 visible_ = false;
207
208 emit visibilityChanged( id() );
209 }
210 }
211
212 bool BaseObjectData::visible(){
213 return visible_;
214 }
215
216 void BaseObjectData::visible(bool _visible) {
217
218 if ( visible_ != _visible ) {
219
220 if (_visible)
221 separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active );
222 else
223 separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
224
225 visible_ = _visible;
226
227 emit visibilityChanged( id() );
228 }
229 }
230
231 SeparatorNode* BaseObjectData::baseNode() {
232 return separatorNode_;
233 }
234
235 bool BaseObjectData::hasNode(BaseNode* _node) {
236
237 QList< BaseNode* > list;
238 list.push_back(separatorNode_);
239
240 BaseNode* currentNode;
241 while (!list.empty()) {
242 currentNode = list.front();
243
244 if ( currentNode->find(_node) == currentNode->childrenEnd() ) {
245 for ( BaseNode::ChildIter child = currentNode->childrenBegin() ; child != currentNode->childrenEnd(); ++child )
246 list.push_back(*child);
247 } else
248 return true;
249
250 list.pop_front();
251 }
252
253 return false;
254
255 }
256
257 BaseNode* BaseObjectData::primaryNode() {
258 return separatorNode_;
259 }
260
261 QtTranslationManipulatorNode* BaseObjectData::manipulatorNode() {
262 return manipulatorNode_;
263 }
264
265 ACG::SceneGraph::ShaderNode* BaseObjectData::shaderNode() {
266 return 0;
267 }
268
269 MaterialNode* BaseObjectData::materialNode() {
270 return materialNode_;
271 }
272
273 BoundingBoxNode* BaseObjectData::boundingBoxNode() {
274 return boundingBoxNode_;
275 }
276
277 StencilRefNode* BaseObjectData::stencilRefNode() {
278 return stencilRefNode_;
279 }
280
281 bool BaseObjectData::manipPlaced() {
282 return manipPlaced_;
283 }
284
285 void BaseObjectData::manipPlaced( bool _placed ) {
286 manipPlaced_ = _placed;
287 }
288
289 void BaseObjectData::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){
290
291 // Single pass action, as the bounding box is not influenced by multipass traversal
292 ACG::SceneGraph::BoundingBoxAction act;
293 ACG::SceneGraph::traverse(separatorNode_, act);
294
295
296 bbmin = (ACG::Vec3d) act.bbMin();
297 bbmax = (ACG::Vec3d) act.bbMax();
298 }
299
300 void BaseObjectData::setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode& _mode, const bool& _force) {
301
302 // Set draw mode for this object
303 ACG::SceneGraph::SetDrawModesAction actionActive(_mode, _force);
304
305 // Traverse scenegraph in order to set new draw mode
306 ACG::SceneGraph::traverse(primaryNode(), actionActive);
307 }
308
309 // ===============================================================================
310 // Picking
311 // ===============================================================================
312
313 bool BaseObjectData::picked( uint /* _node_idx */ ) {
314 return false;
315 }
316
317 void BaseObjectData::enablePicking( bool /*_enable*/ ) {
318 }
319
320 bool BaseObjectData::pickingEnabled() {
321 return true;
322 }
323
324 ACG::Vec3d BaseObjectData::refinePick(const ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start , const ACG::Vec3d _dir, const unsigned int _targetIdx ) {
325 return _hitPoint;
326 }
327
328 // ===============================================================================
329 // Content Nodes
330 // ===============================================================================
331 void BaseObjectData::update(UpdateType _type )
332 {
333
334 }
335
336 // ===============================================================================
337 // Additional Nodes
338 // ===============================================================================
339
340 bool BaseObjectData::hasAdditionalNode(QString _pluginName, QString _nodeName , int _id )
341 {
342 QString index;
343 index.setNum(_id);
344 QString searchname = _pluginName+"#"+_nodeName+"#"+index;
345
346 for ( uint i =0 ; i < additionalNodes_.size() ; ++i ) {
347 if (additionalNodes_[i].second == searchname )
348 return true;
349 }
350
351 return false;
352 }
353
354
355 //=============================================================================
356
357 void BaseObjectData::setName(QString _name ) {
358 BaseObject::setName(_name);
359
360 std::string nodename = std::string("SeparatorNode for object " + _name.toUtf8());
361 separatorNode_->name( nodename );
362
363 nodename = std::string("ManipulatorNode for object " + _name.toUtf8());
364 manipulatorNode_->name( nodename );
365
366 nodename = std::string("BoundingBoxNode for object " + _name.toUtf8());
367 boundingBoxNode_->name( nodename );
368
369 nodename = std::string(_name.toUtf8() + "'s Material" );
370 materialNode_->name( nodename );
371
372 nodename = std::string("StencilRefNode for object " + _name.toUtf8());
373 stencilRefNode_->name( nodename );
374 }
375
OpenFlipperSettings
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
Definition: GlobalOptions.cc:938
ACG::SceneGraph::SetDrawModesAction
Definition: SceneGraph.hh:638
ACG::SceneGraph::SeparatorNode
Definition: SeparatorNode.hh:84
SeparatorNode
ACG::SceneGraph::SeparatorNode SeparatorNode
Seperator Node.
Definition: BaseObjectData.hh:92
ACG::SceneGraph::BoundingBoxNode
Definition: BoundingBoxNode.hh:88
ACG
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::BaseNode::push_back
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:294
ACG::SceneGraph::BaseNode
Definition: BaseNode.hh:135
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
BaseObjectData::stencilRefNode_
StencilRefNode * stencilRefNode_
Stencil reference node for the object.
Definition: BaseObjectData.hh:239
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
BaseObjectData::manipPlaced
bool manipPlaced()
Check if the manipulator has been placed.
Definition: BaseObjectData.cc:281
PluginFunctions
Definition: PluginFunctionsBSplineCurve.cc:69
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::visible_
bool visible_
Definition: BaseObject.hh:286
BaseObjectData::manipulatorNode
QtTranslationManipulatorNode * manipulatorNode()
Definition: BaseObjectData.cc:261
UpdateType
Update type class.
Definition: UpdateType.hh:70
BoundingBoxNode
ACG::SceneGraph::BoundingBoxNode BoundingBoxNode
Bounding box Node.
Definition: BaseObjectData.hh:96
ACG::SceneGraph::BaseNode::Active
Draw node & children.
Definition: BaseNode.hh:368
BaseObjectData::~BaseObjectData
virtual ~BaseObjectData()
destructor
Definition: BaseObjectData.cc:101
ACG::SceneGraph::BaseNode::HideSubtree
Hide this node and its children.
Definition: BaseNode.hh:374
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:357
BaseObjectData::pickingEnabled
virtual bool pickingEnabled()
Definition: BaseObjectData.cc:320
BaseObjectData::show
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
Definition: BaseObjectData.cc:194
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
ACG::SceneGraph::MaterialNode::set_overlay_color
void set_overlay_color(const Vec4f &_s)
set the overlay color
Definition: MaterialNode.hh:424
BaseObjectData::BaseObjectData
BaseObjectData()
constructor
Definition: BaseObjectData.cc:88
ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:270
ACG::SceneGraph::BoundingBoxAction
Definition: SceneGraph.hh:368
BaseObjectData::refinePick
virtual ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start, const ACG::Vec3d _dir, const unsigned int _targetIdx)
Refine picking.
Definition: BaseObjectData.cc:324
BaseObjectData::separatorNode_
SeparatorNode * separatorNode_
Separator at top of Scenegraph structure used for this Object.
Definition: BaseObjectData.hh:227
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
BaseObjectData::hide
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
Definition: BaseObjectData.cc:203
ACG::SceneGraph::ACG::SceneGraph::BaseNode::delete_subtree
void delete_subtree()
Delete the whole subtree of this node.
Definition: BaseNode.cc:176
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
ACG::SceneGraph::QtTranslationManipulatorNode::setIdentifier
void setIdentifier(int _id)
Set an identifier for that manipulator.
Definition: QtTranslationManipulatorNode.hh:133
BaseObjectData::hasNode
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
Definition: BaseObjectData.cc:235
ACG::SceneGraph::MaterialNode::set_base_color
void set_base_color(const Vec4f &_c)
set the base color
Definition: MaterialNode.hh:404
BaseObjectData::hasAdditionalNode
bool hasAdditionalNode(QString _pluginName, QString _nodeName, int _id=0)
check if an object has the additional node
Definition: BaseObjectData.cc:340
ACG::SceneGraph::QtTranslationManipulatorNode
Definition: QtTranslationManipulatorNode.hh:87
ACG::SceneGraph::BaseNode::ChildIter
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
BaseObjectData::baseNode
SeparatorNode * baseNode()
Definition: BaseObjectData.cc:231
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
ACG::SceneGraph::ACG::SceneGraph::BaseNode::set_status
void set_status(StatusMode _s)
Set the status of this node.
Definition: MeshNode2T.cc:379
ACG::SceneGraph::BoundingBoxAction::bbMax
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Definition: SceneGraph.hh:409
ACG::SceneGraph::MaterialNode::set_color
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
Definition: MaterialNode.hh:394
BaseObjectData::primaryNode
virtual BaseNode * primaryNode()
Definition: BaseObjectData.cc:257
BaseObject::cleanup
virtual void cleanup()
Definition: BaseObject.cc:218
BaseObjectData::stencilRefNode
StencilRefNode * stencilRefNode()
get a pointer to the stencil reference node
Definition: BaseObjectData.cc:277
BaseObjectData::enablePicking
virtual void enablePicking(bool _enable)
Definition: BaseObjectData.cc:317
BaseObject
Definition: BaseObject.hh:94
BaseObjectData::shaderNode
virtual ACG::SceneGraph::ShaderNode * shaderNode()
Definition: BaseObjectData.cc:265
OpenMesh::VectorT
Definition: Vector11T.hh:83
BaseObjectData::boundingBoxNode
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
Definition: BaseObjectData.cc:273
BaseObjectData::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObjectData.cc:331
ACG::SceneGraph::ACG::SceneGraph::BaseNode::Active
Draw node & children.
Definition: MeshNode2T.cc:368
StencilRefNode
ACG::SceneGraph::StencilRefNode StencilRefNode
Stencil reference Node.
Definition: BaseObjectData.hh:98
BaseObjectData::getBoundingBox
void getBoundingBox(ACG::Vec3d &bbmin, ACG::Vec3d &bbmax)
get the bounding box of the object
Definition: BaseObjectData.cc:289
ACG::SceneGraph::BoundingBoxAction::bbMin
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Definition: SceneGraph.hh:407
BaseObjectData::additionalNodes_
std::vector< std::pair< BaseNode *, QString > > additionalNodes_
Definition: BaseObjectData.hh:375
SceneGraph.hh
GlobalOptions.hh
ACG::SceneGraph::MaterialNode::specular_color
const Vec4f & specular_color() const
get the specular color
Definition: MaterialNode.hh:421
BaseObjectData::manipPlaced_
bool manipPlaced_
rootNode of global Scenegraph structure
Definition: BaseObjectData.hh:221
BaseObject::visibilityChanged
void visibilityChanged(int _objectId)
QtTranslationManipulatorNode
ACG::SceneGraph::QtTranslationManipulatorNode QtTranslationManipulatorNode
ManipulatorNode.
Definition: BaseObjectData.hh:90
OpenFlipperQSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: OpenFlipperQSettings.cc:53
BaseObjectData::manipulatorNode_
QtTranslationManipulatorNode * manipulatorNode_
Manipulator used for this Object.
Definition: BaseObjectData.hh:230
ACG::SceneGraph::StencilRefNode
Definition: StencilRefNode.hh:83
ACG::SceneGraph::ShaderNode
Definition: ShaderNode.hh:87
ACG::SceneGraph::BaseNode::HideNode
Hide this node, but draw children.
Definition: BaseNode.hh:370
BaseObjectData::initializeScenegraphNodes
void initializeScenegraphNodes()
Definition: BaseObjectData.cc:127
BaseObjectData::visible
virtual bool visible()
return visiblity
Definition: BaseObjectData.cc:212
BaseObjectData::materialNode_
MaterialNode * materialNode_
Scenegraph Material Node for the object.
Definition: BaseObjectData.hh:233
PluginFunctions.hh
BaseObjectData::boundingBoxNode_
BoundingBoxNode * boundingBoxNode_
Bounding box node for the object.
Definition: BaseObjectData.hh:236
BaseObject::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.cc:734
MaterialNode
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
Definition: BaseObjectData.hh:88
Types.hh
BaseObjectData::setObjectDrawMode
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
Definition: BaseObjectData.cc:300
BaseObject::child
BaseObject * child(int row)
return a child
Definition: BaseObject.cc:517
ACG::SceneGraph::MaterialNode
Definition: MaterialNode.hh:321
BaseObjectData.hh
ACG::SceneGraph::traverse
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
BaseObjectData::rootNode_
SeparatorNode * rootNode_
rootNode of global Scenegraph structure
Definition: BaseObjectData.hh:224
ACG::SceneGraph::BaseNode::childrenEnd
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:274
ACG::SceneGraph::BaseNode::find
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:322
BaseObjectData::picked
virtual bool picked(uint _node_idx)
detect if the node has been picked
Definition: BaseObjectData.cc:313