+ // 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
+ int i = mMainWindow->GetSlicerManagerCurrentIndex();
+ mCurrentSlicerManager = mMainWindow->GetSlicerManagers()[i];
+ // Set it as current (only if not ReadStateFlag)
+ mMainWindow->GetTab()->setCurrentIndex(mIndexFirstTab);
+ }
+ else {
+ // Set the first tab in front to avoid displaying two roimanager
+ // in the same tab. Because toolcreatorBase do show() and I am too
+ // lazy to find another solution now.
+ mMainWindow->GetTab()->setCurrentIndex(0);
+
+ // Read all information in the XML
+ ReadXMLInformation();
+
+ // Check that a ROI is not already present
+ mInitialImageIndex += mImageIndex;
+ if (mInitialImageIndex >= mMainWindow->GetSlicerManagers().size()) {
+ QMessageBox::warning(this, "ROIManager tool", QString("Image index %1 not found, abort.").arg(mInitialImageIndex));
+ close();
+ return;
+ }
+
+ // Set the attached image
+ mCurrentSlicerManager = mMainWindow->GetSlicerManagers()[mInitialImageIndex];
+ }
+
+ // Tab insertion, check that another tool does not already exist for this image
+ std::vector<vvToolBaseBase*> & tools =
+ vvToolManager::GetInstance()->GetToolCreatorFromName(GetToolName())->GetListOfTool();
+ if (tools.size() > 0) {
+ for(uint i=0; i<tools.size()-1; i++) { // current tool is last
+ vvToolROIManager * t = dynamic_cast<vvToolROIManager*>(tools[i]);
+ if (mCurrentSlicerManager == t->GetCurrentSlicerManager()) {
+ QMessageBox::warning(this, "ROIManager tool", "Already a ROI for this image, abort.");
+ close();
+ return;
+ }
+ }
+ }
+
+ // Display tool in the correct tab
+ QWidget * tab = qFindChild<QWidget*>(mMainWindow->GetTab(), "ROItab");
+ tab->layout()->addWidget(this);
+
+ // If not read in a file we start automatically the browser to load
+ // a roi file (binary image)
+ if (ReadStateFlag) {
+ mOpenFileBrowserFlag = false;
+ InputIsSelected(mCurrentSlicerManager);
+ mOpenFileBrowserFlag = true;
+ }
+ else InputIsSelected(mCurrentSlicerManager);
+
+ // Load ROI (if read in the XML files, empty otherwise)
+ OpenBinaryImage(mROIFilenames);
+
+ // Set the options to the open roi
+ for(uint i=0; i<mROIActorsParamList.size(); i++) {
+ QSharedPointer<vvROIActor> roi = mROIActorsList[i];
+ QSharedPointer<vvROIActor> roi_param = mROIActorsParamList[i];
+ roi->CopyParameters(roi_param);
+
+ // Update Tree
+ QTreeWidgetItem * w = mMapROIToTreeWidget[roi->GetROI()];
+ QBrush brush(QColor(roi->GetROI()->GetDisplayColor()[0]*255,
+ roi->GetROI()->GetDisplayColor()[1]*255,
+ roi->GetROI()->GetDisplayColor()[2]*255));
+ brush.setStyle(Qt::SolidPattern);
+ w->setBackground(2, brush);
+ w->setText(3, QString("%1").arg(roi->GetDepth()));
+ roi->UpdateColor();
+ }