DD("remo mask");
if (mCurrentMaskActor) mCurrentMaskActor->RemoveActors();
for(int i=0; i<mCurrentCCLActors.size(); i++) {
- DD(i);
if (mCurrentCCLActors[i]) mCurrentCCLActors[i]->RemoveActors();
}
DD("wclose");
// Add a new roi actor for the current mask
mCurrentMaskActor = CreateMaskActor(mCurrentMaskImage, 1, 0, false);
mCurrentMaskActor->Update(); // default color is red
+ UpdateMaskSize(mCurrentMaskImage, mCurrentMaskSizeInPixels, mCurrentMaskSizeInCC);
// Add a mask actor for the reference
mRefMaskActor = CreateMaskActor(mRefMaskImage, 0, 1, true);
mRefMaskActor->SetContourColor(0,1,0); // green contour
mRefMaskActor->UpdateColor();
mRefMaskActor->Update();
+ UpdateMaskSize(mRefMaskImage, mRefMaskSizeInPixels, mRefMaskSizeInCC);
+
+ // Update GUI
+ UpdateMaskSizeLabels();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolSegmentation::UpdateMaskSizeLabels()
+{
+ QString s("%1 pix (%2 cm3)");
+ s = s.arg(mRefMaskSizeInPixels).arg(mRefMaskSizeInCC);
+ mRefMaskSizeLabel->setText(s);
+ QString s2("%1 pix (%2 cm3)");
+ s2 = s2.arg(mCurrentMaskSizeInPixels).arg(mCurrentMaskSizeInCC);
+ mCurrentMaskSizeLabel->setText(s2);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolSegmentation::UpdateMaskSize(vvImage::Pointer image, long & pix, double & cc)
+{
+ pix = ComputeNumberOfPixels(image, GetForegroundValue());
+ double vol = image->GetSpacing()[0]*image->GetSpacing()[1]*image->GetSpacing()[2];
+ cc = pix * vol / (10*10*10);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+long vvToolSegmentation::ComputeNumberOfPixels(vvImage::Pointer image, double value)
+{
+ int n=0;
+ vtkImageData * im = image->GetFirstVTKImageData();
+ char * pPix = (char*)im->GetScalarPointer(); // FIXME char ?
+ for(uint i=0; i<im->GetNumberOfPoints(); i++) {
+ if (pPix[i] == value) n++;
+ }
+ DD(n);
+ return n;
}
//------------------------------------------------------------------------------
}
if (KeyPress == "m") {
Merge();
+ UpdateAndRenderNewMask();
}
if (KeyPress == "s") { // Supress "Remove" one label
if (mCurrentState == State_CCL) RemoveLabel();
int * pCCL = (int*)ccl->GetScalarPointer();
char * pPix = (char*)mask->GetScalarPointer();
for(uint i=0; i<ccl->GetNumberOfPoints(); i++) {
- if (pCCL[i] == 0) pPix[i] = 0; // copy BG
+ if (pCCL[i] == 0) pPix[i] = GetBackgroundValue(); // copy BG. In CCL BG is always 0
}
// Display new mask and remove ccl
mCurrentMaskActor = CreateMaskActor(mCurrentMaskImage, 1, 0, false); // renew
mCurrentMaskActor->Update();
mCurrentMaskActor->SetVisible(true);
- mCurrentSlicerManager->Render();
+ // mCurrentSlicerManager->Render();
mCurrentState = State_Default;
}
//------------------------------------------------------------------------------
mCurrentMaskActor->SetContourVisible(cvisible);
mCurrentSlicerManager->Render();
+ UpdateMaskSize(mCurrentMaskImage, mCurrentMaskSizeInPixels, mCurrentMaskSizeInCC);
+ UpdateMaskSizeLabels();
}
//------------------------------------------------------------------------------
typedef args_info_clitkConnectedComponentLabeling ArgsInfoType;
ArgsInfoType a;
cmdline_parser_clitkConnectedComponentLabeling_init(&a);
- a.inputBG_arg = 0;
+ 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;
}
else {
// DD("out of mask");
- mCurrentLabelUnderMousePointer = 0;
+ mCurrentLabelUnderMousePointer = 0; // BG is always 0 in CCL
}
// DD(mCurrentLabelUnderMousePointer);
}
QSharedPointer<vvROIActor> CreateMaskActor(vvImage::Pointer image, int i, int colorID, bool BGMode=false);
double mCurrentLabelUnderMousePointer;
+ double GetBackgroundValue() { return 0; }
+ double GetForegroundValue() { return 1; }
+ long ComputeNumberOfPixels(vvImage::Pointer image, double value);
+
+ // Compute and store sizes of mask Foreground
+ void UpdateMaskSize(vvImage::Pointer image, long & pix, double & cc);
+ void UpdateMaskSizeLabels();
+ long mRefMaskSizeInPixels;
+ double mRefMaskSizeInCC;
+ long mCurrentMaskSizeInPixels;
+ double mCurrentMaskSizeInCC;
}; // end class vvToolSegmentation
//------------------------------------------------------------------------------