Mercurial > hg > minc-tools
changeset 2639:81e021d5b096
Fixed bug withing minc_1_writer::close()
author | Vladimir S. FONOV <vladimir.fonov@gmail.com> |
---|---|
date | Tue, 13 Mar 2012 16:08:20 -0400 |
parents | 9a50bb928cad |
children | 55857e335f55 |
files | CMakeLists.txt ezminc/examples/trilinear_resample.cpp ezminc/minc_1_rw.cpp ezminc/minc_1_rw.h |
diffstat | 4 files changed, 61 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,15 +61,16 @@ IF(ITKHDF5_LOADED) message(WARNING "ITK compiled with HDF5 support!") SET(USE_ITK_HDF5 ON) + ELSE(ITKHDF5_LOADED) + SET(USE_ITK_HDF5 OFF) ENDIF(ITKHDF5_LOADED) ELSE(ITK_FOUND AND ITK_VERSION_MAJOR VERSION_EQUAL 4) # check if using ITK HDF5 library - + SET(USE_ITK_HDF5 OFF) IF(ENABLE_SUPERBUILD) OPTION(USE_SYSTEM_HDF5 "Use System HDF5 > 1.8" ON) ELSE(ENABLE_SUPERBUILD) SET(USE_SYSTEM_HDF5 ON) ENDIF(ENABLE_SUPERBUILD) - ENDIF(ITK_FOUND AND ITK_VERSION_MAJOR VERSION_EQUAL 4) # check if using ITK HDF5 library ENDIF(BUILD_MINC2)
--- a/ezminc/examples/trilinear_resample.cpp +++ b/ezminc/examples/trilinear_resample.cpp @@ -120,6 +120,7 @@ minc_1_writer wrt; wrt.open(argv[optind+1],new_info,2,NC_FLOAT); save_simple_volume<float>(wrt,output_vol); + //wrt.close(); } catch (const minc::generic_error & err) { std::cerr << "Got an error at:" << err.file () << ":" << err.line () << std::endl; std::cerr << err.msg()<<std::endl;
--- a/ezminc/minc_1_rw.cpp +++ b/ezminc/minc_1_rw.cpp @@ -598,10 +598,19 @@ } } - minc_1_reader::~minc_1_reader() + void minc_1_reader::close(void) { if(_have_temp_file) remove(_tempfile.c_str()); + + _have_temp_file=false; + + minc_1_base::close(); + } + + minc_1_reader::~minc_1_reader() + { + close(); } minc_1_writer::minc_1_writer(): @@ -1310,8 +1319,8 @@ } miicv_put(_icvid, &_cur[0], &_slab[0], buffer); } - - minc_1_writer::~minc_1_writer() + + void minc_1_writer::close(void) { if(_set_image_range) { @@ -1319,6 +1328,13 @@ mivarput1(_mincid, _icmax, 0, NC_DOUBLE, NULL, &_image_range[1]); miset_valid_range(_mincid, _imgid, _image_range); } + minc_1_base::close(); + } + + + minc_1_writer::~minc_1_writer() + { + close(); } void minc_1_writer::copy_headers(const minc_1_base& src)
--- a/ezminc/minc_1_rw.h +++ b/ezminc/minc_1_rw.h @@ -108,7 +108,7 @@ virtual ~minc_1_base(); //! close the minc file - virtual void close(); + virtual void close(void); //! is last slice was read? bool last(void) const @@ -157,7 +157,7 @@ const dim_info& dim(unsigned int n) const { if(n>=static_cast<unsigned int>(_ndims)) - REPORT_ERROR("Dimension is not defined"); + REPORT_ERROR("Dimension is not defined"); return _info[n]; } @@ -324,10 +324,18 @@ //! default constructor minc_1_reader(); + + //! close the minc file + virtual void close(void); //! destructor virtual ~minc_1_reader(); + //! open a minc file + //! \param path - path to existing minc file + //! \param positive_directions - make all step sizes positive + //! \param metadate_only - file is opened only for the purpose of reading metadata (will save memory) + //! \param rw - file headers may be modified void open(const char *path,bool positive_directions=false,bool metadate_only=false,bool rw=false); //! read single slice @@ -357,33 +365,59 @@ bool _calc_min_max; bool _write_prepared; public: + //! open minc file for writing - will overwrite existing + //! \param path - path to minc file + //! \param inf - information about dimensions + //! \param slice_dimensions - number of dimensions per slice (used for storage) + //! \param datatype - storage datatype + //! \param __signed - check if datatype will be signed or not void open(const char *path,const minc_info& inf,int slice_dimensions,nc_type datatype,int __signed=0); + + //! open minc file for writing - will overwrite existing + //! \param path - path to minc file + //! \param imitate - all information is copied from this opened minc file void open(const char *path,const minc_1_base& imitate); + + //! open minc file for writing - will overwrite existing + //! \param path - path to minc file + //! \param imitate_file - all information is copied from this existing minc file void open(const char *path,const char *imitate_file); + //! prepare for writing float array void setup_write_float(void); + //! prepare for writing double array void setup_write_double(void); + //! prepare for writing short array void setup_write_short(bool normalize=false); + //! prepare for writing unsigned short array void setup_write_ushort(bool normalize=false); + //! prepare for writing unsigned char array void setup_write_byte(bool normalize=false); + //! prepare for writing int array void setup_write_int(bool normalize=false); + //! prepare for writing unsigned int array void setup_write_uint(bool normalize=false); //! copy header from another minc file + //! \param src - path to existing minc file void copy_headers(const minc_1_base& src); //! append a line into minc history + //! \param append_history - history line to append void append_history(const char *append_history); - - //! constructor + //! default constructor minc_1_writer(); + //! make a copy of another writer minc_1_writer(const minc_1_writer&); //! destructor virtual ~minc_1_writer(); + //! close the minc file + virtual void close(void); + //!write a single slice, size of the buffer should be more or equall to slab_len void write(void* slice); };