DGtal  0.9.3
Functions
testGenericReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/readers/GenericReader.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigTest.h"
Include dependency graph for testGenericReader.cpp:

Go to the source code of this file.

Functions

bool testGenericReader ()
 
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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2013/05/01

Functions for testing class GenericReader.

This file is part of the DGtal library.

Definition in file testGenericReader.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 175 of file testGenericReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testGenericReader(), and DGtal::trace.

176 {
177  DGtal::trace.beginBlock ( "Testing class GenericReader" );
178  DGtal::trace.info() << "Args:";
179  for ( int i = 0; i < argc; ++i )
180  DGtal::trace.info() << " " << argv[ i ];
181  DGtal::trace.info() << std::endl;
182 
183  bool res = testGenericReader(); // && ... other tests
184  DGtal::trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
186  return res ? 0 : 1;
187 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
std::ostream & info()
bool testGenericReader()

◆ testGenericReader()

bool testGenericReader ( )

Example of a test. To be completed.

Definition at line 51 of file testGenericReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::GenericReader< TContainer, Tdim, TValue >::import(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().

Referenced by main().

52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
55 
56  DGtal::trace.beginBlock ( "Testing 2D/3D Image Reader" );
57 
60 
64 
65 
66  std::string filenameImage1 = testPath + "samples/cat10.vol";
67  Image3D anImportedImage1= DGtal::GenericReader<Image3D>::import(filenameImage1);
68  DGtal::Z3i::Domain domain1 = anImportedImage1.domain();
69  unsigned int size0Img1= domain1.upperBound()[0]-domain1.lowerBound()[0]+1;
70  unsigned int size1Img1= domain1.upperBound()[1]-domain1.lowerBound()[1]+1;
71  unsigned int size2Img1= domain1.upperBound()[2]-domain1.lowerBound()[2]+1;
72  DGtal::trace.info()<<"Vol image read: size[0]:" << size0Img1 ;
73  DGtal::trace.info()<<"size[1]: " << size1Img1;
74  DGtal::trace.info()<<"size[2]: " << size2Img1 << std::endl;
75  nbok += (size0Img1==40 && size1Img1==40 && size2Img1==40) ? 1 : 0;
76  nb++;
77  std::string filenameImage0 = testPath + "samples/test.longvol";
78  Image3D64bits anImportedImage0= DGtal::GenericReader<Image3D64bits>::import(filenameImage0);
79  DGtal::Z3i::Domain domain0 = anImportedImage0.domain();
80  unsigned int size0Img0= domain0.upperBound()[0]-domain0.lowerBound()[0]+1;
81  unsigned int size1Img0= domain0.upperBound()[1]-domain0.lowerBound()[1]+1;
82  unsigned int size2Img0= domain0.upperBound()[2]-domain0.lowerBound()[2]+1;
83  DGtal::trace.info()<<"Longvol image read: size[0]:" << size0Img0 ;
84  DGtal::trace.info()<<"size[1]: " << size1Img0;
85  DGtal::trace.info()<<"size[2]: " << size2Img0 << std::endl;
86  nbok += (size0Img0==16 && size1Img0==16 && size2Img0==16) ? 1 : 0;
87  nb++;
88  std::string filenameImage2 = testPath + "samples/cat10.pgm3d";
89  Image3D anImportedImage2= DGtal::GenericReader<Image3D>::import(filenameImage2);
90  DGtal::Z3i::Domain domain2 = anImportedImage2.domain();
91  unsigned int size0Img2= domain2.upperBound()[0]-domain2.lowerBound()[0]+1;
92  unsigned int size1Img2= domain2.upperBound()[1]-domain2.lowerBound()[1]+1;
93  unsigned int size2Img2= domain2.upperBound()[2]-domain2.lowerBound()[2]+1;
94  DGtal::trace.info()<<"Pgm3D image read: size[0]:" << size0Img2 ;
95  DGtal::trace.info()<<"size[1]: " << size1Img2;
96  DGtal::trace.info()<<"size[2]: " << size2Img2 << std::endl;;
97  nbok += (size0Img2==40 && size1Img2==40 && size2Img2==40) ? 1 : 0;
98  nb++;
99 
101  Image3D imageanImportedImage2 = DGtal::GenericReader<Image3D>::importWithValueFunctor( filenameImage2, RescalFCT(0, 120,
102  0, 255) );
103  domain2 = anImportedImage2.domain();
104  size0Img2= domain2.upperBound()[0]-domain2.lowerBound()[0]+1;
105  size1Img2= domain2.upperBound()[1]-domain2.lowerBound()[1]+1;
106  size2Img2= domain2.upperBound()[2]-domain2.lowerBound()[2]+1;
107  DGtal::trace.info()<<"Pgm3D image read (with scale functor) : size[0]:" << size0Img2 ;
108  DGtal::trace.info()<<"size[1]: " << size1Img2;
109  DGtal::trace.info()<<"size[2]: " << size2Img2 << std::endl;;
110  nbok += (size0Img2==40 && size1Img2==40 && size2Img2==40) ? 1 : 0;
111  nb++;
112 
113 
114 #ifdef WITH_HDF5
115  std::string filenameImageh5 = testPath + "samples/cat10.h5";
116  Image3D anImportedImageh5= DGtal::GenericReader<Image3D>::import(filenameImageh5);
117  DGtal::Z3i::Domain domainh5 = anImportedImageh5.domain();
118  unsigned int size0Imgh5= domainh5.upperBound()[0]-domainh5.lowerBound()[0]+1;
119  unsigned int size1Imgh5= domainh5.upperBound()[1]-domainh5.lowerBound()[1]+1;
120  unsigned int size2Imgh5= domainh5.upperBound()[2]-domainh5.lowerBound()[2]+1;
121  DGtal::trace.info()<<"HDF5 3D image read: size[0]:" << size0Imgh5;
122  DGtal::trace.info()<<"size[1]: " << size1Imgh5;
123  DGtal::trace.info()<<"size[2]: " << size2Imgh5 << std::endl;;
124  nbok += (size0Imgh5==40 && size1Imgh5==40 && size2Imgh5==40) ? 1 : 0;
125  nb++;
126 #endif
127  std::string filenameImage3 = testPath + "samples/contourS.pgm";
128  Image2D anImportedImage3= DGtal::GenericReader<Image2D>::import(filenameImage3);
129  DGtal::Z2i::Domain domain3 = anImportedImage3.domain();
130  unsigned int size0Img3= domain3.upperBound()[0]-domain3.lowerBound()[0]+1;
131  unsigned int size1Img3= domain3.upperBound()[1]-domain3.lowerBound()[1]+1;
132 
133  DGtal::trace.info()<<"Pgm image read: size[0]:" << size0Img3 ;
134  DGtal::trace.info()<<"size[1]: " << size1Img3 << std::endl;;
135  nbok += (size0Img3==185 && size1Img3==85 ) ? 1 : 0;
136  nb++;
137 
138  std::string filenameImage4 = testPath + "samples/raw32bits5x5x5.raw";
139  Image3D32bits anImportedImage4= DGtal::GenericReader<Image3D32bits>::import(filenameImage4, 5, 5, 5);
140  DGtal::Z3i::Domain domain4 = anImportedImage4.domain();
141  unsigned int size0Img4= domain4.upperBound()[0]-domain4.lowerBound()[0]+1;
142  unsigned int size1Img4= domain4.upperBound()[1]-domain4.lowerBound()[1]+1;
143  unsigned int size2Img4= domain4.upperBound()[2]-domain4.lowerBound()[2]+1;
144  DGtal::trace.info()<<"Raw32 bits 3D image read: size[0]:" << size0Img4;
145  DGtal::trace.info()<<"size[1]: " << size1Img4;
146  DGtal::trace.info()<<"size[2]: " << size2Img4 << std::endl;
147  DGtal::trace.info()<<"Image value of Point (2,3,4): " << anImportedImage4(DGtal::Z3i::Point(2,3,4)) << " (should be 250000*2*3*4) "<<std::endl;
148  nbok += (size0Img4==5 && size1Img4==5 && size2Img4==5 && anImportedImage4(DGtal::Z3i::Point(2,3,4))==250000*2*3*4) ? 1 : 0;
149  nb++;
150 
151  std::string filenameImage5 = testPath + "samples/raw32bits5x5.raw";
152  Image2D32bits anImportedImage5= DGtal::GenericReader<Image2D32bits>::import(filenameImage5, 5, 5);
153  DGtal::Z2i::Domain domain5 = anImportedImage5.domain();
154  unsigned int size0Img5= domain5.upperBound()[0]-domain5.lowerBound()[0]+1;
155  unsigned int size1Img5= domain5.upperBound()[1]-domain5.lowerBound()[1]+1;
156  DGtal::trace.info()<<"Raw32 bits 3D image read: size[0]:" << size0Img4;
157  DGtal::trace.info()<<"size[1]: " << size1Img5 << std::endl;
158  DGtal::trace.info()<<"Image value of Point (2,3): " << anImportedImage5(DGtal::Z2i::Point(2,3)) << " (should be 250000*2*3*4) "<<std::endl;
159  nbok += (size0Img5==5 && size1Img5==5 && anImportedImage5(DGtal::Z2i::Point(2,3))==250000*2*3*4) ? 1 : 0;
160  nb++;
161 
162 
163 
164 
165  DGtal::trace.info() << "(" << nbok << "/" << nb << ") "
166  << "true == true" << std::endl;
168 
169  return nbok == nb;
170 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
const Point & upperBound() const
double endBlock()
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
Aim: Functor allowing to rescale a value. Values of the initial scale [initMin,initMax] are rescaled ...
std::ostream & info()
const Point & lowerBound() const