DGtal 1.3.0
Loading...
Searching...
No Matches
testContourHelper.cpp
Go to the documentation of this file.
1
31#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"
36#include "DGtal/kernel/PointVector.h"
38
39using namespace std;
40using namespace DGtal;
41
43// Functions for testing class ContourHelper.
45
50{
51 unsigned int nbok = 0;
52 unsigned int nb = 0;
53
54 trace.beginBlock ( "Test ContourHelper: getgetBarycenter and isCounterClockWise" );
55 std::vector<Z2i::Point> aContour;
56 aContour.push_back(Z2i::Point(0,0));
57 aContour.push_back(Z2i::Point(10,0));
58 aContour.push_back(Z2i::Point(10,4));
59 aContour.push_back(Z2i::Point(0,4));
60 Z2i::RealPoint midPoint = ContourHelper::getBarycenter(aContour);
61
62 std::vector<Z2i::Point> aContour2;
63 aContour2.push_back(Z2i::Point(0,0));
64 aContour2.push_back(Z2i::Point(0,10));
65 aContour2.push_back(Z2i::Point(5,10));
66
67 nbok += midPoint==Z2i::Point(5,2) ? 1 : 0;
68 nb++;
69 nbok += ContourHelper::isCounterClockWise(aContour) ? 1 : 0;
70 nb++;
71 nbok += ContourHelper::isCounterClockWise(aContour2) ? 0 : 1;
72 nb++;
74
75 trace.beginBlock("Test ContourHelper: pixels2pixels8c ");
76
77 std::vector<Z2i::Point> aContour3;
78 aContour3.push_back(Z2i::Point(0,0));
79 aContour3.push_back(Z2i::Point(1,0));
80 aContour3.push_back(Z2i::Point(1,1));
81 aContour3.push_back(Z2i::Point(2,1));
82 aContour3.push_back(Z2i::Point(3,1));
83 aContour3.push_back(Z2i::Point(4,1));
84 aContour3.push_back(Z2i::Point(4,2));
85 aContour3.push_back(Z2i::Point(5,2));
86 aContour3.push_back(Z2i::Point(6,2));
87 std::vector<Z2i::Point> res, res2;
88
89 ContourHelper::pixels2pixels8C(aContour3.begin(),
90 aContour3.end(), std::back_inserter(res));
91 trace.info() << "Apply pixels2pixels8c (from std::vector contour)init size : " << res.size() << " (should be: " << aContour3.size() -2 << " ) "<< std::endl;
92 trace.info() << "Third point : " << res[2] << " (should be: " << Z2i::Point(2,1) << " ) "<< std::endl;
93 nb++;
94 nbok += res.size() == aContour3.size() -2 || Z2i::Point(2,1)==res[2];
95
96 typedef GridCurve< KhalimskySpaceND<2>> GridCurve2d ;
97 GridCurve2d gc;
98 gc.initFromPointsVector(aContour3);
99 ContourHelper::pixels2pixels8C(gc.getPointsRange().begin(),
100 gc.getPointsRange().end(), std::back_inserter(res2));
101 trace.info() << "Apply pixels2pixels8c (from GridCurve contour) init size : " << res2.size() << " (should be: " << aContour3.size() -2 << " ) "<< std::endl;
102 trace.info() << "Third point : " << res2[2] << " (should be: " << Z2i::Point(2,1) << " ) "<< std::endl;
103 nb++;
104 nbok += res2.size() == aContour3.size() -2 || Z2i::Point(2,1)==res2[2];
105
106 trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
107
108 for(auto p: res)
109 trace.info() << p << std::endl;
110 return nbok == nb;
111}
112
114// Standard services - public :
115
116int main( int argc, char** argv )
117{
118 trace.beginBlock ( "Testing class ContourHelper" );
119 trace.info() << "Args:";
120 for ( int i = 0; i < argc; ++i )
121 trace.info() << " " << argv[ i ];
122 trace.info() << endl;
123
124 bool res = testContourHelper(); // && ... other tests
125 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
126 trace.endBlock();
127 return res ? 0 : 1;
128}
129// //
static DGtal::PointVector< TPoint::dimension, double > getBarycenter(const std::vector< TPoint > &aSet)
static void pixels2pixels8C(const TIterator &itb, const TIterator &ite, TOutputIterator out)
static bool isCounterClockWise(const std::vector< TPoint > &aCurve)
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromPointsVector(const std::vector< Point > &aVectorOfPoints)
static Dimension size()
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Space::Point Point
Definition: StdDefs.h:95
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
int main()
Definition: testBits.cpp:56
bool testContourHelper()