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 
65 
66 #include <ACG/Scenegraph/MaterialNode.hh>
67 
68 //== DEFINES ==================================================================
69 
70 //== TYPEDEFS =================================================================
71 
72 //== CLASS DEFINITION =========================================================
73 
81  BaseObjectData( ),
82  cameraNode_(NULL)
83 {
85  init();
86 }
87 
88 //=============================================================================
89 
90 
95  BaseObjectData(_object)
96 {
97 
98  init(_object.cameraNode_);
99 
100  setName( name() );
101 }
102 
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 
123 
125 
126  cameraNode_ = NULL;
127 
129 
130  init();
131 
132 }
133 
138  CameraObject* object = new CameraObject(*this);
139  return dynamic_cast< BaseObject* >(object);
140 }
141 
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 ) {
171 
172  std::string nodename = std::string("CameraNode for Camera " + _name.toUtf8() );
173  cameraNode_->name( nodename );
174 }
175 
176 // ===============================================================================
177 // Visualization
178 // ===============================================================================
179 
181  return cameraNode_;
182 }
183 
184 // ===============================================================================
185 // Object information
186 // ===============================================================================
187 
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 
232  return cameraNode_->pickingEnabled();
233 }
234 
235 // ===============================================================================
236 // Update
237 // ===============================================================================
238 
239 
241  BaseObject::update(_type);
242 }
243 
244 
245 //=============================================================================
246 
Update type class.
Definition: UpdateType.hh:60
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
virtual void cleanup()
Reset current object, including all related nodes.
QString getObjectinfo()
Get all Info for the Object as a string.
MaterialNode * materialNode()
get a pointer to the materialnode
void setDataType(DataType _type)
Definition: BaseObject.cc:233
std::string name() const
Returns: name of node (needs not be unique)
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
CameraNode * cameraNode_
Get the scenegraph Node.
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
bool pickingEnabled()
Check if picking is enabled for this Object.
void setName(QString _name)
Set the name of the Object.
virtual void cleanup()
bool picked(uint _node_idx)
detect if the node has been picked
#define DATA_CAMERA
Definition: Camera.hh:67
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
ACG::SceneGraph::CameraNode CameraNode
Simple Name for CameraNode.
Definition: CameraTypes.hh:75
virtual ~CameraObject()
destructor
virtual void init(CameraNode *_plane=0)
Initialize current object, including all related nodes.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
CameraNode * cameraNode()
Get the scenegraph Node.
CameraObject()
constructor
Definition: CameraObject.cc:80
BaseObject * copy()
DataType dataType() const
Definition: BaseObject.cc:229