DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testContourHelper.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/geometry/helpers/ContourHelper.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/PointVector.h"

Go to the source code of this file.

Functions

bool testContourHelper ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2014/06/11

Functions for testing class ContourHelper.

This file is part of the DGtal library.

Definition in file testContourHelper.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 116 of file testContourHelper.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testContourHelper()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testContourHelper(), and DGtal::trace.

◆ testContourHelper()

bool testContourHelper ( )

Example of a test. To be completed.

Definition at line 49 of file testContourHelper.cpp.

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}
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()
Space::Point Point
Definition: StdDefs.h:95

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::ContourHelper::getBarycenter(), DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromPointsVector(), DGtal::ContourHelper::isCounterClockWise(), DGtal::ContourHelper::pixels2pixels8C(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::size(), and DGtal::trace.

Referenced by main().