Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 //=============================================================================
51 //
52 // MyTypes
53 //
54 //=============================================================================
55 
56 #define POLYLINECOLLECTIONOBJECT_C
57 
58 //== INCLUDES =================================================================
59 
61 #include "PolyLineCollection.hh"
62 #include "PolyLineCollectionObject.hh"
63 
64 //== DEFINES ==================================================================
65 
66 //== TYPEDEFS =================================================================
67 
68 //== CLASS DEFINITION =========================================================
69 
77  BaseObjectData( ),
78  collection_(NULL),
79  collectionNode_(NULL)
80 {
82  init();
83 }
84 
85 //=============================================================================
86 
87 
92  BaseObjectData(_object)
93 {
94  init(_object.collection_);
95 
96  setName( name() );
97 }
98 
103 {
104  // Delete the data attached to this object ( this will remove all perObject data)
105  // Not the best way to do it but it will work.
106  // This is only necessary if people use references to the line below and
107  // they do something with the polyline in the destructor of their
108  // perObjectData.
109  deleteData();
110 
111  // Delete the collection only, if this object contains a collection
112  if ( collection_ != NULL) {
113  delete collection_;
114  collection_ = NULL;
115  } else {
116  std::cerr << "Destructor error : Line Collection already deleted" << std::endl;
117  }
118 
119  // No need to delete the scenegraph Nodes as this will be managed by BasePlugin
120  collectionNode_ = NULL;
121 }
122 
127 
128  // Delete the Collection only, if this object contains a Collection
129  if ( collection_ != NULL) {
130  delete collection_;
131  collection_ = NULL;
132  } else {
133  std::cerr << "Cleanup error : Line already deleted" << std::endl;
134  }
135 
137 
138  collectionNode_ = NULL;
139 
141 
142  init();
143 
144 }
145 
151  return dynamic_cast< BaseObject* >(object);
152 }
153 
158 
159  if (_collection == 0)
161  else
162  collection_ = new PolyLineCollection(*_collection);
163 
164  // request default properties (managed by the polyline collection)
165 
166  if ( materialNode() == NULL)
167  std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl;
168 
170 
171  // Set default material of the polyLine
176 
177 }
178 
179 // ===============================================================================
180 // Name/Path Handling
181 // ===============================================================================
182 
186 void PolyLineCollectionObject::setName( QString _name ) {
188 
189  std::string nodename = std::string("PolyLineCollectionNode for PolyLineCollection " + _name.toUtf8() );
190  collectionNode_->name( nodename );
191 }
192 
193 // ===============================================================================
194 // Content
195 // ===============================================================================
196 
201  return collection_;
202 }
203 
204 
206  if(_type == UPDATE_COLOR || _type == UPDATE_ALL){
207  collectionNode_->resetVBO();
208  }
209 
210  collectionNode_->update();
211 }
212 
213 // ===============================================================================
214 // Visualization
215 // ===============================================================================
216 
218  return collectionNode_;
219 }
220 
221 // ===============================================================================
222 // Object information
223 // ===============================================================================
224 
231  QString output;
232 
233  output += "========================================================================\n";
234  output += BaseObjectData::getObjectinfo();
235 
237  output += "Object Contains PolyLineCollection : ";
238 
239  output += QString::number( collection()->n_polylines() ) + " polylines, ";
240 
241  output += "========================================================================\n";
242  return output;
243 }
244 
245 // ===============================================================================
246 // Picking
247 // ===============================================================================
248 
255 bool PolyLineCollectionObject::picked( uint _node_idx ) {
256  return ( _node_idx == collectionNode_->id() );
257 }
258 
260  collectionNode_->enablePicking( _enable );
261 }
262 
264  return collectionNode_->pickingEnabled();
265 }
266 
269  const ACG::Vec3d _hitPoint,
270  const ACG::Vec3d _start ,
271  const ACG::Vec3d _dir,
272  const size_t _targetIdx )
273 {
274  return _hitPoint;
275 }
276 
277 //=============================================================================
278 
virtual void cleanup()
Reset current object, including all related nodes.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
void set_point_size(float _sz)
set point size (default: 1.0)
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
void set_round_points(bool _b)
set round points enabled
ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start, const ACG::Vec3d _dir, const size_t _targetIdx)
Refine picking on triangle meshes.
virtual void cleanup()
Update type class.
Definition: UpdateType.hh:70
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode()
Get the scenegraph Node.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
MaterialNode * materialNode()
get a pointer to the materialnode
QString getObjectinfo()
Get all Info for the Object as a string.
DataType dataType() const
Definition: BaseObject.cc:240
bool picked(uint _node_idx)
detect if the node has been picked
void set_line_width(float _sz)
set line width (default: 1.0)
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
void setName(QString _name)
Set the name of the Object.
virtual void init(PolyLineCollection *_collection=0)
Initialize current object, including all related nodes.
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode_
Scenegraph Mesh Node.
PolyLineCollection * collection()
return a pointer to the line
#define DATA_POLY_LINE_COLLECTION
void setDataType(DataType _type)
Definition: BaseObject.cc:244
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void set_random_color()
Generates a random color and sets it.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
virtual ~PolyLineCollectionObject()
destructor
PolyLineCollection * collection_
return a pointer to the line
bool pickingEnabled()
Check if picking is enabled for this Object.