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 
58 
59 
60 //== DEFINES ==================================================================
61 
62 //== TYPEDEFS =================================================================
63 
64 //== CLASS DEFINITION =========================================================
65 
73  BaseObjectData( ),
74  planeNode_(nullptr),
75  textureNode_(nullptr)
76 {
78  init();
79 }
80 
81 //=============================================================================
82 
83 
88  BaseObjectData(_object)
89 {
90 
91  init( &_object.plane_ );
92 
93  setName( name() );
94 }
95 
100 {
101  // Delete the data attached to this object ( this will remove all perObject data)
102  // Not the best way to do it but it will work.
103  // This is only necessary if people use references to the plane below and
104  // they do something with the plane in the destructor of their
105  // perObjectData.
106  deleteData();
107 
108  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
109  planeNode_ = NULL;
110 }
111 
116 
118 
119  planeNode_ = NULL;
120 
122  setTypeIcon(DATA_PLANE,"PlaneType.png");
123 
124  init();
125 
126 }
127 
132  PlaneObject* object = new PlaneObject(*this);
133  return dynamic_cast< BaseObject* >(object);
134 }
135 
136 
138  return textureNode_;
139 }
140 
143 void PlaneObject::init(const Plane* _plane) {
144 
145  if ( materialNode() == NULL) {
146  std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
147  return;
148  }
149 
150  textureNode_ = new ACG::SceneGraph::EnvMapNode( materialNode() , "TextureNode for Plane" );
151  planeNode_ = new PlaneNode( plane_, textureNode() , "NEW PlaneNode" );
152 
153  if (_plane){
154  plane_ = *_plane;
155  } else {
156  plane_.setPlane( ACG::Vec3d(0.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0) );
157  plane_.setSize( 5.0, 5.0 );
158  }
159 
161 }
162 
163 // ===============================================================================
164 // Name/Path Handling
165 // ===============================================================================
166 
170 void PlaneObject::setName( QString _name ) {
172 
173  std::string nodename = std::string("PlaneNode for Plane " + _name.toUtf8() );
174  planeNode_->name( nodename );
175 }
176 
177 // ===============================================================================
178 // Visualization
179 // ===============================================================================
180 
182  return planeNode_;
183 }
184 
185 // ===============================================================================
186 // Object information
187 // ===============================================================================
188 
195  QString output;
196 
197  output += "========================================================================\n";
198  output += BaseObjectData::getObjectinfo();
199 
200  if ( dataType( DATA_PLANE ) )
201  output += "Object Contains Plane : ";
202 
203  ACG::Vec3d pos = planeNode_->position();
204  ACG::Vec3d nor = planeNode_->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 // Content
215 // ===============================================================================
216 
218  if (planeNode_)
219  planeNode_->update();
220 }
221 
222 // ===============================================================================
223 // Data
224 // ===============================================================================
225 
226 Plane& PlaneObject::plane() {
227  return plane_;
228 }
229 
230 void PlaneObject::plane(Plane _plane) {
231  plane_ = _plane;
232 }
233 
234 // ===============================================================================
235 // Picking
236 // ===============================================================================
237 
244 bool PlaneObject::picked( uint _node_idx ) {
245  return ( _node_idx == planeNode_->id() );
246 }
247 
248 void PlaneObject::enablePicking( bool _enable ) {
249  planeNode_->enablePicking( _enable );
250 }
251 
253  return planeNode_->pickingEnabled();
254 }
255 
256 //=============================================================================
257 
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
BaseObject * copy()
Definition: PlaneObject.cc:131
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
void setName(QString _name)
Set the name of the Object.
Definition: PlaneObject.cc:170
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
void update()
updates the plane before the next render call
Definition: PlaneNode.cc:465
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:181
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PlaneObject.cc:217
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PlaneObject.cc:248
virtual void cleanup() override
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:416
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PlaneObject.cc:252
Update type class.
Definition: UpdateType.hh:59
PlaneNode * planeNode_
Get the scenegraph Node.
Definition: PlaneObject.hh:163
MaterialNode * materialNode()
get a pointer to the materialnode
unsigned int id() const
Definition: BaseNode.hh:423
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PlaneObject.cc:194
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PlaneObject.cc:244
void setSize(double _xDirection, double _yDirection)
Set plane size.
Definition: PlaneType.cc:100
virtual void init(const Plane *_plane=0)
Initialize current object, including all related nodes.
Definition: PlaneObject.cc:143
virtual ~PlaneObject()
destructor
Definition: PlaneObject.cc:99
#define DATA_PLANE
Definition: Plane.hh:58
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PlaneObject.cc:115
ACG::SceneGraph::EnvMapNode * textureNode_
Get the scenegraph Node.
Definition: PlaneObject.hh:165
ACG::Vec3d normal()
get current normal
Definition: PlaneNode.cc:420
void setDataType(DataType _type)
Definition: BaseObject.cc:233
ACG::SceneGraph::EnvMapNode * textureNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:137
DataType dataType() const
Definition: BaseObject.cc:229
void set_point_size(float _sz)
set point size (default: 1.0)
PlaneObject()
constructor
Definition: PlaneObject.cc:72