Developer Documentation

Spherical_test.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 #include <gtest/gtest.h>
44
45 #include <ACG/Math/VectorT.hh>
46 #include <ACG/Math/GLMatrixT.hh>
47 #include <ACG/Geometry/Spherical.hh>
48
49 namespace {
50
51 using ACG::Vec3d;
52
53 inline Vec3d rot(const Vec3d &ref, const Vec3d &normal, double angle) {
54 ACG::GLMatrixT<double> rmat;
55 rmat.identity();
56 rmat.rotate(angle * M_1_PI * 180.0, normal, ACG::MULT_FROM_LEFT);
57 return rmat.transform_vector(ref);
58 }
59
60 class Spherical : public testing::Test {
61
62 protected:
63
64 virtual void SetUp() {
65 }
66
67 virtual void TearDown() {
68 }
69
70 };
71
72 TEST_F(Spherical, sphericalInnerAngleSum_zeroTriangle) {
73 {
74 const Vec3d n1(1, 0, 0);
75 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(n1, n1, n1), 1e-6);
76 }
77
78 /*
79 * Jitter along one axis.
80 */
81 {
82 const Vec3d n1(1, 0, 0);
83 const Vec3d axis = (n1 % Vec3d(3, 1, 2).normalized()).normalized();
84 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(
85 rot(n1, axis, .1), n1, n1), 1e-6);
86 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(
87 n1, rot(n1, axis, .1), n1), 1e-6);
88 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(
89 n1, n1, rot(n1, axis, .1)), 1e-6);
90 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(
91 rot(n1, axis, .1), rot(n1, axis, -.05), rot(n1, axis, .07)), 1e-6);
92 }
93
94 {
95 const Vec3d n1 = Vec3d(4, 5, 6).normalized();
96 const Vec3d axis = (n1 % Vec3d(3, 1, 2).normalized()).normalized();
97 EXPECT_NEAR(M_PI, ACG::Geometry::sphericalInnerAngleSum(
98 rot(n1, axis, .1), rot(n1, axis, -.05), rot(n1, axis, .07)), 1e-6);
99 }
100 }
101
102 TEST_F(Spherical, sphericalPolyhedralGaussCurv_pointPolyhedral) {
103 std::vector<Vec3d> normals;
104 normals.push_back(Vec3d(1, 0, 0));
105 normals.push_back(Vec3d(1, 0, 0));
106 normals.push_back(Vec3d(1, 0, 0));
107 normals.push_back(Vec3d(1, 0, 0));
108
109 EXPECT_NEAR(0, ACG::Geometry::sphericalPolyhedralGaussCurv<Vec3d>(normals.begin(), normals.end()), 1e-6);
110
111 const Vec3d v = Vec3d(3, 2, 7).normalized();
112 normals.clear();
113 for (int i = 0; i < 7; ++i) normals.push_back(v);
114
115 EXPECT_NEAR(0, ACG::Geometry::sphericalPolyhedralGaussCurv<Vec3d>(normals.begin(), normals.end()), 1e-6);
116 }
117
118 TEST_F(Spherical, sphericalPolyhedralGaussCurv_linePolyhedral) {
119 /*
120 * Jitter along one axis.
121 */
122 const Vec3d n1 = Vec3d(4, 5, 6).normalized();
123 const Vec3d axis = (n1 % Vec3d(3, 1, 2)).normalized();
124
125 std::vector<Vec3d> normals;
126 normals.push_back(rot(n1, axis, .1));
127 normals.push_back(rot(n1, axis, .2));
128 normals.push_back(rot(n1, axis, .05));
129 normals.push_back(rot(n1, axis, .09));
130 normals.push_back(rot(n1, axis, -.2));
131 normals.push_back(rot(n1, axis, .01));
132 normals.push_back(rot(n1, axis, -.1));
133 normals.push_back(rot(n1, axis, -.2));
134
135 EXPECT_NEAR(0, ACG::Geometry::sphericalPolyhedralGaussCurv<Vec3d>(normals.begin(), normals.end()), 1e-6);
136 }
137
138 TEST_F(Spherical, sphericalPolyhedralGaussCurv_cubeCorner) {
139 {
140 std::vector<Vec3d> normals;
141 normals.push_back(Vec3d(1, 0, 0));
142 normals.push_back(Vec3d(0, 1, 0));
143 normals.push_back(Vec3d(0, 0, 1));
144
145 EXPECT_NEAR(M_PI_2, ACG::Geometry::sphericalPolyhedralGaussCurv<Vec3d>(normals.begin(), normals.end()), 1e-6);
146 }
147 }
148
149
150 TEST_F(Spherical, sphericalPolyhedralGaussCurv_houseCorner) {
151 std::vector<Vec3d> normals;
152 normals.push_back(Vec3d(0, 0, 1));
153 normals.push_back(Vec3d(0, 1, 0));
154 normals.push_back(Vec3d(0, 1, 0));
155 normals.push_back(Vec3d(0, 1, 0));
156 normals.push_back(Vec3d(1, 0, 0));
157
158 EXPECT_NEAR(-M_PI_2, ACG::Geometry::sphericalPolyhedralGaussCurv<Vec3d>(normals.begin(), normals.end()), 1e-6);
159 }
160
161 } /* namespace */
OpenMesh::VectorT::normalized
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:440
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
ACG::GLMatrixT< double >
ACG::Matrix4x4T::identity
void identity()
setup an identity matrix
Definition: Matrix4x4T_impl.hh:250
ACG::GLMatrixT::rotate
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
Definition: GLMatrixT_impl.hh:155
ACG::Matrix4x4T::transform_vector
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x&#39;,y&#39;,z&#39;,0) = A * (x,y,z,0)
Definition: Matrix4x4T_impl.hh:219