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
54 #include <OpenFlipper/common/Types.hh>
55 #include "Plane.hh"
56
57 //== DEFINES ==================================================================
58
59 //== TYPEDEFS =================================================================
60
61 //== CLASS DEFINITION =========================================================
62
69 PlaneObject::PlaneObject( ) :
70 BaseObjectData( ),
71 planeNode_(NULL)
72 {
73 setDataType(DATA_PLANE);
74 init();
75 }
76
77 //=============================================================================
78
79
83 PlaneObject::PlaneObject(const PlaneObject & _object) :
84 BaseObjectData(_object)
85 {
86
87 init( &_object.plane_ );
88
89 setName( name() );
90 }
91
95 PlaneObject::~PlaneObject()
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
111 void PlaneObject::cleanup() {
112
113 BaseObjectData::cleanup();
114
115 planeNode_ = NULL;
116
117 setDataType(DATA_PLANE);
118 setTypeIcon(DATA_PLANE,"PlaneType.png");
119
120 init();
121
122 }
123
127 BaseObject* PlaneObject::copy() {
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
150 materialNode()->set_point_size(3.0);
151 }
152
153 // ===============================================================================
154 // Name/Path Handling
155 // ===============================================================================
156
160 void PlaneObject::setName( QString _name ) {
161 BaseObjectData::setName(_name);
162
163 std::string nodename = std::string("PlaneNode for Plane " + _name.toUtf8() );
164 planeNode_->name( nodename );
165 }
166
167 // ===============================================================================
168 // Visualization
169 // ===============================================================================
170
171 PlaneNode* PlaneObject::planeNode() {
172 return planeNode_;
173 }
174
175 // ===============================================================================
176 // Object information
177 // ===============================================================================
178
184 QString PlaneObject::getObjectinfo() {
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
207 void PlaneObject::update(UpdateType _type) {
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
242 bool PlaneObject::pickingEnabled() {
243 return planeNode_->pickingEnabled();
244 }
245
246 //=============================================================================
247
UpdateType
Update type class.
Definition: UpdateType.hh:60
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
ACG::Geometry::Plane::setSize
void setSize(double _xDirection, double _yDirection)
Set plane size.
Definition: PlaneType.cc:100
PlaneObject::planeNode_
PlaneNode * planeNode_
Get the scenegraph Node.
Definition: PlaneObject.hh:159
PlaneObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PlaneObject.cc:234
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: BaseNode.hh:269
PlaneObject::update
void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PlaneObject.cc:207
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:102
PlaneObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PlaneObject.cc:238
PlaneObject::init
virtual void init(const Plane *_plane=0)
Initialize current object, including all related nodes.
Definition: PlaneObject.cc:134
PlaneObject::PlaneObject
PlaneObject()
constructor
Definition: PlaneObject.cc:69
PlaneObject::planeNode
PlaneNode * planeNode()
Get the scenegraph Node.
Definition: PlaneObject.cc:171
ACG::Geometry::Plane::setPlane
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
Definition: PlaneType.cc:48
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
PlaneObject
Definition: PlaneObject.hh:75
DATA_PLANE
#define DATA_PLANE
Definition: Plane.hh:58
setTypeIcon
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
PlaneObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PlaneObject.cc:111
PlaneObject::~PlaneObject
virtual ~PlaneObject()
destructor
Definition: PlaneObject.cc:95
ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
PlaneNode::position
ACG::Vec3d position()
get center position of the plane
Definition: PlaneNode.cc:258
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:486
Types.hh
BaseObject
Definition: BaseObject.hh:82
PlaneNode::update
void update()
updates the plane before the next render call
Definition: PlaneNode.cc:323
OpenMesh::VectorT
Definition: Vector11T.hh:83
PlaneNode
Definition: PlaneNode.hh:74
PlaneObject::copy
BaseObject * copy()
Definition: PlaneObject.cc:127
PlaneNode::normal
ACG::Vec3d normal()
get current normal
Definition: PlaneNode.cc:265
Plane.hh
PlaneObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PlaneObject.cc:184
BaseObjectData
Definition: BaseObjectData.hh:102
ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: BaseNode.hh:423
PlaneObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PlaneObject.cc:160
PlaneObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PlaneObject.cc:242
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229
ACG::Geometry::Plane
Definition: PlaneType.hh:50