X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvMainWindow.cxx;h=d148c3f14cc8ecf9ed748483372cbe5751ebaa6c;hb=HEAD;hp=79b28058f24bafe5b21d7a9568c728d01b74981b;hpb=185f4e4c61631a8e5e256d8999e2d27ba934dcbf;p=clitk.git diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 79b2805..d148c3f 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,6 +50,9 @@ It is distributed under dual licence #include "vvMeshReader.h" #include "vvSaveState.h" #include "vvReadState.h" +#if CLITK_USE_PACS_CONNECTION +#include "vvQPacsConnection.h" +#endif #include "clitkConfiguration.h" #include "clitkMatrix.h" #ifdef Q_OS_OSX @@ -79,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 @@ -131,6 +134,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() { setupUi(this); // this sets up the GUI + setAcceptDrops(true); // enable to drop into the window + + setDicomClient(); + //Qt::WindowFlags flags = windowFlags(); //setWindowFlags(flags | Qt::WindowStaysOnTopHint); @@ -230,6 +237,9 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() documentation = new vvDocumentation(); help_dialog = new vvHelpDialog(); dicomSeriesSelector = new vvDicomSeriesSelector(); +#if CLITK_USE_PACS_CONNECTION + PacsConnection = new vvQPacsConnection(); +#endif inverseButton->setEnabled(0); actionAdd_overlay_image_to_current_image->setEnabled(0); @@ -272,6 +282,9 @@ 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())); +#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())); connect(actionOpen_Multiple_Images_As_One,SIGNAL(triggered()),this,SLOT(MergeImages())); @@ -374,6 +387,9 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() 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); @@ -386,6 +402,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() 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())); @@ -403,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"); } //------------------------------------------------------------------------------ @@ -758,7 +778,24 @@ void vvMainWindow::OpenDicom() files = *(dicomSeriesSelector->GetFilenames()); LoadImages(files, vvImageReader::DICOM); } -} +} +#if CLITK_USE_PACS_CONNECTION +void vvMainWindow::ConnectPacs() +{ + std::vector files; + + //std::cout << "dicomSeriesSelector " << std::endl; +if (PacsConnection->exec() == QDialog::Accepted) { + for (int i = 0; i < PacsConnection->getSeriesCount(); i++) + { + files = PacsConnection->getFileNames(i); + LoadImages(files, vvImageReader::DICOM); + } + PacsConnection->clearMove(); + } + } + +#endif //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ @@ -786,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); +} +//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ @@ -872,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"; @@ -925,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)), @@ -954,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++; } @@ -1142,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 + ")"; @@ -1343,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; } @@ -1383,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) @@ -3245,7 +3333,11 @@ void vvMainWindow::SaveSEScreenshot() //------------------------------------------------------------------------------ void vvMainWindow::SaveScreenshotAllSlices() { +#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9 + QVTKOpenGLNativeWidget *widget = NOViewWidget; +#else QVTKWidget *widget = NOViewWidget; +#endif int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]); vvSlicerManager * SM = mSlicerManagers[index]; @@ -3271,7 +3363,11 @@ void vvMainWindow::SaveScreenshotAllSlices() // Screenshot vtkSmartPointer windowToImageFilter = vtkSmartPointer::New(); windowToImageFilter->SetInput(renderWindow); +#if (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9 + windowToImageFilter->SetScale(1); +#else windowToImageFilter->SetMagnification(1); +#endif windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel windowToImageFilter->Update(); @@ -3297,22 +3393,24 @@ void vvMainWindow::SaveScreenshotAllSlices() //------------------------------------------------------------------------------ +#if (VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 2) || VTK_MAJOR_VERSION >= 9 +void vvMainWindow::SaveScreenshot(QVTKOpenGLNativeWidget *widget) +#else void vvMainWindow::SaveScreenshot(QVTKWidget *widget) +#endif { - QString Extensions = "Images( *.png);;"; - Extensions += "Images( *.jpg);;"; - Extensions += "Images( *.bmp);;"; - Extensions += "Images( *.tif);;"; - Extensions += "Images( *.ppm)"; + QString Extensions = "*.png;;"; + Extensions += "*.jpg;;"; + Extensions += "*.bmp;;"; + Extensions += "*.tif;;"; + Extensions += "*.ppm"; #if defined(VTK_USE_FFMPEG_ENCODER) || defined(VTK_USE_VIDEO_FOR_WINDOWS) - Extensions += ";;Video( *.avi)"; + Extensions += ";;*.avi Video"; #endif #ifdef VTK_USE_MPEG2_ENCODER - Extensions += ";;Video( *.mpg)"; -#endif -#ifdef CLITK_EXPERIMENTAL - Extensions += ";;Video( *.gif)"; + Extensions += ";;*.mpg Video"; #endif + Extensions += ";;*.gif Video"; int smIndex=GetSlicerIndexFromItem(DataTree->selectedItems()[0]); QString fileName = QFileDialog::getSaveFileName(this, @@ -3323,8 +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 >= 2) || VTK_MAJOR_VERSION >= 9 + w2i->SetScale(1); +#else w2i->SetMagnification(1); - w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel +#endif + //w2i->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel w2i->Update(); vtkImageData *image = w2i->GetOutput(); @@ -3357,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; @@ -3382,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(); @@ -3671,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()));