DGtal  1.2.0
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 151 of file testGenericWriter.cpp.

152 {
153  trace.beginBlock ( "Testing class GenericWriter" );
154  trace.info() << "Args:";
155  for ( int i = 0; i < argc; ++i )
156  trace.info() << " " << argv[ i ];
157  trace.info() << endl;
158 
159  bool res = testGenericWriter(); // && ... other tests
160  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
161  trace.endBlock();
162  return res ? 0 : 1;
163 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
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;
60 
61  Image3D32bits an32bitsImage3D (DGtal::Z3i::Domain(DGtal::Z3i::Point(0,0,0), DGtal::Z3i::Point(4,4,4)));
62  for(unsigned int i =0; i< 5; i++){
63  for(unsigned int j =0; j< 5; j++){
64  for(unsigned int k =0; k< 5; k++){
65  an32bitsImage3D.setValue(DGtal::Z3i::Point(k,j,i), 250000*i*j*k);
66  }
67  }
68  }
69  Image2D32bits an32bitsImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(4,4)));
70  for(unsigned int i =0; i< 5; i++){
71  for(unsigned int j =0; j< 5; j++){
72  an32bitsImage2D.setValue(DGtal::Z2i::Point(j,i), 250000*i*j*4);
73  }
74  }
75 
76  Image2DColor anColorImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(255,255)));
77 
78 
79  for(unsigned int i =0; i<= 255; i++){
80  for(unsigned int j =0; j<= 255; j++){
81  anColorImage2D.setValue(DGtal::Z2i::Point(i,j),DGtal::Color(i,j,(i+j)%255));
82  }
83  }
84 
85 
86  trace.beginBlock ( "Testing block ..." );
87  std::string filenameImage1 = testPath + "samples/cat10.pgm3d";
88  trace.info() << "Reading 3D image ... ";
89  Image3D anImportedImage1 = DGtal::GenericReader<Image3D>::import(filenameImage1);
90  trace.info() <<"[done]" << std::endl;
91  trace.info() << "Testing writing PGM3D ... ";
92  bool ok1 = anImportedImage1>> "testGenericWriter.pgm3d";
93  trace.info() <<"[done]" << std::endl;
94 
95  bool okh5 = true;
96  bool okh5bis = true;
97 #ifdef WITH_HDF5
98  trace.info() << "Testing writing HDF5 3D ... ";
99  okh5 = anImportedImage1 >> "testGenericWriter.h5";
100  trace.info() <<"[done]" << std::endl;
101  trace.info() << "Testing writing HDF5 3D (bis) ... ";
102  okh5bis = DGtal::GenericWriter<Image3D>::exportFile("testGenericWriter_bis.h5", anImportedImage1, "/UInt8Array3D");
103  trace.info() <<"[done]" << std::endl;
104 #endif
105 
106  trace.info() << "Testing writing vol ... ";
107  bool ok2 = anImportedImage1 >> "testGenericWriter.vol";
108  trace.info() <<"[done]" << std::endl;
109  trace.info() << "Testing writing raw ... ";
110  bool ok3 = anImportedImage1 >>"testGenericWriter.raw";
111  trace.info() <<"[done]" << std::endl;
112  trace.info() << "Testing writing raw (bis) ... ";
113  bool ok3bis = DGtal::GenericWriter<Image3D>::exportFile( "testGenericWriter.raw", anImportedImage1);
114  trace.info() <<"[done]" << std::endl;
115 
116  std::string filenameImage2 = testPath + "samples/contourS.pgm";
117 
118  trace.info() << "Reading 2D image ... ";
119  Image2D anImportedImage2 = DGtal::GenericReader<Image2D>::import(filenameImage2);
120  trace.info() <<"[done]" << std::endl;
121  trace.info() << "Testing writing pgm ... ";
122  bool ok4 = anImportedImage2 >> "testGenericWriter.pgm";
123  trace.info() <<"[done]" << std::endl;
124  trace.info() << "Testing writing raw ... ";
125  bool ok5 = anImportedImage2 >> "testGenericWriter.raw";
126  trace.info() <<"[done]" << std::endl;
127  bool ok6 = DGtal::GenericWriter<Image3D32bits>::exportFile( "testGenericWriter32bits3D.raw", an32bitsImage3D);
128  trace.info() <<"[done]" << std::endl;
129  bool ok7 = DGtal::GenericWriter<Image2D32bits>::exportFile( "testGenericWriter32bits2D.raw", an32bitsImage2D);
130  trace.info() <<"[done]" << std::endl;
131  bool ok8 = DGtal::GenericWriter<Image2DColor>::exportFile( "testGenericWriterColorImage.ppm", anColorImage2D);
132  trace.info() <<"[done]" << std::endl;
133 #ifdef WITH_MAGICK
134  bool ok9 = DGtal::GenericWriter<Image2DColor>::exportFile( "testGenericWriterColorImage.png", anColorImage2D);
135 #else
136  bool ok9 = true;
137 #endif
138 
139  nbok += ((ok1 && okh5 && okh5bis && ok2 && ok3 && ok3bis && ok4 && ok5 && ok6 && ok7 && ok8 && ok9) ? 1 : 0);
140  nb++;
141  trace.info() << "(" << nbok << "/" << nb << ") "
142  << "true == true" << std::endl;
143  trace.endBlock();
144 
145  return nbok == nb;
146 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
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(), and DGtal::trace.

Referenced by main().