From: tbaudier Date: Tue, 9 May 2017 08:03:43 +0000 (+0200) Subject: Update clitkProfileImage Tool X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ec05c5b4385b34858d6ddd47b91ed1d78dc9615c;p=clitk.git Update clitkProfileImage Tool Add output to the tool (like with the GUI) Change the first and second input to vox (correct now) --- diff --git a/tools/clitkProfileImage.ggo b/tools/clitkProfileImage.ggo index 773790d..9f3f443 100644 --- a/tools/clitkProfileImage.ggo +++ b/tools/clitkProfileImage.ggo @@ -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) diff --git a/tools/clitkProfileImageGenericFilter.cxx b/tools/clitkProfileImageGenericFilter.cxx index 02394d3..6c81756 100644 --- a/tools/clitkProfileImageGenericFilter.cxx +++ b/tools/clitkProfileImageGenericFilter.cxx @@ -120,6 +120,9 @@ ProfileImageGenericFilter::UpdateWithInputImageType() mArrayY = vtkSmartPointer::New(); mCoord = vtkSmartPointer::New(); mCoord->SetNumberOfComponents(InputImageType::ImageDimension); + mCoordmm = vtkSmartPointer::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; iInsertNextTuple(tuple); //mm ++lineNumber; ++itProfile; } + + if (mArgsInfo.output_given) { + std::string str(mArgsInfo.output_arg); + this->WriteOutput(str); + } /* itk::LineIterator 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 (iGetNumberOfTuples()) { + fileOpen << i << "\t" << mArrayY->GetTuple(i)[0] << "\t" ; + + mCoord->GetTuple(i, tuple); + for (int j=0; jGetTuple(i, tuple); + for (int j=0; j #include //-------------------------------------------------------------------- @@ -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 void InitializeImageType(); @@ -68,6 +70,8 @@ namespace clitk vtkSmartPointer mArrayX; vtkSmartPointer mArrayY; vtkSmartPointer mCoord; + vtkSmartPointer mCoordmm; + int mDimension; }; // end class diff --git a/vv/vvToolProfile.cxx b/vv/vvToolProfile.cxx index e0ebdf1..7ef2310 100644 --- a/vv/vvToolProfile.cxx +++ b/vv/vvToolProfile.cxx @@ -511,50 +511,8 @@ void vvToolProfile::SaveAs() close(); return; } - - vtkSmartPointer arrX = vtkSmartPointer::New(); - vtkSmartPointer arrY = vtkSmartPointer::New(); - vtkSmartPointer coords = vtkSmartPointer::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 (iGetNumberOfTuples()) { - fileOpen << i << "\t" << arrY->GetTuple(i)[0] << "\t" ; - - coords->GetTuple(i, tuple); - for (int j=0; jGetImage()->GetNumberOfDimensions() ; ++j) { - fileOpen << tuple[j] << "\t" ; - } - int j(0); - while (jGetImage()->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();