X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fvtk%2Fsrc%2FbbvtkMetaImageWriter.cxx;h=6474b0adf745e0f96f58bb6c56ab3a8238940d58;hb=edb8e9b8948e7216e06b3ef5228b16f18417ca52;hp=140e6bb51dbfe76f0aeeb2f8df54cb4316f106e8;hpb=53a0182954e0416dfa5ea8c4a4d5ceba7ca9d472;p=bbtk.git diff --git a/packages/vtk/src/bbvtkMetaImageWriter.cxx b/packages/vtk/src/bbvtkMetaImageWriter.cxx index 140e6bb..6474b0a 100644 --- a/packages/vtk/src/bbvtkMetaImageWriter.cxx +++ b/packages/vtk/src/bbvtkMetaImageWriter.cxx @@ -7,6 +7,14 @@ #include #include +#include "vtkJSONImageWriter.h" +#include "vtkXMLImageDataWriter.h" +#include "vtkXMLDataSetWriter.h" +#include "vtkDataSetWriter.h" +#include "vtkPDataSetWriter.h" +#include "vtkXMLWriter.h" +#include + namespace bbvtk { @@ -20,28 +28,46 @@ void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int int i,j,k; int ext[6]; int dim[3]; - img->GetExtent(ext); - dim[0]=ext[1]-ext[0]+1; - dim[1]=ext[3]-ext[2]+1; - dim[2]=ext[5]-ext[4]+1; + int elementType=img->GetScalarType(); - int bsx=ceil((double)dim[0]/(double)sizeB); - int bsy=ceil((double)dim[1]/(double)sizeB); - int bsz=ceil((double)dim[2]/(double)sizeB); + img->GetExtent(ext); + dim[0] = ext[1]-ext[0]+1; + dim[1] = ext[3]-ext[2]+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; + std::string filenameBlockVti; + 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(),"w"); + 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=dim[0]) { voi[1]=dim[0]-1; } if (voi[3]>=dim[1]) { voi[3]=dim[1]-1; } if (voi[5]>=dim[2]) { voi[5]=dim[2]-1; } @@ -51,15 +77,26 @@ void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int extract->UpdateWholeExtent(); extract->Modified(); extract->Update(); + filenameBlock =filename+"/mhdb-"+ std::to_string(i)+"-"+ std::to_string(j)+"-"+ std::to_string(k)+".mha"; vtkMetaImageWriter* w = vtkMetaImageWriter::New(); 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() ); w->SetFileName( filenameBlock.c_str() ); w->Write(); w->Delete(); + +/* Borrame + filenameBlockVti=filenameBlock+"-ZLib.vti"; + vtkXMLImageDataWriter *writer = vtkXMLImageDataWriter::New(); + writer->SetDataModeToBinary(); +// writer->SetCompressionLevel(5); + writer->SetCompressorTypeToZLib(); + writer->SetFileName( filenameBlockVti.c_str() ); + writer->SetInputData( bbGetInputIn() ); + writer->Write(); +*/ + extract->Delete(); } // for k } // for j @@ -73,7 +110,6 @@ void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int //===== void MetaImageWriter::Process() { - // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value @@ -86,28 +122,23 @@ 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 + if (!((userGivenName.substr(userGivenName.size()-4) == ".mhd") || (userGivenName.substr(userGivenName.size()-4) == ".mha"))) //JPR { userGivenName += ".mhd"; - } + } vtkMetaImageWriter* w = vtkMetaImageWriter::New(); //EED 2017-01-01 Migration VTK7 #if VTK_MAJOR_VERSION <= 5 @@ -123,9 +154,8 @@ void MetaImageWriter::Process() w->Delete(); } // .mhdb } // bbGetInputIn()!=NULL - -printf("EED vtkMetaImageWriter::Process END\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) //===== @@ -135,34 +165,31 @@ 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) //===== void MetaImageWriter::bbUserInitializeProcessing() { - // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers -// if any - - +// if any } + //===== // 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) //===== void MetaImageWriter::bbUserFinalizeProcessing() { - // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any - } -} -// EO namespace bbvtk + +} // EO namespace bbvtk