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);
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)
108 trace.
info() <<
"Open/Closed test" << endl;
113 instream.open (filename.c_str(), ifstream::in);
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);
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);
172 aBoard.
setUnit(Board2D::UCentimeter);
174 aBoard.
saveEPS(
"GridCurve.eps", Board2D::BoundingBox, 5000 );
175#ifdef DGTAL_WITH_CAIRO
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;
199 typename Range::ConstIterator i = aRange.begin();
200 typename Range::ConstIterator end = aRange.end();
201 for ( ; i != end; ++i) {
208 typename Range::ConstReverseIterator i = aRange.rbegin();
209 typename Range::ConstReverseIterator end = aRange.rend();
210 for ( ; i != end; ++i) {
217 typename Range::ConstCirculator c = aRange.c();
218 typename Range::ConstCirculator cend = aRange.c();
231 trace.
info() <<
"Reverse Circulator" << endl;
232 typename Range::ConstReverseCirculator c = aRange.rc();
234 typename Range::ConstReverseCirculator cend = c;
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)
261 typename Range::ConstIterator i = aRange.begin();
262 typename Range::ConstIterator end = aRange.end();
263 for ( ; i != end; ++i) {
264 cout << (*i).first <<
" " << (*i).second << endl;
269 typename Range::ConstReverseIterator i = aRange.rbegin();
270 typename Range::ConstReverseIterator end = aRange.rend();
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);
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.
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...