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