| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2014 Frederik Heber. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | * This file is part of MoleCuilder.
|
|---|
| 8 | *
|
|---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 10 | * it under the terms of the GNU General Public License as published by
|
|---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 12 | * (at your option) any later version.
|
|---|
| 13 | *
|
|---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | * GNU General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | * SphericalPointDistributionUnitTest.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: May 29, 2014
|
|---|
| 27 | * Author: heber
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | using namespace std;
|
|---|
| 36 |
|
|---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
|---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
|---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
|---|
| 40 |
|
|---|
| 41 | // include headers that implement a archive in simple text format
|
|---|
| 42 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 44 |
|
|---|
| 45 | #include "SphericalPointDistributionUnitTest.hpp"
|
|---|
| 46 |
|
|---|
| 47 | #include <algorithm>
|
|---|
| 48 | #include <boost/assign.hpp>
|
|---|
| 49 | #include <boost/bind.hpp>
|
|---|
| 50 | #include <numeric>
|
|---|
| 51 |
|
|---|
| 52 | #include "CodePatterns/Assert.hpp"
|
|---|
| 53 | #include "CodePatterns/Log.hpp"
|
|---|
| 54 |
|
|---|
| 55 | #include "LinearAlgebra/Line.hpp"
|
|---|
| 56 |
|
|---|
| 57 | #include "Atom/TesselPoint.hpp"
|
|---|
| 58 | #include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
|
|---|
| 59 | #include "LinkedCell/linkedcell.hpp"
|
|---|
| 60 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
|---|
| 61 | #include "Tesselation/BoundaryLineSet.hpp"
|
|---|
| 62 | #include "Tesselation/tesselation.hpp"
|
|---|
| 63 |
|
|---|
| 64 | #ifdef HAVE_TESTRUNNER
|
|---|
| 65 | #include "UnitTestMain.hpp"
|
|---|
| 66 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 67 |
|
|---|
| 68 | using namespace boost::assign;
|
|---|
| 69 |
|
|---|
| 70 | /********************************************** Test classes **************************************/
|
|---|
| 71 |
|
|---|
| 72 | // Registers the fixture into the 'registry'
|
|---|
| 73 | CPPUNIT_TEST_SUITE_REGISTRATION( SphericalPointDistributionTest );
|
|---|
| 74 |
|
|---|
| 75 | /** due to root-taking in function we only have limited numerical precision,
|
|---|
| 76 | * basically half of the double range.
|
|---|
| 77 | */
|
|---|
| 78 | const double CenterAccuracy = sqrt(std::numeric_limits<double>::epsilon()*1e2);
|
|---|
| 79 |
|
|---|
| 80 | void SphericalPointDistributionTest::setUp()
|
|---|
| 81 | {
|
|---|
| 82 | // failing asserts should be thrown
|
|---|
| 83 | ASSERT_DO(Assert::Throw);
|
|---|
| 84 |
|
|---|
| 85 | setVerbosity(2);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | void SphericalPointDistributionTest::tearDown()
|
|---|
| 90 | {
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /** UnitTest for calculateCenterOfMinimumDistance()
|
|---|
| 94 | */
|
|---|
| 95 | void SphericalPointDistributionTest::calculateCenterOfMinimumDistanceTest()
|
|---|
| 96 | {
|
|---|
| 97 | // single point
|
|---|
| 98 | {
|
|---|
| 99 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 100 | points +=
|
|---|
| 101 | Vector(1.,0.,0.);
|
|---|
| 102 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 103 | indices += 0;
|
|---|
| 104 | const Vector expected = points[0];
|
|---|
| 105 | const Vector center =
|
|---|
| 106 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 107 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 108 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 109 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // single point, rotated
|
|---|
| 113 | {
|
|---|
| 114 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 115 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 116 | points +=
|
|---|
| 117 | RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI);
|
|---|
| 118 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 119 | indices += 0;
|
|---|
| 120 | const Vector expected = points[0];
|
|---|
| 121 | const Vector center =
|
|---|
| 122 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 123 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 124 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 125 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | // two points
|
|---|
| 129 | {
|
|---|
| 130 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 131 | points +=
|
|---|
| 132 | Vector(1.,0.,0.),
|
|---|
| 133 | Vector(0.,1.,0.);
|
|---|
| 134 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 135 | indices += 0,1;
|
|---|
| 136 | const Vector expected = Vector(M_SQRT1_2,M_SQRT1_2,0.);
|
|---|
| 137 | const Vector center =
|
|---|
| 138 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 139 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 140 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 141 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | // two points, rotated
|
|---|
| 145 | {
|
|---|
| 146 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 147 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 148 | points +=
|
|---|
| 149 | RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
|
|---|
| 150 | RotationAxis.rotateVector(Vector(0.,1.,0.), 47.6/180*M_PI);
|
|---|
| 151 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 152 | indices += 0,1;
|
|---|
| 153 | const Vector expected = RotationAxis.rotateVector(Vector(M_SQRT1_2,M_SQRT1_2,0.), 47.6/180*M_PI);
|
|---|
| 154 | const Vector center =
|
|---|
| 155 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 156 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 157 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 158 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | // three points in line
|
|---|
| 162 | {
|
|---|
| 163 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 164 | points +=
|
|---|
| 165 | Vector(1.,0.,0.),
|
|---|
| 166 | Vector(0.,1.,0.),
|
|---|
| 167 | Vector(-1.,0.,0.);
|
|---|
| 168 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 169 | indices += 0,1,2;
|
|---|
| 170 | const Vector expected = points[1];
|
|---|
| 171 | const Vector center =
|
|---|
| 172 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 173 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 174 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 175 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | // three points in line, rotated
|
|---|
| 179 | {
|
|---|
| 180 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 181 | SphericalPointDistribution::VectorArray_t points;
|
|---|
| 182 | points +=
|
|---|
| 183 | RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
|
|---|
| 184 | RotationAxis.rotateVector(Vector(0.,1.,0.), 47.6/180*M_PI),
|
|---|
| 185 | RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
|
|---|
| 186 | SphericalPointDistribution::IndexList_t indices;
|
|---|
| 187 | indices += 0,1,2;
|
|---|
| 188 | const Vector expected = points[1];
|
|---|
| 189 | const Vector center =
|
|---|
| 190 | SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
|
|---|
| 191 | // std::cout << " Difference is " << (expected - center).Norm() << std::endl;
|
|---|
| 192 | // CPPUNIT_ASSERT_EQUAL ( expected, center );
|
|---|
| 193 | CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | static
|
|---|
| 198 | bool areEqualToWithinBounds(
|
|---|
| 199 | const SphericalPointDistribution::Polygon_t &_polygon,
|
|---|
| 200 | const SphericalPointDistribution::Polygon_t &_otherpolygon,
|
|---|
| 201 | double _amplitude
|
|---|
| 202 | )
|
|---|
| 203 | {
|
|---|
| 204 | // same size?
|
|---|
| 205 | if (_polygon.size() != _otherpolygon.size())
|
|---|
| 206 | return false;
|
|---|
| 207 | // same points ? We just check witrh trivial mapping, nothing fancy ...
|
|---|
| 208 | bool status = true;
|
|---|
| 209 | SphericalPointDistribution::Polygon_t::const_iterator iter = _polygon.begin();
|
|---|
| 210 | SphericalPointDistribution::Polygon_t::const_iterator otheriter = _otherpolygon.begin();
|
|---|
| 211 | for (; iter != _polygon.end(); ++iter, ++otheriter) {
|
|---|
| 212 | status &= (*iter).IsEqualTo(*otheriter, _amplitude);
|
|---|
| 213 | }
|
|---|
| 214 | return status;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | /** UnitTest for areEqualToWithinBounds()
|
|---|
| 218 | */
|
|---|
| 219 | void SphericalPointDistributionTest::areEqualToWithinBoundsTest()
|
|---|
| 220 | {
|
|---|
| 221 | // test with no points
|
|---|
| 222 | {
|
|---|
| 223 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 224 | SphericalPointDistribution::Polygon_t expected = polygon;
|
|---|
| 225 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
|---|
| 226 | }
|
|---|
| 227 | // test with one point
|
|---|
| 228 | {
|
|---|
| 229 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 230 | polygon += Vector(1.,0.,0.);
|
|---|
| 231 | SphericalPointDistribution::Polygon_t expected = polygon;
|
|---|
| 232 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
|---|
| 233 | }
|
|---|
| 234 | // test with two points
|
|---|
| 235 | {
|
|---|
| 236 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 237 | polygon += Vector(1.,0.,0.);
|
|---|
| 238 | polygon += Vector(0.,1.,0.);
|
|---|
| 239 | SphericalPointDistribution::Polygon_t expected = polygon;
|
|---|
| 240 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | // test with two points in different order: THIS GOES WRONG: We only check trivially
|
|---|
| 244 | {
|
|---|
| 245 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 246 | polygon += Vector(1.,0.,0.);
|
|---|
| 247 | polygon += Vector(0.,1.,0.);
|
|---|
| 248 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 249 | expected += Vector(0.,1.,0.);
|
|---|
| 250 | expected += Vector(1.,0.,0.);
|
|---|
| 251 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | // test with two different points
|
|---|
| 255 | {
|
|---|
| 256 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 257 | polygon += Vector(1.,0.,0.);
|
|---|
| 258 | polygon += Vector(0.,1.,0.);
|
|---|
| 259 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 260 | expected += Vector(1.01,0.,0.);
|
|---|
| 261 | expected += Vector(0.,1.,0.);
|
|---|
| 262 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, 0.05) );
|
|---|
| 263 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.005) );
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | // test with different number of points
|
|---|
| 267 | {
|
|---|
| 268 | SphericalPointDistribution::Polygon_t polygon;
|
|---|
| 269 | polygon += Vector(1.,0.,0.);
|
|---|
| 270 | polygon += Vector(0.,1.,0.);
|
|---|
| 271 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 272 | expected += Vector(0.,1.,0.);
|
|---|
| 273 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.05) );
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /** UnitTest for getConnections()
|
|---|
| 278 | */
|
|---|
| 279 | template <>
|
|---|
| 280 | void SphericalPointDistributionTest_assistant::getConnectionTest<0>()
|
|---|
| 281 | {
|
|---|
| 282 | const int N=0;
|
|---|
| 283 | SphericalPointDistribution SPD(1.);
|
|---|
| 284 |
|
|---|
| 285 | // create empty adjacency
|
|---|
| 286 | SphericalPointDistribution::adjacency_t adjacency;
|
|---|
| 287 |
|
|---|
| 288 | // get the implemented connections
|
|---|
| 289 | SphericalPointDistribution::adjacency_t expected =
|
|---|
| 290 | SPD.getConnections<N>();
|
|---|
| 291 |
|
|---|
| 292 | // and compare the two
|
|---|
| 293 | CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | /** UnitTest for getConnections()
|
|---|
| 297 | */
|
|---|
| 298 | template <>
|
|---|
| 299 | void SphericalPointDistributionTest_assistant::getConnectionTest<1>()
|
|---|
| 300 | {
|
|---|
| 301 | const int N=1;
|
|---|
| 302 | SphericalPointDistribution SPD(1.);
|
|---|
| 303 |
|
|---|
| 304 | // create empty adjacency
|
|---|
| 305 | SphericalPointDistribution::adjacency_t adjacency;
|
|---|
| 306 |
|
|---|
| 307 | // get the implemented connections
|
|---|
| 308 | SphericalPointDistribution::adjacency_t expected =
|
|---|
| 309 | SPD.getConnections<N>();
|
|---|
| 310 |
|
|---|
| 311 | // and compare the two
|
|---|
| 312 | CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | /** UnitTest for getConnections()
|
|---|
| 316 | */
|
|---|
| 317 | template <>
|
|---|
| 318 | void SphericalPointDistributionTest_assistant::getConnectionTest<2>()
|
|---|
| 319 | {
|
|---|
| 320 | const int N=2;
|
|---|
| 321 | SphericalPointDistribution SPD(1.);
|
|---|
| 322 |
|
|---|
| 323 | // create empty adjacency
|
|---|
| 324 | SphericalPointDistribution::adjacency_t adjacency;
|
|---|
| 325 | adjacency +=
|
|---|
| 326 | make_pair<
|
|---|
| 327 | unsigned int,
|
|---|
| 328 | SphericalPointDistribution::IndexSet_t >
|
|---|
| 329 | (0, list_of<unsigned int>(1));
|
|---|
| 330 | adjacency +=
|
|---|
| 331 | make_pair<
|
|---|
| 332 | unsigned int,
|
|---|
| 333 | SphericalPointDistribution::IndexSet_t >
|
|---|
| 334 | (1, list_of<unsigned int>(0));
|
|---|
| 335 |
|
|---|
| 336 | // get the implemented connections
|
|---|
| 337 | SphericalPointDistribution::adjacency_t expected =
|
|---|
| 338 | SPD.getConnections<N>();
|
|---|
| 339 |
|
|---|
| 340 | // and compare the two
|
|---|
| 341 | CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | /** UnitTest for getConnections()
|
|---|
| 345 | */
|
|---|
| 346 | template <>
|
|---|
| 347 | void SphericalPointDistributionTest_assistant::getConnectionTest<8>()
|
|---|
| 348 | {
|
|---|
| 349 | const int N=8;
|
|---|
| 350 | SphericalPointDistribution SPD(1.);
|
|---|
| 351 | // get the points and convert into TesselPoint list
|
|---|
| 352 | SphericalPointDistribution::Polygon_t newpolygon = SPD.get<N>();
|
|---|
| 353 | TesselPointSTLList Corners;
|
|---|
| 354 | SphericalPointDistribution::IndexList_t indices(N);
|
|---|
| 355 | std::generate(indices.begin(), indices.end(), UniqueNumber);
|
|---|
| 356 | std::transform(
|
|---|
| 357 | newpolygon.begin(), newpolygon.end(),
|
|---|
| 358 | indices.begin(),
|
|---|
| 359 | std::back_inserter(Corners),
|
|---|
| 360 | VectorToTesselPoint());
|
|---|
| 361 |
|
|---|
| 362 | // create the tesselation
|
|---|
| 363 | const double SPHERERADIUS = 1.5;
|
|---|
| 364 | Tesselation TesselStruct;
|
|---|
| 365 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
|
|---|
| 366 | TesselStruct(cloud, SPHERERADIUS);
|
|---|
| 367 |
|
|---|
| 368 | // create a adjacency list from a tesselation of the (convex set of) points
|
|---|
| 369 | SphericalPointDistribution::adjacency_t adjacency;
|
|---|
| 370 | for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin();
|
|---|
| 371 | iter != TesselStruct.LinesOnBoundary.end(); ++iter) {
|
|---|
| 372 | const BoundaryLineSet * const line = iter->second;
|
|---|
| 373 | {
|
|---|
| 374 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
|---|
| 375 | adjacency.insert(
|
|---|
| 376 | std::make_pair(
|
|---|
| 377 | line->endpoints[0]->Nr,
|
|---|
| 378 | SphericalPointDistribution::IndexSet_t() ));
|
|---|
| 379 | inserter.first->second.insert(line->endpoints[1]->Nr);
|
|---|
| 380 | LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr);
|
|---|
| 381 | }
|
|---|
| 382 | {
|
|---|
| 383 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
|---|
| 384 | adjacency.insert(
|
|---|
| 385 | std::make_pair(
|
|---|
| 386 | line->endpoints[1]->Nr,
|
|---|
| 387 | SphericalPointDistribution::IndexSet_t() ));
|
|---|
| 388 | inserter.first->second.insert(line->endpoints[0]->Nr);
|
|---|
| 389 | LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr);
|
|---|
| 390 | }
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | // get the implemented connections
|
|---|
| 394 | SphericalPointDistribution::adjacency_t expected =
|
|---|
| 395 | SPD.getConnections<N>();
|
|---|
| 396 |
|
|---|
| 397 | // and compare the two
|
|---|
| 398 | // CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
|---|
| 399 |
|
|---|
| 400 | // with eight points we obtain a cube. The problem is that each side
|
|---|
| 401 | // is a polygon with four corners that is ambiguous in the tesselation
|
|---|
| 402 | // it receives. Hence, we cannot directly test the linking but only
|
|---|
| 403 | // the properties.
|
|---|
| 404 | size_t NumberEdges_expected = 0;
|
|---|
| 405 | for (SphericalPointDistribution::adjacency_t::const_iterator iter = expected.begin();
|
|---|
| 406 | iter != expected.begin(); ++iter) {
|
|---|
| 407 | NumberEdges_expected += iter->second.size();
|
|---|
| 408 | CPPUNIT_ASSERT( iter->second.size() >= 3 );
|
|---|
| 409 | CPPUNIT_ASSERT( iter->second.size() <= 6 );
|
|---|
| 410 | }
|
|---|
| 411 | size_t NumberEdges_adjacency = 0;
|
|---|
| 412 | for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin();
|
|---|
| 413 | iter != adjacency.begin(); ++iter) {
|
|---|
| 414 | NumberEdges_adjacency += iter->second.size();
|
|---|
| 415 | CPPUNIT_ASSERT( iter->second.size() >= 3 );
|
|---|
| 416 | CPPUNIT_ASSERT( iter->second.size() <= 6 );
|
|---|
| 417 | }
|
|---|
| 418 | CPPUNIT_ASSERT_EQUAL( NumberEdges_expected, NumberEdges_adjacency);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /** UnitTest for getConnections()
|
|---|
| 422 | */
|
|---|
| 423 | template <>
|
|---|
| 424 | void SphericalPointDistributionTest_assistant::getConnectionTest<11>()
|
|---|
| 425 | {
|
|---|
| 426 | const int N=11;
|
|---|
| 427 | SphericalPointDistribution SPD(1.);
|
|---|
| 428 | // get the points and convert into TesselPoint list
|
|---|
| 429 | SphericalPointDistribution::Polygon_t newpolygon = SPD.get<N>();
|
|---|
| 430 | TesselPointSTLList Corners;
|
|---|
| 431 | SphericalPointDistribution::IndexList_t indices(N);
|
|---|
| 432 | std::generate(indices.begin(), indices.end(), UniqueNumber);
|
|---|
| 433 | std::transform(
|
|---|
| 434 | newpolygon.begin(), newpolygon.end(),
|
|---|
| 435 | indices.begin(),
|
|---|
| 436 | std::back_inserter(Corners),
|
|---|
| 437 | VectorToTesselPoint());
|
|---|
| 438 |
|
|---|
| 439 | // create the tesselation
|
|---|
| 440 | const double SPHERERADIUS = 1.5;
|
|---|
| 441 | Tesselation TesselStruct;
|
|---|
| 442 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
|
|---|
| 443 | TesselStruct(cloud, SPHERERADIUS);
|
|---|
| 444 |
|
|---|
| 445 | // create a adjacency list from a tesselation of the (convex set of) points
|
|---|
| 446 | SphericalPointDistribution::adjacency_t adjacency;
|
|---|
| 447 | for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin();
|
|---|
| 448 | iter != TesselStruct.LinesOnBoundary.end(); ++iter) {
|
|---|
| 449 | const BoundaryLineSet * const line = iter->second;
|
|---|
| 450 | {
|
|---|
| 451 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
|---|
| 452 | adjacency.insert(
|
|---|
| 453 | std::make_pair(
|
|---|
| 454 | line->endpoints[0]->Nr,
|
|---|
| 455 | SphericalPointDistribution::IndexSet_t() ));
|
|---|
| 456 | inserter.first->second.insert(line->endpoints[1]->Nr);
|
|---|
| 457 | LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr);
|
|---|
| 458 | }
|
|---|
| 459 | {
|
|---|
| 460 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
|---|
| 461 | adjacency.insert(
|
|---|
| 462 | std::make_pair(
|
|---|
| 463 | line->endpoints[1]->Nr,
|
|---|
| 464 | SphericalPointDistribution::IndexSet_t() ));
|
|---|
| 465 | inserter.first->second.insert(line->endpoints[0]->Nr);
|
|---|
| 466 | LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr);
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | // get the implemented connections
|
|---|
| 471 | SphericalPointDistribution::adjacency_t expected =
|
|---|
| 472 | SPD.getConnections<N>();
|
|---|
| 473 |
|
|---|
| 474 | // and compare the two
|
|---|
| 475 | // CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
|---|
| 476 |
|
|---|
| 477 | // again, we only check properties as tesselation has ambiguities.
|
|---|
| 478 | size_t NumberEdges_expected = 0;
|
|---|
| 479 | for (SphericalPointDistribution::adjacency_t::const_iterator iter = expected.begin();
|
|---|
| 480 | iter != expected.begin(); ++iter) {
|
|---|
| 481 | NumberEdges_expected += iter->second.size();
|
|---|
| 482 | CPPUNIT_ASSERT( iter->second.size() >= 4 );
|
|---|
| 483 | CPPUNIT_ASSERT( iter->second.size() <= 6 );
|
|---|
| 484 | }
|
|---|
| 485 | size_t NumberEdges_adjacency = 0;
|
|---|
| 486 | for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin();
|
|---|
| 487 | iter != adjacency.begin(); ++iter) {
|
|---|
| 488 | NumberEdges_adjacency += iter->second.size();
|
|---|
| 489 | CPPUNIT_ASSERT( iter->second.size() >= 4 );
|
|---|
| 490 | CPPUNIT_ASSERT( iter->second.size() <= 6 );
|
|---|
| 491 | }
|
|---|
| 492 | CPPUNIT_ASSERT_EQUAL( NumberEdges_expected, NumberEdges_adjacency);
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | void perturbPolygon(
|
|---|
| 496 | SphericalPointDistribution::WeightedPolygon_t &_polygon,
|
|---|
| 497 | double _amplitude
|
|---|
| 498 | )
|
|---|
| 499 | {
|
|---|
| 500 | for (SphericalPointDistribution::WeightedPolygon_t::iterator iter = _polygon.begin();
|
|---|
| 501 | iter != _polygon.end(); ++iter) {
|
|---|
| 502 | Vector perturber;
|
|---|
| 503 | perturber.GetOneNormalVector(iter->first);
|
|---|
| 504 | perturber.Scale(_amplitude);
|
|---|
| 505 | iter->first = iter->first + perturber;
|
|---|
| 506 | (iter->first).Normalize();
|
|---|
| 507 | }
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | /** UnitTest for joinPoints()
|
|---|
| 511 | */
|
|---|
| 512 | void SphericalPointDistributionTest::joinPointsTest()
|
|---|
| 513 | {
|
|---|
| 514 | // test with simple configuration of three points
|
|---|
| 515 | {
|
|---|
| 516 | SphericalPointDistribution::Polygon_t newpolygon;
|
|---|
| 517 | newpolygon += Vector(1.,0.,0.);
|
|---|
| 518 | newpolygon += Vector(0.,1.,0.);
|
|---|
| 519 | newpolygon += Vector(0.,0.,1.);
|
|---|
| 520 | SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
|
|---|
| 521 | SphericalPointDistribution::IndexTupleList_t matching;
|
|---|
| 522 | matching += SphericalPointDistribution::IndexList_t(1,0);
|
|---|
| 523 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
|---|
| 524 | matching += SphericalPointDistribution::IndexList_t(1,2);
|
|---|
| 525 | SphericalPointDistribution::IndexList_t IndexList =
|
|---|
| 526 | SphericalPointDistribution::joinPoints(
|
|---|
| 527 | newpolygon,
|
|---|
| 528 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
|---|
| 529 | matching);
|
|---|
| 530 | SphericalPointDistribution::IndexList_t expected;
|
|---|
| 531 | expected += 0,1,2;
|
|---|
| 532 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
|---|
| 533 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | // test with simple configuration of three points, only two are picked
|
|---|
| 537 | {
|
|---|
| 538 | SphericalPointDistribution::Polygon_t newpolygon;
|
|---|
| 539 | newpolygon += Vector(1.,0.,0.);
|
|---|
| 540 | newpolygon += Vector(0.,1.,0.);
|
|---|
| 541 | newpolygon += Vector(0.,0.,1.);
|
|---|
| 542 | SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
|
|---|
| 543 | SphericalPointDistribution::IndexTupleList_t matching;
|
|---|
| 544 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
|---|
| 545 | matching += SphericalPointDistribution::IndexList_t(1,2);
|
|---|
| 546 | SphericalPointDistribution::IndexList_t IndexList =
|
|---|
| 547 | SphericalPointDistribution::joinPoints(
|
|---|
| 548 | newpolygon,
|
|---|
| 549 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
|---|
| 550 | matching);
|
|---|
| 551 | SphericalPointDistribution::IndexList_t expected;
|
|---|
| 552 | expected += 1,2;
|
|---|
| 553 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
|---|
| 554 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 | // test with simple configuration of three points, two are joined
|
|---|
| 558 | {
|
|---|
| 559 | SphericalPointDistribution::Polygon_t newpolygon;
|
|---|
| 560 | newpolygon += Vector(1.,0.,0.);
|
|---|
| 561 | newpolygon += Vector(0.,1.,0.);
|
|---|
| 562 | newpolygon += Vector(0.,0.,1.);
|
|---|
| 563 | SphericalPointDistribution::Polygon_t expectedpolygon;
|
|---|
| 564 | expectedpolygon += Vector(1.,0.,0.);
|
|---|
| 565 | expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2);
|
|---|
| 566 | SphericalPointDistribution::IndexTupleList_t matching;
|
|---|
| 567 | SphericalPointDistribution::IndexList_t joined;
|
|---|
| 568 | joined += 1,2;
|
|---|
| 569 | matching += SphericalPointDistribution::IndexList_t(1,0);
|
|---|
| 570 | matching += joined;
|
|---|
| 571 | SphericalPointDistribution::IndexList_t IndexList =
|
|---|
| 572 | SphericalPointDistribution::joinPoints(
|
|---|
| 573 | newpolygon,
|
|---|
| 574 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
|---|
| 575 | matching);
|
|---|
| 576 | SphericalPointDistribution::IndexList_t expected;
|
|---|
| 577 | expected += 0,1;
|
|---|
| 578 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
|---|
| 579 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | // test with simple configuration of six points, two are joined, jumbled indices
|
|---|
| 583 | {
|
|---|
| 584 | SphericalPointDistribution::Polygon_t newpolygon;
|
|---|
| 585 | newpolygon += Vector(1.,0.,1.);
|
|---|
| 586 | newpolygon += Vector(1.,0.,0.);
|
|---|
| 587 | newpolygon += Vector(1.,1.,0.);
|
|---|
| 588 | newpolygon += Vector(0.,1.,0.);
|
|---|
| 589 | newpolygon += Vector(0.,0.,1.);
|
|---|
| 590 | newpolygon += Vector(1.,0.,1.);
|
|---|
| 591 | SphericalPointDistribution::Polygon_t expectedpolygon;
|
|---|
| 592 | expectedpolygon += Vector(1.,0.,1.);
|
|---|
| 593 | expectedpolygon += Vector(1.,0.,0.);
|
|---|
| 594 | expectedpolygon += Vector(1.,1.,0.);
|
|---|
| 595 | expectedpolygon += Vector(1.,0.,1.);
|
|---|
| 596 | expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2); // new centers go last
|
|---|
| 597 | SphericalPointDistribution::IndexTupleList_t matching;
|
|---|
| 598 | SphericalPointDistribution::IndexList_t joined;
|
|---|
| 599 | joined += 3,4;
|
|---|
| 600 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
|---|
| 601 | matching += joined;
|
|---|
| 602 | SphericalPointDistribution::IndexList_t IndexList =
|
|---|
| 603 | SphericalPointDistribution::joinPoints(
|
|---|
| 604 | newpolygon,
|
|---|
| 605 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
|---|
| 606 | matching);
|
|---|
| 607 | SphericalPointDistribution::IndexList_t expected;
|
|---|
| 608 | expected += 1,4;
|
|---|
| 609 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
|---|
| 610 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
|---|
| 611 | }
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | /** UnitTest for getRemainingPoints() with two points
|
|---|
| 615 | */
|
|---|
| 616 | void SphericalPointDistributionTest::getRemainingPointsTest_2()
|
|---|
| 617 | {
|
|---|
| 618 | SphericalPointDistribution SPD(1.);
|
|---|
| 619 | // test with one point, matching trivially
|
|---|
| 620 | {
|
|---|
| 621 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 622 | polygon += std::make_pair(Vector(1.,0.,0.), 1);
|
|---|
| 623 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 624 | expected += Vector(-1.,0.,0.);
|
|---|
| 625 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 626 | SPD.getRemainingPoints(polygon, 2);
|
|---|
| 627 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 628 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | // test with one point, just a flip of axis
|
|---|
| 632 | {
|
|---|
| 633 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 634 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 635 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 636 | expected += Vector(0.,-1.,0.);
|
|---|
| 637 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 638 | SPD.getRemainingPoints(polygon, 2);
|
|---|
| 639 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 640 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | // test with one point, just a flip to another axis
|
|---|
| 644 | {
|
|---|
| 645 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 646 | polygon += std::make_pair( Vector(0.,0.,-1.), 1);
|
|---|
| 647 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 648 | expected += Vector(0.,0.,1.);
|
|---|
| 649 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 650 | SPD.getRemainingPoints(polygon, 2);
|
|---|
| 651 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 652 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | // test with one point, full rotation
|
|---|
| 656 | {
|
|---|
| 657 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 658 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 659 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 660 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 661 | expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
|
|---|
| 662 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 663 | SPD.getRemainingPoints(polygon, 2);
|
|---|
| 664 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 665 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 666 | }
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | /** UnitTest for getRemainingPoints() with three points
|
|---|
| 670 | */
|
|---|
| 671 | void SphericalPointDistributionTest::getRemainingPointsTest_3()
|
|---|
| 672 | {
|
|---|
| 673 | SphericalPointDistribution SPD(1.);
|
|---|
| 674 |
|
|---|
| 675 | // test with one point, matching trivially
|
|---|
| 676 | {
|
|---|
| 677 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 678 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 679 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 680 | SPD.get<3>();
|
|---|
| 681 | expected.pop_front(); // remove first point
|
|---|
| 682 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 683 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 684 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 685 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | // test with one point, just a flip of x and y axis
|
|---|
| 689 | {
|
|---|
| 690 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 691 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 692 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 693 | SPD.get<3>();
|
|---|
| 694 | expected.pop_front(); // remove first point
|
|---|
| 695 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 696 | iter != expected.end(); ++iter) {
|
|---|
| 697 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 698 | (*iter)[0] *= -1.;
|
|---|
| 699 | }
|
|---|
| 700 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 701 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 702 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 703 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | // test with two points, matching trivially
|
|---|
| 707 | {
|
|---|
| 708 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 709 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 710 | polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
|
|---|
| 711 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 712 | SPD.get<3>();
|
|---|
| 713 | expected.pop_front(); // remove first point
|
|---|
| 714 | expected.pop_front(); // remove second point
|
|---|
| 715 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 716 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 717 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 718 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 719 | // also slightly perturbed
|
|---|
| 720 | const double amplitude = 0.05;
|
|---|
| 721 | perturbPolygon(polygon, amplitude);
|
|---|
| 722 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | // test with two points, full rotation
|
|---|
| 726 | {
|
|---|
| 727 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 728 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 729 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 730 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
|---|
| 731 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 732 | SPD.get<3>();
|
|---|
| 733 | expected.pop_front(); // remove first point
|
|---|
| 734 | expected.pop_front(); // remove second point
|
|---|
| 735 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 736 | iter != expected.end(); ++iter)
|
|---|
| 737 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 738 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 739 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 740 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 741 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 742 | // also slightly perturbed
|
|---|
| 743 | const double amplitude = 0.05;
|
|---|
| 744 | perturbPolygon(polygon, amplitude);
|
|---|
| 745 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | // test with three points, matching trivially
|
|---|
| 749 | {
|
|---|
| 750 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 751 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 752 | polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
|
|---|
| 753 | polygon += std::make_pair( Vector(-0.5, -sqrt(3)*0.5,0.), 1);
|
|---|
| 754 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 755 | SPD.get<3>();
|
|---|
| 756 | SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
|
|---|
| 757 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 758 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 759 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 760 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 761 | // also slightly perturbed
|
|---|
| 762 | const double amplitude = 0.05;
|
|---|
| 763 | perturbPolygon(polygon, amplitude);
|
|---|
| 764 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 765 | }
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 | // test with three points, full rotation
|
|---|
| 769 | {
|
|---|
| 770 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 771 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 772 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 773 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
|---|
| 774 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
|---|
| 775 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 776 | SPD.get<3>();
|
|---|
| 777 | SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
|
|---|
| 778 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 779 | SPD.getRemainingPoints(polygon, 3);
|
|---|
| 780 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 781 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 782 | // also slightly perturbed
|
|---|
| 783 | const double amplitude = 0.05;
|
|---|
| 784 | perturbPolygon(polygon, amplitude);
|
|---|
| 785 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 786 | }
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | /** UnitTest for getRemainingPoints() with four points
|
|---|
| 790 | */
|
|---|
| 791 | void SphericalPointDistributionTest::getRemainingPointsTest_4()
|
|---|
| 792 | {
|
|---|
| 793 | SphericalPointDistribution SPD(1.);
|
|---|
| 794 |
|
|---|
| 795 | // test with one point, matching trivially
|
|---|
| 796 | {
|
|---|
| 797 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 798 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 799 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 800 | SPD.get<4>();
|
|---|
| 801 | expected.pop_front(); // remove first point
|
|---|
| 802 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 803 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 804 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 805 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | // test with one point, just a flip of axis
|
|---|
| 809 | {
|
|---|
| 810 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 811 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 812 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 813 | SPD.get<4>();
|
|---|
| 814 | expected.pop_front(); // remove first point
|
|---|
| 815 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 816 | iter != expected.end(); ++iter) {
|
|---|
| 817 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 818 | (*iter)[0] *= -1.;
|
|---|
| 819 | }
|
|---|
| 820 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 821 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 822 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 823 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 824 | }
|
|---|
| 825 |
|
|---|
| 826 | // test with two points, matching trivially
|
|---|
| 827 | {
|
|---|
| 828 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 829 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 830 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
|---|
| 831 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 832 | SPD.get<4>();
|
|---|
| 833 | expected.pop_front(); // remove first point
|
|---|
| 834 | expected.pop_front(); // remove second point
|
|---|
| 835 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 836 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 837 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 838 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 839 | // also slightly perturbed
|
|---|
| 840 | const double amplitude = 0.05;
|
|---|
| 841 | perturbPolygon(polygon, amplitude);
|
|---|
| 842 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 843 | }
|
|---|
| 844 |
|
|---|
| 845 | // test with two points, matching trivially, also with slightly perturbed
|
|---|
| 846 | {
|
|---|
| 847 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 848 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 849 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
|---|
| 850 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 851 | SPD.get<4>();
|
|---|
| 852 | expected.pop_front(); // remove first point
|
|---|
| 853 | expected.pop_front(); // remove second point
|
|---|
| 854 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 855 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 856 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 857 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 858 | // also slightly perturbed
|
|---|
| 859 | const double amplitude = 0.05;
|
|---|
| 860 | perturbPolygon(polygon, amplitude);
|
|---|
| 861 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | // test with two points, full rotation
|
|---|
| 865 | {
|
|---|
| 866 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 867 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 868 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 869 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
|
|---|
| 870 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 871 | SPD.get<4>();
|
|---|
| 872 | expected.pop_front(); // remove first point
|
|---|
| 873 | expected.pop_front(); // remove second point
|
|---|
| 874 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 875 | iter != expected.end(); ++iter)
|
|---|
| 876 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 877 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 878 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 879 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 880 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 881 | // also slightly perturbed
|
|---|
| 882 | const double amplitude = 0.05;
|
|---|
| 883 | perturbPolygon(polygon, amplitude);
|
|---|
| 884 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | // test with three points, matching trivially
|
|---|
| 888 | {
|
|---|
| 889 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 890 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 891 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
|---|
| 892 | polygon += std::make_pair( Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 1);
|
|---|
| 893 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 894 | SPD.get<4>();
|
|---|
| 895 | expected.pop_front(); // remove first point
|
|---|
| 896 | expected.pop_front(); // remove second point
|
|---|
| 897 | expected.pop_front(); // remove third point
|
|---|
| 898 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 899 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 900 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 901 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 902 | // also slightly perturbed
|
|---|
| 903 | const double amplitude = 0.05;
|
|---|
| 904 | perturbPolygon(polygon, amplitude);
|
|---|
| 905 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | // test with three points, full rotation
|
|---|
| 909 | {
|
|---|
| 910 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 911 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 912 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 913 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
|
|---|
| 914 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI), 1);
|
|---|
| 915 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 916 | SPD.get<4>();
|
|---|
| 917 | expected.pop_front(); // remove first point
|
|---|
| 918 | expected.pop_front(); // remove second point
|
|---|
| 919 | expected.pop_front(); // remove third point
|
|---|
| 920 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 921 | iter != expected.end(); ++iter)
|
|---|
| 922 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 923 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 924 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 925 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 926 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 927 | // also slightly perturbed
|
|---|
| 928 | const double amplitude = 0.05;
|
|---|
| 929 | perturbPolygon(polygon, amplitude);
|
|---|
| 930 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 931 | }
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | /** UnitTest for getRemainingPoints() with four points and weights
|
|---|
| 935 | * not all equal to one.
|
|---|
| 936 | */
|
|---|
| 937 | void SphericalPointDistributionTest::getRemainingPointsTest_multiple()
|
|---|
| 938 | {
|
|---|
| 939 | SphericalPointDistribution SPD(1.);
|
|---|
| 940 |
|
|---|
| 941 | // test with four points: one point having weight of two
|
|---|
| 942 | {
|
|---|
| 943 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 944 | polygon += std::make_pair( Vector(1.,0.,0.), 2);
|
|---|
| 945 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 946 | SPD.get<4>();
|
|---|
| 947 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 948 | expected += Vector(-0.5773502691896,-5.551115123126e-17,0.8164965809277);
|
|---|
| 949 | expected += Vector(-0.5773502691896,-5.551115123126e-17,-0.8164965809277);
|
|---|
| 950 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 951 | SPD.getRemainingPoints(polygon, 4);
|
|---|
| 952 | // std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
|
|---|
| 953 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 954 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 955 | }
|
|---|
| 956 |
|
|---|
| 957 | // test with five points: one point having weight of two
|
|---|
| 958 | {
|
|---|
| 959 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 960 | polygon += std::make_pair( Vector(1.,0.,0.), 2);
|
|---|
| 961 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 962 | SPD.get<5>();
|
|---|
| 963 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 964 | expected += Vector(-0.7071067811865,0.7071067811865,0);
|
|---|
| 965 | expected += Vector(-0.3535533905933,-0.3535533905933,0.8660254037844);
|
|---|
| 966 | expected += Vector(-0.3535533905933,-0.3535533905933,-0.8660254037844);
|
|---|
| 967 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 968 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 969 | std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
|
|---|
| 970 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 971 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 972 | }
|
|---|
| 973 |
|
|---|
| 974 |
|
|---|
| 975 | // test with five points: one point having weight of two, one weight of one
|
|---|
| 976 | {
|
|---|
| 977 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 978 | polygon += std::make_pair( Vector(M_SQRT1_2,M_SQRT1_2,0.), 2);
|
|---|
| 979 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
|---|
| 980 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 981 | SPD.get<5>();
|
|---|
| 982 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 983 | expected += Vector(0.3535533786708,-0.3535533955317,-0.8660254066357);
|
|---|
| 984 | expected += Vector(0.3535534025157,-0.3535533856548,0.8660254009332);
|
|---|
| 985 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 986 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 987 | // std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
|
|---|
| 988 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 989 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 990 | }
|
|---|
| 991 |
|
|---|
| 992 | // test with six points: two points each having weight of two
|
|---|
| 993 | {
|
|---|
| 994 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 995 | polygon += std::make_pair( Vector(M_SQRT1_2,-M_SQRT1_2,0.), 2);
|
|---|
| 996 | polygon += std::make_pair( Vector(-M_SQRT1_2,M_SQRT1_2,0.), 2);
|
|---|
| 997 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 998 | SPD.get<6>();
|
|---|
| 999 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 1000 | expected += Vector(0.,0.,1.);
|
|---|
| 1001 | expected += Vector(0.,0.,-1.);
|
|---|
| 1002 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1003 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1004 | // std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
|
|---|
| 1005 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1006 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1007 | }
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | /** UnitTest for getRemainingPoints() with five points
|
|---|
| 1011 | */
|
|---|
| 1012 | void SphericalPointDistributionTest::getRemainingPointsTest_5()
|
|---|
| 1013 | {
|
|---|
| 1014 | SphericalPointDistribution SPD(1.);
|
|---|
| 1015 |
|
|---|
| 1016 | // test with one point, matching trivially
|
|---|
| 1017 | {
|
|---|
| 1018 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1019 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1020 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1021 | SPD.get<5>();
|
|---|
| 1022 | expected.pop_front(); // remove first point
|
|---|
| 1023 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1024 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1025 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1026 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1027 | }
|
|---|
| 1028 |
|
|---|
| 1029 | // test with one point, just a flip of axis
|
|---|
| 1030 | {
|
|---|
| 1031 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1032 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 1033 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1034 | SPD.get<5>();
|
|---|
| 1035 | expected.pop_front(); // remove first point
|
|---|
| 1036 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1037 | iter != expected.end(); ++iter) {
|
|---|
| 1038 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 1039 | (*iter)[0] *= -1.;
|
|---|
| 1040 | }
|
|---|
| 1041 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1042 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1043 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1044 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1045 | }
|
|---|
| 1046 |
|
|---|
| 1047 | // test with two points, matching trivially
|
|---|
| 1048 | {
|
|---|
| 1049 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1050 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1051 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
|---|
| 1052 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1053 | SPD.get<5>();
|
|---|
| 1054 | expected.pop_front(); // remove first point
|
|---|
| 1055 | expected.pop_front(); // remove second point
|
|---|
| 1056 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1057 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1058 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1059 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1060 | // also slightly perturbed
|
|---|
| 1061 | const double amplitude = 0.05;
|
|---|
| 1062 | perturbPolygon(polygon, amplitude);
|
|---|
| 1063 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | // test with two points, full rotation
|
|---|
| 1067 | {
|
|---|
| 1068 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1069 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1070 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI), 1);
|
|---|
| 1071 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI), 1);
|
|---|
| 1072 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1073 | SPD.get<5>();
|
|---|
| 1074 | expected.pop_front(); // remove first point
|
|---|
| 1075 | expected.pop_front(); // remove second point
|
|---|
| 1076 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1077 | iter != expected.end(); ++iter)
|
|---|
| 1078 | *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
|
|---|
| 1079 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1080 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1081 | // the three remaining points sit on a plane that may be rotated arbitrarily
|
|---|
| 1082 | // so we cannot simply check for equality between expected and remaining
|
|---|
| 1083 | // hence, we just check that they are orthogonal to the first two points
|
|---|
| 1084 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
|---|
| 1085 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| 1086 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 1087 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 1088 | iter != remaining.end(); ++iter) {
|
|---|
| 1089 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| 1090 | }
|
|---|
| 1091 | }
|
|---|
| 1092 | }
|
|---|
| 1093 |
|
|---|
| 1094 | // test with three points, matching trivially
|
|---|
| 1095 | {
|
|---|
| 1096 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1097 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1098 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
|---|
| 1099 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
|---|
| 1100 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1101 | SPD.get<5>();
|
|---|
| 1102 | expected.pop_front(); // remove first point
|
|---|
| 1103 | expected.pop_front(); // remove second point
|
|---|
| 1104 | expected.pop_front(); // remove third point
|
|---|
| 1105 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1106 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1107 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1108 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1109 | // also slightly perturbed
|
|---|
| 1110 | const double amplitude = 0.05;
|
|---|
| 1111 | perturbPolygon(polygon, amplitude);
|
|---|
| 1112 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1113 | }
|
|---|
| 1114 |
|
|---|
| 1115 | // test with three points, full rotation
|
|---|
| 1116 | {
|
|---|
| 1117 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1118 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1119 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1120 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1121 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1122 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1123 | SPD.get<5>();
|
|---|
| 1124 | expected.pop_front(); // remove first point
|
|---|
| 1125 | expected.pop_front(); // remove second point
|
|---|
| 1126 | expected.pop_front(); // remove third point
|
|---|
| 1127 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1128 | iter != expected.end(); ++iter)
|
|---|
| 1129 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1130 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1131 | SPD.getRemainingPoints(polygon, 5);
|
|---|
| 1132 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1133 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1134 | // also slightly perturbed
|
|---|
| 1135 | const double amplitude = 0.05;
|
|---|
| 1136 | perturbPolygon(polygon, amplitude);
|
|---|
| 1137 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1138 | }
|
|---|
| 1139 | }
|
|---|
| 1140 |
|
|---|
| 1141 | /** UnitTest for getRemainingPoints() with six points
|
|---|
| 1142 | */
|
|---|
| 1143 | void SphericalPointDistributionTest::getRemainingPointsTest_6()
|
|---|
| 1144 | {
|
|---|
| 1145 | SphericalPointDistribution SPD(1.);
|
|---|
| 1146 |
|
|---|
| 1147 | // test with one point, matching trivially
|
|---|
| 1148 | {
|
|---|
| 1149 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1150 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1151 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1152 | SPD.get<6>();
|
|---|
| 1153 | expected.pop_front(); // remove first point
|
|---|
| 1154 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1155 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1156 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1157 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1158 | }
|
|---|
| 1159 |
|
|---|
| 1160 | // test with one point, just a flip of axis
|
|---|
| 1161 | {
|
|---|
| 1162 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1163 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 1164 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1165 | SPD.get<6>();
|
|---|
| 1166 | expected.pop_front(); // remove first point
|
|---|
| 1167 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1168 | iter != expected.end(); ++iter) {
|
|---|
| 1169 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 1170 | (*iter)[0] *= -1.;
|
|---|
| 1171 | }
|
|---|
| 1172 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1173 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1174 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1175 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1176 | }
|
|---|
| 1177 |
|
|---|
| 1178 | // test with two points, matching trivially
|
|---|
| 1179 | {
|
|---|
| 1180 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1181 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1182 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
|---|
| 1183 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1184 | SPD.get<6>();
|
|---|
| 1185 | expected.pop_front(); // remove first point
|
|---|
| 1186 | expected.pop_front(); // remove second spoint
|
|---|
| 1187 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1188 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1189 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1190 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1191 | // also slightly perturbed
|
|---|
| 1192 | const double amplitude = 0.05;
|
|---|
| 1193 | perturbPolygon(polygon, amplitude);
|
|---|
| 1194 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1195 | }
|
|---|
| 1196 |
|
|---|
| 1197 | // test with two points, full rotation
|
|---|
| 1198 | {
|
|---|
| 1199 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1200 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1201 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1202 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1203 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1204 | SPD.get<6>();
|
|---|
| 1205 | expected.pop_front(); // remove first point
|
|---|
| 1206 | expected.pop_front(); // remove second spoint
|
|---|
| 1207 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1208 | iter != expected.end(); ++iter)
|
|---|
| 1209 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1210 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1211 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1212 | // the four remaining points sit on a plane that may have been rotated arbitrarily
|
|---|
| 1213 | // so we cannot simply check for equality between expected and remaining
|
|---|
| 1214 | // hence, we just check that they are orthogonal to the first two points
|
|---|
| 1215 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
|---|
| 1216 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| 1217 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 1218 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 1219 | iter != remaining.end(); ++iter) {
|
|---|
| 1220 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| 1221 | }
|
|---|
| 1222 | }
|
|---|
| 1223 | }
|
|---|
| 1224 |
|
|---|
| 1225 | // test with three points, matching trivially
|
|---|
| 1226 | {
|
|---|
| 1227 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1228 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1229 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
|---|
| 1230 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
|---|
| 1231 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1232 | SPD.get<6>();
|
|---|
| 1233 | expected.pop_front(); // remove first point
|
|---|
| 1234 | expected.pop_front(); // remove second point
|
|---|
| 1235 | expected.pop_front(); // remove third point
|
|---|
| 1236 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1237 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1238 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1239 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1240 | // also slightly perturbed
|
|---|
| 1241 | const double amplitude = 0.05;
|
|---|
| 1242 | perturbPolygon(polygon, amplitude);
|
|---|
| 1243 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1244 | }
|
|---|
| 1245 |
|
|---|
| 1246 | // test with three points, full rotation
|
|---|
| 1247 | {
|
|---|
| 1248 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1249 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1250 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1251 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1252 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1253 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1254 | SPD.get<6>();
|
|---|
| 1255 | expected.pop_front(); // remove first point
|
|---|
| 1256 | expected.pop_front(); // remove second point
|
|---|
| 1257 | expected.pop_front(); // remove third point
|
|---|
| 1258 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1259 | iter != expected.end(); ++iter)
|
|---|
| 1260 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1261 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1262 | SPD.getRemainingPoints(polygon, 6);
|
|---|
| 1263 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1264 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1265 | // also slightly perturbed
|
|---|
| 1266 | const double amplitude = 0.05;
|
|---|
| 1267 | perturbPolygon(polygon, amplitude);
|
|---|
| 1268 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1269 | }
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | /** UnitTest for getRemainingPoints() with seven points
|
|---|
| 1273 | */
|
|---|
| 1274 | void SphericalPointDistributionTest::getRemainingPointsTest_7()
|
|---|
| 1275 | {
|
|---|
| 1276 | SphericalPointDistribution SPD(1.);
|
|---|
| 1277 |
|
|---|
| 1278 | // test with one point, matching trivially
|
|---|
| 1279 | {
|
|---|
| 1280 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1281 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1282 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1283 | SPD.get<7>();
|
|---|
| 1284 | expected.pop_front(); // remove first point
|
|---|
| 1285 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1286 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1287 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1288 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1289 | }
|
|---|
| 1290 |
|
|---|
| 1291 | // test with one point, just a flip of axis
|
|---|
| 1292 | {
|
|---|
| 1293 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1294 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 1295 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1296 | SPD.get<7>();
|
|---|
| 1297 | expected.pop_front(); // remove first point
|
|---|
| 1298 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1299 | iter != expected.end(); ++iter) {
|
|---|
| 1300 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 1301 | (*iter)[0] *= -1.;
|
|---|
| 1302 | }
|
|---|
| 1303 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1304 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1305 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1306 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1307 | }
|
|---|
| 1308 |
|
|---|
| 1309 | // test with two points, matching trivially
|
|---|
| 1310 | {
|
|---|
| 1311 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1312 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1313 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
|---|
| 1314 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1315 | SPD.get<7>();
|
|---|
| 1316 | expected.pop_front(); // remove first point
|
|---|
| 1317 | expected.pop_front(); // remove second point
|
|---|
| 1318 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1319 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1320 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1321 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1322 | // also slightly perturbed
|
|---|
| 1323 | const double amplitude = 0.05;
|
|---|
| 1324 | perturbPolygon(polygon, amplitude);
|
|---|
| 1325 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1326 | }
|
|---|
| 1327 |
|
|---|
| 1328 | // test with two points, full rotation
|
|---|
| 1329 | {
|
|---|
| 1330 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1331 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1332 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1333 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1334 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1335 | SPD.get<7>();
|
|---|
| 1336 | expected.pop_front(); // remove first point
|
|---|
| 1337 | expected.pop_front(); // remove second point
|
|---|
| 1338 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1339 | iter != expected.end(); ++iter)
|
|---|
| 1340 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1341 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1342 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1343 | // the five remaining points sit on a plane that may have been rotated arbitrarily
|
|---|
| 1344 | // so we cannot simply check for equality between expected and remaining
|
|---|
| 1345 | // hence, we just check that they are orthogonal to the first two points
|
|---|
| 1346 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
|---|
| 1347 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| 1348 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 1349 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 1350 | iter != remaining.end(); ++iter) {
|
|---|
| 1351 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| 1352 | }
|
|---|
| 1353 | }
|
|---|
| 1354 | }
|
|---|
| 1355 |
|
|---|
| 1356 | // test with three points, matching trivially
|
|---|
| 1357 | {
|
|---|
| 1358 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1359 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1360 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
|---|
| 1361 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
|---|
| 1362 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1363 | SPD.get<7>();
|
|---|
| 1364 | expected.pop_front(); // remove first point
|
|---|
| 1365 | expected.pop_front(); // remove second point
|
|---|
| 1366 | expected.pop_front(); // remove third point
|
|---|
| 1367 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1368 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1369 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1370 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1371 | // also slightly perturbed
|
|---|
| 1372 | const double amplitude = 0.05;
|
|---|
| 1373 | perturbPolygon(polygon, amplitude);
|
|---|
| 1374 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1375 | }
|
|---|
| 1376 |
|
|---|
| 1377 | // test with three points, full rotation
|
|---|
| 1378 | {
|
|---|
| 1379 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1380 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1381 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1382 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1383 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1384 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1385 | SPD.get<7>();
|
|---|
| 1386 | expected.pop_front(); // remove first point
|
|---|
| 1387 | expected.pop_front(); // remove second point
|
|---|
| 1388 | expected.pop_front(); // remove third point
|
|---|
| 1389 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1390 | iter != expected.end(); ++iter)
|
|---|
| 1391 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1392 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1393 | SPD.getRemainingPoints(polygon, 7);
|
|---|
| 1394 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1395 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1396 | // also slightly perturbed
|
|---|
| 1397 | const double amplitude = 0.05;
|
|---|
| 1398 | perturbPolygon(polygon, amplitude);
|
|---|
| 1399 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1400 | }
|
|---|
| 1401 | }
|
|---|
| 1402 |
|
|---|
| 1403 | /** UnitTest for getRemainingPoints() with eight points
|
|---|
| 1404 | */
|
|---|
| 1405 | void SphericalPointDistributionTest::getRemainingPointsTest_8()
|
|---|
| 1406 | {
|
|---|
| 1407 | SphericalPointDistribution SPD(1.);
|
|---|
| 1408 |
|
|---|
| 1409 | // test with one point, matching trivially
|
|---|
| 1410 | {
|
|---|
| 1411 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1412 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1413 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1414 | SPD.get<8>();
|
|---|
| 1415 | expected.pop_front(); // remove first point
|
|---|
| 1416 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1417 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1418 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1419 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1420 | }
|
|---|
| 1421 |
|
|---|
| 1422 | // test with one point, just a flip of axis
|
|---|
| 1423 | {
|
|---|
| 1424 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1425 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| 1426 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1427 | SPD.get<8>();
|
|---|
| 1428 | expected.pop_front(); // remove first point
|
|---|
| 1429 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1430 | iter != expected.end(); ++iter) {
|
|---|
| 1431 | std::swap((*iter)[0], (*iter)[1]);
|
|---|
| 1432 | (*iter)[0] *= -1.;
|
|---|
| 1433 | }
|
|---|
| 1434 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1435 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1436 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1437 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1438 | }
|
|---|
| 1439 |
|
|---|
| 1440 | // test with two points, matching trivially
|
|---|
| 1441 | {
|
|---|
| 1442 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1443 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1444 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
|---|
| 1445 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1446 | SPD.get<8>();
|
|---|
| 1447 | expected.pop_front(); // remove first point
|
|---|
| 1448 | expected.pop_front(); // remove second point
|
|---|
| 1449 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1450 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1451 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1452 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1453 | // also slightly perturbed
|
|---|
| 1454 | const double amplitude = 0.05;
|
|---|
| 1455 | perturbPolygon(polygon, amplitude);
|
|---|
| 1456 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| 1459 | // test with two points, full rotation
|
|---|
| 1460 | {
|
|---|
| 1461 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1462 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1463 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1464 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1465 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1466 | SPD.get<8>();
|
|---|
| 1467 | expected.pop_front(); // remove first point
|
|---|
| 1468 | expected.pop_front(); // remove second point
|
|---|
| 1469 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1470 | iter != expected.end(); ++iter)
|
|---|
| 1471 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1472 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1473 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1474 | // the six remaining points sit on two planes that may have been rotated arbitrarily
|
|---|
| 1475 | // so we cannot simply check for equality between expected and remaining
|
|---|
| 1476 | // hence, we just check that they are orthogonal to the first two points
|
|---|
| 1477 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
|---|
| 1478 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| 1479 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 1480 | SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
|
|---|
| 1481 | SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
|
|---|
| 1482 | for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
|
|---|
| 1483 | // check that points in expected/remaining have same angle to the given ones
|
|---|
| 1484 | // CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
|
|---|
| 1485 | CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
|
|---|
| 1486 | < std::numeric_limits<double>::epsilon()*1e4 );
|
|---|
| 1487 | }
|
|---|
| 1488 | }
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | // test with three points, matching trivially
|
|---|
| 1492 | {
|
|---|
| 1493 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1494 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| 1495 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
|---|
| 1496 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 1);
|
|---|
| 1497 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1498 | SPD.get<8>();
|
|---|
| 1499 | expected.pop_front(); // remove first point
|
|---|
| 1500 | expected.pop_front(); // remove second point
|
|---|
| 1501 | expected.pop_front(); // remove third point
|
|---|
| 1502 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1503 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1504 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1505 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1506 | // also slightly perturbed
|
|---|
| 1507 | const double amplitude = 0.05;
|
|---|
| 1508 | perturbPolygon(polygon, amplitude);
|
|---|
| 1509 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1510 | }
|
|---|
| 1511 |
|
|---|
| 1512 | // test with three points, full rotation
|
|---|
| 1513 | {
|
|---|
| 1514 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| 1515 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1516 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| 1517 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1518 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI), 1);
|
|---|
| 1519 | SphericalPointDistribution::Polygon_t expected =
|
|---|
| 1520 | SPD.get<8>();
|
|---|
| 1521 | expected.pop_front(); // remove first point
|
|---|
| 1522 | expected.pop_front(); // remove second point
|
|---|
| 1523 | expected.pop_front(); // remove third point
|
|---|
| 1524 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
|---|
| 1525 | iter != expected.end(); ++iter)
|
|---|
| 1526 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
|---|
| 1527 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 1528 | SPD.getRemainingPoints(polygon, 8);
|
|---|
| 1529 | // CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1530 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
|
|---|
| 1531 | // also slightly perturbed
|
|---|
| 1532 | const double amplitude = 0.05;
|
|---|
| 1533 | perturbPolygon(polygon, amplitude);
|
|---|
| 1534 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| 1535 | }
|
|---|
| 1536 | }
|
|---|