2 // 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)
4 #include "bbvtkMetaImageWriter.h"
5 #include "bbvtkPackage.h"
7 #include <vtkExtractVOI.h>
8 #include <vtkMetaImageWriter.h>
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MetaImageWriter)
14 BBTK_BLACK_BOX_IMPLEMENTATION(MetaImageWriter,bbtk::AtomicBlackBox);
18 void MetaImageWriter::Save_mhdb( std::string filename , vtkImageData* img ,int sizeB)
24 dim[0]=ext[1]-ext[0]+1;
25 dim[1]=ext[3]-ext[2]+1;
26 dim[2]=ext[5]-ext[4]+1;
28 int bsx=ceil((double)dim[0]/(double)sizeB);
29 int bsy=ceil((double)dim[1]/(double)sizeB);
30 int bsz=ceil((double)dim[2]/(double)sizeB);
32 printf("EED MetaImageWriter::Save_mhdb bsx bsy bsz = %d %d %d\n", bsx,bsy,bsz);
33 printf("EED MetaImageWriter::Save_mhdb dim = %d %d %d\n", dim[0],dim[1],dim[2] );
36 std::string filenameBlock;
45 voi[1]=voi[0]+(sizeB-1);
47 voi[3]=voi[2]+(sizeB-1);
49 voi[5]=voi[4]+(sizeB-1);
59 if (voi[1]>=dim[0]) { voi[1]=dim[0]-1; }
60 if (voi[3]>=dim[1]) { voi[3]=dim[1]-1; }
61 if (voi[5]>=dim[2]) { voi[5]=dim[2]-1; }
63 vtkExtractVOI *extract = vtkExtractVOI::New();
64 extract->SetInputData( img );
66 extract->UpdateWholeExtent();
70 vtkMetaImageWriter* w = vtkMetaImageWriter::New();
71 w->SetInputData( extract->GetOutput() );
72 w->SetCompression(true);
73 w->SetFileDimensionality(bbGetInputIn()->GetDataDimension()); // NTU
74 filenameBlock=filename+"/a-"+ std::to_string(i)+"-"+ std::to_string(j)+"-"+ std::to_string(k)+".mhd";
75 printf("EED MetaImageWriter::Save_mhdb name = %s \n", filenameBlock.c_str() );
76 w->SetFileName( filenameBlock.c_str() );
91 // 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)
93 void MetaImageWriter::Process()
96 // THE MAIN PROCESSING METHOD BODY
97 // Here we simply set the input 'In' value to the output 'Out'
98 // And print out the output value
99 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
100 // void bbSet{Input|Output}NAME(const TYPE&)
101 // const TYPE& bbGet{Input|Output}NAME() const
103 // * NAME is the name of the input/output
104 // (the one provided in the attribute 'name' of the tag 'input')
105 // * TYPE is the C++ type of the input/output
106 // (the one provided in the attribute 'type' of the tag 'input')
109 //EED 2017-01-01 Migration VTK7
110 #if VTK_MAJOR_VERSION <= 5
111 bbGetInputIn()->Update();
116 std::string userGivenName = bbGetInputFilename();
117 if (bbGetInputIn()!=NULL)
119 if (userGivenName.substr(userGivenName.size()-5) == ".mhdb")
121 printf("EED vtkMetaImageWriter process block..ups\n");
123 Save_mhdb( userGivenName , bbGetInputIn() , 20 );
126 if (userGivenName.substr(userGivenName.size()-4) != ".mhd") //JPR
128 userGivenName += ".mhd";
130 vtkMetaImageWriter* w = vtkMetaImageWriter::New();
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
133 w->SetInput(bbGetInputIn());
135 w->SetInputData(bbGetInputIn());
137 w->SetCompression(bbGetInputCompression());
138 w->SetFileDimensionality(bbGetInputIn()->GetDataDimension()); // NTU
139 w->SetFileName(userGivenName.c_str());
140 //w->SetFileName(bbGetInputFilename().c_str()); // JPR
144 } // bbGetInputIn()!=NULL
149 // 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)
151 void MetaImageWriter::bbUserSetDefaultValues()
154 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
155 // Here we initialize the input 'In' to 0
156 bbSetInputCompression(false);
160 // 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)
162 void MetaImageWriter::bbUserInitializeProcessing()
165 // THE INITIALIZATION METHOD BODY :
167 // but this is where you should allocate the internal/output pointers
173 // 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)
175 void MetaImageWriter::bbUserFinalizeProcessing()
178 // THE FINALIZATION METHOD BODY :
180 // but this is where you should desallocate the internal/output pointers
185 // EO namespace bbvtk