X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvMainWindow.cxx;h=772cdea60df5bd24fe3127b0da15e5195ef42993;hb=58ddf0c584671ec5b42b1d90515218e297b98cc8;hp=f62198883969d56e456f1d22e0a0a54d85b69d11;hpb=31e7228948005ecc782d2a56bb8faf17a785f83e;p=clitk.git diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index f621988..772cdea 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -67,9 +67,13 @@ #include "vtkPNMWriter.h" #include "vtkPNGWriter.h" #include "vtkJPEGWriter.h" +#include "vtkMatrix4x4.h" +#include "vtkTransform.h" // Standard includes #include +#include +#include #define COLUMN_TREE 0 #define COLUMN_UL_VIEW 1 @@ -105,6 +109,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() mMainWidget = this; mCurrentTime = -1; mCurrentSelectedImageId = ""; + mCurrentPickedImageId = ""; + mCurrentPickedImageIndex = 0; //Init the contextMenu this->setContextMenuPolicy(Qt::CustomContextMenu); @@ -268,13 +274,14 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() connect(colorMapComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateColorMap())); connect(presetComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateWindowLevel())); connect(inverseButton,SIGNAL(clicked()),this,SLOT(SwitchWindowLevel())); + connect(applyWindowLevelToAllButton,SIGNAL(clicked()),this,SLOT(ApplyWindowLevelToAllImages())); connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ShowContextMenu(QPoint))); connect(linkPanel,SIGNAL(addLink(QString,QString)),this,SLOT(AddLink(QString,QString))); connect(linkPanel,SIGNAL(removeLink(QString,QString)),this,SLOT(RemoveLink(QString,QString))); - connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int)),this,SLOT(SetVFProperty(int,int,int,int))); + connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int,double,double,double)),this,SLOT(SetVFProperty(int,int,int,int,double,double,double))); connect(overlayPanel,SIGNAL(OverlayPropertyUpdated(int)),this,SLOT(SetOverlayProperty(int))); connect(overlayPanel,SIGNAL(FusionPropertyUpdated(int,int,double,double)), this,SLOT(SetFusionProperty(int,int,double,double))); @@ -316,6 +323,23 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() if (!CLITK_EXPERIMENTAL) menuExperimental->menuAction()->setVisible(false); + + + QTimer * timerMemory = new QTimer(this); + //timerMemory->setInterval(5); + connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage())); + timerMemory->start(2000); + +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvMainWindow::UpdateMemoryUsage() +{ + // clitk::PrintMemory(true); + if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA"); + else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB"); } //------------------------------------------------------------------------------ @@ -772,7 +796,7 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi nSlices[i] = header->GetDimensions( header->GetNumberOfDimensions()-1 ); } } - + //Only add to the list of recently opened files when a single file is opened, //to avoid polluting the list of recently opened files if (files.size() == 1) { @@ -807,7 +831,7 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi else { SetImageSucceed = imageManager->SetImages(files,filetype, number); } - if (SetImageSucceed == false) { + if (!SetImageSucceed) { QApplication::restoreOverrideCursor(); QString error = "Cannot open file \n"; error += imageManager->GetLastError().c_str(); @@ -855,6 +879,8 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)), this,SLOT(CurrentImageChanged(std::string))); + connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)), + this, SLOT(CurrentPickedImageChanged(std::string))); connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)), this,SLOT(MousePositionChanged(int,double, double, double, double, double, double, double))); connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)), @@ -881,8 +907,8 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int))); connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint())); InitSlicers(); + numberofsuccesulreads++; } - numberofsuccesulreads++; } } if (numberofsuccesulreads) { @@ -897,8 +923,6 @@ void vvMainWindow::LoadImages(std::vector files, LoadedImageType fi // Try to guess default WindowLevel double range[2]; mSlicerManagers.back()->GetImage()->GetFirstVTKImageData()->GetScalarRange(range); - // DD(range[0]); - // DD(range[1]); if ((range[0] == 0) && (range[1] == 1)) { presetComboBox->setCurrentIndex(5);// binary } else { @@ -926,9 +950,6 @@ void vvMainWindow::UpdateTree() //------------------------------------------------------------------------------ void vvMainWindow::CurrentImageChanged(std::string id) { - // DD("CurrentImageChanged"); -// DD(id); -// DD(mCurrentSelectedImageId); if (id == mCurrentSelectedImageId) return; // Do nothing int selected = 0; for (int i = 0; i < DataTree->topLevelItemCount(); i++) { @@ -942,12 +963,32 @@ void vvMainWindow::CurrentImageChanged(std::string id) } DataTree->topLevelItem(selected)->setSelected(1); - // DD(mSlicerManagers[selected]->GetFileName()); mCurrentSelectedImageId = id; emit SelectedImageHasChanged(mSlicerManagers[selected]); } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvMainWindow::CurrentPickedImageChanged(std::string id) +{ + if (id == mCurrentPickedImageId) return; // Do nothing + int selected = 0; + for (int i = 0; i < DataTree->topLevelItemCount(); i++) { + if (DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString().toStdString() == id) { + selected = i; + } else { + DataTree->topLevelItem(i)->setSelected(0); + } + for (int child = 0; child < DataTree->topLevelItem(i)->childCount(); child++) + DataTree->topLevelItem(i)->child(child)->setSelected(0); + + } + DataTree->topLevelItem(selected)->setSelected(1); + mCurrentPickedImageId = id; + mCurrentPickedImageIndex = selected; +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::ImageInfoChanged() { @@ -980,6 +1021,7 @@ void vvMainWindow::ImageInfoChanged() std::vector inputSpacing; std::vector inputSize; std::vector sizeMM; + vtkSmartPointer transformation; int dimension=0; QString pixelType; QString inputSizeInBytes; @@ -998,8 +1040,9 @@ void vvMainWindow::ImageInfoChanged() //read image header int NPixel = 1; + vvImage::Pointer imageSelected; if (DataTree->topLevelItem(index) == DataTree->selectedItems()[0]) { - vvImage::Pointer imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage(); + imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetImage(); dimension = imageSelected->GetNumberOfDimensions(); origin.resize(dimension); inputSpacing.resize(dimension); @@ -1015,7 +1058,7 @@ void vvMainWindow::ImageInfoChanged() } inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000); } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") { - vvImage::Pointer imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetVF(); + imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetVF(); dimension = imageSelected->GetNumberOfDimensions(); origin.resize(dimension); inputSpacing.resize(dimension); @@ -1031,7 +1074,7 @@ void vvMainWindow::ImageInfoChanged() } inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000); } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "overlay") { - vvImage::Pointer imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetOverlay(); + imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetOverlay(); dimension = imageSelected->GetNumberOfDimensions(); origin.resize(dimension); inputSpacing.resize(dimension); @@ -1047,7 +1090,7 @@ void vvMainWindow::ImageInfoChanged() } inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000); } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "fusion") { - vvImage::Pointer imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetFusion(); + imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetFusion(); dimension = imageSelected->GetNumberOfDimensions(); origin.resize(dimension); inputSpacing.resize(dimension); @@ -1074,6 +1117,8 @@ void vvMainWindow::ImageInfoChanged() infoPanel->setOrigin(GetVectorDoubleAsString(origin)); infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing)); infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")"); + transformation = imageSelected->GetTransform()->GetMatrix(); + infoPanel->setTransformation(Get4x4MatrixDoubleAsString(transformation)); landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(), mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size()); @@ -1089,8 +1134,6 @@ void vvMainWindow::ImageInfoChanged() } windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow()); levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel()); - // DD(mSlicerManagers[index]->GetColorMap()); - // DD(mSlicerManagers[index]->GetPreset()); presetComboBox->setCurrentIndex(mSlicerManagers[index]->GetPreset()); colorMapComboBox->setCurrentIndex(mSlicerManagers[index]->GetColorMap()); @@ -1224,6 +1267,29 @@ QString vvMainWindow::GetSizeInBytes(unsigned long size) } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +QString vvMainWindow::Get4x4MatrixDoubleAsString(vtkSmartPointer matrix) +{ + std::ostringstream strmatrix; + + for (unsigned int i = 0; i < 4; i++) { + for (unsigned int j = 0; j < 4; j++) { + strmatrix.flags(ios::showpos); + strmatrix.width(10); + strmatrix.precision(3); + strmatrix.setf(ios::fixed,ios::floatfield); + strmatrix.fill(' '); + strmatrix << std::left << matrix->GetElement(i, j); + //strmatrix.width(10); + strmatrix << " "; + } + strmatrix << std::endl; + } + QString result = strmatrix.str().c_str(); + return result; +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ QString vvMainWindow::GetVectorDoubleAsString(std::vector vectorDouble) { @@ -1495,6 +1561,7 @@ void vvMainWindow::CloseImage(QTreeWidgetItem* item, int column) InitDisplay(); } } + ImageInfoChanged(); } //------------------------------------------------------------------------------ @@ -1592,6 +1659,8 @@ void vvMainWindow::UpdateWindowLevel() mSlicerManagers[index]->SetColorLevel(levelSpinBox->value()); mSlicerManagers[index]->SetPreset(presetComboBox->currentIndex()); mSlicerManagers[index]->Render(); + windowSpinBox->setValue(mSlicerManagers[index]->GetColorWindow()); + levelSpinBox->setValue(mSlicerManagers[index]->GetColorLevel()); } } //------------------------------------------------------------------------------ @@ -1616,6 +1685,20 @@ void vvMainWindow::SwitchWindowLevel() } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvMainWindow::ApplyWindowLevelToAllImages() +{ + for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { + if (mSlicerManagers[i] == NULL) + continue; + mSlicerManagers[i]->SetColorWindow(windowSpinBox->value()); + mSlicerManagers[i]->SetColorLevel(levelSpinBox->value()); + mSlicerManagers[i]->SetPreset(6); + mSlicerManagers[i]->Render(); + } +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvMainWindow::UpdateLinkManager(std::string id, int slicer, double x, double y, double z, int temps) { @@ -1782,7 +1865,6 @@ void vvMainWindow::AddOverlayImage(int index, QString file) //------------------------------------------------------------------------------ void vvMainWindow::AddROI(int index, QString file) { - DD("AddImageAndROI"); /* // Get slice manager @@ -1803,7 +1885,7 @@ void vvMainWindow::AddROI(int index, QString file) // Create roi in new tool vvToolStructureSetManager::AddImage(mCurrentSlicerManager, roi); -*/ + */ } //------------------------------------------------------------------------------ @@ -2032,7 +2114,7 @@ void vvMainWindow::AddField(QString file,int index) //------------------------------------------------------------------------------ -void vvMainWindow::SetVFProperty(int subsampling, int scale, int log, int width) +void vvMainWindow::SetVFProperty(int subsampling, int scale, int log, int width, double r, double g, double b) { int index = GetSlicerIndexFromItem(DataTree->selectedItems()[0]); if (mSlicerManagers[index]->GetSlicer(0)->GetVF()) { @@ -2040,6 +2122,7 @@ void vvMainWindow::SetVFProperty(int subsampling, int scale, int log, int width) mSlicerManagers[index]->GetSlicer(i)->SetVFSubSampling(subsampling); mSlicerManagers[index]->GetSlicer(i)->SetVFScale(scale); mSlicerManagers[index]->GetSlicer(i)->SetVFWidth(width); + mSlicerManagers[index]->GetSlicer(i)->SetVFColor(r,g,b); if (log > 0) mSlicerManagers[index]->GetSlicer(i)->SetVFLog(1); else @@ -2153,22 +2236,35 @@ void vvMainWindow::SaveAs() //------------------------------------------------------------------------------ void vvMainWindow::AddLink(QString image1,QString image2) { + unsigned int sm1 = 0; + unsigned int sm2 = 0; + for (unsigned int i = 0; i < mSlicerManagers.size(); i++) { if (image1.toStdString() == mSlicerManagers[i]->GetId()) { mSlicerManagers[i]->AddLink(image2.toStdString()); + sm1 = i; } if (image2.toStdString() == mSlicerManagers[i]->GetId()) { mSlicerManagers[i]->AddLink(image1.toStdString()); + sm2 = i; } } + + if (linkPanel->isLinkAll()) { + emit UpdateLinkedNavigation(mSlicerManagers[sm1]->GetId(), mSlicerManagers[mCurrentPickedImageIndex]); + emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[mCurrentPickedImageIndex]); + } + else { + emit UpdateLinkedNavigation(mSlicerManagers[sm2]->GetId(), mSlicerManagers[sm1]); + } } + //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ 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()) { mSlicerManagers[i]->RemoveLink(image2.toStdString()); @@ -2303,8 +2399,6 @@ void vvMainWindow::NEVerticalSliderChanged() void vvMainWindow::SOVerticalSliderChanged() { static int value=-1; - // DD(value); -// DD(SOVerticalSlider->value()); if (value == SOVerticalSlider->value()) return; else value = SOVerticalSlider->value(); //int value = SOVerticalSlider->value(); @@ -2631,7 +2725,7 @@ int vvMainWindow::GetImageDuplicateFilenameNumber(std::string filename) for(unsigned int l=0; lGetBaseFileName() == - vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename))) { + vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename))) { number = std::max(number, v->GetBaseFileNameNumber()+1); } } @@ -2691,6 +2785,8 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)), this, SLOT(CurrentImageChanged(std::string))); + connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)), + this, SLOT(CurrentPickedImageChanged(std::string))); connect(mSlicerManagers.back(), SIGNAL(UpdatePosition(int, double, double, double, double, double, double, double)), this, SLOT(MousePositionChanged(int,double, double, double, double, double, double, double))); connect(mSlicerManagers.back(), SIGNAL(UpdateVector(int, double, double, double, double)), @@ -2722,8 +2818,9 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen ShowLastImage(); InitDisplay(); qApp->processEvents(); - + // End + ImageInfoChanged(); return slicer_manager; } //------------------------------------------------------------------------------