Developer Documentation
 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"
66 
67 
68 
69 
70 //== TYPEDEFS =================================================================
71 
72 //== CLASS DEFINITION =========================================================
73 
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 {
86 }
87 
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 {
99 }
100 
102  if ( separatorNode_ != 0 ) {
104  }
105 
106 }
107 
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 {
115  separatorNode_ = 0;
116  manipulatorNode_ = 0;
117  materialNode_ = 0;
118  boundingBoxNode_ = 0;
119  additionalNodes_.clear();
120  }
121 
123 
125 }
126 
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
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");
147  }
148  if ( stencilRefNode_ == 0 )
149  {
150  stencilRefNode_ = new StencilRefNode(boundingBoxNode(), "New Stencil Reference");
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
186  }
187 }
188 
189 
190 // ===============================================================================
191 // Object visualization
192 // ===============================================================================
193 
195  if ( !visible_ ) {
197  visible_ = true;
198 
199  emit visibilityChanged( id() );
200  }
201 }
202 
204  if ( visible_ ) {
206  visible_ = false;
207 
208  emit visibilityChanged( id() );
209  }
210 }
211 
213  return visible_;
214 }
215 
216 void BaseObjectData::visible(bool _visible) {
217 
218  if ( visible_ != _visible ) {
219 
220  if (_visible)
222  else
224 
225  visible_ = _visible;
226 
227  emit visibilityChanged( id() );
228  }
229 }
230 
232  return separatorNode_;
233 }
234 
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 
258  return separatorNode_;
259 }
260 
262  return manipulatorNode_;
263 }
264 
266  return 0;
267 }
268 
270  return materialNode_;
271 }
272 
274  return boundingBoxNode_;
275 }
276 
278  return stencilRefNode_;
279 }
280 
282  return manipPlaced_;
283 }
284 
285 void BaseObjectData::manipPlaced( bool _placed ) {
286  manipPlaced_ = _placed;
287 }
288 
290 
291  // Single pass action, as the bounding box is not influenced by multipass traversal
294 
295 
296  bbmin = (ACG::Vec3d) act.bbMin();
297  bbmax = (ACG::Vec3d) act.bbMax();
298 }
299 
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 
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 // ===============================================================================
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 
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
ACG::SceneGraph::SeparatorNode SeparatorNode
Seperator Node.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:294
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
StencilRefNode * stencilRefNode_
Stencil reference node for the object.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
bool manipPlaced()
Check if the manipulator has been placed.
bool visible_
Definition: BaseObject.hh:286
QtTranslationManipulatorNode * manipulatorNode()
Update type class.
Definition: UpdateType.hh:70
ACG::SceneGraph::BoundingBoxNode BoundingBoxNode
Bounding box Node.
Draw node & children.
Definition: BaseNode.hh:368
virtual ~BaseObjectData()
destructor
Hide this node and its children.
Definition: BaseNode.hh:374
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
virtual bool pickingEnabled()
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
MaterialNode * materialNode()
get a pointer to the materialnode
void set_overlay_color(const Vec4f &_s)
set the overlay color
BaseObjectData()
constructor
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:270
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.
SeparatorNode * separatorNode_
Separator at top of Scenegraph structure used for this Object.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
void delete_subtree()
Delete the whole subtree of this node.
Definition: BaseNode.cc:176
virtual void cleanup()
void setIdentifier(int _id)
Set an identifier for that manipulator.
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
void set_base_color(const Vec4f &_c)
set the base color
bool hasAdditionalNode(QString _pluginName, QString _nodeName, int _id=0)
check if an object has the additional node
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
SeparatorNode * baseNode()
void set_status(StatusMode _s)
Set the status of this node.
Definition: MeshNode2T.cc:379
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Definition: SceneGraph.hh:409
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
virtual BaseNode * primaryNode()
virtual void cleanup()
Definition: BaseObject.cc:218
StencilRefNode * stencilRefNode()
get a pointer to the stencil reference node
virtual void enablePicking(bool _enable)
virtual ACG::SceneGraph::ShaderNode * shaderNode()
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
ACG::SceneGraph::StencilRefNode StencilRefNode
Stencil reference Node.
void getBoundingBox(ACG::Vec3d &bbmin, ACG::Vec3d &bbmax)
get the bounding box of the object
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Definition: SceneGraph.hh:407
std::vector< std::pair< BaseNode *, QString > > additionalNodes_
const Vec4f & specular_color() const
get the specular color
bool manipPlaced_
rootNode of global Scenegraph structure
void visibilityChanged(int _objectId)
ACG::SceneGraph::QtTranslationManipulatorNode QtTranslationManipulatorNode
ManipulatorNode.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
QtTranslationManipulatorNode * manipulatorNode_
Manipulator used for this Object.
Hide this node, but draw children.
Definition: BaseNode.hh:370
void initializeScenegraphNodes()
virtual bool visible()
return visiblity
MaterialNode * materialNode_
Scenegraph Material Node for the object.
BoundingBoxNode * boundingBoxNode_
Bounding box node for the object.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.cc:734
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
BaseObject * child(int row)
return a child
Definition: BaseObject.cc:517
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
SeparatorNode * rootNode_
rootNode of global Scenegraph structure
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:274
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:322
virtual bool picked(uint _node_idx)
detect if the node has been picked