From e01ff4c52156fd3827d8aed581a21cc236d9ac43 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 23 Dec 2015 15:43:47 +0100 Subject: [PATCH] Create the line iterator --- tools/clitkProfileImage.ggo | 19 ++-- tools/clitkProfileImageGenericFilter.cxx | 37 +++++--- vv/qt_ui/vvToolProfile.ui | 53 +++++++---- vv/vvToolProfile.cxx | 111 +++++++++++++++-------- vv/vvToolProfile.h | 5 +- 5 files changed, 143 insertions(+), 82 deletions(-) diff --git a/tools/clitkProfileImage.ggo b/tools/clitkProfileImage.ggo index 1894af6..7714e18 100644 --- a/tools/clitkProfileImage.ggo +++ b/tools/clitkProfileImage.ggo @@ -1,19 +1,16 @@ #File clitkProfileImage.ggo package "clitkProfileImage" version "1.0" -purpose "" +purpose "Save the profile between 2 points of the input image in the output text file" -option "config" - "Config file" string no -option "verbose" v "Verbose" flag off -option "imagetypes" - "Display allowed image types" flag off +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Display allowed image types" flag off -option "input" i "Input image filename" string yes -option "output" o "Output image filename" string yes -option "lower" l "Lower intensity (default=min), fg is greater than this value" double no -option "upper" u "Upper intensity (default=max), fg is lower than this value" double no +option "input" i "Input image filename" string yes +option "output" o "Output texte filename" string yes +option "point1" f "First point (mm)" int yes multiple(-4) +option "point2" s "Second point (mm)" int yes multiple(-4) -option "fg" - "Foreground (FG) or 'inside' value" double no default="1" -option "bg" - "Background (BG) or 'ouside' value" double no default="0" -option "mode" - "Use FG and/or BG values (if FG, the BG is replaced by the input image values)" values="FG","BG","both" no default="both" diff --git a/tools/clitkProfileImageGenericFilter.cxx b/tools/clitkProfileImageGenericFilter.cxx index 8229815..3c6d6b7 100644 --- a/tools/clitkProfileImageGenericFilter.cxx +++ b/tools/clitkProfileImageGenericFilter.cxx @@ -30,9 +30,7 @@ #include "clitkProfileImageGenericFilter.h" // itk include -#include "itkBinaryThresholdImageFilter.h" -#include "itkMaskImageFilter.h" -#include "itkMaskNegatedImageFilter.h" +#include #include @@ -88,25 +86,40 @@ ProfileImageGenericFilter::UpdateWithInputImageType() // Reading input typename InputImageType::Pointer input = this->template GetInput(0); - - // Main filter typedef typename InputImageType::PixelType PixelType; + typedef typename InputImageType::IndexType IndexType; typedef itk::Image OutputImageType; + + //Iterator + IndexType pointBegin, pointEnd; + + for (int i = 0; i < mArgsInfo.point1_given; ++i) { + pointBegin[i] = mArgsInfo.point1_arg[i]; + pointEnd[i] = mArgsInfo.point2_arg[i]; + } + + itk::LineConstIterator itProfile(input, pointBegin, pointEnd); + itProfile.GoToBegin(); + while (!itProfile.IsAtEnd()) + { + + ++itProfile; + } // Filter - typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; - typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New(); - thresholdFilter->SetInput(input); - thresholdFilter->SetInsideValue(mArgsInfo.fg_arg); + //typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; + //typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New(); + //thresholdFilter->SetInput(input); + /*thresholdFilter->SetInsideValue(mArgsInfo.fg_arg); if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast(mArgsInfo.lower_arg)); if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(mArgsInfo.upper_arg)); - /* Three modes : + Three modes : - FG -> only use FG value for pixel in the Foreground (or Inside), keep input values for outside - BG -> only use BG value for pixel in the Background (or Outside), keep input values for inside - both -> use FG and BG (real binary image) - */ + if (mArgsInfo.mode_arg == std::string("both")) { thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg); thresholdFilter->Update(); @@ -134,7 +147,7 @@ ProfileImageGenericFilter::UpdateWithInputImageType() } // Write/Save results this->template SetNextOutput(outputImage); - } + }*/ } //-------------------------------------------------------------------- diff --git a/vv/qt_ui/vvToolProfile.ui b/vv/qt_ui/vvToolProfile.ui index 6366b49..3d6af50 100644 --- a/vv/qt_ui/vvToolProfile.ui +++ b/vv/qt_ui/vvToolProfile.ui @@ -28,6 +28,24 @@ + + + + + + Point2 (mm): + + + + + + + + + + + + @@ -35,42 +53,41 @@ - - - - Cancel - - - - - + + - + - Point1 (mm): + Cancel - + + + + 0 + 0 + + - + Compute Profile - - + + - + - Point2 (mm): + Point1 (mm): - + diff --git a/vv/vvToolProfile.cxx b/vv/vvToolProfile.cxx index 54eafd8..b9c34c9 100644 --- a/vv/vvToolProfile.cxx +++ b/vv/vvToolProfile.cxx @@ -64,7 +64,8 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f) // Connect signals & slots connect(mSelectPoint1Button, SIGNAL(clicked()), this, SLOT(selectPoint1())); connect(mSelectPoint2Button, SIGNAL(clicked()), this, SLOT(selectPoint2())); - connect(mCancelPoints, SIGNAL(clicked()), this, SLOT(cancelPoints())); + connect(mCancelPointsButton, SIGNAL(clicked()), this, SLOT(cancelPoints())); + connect(mComputeProfileButton, SIGNAL(clicked()), this, SLOT(computeProfile())); // Initialize some widget //mThresholdSlider1->SetText(""); @@ -74,6 +75,9 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f) mPoint1 = NULL; mPoint2 = NULL; + + point1Selected = false; + point2Selected = false; // Main filter mFilter = clitk::ProfileImageGenericFilter::New(); @@ -98,17 +102,18 @@ void vvToolProfile::selectPoint1() point1Selected = false; if(mCurrentSlicerManager) { if(mCurrentSlicerManager->GetSelectedSlicer() != -1) { - double x = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[0]; - double y = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[1]; - double z = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[2]; - position += QString::number(x,'f',1) + " "; - position += QString::number(y,'f',1) + " "; - position += QString::number(z,'f',1) + " "; + double *pos; + int *index; + pos = new double [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + + for (int i=0; iGetImage()->GetNumberOfDimensions(); ++i) { + pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i]; + index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i]; - mPoint1[0] = x; - mPoint1[1] = y; - mPoint1[2] = z; - + position += QString::number(pos[i],'f',1) + " "; + mPoint1[i] = index[i]; + } point1Selected = true; } } @@ -125,17 +130,18 @@ void vvToolProfile::selectPoint2() point2Selected = false; if(mCurrentSlicerManager) { if(mCurrentSlicerManager->GetSelectedSlicer() != -1) { - double x = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[0]; - double y = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[1]; - double z = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[2]; - position += QString::number(x,'f',1) + " "; - position += QString::number(y,'f',1) + " "; - position += QString::number(z,'f',1) + " "; + double *pos; + int *index; + pos = new double [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + + for (int i=0; iGetImage()->GetNumberOfDimensions(); ++i) { + pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i]; + index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i]; - mPoint2[0] = x; - mPoint2[1] = y; - mPoint2[2] = z; - + position += QString::number(pos[i],'f',1) + " "; + mPoint2[i] = index[i]; + } point2Selected = true; } } @@ -147,15 +153,36 @@ void vvToolProfile::selectPoint2() //------------------------------------------------------------------------------ bool vvToolProfile::isPointsSelected() { - if (point1Selected && point2Selected) { - //Lancer le calcule du profil - } + if (point1Selected && point2Selected) + mComputeProfileButton->setEnabled(true); + else + mComputeProfileButton->setEnabled(false); return (point1Selected && point2Selected); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolProfile::computeProfile() +{ + if (!mCurrentSlicerManager) close(); + + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + GetArgsInfoFromGUI(); + + // Main filter + clitk::ProfileImageGenericFilter::Pointer filter = clitk::ProfileImageGenericFilter::New(); + filter->SetInputVVImage(mCurrentImage); + filter->SetArgsInfo(mArgsInfo); + filter->Update(); + + QApplication::restoreOverrideCursor(); + +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvToolProfile::cancelPoints() { @@ -164,6 +191,7 @@ void vvToolProfile::cancelPoints() mPosPoint2Label->setText(position); point1Selected = false; point2Selected = false; + mComputeProfileButton->setEnabled(false); isPointsSelected(); } //------------------------------------------------------------------------------ @@ -270,10 +298,10 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m) { mCurrentSlicerManager = m; - mPoint1 = new double[3]; - mPoint2 = new double[3]; - //mPoint1 = new double[m->GetImage()->GetNumberOfSpatialDimensions()]; - //mPoint2 = new double[m->GetImage()->GetNumberOfSpatialDimensions()]; + mPoint1 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + mPoint2 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()]; + + mComputeProfileButton->setEnabled(false); // Specific for this gui //mThresholdSlider1->SetValue(0); @@ -298,7 +326,7 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m) mBGSlider->SetValue(0); mFGSlider->SetSingleStep(1); mBGSlider->SetSingleStep(1); -*/ + // VTK objects for interactive display for(int i=0; iGetNumberOfSlicers(); i++) { mImageContour.push_back(vvImageContour::New()); @@ -321,7 +349,7 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m) //connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateOrientation(int, int))); // connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int))); - InteractiveDisplayToggled(mInteractiveDisplayIsEnabled); + InteractiveDisplayToggled(mInteractiveDisplayIsEnabled); */ } //------------------------------------------------------------------------------ @@ -354,7 +382,7 @@ void vvToolProfile::UpdateSlice(int slicer,int slices) //------------------------------------------------------------------------------ void vvToolProfile::Update(int slicer) { - if (!mInteractiveDisplayIsEnabled) return; + //if (!mInteractiveDisplayIsEnabled) return; if (!mCurrentSlicerManager) close(); //mImageContour[slicer]->Update(mThresholdSlider1->GetValue()); //if (mRadioButtonLowerThan->isChecked()) @@ -377,9 +405,9 @@ void vvToolProfile::GetArgsInfoFromGUI() DD(good); */ cmdline_parser_clitkProfileImage_init(&mArgsInfo); // Initialisation to default - bool inverseBGandFG = false; + //bool inverseBGandFG = false; - mArgsInfo.lower_given = 1; + //mArgsInfo.lower_given = 1; /*mArgsInfo.lower_arg = mThresholdSlider1->GetValue(); if (mRadioButtonLowerThan->isChecked()) { mArgsInfo.upper_given = 1; @@ -406,13 +434,18 @@ void vvToolProfile::GetArgsInfoFromGUI() } else mArgsInfo.mode_arg = (char*)"FG"; */ mArgsInfo.verbose_flag = false; + + mArgsInfo.point1_arg = mPoint1; + mArgsInfo.point2_arg = mPoint2; + mArgsInfo.point1_given = mCurrentSlicerManager->GetImage()->GetNumberOfDimensions(); + mArgsInfo.point2_given = mCurrentSlicerManager->GetImage()->GetNumberOfDimensions(); + + // Required (even if not used) + mArgsInfo.input_given = 0; + mArgsInfo.output_given = 0; - // // Required (even if not used) - // mArgsInfo.input_given = 0; - // mArgsInfo.output_given = 0; - - // mArgsInfo.input_arg = new char; - // mArgsInfo.output_arg = new char; + mArgsInfo.input_arg = new char; + mArgsInfo.output_arg = new char; } //------------------------------------------------------------------------------ diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h index dd5efbd..ecccf06 100644 --- a/vv/vvToolProfile.h +++ b/vv/vvToolProfile.h @@ -62,6 +62,7 @@ class vvToolProfile: void selectPoint1(); void selectPoint2(); void cancelPoints(); + void computeProfile(); protected: void RemoveVTKObjects(); @@ -72,8 +73,8 @@ class vvToolProfile: std::vector mImageContourLower; bool mInteractiveDisplayIsEnabled; - double* mPoint1; - double* mPoint2; + int* mPoint1; + int* mPoint2; bool point1Selected; bool point2Selected; -- 2.47.1