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
TriangleMesh.cc
Go to the documentation of this file.
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: 18128 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2014-02-05 10:20:28 +0100 (Mi, 05. Feb 2014) $ *
47 * *
48 \*===========================================================================*/
49
50
59 //== INCLUDES =================================================================
60
61 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
62
63
64 TriMeshObject::TriMeshObject(const TriMeshObject& _object) : MeshObject< TriMesh >(_object) {
65
66 }
67
68
69 TriMeshObject::TriMeshObject(DataType _typeId) : MeshObject< TriMesh >(_typeId) {
70
71 }
72
73
74 TriMeshObject::~TriMeshObject() {
75
76 }
77
78 BaseObject* TriMeshObject::copy() {
79 TriMeshObject* object = new TriMeshObject(*this );
80 return object;
81 }
82
84 ACG::Vec3d TriMeshObject::refinePick(ACG::SceneGraph::PickTarget _pickTarget, const ACG::Vec3d _hitPoint, const ACG::Vec3d _start , const ACG::Vec3d _dir, const unsigned int _targetIdx ) {
85 if ( _pickTarget == ACG::SceneGraph::PICK_FACE) {
86
87 // get picked face handle
88 TriMesh::FaceHandle fh = mesh()->face_handle(_targetIdx);
89
90 TriMesh::FaceVertexIter fv_it = mesh()->fv_begin(fh);
91
92 // Get vertices of the face
93 ACG::Vec3d p1 = mesh()->point(*fv_it);
94 ++fv_it;
95
96 ACG::Vec3d p2 = mesh()->point(*fv_it);
97 ++fv_it;
98
99 ACG::Vec3d p3 = mesh()->point(*fv_it);
100 ++fv_it;
101
102 ACG::Vec3d hitpointNew = _hitPoint;
103
104 TriMesh::Scalar t,u,v;
105 if ( ACG::Geometry::triangleIntersection( _start, _dir, p1 , p2 , p3 , t , u , v) ) {
106 hitpointNew = _start + t * _dir;
107 }
108
109 return hitpointNew;
110 }
111
112 if ( _pickTarget == ACG::SceneGraph::PICK_EDGE) {
113 // get picked edge handle
114 TriMesh::EdgeHandle eh = mesh()->edge_handle(_targetIdx);
115 if(eh.is_valid())
116 {
117 TriMesh::HalfedgeHandle heh = mesh()->halfedge_handle(eh,0);
118
119 //get vertices of the edge
120 TriMesh::VertexHandle vhbegin = mesh()->to_vertex_handle(heh);
121 TriMesh::VertexHandle vhend = mesh()->from_vertex_handle(heh);
122 ACG::Vec3d edgeStart = mesh()->point(vhbegin);
123 ACG::Vec3d edgeEnd = mesh()->point(vhend);
124
125 //retrieve the point on the edge that is closest to the backprojected hitpoint
126 ACG::Vec3d hitPointNew;
127 ACG::Geometry::distPointLineSquared(_hitPoint,edgeStart,edgeEnd,&hitPointNew);
128
129
130 return hitPointNew;
131 }
132 }
133
134 if ( _pickTarget == ACG::SceneGraph::PICK_VERTEX) {
135 // get picked vertex handle
136 TriMesh::VertexHandle vh = mesh()->vertex_handle(_targetIdx);
137 if(vh.is_valid())
138 {
139 ACG::Vec3d hitpointNew = mesh()->point(vh);
140
141 //just return the vertex position
142 return hitpointNew;
143 }
144 }
145
146 return _hitPoint;
147 }
148
149
150 //=============================================================================
151
MeshObject< TriMesh >::mesh
TriMesh * mesh()
return a pointer to the mesh
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
TriangleMesh.hh
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
TriMeshObject
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:73
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
ACG::Geometry::triangleIntersection
bool triangleIntersection(const Vec &_o, const Vec &_dir, const Vec &_v0, const Vec &_v1, const Vec &_v2, typename Vec::value_type &_t, typename Vec::value_type &_u, typename Vec::value_type &_v)
Intersect a ray and a triangle.
Definition: Algorithms.cc:1317
ACG::SceneGraph::PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
BaseObject
Definition: BaseObject.hh:94
TriMeshObject::copy
BaseObject * copy()
Definition: TriangleMesh.cc:78
OpenMesh::VectorT
Definition: Vector11T.hh:83
TriMeshObject::~TriMeshObject
virtual ~TriMeshObject()
destructor
Definition: TriangleMesh.cc:74
TriMeshObject::TriMeshObject
TriMeshObject(const TriMeshObject &_object)
copy constructor
Definition: TriangleMesh.cc:64
MeshObject
Definition: MeshObjectT.hh:103
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
TriMeshObject::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: TriangleMesh.cc:84
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