DGtal 2.1.0
Loading...
Searching...
No Matches
testVolReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
#include "DGtal/io/writers/VolWriter.h"
#include "ConfigTest.h"
Include dependency graph for testVolReader.cpp:

Go to the source code of this file.

Functions

bool testVolReader ()
 
bool testIOException ()
 Tests the VolReader's behavior when attempting to read a non-existent or invalid .vol file.
 
bool testConsistence ()
 
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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/07/25

Functions for testing class VolReader.

This file is part of the DGtal library.

Definition in file testVolReader.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 176 of file testVolReader.cpp.

177{
178 int aaaaa = 21/2;
179 std::cout << aaaaa << std::endl;
180
181 trace.beginBlock ( "Testing class VolReader" );
182 trace.info() << "Args:";
183 for ( int i = 0; i < argc; ++i )
184 trace.info() << " " << argv[ i ];
185 trace.info() << endl;
186
187 bool res = testVolReader() && testIOException() && testConsistence(); // && ... other tests
188 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
189 trace.endBlock();
190 return res ? 0 : 1;
191
192}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
bool testConsistence()
bool testIOException()
Tests the VolReader's behavior when attempting to read a non-existent or invalid ....
bool testVolReader()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testConsistence(), testIOException(), testVolReader(), and DGtal::trace.

◆ testConsistence()

bool testConsistence ( )

Definition at line 140 of file testVolReader.cpp.

141{
142 trace.beginBlock ( "Testing VolWriter ..." );
143
144 typedef SpaceND<3> Space4Type;
145 typedef HyperRectDomain<Space4Type> TDomain;
146 typedef TDomain::Point Point;
147
148 //Default image selector = STLVector
150 TDomain domain(Point(-17,-14,-13), Point(5,7,11));
152 trace.info() << image.domain() <<endl;
153
154 VolWriter<Image>::exportVol("testConsistence.vol",image);
155
156 trace.endBlock();
157
158 trace.beginBlock ( "Testing VolReader ..." );
159
160 Image image2 = VolReader<Image>::importVol( "testConsistence.vol" );
161
162 trace.info() << image2.domain() <<endl;
163 trace.endBlock();
164
165 if( image.domain().lowerBound() != image2.domain().lowerBound()
166 || image.domain().upperBound() != image2.domain().upperBound() )
167 {
168 return false;
169 }
170 return true;
171}
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
static bool exportVol(const std::string &filename, const Image &aImage, const bool compressed=true, const Functor &aFunctor=Functor())
MyPointD Point
Domain domain
Image image(domain)

References DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), domain, DGtal::Trace::endBlock(), DGtal::VolWriter< TImage, TFunctor >::exportVol(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testIOException()

bool testIOException ( )

Tests the VolReader's behavior when attempting to read a non-existent or invalid .vol file.

Returns
true if the test passes and the exception is handled as expected; false otherwise.

Definition at line 104 of file testVolReader.cpp.

105{
106 unsigned int nbok = 0;
107 unsigned int nb = 0;
108
109 trace.beginBlock ( "Testing VolReader ..." );
110
111 typedef SpaceND<3> Space4Type;
112 typedef HyperRectDomain<Space4Type> TDomain;
113
114 //Default image selector = STLVector
116
117
118 std::string filename = testPath + "samples/null.vol";
119 try
120 {
122 }
123 catch(exception& e)
124 {
125 trace.info() << "Exception catched. Message : "<< e.what()<<endl;
126 }
127
128
129
130 nbok += ( true ) ? 1 : 0;
131 nb++;
132
133 trace.info() << "(" << nbok << "/" << nb << ") "
134 << "true == true" << std::endl;
135 trace.endBlock();
136
137 return nbok == nb;
138}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testVolReader()

bool testVolReader ( )

Example of a test. To be completed.

Definition at line 57 of file testVolReader.cpp.

58{
59 unsigned int nbok = 0;
60 unsigned int nb = 0;
61
62 trace.beginBlock ( "Testing VolReader ..." );
63
64 typedef SpaceND<3> Space4Type;
65 typedef HyperRectDomain<Space4Type> TDomain;
66
67 //Default image selector = STLVector
69
70
71 std::string filename = testPath + "samples/cat10.vol";
73
74 trace.info() << image <<endl;
75
76 unsigned int nbval=0;
77 for(Image::ConstIterator it=image.begin(), itend=image.end();
78 it != itend; ++it)
79 if ( (*it) != 0)
80 nbval++;
81
82 trace.info() << "Number of points with (val!=0) = "<<nbval<<endl;
83
84 nbok += ( nbval == 8043) ? 1 : 0;
85 nb++;
86
87 VolWriter<Image>::exportVol("catenoid-export.vol",image);
88
89 nbok += ( true ) ? 1 : 0;
90 nb++;
91
92 trace.info() << "(" << nbok << "/" << nb << ") "
93 << "true == true" << std::endl;
95
96 return nbok == nb;
97}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::VolWriter< TImage, TFunctor >::exportVol(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().