]> Creatis software - creaVtk.git/commitdiff
#3457 creaVtk Feature New Normal - new box VtkWriteLstImages
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 20 Jul 2020 13:23:51 +0000 (15:23 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 20 Jul 2020 13:23:51 +0000 (15:23 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkImageExtractComponents.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx [new file with mode: 0644]
bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h [new file with mode: 0644]

index 4d274db6cce66b378c23f577613cb62f390333ab..e4bd31866c3f97d80d2845152f331cba86d3a2c1 100644 (file)
@@ -107,15 +107,13 @@ void ImageExtractComponents::Process()
                        vtkImageExtractComponents* IEC;
                        IEC=vtkImageExtractComponents::New();  
                        IEC->SetInputData( bbGetInputIn() );
-                       IEC->SetComponents( bbGetInputComponent2() );
+                       IEC->SetComponents( i );
                        IEC->Update();
                        lstIEC.push_back( IEC);
                        lstOut.push_back( IEC->GetOutput() );
-                       IEC->Delete();
                } // for i
                bbSetOutputLstOut( lstOut ); 
        } // Type 1
-
 }
 
 //===== 
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx
new file mode 100644 (file)
index 0000000..973a7b7
--- /dev/null
@@ -0,0 +1,119 @@
+//===== 
+// 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 "bbcreaVtkWriteLstImages.h"
+#include "bbcreaVtkPackage.h"
+
+#include "vtkMetaImageWriter.h"
+#include <vtkNIFTIImageWriter.h>
+namespace bbcreaVtk
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,WriteLstImages)
+BBTK_BLACK_BOX_IMPLEMENTATION(WriteLstImages,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)
+//===== 
+void WriteLstImages::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')
+//    bbSetOutputOut( bbGetInputIn() );
+//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+
+
+printf("EED WriteLstImages::Process Start\n");
+       vtkImageData    *inImg;
+       std::string     txtNum;
+       int i,size=bbGetInputLstImages().size();
+       for (i=0;i<size;i++)
+       {
+printf("  EED WriteLstImages::Process i=%d\n",i );
+
+               txtNum=std::to_string(i);
+               while (txtNum.length()<=5) 
+               {
+                       txtNum="0"+txtNum;
+               } // while
+
+               inImg=bbGetInputLstImages()[i];
+               if (bbGetInputType()==0)  // mhd
+               {
+                       vtkMetaImageWriter* w = vtkMetaImageWriter::New();
+                       w->SetInputData( inImg );
+               w->SetCompression( bbGetInputCompression() );  
+                       w->SetFileDimensionality(inImg->GetDataDimension()); // NTU
+                       std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".mhd";
+                   w->SetFileName(filename.c_str());  
+                   w->Write();
+                       w->Delete();
+               } // Type
+
+               if (bbGetInputType()==1)  // NIFTI 
+               {
+                       vtkNIFTIImageWriter* w = vtkNIFTIImageWriter::New();
+                       w->SetInputData( inImg );
+                       std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".nii";
+                   w->SetFileName(filename.c_str());  
+                   w->Write();
+                       w->Delete();
+               } // Type
+
+
+
+       } // for i  
+printf("EED WriteLstImages::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)
+//===== 
+void WriteLstImages::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+       bbSetInputType(0);
+       bbSetInputCompression(false);
+       bbSetInputFileName("void");
+       bbSetInputOutputDir(".");
+}
+//===== 
+// 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 WriteLstImages::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 WriteLstImages::bbUserFinalizeProcessing()
+{
+
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any
+  
+}
+}
+// EO namespace bbcreaVtk
+
+
diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h b/bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.h
new file mode 100644 (file)
index 0000000..412b32f
--- /dev/null
@@ -0,0 +1,61 @@
+//===== 
+// 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 __bbcreaVtkWriteLstImages_h_INCLUDED__
+#define __bbcreaVtkWriteLstImages_h_INCLUDED__
+
+#include "bbcreaVtk_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+#include <vector>
+#include "vtkImageData.h"
+
+
+namespace bbcreaVtk
+{
+
+class bbcreaVtk_EXPORT WriteLstImages
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(WriteLstImages,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(Type,int);
+  BBTK_DECLARE_INPUT(OutputDir,std::string);
+  BBTK_DECLARE_INPUT(LstImages,std::vector< vtkImageData* >);
+  BBTK_DECLARE_INPUT(FileName,std::string);
+  BBTK_DECLARE_INPUT(Compression,bool);
+//  BBTK_DECLARE_OUTPUT(Out,double);
+  BBTK_PROCESS(Process);
+  void Process();
+//===== 
+// 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(WriteLstImages,bbtk::AtomicBlackBox);
+  BBTK_NAME("WriteLstImages");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+
+  BBTK_INPUT(WriteLstImages,Type,"(default 0)  0:mhd  1:nii",int,"");
+  BBTK_INPUT(WriteLstImages,OutputDir,"Output directory",std::string,"");
+  BBTK_INPUT(WriteLstImages,LstImages,"Lst of images",std::vector< vtkImageData* >,"");
+  BBTK_INPUT(WriteLstImages,FileName,"File name (no extension)",std::string,"");
+  BBTK_INPUT(WriteLstImages,Compression,"(Default false)  true/false  just for mhd",bool,"");
+
+//  BBTK_OUTPUT(WriteLstImages,Out,"First output",double,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(WriteLstImages);
+//===== 
+// 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 bbcreaVtk
+
+#endif // __bbcreaVtkWriteLstImages_h_INCLUDED__
+