]> Creatis software - bbtk.git/commitdiff
MetaImageWriter Block
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Wed, 28 Oct 2020 16:06:05 +0000 (17:06 +0100)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Wed, 28 Oct 2020 16:06:05 +0000 (17:06 +0100)
packages/vtk/src/bbvtkExtractVtkImageFilter.cxx
packages/vtk/src/bbvtkMetaImageWriter.cxx [new file with mode: 0644]
packages/vtk/src/bbvtkMetaImageWriter.h [new file with mode: 0644]
packages/vtk/src/bbvtkMetaImageWriter.xml [deleted file]

index 21934235fe84b9e2126d4c9dfa11f49160fcd170..30ca25a508d7d6005997cf524b2e614fef4124ca 100644 (file)
@@ -88,7 +88,7 @@ void ExtractVtkImageFilter::bbUserSetDefaultValues()
        bbSetInputIndex(tmpIndex);
        bbSetInputSize(tmpSize);
        
-       bbSetOutputOut(0);
+       bbSetOutputOut(NULL);
   
 }
 //===== 
diff --git a/packages/vtk/src/bbvtkMetaImageWriter.cxx b/packages/vtk/src/bbvtkMetaImageWriter.cxx
new file mode 100644 (file)
index 0000000..3be4743
--- /dev/null
@@ -0,0 +1,187 @@
+//===== 
+// 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)
+//===== 
+#include "bbvtkMetaImageWriter.h"
+#include "bbvtkPackage.h"
+
+#include <vtkExtractVOI.h> 
+#include <vtkMetaImageWriter.h> 
+
+namespace bbvtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MetaImageWriter)
+BBTK_BLACK_BOX_IMPLEMENTATION(MetaImageWriter,bbtk::AtomicBlackBox);
+
+
+
+void MetaImageWriter::Save_mhdb( std::string filename  , vtkImageData* img ,int sizeB)
+{
+       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 bsx=ceil((double)dim[0]/(double)sizeB);
+       int bsy=ceil((double)dim[1]/(double)sizeB);
+       int bsz=ceil((double)dim[2]/(double)sizeB);
+       
+       printf("EED MetaImageWriter::Save_mhdb  bsx bsy bsz  = %d %d %d\n", bsx,bsy,bsz);       
+       printf("EED MetaImageWriter::Save_mhdb  dim          = %d %d %d\n", dim[0],dim[1],dim[2]  );
+       
+       int voi[6];
+       std::string filenameBlock;
+       
+       for (i=0;i<bsx;i++)
+       {
+               for (j=0;j<bsy;j++)
+               {
+                       for (k=0;k<bsz;k++)
+                       {
+                               voi[0]=i*sizeB;
+                               voi[1]=voi[0]+(sizeB-1);
+                               voi[2]=j*sizeB;
+                               voi[3]=voi[2]+(sizeB-1);
+                               voi[4]=k*sizeB;
+                               voi[5]=voi[4]+(sizeB-1);
+
+/*
+                               voi[0]=0;
+                               voi[1]=10;
+                               voi[2]=0;
+                               voi[3]=10;
+                               voi[4]=0;
+                               voi[5]=10;
+       */              
+                               if (voi[1]>=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; } 
+                               
+                               vtkExtractVOI *extract = vtkExtractVOI::New();
+                               extract->SetInputData( img );
+                               extract->SetVOI(voi);   
+                               extract->UpdateWholeExtent();
+                               extract->Modified();
+                               extract->Update();
+
+                               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();
+                               extract->Delete();
+                       } // for k
+               } // for j
+       } // for i
+       
+               
+}
+
+
+
+//===== 
+// 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::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+//   Here we simply set the input 'In' value to the output 'Out'
+//   And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+//    void bbSet{Input|Output}NAME(const TYPE&)
+//    const TYPE& bbGet{Input|Output}NAME() const 
+//    Where :
+//    * NAME is the name of the input/output
+//      (the one provided in the attribute 'name' of the tag 'input')
+//    * 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() , 20 );
+                       
+               } else {
+                               if (userGivenName.substr(userGivenName.size()-4) != ".mhd")  //JPR
+                               { 
+                                       userGivenName += ".mhd";
+                               }
+                          vtkMetaImageWriter* w = vtkMetaImageWriter::New();
+       //EED 2017-01-01 Migration VTK7
+       #if VTK_MAJOR_VERSION <= 5
+                                w->SetInput(bbGetInputIn());
+       #else
+                                w->SetInputData(bbGetInputIn());
+       #endif
+                                w->SetCompression(bbGetInputCompression());  
+                                w->SetFileDimensionality(bbGetInputIn()->GetDataDimension());  // NTU
+                                w->SetFileName(userGivenName.c_str());  
+                                //w->SetFileName(bbGetInputFilename().c_str());                                // JPR
+                                w->Write();
+                                w->Delete();
+               } // .mhdb
+       } // bbGetInputIn()!=NULL
+
+  
+}
+//===== 
+// 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::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+   bbSetInputCompression(false);
+  
+}
+//===== 
+// 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 
+
+  
+}
+//===== 
+// 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
+
+
diff --git a/packages/vtk/src/bbvtkMetaImageWriter.h b/packages/vtk/src/bbvtkMetaImageWriter.h
new file mode 100644 (file)
index 0000000..37ec801
--- /dev/null
@@ -0,0 +1,59 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbvtkMetaImageWriter_h_INCLUDED__
+#define __bbvtkMetaImageWriter_h_INCLUDED__
+
+#include "bbvtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include <vtkImageData.h> 
+
+
+namespace bbvtk
+{
+
+class bbvtk_EXPORT MetaImageWriter
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(MetaImageWriter,bbtk::AtomicBlackBox);
+//===== 
+// 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)
+//===== 
+  BBTK_DECLARE_INPUT(In,vtkImageData*);
+  BBTK_DECLARE_INPUT(Filename,std::string);
+  BBTK_DECLARE_INPUT(Compression,bool);
+//  BBTK_DECLARE_OUTPUT(Out,double);
+  BBTK_PROCESS(Process);
+  void Process();
+  
+void Save_mhdb( std::string filename  , vtkImageData* img , int sizeB);
+  
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(MetaImageWriter,bbtk::AtomicBlackBox);
+  BBTK_NAME("MetaImageWriter");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+
+  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_OUTPUT(MetaImageWriter,Out,"First output",double,"");
+  
+BBTK_END_DESCRIBE_BLACK_BOX(MetaImageWriter);
+//===== 
+// 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)
+//===== 
+}
+// EO namespace bbvtk
+
+#endif // __bbvtkMetaImageWriter_h_INCLUDED__
+
diff --git a/packages/vtk/src/bbvtkMetaImageWriter.xml b/packages/vtk/src/bbvtkMetaImageWriter.xml
deleted file mode 100644 (file)
index 7093390..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-
-<blackbox name="MetaImageWriter" type="VTK_ImageAlgorithm">
-
-<author>laurent.guigues at creatis.insa-lyon.fr</author>
-<description><PRE>Writes .mhd / .mhd image formats (bbfication of vtkMetaImageWriter)</PRE></description>
-<category>image;read/write</category>
-
-<include>vtkMetaImageWriter.h</include> 
-<include>vtkImageData.h</include>
-
-<vtkobject>vtkMetaImageWriter</vtkobject> 
-
-<input name="Filename"  type="std::string"   nature="file name"   description="Name of the file to write"/>  
-<input name="In" type="vtkImageData*" description="Input image" />
-<input name="Compression" type="bool" description="default(false)   true/false" />
- <process><PRE>
-
-
-
-//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..\n");
-               } else {
-                               if (userGivenName.substr(userGivenName.size()-4) != ".mhd")  //JPR
-                               { 
-                                       userGivenName += ".mhd";
-                               }
-                          vtkMetaImageWriter* w = vtkMetaImageWriter::New();
-       //EED 2017-01-01 Migration VTK7
-       #if VTK_MAJOR_VERSION <= 5
-                                w->SetInput(bbGetInputIn());
-       #else
-                                w->SetInputData(bbGetInputIn());
-       #endif
-                                w->SetCompression(bbGetInputCompression());  
-                                w->SetFileDimensionality(bbGetInputIn()->GetDataDimension());  // NTU
-                                w->SetFileName(userGivenName.c_str());  
-                                //w->SetFileName(bbGetInputFilename().c_str());                                // JPR
-                                w->Write();
-                                w->Delete();
-               } // .mhdb
-       } // bbGetInputIn()!=NULL
- </PRE></process>
-
- <defaultValues>
-  <PRE>
-    bbSetInputCompression(false);
-  </PRE>
-  </defaultValues>
-
-
-</blackbox>  
-