DGtal  0.9.3
Functions
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 135 of file testGenericWriter.cpp.

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

136 {
137  trace.beginBlock ( "Testing class GenericWriter" );
138  trace.info() << "Args:";
139  for ( int i = 0; i < argc; ++i )
140  trace.info() << " " << argv[ i ];
141  trace.info() << endl;
142 
143  bool res = testGenericWriter(); // && ... other tests
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  trace.endBlock();
146  return res ? 0 : 1;
147 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
bool testGenericWriter()
std::ostream & emphase()
std::ostream & info()

◆ testGenericWriter()

bool testGenericWriter ( )

Example of a test. To be completed.

Definition at line 51 of file testGenericWriter.cpp.

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

Referenced by main().

52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
59 
60  Image3D32bits an32bitsImage3D (DGtal::Z3i::Domain(DGtal::Z3i::Point(0,0,0), DGtal::Z3i::Point(4,4,4)));
61  for(unsigned int i =0; i< 5; i++){
62  for(unsigned int j =0; j< 5; j++){
63  for(unsigned int k =0; k< 5; k++){
64  an32bitsImage3D.setValue(DGtal::Z3i::Point(k,j,i), 250000*i*j*k);
65  }
66  }
67  }
68  Image2D32bits an32bitsImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(4,4)));
69  for(unsigned int i =0; i< 5; i++){
70  for(unsigned int j =0; j< 5; j++){
71  an32bitsImage2D.setValue(DGtal::Z2i::Point(j,i), 250000*i*j*4);
72  }
73  }
74 
75  trace.beginBlock ( "Testing block ..." );
76  std::string filenameImage1 = testPath + "samples/cat10.pgm3d";
77  trace.info() << "Reading 3D image ... ";
78  Image3D anImportedImage1 = DGtal::GenericReader<Image3D>::import(filenameImage1);
79  trace.info() <<"[done]" << std::endl;
80  trace.info() << "Testing writing PGM3D ... ";
81  bool ok1 = anImportedImage1>> "testGenericWriter.pgm3d";
82  trace.info() <<"[done]" << std::endl;
83 
84  bool okh5 = true;
85  bool okh5bis = true;
86 #ifdef WITH_HDF5
87  trace.info() << "Testing writing HDF5 3D ... ";
88  okh5 = anImportedImage1 >> "testGenericWriter.h5";
89  trace.info() <<"[done]" << std::endl;
90  trace.info() << "Testing writing HDF5 3D (bis) ... ";
91  okh5bis = DGtal::GenericWriter<Image3D>::exportFile("testGenericWriter_bis.h5", anImportedImage1, "/UInt8Array3D");
92  trace.info() <<"[done]" << std::endl;
93 #endif
94 
95  trace.info() << "Testing writing vol ... ";
96  bool ok2 = anImportedImage1 >> "testGenericWriter.vol";
97  trace.info() <<"[done]" << std::endl;
98  trace.info() << "Testing writing raw ... ";
99  bool ok3 = anImportedImage1 >>"testGenericWriter.raw";
100  trace.info() <<"[done]" << std::endl;
101  trace.info() << "Testing writing raw (bis) ... ";
102  bool ok3bis = DGtal::GenericWriter<Image3D>::exportFile( "testGenericWriter.raw", anImportedImage1);
103  trace.info() <<"[done]" << std::endl;
104 
105  std::string filenameImage2 = testPath + "samples/contourS.pgm";
106 
107  trace.info() << "Reading 2D image ... ";
108  Image2D anImportedImage2 = DGtal::GenericReader<Image2D>::import(filenameImage2);
109  trace.info() <<"[done]" << std::endl;
110  trace.info() << "Testing writing pgm ... ";
111  bool ok4 = anImportedImage2 >> "testGenericWriter.pgm";
112  trace.info() <<"[done]" << std::endl;
113  trace.info() << "Testing writing raw ... ";
114  bool ok5 = anImportedImage2 >> "testGenericWriter.raw";
115  trace.info() <<"[done]" << std::endl;
116  bool ok6 = DGtal::GenericWriter<Image3D32bits>::exportFile( "testGenericWriter32bits3D.raw", an32bitsImage3D);
117  trace.info() <<"[done]" << std::endl;
118  bool ok7 = DGtal::GenericWriter<Image2D32bits>::exportFile( "testGenericWriter32bits2D.raw", an32bitsImage2D);
119  trace.info() <<"[done]" << std::endl;
120 
121 
122 
123  nbok += ok1 && okh5 && okh5bis && ok2 && ok3 && ok3bis && ok4 & ok5 & ok6 & ok7 ? 1 : 0;
124  nb++;
125  trace.info() << "(" << nbok << "/" << nb << ") "
126  << "true == true" << std::endl;
127  trace.endBlock();
128 
129  return nbok == nb;
130 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
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())
std::ostream & info()