Developer Documentation
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 //=============================================================================
45 //
46 // Sphere Object
47 //
48 //=============================================================================
49 
50 #define SPHEREOBJECT_C
51 
52 //== INCLUDES =================================================================
53 
55 #include "Sphere.hh"
56 
57 #include <ACG/Scenegraph/GlutPrimitiveNode.hh>
58 #include <ACG/Scenegraph/MaterialNode.hh>
59 
60 //== DEFINES ==================================================================
61 
62 //== TYPEDEFS =================================================================
63 
64 //== CLASS DEFINITION =========================================================
65 
73  BaseObjectData( ),
74  sphereNode_(NULL)
75 {
77  init();
78 }
79 
80 //=============================================================================
81 
82 
87  BaseObjectData(_object)
88 {
89 
90  init(_object.sphereNode_);
91 
92  setName( name() );
93 }
94 
99 {
100  // Delete the data attached to this object ( this will remove all perObject data)
101  // Not the best way to do it but it will work.
102  // This is only necessary if people use references to the plane below and
103  // they do something with the plane in the destructor of their
104  // perObjectData.
105  deleteData();
106 
107  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
108  sphereNode_ = NULL;
109 }
110 
115 
117 
118  sphereNode_ = NULL;
119 
121 
122  init();
123 
124 }
125 
130  SphereObject* object = new SphereObject(*this);
131  return dynamic_cast< BaseObject* >(object);
132 }
133 
137 
138  if ( materialNode() == NULL)
139  std::cerr << "Error when creating Sphere Object! materialNode is NULL!" << std::endl;
140 
141  sphereNode_ = new SphereNode( SphereNode::SPHERE, materialNode() , "NEW SphereNode");
142 
143 
144  if (_sphere){
145  sphereNode_->get_primitive(0).position = _sphere->get_primitive(0).position;
146  sphereNode_->get_primitive(0).color = _sphere->get_primitive(0).color;
147  sphereNode_->get_primitive(0).size = _sphere->get_primitive(0).size;
148  sphereNode_->get_primitive(0).slices = _sphere->get_primitive(0).slices;
149  sphereNode_->get_primitive(0).stacks = _sphere->get_primitive(0).stacks;
151  } else {
152  sphereNode_->get_primitive(0).position = ACG::Vec3f(0.0, 0.0, 0.0);
153  sphereNode_->get_primitive(0).size = 1.0;
154  sphereNode_->get_primitive(0).slices = 40;
155  sphereNode_->get_primitive(0).stacks = 40;
156  sphereNode_->get_primitive(0).color = ACG::Vec4f(0.5, 0.5, 0.5, 1.0);
158  }
159 
160 }
161 
162 // ===============================================================================
163 // Name/Path Handling
164 // ===============================================================================
165 
169 void SphereObject::setName( QString _name ) {
171 
172  std::string nodename = std::string("SphereNode for Sphere " + _name.toUtf8() );
173  sphereNode_->name( nodename );
174 }
175 
176 // ===============================================================================
177 // Visualization
178 // ===============================================================================
179 
181  return sphereNode_;
182 }
183 
184 // ===============================================================================
185 // Object information
186 // ===============================================================================
187 
194  QString output;
195 
196  output += "========================================================================\n";
197  output += BaseObjectData::getObjectinfo();
198 
199  if ( dataType( DATA_SPHERE ) )
200  output += "Object Contains Sphere : ";
201 
202  ACG::Vec3d pos = sphereNode_->get_primitive(0).position;
203  double size = sphereNode_->get_primitive(0).size;
204 
205  output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
206  output += " Size ( " + QString::number(size) + ")";
207 
208  output += "========================================================================\n";
209  return output;
210 }
211 
212 // ===============================================================================
213 // Picking
214 // ===============================================================================
215 
222 bool SphereObject::picked( uint _node_idx ) {
223  return ( _node_idx == sphereNode_->id() );
224 }
225 
226 void SphereObject::enablePicking( bool _enable ) {
227  sphereNode_->enablePicking( _enable );
228 }
229 
231  return sphereNode_->pickingEnabled();
232 }
233 
234 // ===============================================================================
235 // Update
236 // ===============================================================================
239  BaseObject::update(_type);
240 }
241 
242 //=============================================================================
243 
Update type class.
Definition: UpdateType.hh:60
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
ACG::SceneGraph::GlutPrimitiveNode SphereNode
Simple Name for SphereNode.
Definition: SphereTypes.hh:67
BaseObject * copy()
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:119
Primitive & get_primitive(int _idx)
get a primitive
MaterialNode * materialNode()
get a pointer to the materialnode
void setDataType(DataType _type)
Definition: BaseObject.cc:233
virtual void init(SphereNode *_sphere=0)
Initialise current object, including all related nodes.
std::string name() const
Returns: name of node (needs not be unique)
virtual void cleanup()
Reset current object, including all related nodes.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
void enablePicking(bool _enable)
Enable or disable picking for this Object.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138
#define DATA_SPHERE
Definition: Sphere.hh:58
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
SphereNode * sphereNode()
Get the scenegraph Node.
virtual void cleanup()
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
void setName(QString _name)
Set the name of the Object.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
void setColorInternal(bool _set)
Disable internal color processing.
bool picked(uint _node_idx)
detect if the node has been picked
QString getObjectinfo()
Get all Info for the Object as a string.
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual ~SphereObject()
destructor
Definition: SphereObject.cc:98
SphereObject()
constructor
Definition: SphereObject.cc:72
DataType dataType() const
Definition: BaseObject.cc:229
SphereNode * sphereNode_
Get the scenegraph Node.