]> Creatis software - clitk.git/commitdiff
Update clitkProfileImage Tool
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 9 May 2017 08:03:43 +0000 (10:03 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 9 May 2017 08:03:43 +0000 (10:03 +0200)
Add output to the tool (like with the GUI)
Change the first and second input to vox (correct now)

tools/clitkProfileImage.ggo
tools/clitkProfileImageGenericFilter.cxx
tools/clitkProfileImageGenericFilter.h
vv/vvToolProfile.cxx

index 773790dcf0a13a195bd813d238d89a51734af086..9f3f443bc596e40a858078523d23e236de35c0c4 100644 (file)
@@ -9,8 +9,8 @@ option "imagetypes" -   "Display allowed image types"   flag    off
 
 option "input"      i   "Input image filename"          string  yes
 option "output"     o   "Output texte filename"         string  yes
-option "point1"     f   "First point (mm)"              double     yes multiple(-4)
-option "point2"     s   "Second point (mm)"             double     yes multiple(-4)
+option "point1"     f   "First point (vox)"              double     yes multiple(-4)
+option "point2"     s   "Second point (vox)"             double     yes multiple(-4)
 
 
 
index 02394d3ca60231943e534a5d036dcf0911cd224a..6c81756fbcf7adf9a3f51bfa0ad7fd753a73431f 100644 (file)
@@ -120,6 +120,9 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
   mArrayY = vtkSmartPointer<vtkFloatArray>::New();
   mCoord = vtkSmartPointer<vtkFloatArray>::New();
   mCoord->SetNumberOfComponents(InputImageType::ImageDimension);
+  mCoordmm = vtkSmartPointer<vtkFloatArray>::New();
+  mCoordmm->SetNumberOfComponents(InputImageType::ImageDimension);
+  mDimension = InputImageType::ImageDimension;
   
   /*typename InputImageType::Pointer outputImage;
   outputImage = InputImageType::New();
@@ -162,11 +165,20 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
     // Fill in the table the distance value
     mArrayX->InsertNextTuple1(distance);
     
-    // Fille in the table the voxel coordinate value
-    mCoord->InsertNextTuple(tuple);
+    // Fill in the table the voxel coordinate value
+    mCoord->InsertNextTuple(tuple); //index
+    for (int i=0; i<InputImageType::ImageDimension; ++i) {
+        tuple[i] = transformedCurrentPoint[i];
+    }
+    mCoordmm->InsertNextTuple(tuple); //mm
     ++lineNumber;
     ++itProfile;
   }
+
+  if (mArgsInfo.output_given) {
+    std::string str(mArgsInfo.output_arg);
+    this->WriteOutput(str);
+  }
   
   /*
   itk::LineIterator<InputImageType> otProfile(outputImage, pointBegin, pointEnd);
@@ -184,6 +196,58 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+void ProfileImageGenericFilter::WriteOutput(std::string outputFilename)
+{
+  ofstream fileOpen(outputFilename.c_str(), std::ofstream::trunc);
+
+  if(!fileOpen) {
+      cerr << "Error during saving" << endl;
+      return;
+  }
+
+  double *tuple;
+  tuple = new double[mDimension];
+  int i(0);
+  fileOpen << "The Bresenham algorithm is used to travel along the line. Values represent the center of each crossed voxel (in voxel and mm)" << endl;
+  fileOpen << "Id" << "\t" << "Value" << "\t" ;
+  fileOpen << "x(vox)" << "\t" << "y(vox)" << "\t";
+  if (mDimension >=3)
+      fileOpen << "z(vox)" << "\t";
+  if (mDimension >=4)
+      fileOpen << "t" << "\t";
+  fileOpen << "x(mm)" << "\t" << "y(mm)" << "\t";
+  if (mDimension >=3)
+      fileOpen << "z(mm)" << "\t";
+  if (mDimension >=4)
+      fileOpen << "t" << "\t";
+  fileOpen << endl;
+
+  while (i<mArrayX->GetNumberOfTuples()) {
+      fileOpen << i << "\t" << mArrayY->GetTuple(i)[0] << "\t" ;
+
+      mCoord->GetTuple(i, tuple);
+      for (int j=0; j<mDimension ; ++j) {
+          fileOpen << tuple[j] << "\t" ;
+      }
+      mCoordmm->GetTuple(i, tuple);
+      for (int j=0; j<mDimension ; ++j) {
+          fileOpen << tuple[j] << "\t" ;
+      }
+      if (mDimension == 4) {
+          fileOpen << tuple[3] << "\t" ;
+      }
+      fileOpen << endl;
+      ++i;
+  }
+
+  delete [] tuple;
+
+  fileOpen.close();
+}
+//--------------------------------------------------------------------
+
+
 }//end clitk
 
 #endif  //#define clitkProfileImageGenericFilter_cxx
index 573a41ca62b2a487908565ec9069f51574d1de0b..e22ed74206018bac0dad4f8d67d66f2512813daa 100644 (file)
@@ -23,7 +23,6 @@
 #include "clitkImageToImageGenericFilter.h"
 #include "clitkProfileImage_ggo.h"
 
-#include <vtkIntArray.h>
 #include <vtkFloatArray.h>
 
 //--------------------------------------------------------------------
@@ -59,6 +58,9 @@ namespace clitk
     vtkFloatArray* GetArrayY();
     vtkFloatArray* GetCoord();
 
+    //Write the output in the txt file
+    void WriteOutput(std::string outputFilename);
+
   protected:
     ProfileImageGenericFilter();
     template<unsigned int Dim> void InitializeImageType();
@@ -68,6 +70,8 @@ namespace clitk
     vtkSmartPointer<vtkFloatArray> mArrayX;
     vtkSmartPointer<vtkFloatArray> mArrayY;
     vtkSmartPointer<vtkFloatArray> mCoord;
+    vtkSmartPointer<vtkFloatArray> mCoordmm;
+    int mDimension;
     
     
   }; // end class
index e0ebdf1c14f283e7795a54e4adfbecaec5cf0ce8..7ef23101a2ab9d5d0263caad118f0c09a6120e73 100644 (file)
@@ -511,50 +511,8 @@ void vvToolProfile::SaveAs()
             close();
             return;
         }
-        
-        vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
-        vtkSmartPointer<vtkFloatArray> arrY = vtkSmartPointer<vtkFloatArray>::New();
-        vtkSmartPointer<vtkFloatArray> coords = vtkSmartPointer<vtkFloatArray>::New();
-        arrX = mFilter->GetArrayX();
-        arrY = mFilter->GetArrayY();
-        coords = mFilter->GetCoord();
-        double *tuple;
-        tuple = new double[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
-        int i(0);
-        fileOpen << "The Bresenham algorithm is used to travel along the line. Values represent the center of each crossed voxel (in voxel and mm)" << endl;
-        fileOpen << "Id" << "\t" << "Value" << "\t" ;
-        fileOpen << "x(vox)" << "\t" << "y(vox)" << "\t";
-        if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() >=3)
-            fileOpen << "z(vox)" << "\t";
-        if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() >=4)
-            fileOpen << "t" << "\t";
-        fileOpen << "x(mm)" << "\t" << "y(mm)" << "\t";
-        if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() >=3)
-            fileOpen << "z(mm)" << "\t";
-        if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() >=4)
-            fileOpen << "t" << "\t";
-        fileOpen << endl;
-   
-        while (i<arrX->GetNumberOfTuples()) {
-            fileOpen << i << "\t" << arrY->GetTuple(i)[0] << "\t" ;
-      
-            coords->GetTuple(i, tuple);
-            for (int j=0; j<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() ; ++j) {
-                fileOpen << tuple[j] << "\t" ;
-            }
-            int j(0);
-            while (j<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() && j<3) {
-                fileOpen << tuple[j]*mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetImage()->GetVTKImages()[mCurrentSlicerManager->GetTSlice()]->GetSpacing()[j]+mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetImage()->GetVTKImages()[mCurrentSlicerManager->GetTSlice()]->GetOrigin()[j] << "\t" ;
-                ++j;
-            }
-            if (mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() == 4) {
-                fileOpen << tuple[3] << "\t" ;
-            }
-            fileOpen << endl;
-            ++i;
-        }
-  
-        delete [] tuple;
+
+        mFilter->WriteOutput(mTextFileName.c_str());
 
         fileOpen.close();
         QApplication::restoreOverrideCursor();