]> Creatis software - bbtk.git/commitdiff
mhdb
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 29 Oct 2020 15:28:17 +0000 (16:28 +0100)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Thu, 29 Oct 2020 15:28:17 +0000 (16:28 +0100)
packages/vtk/src/bbvtkMetaImageReader.cxx
packages/vtk/src/bbvtkMetaImageReader.h
packages/vtk/src/bbvtkMetaImageWriter.cxx
packages/vtk/src/bbvtkMetaImageWriter.h

index f092643b7aecd9497ec6755d60c9f3c55d5d7d26..e035419cae47190b387bbaf2201cce774aacaa35 100644 (file)
@@ -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 = " <<bbGetOutputOut() << std::endl;
 
-       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());
+       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)
 //===== 
index 25d749d35da95922394e326513e4890935e8ffbd..66bc9cffb8c35139faa26d6c4284f3c6292877c3 100644 (file)
@@ -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)
 //===== 
index 140e6bb51dbfe76f0aeeb2f8df54cb4316f106e8..7478b1da0fd48a1fc6659d127ac0696c43aad320 100644 (file)
@@ -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;i<bsx;i++)
        {
                for (j=0;j<bsy;j++)
@@ -55,8 +72,7 @@ void MetaImageWriter::Save_mhdb( std::string filename  , vtkImageData* img ,int
                                w->SetInputData( 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)
index 37ec801fc71bfc8eea345c352a0c845ab9c91ab7..7ddd20dbb128cea0832e8fd846469d5e3cd3e7c5 100644 (file)
@@ -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,"");