Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/tesselationunittest.cpp

    r49e1ae re138de  
    1313#include <cppunit/ui/text/TestRunner.h>
    1414
    15 #include <cstring>
    16 
    1715#include "defs.hpp"
    1816#include "tesselation.hpp"
     
    3230  class TesselPoint *Walker;
    3331  Walker = new TesselPoint;
    34   Walker->node = new Vector(1., 0., -1.);
    35   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     32  Walker->node = new Vector(1., 0., 0.);
     33  Walker->Name = new char[3];
    3634  strcpy(Walker->Name, "1");
    3735  Walker->nr = 1;
    3836  Corners.push_back(Walker);
    3937  Walker = new TesselPoint;
    40   Walker->node = new Vector(-1., 1., -1.);
    41   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     38  Walker->node = new Vector(-1., 1., 0.);
     39  Walker->Name = new char[3];
    4240  strcpy(Walker->Name, "2");
    4341  Walker->nr = 2;
    4442  Corners.push_back(Walker);
    4543  Walker = new TesselPoint;
    46   Walker->node = new Vector(-1., -1., -1.);
    47   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     44  Walker->node = new Vector(-1., -1., 0.);
     45  Walker->Name = new char[3];
    4846  strcpy(Walker->Name, "3");
    4947  Walker->nr = 3;
     
    5149  Walker = new TesselPoint;
    5250  Walker->node = new Vector(-1., 0., 1.);
    53   Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
     51  Walker->Name = new char[3];
    5452  strcpy(Walker->Name, "4");
    5553  Walker->nr = 4;
     
    6159  // create tesselation
    6260  TesselStruct = new Tesselation;
    63   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
    64   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
    65   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
     61  TesselStruct->PointsOnBoundary.clear();
     62  TesselStruct->LinesOnBoundary.clear();
     63  TesselStruct->TrianglesOnBoundary.clear();
    6664  TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
    67 
    68   CandidateForTesselation *baseline = NULL;
    69   BoundaryTriangleSet *T = NULL;
    70   bool OneLoopWithoutSuccessFlag = true;
    71   bool TesselationFailFlag = false;
    72   while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
    73     // 2a. fill all new OpenLines
    74     for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    75       baseline = Runner->second;
    76       if (baseline->pointlist.empty()) {
    77         T = (((baseline->BaseLine->triangles.begin()))->second);
    78         TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
    79       }
    80     }
    81 
    82     // 2b. search for smallest ShortestAngle among all candidates
    83     double ShortestAngle = 4.*M_PI;
    84     for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    85       if (Runner->second->ShortestAngle < ShortestAngle) {
    86         baseline = Runner->second;
    87         ShortestAngle = baseline->ShortestAngle;
    88       }
    89     }
    90     if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
    91       OneLoopWithoutSuccessFlag = false;
    92     else {
    93       TesselStruct->AddCandidateTriangle(*baseline);
     65  bool flag = false;
     66
     67  LineMap::iterator baseline = TesselStruct->LinesOnBoundary.begin();
     68  while (baseline != TesselStruct->LinesOnBoundary.end()) {
     69    if (baseline->second->triangles.size() == 1) {
     70      flag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     71    }
     72    baseline++;
     73    if ((baseline == TesselStruct->LinesOnBoundary.end()) && (flag)) {
     74      baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
     75      flag = false;
    9476    }
    9577  }
     
    10284  delete(TesselStruct);
    10385  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
     86    delete[]((*Runner)->Name);
    10487    delete((*Runner)->node);
    10588    delete(*Runner);
    10689  }
    10790  Corners.clear();
    108   MemoryUsageObserver::purgeInstance();
    109   logger::purgeInstance();
    110   errorLogger::purgeInstance();
     91};
     92
     93/** UnitTest for Tesselation::IsInnerPoint()
     94 */
     95void TesselationTest::IsInnerPointTest()
     96{
     97  // true inside points
     98  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.), LinkedList) );
     99  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.5,0.,0.), LinkedList) );
     100  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.5,0.), LinkedList) );
     101  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.5), LinkedList) );
     102
     103  // corners
     104  for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
     105    CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((*Runner), LinkedList) );
     106
     107  // true outside points
     108  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,5.,0.), LinkedList) );
     109  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,0.,5.), LinkedList) );
     110  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(1.,1.,1.), LinkedList) );
     111
     112  // tricky point, there are three equally close triangles
     113  CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(5.,0.,0.), LinkedList) );
     114
    111115};
    112116
Note: See TracChangeset for help on using the changeset viewer.