Developer Documentation
PlaneObject.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 //=============================================================================
45 //
46 // Plane Object
47 //
48 //=============================================================================
49 
50 #define PLANEOBJECT_C
51 
52 //== INCLUDES =================================================================
53 
55 #include "Plane.hh"
56 
57 //== DEFINES ==================================================================
58 
59 //== TYPEDEFS =================================================================
60 
61 //== CLASS DEFINITION =========================================================
62 
70  BaseObjectData( ),
71  planeNode_(NULL)
72 {
74  init();
75 }
76 
77 //=============================================================================
78 
79 
84  BaseObjectData(_object)
85 {
86 
87  init( &_object.plane_ );
88 
89  setName( name() );
90 }
91 
96 {
97  // Delete the data attached to this object ( this will remove all perObject data)
98  // Not the best way to do it but it will work.
99  // This is only necessary if people use references to the plane below and
100  // they do something with the plane in the destructor of their
101  // perObjectData.
102  deleteData();
103 
104  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
105  planeNode_ = NULL;
106 }
107 
112 
114 
115  planeNode_ = NULL;
116 
118  setTypeIcon(DATA_PLANE,"PlaneType.png");
119 
120  init();
121 
122 }
123 
128  PlaneObject* object = new PlaneObject(*this);
129  return dynamic_cast< BaseObject* >(object);
130 }
131 
134 void PlaneObject::init(const Plane* _plane) {
135 
136  if ( materialNode() == NULL) {
137  std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
138  return;
139  }
140 
141  planeNode_ = new PlaneNode( plane_, materialNode() , "NEW PlaneNode" );
142 
143  if (_plane){
144  plane_ = *_plane;
145  } else {
146  plane_.setPlane( ACG::Vec3d(0.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0) );
147  plane_.setSize( 5.0, 5.0 );
148  }
149 
151 }
152 
153 // ===============================================================================
154 // Name/Path Handling
155 // ===============================================================================
156 
160 void PlaneObject::setName( QString _name ) {
162 
163  std::string nodename = std::string("PlaneNode for Plane " + _name.toUtf8() );
164  planeNode_->name( nodename );
165 }
166 
167 // ===============================================================================
168 // Visualization
169 // ===============================================================================
170 
172  return planeNode_;
173 }
174 
175 // ===============================================================================
176 // Object information
177 // ===============================================================================
178 
185  QString output;
186 
187  output += "========================================================================\n";
188  output += BaseObjectData::getObjectinfo();
189 
190  if ( dataType( DATA_PLANE ) )
191  output += "Object Contains Plane : ";
192 
193  ACG::Vec3d pos = planeNode_->position();
194  ACG::Vec3d nor = planeNode_->normal();
195 
196  output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
197  output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
198 
199  output += "========================================================================\n";
200  return output;
201 }
202 
203 // ===============================================================================
204 // Content
205 // ===============================================================================
206 
208  if (planeNode_)
209  planeNode_->update();
210 }
211 
212 // ===============================================================================
213 // Data
214 // ===============================================================================
215 
216 Plane& PlaneObject::plane() {
217  return plane_;
218 }
219 
220 void PlaneObject::plane(Plane _plane) {
221  plane_ = _plane;
222 }
223 
224 // ===============================================================================
225 // Picking
226 // ===============================================================================
227 
234 bool PlaneObject::picked( uint _node_idx ) {
235  return ( _node_idx == planeNode_->id() );
236 }
237 
238 void PlaneObject::enablePicking( bool _enable ) {
239  planeNode_->enablePicking( _enable );
240 }
241 
243  return planeNode_->pickingEnabled();
244 }
245 
246 //=============================================================================
247 
Update type class.
Definition: UpdateType.hh:60
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
void setSize(double _xDirection, double _yDirection)
Set plane size.
Definition: PlaneType.cc:100
PlaneNode * planeNode_
Get the scenegraph Node.
Definition: PlaneObject.hh:159
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PlaneObject.cc:234
MaterialNode * materialNode()
get a pointer to the materialnode
void setDataType(DataType _type)
Definition: BaseObject.cc:233
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PlaneObject.cc:207
virtual void cleanup()
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PlaneObject.cc:238
virtual void init(const Plane *_plane=0)
Initialize current object, including all related nodes.
Definition: PlaneObject.cc:134
PlaneObject()
constructor
Definition: PlaneObject.cc:69
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:171
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
#define DATA_PLANE
Definition: Plane.hh:58
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PlaneObject.cc:111
virtual ~PlaneObject()
destructor
Definition: PlaneObject.cc:95
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:258
void set_point_size(float _sz)
set point size (default: 1.0)
void update()
updates the plane before the next render call
Definition: PlaneNode.cc:323
BaseObject * copy()
Definition: PlaneObject.cc:127
ACG::Vec3d normal()
get current normal
Definition: PlaneNode.cc:265
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PlaneObject.cc:184
unsigned int id() const
Definition: BaseNode.hh:423
void setName(QString _name)
Set the name of the Object.
Definition: PlaneObject.cc:160
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PlaneObject.cc:242
DataType dataType() const
Definition: BaseObject.cc:229