]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Romulo: fixed log file, AppendOn was missing
[clitk.git] / vv / vvMainWindow.cxx
index 5266fc15f236f1490d2d0bc40b00cd6510e4f3c8..0673eae896c5dbe7d3f355daa42fcd9e92b5c531 100644 (file)
 #include "vtkPNMWriter.h"
 #include "vtkPNGWriter.h"
 #include "vtkJPEGWriter.h"
+#include "vtkMatrix4x4.h"
+#include "vtkTransform.h"
 
 // Standard includes
 #include <iostream>
+#include <sstream>
+#include <iomanip>
 
 #define COLUMN_TREE 0
 #define COLUMN_UL_VIEW 1
@@ -275,7 +279,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 
   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)));
@@ -331,7 +335,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 void vvMainWindow::UpdateMemoryUsage()
 {
   //  clitk::PrintMemory(true);
-  infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB");
+  if (clitk::GetMemoryUsageInMb() == 0) infoPanel->setMemoryInMb("NA");
+  else infoPanel->setMemoryInMb(QString::number(clitk::GetMemoryUsageInMb())+" MiB");
 }
 //------------------------------------------------------------------------------
 
@@ -913,8 +918,6 @@ void vvMainWindow::LoadImages(std::vector<std::string> 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 {
@@ -942,9 +945,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++) {
@@ -958,7 +958,6 @@ void vvMainWindow::CurrentImageChanged(std::string id)
 
   }
   DataTree->topLevelItem(selected)->setSelected(1);
-  // DD(mSlicerManagers[selected]->GetFileName());
   mCurrentSelectedImageId = id;
   emit SelectedImageHasChanged(mSlicerManagers[selected]);
 }
@@ -996,6 +995,7 @@ void vvMainWindow::ImageInfoChanged()
     std::vector<double> inputSpacing;
     std::vector<int> inputSize;
     std::vector<double> sizeMM;
+    vtkSmartPointer<vtkMatrix4x4> transformation;
     int dimension=0;
     QString pixelType;
     QString inputSizeInBytes;
@@ -1029,6 +1029,7 @@ void vvMainWindow::ImageInfoChanged()
         sizeMM[i] = inputSize[i]*inputSpacing[i];
         NPixel *= inputSize[i];
       }
+      transformation = imageSelected->GetTransform()->GetMatrix();
       inputSizeInBytes = GetSizeInBytes(imageSelected->GetActualMemorySize()*1000);
     } else if (DataTree->selectedItems()[0]->data(1,Qt::UserRole).toString() == "vector") {
       vvImage::Pointer imageSelected = mSlicerManagers[index]->GetSlicer(0)->GetVF();
@@ -1090,6 +1091,7 @@ void vvMainWindow::ImageInfoChanged()
     infoPanel->setOrigin(GetVectorDoubleAsString(origin));
     infoPanel->setSpacing(GetVectorDoubleAsString(inputSpacing));
     infoPanel->setNPixel(QString::number(NPixel)+" ("+inputSizeInBytes+")");
+    infoPanel->setTransformation(Get4x4MatrixDoubleAsString(transformation));
 
     landmarksPanel->SetCurrentLandmarks(mSlicerManagers[index]->GetLandmarks(),
                                         mSlicerManagers[index]->GetSlicer(0)->GetImage()->GetVTKImages().size());
@@ -1105,8 +1107,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());
 
@@ -1240,6 +1240,29 @@ QString vvMainWindow::GetSizeInBytes(unsigned long size)
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+QString vvMainWindow::Get4x4MatrixDoubleAsString(vtkSmartPointer<vtkMatrix4x4> 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<double> vectorDouble)
 {
@@ -1609,6 +1632,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());
   }
 }
 //------------------------------------------------------------------------------
@@ -1813,7 +1838,6 @@ void vvMainWindow::AddOverlayImage(int index, QString file)
 //------------------------------------------------------------------------------
 void vvMainWindow::AddROI(int index, QString file)
 {
-  DD("AddImageAndROI");
   /*
   // Get slice manager
 
@@ -2063,7 +2087,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()) {
@@ -2071,6 +2095,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
@@ -2199,7 +2224,6 @@ 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()) {
       mSlicerManagers[i]->RemoveLink(image2.toStdString());
@@ -2334,8 +2358,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();