Developer Documentation
NormalConeT.cc
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  * $Revision$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS NormalConeT - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 #define OPENMESH_NORMALCONE_C
60 
61 //== INCLUDES =================================================================
62 
63 #include <math.h>
64 #include "NormalConeT.hh"
65 
66 #ifdef max
67 # undef max
68 #endif
69 
70 #ifdef min
71 # undef min
72 #endif
73 
74 
75 //== NAMESPACES ===============================================================
76 
77 
78 namespace OpenMesh {
79 
80 
81 //== IMPLEMENTATION ==========================================================
82 
83 template <typename Scalar>
85 NormalConeT(const Vec3& _center_normal, Scalar _angle)
86  : center_normal_(_center_normal), angle_(_angle)
87 {
88 }
89 
90 
91 //----------------------------------------------------------------------------
92 
93 
94 template <typename Scalar>
95 Scalar
97 max_angle(const Vec3& _norm) const
98 {
99  Scalar dotp = (center_normal_ | _norm);
100  return (dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp)))
101  + angle_;
102 }
103 
104 
105 //----------------------------------------------------------------------------
106 
107 
108 template <typename Scalar>
109 Scalar
111 max_angle(const NormalConeT& _cone) const
112 {
113  Scalar dotp = (center_normal_ | _cone.center_normal_);
114  Scalar centerAngle = dotp >= 1.0 ? 0.0 : (dotp <= -1.0 ? M_PI : acos(dotp));
115  Scalar sideAngle0 = std::max(angle_-centerAngle, _cone.angle_);
116  Scalar sideAngle1 = std::max(_cone.angle_-centerAngle, angle_);
117 
118  return centerAngle + sideAngle0 + sideAngle1;
119 }
120 
121 
122 //----------------------------------------------------------------------------
123 
124 
125 template <typename Scalar>
126 void
128 merge(const NormalConeT& _cone)
129 {
130  Scalar dotp = (center_normal_ | _cone.center_normal_);
131 
132  if (fabs(dotp) < 0.99999f)
133  {
134  // new angle
135  Scalar centerAngle = acos(dotp);
136  Scalar minAngle = std::min(-angle(), centerAngle - _cone.angle());
137  Scalar maxAngle = std::max( angle(), centerAngle + _cone.angle());
138  angle_ = (maxAngle - minAngle) * Scalar(0.5f);
139 
140  // axis by SLERP
141  Scalar axisAngle = Scalar(0.5f) * (minAngle + maxAngle);
142  center_normal_ = ((center_normal_ * sin(centerAngle-axisAngle)
143  + _cone.center_normal_ * sin(axisAngle))
144  / sin(centerAngle));
145  }
146  else
147  {
148  // axes point in same direction
149  if (dotp > 0.0f)
150  angle_ = std::max(angle_, _cone.angle_);
151 
152  // axes point in opposite directions
153  else
154  angle_ = Scalar(2.0f * M_PI);
155  }
156 }
157 
158 
159 //=============================================================================
160 } // namespace OpenMesh
161 //=============================================================================
void merge(const NormalConeT &)
merge _cone; this instance will then enclose both former cones
Definition: NormalConeT.cc:128
NormalConeT()
default constructor (not initialized)
Definition: NormalConeT.hh:95
Scalar angle() const
returns size of cone (radius in radians)
Definition: NormalConeT.hh:113
Scalar max_angle(const Vec3 &) const
return max. distance (radians) unit vector to cone (distant side)
Definition: NormalConeT.cc:97