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
LightObject.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 // Light Object
53 //
54 //=============================================================================
55
56 #define LIGHTOBJECT_C
57
58 //== INCLUDES =================================================================
59
60 #include <OpenFlipper/common/Types.hh>
61 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
62 #include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
63 #include "LightWidget.hh"
64
65 //== DEFINES ==================================================================
66
67 //== TYPEDEFS =================================================================
68
69 //== CLASS DEFINITION =========================================================
70
71 class LightWidgetGenerator : public ACG::QtWidgets::SceneGraphWidgetGenerator {
72 public:
73 // constructor
74 LightWidgetGenerator() {
75 }
76
77
78 virtual QWidget* getWidget(ACG::SceneGraph::BaseNode* _node ) {
79
80 // Check if we can handle this type
81 if ( ! canHandle( _node->className() ) )
82 return 0;
83
84 // Check if we already have a widget, otherwise generate a new one.
85 if ( widgetMap_.contains(_node) ) {
86 return widgetMap_[_node];
87 } else {
88 QWidget* widget = new LightWidget(_node);
89 widgetMap_[_node] = widget;
90 return widget;
91 }
92
93 }
94
95 virtual bool canHandle(std::string _className) {
96 return ( _className == std::string("LightNode") );
97 }
98
99 virtual std::string handles() {
100 return std::string("LightNode");
101 }
102
103 virtual QString contextMenuName() {
104 return QString("Edit Light");
105 }
106 };
107
108 static LightWidgetGenerator lightWidgetGenerator_;
109
113 LightObject::LightObject( ) :
114 BaseObjectData(),
115 lightNode_(0),
116 lightNodeVis_(0)
117 {
118 setDataType(DATA_LIGHT);
119 setTypeIcon(DATA_LIGHT,"LightType.png");
120 init();
121
122 // Make sure, the generator is added to the widget
123 PluginFunctions::addSceneGraphGenerator( &lightWidgetGenerator_ );
124 }
125
126 //=============================================================================
127
128
132 LightObject::LightObject(const LightObject & _object) :
133 BaseObjectData(_object),
134 defaultLightSource_(false)
135 {
136
137 init(_object.lightNode_);
138
139 setName( name() );
140 }
141
145 LightObject::~LightObject()
146 {
147 // Delete the data attached to this object ( this will remove all perObject data)
148 // Not the best way to do it but it will work.
149 // This is only necessary if people use references to the light below and
150 // they do something with the light in the destructor of their
151 // perObjectData.
152 deleteData();
153
154 // Move children to parent
155 BaseNode* parent = lightNode_->parent();
156
157 // First, collect all children as the iterator will get invalid if we delete while iterating!
158 std::vector< BaseNode*> children;
159 for (BaseNode::ChildIter cIt=lightNode_->childrenBegin(); cIt!=lightNode_->childrenEnd(); ++cIt)
160 children.push_back( (*cIt) );
161
162 // Move the children
163 for (unsigned int i = 0 ; i < children.size(); ++i )
164 children[i]->set_parent(parent);
165
166 // Delete the scenegraph node
167 delete lightNode_;
168 }
169
173 void LightObject::cleanup() {
174
175 BaseObjectData::cleanup();
176
177 lightNode_ = NULL;
178
179 setDataType(DATA_LIGHT);
180 setTypeIcon(DATA_LIGHT,"LightType.png");
181
182 init();
183
184 }
185
189 BaseObject* LightObject::copy() {
190 LightObject* object = new LightObject(*this);
191 return dynamic_cast< BaseObject* >(object);
192 }
193
196 void LightObject::init(LightNode* _light, LightNode* _lightVis) {
197
198 // Light nodes have to be on top of all other nodes.
199 lightNode_ = new LightNode( 0 , "LightNode");
200 lightNode_->visualize(false);
201 PluginFunctions::addGlobalStatusNode(lightNode_);
202
203 lightNodeVis_ = new LightNode( materialNode() , "LightNode Visualization");
204 lightNodeVis_->visualize(true);
205 lightNodeVis_->show();
206 }
207
208 // ===============================================================================
209 // Name/Path Handling
210 // ===============================================================================
211
215 void LightObject::setName( QString _name ) {
216 BaseObjectData::setName(_name);
217
218 std::string nodename = std::string("LightNode for Light " + _name.toUtf8() );
219 lightNode_->name( nodename );
220
221 std::string nodenameVis = std::string("LightNode Visualization for Light " + _name.toUtf8() );
222 lightNodeVis_->name( nodenameVis );
223 }
224
225 // ===============================================================================
226 // Visualization
227 // ===============================================================================
228
229 LightNode* LightObject::lightNode() {
230 return lightNode_;
231 }
232
233 LightNode* LightObject::lightNodeVis() {
234 return lightNodeVis_;
235 }
236
237 bool LightObject::hasNode(BaseNode* _node) {
238 if ( BaseObjectData::hasNode(_node) )
239 return true;
240
241 if ( _node == lightNode_ )
242 return true;
243
244 return false;
245 }
246
247 // ===============================================================================
248 // Object information
249 // ===============================================================================
250
256 QString LightObject::getObjectinfo() {
257 QString output;
258
259 output += "========================================================================\n";
260 output += BaseObjectData::getObjectinfo();
261
262 if ( dataType( DATA_LIGHT ) )
263 output += "Object Contains Light : ";
264
265 ACG::Vec3d pos = lightSource_.position();
266 // ACG::Vec3f nor = lightNode_->normal();
267
268 output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
269 // output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
270
271 output += "========================================================================\n";
272 return output;
273 }
274
275 // ===============================================================================
276 // Picking
277 // ===============================================================================
278
285 bool LightObject::picked( uint _node_idx ) {
286 return ( _node_idx == lightNode_->id() || _node_idx == lightNodeVis_->id() );
287 }
288
289 void LightObject::enablePicking( bool _enable ) {
290 lightNode_->enablePicking( _enable );
291 }
292
293 bool LightObject::pickingEnabled() {
294 return lightNode_->pickingEnabled();
295 }
296
297 void LightObject::show() {
298 if ( !visible_ ) {
299 BaseObjectData::show();
300 visible_ = true;
301
302 lightNodeVis_->visualize(true);
303
304 emit visibilityChanged( id() );
305 }
306 }
307
308 void LightObject::hide() {
309 if ( visible_ ) {
310 BaseObjectData::hide();
311 visible_ = false;
312
313 emit visibilityChanged( id() );
314 }
315 }
316
317 void LightObject::visible(bool _visible) {
318 if ( _visible )
319 show();
320 else
321 hide();
322 }
323
324 bool LightObject::visible() {
325 return visible_;
326 }
327
328 LightSource* LightObject::lightSource() {
329 return &lightSource_;
330 }
331
332 void LightObject::update(UpdateType _type) {
333
334 if(lightSource_.enabled()) {
335 lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::ALLPASSES);
336 lightNode_->set_status( ACG::SceneGraph::BaseNode::Active );
337 } else {
338 lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
339 lightNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
340 }
341
342 lightNode_->setLightSource(lightSource_);
343 lightNodeVis_->setLightSource(lightSource_);
344 }
345
346 //=============================================================================
347
ACG::SceneGraph::LightNode::visualize
bool visualize()
Should node be visualized?
Definition: LightNode.hh:296
ACG::SceneGraph::LightSource::enabled
bool enabled() const
Get light source status.
Definition: LightNode.cc:143
setTypeIcon
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
LightObject::lightSource_
LightSource lightSource_
Definition: LightObject.hh:136
BaseObject::parent
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:477
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
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
BaseObjectData
Definition: BaseObjectData.hh:105
ACG::SceneGraph::LightNode::setLightSource
void setLightSource(LightSource _light)
Set the light source parameters.
Definition: LightNode.hh:268
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
BaseObject::visible_
bool visible_
Definition: BaseObject.hh:286
LightObject::~LightObject
virtual ~LightObject()
destructor
Definition: LightObject.cc:145
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
LightObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: LightObject.cc:173
UpdateType
Update type class.
Definition: UpdateType.hh:70
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenEnd
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: MeshNode2T.cc:274
ACG::SceneGraph::ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: MeshNode2T.cc:245
ACG::SceneGraph::BaseNode::Active
Draw node & children.
Definition: BaseNode.hh:368
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:357
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
LightObject::lightNode
LightNode * lightNode()
Get the scenegraph Node.
Definition: LightObject.cc:229
LightNode
ACG::SceneGraph::LightNode LightNode
Simple Name for PlaneNode.
Definition: LightTypes.hh:75
LightObject
Definition: LightObject.hh:78
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
LightObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: LightObject.cc:293
BaseObjectData::hide
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
Definition: BaseObjectData.cc:203
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
LightObject::lightNodeVis_
LightNode * lightNodeVis_
Light rendering node (only for rendering purposes)
Definition: LightObject.hh:181
BaseObjectData::hasNode
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
Definition: BaseObjectData.cc:235
ACG::SceneGraph::BaseNode::className
virtual const std::string & className() const =0
Return class name (implemented by the ACG_CLASSNAME macro)
ACG::SceneGraph::BaseNode::ChildIter
std::list< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:262
ACG::SceneGraph::ACG::SceneGraph::BaseNode::set_status
void set_status(StatusMode _s)
Set the status of this node.
Definition: MeshNode2T.cc:379
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: MeshNode2T.cc:399
PluginFunctions::addGlobalStatusNode
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.
Definition: PluginFunctions.cc:969
BaseObject
Definition: BaseObject.hh:94
LightObject::lightSource
LightSource * lightSource()
Definition: LightObject.cc:328
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::ACG::SceneGraph::BaseNode::setMultipassStatus
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition: MeshNode2T.cc:481
LightWidgetGenerator::canHandle
virtual bool canHandle(std::string _className)
returns if the widgets can handle the given class
Definition: LightObject.cc:95
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
LightObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: LightObject.cc:215
LightObject::lightNode_
LightNode * lightNode_
Light status node.
Definition: LightObject.hh:178
ACG::SceneGraph::LightNode
Definition: LightNode.hh:255
LightObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: LightObject.cc:256
ACG::SceneGraph::ACG::SceneGraph::BaseNode::childrenBegin
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: MeshNode2T.cc:270
BaseObject::visibilityChanged
void visibilityChanged(int _objectId)
DATA_LIGHT
#define DATA_LIGHT
Definition: Light.hh:64
LightObject::visible
virtual bool visible()
Show Light Node.
Definition: LightObject.cc:324
PluginFunctions::addSceneGraphGenerator
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator *_generator)
Add a scenegraph generator ( the handled type will be extracted from the generator) ...
Definition: PluginFunctions.cc:1160
LightObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the Light Object.
Definition: LightObject.cc:332
ACG::SceneGraph::ACG::SceneGraph::BaseNode::show
void show()
Show node: set status to Active.
Definition: MeshNode2T.cc:383
ACG::SceneGraph::LightSource
Structure to hold options for one LightSource.
Definition: LightNode.hh:91
LightObject::LightObject
LightObject()
constructor
Definition: LightObject.cc:113
LightObject::hide
virtual void hide()
Hide Light Node.
Definition: LightObject.cc:308
LightWidget
Definition: LightWidget.hh:62
LightObject::lightNodeVis
LightNode * lightNodeVis()
Get the scenegraph Node.
Definition: LightObject.cc:233
ACG::SceneGraph::BaseNode::HideNode
Hide this node, but draw children.
Definition: BaseNode.hh:370
LightObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: LightObject.cc:285
PluginFunctions.hh
LightWidgetGenerator::getWidget
virtual QWidget * getWidget(ACG::SceneGraph::BaseNode *_node)
Get a widget for this Node.
Definition: LightObject.cc:78
LightObject::show
virtual void show()
Show Light Node.
Definition: LightObject.cc:297
LightObject::hasNode
virtual bool hasNode(BaseNode *_node)
Light status node.
Definition: LightObject.cc:237
Types.hh
ACG::QtWidgets::SceneGraphWidgetGenerator
Definition: QtSceneGraphWidget.hh:87
LightObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: LightObject.cc:289
LightWidgetGenerator::contextMenuName
virtual QString contextMenuName()
Return a name for your widget in the context menu.
Definition: LightObject.cc:103
LightWidgetGenerator::handles
virtual std::string handles()
return the type this generator handles
Definition: LightObject.cc:99
ACG::SceneGraph::LightSource::position
void position(Vec3d _pos)
Set position for LightSource.
Definition: LightNode.cc:114
LightObject::init
virtual void init(LightNode *_light=0, LightNode *_lightVis=0)
Initialize current object, including all related nodes.
Definition: LightObject.cc:196
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T.cc:241
LightWidgetGenerator
Definition: LightObject.cc:71
LightObject::copy
BaseObject * copy()
Definition: LightObject.cc:189
ACG::SceneGraph::ACG::SceneGraph::BaseNode::parent
BaseNode * parent()
Get the nodes parent node.
Definition: MeshNode2T.cc:348