DGtal  0.9.2
testContourHelper.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/geometry/helpers/ContourHelper.h"
35 #include "DGtal/helpers/StdDefs.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 
42 // Functions for testing class ContourHelper.
44 
48 bool testContourHelper()
49 {
50  unsigned int nbok = 0;
51  unsigned int nb = 0;
52 
53  trace.beginBlock ( "Test Contour Helper" );
54  std::vector<Z2i::Point> aContour;
55  aContour.push_back(Z2i::Point(0,0));
56  aContour.push_back(Z2i::Point(10,0));
57  aContour.push_back(Z2i::Point(10,4));
58  aContour.push_back(Z2i::Point(0,4));
59  Z2i::Point midPoint = ContourHelper::getMeanPoint(aContour);
60 
61  std::vector<Z2i::Point> aContour2;
62  aContour2.push_back(Z2i::Point(0,0));
63  aContour2.push_back(Z2i::Point(0,10));
64  aContour2.push_back(Z2i::Point(5,10));
65 
66  nbok += midPoint==Z2i::Point(5,2) ? 1 : 0;
67  nb++;
68  nbok += ContourHelper::isCounterClockWise(aContour) ? 1 : 0;
69  nb++;
70  nbok += ContourHelper::isCounterClockWise(aContour2) ? 0 : 1;
71  nb++;
72 
73  trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
74 
75 
76 
77 
78  trace.endBlock();
79  return nbok == nb;
80 }
81 
83 // Standard services - public :
84 
85 int main( int argc, char** argv )
86 {
87  trace.beginBlock ( "Testing class ContourHelper" );
88  trace.info() << "Args:";
89  for ( int i = 0; i < argc; ++i )
90  trace.info() << " " << argv[ i ];
91  trace.info() << endl;
92 
93  bool res = testContourHelper(); // && ... other tests
94  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
95  trace.endBlock();
96  return res ? 0 : 1;
97 }
98 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()