Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 //== DEFINES ==================================================================
67 
68 //== TYPEDEFS =================================================================
69 
70 //== CLASS DEFINITION =========================================================
71 
79  BaseObjectData( ),
80  cameraNode_(NULL)
81 {
83  init();
84 }
85 
86 //=============================================================================
87 
88 
93  BaseObjectData(_object)
94 {
95 
96  init(_object.cameraNode_);
97 
98  setName( name() );
99 }
100 
105 {
106  // Delete the data attached to this object ( this will remove all perObject data)
107  // Not the best way to do it but it will work.
108  // This is only necessary if people use references to the camera below and
109  // they do something with the camera in the destructor of their
110  // perObjectData.
111  deleteData();
112 
113  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
114  cameraNode_ = NULL;
115 }
116 
121 
123 
124  cameraNode_ = NULL;
125 
127 
128  init();
129 
130 }
131 
136  CameraObject* object = new CameraObject(*this);
137  return dynamic_cast< BaseObject* >(object);
138 }
139 
143 
144  if ( materialNode() == NULL)
145  std::cerr << "Error when creating Camera Object! materialNode is NULL!" << std::endl;
146 
147  cameraNode_ = new CameraNode( materialNode() , "NEW CameraNode");
148 
149  // TODO: Set initial position
150 
151 // if (_camera){
152 // cameraNode_->setPosition( _camera->position(), _camera->normal() );
153 // cameraNode_->setSize( _camera->xDirection().norm(), _camera->yDirection().norm() );
154 // } else {
155 // cameraNode_->setPosition( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
156 // cameraNode_->setSize( 5.0, 5.0 );
157 // }
158 }
159 
160 // ===============================================================================
161 // Name/Path Handling
162 // ===============================================================================
163 
167 void CameraObject::setName( QString _name ) {
169 
170  std::string nodename = std::string("CameraNode for Camera " + _name.toUtf8() );
171  cameraNode_->name( nodename );
172 }
173 
174 // ===============================================================================
175 // Visualization
176 // ===============================================================================
177 
179  return cameraNode_;
180 }
181 
182 // ===============================================================================
183 // Object information
184 // ===============================================================================
185 
192  QString output;
193 
194  output += "========================================================================\n";
195  output += BaseObjectData::getObjectinfo();
196 
197  if ( dataType( DATA_CAMERA ) )
198  output += "Object Contains Camera : ";
199 
200  // TODO: Write correct data
201 // ACG::Vec3f pos = cameraNode_->position();
202 // ACG::Vec3f nor = cameraNode_->normal();
203 //
204 // output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
205 // output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
206 
207  output += "========================================================================\n";
208  return output;
209 }
210 
211 // ===============================================================================
212 // Picking
213 // ===============================================================================
214 
221 bool CameraObject::picked( uint _node_idx ) {
222  return ( _node_idx == cameraNode_->id() );
223 }
224 
225 void CameraObject::enablePicking( bool _enable ) {
226  cameraNode_->enablePicking( _enable );
227 }
228 
230  return cameraNode_->pickingEnabled();
231 }
232 
233 // ===============================================================================
234 // Update
235 // ===============================================================================
236 
237 
239  BaseObject::update(_type);
240 }
241 
242 
243 //=============================================================================
244 
bool picked(uint _node_idx)
detect if the node has been picked
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
BaseObject * copy()
void setName(QString _name)
Set the name of the Object.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
Update type class.
Definition: UpdateType.hh:70
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:756
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
MaterialNode * materialNode()
get a pointer to the materialnode
virtual ~CameraObject()
destructor
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
DataType dataType() const
Definition: BaseObject.cc:240
virtual void cleanup()
ACG::SceneGraph::CameraNode CameraNode
Simple Name for CameraNode.
Definition: CameraTypes.hh:75
CameraNode * cameraNode_
Get the scenegraph Node.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
CameraNode * cameraNode()
Get the scenegraph Node.
CameraObject()
constructor
Definition: CameraObject.cc:78
virtual void cleanup()
Reset current object, including all related nodes.
void setDataType(DataType _type)
Definition: BaseObject.cc:244
#define DATA_CAMERA
Definition: Camera.hh:67
bool pickingEnabled()
Check if picking is enabled for this Object.
QString getObjectinfo()
Get all Info for the Object as a string.
virtual void init(CameraNode *_plane=0)
Initialize current object, including all related nodes.