Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PolyLineObject.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 POLYLINEOBJECT_C
57
58 //== INCLUDES =================================================================
59
60 #include <OpenFlipper/common/Types.hh>
61 #include "PolyLine.hh"
62
63 //== DEFINES ==================================================================
64
65 //== TYPEDEFS =================================================================
66
67 //== CLASS DEFINITION =========================================================
68
75 PolyLineObject::PolyLineObject() :
76 BaseObjectData( ),
77 line_(NULL),
78 lineNode_(NULL)
79 {
80 setDataType(DATA_POLY_LINE);
81 init();
82 }
83
84 //=============================================================================
85
86
90 PolyLineObject::PolyLineObject(const PolyLineObject & _object) :
91 BaseObjectData(_object)
92 {
93
94 init(_object.line_);
95
96 setName( name() );
97 }
98
102 PolyLineObject::~PolyLineObject()
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 Mesh only, if this object contains a mesh
112 if ( line_ != NULL) {
113 delete line_;
114 line_ = NULL;
115 } else {
116 std::cerr << "Destructor error : Line already deleted" << std::endl;
117 }
118
119 // No need to delete the scenegraph Nodes as this will be managed by baseplugin
120 lineNode_ = NULL;
121 }
122
126 void PolyLineObject::cleanup() {
127 // Delete the Line only, if this object contains a line
128 if ( line_ != NULL) {
129 delete line_;
130 line_ = NULL;
131 } else {
132 std::cerr << "Cleanup error : Line already deleted" << std::endl;
133 }
134
135 BaseObjectData::cleanup();
136
137 lineNode_ = NULL;
138
139 setDataType(DATA_POLY_LINE);
140
141 init();
142
143 }
144
148 BaseObject* PolyLineObject::copy() {
149 PolyLineObject* object = new PolyLineObject(*this);
150 return dynamic_cast< BaseObject* >(object);
151 }
152
156 void PolyLineObject::init(PolyLine* _line) {
157
158 if (_line == 0)
159 line_ = new PolyLine();
160 else
161 line_ = new PolyLine(*_line);
162
163 // request default properties
164 line()->request_vertex_selections();
165 line()->request_edge_selections();
166 line()->request_vertex_vhandles();
167 line()->request_vertex_ehandles();
168 line()->request_vertex_fhandles();
169
170
171 if ( materialNode() == NULL)
172 std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl;
173
174 lineNode_ = new ACG::SceneGraph::PolyLineNodeT< PolyLine >(*line_, materialNode() , "NEW LineNode");
175
176 // Set default material of the polyLine
177 materialNode()->set_random_color();
178 materialNode()->set_line_width(3.0);
179 materialNode()->set_point_size(8.0);
180 materialNode()->set_round_points(true);
181
182 }
183
184 // ===============================================================================
185 // Name/Path Handling
186 // ===============================================================================
187
191 void PolyLineObject::setName( QString _name ) {
192 BaseObjectData::setName(_name);
193
194 std::string nodename = std::string("LineNode for Line " + _name.toUtf8() );
195 lineNode_->name( nodename );
196 }
197
198 // ===============================================================================
199 // Content
200 // ===============================================================================
201
205 PolyLine* PolyLineObject::line() {
206 return line_;
207 }
208
209
210 void PolyLineObject::update(UpdateType _type) {
211 lineNode_->update();
212 }
213
214 // ===============================================================================
215 // Visualization
216 // ===============================================================================
217
218 ACG::SceneGraph::PolyLineNodeT< PolyLine >* PolyLineObject::lineNode() {
219 return lineNode_;
220 }
221
222 // ===============================================================================
223 // Object information
224 // ===============================================================================
225
231 QString PolyLineObject::getObjectinfo() {
232 QString output;
233
234 output += "========================================================================\n";
235 output += BaseObjectData::getObjectinfo();
236
237 if ( dataType( DATA_POLY_LINE ) )
238 output += "Object Contains PolyLine : ";
239
240 output += QString::number( line()->n_vertices() ) + " vertices, ";
241 output += QString::number( line()->n_edges() ) += " edges and is ";
242 if ( line()->is_closed() )
243 output += "closed.\n";
244 else
245 output += "open.\n";
246
247 output += "========================================================================\n";
248 return output;
249 }
250
251 // ===============================================================================
252 // Picking
253 // ===============================================================================
254
261 bool PolyLineObject::picked( uint _node_idx ) {
262 return ( _node_idx == lineNode_->id() );
263 }
264
265 void PolyLineObject::enablePicking( bool _enable ) {
266 lineNode_->enablePicking( _enable );
267 }
268
269 bool PolyLineObject::pickingEnabled() {
270 return lineNode_->pickingEnabled();
271 }
272
274 ACG::Vec3d PolyLineObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget,
275 const ACG::Vec3d _hitPoint,
276 const ACG::Vec3d _start ,
277 const ACG::Vec3d _dir,
278 const unsigned int _targetIdx )
279 {
280 if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
281 //don't refine polyLine faces
282 return _hitPoint;
283 }
284
285 if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
286 // get picked edge handle
287
288 int eh;
289
290 eh = _targetIdx;
291
292
293 if(eh >= 0 && eh < (int)line()->n_edges())
294 {
295 //get vertices of the edge
296 ACG::Vec3d edgeStart = line()->point((eh+1)%line()->n_vertices());
297 ACG::Vec3d edgeEnd = line()->point(eh);
298
299 //retrieve the point on the edge that is closest to the backprojected hitpoint
300 ACG::Vec3d hitPointNew;
301 ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
302
303
304 return hitPointNew;
305 }
306 }
307
308 if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
309 // get picked vertex handle
310 int vh = _targetIdx;
311 if(vh>=0 && vh < (int)line()->n_vertices())
312 {
313 ACG::Vec3d hitpointNew = line()->point(vh);
314
315 //just return the vertex position
316 return hitpointNew;
317 }
318 }
319
320 return _hitPoint;
321 }
322
323 //=============================================================================
PolyLine.hh
PolyLineObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PolyLineObject.cc:265
PolyLineObject::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: PolyLineObject.cc:274
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
PolyLine
ACG::PolyLineT< ACG::Vec3d > PolyLine
Simple Name for PolyLine.
Definition: PolyLineTypes.hh:72
DATA_POLY_LINE
#define DATA_POLY_LINE
Definition: PolyLine.hh:70
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
ACG::PolyLineT
Definition: PolyLineT.hh:90
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
UpdateType
Update type class.
Definition: UpdateType.hh:70
ACG::SceneGraph::MaterialNode::set_random_color
void set_random_color()
Generates a random color and sets it.
Definition: MaterialNode.hh:399
BaseObjectData::setName
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:357
PolyLineObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PolyLineObject.cc:126
PolyLineObject::lineNode_
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode_
Scenegraph Mesh Node.
Definition: PolyLineObject.hh:176
PolyLineObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PolyLineObject.cc:191
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:269
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:240
PolyLineObject
Definition: PolyLineObject.hh:82
BaseObjectData::cleanup
virtual void cleanup()
Definition: BaseObjectData.cc:108
PolyLineObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PolyLineObject.cc:269
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
ACG::SceneGraph::PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
PolyLineObject::PolyLineObject
PolyLineObject()
constructor
Definition: PolyLineObject.cc:75
PolyLineObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PolyLineObject.cc:261
PolyLineObject::init
virtual void init(PolyLine *_line=0)
Initialise current object, including all related nodes.
Definition: PolyLineObject.cc:156
BaseObject
Definition: BaseObject.hh:94
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:454
ACG::SceneGraph::PolyLineNodeT
Definition: PolyLineNodeT.hh:94
PolyLineObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PolyLineObject.cc:231
OpenMesh::VectorT
Definition: Vector11T.hh:83
PolyLineObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PolyLineObject.cc:210
ACG::SceneGraph::MaterialNode::set_line_width
void set_line_width(float _sz)
set line width (default: 1.0)
Definition: MaterialNode.hh:459
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:244
ACG::SceneGraph::MaterialNode::set_round_points
void set_round_points(bool _b)
set round points enabled
Definition: MaterialNode.hh:464
PolyLineObject::copy
BaseObject * copy()
Definition: PolyLineObject.cc:148
ACG::PolyLineT::point
Point & point(unsigned int _i)
Get a point of the polyline.
Definition: PolyLineT.hh:148
PolyLineObject::lineNode
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode()
Get the scenegraph Node.
Definition: PolyLineObject.cc:218
Types.hh
PolyLineObject::line
PolyLine * line()
return a pointer to the line
Definition: PolyLineObject.cc:205
PolyLineObject::line_
PolyLine * line_
Pointer to the polyline.
Definition: PolyLineObject.hh:137
ACG::Geometry::distPointLineSquared
Vec::value_type distPointLineSquared(const Vec &_p, const Vec &_v0, const Vec &_v1, Vec *_min_v)
squared distance from point _p to line segment (_v0,_v1)
Definition: Algorithms.cc:300
PolyLineObject::~PolyLineObject
virtual ~PolyLineObject()
destructor
Definition: PolyLineObject.cc:102