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
SphereObject.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 // Sphere Object
53 //
54 //=============================================================================
55
56 #define SPHEREOBJECT_C
57
58 //== INCLUDES =================================================================
59
60 #include <OpenFlipper/common/Types.hh>
61 #include "Sphere.hh"
62
63 //== DEFINES ==================================================================
64
65 //== TYPEDEFS =================================================================
66
67 //== CLASS DEFINITION =========================================================
68
75 SphereObject::SphereObject( ) :
76 BaseObjectData( ),
77 sphereNode_(NULL)
78 {
79 setDataType(DATA_SPHERE);
80 init();
81 }
82
83 //=============================================================================
84
85
89 SphereObject::SphereObject(const SphereObject & _object) :
90 BaseObjectData(_object)
91 {
92
93 init(_object.sphereNode_);
94
95 setName( name() );
96 }
97
101 SphereObject::~SphereObject()
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 sphereNode_ = NULL;
112 }
113
117 void SphereObject::cleanup() {
118
119 BaseObjectData::cleanup();
120
121 sphereNode_ = NULL;
122
123 setDataType(DATA_SPHERE);
124
125 init();
126
127 }
128
132 BaseObject* SphereObject::copy() {
133 SphereObject* object = new SphereObject(*this);
134 return dynamic_cast< BaseObject* >(object);
135 }
136
139 void SphereObject::init(SphereNode* _sphere) {
140
141 if ( materialNode() == NULL)
142 std::cerr << "Error when creating Sphere Object! materialNode is NULL!" << std::endl;
143
144 sphereNode_ = new SphereNode( SphereNode::SPHERE, materialNode() , "NEW SphereNode");
145
146
147 if (_sphere){
148 sphereNode_->get_primitive(0).position = _sphere->get_primitive(0).position;
149 sphereNode_->get_primitive(0).color = _sphere->get_primitive(0).color;
150 sphereNode_->get_primitive(0).size = _sphere->get_primitive(0).size;
151 sphereNode_->get_primitive(0).slices = _sphere->get_primitive(0).slices;
152 sphereNode_->get_primitive(0).stacks = _sphere->get_primitive(0).stacks;
153 sphereNode_->setColorInternal(false);
154 } else {
155 sphereNode_->get_primitive(0).position = ACG::Vec3f(0.0, 0.0, 0.0);
156 sphereNode_->get_primitive(0).size = 1.0;
157 sphereNode_->get_primitive(0).slices = 40;
158 sphereNode_->get_primitive(0).stacks = 40;
159 sphereNode_->get_primitive(0).color = ACG::Vec4f(0.5, 0.5, 0.5, 1.0);
160 sphereNode_->setColorInternal(false);
161 }
162
163 }
164
165 // ===============================================================================
166 // Name/Path Handling
167 // ===============================================================================
168
172 void SphereObject::setName( QString _name ) {
173 BaseObjectData::setName(_name);
174
175 std::string nodename = std::string("SphereNode for Sphere " + _name.toUtf8() );
176 sphereNode_->name( nodename );
177 }
178
179 // ===============================================================================
180 // Visualization
181 // ===============================================================================
182
183 SphereNode* SphereObject::sphereNode() {
184 return sphereNode_;
185 }
186
187 // ===============================================================================
188 // Object information
189 // ===============================================================================
190
196 QString SphereObject::getObjectinfo() {
197 QString output;
198
199 output += "========================================================================\n";
200 output += BaseObjectData::getObjectinfo();
201
202 if ( dataType( DATA_SPHERE ) )
203 output += "Object Contains Sphere : ";
204
205 ACG::Vec3d pos = sphereNode_->get_primitive(0).position;
206 double size = sphereNode_->get_primitive(0).size;
207
208 output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
209 output += " Size ( " + QString::number(size) + ")";
210
211 output += "========================================================================\n";
212 return output;
213 }
214
215 // ===============================================================================
216 // Picking
217 // ===============================================================================
218
225 bool SphereObject::picked( uint _node_idx ) {
226 return ( _node_idx == sphereNode_->id() );
227 }
228
229 void SphereObject::enablePicking( bool _enable ) {
230 sphereNode_->enablePicking( _enable );
231 }
232
233 bool SphereObject::pickingEnabled() {
234 return sphereNode_->pickingEnabled();
235 }
236
237 // ===============================================================================
238 // Update
239 // ===============================================================================
241 void SphereObject::update(UpdateType _type) {
242 BaseObject::update(_type);
243 }
244
245 //=============================================================================
246
ACG::SceneGraph::ACG::SceneGraph::BaseNode::name
std::string name() const
Returns: name of node (needs not be unique)
Definition: MeshNode2T.cc:391
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
DATA_SPHERE
#define DATA_SPHERE
Definition: Sphere.hh:64
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
BaseObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:756
ACG::SceneGraph::ACG::SceneGraph::BaseNode::pickingEnabled
bool pickingEnabled()
Definition: MeshNode2T.cc:245
SphereObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: SphereObject.cc:229
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
ACG::Vec4f
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:144
Sphere.hh
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
SphereObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: SphereObject.cc:233
SphereObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: SphereObject.cc:172
SphereObject::~SphereObject
virtual ~SphereObject()
destructor
Definition: SphereObject.cc:101
SphereObject::sphereNode
SphereNode * sphereNode()
Get the scenegraph Node.
Definition: SphereObject.cc:183
SphereObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: SphereObject.cc:196
ACG::SceneGraph::ACG::SceneGraph::BaseNode::id
unsigned int id() const
Definition: MeshNode2T.cc:399
SphereObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: SphereObject.cc:117
ACG::Vec3f
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
BaseObject
Definition: BaseObject.hh:94
OpenMesh::VectorT
Definition: Vector11T.hh:83
SphereObject
Definition: SphereObject.hh:79
SphereObject::SphereObject
SphereObject()
constructor
Definition: SphereObject.cc:75
SphereObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: SphereObject.cc:225
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
ACG::SceneGraph::GlutPrimitiveNode::get_primitive
Primitive & get_primitive(int _idx)
get a primitive
Definition: GlutPrimitiveNode.hh:203
SphereNode
ACG::SceneGraph::GlutPrimitiveNode SphereNode
Simple Name for SphereNode.
Definition: SphereTypes.hh:73
SphereObject::sphereNode_
SphereNode * sphereNode_
Get the scenegraph Node.
Definition: SphereObject.hh:128
SphereObject::copy
BaseObject * copy()
Definition: SphereObject.cc:132
ACG::SceneGraph::GlutPrimitiveNode::setColorInternal
void setColorInternal(bool _set)
Disable internal color processing.
Definition: GlutPrimitiveNode.hh:230
Types.hh
SphereObject::init
virtual void init(SphereNode *_sphere=0)
Initialise current object, including all related nodes.
Definition: SphereObject.cc:139
ACG::SceneGraph::ACG::SceneGraph::BaseNode::enablePicking
void enablePicking(bool _enable)
Definition: MeshNode2T.cc:241
ACG::SceneGraph::GlutPrimitiveNode
Definition: GlutPrimitiveNode.hh:88
SphereObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
Definition: SphereObject.cc:241