Developer Documentation
Loading...
Searching...
No Matches
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
72 collection_(nullptr),
73 collectionNode_(nullptr)
74{
76 init();
77}
78
79//=============================================================================
80
81
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_ != nullptr) {
107 delete collection_;
108 collection_ = nullptr;
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_ = nullptr;
115}
116
121
122 // Delete the Collection only, if this object contains a Collection
123 if ( collection_ != nullptr) {
124 delete collection_;
125 collection_ = nullptr;
126 } else {
127 std::cerr << "Cleanup error : Line already deleted" << std::endl;
128 }
129
131
132 collectionNode_ = nullptr;
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() == nullptr)
161 std::cerr << "Error when creating Line Object! materialNode is nullptr!" << std::endl;
162
164
165 // Set default material of the polyLine
170
171}
172
173// ===============================================================================
174// Name/Path Handling
175// ===============================================================================
176
182
183 std::string nodename = std::string("PolyLineCollectionNode for PolyLineCollection " + _name.toUtf8() );
184 collectionNode_->name( nodename );
185}
186
187// ===============================================================================
188// Content
189// ===============================================================================
190
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
214
215// ===============================================================================
216// Object information
217// ===============================================================================
218
225 QString output;
226
227 output += "========================================================================\n";
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
249bool 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
#define DATA_POLY_LINE_COLLECTION
void set_random_color()
Generates a random color and sets it.
void set_round_points(bool _b)
set round points enabled
void set_line_width(float _sz)
set line width (default: 1.0)
void set_point_size(float _sz)
set point size (default: 1.0)
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
MaterialNode * materialNode()
get a pointer to the materialnode
virtual void cleanup() override
virtual QString getObjectinfo()
Get all Info for the Object as a string.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
void setDataType(DataType _type)
void deleteData()
Delete all data attached to this object ( calls delete on each object )
DataType dataType() const
bool pickingEnabled()
Check if picking is enabled for this Object.
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.
PolyLineCollection * collection_
return a pointer to the line
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode_
Scenegraph Mesh Node.
void setName(QString _name)
Set the name of the Object.
virtual void init(PolyLineCollection *_collection=0)
Initialize current object, including all related nodes.
void enablePicking(bool _enable)
Enable or disable picking for this Object.
virtual void cleanup()
Reset current object, including all related nodes.
bool picked(uint _node_idx)
detect if the node has been picked
QString getObjectinfo()
Get all Info for the Object as a string.
virtual ~PolyLineCollectionObject()
destructor
ACG::SceneGraph::PolyLineCollectionNodeT< PolyLineCollection > * collectionNode()
Get the scenegraph Node.
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
PolyLineCollection * collection()
return a pointer to the line
Update type class.
Definition UpdateType.hh:59
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
PickTarget
What target to use for picking.
Definition PickTarget.hh:74