38#include "DGtal/base/Common.h"
40#include "DGtal/kernel/SpaceND.h"
41#include "DGtal/kernel/domains/HyperRectDomain.h"
42#include "DGtal/topology/KhalimskySpaceND.h"
43#include "DGtal/geometry/curves/GridCurve.h"
45#include "DGtal/io/boards/Board2D.h"
47#include "DGtal/io/boards/CDrawableWithBoard2D.h"
49#include "ConfigTest.h"
64template <
typename KSpace>
65bool testIOGridCurve(
const string& filename)
73 trace.info() <<
"Reading GridCurve d=" << d <<
" ";
76 instream.open (filename.c_str(), ifstream::in);
80 trace.info() <<
"(" << c.
size() <<
") elts" << std::endl;
81 trace.info() << c << endl;
85 s <<
"gridcurve" << d <<
".dat";
87 trace.info() <<
"Writing GridCurve d=" << d <<
" in " << s.str() << endl;
89 ofstream outstream(s.str().c_str());
90 if (!outstream.is_open())
return false;
104bool testIsOpen(
const string &filename,
const bool& aFlag)
107 trace.info() << endl;
108 trace.info() <<
"Open/Closed test" << endl;
113 instream.open (filename.c_str(), ifstream::in);
116 trace.info() << c.
isOpen() <<
" == " << aFlag << endl;
118 return (c.
isOpen() == aFlag);
125bool testExceptions(
const string &filename)
130 trace.info() << endl;
131 trace.info() <<
"Trying to read bad file: " << filename << endl;
134 instream.open (filename.c_str(), ifstream::in);
138 trace.info() <<
"no exception catched!?" << endl;
146 }
catch (exception& e) {
147 trace.info() << e.what() << endl;
156bool testDrawGridCurve(
const string &filename)
161 trace.info() << endl;
162 trace.info() <<
"Displaying GridCurve " << endl;
166 inputStream.open (filename.c_str(), ios::in);
175#ifdef DGTAL_WITH_CAIRO
187template <
typename Range>
188bool testRange(
const Range &aRange)
191 trace.info() << endl;
192 trace.info() <<
"Testing Range" << endl;
195 std::vector<Value> v1,v2,v3,v4;
198 trace.info() <<
"Forward" << endl;
201 for ( ; i != end; ++i) {
207 trace.info() <<
"Backward" << endl;
210 for ( ; i != end; ++i) {
216 trace.info() <<
"Circulator" << endl;
231 trace.info() <<
"Reverse Circulator" << endl;
246 return ( std::equal(v1.begin(),v1.end(),v3.begin())
247 && std::equal(v2.begin(),v2.end(),v4.begin())
248 && std::equal(v1.begin(),v1.end(),v2.rbegin())
249 && std::equal(v3.begin(),v3.end(),v4.rbegin()) );
252template <
typename Range>
253bool testPairsRange(
const Range &aRange)
256 trace.info() << endl;
257 trace.info() <<
"Testing Range" << endl;
260 trace.info() <<
"Forward" << endl;
263 for ( ; i != end; ++i) {
264 cout << (*i).first <<
" " << (*i).second << endl;
268 trace.info() <<
"Backward" << endl;
271 for ( ; i != end; ++i) {
272 cout << i->first <<
" " << i->second << endl;
279template <
typename Range>
280bool testDisplayRange(
const Range &aRange)
283 trace.info() << endl;
284 trace.info() <<
"Displaying Range" << endl;
285 trace.info() << aRange << endl;
290template <
typename Range>
291bool testDrawRange(
const Range &aRange,
const string &aName,
const string& aDomainMode)
295 s << aName <<
"Range.eps";
297 trace.info() << endl;
298 trace.info() <<
"Drawing " << s.str() <<
" " << endl;
308 aBoard <<
SetMode(aDomain.className(), aDomainMode) << aDomain;
317template <
typename Range>
318void testRangeConceptChecking()
327int main(
int argc,
char** argv )
329 trace.beginBlock (
"Testing class GridCurve" );
330 trace.info() <<
"Args:";
331 for (
int i = 0; i < argc; ++i )
332 trace.info() <<
" " << argv[ i ];
333 trace.info() << endl;
336 std::string sinus2D4 = testPath +
"samples/sinus2D4.dat";
337 std::string polyg2D = testPath +
"samples/polyg2D.dat";
338 std::string sinus3D = testPath +
"samples/sinus3D.dat";
339 std::string emptyFile = testPath +
"samples/emptyFile.dat";
340 std::string
square = testPath +
"samples/smallSquare.dat";
348testRangeConceptChecking<GridCurve::SCellsRange>();
349testRangeConceptChecking<GridCurve::PointsRange>();
350testRangeConceptChecking<GridCurve::MidPointsRange>();
351testRangeConceptChecking<GridCurve::ArrowsRange>();
352testRangeConceptChecking<GridCurve::InnerPointsRange>();
353testRangeConceptChecking<GridCurve::OuterPointsRange>();
354testRangeConceptChecking<GridCurve::IncidentPointsRange>();
357 bool res = testIOGridCurve<K2>(sinus2D4)
358 && testIOGridCurve<K3>(sinus3D)
359 && testExceptions(sinus3D)
360 && testExceptions(polyg2D)
361 && testExceptions(emptyFile)
362 && testDrawGridCurve(sinus2D4)
363 && testIsOpen(sinus2D4,
true)
364 && testIsOpen(square,
false);
370 inputStream.open (
square.c_str(), ios::in);
393 && testDisplayRange<GridCurve::CodesRange>(c.
getCodesRange())
397 && testDrawRange<GridCurve::SCellsRange>(c.
getSCellsRange(),
"1cells",
"Grid")
398 && testDrawRange<GridCurve::PointsRange>(c.
getPointsRange(),
"Points",
"Paving")
399 && testDrawRange<GridCurve::MidPointsRange>(c.
getMidPointsRange(),
"MidPoints",
"Paving")
400 && testDrawRange<GridCurve::ArrowsRange>(c.
getArrowsRange(),
"Arrows",
"Paving")
401 && testDrawRange<GridCurve::InnerPointsRange>(c.
getInnerPointsRange(),
"InnerPoints",
"Grid")
402 && testDrawRange<GridCurve::OuterPointsRange>(c.
getOuterPointsRange(),
"OuterPoints",
"Grid")
408 trace.emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
virtual const char * what() const noexcept
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
SCellsRange getSCellsRange() const
MidPointsRange getMidPointsRange() const
bool initFromVectorStream(std::istream &in)
PointsRange getPointsRange() const
IncidentPointsRange getIncidentPointsRange() const
void writeVectorToStream(std::ostream &out)
ArrowsRange getArrowsRange() const
OuterPointsRange getOuterPointsRange() const
Storage::size_type size() const
InnerPointsRange getInnerPointsRange() const
GridCurve::CodesRange getCodesRange() const
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
static const constexpr Dimension dimension
Aim: Implements basic operations that will be used in Point and Vector classes.
boost::reverse_iterator< ConstIterator > ConstReverseIterator
boost::reverse_iterator< ConstCirculator > ConstReverseCirculator
DGtal::Circulator< ConstIterator > ConstCirculator
ConstIterator ConstIterator
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.
bool isNotEmpty(const IC &itb, const IC &ite)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Aim: Defines the concept describing a bidirectional const range.
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...