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 
55 #include "PolyLineCollection.hh"
56 #include "PolyLineCollectionObject.hh"
57 
58 //== DEFINES ==================================================================
59 
60 //== TYPEDEFS =================================================================
61 
62 //== CLASS DEFINITION =========================================================
63 
71  BaseObjectData( ),
72  collection_(NULL),
73  collectionNode_(NULL)
74 {
76  init();
77 }
78 
79 //=============================================================================
80 
81 
86  BaseObjectData(_object)
87 {
88  init(_object.collection_);
89 
90  setName( name() );
91 }
92 
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 
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 
131 
132  collectionNode_ = NULL;
133 
135 
136  init();
137 
138 }
139 
145  return dynamic_cast< BaseObject* >(object);
146 }
147 
152 
153  if (_collection == 0)
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 
164 
165  // Set default material of the polyLine
170 
171 }
172 
173 // ===============================================================================
174 // Name/Path Handling
175 // ===============================================================================
176 
180 void PolyLineCollectionObject::setName( QString _name ) {
182 
183  std::string nodename = std::string("PolyLineCollectionNode for PolyLineCollection " + _name.toUtf8() );
184  collectionNode_->name( nodename );
185 }
186 
187 // ===============================================================================
188 // Content
189 // ===============================================================================
190 
195  return collection_;
196 }
197 
198 
200  if(_type == UPDATE_COLOR || _type == UPDATE_ALL){
201  collectionNode_->resetVBO();
202  }
203 
204  collectionNode_->update();
205 }
206 
207 // ===============================================================================
208 // Visualization
209 // ===============================================================================
210 
212  return collectionNode_;
213 }
214 
215 // ===============================================================================
216 // Object information
217 // ===============================================================================
218 
225  QString output;
226 
227  output += "========================================================================\n";
228  output += BaseObjectData::getObjectinfo();
229 
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 
254  collectionNode_->enablePicking( _enable );
255 }
256 
258  return collectionNode_->pickingEnabled();
259 }
260 
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 
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode()
Get the scenegraph Node.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void set_line_width(float _sz)
set line width (default: 1.0)
void set_random_color()
Generates a random color and sets it.
virtual void cleanup()
Reset current object, including all related nodes.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
virtual void cleanup() override
#define DATA_POLY_LINE_COLLECTION
void enablePicking(bool _enable)
Enable or disable picking for this Object.
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode_
Scenegraph Mesh Node.
virtual void init(PolyLineCollection *_collection=0)
Initialize current object, including all related nodes.
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.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
void setName(QString _name)
Set the name of the Object.
QString getObjectinfo()
Get all Info for the Object as a string.
Update type class.
Definition: UpdateType.hh:59
virtual ~PolyLineCollectionObject()
destructor
MaterialNode * materialNode()
get a pointer to the materialnode
PolyLineCollection * collection()
return a pointer to the line
void set_round_points(bool _b)
set round points enabled
bool picked(uint _node_idx)
detect if the node has been picked
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
void setDataType(DataType _type)
Definition: BaseObject.cc:233
PolyLineCollection * collection_
return a pointer to the line
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
DataType dataType() const
Definition: BaseObject.cc:229
void set_point_size(float _sz)
set point size (default: 1.0)