DGtal  1.5.beta
testGenericWriter.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/readers/GenericReader.h"
#include "DGtal/io/writers/GenericWriter.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigTest.h"
Include dependency graph for testGenericWriter.cpp:

Go to the source code of this file.

Functions

bool testGenericWriter ()
 
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 GenericWriter.

This file is part of the DGtal library.

Definition in file testGenericWriter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 170 of file testGenericWriter.cpp.

171 {
172  trace.beginBlock ( "Testing class GenericWriter" );
173  trace.info() << "Args:";
174  for ( int i = 0; i < argc; ++i )
175  trace.info() << " " << argv[ i ];
176  trace.info() << endl;
177 
178  bool res = testGenericWriter(); // && ... other tests
179  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
180  trace.endBlock();
181  return res ? 0 : 1;
182 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testGenericWriter()

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

◆ testGenericWriter()

bool testGenericWriter ( )

Example of a test. To be completed.

Definition at line 51 of file testGenericWriter.cpp.

52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
61 
62  Image3D32bits an32bitsImage3D (DGtal::Z3i::Domain(DGtal::Z3i::Point(0,0,0), DGtal::Z3i::Point(4,4,4)));
63  for(unsigned int i =0; i< 5; i++){
64  for(unsigned int j =0; j< 5; j++){
65  for(unsigned int k =0; k< 5; k++){
66  an32bitsImage3D.setValue(DGtal::Z3i::Point(k,j,i), 250000*i*j*k);
67  }
68  }
69  }
70  Image3D64bits an64bitsImage3D (DGtal::Z3i::Domain(DGtal::Z3i::Point(0,0,0), DGtal::Z3i::Point(4,4,4)));
71  for(unsigned int i =0; i< 5; i++){
72  for(unsigned int j =0; j< 5; j++){
73  for(unsigned int k =0; k< 5; k++){
74  an64bitsImage3D.setValue(DGtal::Z3i::Point(k,j,i), 250000*i*j*k);
75  }
76  }
77  }
78  Image2D32bits an32bitsImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(4,4)));
79  for(unsigned int i =0; i< 5; i++){
80  for(unsigned int j =0; j< 5; j++){
81  an32bitsImage2D.setValue(DGtal::Z2i::Point(j,i), 250000*i*j*4);
82  }
83  }
84 
85  Image2DColor anColorImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(255,255)));
86 
87 
88  for(unsigned int i =0; i<= 255; i++){
89  for(unsigned int j =0; j<= 255; j++){
90  anColorImage2D.setValue(DGtal::Z2i::Point(i,j),DGtal::Color(i,j,(i+j)%255));
91  }
92  }
93 
94 
95  trace.beginBlock ( "Testing block ..." );
96  std::string filenameImage1 = testPath + "samples/cat10.pgm3d";
97  trace.info() << "Reading 3D image ... ";
98  Image3D anImportedImage1 = DGtal::GenericReader<Image3D>::import(filenameImage1);
99  trace.info() <<"[done]" << std::endl;
100  trace.info() << "Testing writing PGM3D ... ";
101  bool ok1 = anImportedImage1>> "testGenericWriter.pgm3d";
102  trace.info() <<"[done]" << std::endl;
103 
104  bool okh5 = true;
105 #ifdef WITH_HDF5
106  trace.info() << "Testing writing HDF5 3D ... ";
107  okh5 = anImportedImage1 >> "testGenericWriter.h5";
108  trace.info() <<"[done]" << std::endl;
109  trace.info() << "Testing writing HDF5 3D (bis) ... ";
110  okh5 = okh5 && DGtal::GenericWriter<Image3D>::exportFile("testGenericWriter_bis.h5", anImportedImage1, "/UInt8Array3D");
111  trace.info() <<"[done]" << std::endl;
112 #endif
113 
114  trace.info() << "Testing writing vol ... ";
115  bool ok2 = anImportedImage1 >> "testGenericWriter.vol";
116  trace.info() <<"[done]" << std::endl;
117  trace.info() << "Testing writing longvol ... ";
118  bool ok2bis = an64bitsImage3D >> "testGenericWriter.longvol";
119  trace.info() <<"[done]" << std::endl;
120  trace.info() << "Testing writing raw ... ";
121  bool ok3 = anImportedImage1 >>"testGenericWriter.raw";
122  trace.info() <<"[done]" << std::endl;
123  trace.info() << "Testing writing raw (bis) ... ";
124  bool ok3bis = DGtal::GenericWriter<Image3D>::exportFile( "testGenericWriter.raw", anImportedImage1);
125  trace.info() <<"[done]" << std::endl;
126  bool okITK= true;
127 #ifdef WITH_ITK
128  for (auto ext: ITK_IO_IMAGE_EXT){
129  trace.info() << "Testing writing ITK (" << ext << ") ... ";
130  if( ext != std::string("gz") )
131  {
132  okITK &= anImportedImage1 >> (std::string("testGenericWriter.") + ext);
133  }
134  trace.info() <<"[done]" << std::endl;
135  }
136  trace.info() << "Testing writing ITK (.nii.gz) ... ";
137  okITK &= anImportedImage1 >> "testGenericWriter.nii.gz";
138  trace.info() <<"[done]" << std::endl;
139 #endif
140 
141  std::string filenameImage2 = testPath + "samples/contourS.pgm";
142 
143  trace.info() << "Reading 2D image ... ";
144  Image2D anImportedImage2 = DGtal::GenericReader<Image2D>::import(filenameImage2);
145  trace.info() <<"[done]" << std::endl;
146  trace.info() << "Testing writing pgm ... ";
147  bool ok4 = anImportedImage2 >> "testGenericWriter.pgm";
148  trace.info() <<"[done]" << std::endl;
149  trace.info() << "Testing writing raw ... ";
150  bool ok5 = anImportedImage2 >> "testGenericWriter.raw";
151  bool ok6 = DGtal::GenericWriter<Image3D32bits>::exportFile( "testGenericWriter32bits3D.raw", an32bitsImage3D);
152  bool ok7 = DGtal::GenericWriter<Image2D32bits>::exportFile( "testGenericWriter32bits2D.raw", an32bitsImage2D);
153  trace.info() <<"[done]" << std::endl;
154  trace.info() << "Testing writing color image writer ... ";
155  bool ok8 = DGtal::GenericWriter<Image2DColor>::exportFile( "testGenericWriterColorImage.ppm", anColorImage2D);
156  ok8 = ok8 && DGtal::GenericWriter<Image2DColor>::exportFile( "testGenericWriterColorImage.png", anColorImage2D);
157  trace.info() <<"[done]" << std::endl;
158  nbok += ((ok1 && okh5 && ok2 & ok2bis && ok3 && ok3bis && ok4 && ok5 && ok6 && ok7 && ok8 && okITK) ? 1 : 0);
159  nb++;
160  trace.info() << "(" << nbok << "/" << nb << ") "
161  << "true == true" << std::endl;
162  trace.endBlock();
163 
164  return nbok == nb;
165 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::GenericWriter< TContainer, Tdim, TValue, TFunctor >::exportFile(), DGtal::GenericReader< TContainer, Tdim, TValue >::import(), DGtal::Trace::info(), DGtal::ITK_IO_IMAGE_EXT, and DGtal::trace.

Referenced by main().