37 #include <boost/program_options.hpp>
39 #include "DGtal/base/Common.h"
41 #include "DGtal/kernel/SpaceND.h"
42 #include "DGtal/kernel/domains/HyperRectDomain.h"
43 #include "DGtal/topology/KhalimskySpaceND.h"
44 #include "DGtal/geometry/curves/GridCurve.h"
46 #include "DGtal/io/boards/Board2D.h"
48 #include "DGtal/io/boards/CDrawableWithBoard2D.h"
50 #include "ConfigTest.h"
55 using namespace DGtal;
65 template <
typename KSpace>
66 bool testIOGridCurve(
const string& filename)
69 unsigned int d = KSpace::Point::dimension;
74 trace.
info() <<
"Reading GridCurve d=" << d <<
" ";
77 instream.open (filename.c_str(), ifstream::in);
86 s <<
"gridcurve" << d <<
".dat";
88 trace.
info() <<
"Writing GridCurve d=" << d <<
" in " << s.str() << endl;
90 ofstream outstream(s.str().c_str());
91 if (!outstream.is_open())
return false;
105 bool testIsOpen(
const string &filename,
const bool& aFlag)
109 trace.
info() <<
"Open/Closed test" << endl;
114 instream.open (filename.c_str(), ifstream::in);
119 return (c.
isOpen() == aFlag);
126 bool testExceptions(
const string &filename)
132 trace.
info() <<
"Trying to read bad file: " << filename << endl;
135 instream.open (filename.c_str(), ifstream::in);
139 trace.
info() <<
"no exception catched!?" << endl;
147 }
catch (exception& e) {
157 bool testDrawGridCurve(
const string &filename)
163 trace.
info() <<
"Displaying GridCurve " << endl;
167 inputStream.open (filename.c_str(), ios::in);
173 aBoard.
setUnit(Board2D::UCentimeter);
175 aBoard.
saveEPS(
"GridCurve.eps", Board2D::BoundingBox, 5000 );
177 aBoard.saveCairo(
"GridCurve-cairo.pdf", Board2D::CairoPDF, Board2D::BoundingBox, 5000);
188 template <
typename Range>
189 bool testRange(
const Range &aRange)
196 std::vector<Value> v1,v2,v3,v4;
200 typename Range::ConstIterator i = aRange.
begin();
201 typename Range::ConstIterator end = aRange.
end();
202 for ( ; i != end; ++i) {
209 typename Range::ConstReverseIterator i = aRange.rbegin();
210 typename Range::ConstReverseIterator end = aRange.rend();
211 for ( ; i != end; ++i) {
218 typename Range::ConstCirculator c = aRange.c();
219 typename Range::ConstCirculator cend = aRange.c();
232 trace.
info() <<
"Reverse Circulator" << endl;
233 typename Range::ConstReverseCirculator c = aRange.rc();
234 typename Range::ConstReverseCirculator cend = aRange.rc();
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()) );
252 template <
typename Range>
253 bool 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;
279 template <
typename Range>
280 bool testDisplayRange(
const Range &aRange)
284 trace.
info() <<
"Displaying Range" << endl;
290 template <
typename Range>
291 bool 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 );
317 template <
typename Range>
318 void testRangeConceptChecking()
327 int 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";
348 testRangeConceptChecking<GridCurve::SCellsRange>();
349 testRangeConceptChecking<GridCurve::PointsRange>();
350 testRangeConceptChecking<GridCurve::MidPointsRange>();
351 testRangeConceptChecking<GridCurve::ArrowsRange>();
352 testRangeConceptChecking<GridCurve::InnerPointsRange>();
353 testRangeConceptChecking<GridCurve::OuterPointsRange>();
354 testRangeConceptChecking<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;