From: Eduardo DAVILA Date: Thu, 29 Oct 2020 15:28:17 +0000 (+0100) Subject: mhdb X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ebc770e3c035927e1b6f2d78f85b31ce7242f69b;p=bbtk.git mhdb --- diff --git a/packages/vtk/src/bbvtkMetaImageReader.cxx b/packages/vtk/src/bbvtkMetaImageReader.cxx index f092643..e035419 100644 --- a/packages/vtk/src/bbvtkMetaImageReader.cxx +++ b/packages/vtk/src/bbvtkMetaImageReader.cxx @@ -11,6 +11,14 @@ namespace bbvtk BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MetaImageReader) BBTK_BLACK_BOX_IMPLEMENTATION(MetaImageReader,bbtk::AtomicBlackBox); + + +void MetaImageReader::Read_mhdb( std::string filename ) +{ + printf("EED MetaImageReader::Read_mhdb \n"); +} + + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== @@ -32,18 +40,24 @@ void MetaImageReader::Process() // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " <SetFileName(bbGetInputIn().c_str()); - reader->Update(); - bbSetOutputOut(reader->GetOutput()); + if (bbGetInputIn().substr(bbGetInputIn().size()-5) == ".mhdb") + { + Read_mhdb( bbGetInputIn() ); } else { + FILE *ff = fopen( bbGetInputIn().c_str() , "r" ); + if (ff) + { + fclose(ff); + vtkMetaImageReader *reader = vtkMetaImageReader::New(); + reader->SetFileName( bbGetInputIn().c_str() ); + reader->Update(); + bbSetOutputOut( reader->GetOutput() ); + } else { bbSetOutputOut(NULL); - } + } // ff + }// .mhdb } + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== diff --git a/packages/vtk/src/bbvtkMetaImageReader.h b/packages/vtk/src/bbvtkMetaImageReader.h index 25d749d..66bc9cf 100644 --- a/packages/vtk/src/bbvtkMetaImageReader.h +++ b/packages/vtk/src/bbvtkMetaImageReader.h @@ -24,6 +24,7 @@ class bbvtk_EXPORT MetaImageReader BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); void Process(); + void Read_mhdb( std::string filename ); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== diff --git a/packages/vtk/src/bbvtkMetaImageWriter.cxx b/packages/vtk/src/bbvtkMetaImageWriter.cxx index 140e6bb..7478b1d 100644 --- a/packages/vtk/src/bbvtkMetaImageWriter.cxx +++ b/packages/vtk/src/bbvtkMetaImageWriter.cxx @@ -20,16 +20,33 @@ void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int int i,j,k; int ext[6]; int dim[3]; + int elementType=img->GetScalarType(); + img->GetExtent(ext); dim[0]=ext[1]-ext[0]+1; dim[1]=ext[3]-ext[2]+1; - dim[2]=ext[5]-ext[4]+1; - + dim[2]=ext[5]-ext[4]+1; int bsx=ceil((double)dim[0]/(double)sizeB); int bsy=ceil((double)dim[1]/(double)sizeB); int bsz=ceil((double)dim[2]/(double)sizeB); int voi[6]; std::string filenameBlock; + if (filename.substr(filename.size()-5) == ".mhdb") + { + std::string cmd; + cmd="rm -rf "+filename; + system( cmd.c_str() ); + cmd="mkdir "+filename; + system( cmd.c_str() ); + } + + std::string fileinfoname=filename+"/info.dat"; + FILE *ff=fopen(fileinfoname.c_str(),"r"); + fprintf(ff,"SizeBlock = %d\n",sizeB); + fprintf(ff,"DimSize = %d %d %d\n" , dim[0],dim[1],dim[2] ); + fprintf(ff,"ElementType = %d\n", elementType ); + fclose(ff); + for (i=0;iSetInputData( extract->GetOutput() ); w->SetCompression(true); w->SetFileDimensionality(bbGetInputIn()->GetDataDimension()); // NTU - filenameBlock=filename+"/a-"+ std::to_string(i)+"-"+ std::to_string(j)+"-"+ std::to_string(k)+".mhd"; -// printf("EED MetaImageWriter::Save_mhdb name = %s \n", filenameBlock.c_str() ); + filenameBlock=filename+"/mhdb-"+ std::to_string(i)+"-"+ std::to_string(j)+"-"+ std::to_string(k)+".mhd"; w->SetFileName( filenameBlock.c_str() ); w->Write(); w->Delete(); @@ -74,6 +90,8 @@ void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int void MetaImageWriter::Process() { +printf("EED vtkMetaImageWriter::Process START\n"); + // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value @@ -86,23 +104,18 @@ void MetaImageWriter::Process() // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') - //EED 2017-01-01 Migration VTK7 #if VTK_MAJOR_VERSION <= 5 bbGetInputIn()->Update(); #else // ... #endif - std::string userGivenName = bbGetInputFilename(); if (bbGetInputIn()!=NULL) { if (userGivenName.substr(userGivenName.size()-5) == ".mhdb") { - printf("EED vtkMetaImageWriter::Process block..ups\n"); - - Save_mhdb( userGivenName , bbGetInputIn() , 40 ); - + Save_mhdb( userGivenName , bbGetInputIn() , bbGetInputSizeBlock() ); } else { if (userGivenName.substr(userGivenName.size()-4) != ".mhd") //JPR { @@ -123,7 +136,6 @@ void MetaImageWriter::Process() w->Delete(); } // .mhdb } // bbGetInputIn()!=NULL - printf("EED vtkMetaImageWriter::Process END\n"); } //===== @@ -135,7 +147,7 @@ void MetaImageWriter::bbUserSetDefaultValues() // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 bbSetInputCompression(false); - + bbSetInputSizeBlock(20); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/packages/vtk/src/bbvtkMetaImageWriter.h b/packages/vtk/src/bbvtkMetaImageWriter.h index 37ec801..7ddd20d 100644 --- a/packages/vtk/src/bbvtkMetaImageWriter.h +++ b/packages/vtk/src/bbvtkMetaImageWriter.h @@ -25,6 +25,7 @@ class bbvtk_EXPORT MetaImageWriter BBTK_DECLARE_INPUT(In,vtkImageData*); BBTK_DECLARE_INPUT(Filename,std::string); BBTK_DECLARE_INPUT(Compression,bool); + BBTK_DECLARE_INPUT(SizeBlock,int); // BBTK_DECLARE_OUTPUT(Out,double); BBTK_PROCESS(Process); void Process(); @@ -45,6 +46,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(MetaImageWriter,bbtk::AtomicBlackBox); BBTK_INPUT(MetaImageWriter,In,"Input image",vtkImageData*,""); BBTK_INPUT(MetaImageWriter,Filename,"Name of the file to write",std::string,"file name"); BBTK_INPUT(MetaImageWriter,Compression,"default(false) true/false",bool,""); + BBTK_INPUT(MetaImageWriter,SizeBlock,"(default 50) Size block (for .mhdb format)",int,""); //BBTK_OUTPUT(MetaImageWriter,Out,"First output",double,"");