Developer Documentation
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),
94  materialNode_(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 
StencilRefNode * stencilRefNode()
get a pointer to the stencil reference node
ACG::SceneGraph::SeparatorNode SeparatorNode
Seperator Node.
bool manipPlaced_
rootNode of global Scenegraph structure
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:329
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:317
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
BoundingBoxNode * boundingBoxNode_
Bounding box node for the object.
bool hasAdditionalNode(QString _pluginName, QString _nodeName, int _id=0)
check if an object has the additional node
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
void initializeScenegraphNodes()
virtual void cleanup()
Draw node & children.
Definition: BaseNode.hh:423
virtual void cleanup()
Definition: BaseObject.cc:218
Hide this node and its children.
Definition: BaseNode.hh:429
void delete_subtree()
Delete the whole subtree of this node.
Definition: BaseNode.cc:176
void getBoundingBox(ACG::Vec3d &bbmin, ACG::Vec3d &bbmax)
get the bounding box of the object
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
MaterialNode * materialNode_
Scenegraph Material Node for the object.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:377
virtual bool visible()
return visiblity
void setIdentifier(int _id)
Set an identifier for that manipulator.
ACG::SceneGraph::StencilRefNode StencilRefNode
Stencil reference Node.
const Vec3d & bbMin() const
Returns minimum point of the bounding box.
Definition: SceneGraph.hh:407
QtTranslationManipulatorNode * manipulatorNode()
SeparatorNode * rootNode_
rootNode of global Scenegraph structure
virtual BaseNode * primaryNode()
virtual bool picked(uint _node_idx)
detect if the node has been picked
Update type class.
Definition: UpdateType.hh:70
MaterialNode * materialNode()
get a pointer to the materialnode
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
virtual bool pickingEnabled()
SeparatorNode * baseNode()
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
QtTranslationManipulatorNode * manipulatorNode_
Manipulator used for this Object.
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Hide this node, but draw children.
Definition: BaseNode.hh:425
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:325
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
BaseObjectData()
constructor
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
BaseObject * child(int row)
return a child
Definition: BaseObject.cc:517
void set_overlay_color(const Vec4f &_s)
set the overlay color
void visibilityChanged(int _objectId)
SeparatorNode * separatorNode_
Separator at top of Scenegraph structure used for this Object.
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:446
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
ACG::SceneGraph::BoundingBoxNode BoundingBoxNode
Bounding box Node.
virtual void enablePicking(bool _enable)
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.
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:349
const Vec3d & bbMax() const
Returns maximum point of the bounding box.
Definition: SceneGraph.hh:409
bool manipPlaced()
Check if the manipulator has been placed.
void set_color(const Vec4f &_c)
set color (base, ambient, diffuse, specular) based on _c
ACG::SceneGraph::QtTranslationManipulatorNode QtTranslationManipulatorNode
ManipulatorNode.
std::vector< std::pair< BaseNode *, QString > > additionalNodes_
virtual ~BaseObjectData()
destructor
void set_base_color(const Vec4f &_c)
set the base color
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
const Vec4f & specular_color() const
get the specular color
void set_status(StatusMode _s)
Set the status of this node.
Definition: MeshNode2T.cc:434
virtual ACG::SceneGraph::ShaderNode * shaderNode()
bool visible_
Definition: BaseObject.hh:286
StencilRefNode * stencilRefNode_
Stencil reference 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