Developer Documentation

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 //=============================================================================
45 //
46 // MyTypes
47 //
48 //=============================================================================
49
50 #define POLYLINEOBJECT_C
51
52 //== INCLUDES =================================================================
53
54 #include <OpenFlipper/common/Types.hh>
55 #include "PolyLine.hh"
56
57 //== DEFINES ==================================================================
58
59 //== TYPEDEFS =================================================================
60
61 //== CLASS DEFINITION =========================================================
62
69 PolyLineObject::PolyLineObject() :
70 BaseObjectData( ),
71 line_(NULL),
72 lineNode_(NULL)
73 {
74 setDataType(DATA_POLY_LINE);
75 init();
76 }
77
78 //=============================================================================
79
80
84 PolyLineObject::PolyLineObject(const PolyLineObject & _object) :
85 BaseObjectData(_object)
86 {
87
88 init(_object.line_);
89
90 setName( name() );
91 }
92
96 PolyLineObject::~PolyLineObject()
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 Mesh only, if this object contains a mesh
106 if ( line_ != NULL) {
107 delete line_;
108 line_ = NULL;
109 } else {
110 std::cerr << "Destructor error : Line already deleted" << std::endl;
111 }
112
113 // No need to delete the scenegraph Nodes as this will be managed by baseplugin
114 lineNode_ = NULL;
115 }
116
120 void PolyLineObject::cleanup() {
121 // Delete the Line only, if this object contains a line
122 if ( line_ != NULL) {
123 delete line_;
124 line_ = NULL;
125 } else {
126 std::cerr << "Cleanup error : Line already deleted" << std::endl;
127 }
128
129 BaseObjectData::cleanup();
130
131 lineNode_ = NULL;
132
133 setDataType(DATA_POLY_LINE);
134
135 init();
136
137 }
138
142 BaseObject* PolyLineObject::copy() {
143 PolyLineObject* object = new PolyLineObject(*this);
144 return dynamic_cast< BaseObject* >(object);
145 }
146
150 void PolyLineObject::init(PolyLine* _line) {
151
152 if (_line == 0)
153 line_ = new PolyLine();
154 else
155 line_ = new PolyLine(*_line);
156
157 // request default properties
158 line()->request_vertex_selections();
159 line()->request_edge_selections();
160 line()->request_vertex_vhandles();
161 line()->request_vertex_ehandles();
162 line()->request_vertex_fhandles();
163
164
165 if ( materialNode() == NULL)
166 std::cerr << "Error when creating Line Object! materialNode is NULL!" << std::endl;
167
168 lineNode_ = new ACG::SceneGraph::PolyLineNodeT< PolyLine >(*line_, materialNode() , "NEW LineNode");
169
170 // Set default material of the polyLine
171 materialNode()->set_random_color();
172 materialNode()->set_line_width(3.0);
173 materialNode()->set_point_size(8.0);
174 materialNode()->set_round_points(true);
175
176 }
177
178 // ===============================================================================
179 // Name/Path Handling
180 // ===============================================================================
181
185 void PolyLineObject::setName( QString _name ) {
186 BaseObjectData::setName(_name);
187
188 std::string nodename = std::string("LineNode for Line " + _name.toUtf8() );
189 lineNode_->name( nodename );
190 }
191
192 // ===============================================================================
193 // Content
194 // ===============================================================================
195
199 PolyLine* PolyLineObject::line() {
200 return line_;
201 }
202
203
204 void PolyLineObject::update(UpdateType _type) {
205 lineNode_->update();
206 }
207
208 // ===============================================================================
209 // Visualization
210 // ===============================================================================
211
212 ACG::SceneGraph::PolyLineNodeT< PolyLine >* PolyLineObject::lineNode() {
213 return lineNode_;
214 }
215
216 // ===============================================================================
217 // Object information
218 // ===============================================================================
219
225 QString PolyLineObject::getObjectinfo() {
226 QString output;
227
228 output += "========================================================================\n";
229 output += BaseObjectData::getObjectinfo();
230
231 if ( dataType( DATA_POLY_LINE ) )
232 output += "Object Contains PolyLine : ";
233
234 output += QString::number( line()->n_vertices() ) + " vertices, ";
235 output += QString::number( line()->n_edges() ) += " edges and is ";
236 if ( line()->is_closed() )
237 output += "closed.\n";
238 else
239 output += "open.\n";
240
241 output += "========================================================================\n";
242 return output;
243 }
244
245 // ===============================================================================
246 // Picking
247 // ===============================================================================
248
255 bool PolyLineObject::picked( uint _node_idx ) {
256 return ( _node_idx == lineNode_->id() );
257 }
258
259 void PolyLineObject::enablePicking( bool _enable ) {
260 lineNode_->enablePicking( _enable );
261 }
262
263 bool PolyLineObject::pickingEnabled() {
264 return lineNode_->pickingEnabled();
265 }
266
268 ACG::Vec3d PolyLineObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget,
269 const ACG::Vec3d _hitPoint,
270 const ACG::Vec3d _start ,
271 const ACG::Vec3d _dir,
272 const unsigned int _targetIdx )
273 {
274 if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
275 //don't refine polyLine faces
276 return _hitPoint;
277 }
278
279 if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
280 // get picked edge handle
281
282 int eh;
283
284 eh = _targetIdx;
285
286
287 if(eh >= 0 && eh < (int)line()->n_edges())
288 {
289 //get vertices of the edge
290 ACG::Vec3d edgeStart = line()->point((eh+1)%line()->n_vertices());
291 ACG::Vec3d edgeEnd = line()->point(eh);
292
293 //retrieve the point on the edge that is closest to the backprojected hitpoint
294 ACG::Vec3d hitPointNew;
295 ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
296
297
298 return hitPointNew;
299 }
300 }
301
302 if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
303 // get picked vertex handle
304 int vh = _targetIdx;
305 if(vh>=0 && vh < (int)line()->n_vertices())
306 {
307 ACG::Vec3d hitpointNew = line()->point(vh);
308
309 //just return the vertex position
310 return hitpointNew;
311 }
312 }
313
314 return _hitPoint;
315 }
316
317 //=============================================================================
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
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:290
BaseObject::deleteData
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
PolyLineObject::update
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: PolyLineObject.cc:204
ACG::SceneGraph::PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
BaseObjectData::setName
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObjectData.cc:355
PolyLineObject::line_
PolyLine * line_
Pointer to the polyline.
Definition: PolyLineObject.hh:131
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
PolyLineObject::pickingEnabled
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: PolyLineObject.cc:263
BaseObject
Definition: BaseObject.hh:82
PolyLineObject::setName
void setName(QString _name)
Set the name of the Object.
Definition: PolyLineObject.cc:185
PolyLineObject::~PolyLineObject
virtual ~PolyLineObject()
destructor
Definition: PolyLineObject.cc:96
PolyLineObject::lineNode_
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode_
Scenegraph Mesh Node.
Definition: PolyLineObject.hh:170
PolyLineObject::cleanup
virtual void cleanup()
Reset current object, including all related nodes.
Definition: PolyLineObject.cc:120
ACG::SceneGraph::MaterialNode::set_line_width
void set_line_width(float _sz)
set line width (default: 1.0)
Definition: MaterialNode.hh:491
OpenMesh::VectorT
Definition: Vector11T.hh:83
PolyLine
ACG::PolyLineT< ACG::Vec3d > PolyLine
Simple Name for PolyLine.
Definition: PolyLineTypes.hh:66
ACG::SceneGraph::MaterialNode::set_random_color
void set_random_color()
Generates a random color and sets it.
Definition: MaterialNode.hh:416
PolyLineObject
Definition: PolyLineObject.hh:76
PolyLineObject::getObjectinfo
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: PolyLineObject.cc:225
DATA_POLY_LINE
#define DATA_POLY_LINE
Definition: PolyLine.hh:64
PolyLineObject::picked
bool picked(uint _node_idx)
detect if the node has been picked
Definition: PolyLineObject.cc:255
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
BaseObjectData::cleanup
virtual void cleanup() override
Definition: BaseObjectData.cc:102
PolyLineObject::copy
BaseObject * copy()
Definition: PolyLineObject.cc:142
PolyLine.hh
ACG::PolyLineT::point
Point & point(unsigned int _i)
Get a point of the polyline.
Definition: PolyLineT.hh:142
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
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:268
BaseObjectData
Definition: BaseObjectData.hh:102
UpdateType
Update type class.
Definition: UpdateType.hh:60
PolyLineObject::line
PolyLine * line()
return a pointer to the line
Definition: PolyLineObject.cc:199
BaseObjectData::materialNode
MaterialNode * materialNode()
get a pointer to the materialnode
Definition: BaseObjectData.cc:263
ACG::SceneGraph::MaterialNode::set_round_points
void set_round_points(bool _b)
set round points enabled
Definition: MaterialNode.hh:496
PolyLineObject::init
virtual void init(PolyLine *_line=0)
Initialise current object, including all related nodes.
Definition: PolyLineObject.cc:150
ACG::SceneGraph::PolyLineNodeT
Definition: PolyLineNodeT.hh:89
PolyLineObject::lineNode
ACG::SceneGraph::PolyLineNodeT< PolyLine > * lineNode()
Get the scenegraph Node.
Definition: PolyLineObject.cc:212
Types.hh
PolyLineObject::enablePicking
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: PolyLineObject.cc:259
ACG::PolyLineT
Definition: PolyLineT.hh:84
BaseObject::setDataType
void setDataType(DataType _type)
Definition: BaseObject.cc:233
PolyLineObject::PolyLineObject
PolyLineObject()
constructor
Definition: PolyLineObject.cc:69
BaseObject::dataType
DataType dataType() const
Definition: BaseObject.cc:229
ACG::SceneGraph::MaterialNode::set_point_size
void set_point_size(float _sz)
set point size (default: 1.0)
Definition: MaterialNode.hh:486