From: dsarrut Date: Wed, 12 May 2010 06:21:08 +0000 (+0000) Subject: - improve (?) speed render for contours X-Git-Tag: v1.2.0~660 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=30659c9eea7c95c04002cb3de18d6e584f8d1296;p=clitk.git - improve (?) speed render for contours - correct link bug (seg fault when remove last link) --- diff --git a/vv/vvLinkPanel.cxx b/vv/vvLinkPanel.cxx index b57aefd..5cfd853 100644 --- a/vv/vvLinkPanel.cxx +++ b/vv/vvLinkPanel.cxx @@ -14,9 +14,11 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ + ======================================================================-====*/ + #ifndef _vvLinkPanel_CXX #define _vvLinkPanel_CXX + #include "vvLinkPanel.h" #include "clitkCommon.h" @@ -24,159 +26,196 @@ #include #include "QTreePushButton.h" -//==================================================================== +//------------------------------------------------------------------------------ vvLinkPanel::vvLinkPanel(QWidget * parent):QWidget(parent) { - setupUi(this); - imageNames.resize(0); - image1Ids.resize(0); - image2Ids.resize(0); - - linkTableWidget->resizeColumnsToContents(); - linkTableWidget->verticalHeader()->hide(); - linkTableWidget->horizontalHeader()->hide(); - linkTableWidget->hideColumn(4); - linkTableWidget->hideColumn(5); - - connect(image1ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateComboBox2(int))); - connect(linkButton,SIGNAL(clicked()),this,SLOT(addLink())); - connect(linkAllButton,SIGNAL(clicked()),this,SLOT(linkAll())); + setupUi(this); + imageNames.resize(0); + image1Ids.resize(0); + image2Ids.resize(0); + + linkTableWidget->resizeColumnsToContents(); + linkTableWidget->verticalHeader()->hide(); + linkTableWidget->horizontalHeader()->hide(); + linkTableWidget->hideColumn(4); + linkTableWidget->hideColumn(5); + + connect(image1ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateComboBox2(int))); + connect(linkButton,SIGNAL(clicked()),this,SLOT(addLink())); + connect(linkAllButton,SIGNAL(clicked()),this,SLOT(linkAll())); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::addImage(std::string name, std::string id) { - imageNames.push_back(name); - image1Ids.push_back(id); - UpdateComboBox1(); + imageNames.push_back(name); + image1Ids.push_back(id); + UpdateComboBox1(); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::removeImage(int index) { - std::string idRemoved = image1Ids[index]; - std::vector::iterator Nameiter = imageNames.begin(); - std::vector::iterator Iditer = image1Ids.begin(); - for (int i = 0; i < index; i++) + std::string idRemoved = image1Ids[index]; + std::vector::iterator Nameiter = imageNames.begin(); + std::vector::iterator Iditer = image1Ids.begin(); + for (int i = 0; i < index; i++) { - Nameiter++; - Iditer++; + Nameiter++; + Iditer++; } - imageNames.erase(Nameiter); - image1Ids.erase(Iditer); - UpdateComboBox1(); - for (int i = linkTableWidget->rowCount() - 1; i >= 0 ;i--) + imageNames.erase(Nameiter); + image1Ids.erase(Iditer); + UpdateComboBox1(); + for (int i = linkTableWidget->rowCount() - 1; i >= 0 ;i--) { - if (linkTableWidget->item(i,4)->text().toStdString() == idRemoved || - linkTableWidget->item(i,5)->text().toStdString() == idRemoved) + if (linkTableWidget->item(i,4)->text().toStdString() == idRemoved || + linkTableWidget->item(i,5)->text().toStdString() == idRemoved) { - emit removeLink(linkTableWidget->item(i,4)->text(),linkTableWidget->item(i,5)->text()); - linkTableWidget->removeRow(i); - UpdateComboBox2(image1ComboBox->currentIndex()); + emit removeLink(linkTableWidget->item(i,4)->text(),linkTableWidget->item(i,5)->text()); + linkTableWidget->removeRow(i); + UpdateComboBox2(image1ComboBox->currentIndex()); } } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::UpdateComboBox1() { - image1ComboBox->clear(); - for (unsigned int i = 0; i < imageNames.size();i++) + image1ComboBox->clear(); + for (unsigned int i = 0; i < imageNames.size();i++) { - image1ComboBox->addItem(imageNames[i].c_str()); + image1ComboBox->addItem(imageNames[i].c_str()); } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::UpdateComboBox2(int index) { - image2ComboBox->clear(); - image2Ids.resize(0); - if (imageNames.size() > 1 && index >= 0) + image2ComboBox->clear(); + image2Ids.resize(0); + if (imageNames.size() > 1 && index >= 0) { - for (unsigned int i = 0; i < imageNames.size();i++) + for (unsigned int i = 0; i < imageNames.size();i++) { - if ((int)i != index) + if ((int)i != index) { - bool AlreadyLinked = false; - for (int row = 0; row < linkTableWidget->rowCount();row++) + bool AlreadyLinked = false; + for (int row = 0; row < linkTableWidget->rowCount();row++) { - if ((linkTableWidget->item(row,1)->text().toStdString() == imageNames[index] && - linkTableWidget->item(row,3)->text().toStdString() == imageNames[i]) || - (linkTableWidget->item(row,3)->text().toStdString() == imageNames[index] && - linkTableWidget->item(row,1)->text().toStdString() == imageNames[i])) + if ((linkTableWidget->item(row,1)->text().toStdString() == imageNames[index] && + linkTableWidget->item(row,3)->text().toStdString() == imageNames[i]) || + (linkTableWidget->item(row,3)->text().toStdString() == imageNames[index] && + linkTableWidget->item(row,1)->text().toStdString() == imageNames[i])) { - AlreadyLinked = true; - break; + AlreadyLinked = true; + break; } } - if (!AlreadyLinked) + if (!AlreadyLinked) { - image2ComboBox->addItem(imageNames[i].c_str()); - image2Ids.push_back(image1Ids[i]); + image2ComboBox->addItem(imageNames[i].c_str()); + image2Ids.push_back(image1Ids[i]); } } } } - if (image2ComboBox->count() == 0) - linkButton->setEnabled(0); - else - linkButton->setEnabled(1); + if (image2ComboBox->count() == 0) + linkButton->setEnabled(0); + else + linkButton->setEnabled(1); } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::linkAll() { - //First remove all links - while (linkTableWidget->rowCount()) - removeLink(1,1); - //Now create all possible links - int count=image2ComboBox->count(); - for (int j=0;jrowCount()) + removeLink(1,1); + //Now create all possible links + int count=image2ComboBox->count(); + for (int j=0;jsetCurrentIndex(j); - image2ComboBox->setCurrentIndex(0); - for (int i=0;i< count-j;i++) - addLink(); + image1ComboBox->setCurrentIndex(j); + image2ComboBox->setCurrentIndex(0); + for (int i=0;i< count-j;i++) + addLink(); } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::addLink() { - if (!image1ComboBox->currentText().isEmpty() - && !image2ComboBox->currentText().isEmpty()) + if (!image1ComboBox->currentText().isEmpty() + && !image2ComboBox->currentText().isEmpty()) { - int row = linkTableWidget->rowCount(); - linkTableWidget->insertRow(row); - - linkTableWidget->setItem(row,1,new QTableWidgetItem(image1ComboBox->currentText())); - linkTableWidget->setItem(row,2,new QTableWidgetItem("&")); - linkTableWidget->setItem(row,3,new QTableWidgetItem(image2ComboBox->currentText())); - linkTableWidget->setItem(row,4,new QTableWidgetItem(image1Ids[image1ComboBox->currentIndex()].c_str())); - linkTableWidget->setItem(row,5,new QTableWidgetItem(image2Ids[image2ComboBox->currentIndex()].c_str())); - QTreePushButton* cButton = new QTreePushButton; - cButton->setIndex(linkTableWidget->rowCount()); - cButton->setColumn(0); - cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png"))); - connect(cButton,SIGNAL(clickedInto(int, int)), - this,SLOT(removeLink(int, int))); - cButton->setToolTip(tr("remove link")); - linkTableWidget->setCellWidget(row,0,cButton); - - linkTableWidget->resizeColumnToContents(0); - linkTableWidget->resizeColumnToContents(1); - linkTableWidget->resizeColumnToContents(2); - linkTableWidget->resizeColumnToContents(3); - linkTableWidget->setRowHeight(row,17); - - emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(), - image2Ids[image2ComboBox->currentIndex()].c_str()); - UpdateComboBox2(image1ComboBox->currentIndex()); + int row = linkTableWidget->rowCount(); + linkTableWidget->insertRow(row); + + linkTableWidget->setItem(row,1,new QTableWidgetItem(image1ComboBox->currentText())); + linkTableWidget->setItem(row,2,new QTableWidgetItem("&")); + linkTableWidget->setItem(row,3,new QTableWidgetItem(image2ComboBox->currentText())); + linkTableWidget->setItem(row,4,new QTableWidgetItem(image1Ids[image1ComboBox->currentIndex()].c_str())); + linkTableWidget->setItem(row,5,new QTableWidgetItem(image2Ids[image2ComboBox->currentIndex()].c_str())); + QTreePushButton* cButton = new QTreePushButton; + cButton->setIndex(linkTableWidget->rowCount()); + cButton->setColumn(0); + cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png"))); + connect(cButton,SIGNAL(clickedInto(int, int)), + this,SLOT(removeLink(int, int))); + cButton->setToolTip(tr("remove link")); + linkTableWidget->setCellWidget(row,0,cButton); + + linkTableWidget->resizeColumnToContents(0); + linkTableWidget->resizeColumnToContents(1); + linkTableWidget->resizeColumnToContents(2); + linkTableWidget->resizeColumnToContents(3); + linkTableWidget->setRowHeight(row,17); + + emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(), + image2Ids[image2ComboBox->currentIndex()].c_str()); + UpdateComboBox2(image1ComboBox->currentIndex()); } } +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ void vvLinkPanel::removeLink(int row, int column) { - emit removeLink(linkTableWidget->item(row-1,4)->text(),linkTableWidget->item(row-1,5)->text()); - linkTableWidget->removeRow(row-1); - UpdateComboBox2(image1ComboBox->currentIndex()); + // DD(row); +// DD(column); + while (linkTableWidget->item(row-1,4) == NULL) { + --row; + // DD(linkTableWidget->rowCount()); +// DD(row); + // return; + } + if (linkTableWidget->item(row-1,5) == NULL) { + return; // should not happend ... + } + + emit removeLink(linkTableWidget->item(row-1,4)->text(),linkTableWidget->item(row-1,5)->text()); + // DD("after emit"); + linkTableWidget->removeRow(row-1); + // DD("after removeRow"); + UpdateComboBox2(image1ComboBox->currentIndex()); + // DD("end"); } +//------------------------------------------------------------------------------ #endif /* end #define _vvLinkPanel_CXX */ diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 6b5a677..af4b65e 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -2340,6 +2340,7 @@ void vvMainWindow::SaveAs() { } //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::AddLink(QString image1,QString image2) { for (unsigned int i = 0; i < mSlicerManagers.size();i++) @@ -2356,8 +2357,10 @@ void vvMainWindow::AddLink(QString image1,QString image2) { } //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::RemoveLink(QString image1,QString image2) { + // DD("vvMainWindow:RemoveLink"); for (unsigned int i = 0; i < mSlicerManagers.size();i++) { if (image1.toStdString() == mSlicerManagers[i]->GetId()) @@ -2444,15 +2447,20 @@ void vvMainWindow::SEHorizontalSliderMoved() { //------------------------------------------------------------------------------ void vvMainWindow::NOVerticalSliderChanged() { - int value = NOVerticalSlider->value(); + static int value=-1; + if (value == NOVerticalSlider->value()) return; + else value = NOVerticalSlider->value(); + // int value = NOVerticalSlider->value(); for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { if (DataTree->topLevelItem(i)->data(COLUMN_UL_VIEW,Qt::CheckStateRole).toInt() > 1) { - mSlicerManagers[i]->GetSlicer(0)->SetSlice(value); - mSlicerManagers[i]->VerticalSliderHasChanged(0, value); - mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. but needed for ImageContour ... - mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + if (mSlicerManagers[i]->GetSlicer(0)->GetSlice() != value) { + mSlicerManagers[i]->GetSlicer(0)->SetSlice(value); + mSlicerManagers[i]->VerticalSliderHasChanged(0, value); + mSlicerManagers[i]->UpdateSlice(0); // <-- DS add this. Not too much update ? YES. but needed for ImageContour ... + //mSlicerManagers[i]->GetSlicer(0)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + } break; } } @@ -2462,15 +2470,20 @@ void vvMainWindow::NOVerticalSliderChanged() { //------------------------------------------------------------------------------ void vvMainWindow::NEVerticalSliderChanged() { - int value = NEVerticalSlider->value(); + static int value=-1; + if (value == NEVerticalSlider->value()) return; + else value = NEVerticalSlider->value(); + // int value = NEVerticalSlider->value(); for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { if (DataTree->topLevelItem(i)->data(COLUMN_UR_VIEW,Qt::CheckStateRole).toInt() > 1) { - mSlicerManagers[i]->GetSlicer(1)->SetSlice(value); - mSlicerManagers[i]->VerticalSliderHasChanged(1, value); - mSlicerManagers[i]->UpdateSlice(1); - mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + if (mSlicerManagers[i]->GetSlicer(1)->GetSlice() != value) { + mSlicerManagers[i]->GetSlicer(1)->SetSlice(value); + mSlicerManagers[i]->VerticalSliderHasChanged(1, value); + mSlicerManagers[i]->UpdateSlice(1); + //mSlicerManagers[i]->GetSlicer(1)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + } break; } } @@ -2480,15 +2493,24 @@ void vvMainWindow::NEVerticalSliderChanged() { //------------------------------------------------------------------------------ void vvMainWindow::SOVerticalSliderChanged() { - int value = SOVerticalSlider->value(); + // DD("SOVerticalSliderChanged"); + static int value=-1; + // DD(value); +// DD(SOVerticalSlider->value()); + if (value == SOVerticalSlider->value()) return; + else value = SOVerticalSlider->value(); + //int value = SOVerticalSlider->value(); for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { if (DataTree->topLevelItem(i)->data(COLUMN_DL_VIEW,Qt::CheckStateRole).toInt() > 1) { - mSlicerManagers[i]->GetSlicer(2)->SetSlice(value); - mSlicerManagers[i]->VerticalSliderHasChanged(2, value); - mSlicerManagers[i]->UpdateSlice(2); - mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + if (mSlicerManagers[i]->GetSlicer(2)->GetSlice() != value) { + mSlicerManagers[i]->GetSlicer(2)->SetSlice(value); + mSlicerManagers[i]->VerticalSliderHasChanged(2, value); + mSlicerManagers[i]->UpdateSlice(2); + //mSlicerManagers[i]->GetSlicer(2)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + } + // else { DD("avoid SOVerticalSlider slicer update"); } break; } } @@ -2498,15 +2520,20 @@ void vvMainWindow::SOVerticalSliderChanged() { //------------------------------------------------------------------------------ void vvMainWindow::SEVerticalSliderChanged() { - int value = SEVerticalSlider->value(); + static int value=-1; + if (value == SEVerticalSlider->value()) return; + else value = SEVerticalSlider->value(); + // int value = SEVerticalSlider->value(); for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { if (DataTree->topLevelItem(i)->data(COLUMN_DR_VIEW,Qt::CheckStateRole).toInt() > 1) { - mSlicerManagers[i]->GetSlicer(3)->SetSlice(value); - mSlicerManagers[i]->VerticalSliderHasChanged(3, value); - mSlicerManagers[i]->UpdateSlice(3); - mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + if (mSlicerManagers[i]->GetSlicer(3)->GetSlice() != value) { + mSlicerManagers[i]->GetSlicer(3)->SetSlice(value); + mSlicerManagers[i]->VerticalSliderHasChanged(3, value); + mSlicerManagers[i]->UpdateSlice(3); + //mSlicerManagers[i]->GetSlicer(3)->Render(); // <-- DS add this, needed for contour, seems ok ? not too slow ? + } break; } } @@ -2516,16 +2543,26 @@ void vvMainWindow::SEVerticalSliderChanged() { //------------------------------------------------------------------------------ void vvMainWindow::UpdateSlice(int slicer, int slice) { + // DD("vvMainWindow::UpdateSlice"); +// DD(slicer); +// DD(slice); if (slicer == 0) { - if (slice != NOVerticalSlider->value()) - NOVerticalSlider->setValue(slice); + // if (slice != NOVerticalSlider->value()) + NOVerticalSlider->setValue(slice); } - else if (slicer == 1) + else { + if (slicer == 1) NEVerticalSlider->setValue(slice); - else if (slicer == 2) - SOVerticalSlider->setValue(slice); - else if (slicer == 3) - SEVerticalSlider->setValue(slice); + else { + if (slicer == 2) + SOVerticalSlider->setValue(slice); + else { + if (slicer == 3) + SEVerticalSlider->setValue(slice); + } + } + } + // DD("vvMainWindow:UpdateSlice END"); } //------------------------------------------------------------------------------ diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 3b585b2..9a2eec4 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -1256,7 +1256,7 @@ void vvSlicer::GetExtremasAroundMousePointer(double & min, double & max) void vvSlicer::Render() { // DD("vvSlicer::Render"); - //DD(SliceOrientation); + // DD(SliceOrientation); if (this->GetWindowLevel()->GetLookupTable() && !this->mOverlay && !this->mFusion) { legend->SetLookupTable(this->GetWindowLevel()->GetLookupTable()); diff --git a/vv/vvSlicerManager.cxx b/vv/vvSlicerManager.cxx index 344fa73..ca66064 100644 --- a/vv/vvSlicerManager.cxx +++ b/vv/vvSlicerManager.cxx @@ -582,6 +582,10 @@ void vvSlicerManager::SetOpacity(int i, double factor) //---------------------------------------------------------------------------- void vvSlicerManager::UpdateViews(int current,int slicer) { + // DD("UpdateViews"); +// DD(current); +// DD(slicer); + double x = (mSlicers[slicer]->GetCurrentPosition()[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0]) /mSlicers[slicer]->GetInput()->GetSpacing()[0]; double y = (mSlicers[slicer]->GetCurrentPosition()[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1]) @@ -729,8 +733,10 @@ double vvSlicerManager::GetColorLevel() //---------------------------------------------------------------------------- void vvSlicerManager::Render() { + // DD("vvSlicerManager::Render"); for ( unsigned int i = 0; i < mSlicers.size(); i++) { + // DD(i); mSlicers[i]->Render(); } } @@ -974,6 +980,7 @@ void vvSlicerManager::UpdateSlice(int slicer) return; } emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice()); + mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ... mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice(); } //---------------------------------------------------------------------------- diff --git a/vv/vvSlicerManager.h b/vv/vvSlicerManager.h index a5eccce..5d8d5d2 100644 --- a/vv/vvSlicerManager.h +++ b/vv/vvSlicerManager.h @@ -164,7 +164,7 @@ class vvSlicerManager : public QObject { mLinkedId.push_back(newId); } void RemoveLink(std::string oldId) { - mLinkedId.remove(oldId); + mLinkedId.remove(oldId); } ///Remove the actor defined by its type and index (example: 3rd contour) diff --git a/vv/vvSlicerManagerCommand.cxx b/vv/vvSlicerManagerCommand.cxx index 5b35bdd..f29263b 100644 --- a/vv/vvSlicerManagerCommand.cxx +++ b/vv/vvSlicerManagerCommand.cxx @@ -247,9 +247,13 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller, } if (KeyPress == "Up") { - this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); - this->SM->UpdateSlice(VisibleInWindow); - this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + DD("------------ up"); + this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1); + DD("------------ after set slice"); + this->SM->UpdateInfoOnCursorPosition(VisibleInWindow); + DD("------------ after UpdateInfoOnCursorPosition"); + this->SM->UpdateSlice(VisibleInWindow); + DD("------------ after updateslice"); } if (KeyPress == "Down") {