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)
23 int elementType=img->GetScalarType();
26 dim[0]=ext[1]-ext[0]+1;
27 dim[1]=ext[3]-ext[2]+1;
28 dim[2]=ext[5]-ext[4]+1;
29 int bsx=ceil((double)dim[0]/(double)sizeB);
30 int bsy=ceil((double)dim[1]/(double)sizeB);
31 int bsz=ceil((double)dim[2]/(double)sizeB);
33 std::string filenameBlock;
34 if (filename.substr(filename.size()-5) == ".mhdb")
37 cmd="rm -rf "+filename;
38 system( cmd.c_str() );
39 cmd="mkdir "+filename;
40 system( cmd.c_str() );
43 std::string fileinfoname=filename+"/info.dat";
44 FILE *ff=fopen(fileinfoname.c_str(),"r");
45 fprintf(ff,"SizeBlock = %d\n",sizeB);
46 fprintf(ff,"DimSize = %d %d %d\n" , dim[0],dim[1],dim[2] );
47 fprintf(ff,"ElementType = %d\n", elementType );
57 voi[1]=voi[0]+(sizeB-1);
59 voi[3]=voi[2]+(sizeB-1);
61 voi[5]=voi[4]+(sizeB-1);
62 if (voi[1]>=dim[0]) { voi[1]=dim[0]-1; }
63 if (voi[3]>=dim[1]) { voi[3]=dim[1]-1; }
64 if (voi[5]>=dim[2]) { voi[5]=dim[2]-1; }
65 vtkExtractVOI *extract = vtkExtractVOI::New();
66 extract->SetInputData( img );
68 extract->UpdateWholeExtent();
71 vtkMetaImageWriter* w = vtkMetaImageWriter::New();
72 w->SetInputData( extract->GetOutput() );
73 w->SetCompression(true);
74 w->SetFileDimensionality(bbGetInputIn()->GetDataDimension()); // NTU
75 filenameBlock=filename+"/mhdb-"+ std::to_string(i)+"-"+ std::to_string(j)+"-"+ std::to_string(k)+".mhd";
76 w->SetFileName( filenameBlock.c_str() );
88 // 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)
90 void MetaImageWriter::Process()
93 printf("EED vtkMetaImageWriter::Process START\n");
95 // THE MAIN PROCESSING METHOD BODY
96 // Here we simply set the input 'In' value to the output 'Out'
97 // And print out the output value
98 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
99 // void bbSet{Input|Output}NAME(const TYPE&)
100 // const TYPE& bbGet{Input|Output}NAME() const
102 // * NAME is the name of the input/output
103 // (the one provided in the attribute 'name' of the tag 'input')
104 // * TYPE is the C++ type of the input/output
105 // (the one provided in the attribute 'type' of the tag 'input')
107 //EED 2017-01-01 Migration VTK7
108 #if VTK_MAJOR_VERSION <= 5
109 bbGetInputIn()->Update();
113 std::string userGivenName = bbGetInputFilename();
114 if (bbGetInputIn()!=NULL)
116 if (userGivenName.substr(userGivenName.size()-5) == ".mhdb")
118 Save_mhdb( userGivenName , bbGetInputIn() , bbGetInputSizeBlock() );
120 if (userGivenName.substr(userGivenName.size()-4) != ".mhd") //JPR
122 userGivenName += ".mhd";
124 vtkMetaImageWriter* w = vtkMetaImageWriter::New();
125 //EED 2017-01-01 Migration VTK7
126 #if VTK_MAJOR_VERSION <= 5
127 w->SetInput(bbGetInputIn());
129 w->SetInputData(bbGetInputIn());
131 w->SetCompression(bbGetInputCompression());
132 w->SetFileDimensionality(bbGetInputIn()->GetDataDimension()); // NTU
133 w->SetFileName(userGivenName.c_str());
134 //w->SetFileName(bbGetInputFilename().c_str()); // JPR
138 } // bbGetInputIn()!=NULL
139 printf("EED vtkMetaImageWriter::Process END\n");
142 // 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)
144 void MetaImageWriter::bbUserSetDefaultValues()
147 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
148 // Here we initialize the input 'In' to 0
149 bbSetInputCompression(false);
150 bbSetInputSizeBlock(20);
153 // 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)
155 void MetaImageWriter::bbUserInitializeProcessing()
158 // THE INITIALIZATION METHOD BODY :
160 // but this is where you should allocate the internal/output pointers
166 // 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)
168 void MetaImageWriter::bbUserFinalizeProcessing()
171 // THE FINALIZATION METHOD BODY :
173 // but this is where you should desallocate the internal/output pointers
178 // EO namespace bbvtk