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