From af5378525c594d0adb17104cf333e25976d3ac91 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Tue, 24 Jul 2012 17:03:11 +0200 Subject: [PATCH] First trial for seg --- vv/CMakeLists.txt | 1 + vv/vvToolSegmentation.cxx | 79 +++++++++++++++++++++++++++++++++++---- vv/vvToolSegmentation.h | 6 +-- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 1a21d8c..e4f90d6 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -23,6 +23,7 @@ SET(vv_TOOLS vvToolMIP vvToolConvert ## with dummy vvToolConvert.ui vvToolROIManager + vvToolSegmentation ## these ones are for tests (not working) # vvToolFoo diff --git a/vv/vvToolSegmentation.cxx b/vv/vvToolSegmentation.cxx index d4e7a90..58651ec 100644 --- a/vv/vvToolSegmentation.cxx +++ b/vv/vvToolSegmentation.cxx @@ -69,6 +69,8 @@ vvToolSegmentation::vvToolSegmentation(vvMainWindowBase * parent, Qt::WindowFlag AddInputSelector("Select one image"); // Init + mCurrentLabelUnderMousePointer = 0.0; + mCurrentMousePosition.resize(3); mRefMaskImage = NULL; mCurrentState = State_Default; mKernelValue = 3; // FIXME must be odd. If even -> not symmetrical @@ -257,6 +259,9 @@ long vvToolSegmentation::ComputeNumberOfPixels(vvImage::Pointer image, double va //------------------------------------------------------------------------------ void vvToolSegmentation::KeyPressed(std::string KeyPress) { + if (KeyPress == "g") { + RegionGrowing(); + } if (KeyPress == "e") { Erode(); } @@ -288,6 +293,59 @@ void vvToolSegmentation::KeyPressed(std::string KeyPress) //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolSegmentation::RegionGrowing() +{ + DD("RegionGrowing"); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Merge labels if needed + Merge(); + // Get mouse location + DD(mCurrentLabelUnderMousePointer); + DDV(mCurrentMousePosition, 3); + + // FIXME + + // Build RG filter + +clitk.private/deprecated/./mv_to_public.sh ~/src/clitk/clitk.private/tests_dav/ ~/src/clitk/clitk/segmentation/ clitkRegionGrowing.cxx + +clitk.private/deprecated/./mv_to_public.sh ~/src/clitk/clitk.private/tests_dav/ ~/src/clitk/clitk/segmentation/ clitkRegionGrowing.cxx + + +git format-patch --stdout --root -- clitkRegionGrowing.cxx >/tmp/patch +git rm clitkRegionGrowing.cxx +git commit clitkRegionGrowing.cxx -m "Moved from repository tests_dav to segmentation" +/home/dsarrut/src/clitk/clitk/segmentation + + +git am /tmp/patch +git mv clitkRegionGrowing.cxx /home/dsarrut/src/clitk/clitk/segmentation//clitkRegionGrowing.cxx +git commit clitkRegionGrowing.cxx /home/dsarrut/src/clitk/clitk/segmentation//clitkRegionGrowing.cxx -m Moved from repository tests_dav to segmentation + + + + typedef args_info_clitkConnectedComponentLabeling ArgsInfoType; + ArgsInfoType a; + cmdline_parser_clitkConnectedComponentLabeling_init(&a); + a.inputBG_arg = GetBackgroundValue(); + a.full_flag = false; // FIXME set by gui + a.minSize_arg = 100; // FIXME set by gui + typedef clitk::ConnectedComponentLabelingGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + filter->SetArgsInfo(a); + filter->SetInputVVImage(mCurrentMaskImage); // FIXME Check type is ok ? convert float ? + filter->SetIOVerbose(true); + filter->Update(); + DD(filter->GetOriginalNumberOfObjects()); + DD(filter->GetSizeOfObjectsInPixels().size()); + mCurrentCCLImage = filter->GetOutputVVImage(); + DDV(filter->GetSizeOfObjectsInPixels(), filter->GetSizeOfObjectsInPixels().size()); + DD("filter done"); +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvToolSegmentation::Merge() { @@ -471,8 +529,6 @@ QSharedPointer vvToolSegmentation::CreateMaskActor(vvImage::Pointer //------------------------------------------------------------------------------ void vvToolSegmentation::MousePositionChanged(int slicer) { - if (mCurrentState == State_Default) return; // Do nothing in this case - double x = mCurrentSlicerManager->GetSlicer(slicer)->GetCurrentPosition()[0]; double y = mCurrentSlicerManager->GetSlicer(slicer)->GetCurrentPosition()[1]; double z = mCurrentSlicerManager->GetSlicer(slicer)->GetCurrentPosition()[2]; @@ -482,23 +538,30 @@ void vvToolSegmentation::MousePositionChanged(int slicer) double Zover = (z - image->GetOrigin()[2]) / image->GetSpacing()[2]; int ix, iy, iz; + mCurrentMousePosition[0] = Xover; + mCurrentMousePosition[1] = Yover; + mCurrentMousePosition[2] = Zover; + if (Xover >= image->GetWholeExtent()[0] && Xover <= image->GetWholeExtent()[1] && Yover >= image->GetWholeExtent()[2] && Yover <= image->GetWholeExtent()[3] && Zover >= image->GetWholeExtent()[4] && Zover <= image->GetWholeExtent()[5]) { - mCurrentLabelUnderMousePointer = - mCurrentSlicerManager->GetSlicer(0)->GetScalarComponentAsDouble(image, Xover, Yover, Zover, ix, iy, iz, 0); - // DD(Xover); DD(Yover); DD(Zover); - // DD(ix); DD(iy); DD(iz); - // DD(valueOver); + if (mCurrentState == State_Default) { // inside the mask + mCurrentLabelUnderMousePointer = 1; + return; + } + else { // inside the label image + mCurrentLabelUnderMousePointer = + mCurrentSlicerManager->GetSlicer(0)->GetScalarComponentAsDouble(image, Xover, Yover, Zover, ix, iy, iz, 0); + return; + } } else { // DD("out of mask"); mCurrentLabelUnderMousePointer = 0; // BG is always 0 in CCL } - // DD(mCurrentLabelUnderMousePointer); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolSegmentation.h b/vv/vvToolSegmentation.h index accdd52..7ba8d5c 100644 --- a/vv/vvToolSegmentation.h +++ b/vv/vvToolSegmentation.h @@ -42,6 +42,7 @@ class vvToolSegmentation: static void Initialize(); virtual void InputIsSelected(vvSlicerManager * m); void OpenBinaryImage(); + void RegionGrowing(); void Erode(); void Dilate(); void Labelize(); @@ -52,15 +53,11 @@ class vvToolSegmentation: //----------------------------------------------------- public slots: virtual void apply(); - // bool eventFilter(QObject *object, QEvent *event); void KeyPressed(std::string KeyPress); virtual bool close(); virtual void MousePositionChanged(int slicer); - // virtual void keyPressEvent(QKeyEvent * event); - // virtual void reject(); protected: - // virtual void closeEvent(QCloseEvent *event); Ui::vvToolSegmentation ui; QSharedPointer mRefMaskActor; QSharedPointer mCurrentMaskActor; @@ -76,6 +73,7 @@ class vvToolSegmentation: QSharedPointer CreateMaskActor(vvImage::Pointer image, int i, int colorID, bool BGMode=false); double mCurrentLabelUnderMousePointer; + std::vector mCurrentMousePosition; double GetBackgroundValue() { return 0; } double GetForegroundValue() { return 1; } long ComputeNumberOfPixels(vvImage::Pointer image, double value); -- 2.47.1