X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvToolROIManager.cxx;h=00eff1df1472e45fef50c19338c488d03c4eacc2;hb=HEAD;hp=ef83846510c33683d403359b41169ec11456dee3;hpb=983237a103bc281b62a06f7c03507115d6c240f5;p=clitk.git diff --git a/vv/vvToolROIManager.cxx b/vv/vvToolROIManager.cxx index ef83846..00eff1d 100644 --- a/vv/vvToolROIManager.cxx +++ b/vv/vvToolROIManager.cxx @@ -48,12 +48,14 @@ ADD_TOOL(vvToolROIManager); //------------------------------------------------------------------------------ +int vvToolROIManager::nbTotalROI = 0; + //------------------------------------------------------------------------------ vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f): QWidget(parent->GetTab()), vvToolBase(parent), Ui::vvToolROIManager() -{ //out << __func__ << endl; +{ // Store parent mMainWindow = parent; @@ -93,7 +95,7 @@ vvToolROIManager::vvToolROIManager(vvMainWindowBase * parent, Qt::WindowFlags f) //------------------------------------------------------------------------------ vvToolROIManager::~vvToolROIManager() -{ //out << __func__ << endl; +{ mROIActorsList.clear(); } //------------------------------------------------------------------------------ @@ -102,7 +104,7 @@ vvToolROIManager::~vvToolROIManager() //------------------------------------------------------------------------------ // STATIC void vvToolROIManager::Initialize() -{ //out << __func__ << endl; +{ SetToolName("ROIManager"); SetToolMenuName("Open ROI (binary image or RT-STRUCT)"); SetToolIconFilename(":/common/icons/tool-roi.png"); @@ -115,7 +117,7 @@ void vvToolROIManager::Initialize() //------------------------------------------------------------------------------ void vvToolROIManager::InitializeNewTool(bool ReadStateFlag) -{ //out << __func__ << endl; +{ // Check if we need to start a new tool or read in the state file to load if (ReadStateFlag == false) { // Select the current image as the target @@ -213,26 +215,20 @@ void vvToolROIManager::InitializeNewTool(bool ReadStateFlag) connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); connect(mReloadButton, SIGNAL(clicked()), this, SLOT(ReloadCurrentROI())); connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); - connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + connect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close())); + connect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::InputIsSelected(vvSlicerManager *m) -{ //out << __func__ << endl; +{ // Initialization mCurrentSlicerManager = m; mCurrentImage = mCurrentSlicerManager->GetImage(); - // Refuse if non 3D image - if (mCurrentImage->GetNumberOfDimensions() != 3) { - QMessageBox::information(this,tr("Warning"), tr("Warning 3D ROI on a 4D image will results in some display bugs")); - //close(); - //return; - } - // Change gui mLabelInputInfo->setText(QString("%1").arg(m->GetFileName().c_str())); @@ -244,7 +240,7 @@ void vvToolROIManager::InputIsSelected(vvSlicerManager *m) //------------------------------------------------------------------------------ void vvToolROIManager::AnImageIsBeingClosed(vvSlicerManager * m) -{ //out << __func__ << endl; +{ if (m == mCurrentSlicerManager) { close(); return; @@ -252,10 +248,47 @@ void vvToolROIManager::AnImageIsBeingClosed(vvSlicerManager * m) } //------------------------------------------------------------------------------ +void vvToolROIManager::RemoveROI() +{ + + // Search the indice of the selected ROI + QList l = mTree->selectedItems(); + if (l.size() == 0) + return; + + QTreeWidgetItem * w = l[0]; + if (w == NULL) return; + if (w == 0) return; + if (mMapTreeWidgetToROI.find(w) == mMapTreeWidgetToROI.end()) { + return; + } + + clitk::DicomRT_ROI * roi = mMapTreeWidgetToROI[w]; + if (roi == NULL) return; + + // Get selected roi actor + int n = roi->GetROINumber(); + + disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); + mROIActorsList[n]->RemoveActors(); + mROIActorsList.erase(mROIActorsList.begin()+n); + mROIList.erase(mROIList.begin()+n); + mTreeWidgetList.erase(mTreeWidgetList.begin()+n); + + for (int i = n; i < mROIActorsList.size(); ++i) { + mROIList[i]->SetROINumber(i); + mTreeWidgetList[i].data()->setText(0, QString("%1").arg(mROIList[i]->GetROINumber())); + } + connect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); + for(int i=0; iGetNumberOfSlicers(); i++) { + mCurrentSlicerManager->GetSlicer(i)->Render(); + } +} +//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::close() -{ //out << __func__ << endl; +{ disconnect(mTree, SIGNAL(itemSelectionChanged()), this, SLOT(SelectedItemChangedInTree())); disconnect(mCheckBoxShow, SIGNAL(toggled(bool)), this, SLOT(VisibleROIToggled(bool))); disconnect(mOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityChanged(int))); @@ -264,6 +297,7 @@ void vvToolROIManager::close() disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + disconnect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); // Remove actors for (unsigned int i = 0; i < mROIActorsList.size(); i++) { @@ -281,7 +315,7 @@ void vvToolROIManager::close() //------------------------------------------------------------------------------ void vvToolROIManager::SelectedImageHasChanged(vvSlicerManager * m) -{ //out << __func__ << endl; +{ if (mCurrentSlicerManager == NULL) return; if (m == NULL) return; if (m != mCurrentSlicerManager) hide(); @@ -294,7 +328,7 @@ void vvToolROIManager::SelectedImageHasChanged(vvSlicerManager * m) //------------------------------------------------------------------------------ void vvToolROIManager::Open() -{ //out << __func__ << endl; +{ // Open images QString Extensions = "Images or Dicom-Struct files ( *.mha *.mhd *.hdr *.his *.dcm RS*)"; Extensions += ";;All Files (*)"; @@ -315,7 +349,7 @@ void vvToolROIManager::Open() //------------------------------------------------------------------------------ void vvToolROIManager::OpenBinaryImage(QStringList & filename) -{ //out << __func__ << endl; +{ if (filename.size() == 0) return; vvProgressDialog p("Reading ROI ...", true); @@ -359,7 +393,7 @@ void vvToolROIManager::OpenBinaryImage(QStringList & filename) //------------------------------------------------------------------------------ void vvToolROIManager::OpenDicomImage(std::string filename) -{ //out << __func__ << endl; +{ // GUI selector of roi vvMeshReader reader; reader.SetFilename(filename); @@ -375,6 +409,9 @@ void vvToolROIManager::OpenDicomImage(std::string filename) // Read information clitk::DicomRT_StructureSet::Pointer s = clitk::DicomRT_StructureSet::New(); + vtkSmartPointer transformMatrix = vtkSmartPointer::New(); + transformMatrix = mCurrentImage->GetTransform()[0]->GetMatrix(); + s->SetTransformMatrix(transformMatrix); s->Read(filename); // Loop on selected struct @@ -411,7 +448,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, std::string name, std::string filename, double BG, bool modeBG) -{ //out << __func__ << endl; +{ // Check Dimension int dim = mCurrentImage->GetNumberOfDimensions(); int bin_dim = binaryImage->GetNumberOfDimensions(); @@ -424,8 +461,9 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, } // Compute roi index - int n = mROIList.size(); - + + int n = nbTotalROI; + ++nbTotalROI; // Compute the name of the new ROI // std::ostringstream oss; // oss << vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename)); @@ -439,7 +477,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // Create ROI clitk::DicomRT_ROI::Pointer roi = clitk::DicomRT_ROI::New(); - roi->SetFromBinaryImage(binaryImage, n, name, color, filename); + roi->SetFromBinaryImage(binaryImage, mROIList.size(), name, color, filename); // Add a new roi to the list mROIList.push_back(roi); @@ -467,7 +505,7 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // CheckBox for "All" if (actor->IsVisible()) mNumberOfVisibleROI++; if (actor->IsContourVisible()) mNumberOfVisibleContourROI++; - AllVisibleContourROIToggled(true); + AllVisibleContourROIToggled(1); // Add ROI in tree mTreeWidgetList.push_back(QSharedPointer(new QTreeWidgetItem(mTree))); @@ -487,43 +525,71 @@ void vvToolROIManager::AddImage(vvImage * binaryImage, // Update UpdateAllROIStatus(); + + if (mCurrentImage->GetNumberOfDimensions() > 3) { + + //Modifications to avoid display bug with a 4D image + QSharedPointer CurrentROIActorTemp; + CurrentROIActorTemp = mCurrentROIActor; + mCurrentROIActor = actor; + + int VisibleInWindow(0); + mCurrentSlicerManager->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,mCurrentSlicerManager->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice()); + mCurrentSlicerManager->GetSlicer(VisibleInWindow)->Render(); + + VisibleROIToggled(false); + VisibleROIToggled(true); + + mCurrentROIActor = CurrentROIActorTemp; + + } + } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::UpdateAllContours() -{ //out << __func__ << endl; +{ if (mCurrentSlicerManager == NULL) return; // Render loaded ROIs (the first is sufficient) for(unsigned int i=0; iUpdate(); } - mCurrentSlicerManager->Render(); + //mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::UpdateAllROIStatus() -{ //out << __func__ << endl; +{ int nbVisible = 0; + int nbContourVisible = 0; int nb = mROIList.size(); for(int i=0; iIsVisible()) { nbVisible++; } + if (mROIActorsList[i]->IsContourVisible()) { + nbContourVisible++; + } } // change the states disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); - disconnect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + disconnect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); if (nbVisible == nb) mCheckBoxShowAll->setCheckState(Qt::Checked); else { if (nbVisible == 0) mCheckBoxShowAll->setCheckState(Qt::Unchecked); else mCheckBoxShowAll->setCheckState(Qt::PartiallyChecked); } - connect(mContourCheckBoxShowAll, SIGNAL(toggled(bool)), this, SLOT(AllVisibleContourROIToggled(bool))); + if (nbContourVisible == nb) mContourCheckBoxShowAll->setCheckState(Qt::Checked); + else { + if (nbContourVisible == 0) mContourCheckBoxShowAll->setCheckState(Qt::Unchecked); + else mContourCheckBoxShowAll->setCheckState(Qt::PartiallyChecked); + } + connect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); } //------------------------------------------------------------------------------ @@ -531,7 +597,7 @@ void vvToolROIManager::UpdateAllROIStatus() //------------------------------------------------------------------------------ void vvToolROIManager::SelectedItemChangedInTree() -{ //out << __func__ << endl; +{ // Search which roi is selected QList l = mTree->selectedItems(); if (l.size() == 0) { @@ -569,6 +635,7 @@ void vvToolROIManager::SelectedItemChangedInTree() disconnect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); disconnect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); disconnect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + disconnect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); mROInameLabel->setText(roi->GetName().c_str()); mCheckBoxShow->setChecked(actor->IsVisible()); @@ -587,6 +654,7 @@ void vvToolROIManager::SelectedItemChangedInTree() connect(mChangeContourColorButton, SIGNAL(clicked()), this, SLOT(ChangeContourColor())); connect(mContourWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeContourWidth(int))); connect(mDepthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ChangeDepth(int))); + connect(mRemoveButton, SIGNAL(clicked()), this, SLOT(RemoveROI())); // Set the current color to the selected ROI name @@ -614,7 +682,7 @@ void vvToolROIManager::SelectedItemChangedInTree() //------------------------------------------------------------------------------ void vvToolROIManager::VisibleROIToggled(bool b) -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; if (b == mCurrentROIActor->IsVisible()) return; // nothing to do mCurrentROIActor->SetVisible(b); @@ -626,11 +694,12 @@ void vvToolROIManager::VisibleROIToggled(bool b) //------------------------------------------------------------------------------ void vvToolROIManager::VisibleContourROIToggled(bool b) -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; if (mCurrentROIActor->IsContourVisible() == b) return; // nothing to do mCurrentROIActor->SetContourVisible(b); mCurrentROIActor->UpdateColor(); + UpdateAllROIStatus(); mCurrentSlicerManager->Render(); } //------------------------------------------------------------------------------ @@ -638,7 +707,7 @@ void vvToolROIManager::VisibleContourROIToggled(bool b) //------------------------------------------------------------------------------ void vvToolROIManager::OpacityChanged(int v) -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; mCurrentROIActor->SetOpacity((double)v/100.0); mCurrentROIActor->UpdateColor(); @@ -649,7 +718,8 @@ void vvToolROIManager::OpacityChanged(int v) //------------------------------------------------------------------------------ void vvToolROIManager::AllVisibleROIToggled(int b) -{ //out << __func__ << endl; +{ + disconnect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); bool status = false; if ((mCheckBoxShowAll->checkState() == Qt::Checked) || (mCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true; @@ -661,13 +731,15 @@ void vvToolROIManager::AllVisibleROIToggled(int b) else mCheckBoxShowAll->setCheckState(Qt::Unchecked); mCheckBoxShow->setChecked(status); mCurrentSlicerManager->Render(); + connect(mCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleROIToggled(int))); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ -void vvToolROIManager::AllVisibleContourROIToggled(bool b) -{ //out << __func__ << endl; +void vvToolROIManager::AllVisibleContourROIToggled(int b) +{ + disconnect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); bool status = false; if ((mContourCheckBoxShowAll->checkState() == Qt::Checked) || (mContourCheckBoxShowAll->checkState() == Qt::PartiallyChecked)) status = true; @@ -680,13 +752,14 @@ void vvToolROIManager::AllVisibleContourROIToggled(bool b) else mContourCheckBoxShowAll->setCheckState(Qt::Unchecked); mContourCheckBoxShow->setChecked(status); mCurrentSlicerManager->Render(); + connect(mContourCheckBoxShowAll, SIGNAL(stateChanged(int)), this, SLOT(AllVisibleContourROIToggled(int))); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void vvToolROIManager::ChangeColor() -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; QColor color; color.setRgbF(mCurrentROIActor->GetROI()->GetDisplayColor()[0], @@ -712,7 +785,7 @@ void vvToolROIManager::ChangeColor() //------------------------------------------------------------------------------ void vvToolROIManager::ChangeContourColor() -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; QColor color; color.setRgbF(mCurrentROIActor->GetContourColor()[0], @@ -730,7 +803,7 @@ void vvToolROIManager::ChangeContourColor() //------------------------------------------------------------------------------ void vvToolROIManager::ChangeContourWidth(int n) -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; mCurrentROIActor->SetContourWidth(n); mCurrentROIActor->UpdateColor(); @@ -741,7 +814,7 @@ void vvToolROIManager::ChangeContourWidth(int n) //------------------------------------------------------------------------------ void vvToolROIManager::ChangeDepth(int n) -{ //out << __func__ << endl; +{ if (mCurrentROIActor == NULL) return; mCurrentROIActor->SetDepth(n); // mCurrentROIActor->UpdateImage(); // FIXME @@ -755,7 +828,7 @@ void vvToolROIManager::ChangeDepth(int n) //------------------------------------------------------------------------------ void vvToolROIManager::ReloadCurrentROI() -{ //out << __func__ << endl; +{ if (mCurrentROI->GetFilename() == "") { return; // do nothing (contour from rt struct do not reload) } @@ -795,8 +868,12 @@ void vvToolROIManager::ReloadCurrentROI() //------------------------------------------------------------------------------ +#if __cplusplus > 199711L +void vvToolROIManager::SaveState(std::shared_ptr & m_XmlWriter) +#else void vvToolROIManager::SaveState(std::auto_ptr & m_XmlWriter) -{ //out << __func__ << endl; +#endif +{ // Get index of the image int n = mMainWindow->GetSlicerManagers().size(); int index=-1; @@ -842,7 +919,7 @@ void vvToolROIManager::SaveState(std::auto_ptr & m_XmlWriter) //------------------------------------------------------------------------------ void vvToolROIManager::ReadXMLInformation() -{ //out << __func__ << endl; +{ std::string value=""; mInitialImageIndex = -1; while (!(m_XmlReader->isEndElement() && value == GetToolName().toStdString())) { @@ -864,7 +941,7 @@ void vvToolROIManager::ReadXMLInformation() //------------------------------------------------------------------------------ void vvToolROIManager::ReadXMLInformation_ROI() -{ //out << __func__ << endl; +{ QString s; std::string value=""; QSharedPointer param = QSharedPointer(new vvROIActor);