Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 //=============================================================================
51 //
52 // Plane Object
53 //
54 //=============================================================================
55
56 #define PLANEOBJECT_C
57
58 //== INCLUDES =================================================================
59
60 #include <OpenFlipper/common/Types.hh>
61 #include "Plane.hh"
62
63 //== DEFINES ==================================================================
64
65 //== TYPEDEFS =================================================================
66
67 //== CLASS DEFINITION =========================================================
68
75 PlaneObject::PlaneObject( ) :
76 BaseObjectData( ),
77 planeNode_(NULL)
78 {
79 setDataType(DATA_PLANE);
80 init();
81 }
82
83 //=============================================================================
84
85
89 PlaneObject::PlaneObject(const PlaneObject & _object) :
90 BaseObjectData(_object)
91 {
92
93 init( &_object.plane_ );
94
95 setName( name() );
96 }
97
101 PlaneObject::~PlaneObject()
102 {
103 // Delete the data attached to this object ( this will remove all perObject data)
104 // Not the best way to do it but it will work.
105 // This is only necessary if people use references to the plane below and
106 // they do something with the plane in the destructor of their
107 // perObjectData.
108 deleteData();
109
110 // No need to delete the scenegraph Nodes as this will be managed by baseplugin
111 planeNode_ = NULL;
112 }
113
117 void PlaneObject::cleanup() {
118
119 BaseObjectData::cleanup();
120
121 planeNode_ = NULL;
122
123 setDataType(DATA_PLANE);
124 setTypeIcon(DATA_PLANE,"PlaneType.png");
125
126 init();
127
128 }
129
133 BaseObject* PlaneObject::copy() {
134 PlaneObject* object = new PlaneObject(*this);
135 return dynamic_cast< BaseObject* >(object);
136 }
137
140 void PlaneObject::init(const Plane* _plane) {
141
142 if ( materialNode() == NULL) {
143 std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
144 return;
145 }
146
147 planeNode_ = new PlaneNode( plane_, materialNode() , "NEW PlaneNode" );
148
149 if (_plane){
150 plane_ = *_plane;
151 } else {
152 plane_.setPlane( ACG::Vec3d(0.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0) );
153 plane_.setSize( 5.0, 5.0 );
154 }
155
156 materialNode()->set_point_size(3.0);
157 }
158
159 // ===============================================================================
160 // Name/Path Handling
161 // ===============================================================================
162
166 void PlaneObject::setName( QString _name ) {
167 BaseObjectData::setName(_name);
168
169 std::string nodename = std::string("PlaneNode for Plane " + _name.toUtf8() );
170 planeNode_->name( nodename );
171 }
172
173 // ===============================================================================
174 // Visualization
175 // ===============================================================================
176
177 PlaneNode* PlaneObject::planeNode() {
178 return planeNode_;
179 }
180
181 // ===============================================================================
182 // Object information
183 // ===============================================================================
184
190 QString PlaneObject::getObjectinfo() {
191 QString output;
192
193 output += "========================================================================\n";
194 output += BaseObjectData::getObjectinfo();
195
196 if ( dataType( DATA_PLANE ) )
197 output += "Object Contains Plane : ";
198
199 ACG::Vec3d pos = planeNode_->position();
200 ACG::Vec3d nor = planeNode_->normal();
201
202 output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
203 output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
204
205 output += "========================================================================\n";
206 return output;
207 }
208
209 // ===============================================================================
210 // Content
211 // ===============================================================================
212
213 void PlaneObject::update(UpdateType _type) {
214 if (planeNode_)
215 planeNode_->update();
216 }
217
218 // ===============================================================================
219 // Data
220 // ===============================================================================
221
222 Plane& PlaneObject::plane() {
223 return plane_;
224 }
225
226 void PlaneObject::plane(Plane _plane) {
227 plane_ = _plane;
228 }
229
230 // ===============================================================================
231 // Picking
232 // ===============================================================================
233
240 bool PlaneObject::picked( uint _node_idx ) {
241 return ( _node_idx == planeNode_->id() );
242 }
243
244 void PlaneObject::enablePicking( bool _enable ) {
245 planeNode_->enablePicking( _enable );
246 }
247
248 bool PlaneObject::pickingEnabled() {
249 return planeNode_->pickingEnabled();
250 }
251
252 //=============================================================================
253
DATA_PLANE
#define DATA_PLANE
Definition: Plane.hh:64
PlaneNode::position
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:258
setTypeIcon
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
PlaneObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PlaneObject.cc:166
ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: BaseNode.hh:399
PlaneObject::planeNode_
PlaneNode * planeNode_
Get the scenegraph Node.
Definition: PlaneObject.hh:162
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
UpdateType
Update type class.
Definition: UpdateType.hh:70
PlaneObject::copy
BaseObject * copy()
Definition: PlaneObject.cc:133
PlaneNode
Definition: PlaneNode.hh:74
PlaneObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PlaneObject.cc:248
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:357
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
PlaneObject::~PlaneObject
virtual ~PlaneObject()
destructor
Definition: PlaneObject.cc:101
Plane::setSize
void setSize(double _xDirection, double _yDirection)
Set plane size.
Definition: PlaneType.cc:108
Plane
Definition: PlaneType.hh:77
PlaneNode::update
void update()
updates the plane before the next render call
Definition: PlaneNode.cc:323
BaseObject
Definition: BaseObject.hh:94
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:454
ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:391
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: BaseNode.hh:245
PlaneObject::planeNode
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:177
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
PlaneObject::init
virtual void init(const Plane *_plane=0)
Initialize current object, including all related nodes.
Definition: PlaneObject.cc:140
ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: BaseNode.hh:241
PlaneNode::normal
ACG::Vec3d normal()
get current normal
Definition: PlaneNode.cc:265
Plane::setPlane
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:56
PlaneObject::PlaneObject
PlaneObject()
constructor
Definition: PlaneObject.cc:75
PlaneObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PlaneObject.cc:244
PlaneObject::update
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PlaneObject.cc:213
Plane.hh
Types.hh
PlaneObject
Definition: PlaneObject.hh:79
PlaneObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PlaneObject.cc:190
PlaneObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PlaneObject.cc:240
PlaneObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PlaneObject.cc:117