Developer Documentation

CameraObject.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 * $Date$
46 *
47 \*===========================================================================*/
48
49
50
51
52
53 //=============================================================================
54 //
55 // MyTypes
56 //
57 //=============================================================================
58
59 #define CAMERAOBJECT_C
60
61 //== INCLUDES =================================================================
62
63 #include <OpenFlipper/common/Types.hh>
64 #include <ObjectTypes/Camera/Camera.hh>
65
66 #include <ACG/Scenegraph/MaterialNode.hh>
67
68 //== DEFINES ==================================================================
69
70 //== TYPEDEFS =================================================================
71
72 //== CLASS DEFINITION =========================================================
73
80 CameraObject::CameraObject( ) :
81 BaseObjectData( ),
82 cameraNode_(NULL)
83 {
84 setDataType(DATA_CAMERA);
85 init();
86 }
87
88 //=============================================================================
89
90
94 CameraObject::CameraObject(const CameraObject & _object) :
95 BaseObjectData(_object)
96 {
97
98 init(_object.cameraNode_);
99
100 setName( name() );
101 }
102
106 CameraObject::~CameraObject()
107 {
108 // Delete the data attached to this object ( this will remove all perObject data)
109 // Not the best way to do it but it will work.
110 // This is only necessary if people use references to the camera below and
111 // they do something with the camera in the destructor of their
112 // perObjectData.
113 deleteData();
114
115 // No need to delete the scenegraph Nodes as this will be managed by baseplugin
116 cameraNode_ = NULL;
117 }
118
122 void CameraObject::cleanup() {
123
124 BaseObjectData::cleanup();
125
126 cameraNode_ = NULL;
127
128 setDataType(DATA_CAMERA);
129
130 init();
131
132 }
133
137 BaseObject* CameraObject::copy() {
138 CameraObject* object = new CameraObject(*this);
139 return dynamic_cast< BaseObject* >(object);
140 }
141
144 void CameraObject::init(CameraNode* _camera) {
145
146 if ( materialNode() == NULL)
147 std::cerr << "Error when creating Camera Object! materialNode is NULL!" << std::endl;
148
149 cameraNode_ = new CameraNode( materialNode() , "NEW CameraNode");
150
151 // TODO: Set initial position
152
153 // if (_camera){
154 // cameraNode_->setPosition( _camera->position(), _camera->normal() );
155 // cameraNode_->setSize( _camera->xDirection().norm(), _camera->yDirection().norm() );
156 // } else {
157 // cameraNode_->setPosition( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
158 // cameraNode_->setSize( 5.0, 5.0 );
159 // }
160 }
161
162 // ===============================================================================
163 // Name/Path Handling
164 // ===============================================================================
165
169 void CameraObject::setName( QString _name ) {
170 BaseObjectData::setName(_name);
171
172 std::string nodename = std::string("CameraNode for Camera " + _name.toUtf8() );
173 cameraNode_->name( nodename );
174 }
175
176 // ===============================================================================
177 // Visualization
178 // ===============================================================================
179
180 CameraNode* CameraObject::cameraNode() {
181 return cameraNode_;
182 }
183
184 // ===============================================================================
185 // Object information
186 // ===============================================================================
187
193 QString CameraObject::getObjectinfo() {
194 QString output;
195
196 output += "========================================================================\n";
197 output += BaseObjectData::getObjectinfo();
198
199 if ( dataType( DATA_CAMERA ) )
200 output += "Object Contains Camera : ";
201
202 // TODO: Write correct data
203 // ACG::Vec3f pos = cameraNode_->position();
204 // ACG::Vec3f nor = cameraNode_->normal();
205 //
206 // output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
207 // output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
208
209 output += "========================================================================\n";
210 return output;
211 }
212
213 // ===============================================================================
214 // Picking
215 // ===============================================================================
216
223 bool CameraObject::picked( uint _node_idx ) {
224 return ( _node_idx == cameraNode_->id() );
225 }
226
227 void CameraObject::enablePicking( bool _enable ) {
228 cameraNode_->enablePicking( _enable );
229 }
230
231 bool CameraObject::pickingEnabled() {
232 return cameraNode_->pickingEnabled();
233 }
234
235 // ===============================================================================
236 // Update
237 // ===============================================================================
238
239
240 void CameraObject::update(UpdateType _type) {
241 BaseObject::update(_type);
242 }
243
244
245 //=============================================================================
246
CameraObject
Definition: CameraObject.hh:82
UpdateType
Update type class.
Definition: UpdateType.hh:60
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T_impl.hh:265
CameraObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: CameraObject.cc:240
CameraObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: CameraObject.cc:122
CameraObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: CameraObject.cc:193
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T_impl.hh:415
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
CameraObject::cameraNode_
CameraNode * cameraNode_
Get the scenegraph Node.
Definition: CameraObject.hh:131
BaseObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
CameraObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: CameraObject.cc:231
CameraObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: CameraObject.cc:169
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:102
CameraObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: CameraObject.cc:223
DATA_CAMERA
#define DATA_CAMERA
Definition: Camera.hh:67
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: MeshNode2T_impl.hh:423
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
CameraNode
ACG::SceneGraph::CameraNode CameraNode
Simple Name for CameraNode.
Definition: CameraTypes.hh:75
CameraObject::~CameraObject
virtual ~CameraObject()
destructor
Definition: CameraObject.cc:106
ACG::SceneGraph::CameraNode
Definition: CameraNode.hh:90
CameraObject::init
virtual void init(CameraNode *_plane=0)
Initialize current object, including all related nodes.
Definition: CameraObject.cc:144
CameraObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: CameraObject.cc:227
Types.hh
BaseObject
Definition: BaseObject.hh:82
CameraObject::cameraNode
CameraNode * cameraNode()
Get the scenegraph Node.
Definition: CameraObject.cc:180
ACG::SceneGraph::ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: MeshNode2T_impl.hh:269
CameraObject::CameraObject
CameraObject()
constructor
Definition: CameraObject.cc:80
CameraObject::copy
BaseObject * copy()
Definition: CameraObject.cc:137
Camera.hh
BaseObjectData
Definition: BaseObjectData.hh:102
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229