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
PolyLinePlugin_BezierSpline.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: 17392 $ *
45 * $Author: moebius $ *
46 * $Date: 2013-08-26 15:03:53 +0200 (Mon, 26 Aug 2013) $ *
47 * *
48 \*===========================================================================*/
49
50 //=============================================================================
51 //
52 // CLASS PolyLinePlugin - IMPLEMENTATION
53 //
54 //=============================================================================
55
56
57 //== INCLUDES =================================================================
58
59 #include "PolyLinePlugin.hh"
60
61 ACG::Vec3d
62 PolyLinePlugin::
63 getPointOnMesh(PolyLineBezierSplineData* _SplineData, ACG::Vec3d _point, ACG::Vec3d* _nor)
64 {
65 TriMeshObject* mesh;
66 if(!PluginFunctions::getObject(_SplineData->meshIndex_, mesh))
67 return _point;
68 OpenMeshTriangleBSPT<TriMesh>* bsp = mesh->requestTriangleBsp();
69 OpenMeshTriangleBSPT<TriMesh>::NearestNeighbor neigh = bsp->nearest(_point);
70 ACG::Vec3d nor = mesh->mesh()->normal(neigh.handle);
71 if(_nor)
72 *_nor = nor;
73 OpenMeshTriangleBSPT<TriMesh>::RayCollision rayInt;
74 rayInt = bsp->raycollision(_point, nor);
75 if(rayInt.size())
76 return _point + nor * rayInt[0].second;
77 return _point + nor.normalize() * neigh.dist;
78 }
79
80 void
81 PolyLinePlugin::
82 updatePolyBezierHandles(PolyLineObject* _lineObject, ACG::SceneGraph::LineNode* _line)
83 {
84 PolyLineBezierSplineData* splineData = dynamic_cast<PolyLineBezierSplineData*>(_lineObject->objectData(BEZSPLINE_DATA));
85 if(!splineData)
86 return;
87 _line->clear();
88 for(unsigned int i = 0; i < splineData->handles_.size(); i++) {
89 ACG::SceneGraph::GlutPrimitiveNode* node = 0;
90 if(_lineObject->getAdditionalNode(node, name(), "handle", i))
91 node->set_position(splineData->handles_[i]);
92 const PolyLineBezierSplineData::InterpolatePoint& control = splineData->getInterpolatePoint(i);
93 _line->add_line(control.position, splineData->handles_[i]);
94 _line->add_color(ACG::Vec4f(1,0,0,1));
95 }
96 for(unsigned int i = 0; i < splineData->points_.size(); i++) {
97 ACG::SceneGraph::GlutPrimitiveNode* node = 0;
98 if(_lineObject->getAdditionalNode(node, name(), "control", i))
99 node->set_position(splineData->points_[i].position);
100 }
101 }
102
103 void
104 PolyLinePlugin::
105 updatePolyBezierSpline(PolyLineObject* _lineObject, unsigned int _pointCount)
106 {
107 PolyLineBezierSplineData* splineData = dynamic_cast<PolyLineBezierSplineData*>(_lineObject->objectData(BEZSPLINE_DATA));
108 TriMeshObject* mesh;
109 if(!splineData || !PluginFunctions::getObject(splineData->meshIndex_, mesh)) {
110 return;//no mesh -> do nothing
111 }
112 _lineObject->line()->clear();
113 unsigned int segCount = (splineData->points_.size() + splineData->handles_.size() - 1) / 3;
114 for(unsigned int s = 0; s < segCount; s++) {
115 const ACG::Vec3d a = splineData->points_[s].position, d = splineData->points_[s + 1].position,
116 b = splineData->handles_[s * 2], c = splineData->handles_[s * 2 + 1];
117 //the last segment will get one more point to close the spline
118 unsigned int n = (s != segCount - 1) ? _pointCount : (_pointCount + 1);
119 for(unsigned int i = 0; i < n; i++) {
120 float alpha = float(i) / float(_pointCount);
121 const ACG::Vec3d e = a + (b - a) * alpha, f = c + (d - c) * alpha;
122 ACG::Vec3d g = e + (f - e) * alpha;
123 g = getPointOnMesh(splineData, g);
124 _lineObject->line()->add_point(g);
125 }
126 }
127 emit updatedObject(_lineObject->id(), UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
128 }
MeshObject::mesh
MeshT * mesh()
return a pointer to the mesh
Definition: MeshObjectT.cc:351
UPDATE_GEOMETRY
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
BaseObject::objectData
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
Definition: BaseObject.cc:814
BSPImplT< TriangleBSPCoreT< OpenMeshTriangleBSPTraits< Mesh > > >::RayCollision
std::vector< std::pair< Handle, Scalar > > RayCollision
Store nearest neighbor information.
Definition: BSPImplT.hh:105
TriMeshObject
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:73
BaseObjectData::getAdditionalNode
bool getAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
get an addition node from the object
Definition: BaseObjectDataT.cc:91
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
PolyLinePlugin::updatePolyBezierHandles
void updatePolyBezierHandles(PolyLineObject *_lineObject, ACG::SceneGraph::LineNode *_line)
Updates all the handles on the PolyBezier.
Definition: PolyLinePlugin_BezierSpline.cc:82
ACG::PolyLineT::clear
void clear()
Clear the current polyline.
Definition: PolyLineT.cc:187
MeshObject::requestTriangleBsp
OMTriangleBSP * requestTriangleBsp()
Definition: MeshObjectT.cc:756
PolyLineObject
Definition: PolyLineObject.hh:82
BSPImplT< TriangleBSPCoreT< OpenMeshTriangleBSPTraits< Mesh > > >::raycollision
RayCollision raycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
PolyLineBezierSplineData::getInterpolatePoint
InterpolatePoint & getInterpolatePoint(unsigned int _handleIndex)
Retrieves the interpolate point based on the handle.
Definition: PolyLineBezierSplineData.cc:111
ACG::SceneGraph::LineNode::clear
void clear()
clear points/lines and colors
Definition: LineNode.cc:107
PolyLineBezierSplineData
Definition: PolyLineBezierSplineData.hh:59
OpenMesh::VectorT
Definition: Vector11T.hh:83
PolyLinePlugin::updatePolyBezierSpline
void updatePolyBezierSpline(PolyLineObject *_lineObject, unsigned int _pointsPerSegment)
Generates points for the spline, updates handles.
Definition: PolyLinePlugin_BezierSpline.cc:105
PolyLineBezierSplineData::InterpolatePoint
Definition: PolyLineBezierSplineData.hh:64
UPDATE_TOPOLOGY
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
OpenMeshTriangleBSPT
Definition: TriangleBSPT.hh:206
BSPImplT< TriangleBSPCoreT< OpenMeshTriangleBSPTraits< Mesh > > >::nearest
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
ACG::PolyLineT::add_point
void add_point(const Point &_p)
Append a point to the polyline.
Definition: PolyLineT.cc:288
ACG::SceneGraph::LineNode
Definition: LineNode.hh:90
TriangleBSPCoreT< OpenMeshTriangleBSPTraits< Mesh > >::size
size_t size()
Definition: TriangleBSPCoreT.hh:117
ACG::SceneGraph::LineNode::add_line
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
Definition: LineNode.cc:157
ACG::SceneGraph::GlutPrimitiveNode::set_position
void set_position(const Vec3d &_p, int _idx=0)
set position
Definition: GlutPrimitiveNode.cc:106
PolyLineObject::line
PolyLine * line()
return a pointer to the line
Definition: PolyLineObject.cc:205
PolyLinePlugin::getPointOnMesh
ACG::Vec3d getPointOnMesh(PolyLineBezierSplineData *_SplineData, ACG::Vec3d _point, ACG::Vec3d *_nor=0)
Returns the nearest point on the mesh or if none could be found the input.
Definition: PolyLinePlugin_BezierSpline.cc:63
PolyLinePlugin::name
QString name()
Name of the Plugin.
Definition: PolyLinePlugin.hh:209
PolyLineBezierSplineData::meshIndex_
unsigned int meshIndex_
Index of the corresponding mesh.
Definition: PolyLineBezierSplineData.hh:72
BaseObject::id
int id() const
Definition: BaseObject.cc:201
ACG::SceneGraph::GlutPrimitiveNode
Definition: GlutPrimitiveNode.hh:88
ACG::SceneGraph::LineNode::add_color
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)
Definition: LineNode.cc:168