Developer Documentation

PolyLineCollectionObject.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 // MyTypes
47 //
48 //=============================================================================
49
50 #define POLYLINECOLLECTIONOBJECT_C
51
52 //== INCLUDES =================================================================
53
54 #include <OpenFlipper/common/Types.hh>
55 #include "PolyLineCollection.hh"
56 #include "PolyLineCollectionObject.hh"
57
58 //== DEFINES ==================================================================
59
60 //== TYPEDEFS =================================================================
61
62 //== CLASS DEFINITION =========================================================
63
70 PolyLineCollectionObject::PolyLineCollectionObject() :
71 BaseObjectData( ),
72 collection_(NULL),
73 collectionNode_(NULL)
74 {
75 setDataType(DATA_POLY_LINE_COLLECTION);
76 init();
77 }
78
79 //=============================================================================
80
81
85 PolyLineCollectionObject::PolyLineCollectionObject(const PolyLineCollectionObject & _object) :
86 BaseObjectData(_object)
87 {
88 init(_object.collection_);
89
90 setName( name() );
91 }
92
96 PolyLineCollectionObject::~PolyLineCollectionObject()
97 {
98 // Delete the data attached to this object ( this will remove all perObject data)
99 // Not the best way to do it but it will work.
100 // This is only necessary if people use references to the line below and
101 // they do something with the polyline in the destructor of their
102 // perObjectData.
103 deleteData();
104
105 // Delete the collection only, if this object contains a collection
106 if ( collection_ != NULL) {
107 delete collection_;
108 collection_ = NULL;
109 } else {
110 std::cerr << "Destructor error : Line Collection already deleted" << std::endl;
111 }
112
113 // No need to delete the scenegraph Nodes as this will be managed by BasePlugin
114 collectionNode_ = NULL;
115 }
116
120 void PolyLineCollectionObject::cleanup() {
121
122 // Delete the Collection only, if this object contains a Collection
123 if ( collection_ != NULL) {
124 delete collection_;
125 collection_ = NULL;
126 } else {
127 std::cerr << "Cleanup error : Line already deleted" << std::endl;
128 }
129
130 BaseObjectData::cleanup();
131
132 collectionNode_ = NULL;
133
134 setDataType(DATA_POLY_LINE_COLLECTION);
135
136 init();
137
138 }
139
143 BaseObject* PolyLineCollectionObject::copy() {
144 PolyLineCollectionObject* object = new PolyLineCollectionObject(*this);
145 return dynamic_cast< BaseObject* >(object);
146 }
147
151 void PolyLineCollectionObject::init(PolyLineCollection* _collection) {
152
153 if (_collection == 0)
154 collection_ = new PolyLineCollection();
155 else
156 collection_ = new PolyLineCollection(*_collection);
157
158 // request default properties (managed by the polyline collection)
159
160 if ( materialNode() == NULL)
161 std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl;
162
163 collectionNode_ = new ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection >(*collection_, materialNode() , "NEW PolyLineCollection");
164
165 // Set default material of the polyLine
166 materialNode()->set_random_color();
167 materialNode()->set_line_width(3.0);
168 materialNode()->set_point_size(8.0);
169 materialNode()->set_round_points(true);
170
171 }
172
173 // ===============================================================================
174 // Name/Path Handling
175 // ===============================================================================
176
180 void PolyLineCollectionObject::setName( QString _name ) {
181 BaseObjectData::setName(_name);
182
183 std::string nodename = std::string("PolyLineCollectionNode for PolyLineCollection " + _name.toUtf8() );
184 collectionNode_->name( nodename );
185 }
186
187 // ===============================================================================
188 // Content
189 // ===============================================================================
190
194 PolyLineCollection* PolyLineCollectionObject::collection() {
195 return collection_;
196 }
197
198
199 void PolyLineCollectionObject::update(UpdateType _type) {
200 if(_type == UPDATE_COLOR || _type == UPDATE_ALL){
201 collectionNode_->resetVBO();
202 }
203
204 collectionNode_->update();
205 }
206
207 // ===============================================================================
208 // Visualization
209 // ===============================================================================
210
211 ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection >* PolyLineCollectionObject::collectionNode() {
212 return collectionNode_;
213 }
214
215 // ===============================================================================
216 // Object information
217 // ===============================================================================
218
224 QString PolyLineCollectionObject::getObjectinfo() {
225 QString output;
226
227 output += "========================================================================\n";
228 output += BaseObjectData::getObjectinfo();
229
230 if ( dataType( DATA_POLY_LINE_COLLECTION ) )
231 output += "Object Contains PolyLineCollection : ";
232
233 output += QString::number( collection()->n_polylines() ) + " polylines, ";
234
235 output += "========================================================================\n";
236 return output;
237 }
238
239 // ===============================================================================
240 // Picking
241 // ===============================================================================
242
249 bool PolyLineCollectionObject::picked( uint _node_idx ) {
250 return ( _node_idx == collectionNode_->id() );
251 }
252
253 void PolyLineCollectionObject::enablePicking( bool _enable ) {
254 collectionNode_->enablePicking( _enable );
255 }
256
257 bool PolyLineCollectionObject::pickingEnabled() {
258 return collectionNode_->pickingEnabled();
259 }
260
262 ACG::Vec3d PolyLineCollectionObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget,
263 const ACG::Vec3d _hitPoint,
264 const ACG::Vec3d _start ,
265 const ACG::Vec3d _dir,
266 const unsigned int _targetIdx )
267 {
268 return _hitPoint;
269 }
270
271 //=============================================================================
272
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
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyLineCollectionObject::~PolyLineCollectionObject
virtual ~PolyLineCollectionObject()
destructor
Definition: PolyLineCollectionObject.cc:96
ACG::SceneGraph::MaterialNode::set_round_points
void set_round_points(bool _b)
set round points enabled
Definition: MaterialNode.hh:496
PolyLineCollectionObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PolyLineCollectionObject.cc:253
PolyLineCollectionObject::copy
BaseObject * copy()
Definition: PolyLineCollectionObject.cc:143
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
PolyLineCollectionObject::collectionNode_
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode_
Scenegraph Mesh Node.
Definition: PolyLineCollectionObject.hh:152
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:102
PolyLineCollectionObject
Definition: PolyLineCollectionObject.hh:74
PolyLineCollection.hh
PolyLineCollectionObject::collectionNode
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode()
Get the scenegraph Node.
Definition: PolyLineCollectionObject.cc:211
PolyLineCollectionObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PolyLineCollectionObject.cc:199
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
ACG::SceneGraph::MaterialNode::set_line_width
void set_line_width(float _sz)
set line width (default: 1.0)
Definition: MaterialNode.hh:491
ACG::SceneGraph::PolyLineCollectionNodeT
Definition: PolyLineCollectionNodeT.hh:76
ACG::SceneGraph::MaterialNode::set_random_color
void set_random_color()
Generates a random color and sets it.
Definition: MaterialNode.hh:416
PolyLineCollectionObject::collection
PolyLineCollection * collection()
return a pointer to the line
Definition: PolyLineCollectionObject.cc:194
PolyLineCollectionObject::init
virtual void init(PolyLineCollection *_collection=0)
Initialize current object, including all related nodes.
Definition: PolyLineCollectionObject.cc:151
DATA_POLY_LINE_COLLECTION
#define DATA_POLY_LINE_COLLECTION
Definition: PolyLineCollection.hh:63
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:486
Types.hh
PolyLineCollectionT
Definition: PolyLineCollectionT.hh:49
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
BaseObject
Definition: BaseObject.hh:82
PolyLineCollectionObject::PolyLineCollectionObject
PolyLineCollectionObject()
constructor
Definition: PolyLineCollectionObject.cc:70
PolyLineCollectionObject::collection_
PolyLineCollection * collection_
return a pointer to the line
Definition: PolyLineCollectionObject.hh:135
OpenMesh::VectorT
Definition: Vector11T.hh:83
PolyLineCollectionObject::refinePick
ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start, const ACG::Vec3d _dir, const unsigned int _targetIdx)
Refine picking on triangle meshes.
Definition: PolyLineCollectionObject.cc:262
PolyLineCollectionObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PolyLineCollectionObject.cc:257
PolyLineCollectionObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PolyLineCollectionObject.cc:249
BaseObjectData
Definition: BaseObjectData.hh:102
UPDATE_COLOR
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
PolyLineCollectionObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PolyLineCollectionObject.cc:180
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229
PolyLineCollectionObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PolyLineCollectionObject.cc:120
PolyLineCollectionObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PolyLineCollectionObject.cc:224