OpenMesh
NormalConeT_impl.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
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 // CLASS NormalConeT - IMPLEMENTATION
46 //
47 //=============================================================================
48 
49 #define OPENMESH_NORMALCONE_C
50 
51 //== INCLUDES =================================================================
52 
53 #include <math.h>
54 #include "NormalConeT.hh"
55 
56 #ifdef max
57 # undef max
58 #endif
59 
60 #ifdef min
61 # undef min
62 #endif
63 
64 
65 //== NAMESPACES ===============================================================
66 
67 
68 namespace OpenMesh {
69 
70 
71 //== IMPLEMENTATION ==========================================================
72 
73 template <typename Vector>
75 NormalConeT(const Vec3& _center_normal, Scalar _angle)
76  : center_normal_(_center_normal), angle_(_angle)
77 {
78 }
79 
80 
81 //----------------------------------------------------------------------------
82 
83 
84 template <typename Vector>
85 typename NormalConeT<Vector>::Scalar
87 max_angle(const Vec3& _norm) const
88 {
89  Scalar dotp = (center_normal_ | _norm);
90  return (dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp)))
91  + angle_;
92 }
93 
94 
95 //----------------------------------------------------------------------------
96 
97 
98 template <typename Vector>
99 typename NormalConeT<Vector>::Scalar
101 max_angle(const NormalConeT& _cone) const
102 {
103  Scalar dotp = (center_normal_ | _cone.center_normal_);
104  Scalar centerAngle = dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp));
105  Scalar sideAngle0 = std::max(angle_-centerAngle, _cone.angle_);
106  Scalar sideAngle1 = std::max(_cone.angle_-centerAngle, angle_);
107 
108  return centerAngle + sideAngle0 + sideAngle1;
109 }
110 
111 
112 //----------------------------------------------------------------------------
113 
114 
115 template <typename Vector>
116 void
118 merge(const NormalConeT& _cone)
119 {
120  Scalar dotp = dot(center_normal_, _cone.center_normal_);
121 
122  if (fabs(dotp) < 0.99999f)
123  {
124  // new angle
125  Scalar centerAngle = acos(dotp);
126  Scalar minAngle = std::min(-angle(), centerAngle - _cone.angle());
127  Scalar maxAngle = std::max( angle(), centerAngle + _cone.angle());
128  angle_ = (maxAngle - minAngle) * Scalar(0.5f);
129 
130  // axis by SLERP
131  Scalar axisAngle = Scalar(0.5f) * (minAngle + maxAngle);
132  center_normal_ = ((center_normal_ * sin(centerAngle-axisAngle)
133  + _cone.center_normal_ * sin(axisAngle))
134  / sin(centerAngle));
135  }
136  else
137  {
138  // axes point in same direction
139  if (dotp > 0.0f)
140  angle_ = std::max(angle_, _cone.angle_);
141 
142  // axes point in opposite directions
143  else
144  angle_ = Scalar(2.0f * M_PI);
145  }
146 }
147 
148 
149 //=============================================================================
150 } // namespace OpenMesh
151 //=============================================================================
Scalar angle() const
returns size of cone (radius in radians)
Definition: NormalConeT.hh:110
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176
Scalar max_angle(const Vec3 &) const
return max. distance (radians) unit vector to cone (distant side)
Definition: NormalConeT_impl.hh:87
void merge(const NormalConeT &)
merge _cone; this instance will then enclose both former cones
Definition: NormalConeT_impl.hh:118
NormalConeT()
default constructor (not initialized)
Definition: NormalConeT.hh:92
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
/class NormalCone NormalCone.hh <ACG/Geometry/Types/NormalCone.hh>
Definition: NormalConeT.hh:82

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .