X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvMainWindow.cxx;h=2b414926abb673fd0bfa10f8eae36f1f5b750646;hb=706d7e2dc69e12b3823cfae2f3be3f903e4d3c80;hp=ba3f3136d721d1d5240d498d19fea343d57e13dc;hpb=c45f077f35553cdc72396626ac601080093d273b;p=clitk.git diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index ba3f313..2b41492 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -18,12 +18,14 @@ It is distributed under dual licence #include #include +#include #include #include #include "QTreePushButton.h" #include #include #include +#include // VV include #include "vvMainWindow.h" @@ -48,7 +50,7 @@ It is distributed under dual licence #include "vvMeshReader.h" #include "vvSaveState.h" #include "vvReadState.h" -#ifdef CLITK_USE_PACS_CONNECTION +#if CLITK_USE_PACS_CONNECTION #include "vvQPacsConnection.h" #endif #include "clitkConfiguration.h" @@ -82,9 +84,7 @@ It is distributed under dual licence #include #include #include -#ifdef CLITK_EXPERIMENTAL -# include -#endif +#include #ifdef VTK_USE_VIDEO_FOR_WINDOWS # include #endif @@ -134,6 +134,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() { setupUi(this); // this sets up the GUI + setAcceptDrops(true); // enable to drop into the window + setDicomClient(); //Qt::WindowFlags flags = windowFlags(); @@ -235,7 +237,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() documentation = new vvDocumentation(); help_dialog = new vvHelpDialog(); dicomSeriesSelector = new vvDicomSeriesSelector(); -#ifdef CLITK_USE_PACS_CONNECTION +#if CLITK_USE_PACS_CONNECTION PacsConnection = new vvQPacsConnection(); #endif @@ -280,8 +282,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() connect(actionWarp_image_with_vector_field,SIGNAL(triggered()),this,SLOT(WarpImage())); connect(actionLoad_images,SIGNAL(triggered()),this,SLOT(OpenImages())); connect(actionOpen_Dicom,SIGNAL(triggered()),this,SLOT(OpenDicom())); - #ifdef CLITK_USE_PACS_CONNECTION -connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs())); +#if CLITK_USE_PACS_CONNECTION + connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs())); #endif // connect(actionOpen_Dicom_Struct,SIGNAL(triggered()),this,SLOT(OpenDCStructContour())); connect(actionOpen_VTK_contour,SIGNAL(triggered()),this,SLOT(OpenVTKContour())); @@ -385,6 +387,9 @@ connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs())); updateRecentlyOpenedFilesMenu(recent_files); } + //Update and get vv parameters + setVVSettings(); + // Adding all new tools (insertion in the menu) vvToolManager::GetInstance()->InsertToolsInMenu(this); vvToolManager::GetInstance()->EnableToolsInMenu(this, false); @@ -397,6 +402,10 @@ connect(actionConnect_Pacs,SIGNAL(triggered()),this,SLOT(ConnectPacs())); menuExperimental->menuAction()->setVisible(false); #endif +#if !CLITK_USE_PACS_CONNECTION + actionConnect_Pacs->setVisible(false); +#endif + QTimer * timerMemory = new QTimer(this); //timerMemory->setInterval(5); connect(timerMemory, SIGNAL(timeout()), this, SLOT(UpdateMemoryUsage())); @@ -414,7 +423,7 @@ void vvMainWindow::UpdateMemoryUsage() { // clitk::PrintMemory(true); if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA"); - else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB"); + else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MB"); } //------------------------------------------------------------------------------ @@ -770,7 +779,7 @@ void vvMainWindow::OpenDicom() LoadImages(files, vvImageReader::DICOM); } } -#ifdef CLITK_USE_PACS_CONNECTION +#if CLITK_USE_PACS_CONNECTION void vvMainWindow::ConnectPacs() { std::vector files; @@ -814,6 +823,25 @@ void vvMainWindow::OpenRecentImage() LoadImages(images, vvImageReader::IMAGE); } //------------------------------------------------------------------------------ +void vvMainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } +} +//------------------------------------------------------------------------------ +void vvMainWindow::dropEvent(QDropEvent *event) +{ + const QMimeData * mimeData = event->mimeData(); + if (!mimeData->hasUrls()) + return; + std::vector images; + for (int i=0; iurls().size(); ++i) { + images.push_back(mimeData->urls()[i].toLocalFile().toStdString()); + } + LoadImages(images, vvImageReader::IMAGE); +} +//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ @@ -900,11 +928,13 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa // Change filename if an image with the same already exist int number = GetImageDuplicateFilenameNumber(files[i] + std::string("_slice")); - if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED) { + if (filetype == vvImageReader::IMAGE || filetype == vvImageReader::IMAGEWITHTIME || filetype == vvImageReader::SLICED) SetImageSucceed = imageManager->SetImage(files[i],filetype, number, j); - } else { + else if (filetype == vvImageReader::DICOM) + SetImageSucceed = imageManager->SetImages(files,filetype, number, dicomSeriesSelector->IsPatientCoordianteSystemChecked()); + else SetImageSucceed = imageManager->SetImages(files,filetype, number); - } + if (!SetImageSucceed) { QApplication::restoreOverrideCursor(); QString error = "Cannot open file \n"; @@ -953,6 +983,12 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa linkPanel->addImage(imageManager->GetFileName(), id.toStdString()); + //Create a watcher to see if the image file is modified. In such a case, reload it automatically + QFileSystemWatcher* watcher = new QFileSystemWatcher; + watcher->addPath(files[i].c_str()); + connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(SlotFileChanged(const QString&))); + + connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)), this,SLOT(CurrentImageChanged(std::string))); connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)), @@ -982,6 +1018,7 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)), this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int))); connect(mSlicerManagers.back(),SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint())); + connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark())); InitSlicers(); numberofsuccesulreads++; } @@ -1170,7 +1207,7 @@ void vvMainWindow::ImageInfoChanged() sizeMM[i] = inputSize[i]*inputSpacing[i]; NPixel *= inputSize[i]; } - inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000); + inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()); QString dim = QString::number(dimension) + " ("; dim += pixelType + ")"; @@ -1371,15 +1408,15 @@ QString vvMainWindow::GetSizeInBytes(unsigned long size) if (size > 1000000000) { size /= 1000000000; result += QString::number(size); - result += "Gb";//)"; + result += "GB";//)"; } else if (size > 1000000) { size /= 1000000; result += QString::number(size); - result += "Mb";//)"; + result += "MB";//)"; } else if (size > 1000) { size /= 1000; result += QString::number(size); - result += "kb";//)"; + result += "kB";//)"; } return result; } @@ -1411,6 +1448,29 @@ QString vvMainWindow::GetVectorIntAsString(std::vector vectorInt) } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvMainWindow::SlotFileChanged(const QString& pathname) +{ + std::vector items = GetItemFromPathname(pathname); + for (unsigned int i=0; i< items.size(); ++i) + ReloadImage(items[i], 0); +} +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +std::vector vvMainWindow::GetItemFromPathname(const QString& pathname) +{ + std::vector items; + for (int i = 0; i < DataTree->topLevelItemCount(); ++i) { + QString tempItemPathname(DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString()); + tempItemPathname = tempItemPathname.left(tempItemPathname.length() - 1); + if (tempItemPathname == pathname) + items.push_back(DataTree->topLevelItem(i)); + } + return items; +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ //this actually returns the SlicerManager index! int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item) @@ -3273,7 +3333,11 @@ void vvMainWindow::SaveSEScreenshot() //------------------------------------------------------------------------------ void vvMainWindow::SaveScreenshotAllSlices() { +#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9 + QVTKOpenGLNativeWidget *widget = NOViewWidget; +#else QVTKWidget *widget = NOViewWidget; +#endif int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]); vvSlicerManager * SM = mSlicerManagers[index]; @@ -3299,7 +3363,11 @@ void vvMainWindow::SaveScreenshotAllSlices() // Screenshot vtkSmartPointer windowToImageFilter = vtkSmartPointer::New(); windowToImageFilter->SetInput(renderWindow); +#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9 + windowToImageFilter->SetScale(1); +#else windowToImageFilter->SetMagnification(1); +#endif windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel windowToImageFilter->Update(); @@ -3325,7 +3393,11 @@ void vvMainWindow::SaveScreenshotAllSlices() //------------------------------------------------------------------------------ +#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9 +void vvMainWindow::SaveScreenshot(QVTKOpenGLNativeWidget *widget) +#else void vvMainWindow::SaveScreenshot(QVTKWidget *widget) +#endif { QString Extensions = "Images( *.png);;"; Extensions += "Images( *.jpg);;"; @@ -3338,9 +3410,7 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) #ifdef VTK_USE_MPEG2_ENCODER Extensions += ";;Video( *.mpg)"; #endif -#ifdef CLITK_EXPERIMENTAL Extensions += ";;Video( *.gif)"; -#endif int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]); QString fileName = QFileDialog::getSaveFileName(this, @@ -3351,6 +3421,12 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) if (!fileName.isEmpty()) { vtkSmartPointer w2i = vtkSmartPointer::New(); w2i->SetInput(widget->GetRenderWindow()); +#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 1) || VTK_MAJOR_VERSION >= 9 + w2i->SetScale(1); +#else + w2i->SetMagnification(1); +#endif + w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel w2i->Update(); vtkImageData *image = w2i->GetOutput(); @@ -3383,7 +3459,6 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) // Video vtkGenericMovieWriter *vidwriter = NULL; -#if CLITK_EXPERIMENTAL == 1 if (ext==".gif") { vvAnimatedGIFWriter *gif = vvAnimatedGIFWriter::New(); vidwriter = gif; @@ -3408,7 +3483,6 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) msgBox.addButton(tr("No"), QMessageBox::RejectRole); gif->SetDither(msgBox.exec() == QMessageBox::AcceptRole); } -#endif #ifdef VTK_USE_VIDEO_FOR_WINDOWS if (ext==".avi") { vtkAVIWriter *mpg = vtkAVIWriter::New(); @@ -3697,6 +3771,7 @@ vvSlicerManager* vvMainWindow::AddImage(vvImage::Pointer image,std::string filen connect(mSlicerManagers.back(), SIGNAL(ChangeImageWithIndexOffset(vvSlicerManager*,int,int)), this,SLOT(ChangeImageWithIndexOffset(vvSlicerManager*,int,int))); connect(mSlicerManagers.back(), SIGNAL(LandmarkAdded()),landmarksPanel,SLOT(AddPoint())); + connect(landmarksPanel,SIGNAL(UpdateLandmarkTransform()), mSlicerManagers.back(), SLOT(UpdateLandmark()));