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);
78 c.initFromVectorStream(instream);
80 trace.
info() <<
"(" << c.size() <<
") elts" << std::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;
92 c.writeVectorToStream(outstream);
104bool testIsOpen(
const string &filename,
const bool& aFlag)
108 trace.
info() <<
"Open/Closed test" << endl;
113 instream.open (filename.c_str(), ifstream::in);
114 c.initFromVectorStream(instream);
116 trace.
info() << c.isOpen() <<
" == " << aFlag << endl;
118 return (c.isOpen() == aFlag);
125bool testExceptions(
const string &filename)
131 trace.
info() <<
"Trying to read bad file: " << filename << endl;
134 instream.open (filename.c_str(), ifstream::in);
137 c.initFromVectorStream(instream);
138 trace.
info() <<
"no exception catched!?" << endl;
146 }
catch (exception& e) {
156bool testDrawGridCurve(
const string &filename)
162 trace.
info() <<
"Displaying GridCurve " << endl;
166 inputStream.open (filename.c_str(), ios::in);
167 c.initFromVectorStream(inputStream);
172 aBoard.
setUnit(Board2D::UCentimeter);
174 aBoard.
saveEPS(
"GridCurve.eps", Board2D::BoundingBox, 5000 );
176 aBoard.
saveCairo(
"GridCurve-cairo.pdf", Board2D::CairoPDF, Board2D::BoundingBox, 5000);
187template <
typename Range>
188bool testRange(
const Range &aRange)
195 std::vector<Value> v1,v2,v3,v4;
201 for ( ; i != end; ++i) {
210 for ( ; i != end; ++i) {
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)
263 for ( ; i != end; ++i) {
264 cout << (*i).first <<
" " << (*i).second << endl;
271 for ( ; i != end; ++i) {
272 cout << i->first <<
" " << i->second << endl;
279template <
typename Range>
280bool testDisplayRange(
const Range &aRange)
284 trace.
info() <<
"Displaying Range" << endl;
290template <
typename Range>
291bool testDrawRange(
const Range &aRange,
const string &aName,
const string& aDomainMode)
295 s << aName <<
"Range.eps";
298 trace.
info() <<
"Drawing " << s.str() <<
" " << endl;
302 aBoard.
setUnit(Board2D::UCentimeter);
308 aBoard <<
SetMode(aDomain.className(), aDomainMode) << aDomain;
312 aBoard.
saveEPS( s.str().c_str(), Board2D::BoundingBox, 5000 );
317template <
typename Range>
318void testRangeConceptChecking()
327int main(
int argc,
char** argv )
331 for (
int i = 0; i < argc; ++i )
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);
371 c.initFromVectorStream(inputStream);
375 && testRange<GridCurve::SCellsRange>(c.getSCellsRange())
376 && testRange<GridCurve::PointsRange>(c.getPointsRange())
377 && testRange<GridCurve::MidPointsRange>(c.getMidPointsRange())
378 && testPairsRange<GridCurve::ArrowsRange>(c.getArrowsRange())
379 && testRange<GridCurve::InnerPointsRange>(c.getInnerPointsRange())
380 && testRange<GridCurve::OuterPointsRange>(c.getOuterPointsRange())
381 && testPairsRange<GridCurve::IncidentPointsRange>(c.getIncidentPointsRange())
382 && testRange<GridCurve::CodesRange>(c.getCodesRange())
386 && testDisplayRange<GridCurve::SCellsRange>(c.getSCellsRange())
387 && testDisplayRange<GridCurve::PointsRange>(c.getPointsRange())
388 && testDisplayRange<GridCurve::MidPointsRange>(c.getMidPointsRange())
389 && testDisplayRange<GridCurve::ArrowsRange>(c.getArrowsRange())
390 && testDisplayRange<GridCurve::InnerPointsRange>(c.getInnerPointsRange())
391 && testDisplayRange<GridCurve::OuterPointsRange>(c.getOuterPointsRange())
392 && testDisplayRange<GridCurve::IncidentPointsRange>(c.getIncidentPointsRange())
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")
403 && testDrawRange<GridCurve::IncidentPointsRange>(c.getIncidentPointsRange(),
"IncidentPoints",
"Grid")
408 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
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...
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.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
std::reverse_iterator< ConstCirculator > ConstReverseCirculator
TConstIterator ConstIterator
std::reverse_iterator< ConstIterator > ConstReverseIterator
void beginBlock(const std::string &keyword="")
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...