]> Creatis software - clitk.git/commitdiff
First trial for seg
authorDavid Sarrut <david.sarrut@gmail.com>
Tue, 24 Jul 2012 15:03:11 +0000 (17:03 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Tue, 24 Jul 2012 15:03:11 +0000 (17:03 +0200)
vv/CMakeLists.txt
vv/vvToolSegmentation.cxx
vv/vvToolSegmentation.h

index 1a21d8c842e4fec027df7a510969e23c38e2fc8f..e4f90d68c8fd7940793d272f36c52c41ff28159d 100644 (file)
@@ -23,6 +23,7 @@ SET(vv_TOOLS
   vvToolMIP
   vvToolConvert ## with dummy vvToolConvert.ui
   vvToolROIManager
+  vvToolSegmentation
 
   ## these ones are for tests (not working)
   # vvToolFoo
index d4e7a906c936fd5ed7902cd268e1bbcb7f14b2c9..58651ec9537907bfb64987025ebae64229978ba0 100644 (file)
@@ -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<ArgsInfoType> 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<vvROIActor> 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);
 }
 //------------------------------------------------------------------------------
 
index accdd526c32306fad2e0c9267c57bd412dd617a4..7ba8d5cc73555d43b7b0cfec47b5d1735f8101fd 100644 (file)
@@ -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<vvROIActor> mRefMaskActor;
   QSharedPointer<vvROIActor> mCurrentMaskActor;
@@ -76,6 +73,7 @@ class vvToolSegmentation:
   QSharedPointer<vvROIActor> CreateMaskActor(vvImage::Pointer image, int i, int colorID, bool BGMode=false);
   
   double mCurrentLabelUnderMousePointer;
+  std::vector<double> mCurrentMousePosition;
   double GetBackgroundValue() { return 0; }
   double GetForegroundValue() { return 1; }
   long ComputeNumberOfPixels(vvImage::Pointer image, double value);