-/*=========================================================================
- Program: vv http://www.creatis.insa-lyon.fr/rio/vv
-
- Authors belong to:
- - University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the copyright notices for more information.
-
- It is distributed under dual licence
-
- - BSD See included LICENSE.txt file
- - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
- ======================================================================-====*/
-
-#include "vvSlicerManager.h"
-#include "vvSlicer.h"
-#include "vvImage.h"
-#include "vvSlicerManagerCommand.h"
-#include "vvInteractorStyleNavigator.h"
-#include "vvLandmarks.h"
-#include "vvMesh.h"
-#include "vvBlendImageActor.h"
-
-#include <vtkImageActor.h>
-#include <vtkImageData.h>
-#include <vtkRenderWindow.h>
-#include <vtkRendererCollection.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkImageMapToWindowLevelColors.h>
-#include <vtkWindowLevelLookupTable.h>
-#include <vtkColorTransferFunction.h>
-#include <vtkImageClip.h>
-#include <vtkLODActor.h>
-#include <vtkPointData.h>
-#include <vtksys/SystemTools.hxx>
-#include <vtkCamera.h>
-
-#include <qfileinfo.h>
-//----------------------------------------------------------------------------
-vvSlicerManager::vvSlicerManager(int numberOfSlicers)
-{
- mFileName = "";
- mId = "";
- mVFName = "";
- mOverlayName = "";
- mFusionName = "";
- mVFId = "";
- mLastError = "";
- mType = vvImageReader::UNDEFINEDIMAGETYPE;
- mColorMap = 0;
- mPreset = 0;
- mOverlayColor = 130;
-
- mFusionOpacity = 30;
- mFusionThresOpacity = 1;
- mFusionColorMap = 3;
- mFusionWindow = 1000;
- mFusionLevel = 1000;
- mFusionShowLegend = true;
-
- mFusionSequenceFrameIndex = -1;
- mFusionSequenceSpatialSyncFlag = false;
- mFusionSequenceNbFrames = 0;
-
- mLandmarks = NULL;
- mLinkedId.resize(0);
-
- for ( int i = 0; i < numberOfSlicers; i++)
- mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());
- mSelectedSlicer = -1;
-
- mPreviousSlice.resize(numberOfSlicers);
- mPreviousTSlice.resize(numberOfSlicers);
- mSlicingPreset = WORLD_SLICING;
-
-
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-vvSlicerManager::~vvSlicerManager()
-{
- if (mLandmarks)
- delete mLandmarks;
-}
-//----------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvSlicerManager::SetFilename(std::string filename, int number)
-{
- mFileName = filename;
- mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
- mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
- mBaseFileNameNumber = number;
-
- mFileName = mBaseFileName;
- if (number != 0) {
- mFileName.append("_"+clitk::toString(number));
- }
- mFileName.append(vtksys::SystemTools::GetFilenameLastExtension(filename));
-
- for(unsigned int i=0; i<mSlicers.size(); i++) {
- mSlicers[i]->SetFileName(mFileName);//vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
- }
-
-}
-//------------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->AddContour(contour,propagate);
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ToggleContourSuperposition()
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++)
- mSlicers[i]->ToggleContourSuperposition();
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-std::string vvSlicerManager::GetListOfAbsoluteFilePathInOneString(const std::string &actorType)
-{
- vvImageReader *reader = NULL;
-
- if(actorType=="image")
- reader = mReader;
- else if(actorType=="overlay")
- reader = mOverlayReader;
- else if(actorType=="fusion")
- reader = mFusionReader;
- else if(actorType=="vector")
- reader = mVectorReader;
- else if(actorType=="fusionSequence")
- reader = mFusionSequenceReader;
-
- if(!reader)
- return "";
-
- std::string list;
- for(unsigned int i=0; i<reader->GetInputFilenames().size(); i++){
- QFileInfo fileinfo(reader->GetInputFilenames()[i].c_str()); //Do not show the path
- if(i)
- list += '\n';
- list += fileinfo.absoluteFilePath().toStdString();
- }
- return list;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetImage(std::string filename, vvImageReader::LoadedImageType type, int n, unsigned int slice)
-{
- mType = type;
- if (mReader.IsNull())
- mReader = vvImageReader::New();
- std::vector<std::string> filenames;
- filenames.push_back(filename);
- mReader->SetInputFilenames(filenames);
- mReader->SetSlice(slice); // Only used for SLICED type
- mReader->Update(type);
-
- SetFilename(filename, n);
- // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
- //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
- //mBaseFileNameNumber = n;
-
- if (mReader->GetLastError().size() == 0) {
- mImage=mReader->GetOutput();
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));
- mSlicers[i]->SetImage(mReader->GetOutput());
- }
- } else {
- mLastError = mReader->GetLastError();
- return false;
- }
- // if (n!=0) {
- // mFileName.append("_"+clitk::toString(n));
- // }
- return true;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetImage(vvImage::Pointer image)
-{
- mImage=image;
- for (unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetImage(image);
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n)
-{
- mType = type;
- std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);
- if (type == vvImageReader::DICOM)
- fileWithoutExtension += "_dicom";
- else if (type == vvImageReader::MERGED)
- fileWithoutExtension += "_merged";
- else if (type == vvImageReader::MERGEDWITHTIME)
- fileWithoutExtension += "_merged_wt";
-
- mFileName = vtksys::SystemTools::GetFilenameName(mFileName);
- mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);
- if (mReader.IsNull())
- mReader = vvImageReader::New();
- mReader->SetInputFilenames(filenames);
- mReader->Update(type);
-
- mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));
- mBaseFileNameNumber = n;
-
- if (mReader->GetLastError().size() == 0) {
- mImage=mReader->GetOutput();
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFileName(fileWithoutExtension);
- mSlicers[i]->SetImage(mReader->GetOutput());
- }
- } else {
- mLastError = mReader->GetLastError();
- return false;
- }
- if (n!=0) {
- mFileName.append("_"+clitk::toString(n));
- }
- return true;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetOverlay(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)
-{
- mOverlayName = filenames[0];
- mOverlayComponent = component;
- if (dim > mImage->GetNumberOfDimensions()) {
- mLastError = " Overlay dimension cannot be greater than reference image!";
- return false;
- }
- if (mOverlayReader.IsNull())
- mOverlayReader = vvImageReader::New();
- mOverlayReader->SetInputFilenames(filenames);
- mOverlayReader->Update(type);
- if (mOverlayReader->GetLastError().size() == 0) {
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
- }
- } else {
- mLastError = mOverlayReader->GetLastError();
- return false;
- }
- return true;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)
-{
- mFusionName = filename;
- mFusionComponent = component;
- if (dim > mImage->GetNumberOfDimensions()) {
- mLastError = " Overlay dimension cannot be greater then reference image!";
- return false;
- }
- if (mFusionReader.IsNull())
- mFusionReader = vvImageReader::New();
- std::vector<std::string> filenames;
- filenames.push_back(filename);
- mFusionReader->SetInputFilenames(filenames);
- mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);
- if (mFusionReader->GetLastError().size() == 0) {
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFusion(mFusionReader->GetOutput());
- }
- } else {
- mLastError = mFusionReader->GetLastError();
- return false;
- }
- double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
- mFusionLevel = (fusRange[0]+fusRange[1])/2;
- mFusionWindow = fusRange[1]-fusRange[0];
-
- return true;
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetFusionSequence(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)
-{
- mFusionName = filenames[0];
- mFusionComponent = component;
-
- if (dim > mImage->GetNumberOfDimensions()) {
- mLastError = " Fusion Sequence dimension cannot be greater than reference image!";
- return false;
- }
-
- if (mFusionSequenceReader.IsNull())
- mFusionSequenceReader = vvImageReader::New();
-
- mFusionSequenceReader->SetInputFilenames(filenames);
- mFusionSequenceReader->Update(type);
-
- //store the initial transform matrices of each frame, and reset them to identity
- mFusionSequenceListInitialTransformMatrices.clear();
- for (unsigned i=0 ; i<mFusionSequenceReader->GetOutput()->GetTransform().size() ; i++) {
- AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );
- mFusionSequenceReader->GetOutput()->GetTransform()[i]->Identity();
- mFusionSequenceReader->GetOutput()->GetTransform()[i]->Update();
- }
-
- //adjust the time slider in the overlay panel
- mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size()-1; //actually, this is the maximum index...
- if (mFusionSequenceFrameIndex>=mFusionSequenceNbFrames) {
- mFusionSequenceFrameIndex=0;
- }
-
-
- if (mFusionSequenceReader->GetLastError().size() == 0) {
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput());
- }
- } else {
- mLastError = mFusionSequenceReader->GetLastError();
- return false;
- }
- double *fusRange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
- mFusionLevel = (fusRange[0]+fusRange[1])/2;
- mFusionWindow = fusRange[1]-fusRange[0];
-
- return true;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetVF(std::string filename)
-{
- if (mVectorReader.IsNull())
- mVectorReader = vvImageReader::New();
- mVectorReader->SetInputFilename(filename);
-
- if (mType == vvImageReader::IMAGEWITHTIME)
- mVectorReader->Update(vvImageReader::VECTORFIELDWITHTIME);
- else
- mVectorReader->Update(vvImageReader::VECTORFIELD);
- if (mVectorReader->GetLastError().size() != 0) {
- mLastError = mVectorReader->GetLastError();
- return false;
- } else
- return SetVF(mVectorReader->GetOutput(),filename);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
-{
- if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
- mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
- return false;
- }
- if (vf->GetNumberOfDimensions() == 4) {
- if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {
- mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";
- return false;
- }
- if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {
- mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";
- return false;
- }
- }
- mVF=vf;
- mVFName = filename;
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetVF(vf);
- }
- return true;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-vvSlicer* vvSlicerManager::GetSlicer(int i)
-{
- return mSlicers[i];
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateSlicer(int num, bool state)
-{
- if (mSlicers[num]->GetImage())
- mSlicers[num]->SetDisplayMode(state);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)
-{
- mSlicers[i]->SetRenderWindow(i,RW);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)
-{
- vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();
- smc->SM = this;
- smc->SetSlicerNumber(i);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
-
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);
- // mSlicers[i]->GetRenderWindow()->GetInteractor()->
- // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);
- mSlicers[i]->GetRenderWindow()->GetInteractor()->
- GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);
- smc->Delete();
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::LeftButtonReleaseEvent(int slicer)
-{
- emit LeftButtonReleaseSignal(slicer);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::EmitMousePositionUpdated(int slicer)
-{
- emit MousePositionUpdatedSignal(slicer);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::EmitKeyPressed(std::string KeyPress)
-{
- emit KeyPressedSignal(KeyPress);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetSliceOrientation(int slicer, int orientation)
-{
- mSlicers[slicer]->SetSliceOrientation(orientation);
- emit UpdateOrientation(slicer, orientation);
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-int vvSlicerManager::GetTSlice()
-{
- return mSlicers[0]->GetTSlice();
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetTSlice(int slice)
-{
- if (slice < 0)
- slice = 0;
- else if (slice > mSlicers[0]->GetTMax())
- slice = mSlicers[0]->GetTMax();
- if (mLandmarks)
- mLandmarks->SetTime(slice);
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- if (slice != mSlicers[i]->GetMaxCurrentTSlice()) {
- mSlicers[i]->SetTSlice(slice);
- UpdateTSlice(i);
- }
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetFusionSequenceTSlice(int slice)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFusionSequenceTSlice(slice);
- UpdateTSlice(i);
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetNextTSlice(int originating_slicer)
-{
- int t = mSlicers[0]->GetMaxCurrentTSlice();
- t++;
- if (t > mSlicers[0]->GetTMax())
- t = 0;
- //std::cout << "vvSlicerManager::SetNextTSlice" << std::endl;
- emit UpdateTSlice(originating_slicer,t);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetPreviousTSlice(int originating_slicer)
-{
- int t = mSlicers[0]->GetMaxCurrentTSlice();
- t--;
- if (t < 0)
- t = mSlicers[0]->GetTMax();
- //std::cout << "vvSlicerManager::SetPreviousTSlice" << std::endl;
- emit UpdateTSlice(originating_slicer,t);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ToggleInterpolation()
-{
- bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);
- if (mSlicers[i]->GetOverlayActor())
- mSlicers[i]->GetOverlayActor()->SetInterpolate(interpolate);
- if (mSlicers[i]->GetFusionActor())
- mSlicers[i]->GetFusionActor()->SetInterpolate(interpolate);
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)
-{
- if (tslice < 0)
- tslice = 0;
- else if (tslice > mSlicers[slicer]->GetTMax())
- tslice = mSlicers[slicer]->GetTMax();
- if (mLandmarks)
- mLandmarks->SetTime(tslice);
-
- if (mSlicers[slicer]->GetMaxCurrentTSlice() == tslice) return;
-
- mSlicers[slicer]->SetTSlice(tslice);
-
- if(mSlicingPreset==VOXELS_SLICING) {
- vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
- mImage->GetTransform()[mSlicers[slicer]->GetTSlice()]->GetInverse(imageTransformInverse);
- this->GetSlicer(slicer)->GetSlicingTransform()->SetMatrix(imageTransformInverse);
- imageTransformInverse->Delete();
- }
-
- UpdateTSlice(slicer);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetColorWindow(double s)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetColorWindow(s);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetColorLevel(double s)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetColorLevel(s);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetOverlayColorWindow(double s)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetOverlayColorWindow(s);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetOverlayColorLevel(double s)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetOverlayColorLevel(s);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetLinkOverlayWindowLevel(bool b)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetLinkOverlayWindowLevel(b);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetCursorVisibility(s);
- mSlicers[i]->SetCornerAnnotationVisibility(s);
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetOpacity(int i, double factor)
-{
- mSlicers[i]->SetOpacity(1/factor);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateViews(int current,int slicer)
-{
- double p[3], pt[3];
- p[0] = mSlicers[slicer]->GetCurrentPosition()[0];
- p[1] = mSlicers[slicer]->GetCurrentPosition()[1];
- p[2] = mSlicers[slicer]->GetCurrentPosition()[2];
- mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);
-
- double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])
- /mSlicers[slicer]->GetInput()->GetSpacing()[0];
- double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])
- /mSlicers[slicer]->GetInput()->GetSpacing()[1];
- double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])
- /mSlicers[slicer]->GetInput()->GetSpacing()[2];
-
- if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&
- x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&
- y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&
- y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&
- z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&
- z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
- mSlicers[slicer]->UpdateCursorPosition();
- mSlicers[slicer]->SetCursorColor(10,212,255);
- mSelectedSlicer = slicer;
-
- switch (mSlicers[slicer]->GetSliceOrientation()) {
- case vtkImageViewer2::SLICE_ORIENTATION_XY:
- if (mSlicers[slicer]->GetSlice() != (int)lrint(z))
- mSlicers[slicer]->SetSlice((int)lrint(z));
- break;
-
- case vtkImageViewer2::SLICE_ORIENTATION_XZ:
- if (mSlicers[slicer]->GetSlice() != (int)lrint(y))
- mSlicers[slicer]->SetSlice((int)lrint(y));
- break;
-
- case vtkImageViewer2::SLICE_ORIENTATION_YZ:
- if (mSlicers[slicer]->GetSlice() != (int)lrint(x))
- mSlicers[slicer]->SetSlice((int)lrint(x));
- break;
- }
- mSlicers[slicer]->Render();
-
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- if (i != (unsigned int)slicer
- && mSlicers[i]->GetRenderer()->GetDraw()
- && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2
- && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {
- mSlicers[i]->SetCurrentPosition(p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());
- mSlicers[i]->UpdateCursorPosition();
- if (current) { //do not display corner annotation if image is the one picked
- mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
- -VTK_DOUBLE_MAX, mSlicers[slicer]->GetMaxCurrentTSlice());
- mSlicers[i]->SetCursorColor(255,10,212);
- } else {
- mSlicers[i]->SetCursorColor(150,10,282);
- }
- switch (mSlicers[i]->GetSliceOrientation()) {
- case vtkImageViewer2::SLICE_ORIENTATION_XY:
- if (mSlicers[i]->GetSlice() != (int)lrint(z))
- mSlicers[i]->SetSlice((int)lrint(z));
- break;
-
- case vtkImageViewer2::SLICE_ORIENTATION_XZ:
- if (mSlicers[i]->GetSlice() != (int)lrint(y))
- mSlicers[i]->SetSlice((int)lrint(y));
- break;
-
- case vtkImageViewer2::SLICE_ORIENTATION_YZ:
- if (mSlicers[i]->GetSlice() != (int)lrint(x))
- mSlicers[i]->SetSlice((int)lrint(x));
- break;
- }
-
- mSlicers[i]->Render();
-
- UpdateSlice(i);
- UpdateTSlice(i);
- }
- }
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateLinked(int slicer)
-{
- double p[3], pt[3];
- p[0] = mSlicers[slicer]->GetCurrentPosition()[0];
- p[1] = mSlicers[slicer]->GetCurrentPosition()[1];
- p[2] = mSlicers[slicer]->GetCurrentPosition()[2];
- mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);
- double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0]) / mSlicers[slicer]->GetInput()->GetSpacing()[0];
- double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1]) / mSlicers[slicer]->GetInput()->GetSpacing()[1];
- double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2]) / mSlicers[slicer]->GetInput()->GetSpacing()[2];
-
- if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&
- x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&
- y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&
- y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&
- z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&
- z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {
- for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {
- emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());
- }
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagate)
-{
- vtkCamera *refCam = refSlicer->GetRenderer()->GetActiveCamera();
-
- double refPosition[3];
- refCam->GetPosition(refPosition);
- refPosition[refSlicer->GetSliceOrientation()] = refSlicer->GetSlice() *
- refSlicer->GetInput()->GetSpacing()[refSlicer->GetSliceOrientation()] +
- refSlicer->GetInput()->GetOrigin()[refSlicer->GetSliceOrientation()];
-
- refSlicer->GetSlicingTransform()->TransformPoint(refPosition, refPosition);
- mSlicers[0]->GetSlicingTransform()->GetInverse()->TransformPoint(refPosition, refPosition);
-
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- vtkCamera *camera = mSlicers[i]->GetRenderer()->GetActiveCamera();
- camera->SetParallelScale(refCam->GetParallelScale());
-
- double position[3], focal[3];
- camera->GetPosition(position);
- camera->GetFocalPoint(focal);
-
- for(int j=0; j<3; j++) {
- if(j!=mSlicers[i]->GetSliceOrientation()) {
- position[j] = refPosition[j];
- focal[j] = refPosition[j];
- }
- }
-
- camera->SetFocalPoint(focal);
- camera->SetPosition(position);
-
- //Fix for bug #243
- mSlicers[i]->ForceUpdateDisplayExtent();
- }
-
- Render();
- if(bPropagate)
- for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)
- emit UpdateLinkedNavigation(*i, this, refSlicer);
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-double vvSlicerManager::GetColorWindow() const
-{
- if (mSlicers.size())
- return mSlicers[0]->GetColorWindow();
- return -1;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-double vvSlicerManager::GetColorLevel() const
-{
- if (mSlicers.size())
- return mSlicers[0]->GetColorLevel();
- return -1;
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-double vvSlicerManager::GetOverlayColorWindow() const
-{
- if (mSlicers.size())
- return mSlicers[0]->GetOverlayColorWindow();
- return -1;
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-double vvSlicerManager::GetOverlayColorLevel() const
-{
- if (mSlicers.size())
- return mSlicers[0]->GetOverlayColorLevel();
- return -1;
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-bool vvSlicerManager::GetLinkOverlayWindowLevel() const
-{
- if (mSlicers.size())
- return mSlicers[0]->GetLinkOverlayWindowLevel();
- return -1;
-}
-//----------------------------------------------------------------------------
-
-//------------------------------------------------------------------------------
-void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)
-{
- if(actorType == "image")
- for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
- this->GetImage()->GetTransform()[i]->Identity();
- else if(actorType == "overlay")
- for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
- this->GetSlicer(0)->GetOverlay()->GetTransform()[i]->Identity();
- else if(actorType == "fusion")
- for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
- this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
- else if(actorType == "fusionSequence") //TODO: Check what should really be done here
- for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
- this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();
- else if(actorType == "vf")
- for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)
- this->GetVF()->GetTransform()[i]->Identity();
- else
- return;
-
- for(int i=0; i< this->GetNumberOfSlicers(); i++){
- this->GetSlicer(i)->ForceUpdateDisplayExtent();
- this->GetSlicer(i)->ResetCamera();
- this->GetSlicer(i)->Render();
- }
-}
-//------------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::Render()
-{
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->Render();
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::GenerateDefaultLookupTable()
-{
- SetPreset(mPreset);
- SetColorMap(mColorMap);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::Reload()
-{
- mReader->Update(mType);
- mImage=mReader->GetOutput();
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetImage(mImage);
- }
- //TODO: check if this image is involved in a fusion sequence, then the main transform matrix should be updated.
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ReloadFusion()
-{
- mFusionReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),mType);
-
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFusion(mFusionReader->GetOutput());
- mSlicers[i]->Render();
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ReloadFusionSequence()
-{
- mFusionSequenceReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),vvImageReader::MERGEDWITHTIME);
-
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput());
- mSlicers[i]->Render();
- }
-
- //Update the slider
- mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size();
- if (mFusionSequenceFrameIndex>=mFusionSequenceNbFrames) {
- mFusionSequenceFrameIndex=0;
- }
-
- //Update the list of initial transforms
- //Warning, the main transform will not be updated on reload.........
- mFusionSequenceListInitialTransformMatrices.clear();
- for (unsigned i=0 ; i<mFusionSequenceNbFrames ; i++) {
- this->AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );
- }
-
- //emit UpdateFusionSequence(mFusionSequenceFrameIndex, mFusionSequenceSpatialSyncFlag, mFusionSequenceNbFrames);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ReloadOverlay()
-{
- mOverlayReader->Update(mImage->GetNumberOfDimensions(),mOverlayComponent.c_str(),mType);
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());
- mSlicers[i]->Render();
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::ReloadVF()
-{
- mVectorReader->Update(vvImageReader::VECTORFIELD); //deletes the old images through the VF::Init() function
- mVF=mVectorReader->GetOutput();
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetVF(mVF);
- mSlicers[i]->Render();
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)
-{
- if (actor_type =="overlay")
- mOverlayReader = NULL;
-
- if (actor_type =="fusion")
- mFusionReader = NULL;
-
- if (actor_type =="fusionSequence") {
- mFusionSequenceReader = NULL;
- }
-
- for (unsigned int i = 0; i < mSlicers.size(); i++)
- mSlicers[i]->RemoveActor(actor_type,overlay_index);
-
- if (actor_type=="vector") {
- mVF=NULL;
- mVectorReader=NULL;
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::RemoveActors()
-{
- ///This method leaks a few objects. See RemoveActor for what a
- ///correct implementation would look like
- //DS -> probably due to the reader (now released in the
- //RemoveActor() function. (I hope)
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
- mSlicers[i]->SetDisplayMode(0);
- mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)
-{
- // int view = mSlicers[slicer]->GetSliceOrientation();
- // int slice = mSlicers[slicer]->GetSlice();
- double x = mSlicers[slicer]->GetCursorPosition()[0];
- double y = mSlicers[slicer]->GetCursorPosition()[1];
- double z = mSlicers[slicer]->GetCursorPosition()[2];
- double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/
- mSlicers[slicer]->GetInput()->GetSpacing()[0];
- double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/
- mSlicers[slicer]->GetInput()->GetSpacing()[1];
- double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/
- mSlicers[slicer]->GetInput()->GetSpacing()[2];
- double value = -VTK_DOUBLE_MAX;
- int displayVec = 0;
- double xVec=0, yVec=0, zVec=0, valueVec=0;
- int displayOver = 0;
- int displayFus = 0;
- double valueOver=0, valueFus=0;
- if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&
- X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&
- Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&
- Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&
- Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&
- Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {
- value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z);
-
- if (mSlicers[slicer]->GetVFActor() ) {
- displayVec = 1;
- unsigned int currentTime = mSlicers[slicer]->GetMaxCurrentTSlice();
- vtkImageData *vf = NULL;
-
- if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)
- vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];
- else
- vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];
-
- if (vf) {
- double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];
- double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];
- double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];
- xVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 0);
- yVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 1);
- zVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 2);
- valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);
- }
- }
- if (mSlicers[slicer]->GetOverlayActor() ) {
- displayOver = 1;
- vtkImageData *overlay = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput());
- double Xover = (x - overlay->GetOrigin()[0]) / overlay->GetSpacing()[0];
- double Yover = (y - overlay->GetOrigin()[1]) / overlay->GetSpacing()[1];
- double Zover = (z - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2];
- valueOver = this->GetScalarComponentAsDouble(overlay, Xover, Yover, Zover);
- }
-\r
- if (mSlicers[slicer]->GetFusionActor() ) {\r
+/*=========================================================================\r
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv\r
+\r
+ Authors belong to:\r
+ - University of LYON http://www.universite-lyon.fr/\r
+ - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr\r
+ - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr\r
+\r
+ This software is distributed WITHOUT ANY WARRANTY; without even\r
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\r
+ PURPOSE. See the copyright notices for more information.\r
+\r
+ It is distributed under dual licence\r
+\r
+ - BSD See included LICENSE.txt file\r
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html\r
+ ======================================================================-====*/\r
+\r
+#include "vvSlicerManager.h"\r
+#include "vvSlicer.h"\r
+#include "vvImage.h"\r
+#include "vvSlicerManagerCommand.h"\r
+#include "vvInteractorStyleNavigator.h"\r
+#include "vvLandmarks.h"\r
+#include "vvMesh.h"\r
+#include "vvBlendImageActor.h"\r
+\r
+#include <vtkImageActor.h>\r
+#include <vtkImageData.h>\r
+#include <vtkRenderWindow.h>\r
+#include <vtkRendererCollection.h>\r
+#include <vtkRenderWindowInteractor.h>\r
+#include <vtkImageMapToWindowLevelColors.h>\r
+#include <vtkWindowLevelLookupTable.h>\r
+#include <vtkColorTransferFunction.h>\r
+#include <vtkImageClip.h>\r
+#include <vtkLODActor.h>\r
+#include <vtkPointData.h>\r
+#include <vtksys/SystemTools.hxx>\r
+#include <vtkCamera.h>\r
+\r
+#include <qfileinfo.h>\r
+//----------------------------------------------------------------------------\r
+vvSlicerManager::vvSlicerManager(int numberOfSlicers)\r
+{\r
+ mFileName = "";\r
+ mId = "";\r
+ mVFName = "";\r
+ mOverlayName = "";\r
+ mFusionName = "";\r
+ mVFId = "";\r
+ mLastError = "";\r
+ mType = vvImageReader::UNDEFINEDIMAGETYPE;\r
+ mColorMap = 0;\r
+ mPreset = 0;\r
+ mOverlayColor = 130;\r
+\r
+ mFusionOpacity = 30;\r
+ mFusionThresOpacity = 1;\r
+ mFusionColorMap = 3;\r
+ mFusionWindow = 1000;\r
+ mFusionLevel = 1000;\r
+ mFusionShowLegend = true;\r
+ \r
+ mFusionSequenceFrameIndex = -1;\r
+ mFusionSequenceSpatialSyncFlag = false;\r
+ mFusionSequenceNbFrames = 0;\r
+ mFusionSequenceIndexLinkedManager = -1;\r
+\r
+ mLandmarks = NULL;\r
+ mLinkedId.resize(0);\r
+\r
+ for ( int i = 0; i < numberOfSlicers; i++)\r
+ mSlicers.push_back(vtkSmartPointer<vvSlicer>::New());\r
+ mSelectedSlicer = -1;\r
+ \r
+ mPreviousSlice.resize(numberOfSlicers);\r
+ mPreviousTSlice.resize(numberOfSlicers);\r
+ mSlicingPreset = WORLD_SLICING;\r
+\r
+ \r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+vvSlicerManager::~vvSlicerManager()\r
+{\r
+ if (mLandmarks)\r
+ delete mLandmarks;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//------------------------------------------------------------------------------\r
+void vvSlicerManager::SetFilename(std::string filename, int number)\r
+{\r
+ mFileName = filename;\r
+ mFileName = vtksys::SystemTools::GetFilenameName(mFileName);\r
+ mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));\r
+ mBaseFileNameNumber = number;\r
+\r
+ mFileName = mBaseFileName;\r
+ if (number != 0) {\r
+ mFileName.append("_"+clitk::toString(number));\r
+ }\r
+ mFileName.append(vtksys::SystemTools::GetFilenameLastExtension(filename));\r
+\r
+ for(unsigned int i=0; i<mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFileName(mFileName);//vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));\r
+ }\r
+ \r
+}\r
+//------------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::AddContour(vvMesh::Pointer contour,bool propagate)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->AddContour(contour,propagate);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ToggleContourSuperposition()\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++)\r
+ mSlicers[i]->ToggleContourSuperposition();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+std::string vvSlicerManager::GetListOfAbsoluteFilePathInOneString(const std::string &actorType)\r
+{\r
+ vvImageReader *reader = NULL;\r
+\r
+ if(actorType=="image")\r
+ reader = mReader;\r
+ else if(actorType=="overlay")\r
+ reader = mOverlayReader;\r
+ else if(actorType=="fusion")\r
+ reader = mFusionReader;\r
+ else if(actorType=="vector")\r
+ reader = mVectorReader;\r
+ else if(actorType=="fusionSequence")\r
+ reader = mFusionSequenceReader;\r
+\r
+ if(!reader)\r
+ return "";\r
+\r
+ std::string list;\r
+ for(unsigned int i=0; i<reader->GetInputFilenames().size(); i++){\r
+ QFileInfo fileinfo(reader->GetInputFilenames()[i].c_str()); //Do not show the path\r
+ if(i)\r
+ list += '\n';\r
+ list += fileinfo.absoluteFilePath().toStdString();\r
+ }\r
+ return list;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetImage(std::string filename, vvImageReader::LoadedImageType type, int n, unsigned int slice)\r
+{\r
+ mType = type;\r
+ if (mReader.IsNull())\r
+ mReader = vvImageReader::New();\r
+ std::vector<std::string> filenames;\r
+ filenames.push_back(filename);\r
+ mReader->SetInputFilenames(filenames);\r
+ mReader->SetSlice(slice); // Only used for SLICED type\r
+ mReader->Update(type);\r
+\r
+ SetFilename(filename, n);\r
+ // mFileName = vtksys::SystemTools::GetFilenameName(mFileName);\r
+ //mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));\r
+ //mBaseFileNameNumber = n;\r
+\r
+ if (mReader->GetLastError().size() == 0) {\r
+ mImage=mReader->GetOutput();\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFileName(vtksys::SystemTools::GetFilenameWithoutLastExtension(filename));\r
+ mSlicers[i]->SetImage(mReader->GetOutput());\r
+ }\r
+ } else {\r
+ mLastError = mReader->GetLastError();\r
+ return false;\r
+ }\r
+ // if (n!=0) {\r
+ // mFileName.append("_"+clitk::toString(n));\r
+ // }\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetImage(vvImage::Pointer image)\r
+{\r
+ mImage=image;\r
+ for (unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetImage(image);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n)\r
+{\r
+ mType = type;\r
+ std::string fileWithoutExtension = vtksys::SystemTools::GetFilenameWithoutExtension(filenames[0]);\r
+ if (type == vvImageReader::DICOM)\r
+ fileWithoutExtension += "_dicom";\r
+ else if (type == vvImageReader::MERGED)\r
+ fileWithoutExtension += "_merged";\r
+ else if (type == vvImageReader::MERGEDWITHTIME)\r
+ fileWithoutExtension += "_merged_wt";\r
+\r
+ mFileName = vtksys::SystemTools::GetFilenameName(mFileName);\r
+ mFileName = fileWithoutExtension + vtksys::SystemTools::GetFilenameExtension(filenames[0]);\r
+ if (mReader.IsNull())\r
+ mReader = vvImageReader::New();\r
+ mReader->SetInputFilenames(filenames);\r
+ mReader->Update(type);\r
+\r
+ mBaseFileName = vtksys::SystemTools::GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(mFileName));\r
+ mBaseFileNameNumber = n;\r
+\r
+ if (mReader->GetLastError().size() == 0) {\r
+ mImage=mReader->GetOutput();\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFileName(fileWithoutExtension);\r
+ mSlicers[i]->SetImage(mReader->GetOutput());\r
+ }\r
+ } else {\r
+ mLastError = mReader->GetLastError();\r
+ return false;\r
+ }\r
+ if (n!=0) {\r
+ mFileName.append("_"+clitk::toString(n));\r
+ }\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetOverlay(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)\r
+{\r
+ mOverlayName = filenames[0];\r
+ mOverlayComponent = component;\r
+ if (dim > mImage->GetNumberOfDimensions()) {\r
+ mLastError = " Overlay dimension cannot be greater than reference image!";\r
+ return false;\r
+ }\r
+ if (mOverlayReader.IsNull())\r
+ mOverlayReader = vvImageReader::New();\r
+ mOverlayReader->SetInputFilenames(filenames);\r
+ mOverlayReader->Update(type);\r
+ if (mOverlayReader->GetLastError().size() == 0) {\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());\r
+ }\r
+ } else {\r
+ mLastError = mOverlayReader->GetLastError();\r
+ return false;\r
+ }\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetFusion(std::string filename,int dim, std::string component)\r
+{\r
+ mFusionName = filename;\r
+ mFusionComponent = component;\r
+ if (dim > mImage->GetNumberOfDimensions()) {\r
+ mLastError = " Overlay dimension cannot be greater then reference image!";\r
+ return false;\r
+ }\r
+ if (mFusionReader.IsNull())\r
+ mFusionReader = vvImageReader::New();\r
+ std::vector<std::string> filenames;\r
+ filenames.push_back(filename);\r
+ mFusionReader->SetInputFilenames(filenames);\r
+ mFusionReader->Update(mImage->GetNumberOfDimensions(),component.c_str(),mType);\r
+ if (mFusionReader->GetLastError().size() == 0) {\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFusion(mFusionReader->GetOutput());\r
+ }\r
+ } else {\r
+ mLastError = mFusionReader->GetLastError();\r
+ return false;\r
+ }\r
+ double *fusRange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();\r
+ mFusionLevel = (fusRange[0]+fusRange[1])/2;\r
+ mFusionWindow = fusRange[1]-fusRange[0];\r
+\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetFusionSequence(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type)\r
+{\r
+ mFusionName = filenames[0];\r
+ mFusionComponent = component;\r
+\r
+ if (dim > mImage->GetNumberOfDimensions()) {\r
+ mLastError = " Fusion Sequence dimension cannot be greater than reference image!";\r
+ return false;\r
+ }\r
+\r
+ if (mFusionSequenceReader.IsNull())\r
+ mFusionSequenceReader = vvImageReader::New();\r
+\r
+ mFusionSequenceReader->SetInputFilenames(filenames);\r
+ mFusionSequenceReader->Update(type);\r
+\r
+\r
+ if (mFusionSequenceReader->GetLastError().size() == 0) {\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), true);\r
+ }\r
+ } else {\r
+ mLastError = mFusionSequenceReader->GetLastError();\r
+ return false;\r
+ }\r
+ double *fusRange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();\r
+ mFusionLevel = (fusRange[0]+fusRange[1])/2;\r
+ mFusionWindow = fusRange[1]-fusRange[0];\r
+\r
+ //store the initial transform matrices of each frame, and reset them to identity\r
+ mFusionSequenceListInitialTransformMatrices.clear();\r
+ for (unsigned i=0 ; i<mFusionSequenceReader->GetOutput()->GetTransform().size() ; i++) {\r
+ AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );\r
+ mFusionSequenceReader->GetOutput()->GetTransform()[i]->Identity();\r
+ mFusionSequenceReader->GetOutput()->GetTransform()[i]->Update();\r
+ }\r
+\r
+ //adjust the time slider in the overlay panel\r
+ mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size()-1; //actually, this is the maximum index...\r
+ mFusionSequenceFrameIndex = std::max<int>( 0, std::min<int>(mFusionSequenceFrameIndex, mFusionSequenceNbFrames));\r
+\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetVF(std::string filename)\r
+{\r
+ if (mVectorReader.IsNull())\r
+ mVectorReader = vvImageReader::New();\r
+ mVectorReader->SetInputFilename(filename);\r
+ \r
+ if (mType == vvImageReader::IMAGEWITHTIME)\r
+ mVectorReader->Update(vvImageReader::VECTORFIELDWITHTIME);\r
+ else\r
+ mVectorReader->Update(vvImageReader::VECTORFIELD);\r
+ if (mVectorReader->GetLastError().size() != 0) {\r
+ mLastError = mVectorReader->GetLastError();\r
+ return false;\r
+ } else\r
+ return SetVF(mVectorReader->GetOutput(),filename);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)\r
+{\r
+ if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {\r
+ mLastError = "Sorry, vector field dimension cannot be greater then reference image.";\r
+ return false;\r
+ }\r
+ if (vf->GetNumberOfDimensions() == 4) {\r
+ if (vf->GetSpacing()[3] != mImage->GetSpacing()[3]) {\r
+ mLastError = "Sorry, vector field time spacing cannot be different from time spacing of the reference image.";\r
+ return false;\r
+ }\r
+ if (vf->GetOrigin()[3] != mImage->GetOrigin()[3]) {\r
+ mLastError = "Sorry, vector field time origin cannot be different from time origin of the reference image.";\r
+ return false;\r
+ }\r
+ }\r
+ mVF=vf;\r
+ mVFName = filename;\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetVF(vf);\r
+ }\r
+ return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+vvSlicer* vvSlicerManager::GetSlicer(int i)\r
+{\r
+ return mSlicers[i];\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateSlicer(int num, bool state)\r
+{\r
+ if (mSlicers[num]->GetImage())\r
+ mSlicers[num]->SetDisplayMode(state);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetSlicerWindow(int i, vtkRenderWindow* RW)\r
+{\r
+ mSlicers[i]->SetRenderWindow(i,RW);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetInteractorStyleNavigator(int i, vtkInteractorStyle* style)\r
+{\r
+ vvSlicerManagerCommand *smc = vvSlicerManagerCommand::New();\r
+ smc->SM = this;\r
+ smc->SetSlicerNumber(i);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);\r
+\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::KeyPressEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::WindowLevelEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::EndWindowLevelEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::StartWindowLevelEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::PickEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::StartPickEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::LeaveEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::UserEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelForwardEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::MouseWheelBackwardEvent, smc);\r
+ // mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ // GetInteractorStyle()->AddObserver(vtkCommand::LeftButtonReleaseEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::EndPickEvent, smc);\r
+ mSlicers[i]->GetRenderWindow()->GetInteractor()->\r
+ GetInteractorStyle()->AddObserver(vtkCommand::EndInteractionEvent, smc);\r
+ smc->Delete();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::LeftButtonReleaseEvent(int slicer)\r
+{\r
+ emit LeftButtonReleaseSignal(slicer);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::EmitMousePositionUpdated(int slicer)\r
+{\r
+ emit MousePositionUpdatedSignal(slicer);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::EmitKeyPressed(std::string KeyPress)\r
+{\r
+ emit KeyPressedSignal(KeyPress);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetSliceOrientation(int slicer, int orientation)\r
+{\r
+ mSlicers[slicer]->SetSliceOrientation(orientation);\r
+ emit UpdateOrientation(slicer, orientation);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+int vvSlicerManager::GetTSlice()\r
+{\r
+ return mSlicers[0]->GetTSlice();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetTSlice(int slice, bool updateLinkedImages)\r
+{\r
+ if (!updateLinkedImages) {\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetTSlice(slice, updateLinkedImages);\r
+ UpdateTSlice(i);\r
+ }\r
+ return;\r
+ }\r
+\r
+\r
+ if (slice < 0)\r
+ slice = 0;\r
+ else if (slice > mSlicers[0]->GetTMax())\r
+ slice = mSlicers[0]->GetTMax();\r
+ if (mLandmarks)\r
+ mLandmarks->SetTime(slice);\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ if (slice != mSlicers[i]->GetMaxCurrentTSlice()) {\r
+ mSlicers[i]->SetTSlice(slice, updateLinkedImages);\r
+ UpdateTSlice(i);\r
+ }\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetFusionSequenceTSlice(int slice)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFusionSequenceTSlice(slice);\r
+ UpdateTSlice(i);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetNextTSlice(int originating_slicer)\r
+{\r
+ int t = mSlicers[0]->GetMaxCurrentTSlice();\r
+ t++;\r
+ if (t > mSlicers[0]->GetTMax())\r
+ t = 0;\r
+ //std::cout << "vvSlicerManager::SetNextTSlice" << std::endl;\r
+ emit UpdateTSlice(originating_slicer,t);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetPreviousTSlice(int originating_slicer)\r
+{\r
+ int t = mSlicers[0]->GetMaxCurrentTSlice();\r
+ t--;\r
+ if (t < 0)\r
+ t = mSlicers[0]->GetTMax();\r
+ //std::cout << "vvSlicerManager::SetPreviousTSlice" << std::endl;\r
+ emit UpdateTSlice(originating_slicer,t);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ToggleInterpolation()\r
+{\r
+ bool interpolate=!(mSlicers[0]->GetImageActor()->GetInterpolate());\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->GetImageActor()->SetInterpolate(interpolate);\r
+ if (mSlicers[i]->GetOverlayActor())\r
+ mSlicers[i]->GetOverlayActor()->SetInterpolate(interpolate);\r
+ if (mSlicers[i]->GetFusionActor())\r
+ mSlicers[i]->GetFusionActor()->SetInterpolate(interpolate);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetTSliceInSlicer(int tslice, int slicer)\r
+{\r
+ if (tslice < 0)\r
+ tslice = 0;\r
+ else if (tslice > mSlicers[slicer]->GetTMax())\r
+ tslice = mSlicers[slicer]->GetTMax();\r
+ if (mLandmarks)\r
+ mLandmarks->SetTime(tslice);\r
+\r
+ if (mSlicers[slicer]->GetMaxCurrentTSlice() == tslice) return;\r
+\r
+ mSlicers[slicer]->SetTSlice(tslice);\r
+\r
+ if(mSlicingPreset==VOXELS_SLICING) {\r
+ vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();\r
+ mImage->GetTransform()[mSlicers[slicer]->GetTSlice()]->GetInverse(imageTransformInverse);\r
+ this->GetSlicer(slicer)->GetSlicingTransform()->SetMatrix(imageTransformInverse);\r
+ imageTransformInverse->Delete();\r
+ }\r
+\r
+ UpdateTSlice(slicer);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetColorWindow(double s)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetColorWindow(s);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetColorLevel(double s)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetColorLevel(s);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetOverlayColorWindow(double s)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetOverlayColorWindow(s);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetOverlayColorLevel(double s)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetOverlayColorLevel(s);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetLinkOverlayWindowLevel(bool b)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetLinkOverlayWindowLevel(b);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetCursorAndCornerAnnotationVisibility(int s)\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetCursorVisibility(s);\r
+ mSlicers[i]->SetCornerAnnotationVisibility(s);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetOpacity(int i, double factor)\r
+{\r
+ mSlicers[i]->SetOpacity(1/factor);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateViews(int current,int slicer)\r
+{\r
+ double p[3], pt[3];\r
+ p[0] = mSlicers[slicer]->GetCurrentPosition()[0];\r
+ p[1] = mSlicers[slicer]->GetCurrentPosition()[1];\r
+ p[2] = mSlicers[slicer]->GetCurrentPosition()[2];\r
+ mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);\r
+\r
+ double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0])\r
+ /mSlicers[slicer]->GetInput()->GetSpacing()[0];\r
+ double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1])\r
+ /mSlicers[slicer]->GetInput()->GetSpacing()[1];\r
+ double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2])\r
+ /mSlicers[slicer]->GetInput()->GetSpacing()[2];\r
+\r
+ if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&\r
+ x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&\r
+ y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&\r
+ y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&\r
+ z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&\r
+ z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {\r
+ mSlicers[slicer]->UpdateCursorPosition();\r
+ mSlicers[slicer]->SetCursorColor(10,212,255);\r
+ mSelectedSlicer = slicer;\r
+\r
+ switch (mSlicers[slicer]->GetSliceOrientation()) {\r
+ case vtkImageViewer2::SLICE_ORIENTATION_XY:\r
+ if (mSlicers[slicer]->GetSlice() != (int)lrint(z))\r
+ mSlicers[slicer]->SetSlice((int)lrint(z));\r
+ break;\r
+\r
+ case vtkImageViewer2::SLICE_ORIENTATION_XZ:\r
+ if (mSlicers[slicer]->GetSlice() != (int)lrint(y))\r
+ mSlicers[slicer]->SetSlice((int)lrint(y));\r
+ break;\r
+\r
+ case vtkImageViewer2::SLICE_ORIENTATION_YZ:\r
+ if (mSlicers[slicer]->GetSlice() != (int)lrint(x))\r
+ mSlicers[slicer]->SetSlice((int)lrint(x));\r
+ break;\r
+ }\r
+ mSlicers[slicer]->Render();\r
+\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ if (i != (unsigned int)slicer\r
+ && mSlicers[i]->GetRenderer()->GetDraw()\r
+ && mSlicers[i]->GetRenderWindow()->GetSize()[0] > 2\r
+ && mSlicers[i]->GetRenderWindow()->GetSize()[1] > 2) {\r
+ mSlicers[i]->SetCurrentPosition(p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());\r
+ mSlicers[i]->UpdateCursorPosition();\r
+ if (current) { //do not display corner annotation if image is the one picked\r
+ mSlicers[i]->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,\r
+ -VTK_DOUBLE_MAX, mSlicers[slicer]->GetMaxCurrentTSlice());\r
+ mSlicers[i]->SetCursorColor(255,10,212);\r
+ } else {\r
+ mSlicers[i]->SetCursorColor(150,10,282);\r
+ }\r
+ switch (mSlicers[i]->GetSliceOrientation()) {\r
+ case vtkImageViewer2::SLICE_ORIENTATION_XY:\r
+ if (mSlicers[i]->GetSlice() != (int)lrint(z))\r
+ mSlicers[i]->SetSlice((int)lrint(z));\r
+ break;\r
+\r
+ case vtkImageViewer2::SLICE_ORIENTATION_XZ:\r
+ if (mSlicers[i]->GetSlice() != (int)lrint(y))\r
+ mSlicers[i]->SetSlice((int)lrint(y));\r
+ break;\r
+\r
+ case vtkImageViewer2::SLICE_ORIENTATION_YZ:\r
+ if (mSlicers[i]->GetSlice() != (int)lrint(x))\r
+ mSlicers[i]->SetSlice((int)lrint(x));\r
+ break;\r
+ }\r
+ \r
+ mSlicers[i]->Render();\r
+ \r
+ UpdateSlice(i);\r
+ UpdateTSlice(i);\r
+ }\r
+ }\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateLinked(int slicer)\r
+{\r
+ double p[3], pt[3];\r
+ p[0] = mSlicers[slicer]->GetCurrentPosition()[0];\r
+ p[1] = mSlicers[slicer]->GetCurrentPosition()[1];\r
+ p[2] = mSlicers[slicer]->GetCurrentPosition()[2];\r
+ mSlicers[slicer]->GetSlicingTransform()->GetInverse()->TransformPoint(p, pt);\r
+ double x = (pt[0] - mSlicers[slicer]->GetInput()->GetOrigin()[0]) / mSlicers[slicer]->GetInput()->GetSpacing()[0];\r
+ double y = (pt[1] - mSlicers[slicer]->GetInput()->GetOrigin()[1]) / mSlicers[slicer]->GetInput()->GetSpacing()[1];\r
+ double z = (pt[2] - mSlicers[slicer]->GetInput()->GetOrigin()[2]) / mSlicers[slicer]->GetInput()->GetSpacing()[2];\r
+\r
+ if (x >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0]-0.5 &&\r
+ x <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1]+0.5 &&\r
+ y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2]-0.5 &&\r
+ y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3]+0.5 &&\r
+ z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4]-0.5 &&\r
+ z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]+0.5) {\r
+ for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++) {\r
+ if (mFusionSequenceIndexLinkedManager>0) {\r
+ //this SlicerManager is involved in fusionSequence => do not synchronize the times\r
+ emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], -1);\r
+ }\r
+ else {\r
+ emit UpdateLinkManager(*i, slicer, p[0], p[1], p[2], mSlicers[slicer]->GetMaxCurrentTSlice());\r
+ }\r
+ }\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateLinkedNavigation(vvSlicer *refSlicer, bool bPropagate)\r
+{\r
+ vtkCamera *refCam = refSlicer->GetRenderer()->GetActiveCamera();\r
+\r
+ double refPosition[3];\r
+ refCam->GetPosition(refPosition);\r
+ refPosition[refSlicer->GetSliceOrientation()] = refSlicer->GetSlice() *\r
+ refSlicer->GetInput()->GetSpacing()[refSlicer->GetSliceOrientation()] +\r
+ refSlicer->GetInput()->GetOrigin()[refSlicer->GetSliceOrientation()];\r
+\r
+ refSlicer->GetSlicingTransform()->TransformPoint(refPosition, refPosition);\r
+ mSlicers[0]->GetSlicingTransform()->GetInverse()->TransformPoint(refPosition, refPosition);\r
+\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ vtkCamera *camera = mSlicers[i]->GetRenderer()->GetActiveCamera();\r
+ camera->SetParallelScale(refCam->GetParallelScale());\r
+\r
+ double position[3], focal[3];\r
+ camera->GetPosition(position);\r
+ camera->GetFocalPoint(focal);\r
+\r
+ for(int j=0; j<3; j++) {\r
+ if(j!=mSlicers[i]->GetSliceOrientation()) {\r
+ position[j] = refPosition[j];\r
+ focal[j] = refPosition[j];\r
+ }\r
+ }\r
+\r
+ camera->SetFocalPoint(focal);\r
+ camera->SetPosition(position);\r
+\r
+ //Fix for bug #243\r
+ mSlicers[i]->ForceUpdateDisplayExtent();\r
+ }\r
+ \r
+ Render();\r
+ if(bPropagate)\r
+ for (std::list<std::string>::const_iterator i = mLinkedId.begin(); i != mLinkedId.end(); i++)\r
+ emit UpdateLinkedNavigation(*i, this, refSlicer);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+double vvSlicerManager::GetColorWindow() const\r
+{\r
+ if (mSlicers.size())\r
+ return mSlicers[0]->GetColorWindow();\r
+ return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+double vvSlicerManager::GetColorLevel() const\r
+{\r
+ if (mSlicers.size())\r
+ return mSlicers[0]->GetColorLevel();\r
+ return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+double vvSlicerManager::GetOverlayColorWindow() const\r
+{\r
+ if (mSlicers.size())\r
+ return mSlicers[0]->GetOverlayColorWindow();\r
+ return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+double vvSlicerManager::GetOverlayColorLevel() const\r
+{\r
+ if (mSlicers.size())\r
+ return mSlicers[0]->GetOverlayColorLevel();\r
+ return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+bool vvSlicerManager::GetLinkOverlayWindowLevel() const\r
+{\r
+ if (mSlicers.size())\r
+ return mSlicers[0]->GetLinkOverlayWindowLevel();\r
+ return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//------------------------------------------------------------------------------\r
+void vvSlicerManager::ResetTransformationToIdentity(const std::string actorType)\r
+{\r
+ if(actorType == "image")\r
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)\r
+ this->GetImage()->GetTransform()[i]->Identity();\r
+ else if(actorType == "overlay")\r
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)\r
+ this->GetSlicer(0)->GetOverlay()->GetTransform()[i]->Identity();\r
+ else if(actorType == "fusion")\r
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)\r
+ this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();\r
+ else if(actorType == "fusionSequence") //TODO: Check what should really be done here\r
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)\r
+ this->GetSlicer(0)->GetFusion()->GetTransform()[i]->Identity();\r
+ else if(actorType == "vf")\r
+ for(unsigned int i=0; i<this->GetImage()->GetTransform().size(); i++)\r
+ this->GetVF()->GetTransform()[i]->Identity();\r
+ else\r
+ return;\r
+\r
+ for(int i=0; i< this->GetNumberOfSlicers(); i++){\r
+ this->GetSlicer(i)->ForceUpdateDisplayExtent();\r
+ this->GetSlicer(i)->ResetCamera();\r
+ this->GetSlicer(i)->Render();\r
+ }\r
+}\r
+//------------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::Render()\r
+{\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->Render();\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::GenerateDefaultLookupTable()\r
+{\r
+ SetPreset(mPreset);\r
+ SetColorMap(mColorMap);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::Reload()\r
+{\r
+ mReader->Update(mType);\r
+ mImage=mReader->GetOutput();\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetImage(mImage);\r
+ }\r
+ \r
+ //check if this image is involved in a fusion sequence, then the main transform matrix should be updated.\r
+ if (mFusionSequenceReader.IsNotNull()) {\r
+ SetFusionSequenceMainTransformMatrix( mImage->GetTransform()[0]->GetMatrix() );\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ReloadFusion()\r
+{\r
+ mFusionReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),mType);\r
+\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFusion(mFusionReader->GetOutput());\r
+ mSlicers[i]->Render();\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ReloadFusionSequence()\r
+{\r
+ mFusionSequenceReader->Update(mImage->GetNumberOfDimensions(),mFusionComponent.c_str(),vvImageReader::MERGEDWITHTIME);\r
+\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetFusion(mFusionSequenceReader->GetOutput(), true);\r
+ mSlicers[i]->Render();\r
+ }\r
+\r
+ //Update the slider\r
+ mFusionSequenceNbFrames = mFusionSequenceReader->GetOutput()->GetTransform().size();\r
+ if (mFusionSequenceFrameIndex>=mFusionSequenceNbFrames) {\r
+ mFusionSequenceFrameIndex=0;\r
+ }\r
+\r
+ //Update the list of initial transforms\r
+ //Warning, the main transform will not be updated on reload.........\r
+ mFusionSequenceListInitialTransformMatrices.clear();\r
+ for (unsigned i=0 ; i<mFusionSequenceNbFrames ; i++) {\r
+ this->AddFusionSequenceInitialTransformMatrices( mFusionSequenceReader->GetOutput()->GetTransform()[i]->GetMatrix() );\r
+ }\r
+\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ReloadOverlay()\r
+{\r
+ mOverlayReader->Update(mImage->GetNumberOfDimensions(),mOverlayComponent.c_str(),mType);\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetOverlay(mOverlayReader->GetOutput());\r
+ mSlicers[i]->Render();\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::ReloadVF()\r
+{\r
+ mVectorReader->Update(vvImageReader::VECTORFIELD); //deletes the old images through the VF::Init() function\r
+ mVF=mVectorReader->GetOutput();\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetVF(mVF);\r
+ mSlicers[i]->Render();\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::RemoveActor(const std::string& actor_type, int overlay_index)\r
+{\r
+ if (actor_type =="overlay")\r
+ mOverlayReader = NULL;\r
+\r
+ if (actor_type =="fusion")\r
+ mFusionReader = NULL;\r
+\r
+ if (actor_type =="fusionSequence") {\r
+ mFusionSequenceReader = NULL;\r
+ }\r
+\r
+ for (unsigned int i = 0; i < mSlicers.size(); i++)\r
+ mSlicers[i]->RemoveActor(actor_type,overlay_index);\r
+\r
+ if (actor_type=="vector") {\r
+ mVF=NULL;\r
+ mVectorReader=NULL;\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::RemoveActors()\r
+{\r
+ ///This method leaks a few objects. See RemoveActor for what a\r
+ ///correct implementation would look like\r
+ //DS -> probably due to the reader (now released in the\r
+ //RemoveActor() function. (I hope)\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ mSlicers[i]->SetDisplayMode(0);\r
+ mSlicers[i]->GetRenderer()->RemoveActor(mSlicers[i]->GetImageActor());\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateInfoOnCursorPosition(int slicer)\r
+{\r
+//TODO: this is probably here that I shall prevent the overlayPanel to disappear when the mouse goes over the linked sequence!\r
+ // int view = mSlicers[slicer]->GetSliceOrientation();\r
+ // int slice = mSlicers[slicer]->GetSlice();\r
+ double x = mSlicers[slicer]->GetCursorPosition()[0];\r
+ double y = mSlicers[slicer]->GetCursorPosition()[1];\r
+ double z = mSlicers[slicer]->GetCursorPosition()[2];\r
+ double X = (x - mSlicers[slicer]->GetInput()->GetOrigin()[0])/\r
+ mSlicers[slicer]->GetInput()->GetSpacing()[0];\r
+ double Y = (y - mSlicers[slicer]->GetInput()->GetOrigin()[1])/\r
+ mSlicers[slicer]->GetInput()->GetSpacing()[1];\r
+ double Z = (z - mSlicers[slicer]->GetInput()->GetOrigin()[2])/\r
+ mSlicers[slicer]->GetInput()->GetSpacing()[2];\r
+ double value = -VTK_DOUBLE_MAX;\r
+ int displayVec = 0;\r
+ double xVec=0, yVec=0, zVec=0, valueVec=0;\r
+ int displayOver = 0;\r
+ int displayFus = 0;\r
+ double valueOver=0, valueFus=0;\r
+ if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] &&\r
+ X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] &&\r
+ Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] &&\r
+ Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] &&\r
+ Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] &&\r
+ Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) {\r
+\r
+ value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z);\r
+\r
+ if (mSlicers[slicer]->GetVFActor() ) {\r
+ displayVec = 1;\r
+ unsigned int currentTime = mSlicers[slicer]->GetMaxCurrentTSlice();\r
+ vtkImageData *vf = NULL;\r
+\r
+ if (mSlicers[slicer]->GetVF()->GetVTKImages().size() > currentTime)\r
+ vf = mSlicers[slicer]->GetVF()->GetVTKImages()[currentTime];\r
+ else\r
+ vf = mSlicers[slicer]->GetVF()->GetVTKImages()[0];\r
+\r
+ if (vf) {\r
+ double Xvf = (x - vf->GetOrigin()[0])/ vf->GetSpacing()[0];\r
+ double Yvf = (y - vf->GetOrigin()[1])/ vf->GetSpacing()[1];\r
+ double Zvf = (z - vf->GetOrigin()[2])/ vf->GetSpacing()[2];\r
+ xVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 0);\r
+ yVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 1);\r
+ zVec = this->GetScalarComponentAsDouble( vf, Xvf, Yvf, Zvf, 2);\r
+ valueVec = sqrt(xVec*xVec + yVec*yVec + zVec*zVec);\r
+ }\r
+ }\r
+ if (mSlicers[slicer]->GetOverlayActor() ) {\r
+ displayOver = 1;\r
+ vtkImageData *overlay = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetOverlayMapper()->GetInput());\r
+ double Xover = (x - overlay->GetOrigin()[0]) / overlay->GetSpacing()[0];\r
+ double Yover = (y - overlay->GetOrigin()[1]) / overlay->GetSpacing()[1];\r
+ double Zover = (z - overlay->GetOrigin()[2]) / overlay->GetSpacing()[2];\r
+ valueOver = this->GetScalarComponentAsDouble(overlay, Xover, Yover, Zover);\r
+ }\r
+\r
+ if ( mSlicers[slicer]->GetFusionActor() ) {\r
displayFus = 1;\r
vtkImageData *fusion = dynamic_cast<vtkImageData*>(mSlicers[slicer]->GetFusionMapper()->GetInput());\r
double Xover = (x - fusion->GetOrigin()[0]) / fusion->GetSpacing()[0];\r
double Zover = (z - fusion->GetOrigin()[2]) / fusion->GetSpacing()[2];\r
valueFus = this->GetScalarComponentAsDouble(fusion, Xover, Yover, Zover);\r
}\r
-
-
- emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),
- x,y,z,X,Y,Z,value);
- emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);
- emit UpdateOverlay(displayOver,valueOver,value);
- emit UpdateFusion(displayFus,valueFus);
- }
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::Activated()
-{
- emit currentImageChanged(mId);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::Picked()
-{
- emit currentPickedImageChanged(mId);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateWindowLevel()
-{
- emit WindowLevelChanged();
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateSlice(int slicer)
-{
- if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
- //DD("============= NOTHING");
- return;
- }
- //std::cout << "vvSlicerManager::UpdateSlice " << slicer << " " << mSlicers[slicer]->GetSlice() << std::endl;
- 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();
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateTSlice(int slicer)
-{
- int slice = mSlicers[slicer]->GetSlice();
- int tslice = mSlicers[slicer]->GetMaxCurrentTSlice();
- if (mPreviousSlice[slicer] == slice) {
- if (mPreviousTSlice[slicer] == tslice) {
- // DD("************** NOTHING ***********");
- return;
- }
- }
- mPreviousSlice[slicer] = slice;
- mPreviousTSlice[slicer] = tslice;
- //std::cout << "vvSlicerManager::UpdateTSlice " << slicer << " " << tslice << std::endl;
- emit UpdateTSlice(slicer, tslice);
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::UpdateSliceRange(int slicer)
-{
- emit UpdateSliceRange(slicer,
- mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],
- 0,mSlicers[slicer]->GetTMax());
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset)
-{
- if(mSlicingPreset==preset)
- return;
-
- vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();
- mImage->GetTransform()[this->GetTSlice()]->GetInverse(imageTransformInverse);
-
- for(int i=0; i< this->GetNumberOfSlicers(); i++){
- vvSlicer *s = this->GetSlicer(i);
- switch(preset)
- {
- case WORLD_SLICING:
- s->GetSlicingTransform()->Identity();
- break;
- case VOXELS_SLICING:
- s->GetSlicingTransform()->SetMatrix(imageTransformInverse);
- break;
- default:
- imageTransformInverse->Delete();
- return;
- }
- s->ForceUpdateDisplayExtent();
- s->SetSlice((s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2+1]
- +s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2])/2.0);
- s->ResetCamera();
- s->Render();
- }
-
- imageTransformInverse->Delete();
- mSlicingPreset = preset;
-}
-
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetPreset(int preset)
-{
- //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
- double window = mSlicers[0]->GetColorWindow();
- double level = mSlicers[0]->GetColorLevel();
-
- std::string component_type=mImage->GetScalarTypeAsITKString();
- switch (preset) {
- case 0:
- double range[2];
- mImage->GetScalarRange(range);
- window = range[1] - range[0];
- level = (range[1] + range[0])* 0.5;
- break;
- case 1:
- window = 2000;
- level = 0;
- break;
- case 2:
- window = 400;
- level = 20;
- break;
- case 3: // lungs (same as FOCAL)
- window = 1700;
- level = -300;
- break;
- case 4:
- window = 1000;
- level = 500;
- break;
- case 5:
- window = 1;
- level = 0.5;
- break;
- case 6:
- break;
- case 7:
- window=1.;
- level=0.;
- break;
- }
- mPreset = preset;
- this->SetColorWindow(window);
- this->SetColorLevel(level);
-
- //if (LUT)
- //{
- // SetColorMap(-1);
- //}
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlKey)
-{
- double min, max;
- if(bCtrlKey && this->mSlicers[slicer]->GetFusion()) {
- int t = mSlicers[slicer]->GetFusionTSlice();
- this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
- this->mSlicers[slicer]->GetFusion()->GetVTKImages()[t],
- this->mSlicers[slicer]->GetConcatenatedFusionTransform());
- this->SetFusionWindow(max-min);
- this->SetFusionLevel(0.5*(min+max));
- this->SetColorMap(mColorMap);
- }
- else if(bCtrlKey && this->mSlicers[slicer]->GetOverlay()) {
- int t = mSlicers[slicer]->GetOverlayTSlice();
- this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
- this->mSlicers[slicer]->GetOverlay()->GetVTKImages()[t],
- this->mSlicers[slicer]->GetConcatenatedOverlayTransform());
- if(this->mSlicers[slicer]->GetLinkOverlayWindowLevel()){
- this->SetColorWindow(max-min);
- this->SetColorLevel(0.5*(min+max));
- } else {
- this->SetOverlayColorWindow(max-min);
- this->SetOverlayColorLevel(0.5*(min+max));
- }
- }
- else {
- int t = this->GetTSlice();
- this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,
- this->mSlicers[slicer]->GetImage()->GetVTKImages()[t],
- this->mSlicers[slicer]->GetConcatenatedTransform());
- this->SetColorWindow(max-min);
- this->SetColorLevel(0.5*(min+max));
- this->SetPreset(6);
- }
- this->Render();
- this->UpdateWindowLevel();
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::SetColorMap(int colormap)
-{
- double range[2];
-
- range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];
- range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];
-
- double window = mSlicers[0]->GetWindowLevel()->GetWindow();
- double level = mSlicers[0]->GetWindowLevel()->GetLevel();
-
- vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());
- switch (colormap) {
- case -1:
- break;
- case 0:
- LUT = NULL;
- break;
- case 1:
- if (LUT == NULL)
- LUT = vtkLookupTable::New();
- LUT->SetValueRange(0,1);
- LUT->SetSaturationRange(1,1);
- LUT->SetHueRange(0,0.18);
- break;
- case 2:
- if (LUT == NULL)
- LUT = vtkLookupTable::New();
- LUT->SetValueRange(0,1);
- LUT->SetSaturationRange(1,1);
- LUT->SetHueRange(0.4,0.80);
- break;
- case 3:
- if (LUT == NULL)
- LUT = vtkLookupTable::New();
- LUT->SetValueRange(0.5,1);
- LUT->SetSaturationRange(1,1);
- LUT->SetHueRange(0.666,0);
- break;
- case 4:
- if (LUT == NULL)
- LUT = vtkLookupTable::New();
- LUT->SetValueRange(1,1);
- LUT->SetSaturationRange(1,1);
- LUT->SetHueRange(0,1);
- LUT->SetAlphaRange(1, 1);
- break;
- case 5:
- if (LUT == NULL)
- LUT = vtkLookupTable::New();
- LUT->SetValueRange(1,1);
- LUT->SetSaturationRange(1,1);
- LUT->SetHueRange(1,0.1);
- //LUT->SetRampToLinear();
- break;
- }
- if (LUT) {
- LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);
- LUT->Build();
- }
- vtkWindowLevelLookupTable* fusLUT = NULL;
- if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) {
- fusLUT = vtkWindowLevelLookupTable::New();
- double fusRange [2];
- fusRange[0] = mFusionLevel - mFusionWindow/2;
- fusRange[1] = mFusionLevel + mFusionWindow/2;
-
- //check whether it is actually a fusionSequence or a fusion, before invoking mFusionReader...
- double* frange;
- if (mFusionReader.IsNull()) frange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
- else frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();
-
- fusLUT->SetTableRange(frange);
- fusLUT->SetValueRange(1,1);
- fusLUT->SetSaturationRange(1,1);
- fusLUT->SetAlphaRange(1, 1);
- fusLUT->SetWindow(mFusionWindow);
- fusLUT->SetLevel(mFusionLevel);
- if (mFusionColorMap == 1)
- fusLUT->SetHueRange(0,0.18);
- else if (mFusionColorMap == 2)
- fusLUT->SetHueRange(0.4,0.80);
- else if (mFusionColorMap == 3)
- {
- fusLUT->SetHueRange(0.666, 0);
- fusLUT->SetValueRange(0.5, 1);
- }
- else if (mFusionColorMap == 4)
- fusLUT->SetHueRange(0,1);
- else if (mFusionColorMap <= 0)
- {
- fusLUT->SetValueRange(0,1);
- fusLUT->SetSaturationRange(0,0);
- }
-
- fusLUT->ForceBuild();
- double v[4];
-
- // set color table transparency
- //double alpha_range=(double)mFusionThresOpacity/10;
- double range_end = fusRange[0] + (double)mFusionThresOpacity*(fusRange[1] - fusRange[0])/100;
- double curr_value = fusRange[0];
- int nvalues = fusLUT->GetNumberOfTableValues();
- for (double i = 0; curr_value < range_end; i++) {
- fusLUT->GetTableValue(i, v);
- v[3] = 0;
- //if (curr_value >= -alpha_range && curr_value <= alpha_range) v[3] = pow(fabs(curr_value/alpha_range),2);
- //else v[3] = 1;
- fusLUT->SetTableValue(i, v);
- curr_value += (fusRange[1] - fusRange[0])/nvalues;
- }
- }
- for ( unsigned int i = 0; i < mSlicers.size(); i++) {
-
- if (mSlicers[i]->GetOverlay()) {
- vtkLookupTable* supLUT = vtkLookupTable::New();
- supLUT->SetTableRange(range[0],range[1]);
- supLUT->SetValueRange(1,1);
- supLUT->SetSaturationRange(1,1);
- supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);
- supLUT->Build();
- vtkLookupTable* invLUT = vtkLookupTable::New();
- invLUT->SetTableRange(range[0],range[1]);
- invLUT->SetValueRange(1,1);
- invLUT->SetSaturationRange(1,1);
- invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);
- invLUT->Build();
- mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);
- mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);
- invLUT->Delete();
- supLUT->Delete();
- } else if (mSlicers[i]->GetOverlay()) {
- mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
- } else {
- mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);
- }
-
- if (mSlicers[i]->GetFusion()) {
- mSlicers[i]->ShowFusionLegend(mFusionShowLegend);
- mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);
- mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);
- }
- }
- if (fusLUT)
- fusLUT->Delete();
- if (colormap >= 0)
- mColorMap = colormap;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-vvLandmarks* vvSlicerManager::GetLandmarks()
-{
- if (mLandmarks == NULL) {
- mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);
- for (unsigned int i = 0; i < mSlicers.size(); i++)
- mSlicers[i]->SetLandmarks(mLandmarks);
- }
- return mLandmarks;
-}
-//----------------------------------------------------------------------------
-
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::AddLandmark(float x,float y,float z,float t)
-{
- double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];
- double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];
- double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];
- if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0]-0.5 &&
- x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1]+0.5 &&
- y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2]-0.5 &&
- y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3]+0.5 &&
- z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4]-0.5 &&
- z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]+0.5) {
- double value = this->GetScalarComponentAsDouble(mSlicers[0]->GetInput(), x_index, y_index, z_index);
- this->GetLandmarks()->AddLandmark(x,y,z,t,value);
- emit LandmarkAdded();
- }
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::PrevImage(int slicer)
-{
- emit ChangeImageWithIndexOffset(this, slicer, -1);
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::NextImage(int slicer)
-{
- emit ChangeImageWithIndexOffset(this, slicer, 1);
-}
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)
-{
- emit AVerticalSliderHasChanged(slicer, slice);
-}
-
-//----------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------
-double vvSlicerManager::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component)
-{
- int ix, iy, iz;
- return mSlicers[0]->GetScalarComponentAsDouble(image, X, Y, Z, ix, iy, iz, component);
-}
-//----------------------------------------------------------------------------
+ else if (mFusionSequenceIndexLinkedManager>=0) {\r
+ displayFus = 1;\r
+ valueFus = std::numeric_limits<double>::quiet_NaN();\r
+ }\r
+\r
+ emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(),\r
+ x,y,z,X,Y,Z,value);\r
+ emit UpdateVector(displayVec,xVec, yVec, zVec, valueVec);\r
+ emit UpdateOverlay(displayOver,valueOver,value);\r
+ emit UpdateFusion(displayFus,valueFus);\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::Activated()\r
+{\r
+ emit currentImageChanged(mId);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::Picked()\r
+{\r
+ emit currentPickedImageChanged(mId);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateWindowLevel()\r
+{\r
+ emit WindowLevelChanged();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateSlice(int slicer)\r
+{\r
+ if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {\r
+ //DD("============= NOTHING");\r
+ return;\r
+ }\r
+ //std::cout << "vvSlicerManager::UpdateSlice " << slicer << " " << mSlicers[slicer]->GetSlice() << std::endl;\r
+ emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());\r
+ mSlicers[slicer]->Render(); // DS <-- I add this, this could/must be the only Render ...\r
+ mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateTSlice(int slicer)\r
+{\r
+ int slice = mSlicers[slicer]->GetSlice();\r
+ int tslice = mSlicers[slicer]->GetMaxCurrentTSlice();\r
+ \r
+ if (mFusionSequenceIndexLinkedManager>=0) tslice = mSlicers[slicer]->GetTSlice();\r
+\r
+ if (mPreviousSlice[slicer] == slice) {\r
+ if (mPreviousTSlice[slicer] == tslice) {\r
+ // DD("************** NOTHING ***********");\r
+ return;\r
+ }\r
+ }\r
+ mPreviousSlice[slicer] = slice;\r
+ mPreviousTSlice[slicer] = tslice;\r
+\r
+ if (mFusionSequenceIndexLinkedManager>=0) return;\r
+\r
+ emit UpdateTSlice(slicer, tslice);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::UpdateSliceRange(int slicer)\r
+{\r
+ emit UpdateSliceRange(slicer,\r
+ mSlicers[slicer]->GetSliceRange()[0], mSlicers[slicer]->GetSliceRange()[1],\r
+ 0,mSlicers[slicer]->GetTMax());\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetSlicingPreset(SlicingPresetType preset)\r
+{\r
+ if(mSlicingPreset==preset)\r
+ return;\r
+\r
+ vtkMatrix4x4 *imageTransformInverse = vtkMatrix4x4::New();\r
+ mImage->GetTransform()[this->GetTSlice()]->GetInverse(imageTransformInverse);\r
+\r
+ for(int i=0; i< this->GetNumberOfSlicers(); i++){\r
+ vvSlicer *s = this->GetSlicer(i);\r
+ switch(preset)\r
+ {\r
+ case WORLD_SLICING:\r
+ s->GetSlicingTransform()->Identity();\r
+ break;\r
+ case VOXELS_SLICING:\r
+ s->GetSlicingTransform()->SetMatrix(imageTransformInverse);\r
+ break;\r
+ default:\r
+ imageTransformInverse->Delete();\r
+ return;\r
+ }\r
+ s->ForceUpdateDisplayExtent();\r
+ s->SetSlice((s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2+1]\r
+ +s->GetInput()->GetWholeExtent()[s->GetSliceOrientation()*2])/2.0);\r
+ s->ResetCamera();\r
+ s->Render();\r
+ }\r
+\r
+ imageTransformInverse->Delete();\r
+ mSlicingPreset = preset;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetPreset(int preset)\r
+{\r
+ //vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());\r
+ double window = mSlicers[0]->GetColorWindow();\r
+ double level = mSlicers[0]->GetColorLevel();\r
+\r
+ std::string component_type=mImage->GetScalarTypeAsITKString();\r
+ switch (preset) {\r
+ case 0:\r
+ double range[2];\r
+ mImage->GetScalarRange(range);\r
+ window = range[1] - range[0];\r
+ level = (range[1] + range[0])* 0.5;\r
+ break;\r
+ case 1:\r
+ window = 2000;\r
+ level = 0;\r
+ break;\r
+ case 2:\r
+ window = 400;\r
+ level = 20;\r
+ break;\r
+ case 3: // lungs (same as FOCAL)\r
+ window = 1700;\r
+ level = -300;\r
+ break;\r
+ case 4:\r
+ window = 1000;\r
+ level = 500;\r
+ break;\r
+ case 5:\r
+ window = 1;\r
+ level = 0.5;\r
+ break;\r
+ case 6:\r
+ break;\r
+ case 7:\r
+ window=1.;\r
+ level=0.;\r
+ break;\r
+ }\r
+ mPreset = preset;\r
+ this->SetColorWindow(window);\r
+ this->SetColorLevel(level);\r
+\r
+ //if (LUT)\r
+ //{\r
+ // SetColorMap(-1);\r
+ //}\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetLocalColorWindowing(const int slicer, const bool bCtrlKey)\r
+{\r
+ double min, max;\r
+ if(bCtrlKey && this->mSlicers[slicer]->GetFusion()) {\r
+ int t = mSlicers[slicer]->GetFusionTSlice();\r
+ this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,\r
+ this->mSlicers[slicer]->GetFusion()->GetVTKImages()[t],\r
+ this->mSlicers[slicer]->GetConcatenatedFusionTransform());\r
+ this->SetFusionWindow(max-min);\r
+ this->SetFusionLevel(0.5*(min+max));\r
+ this->SetColorMap(mColorMap);\r
+ }\r
+ else if(bCtrlKey && this->mSlicers[slicer]->GetOverlay()) {\r
+ int t = mSlicers[slicer]->GetOverlayTSlice();\r
+ this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,\r
+ this->mSlicers[slicer]->GetOverlay()->GetVTKImages()[t],\r
+ this->mSlicers[slicer]->GetConcatenatedOverlayTransform());\r
+ if(this->mSlicers[slicer]->GetLinkOverlayWindowLevel()){\r
+ this->SetColorWindow(max-min);\r
+ this->SetColorLevel(0.5*(min+max));\r
+ } else {\r
+ this->SetOverlayColorWindow(max-min);\r
+ this->SetOverlayColorLevel(0.5*(min+max));\r
+ }\r
+ }\r
+ else {\r
+ int t = this->GetTSlice();\r
+ this->mSlicers[slicer]->GetExtremasAroundMousePointer(min, max,\r
+ this->mSlicers[slicer]->GetImage()->GetVTKImages()[t],\r
+ this->mSlicers[slicer]->GetConcatenatedTransform());\r
+ this->SetColorWindow(max-min);\r
+ this->SetColorLevel(0.5*(min+max));\r
+ this->SetPreset(6);\r
+ }\r
+ this->Render();\r
+ this->UpdateWindowLevel();\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::SetColorMap(int colormap)\r
+{\r
+ double range[2];\r
+\r
+ range[0] = mSlicers[0]->GetInput()->GetScalarRange()[0];\r
+ range[1] = mSlicers[0]->GetInput()->GetScalarRange()[1];\r
+\r
+ double window = mSlicers[0]->GetWindowLevel()->GetWindow();\r
+ double level = mSlicers[0]->GetWindowLevel()->GetLevel();\r
+\r
+ vtkLookupTable* LUT = static_cast<vtkLookupTable*>(mSlicers[0]->GetWindowLevel()->GetLookupTable());\r
+ switch (colormap) {\r
+ case -1:\r
+ break;\r
+ case 0:\r
+ LUT = NULL;\r
+ break;\r
+ case 1:\r
+ if (LUT == NULL)\r
+ LUT = vtkLookupTable::New();\r
+ LUT->SetValueRange(0,1);\r
+ LUT->SetSaturationRange(1,1);\r
+ LUT->SetHueRange(0,0.18);\r
+ break;\r
+ case 2:\r
+ if (LUT == NULL)\r
+ LUT = vtkLookupTable::New();\r
+ LUT->SetValueRange(0,1);\r
+ LUT->SetSaturationRange(1,1);\r
+ LUT->SetHueRange(0.4,0.80);\r
+ break;\r
+ case 3:\r
+ if (LUT == NULL)\r
+ LUT = vtkLookupTable::New();\r
+ LUT->SetValueRange(0.5,1);\r
+ LUT->SetSaturationRange(1,1);\r
+ LUT->SetHueRange(0.666,0);\r
+ break;\r
+ case 4:\r
+ if (LUT == NULL)\r
+ LUT = vtkLookupTable::New();\r
+ LUT->SetValueRange(1,1);\r
+ LUT->SetSaturationRange(1,1);\r
+ LUT->SetHueRange(0,1);\r
+ LUT->SetAlphaRange(1, 1);\r
+ break;\r
+ case 5:\r
+ if (LUT == NULL)\r
+ LUT = vtkLookupTable::New();\r
+ LUT->SetValueRange(1,1);\r
+ LUT->SetSaturationRange(1,1);\r
+ LUT->SetHueRange(1,0.1);\r
+ //LUT->SetRampToLinear();\r
+ break;\r
+ }\r
+ if (LUT) {\r
+ LUT->SetTableRange(level-fabs(window)/2,level+fabs(window)/2);\r
+ LUT->Build();\r
+ }\r
+ vtkWindowLevelLookupTable* fusLUT = NULL;\r
+ if (mSlicers[0]->GetFusion()) { // && mFusionColorMap >= 0) {\r
+ fusLUT = vtkWindowLevelLookupTable::New();\r
+ double fusRange [2];\r
+ fusRange[0] = mFusionLevel - mFusionWindow/2;\r
+ fusRange[1] = mFusionLevel + mFusionWindow/2;\r
+\r
+ //check whether it is actually a fusionSequence or a fusion, before invoking mFusionReader...\r
+ double* frange;\r
+ if (mFusionReader.IsNull()) frange = mFusionSequenceReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();\r
+ else frange = mFusionReader->GetOutput()->GetVTKImages()[0]->GetScalarRange();\r
+\r
+ fusLUT->SetTableRange(frange);\r
+ fusLUT->SetValueRange(1,1);\r
+ fusLUT->SetSaturationRange(1,1);\r
+ fusLUT->SetAlphaRange(1, 1);\r
+ fusLUT->SetWindow(mFusionWindow);\r
+ fusLUT->SetLevel(mFusionLevel);\r
+ if (mFusionColorMap == 1)\r
+ fusLUT->SetHueRange(0,0.18);\r
+ else if (mFusionColorMap == 2)\r
+ fusLUT->SetHueRange(0.4,0.80);\r
+ else if (mFusionColorMap == 3)\r
+ {\r
+ fusLUT->SetHueRange(0.666, 0);\r
+ fusLUT->SetValueRange(0.5, 1);\r
+ }\r
+ else if (mFusionColorMap == 4)\r
+ fusLUT->SetHueRange(0,1);\r
+ else if (mFusionColorMap <= 0)\r
+ {\r
+ fusLUT->SetValueRange(0,1);\r
+ fusLUT->SetSaturationRange(0,0);\r
+ }\r
+ \r
+ fusLUT->ForceBuild();\r
+ double v[4];\r
+ \r
+ // set color table transparency\r
+ //double alpha_range=(double)mFusionThresOpacity/10;\r
+ double range_end = fusRange[0] + (double)mFusionThresOpacity*(fusRange[1] - fusRange[0])/100;\r
+ double curr_value = fusRange[0];\r
+ int nvalues = fusLUT->GetNumberOfTableValues();\r
+ for (double i = 0; curr_value < range_end; i++) { \r
+ fusLUT->GetTableValue(i, v);\r
+ v[3] = 0;\r
+ //if (curr_value >= -alpha_range && curr_value <= alpha_range) v[3] = pow(fabs(curr_value/alpha_range),2);\r
+ //else v[3] = 1;\r
+ fusLUT->SetTableValue(i, v);\r
+ curr_value += (fusRange[1] - fusRange[0])/nvalues;\r
+ }\r
+ }\r
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {\r
+ \r
+ if (mSlicers[i]->GetOverlay()) {\r
+ vtkLookupTable* supLUT = vtkLookupTable::New();\r
+ supLUT->SetTableRange(range[0],range[1]);\r
+ supLUT->SetValueRange(1,1);\r
+ supLUT->SetSaturationRange(1,1);\r
+ supLUT->SetHueRange(double(mOverlayColor)/360,double(mOverlayColor)/360);\r
+ supLUT->Build();\r
+ vtkLookupTable* invLUT = vtkLookupTable::New();\r
+ invLUT->SetTableRange(range[0],range[1]);\r
+ invLUT->SetValueRange(1,1);\r
+ invLUT->SetSaturationRange(1,1);\r
+ invLUT->SetHueRange(double((mOverlayColor+180)%360)/360,double((mOverlayColor+180)%360)/360);\r
+ invLUT->Build();\r
+ mSlicers[i]->GetWindowLevel()->SetLookupTable(supLUT);\r
+ mSlicers[i]->GetOverlayMapper()->SetLookupTable(invLUT);\r
+ invLUT->Delete();\r
+ supLUT->Delete();\r
+ } else if (mSlicers[i]->GetOverlay()) {\r
+ mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);\r
+ } else {\r
+ mSlicers[i]->GetWindowLevel()->SetLookupTable(LUT);\r
+ }\r
+ \r
+ if (mSlicers[i]->GetFusion()) {\r
+ mSlicers[i]->ShowFusionLegend(mFusionShowLegend);\r
+ mSlicers[i]->GetFusionMapper()->SetLookupTable(fusLUT);\r
+ mSlicers[i]->GetFusionActor()->SetOpacity(double(mFusionOpacity)/100);\r
+ }\r
+ }\r
+ if (fusLUT)\r
+ fusLUT->Delete();\r
+ if (colormap >= 0)\r
+ mColorMap = colormap;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+vvLandmarks* vvSlicerManager::GetLandmarks()\r
+{\r
+ if (mLandmarks == NULL) {\r
+ mLandmarks = new vvLandmarks(mSlicers[0]->GetTMax()+1);\r
+ for (unsigned int i = 0; i < mSlicers.size(); i++)\r
+ mSlicers[i]->SetLandmarks(mLandmarks);\r
+ }\r
+ return mLandmarks;\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::AddLandmark(float x,float y,float z,float t)\r
+{\r
+ double x_index = (x - mSlicers[0]->GetInput()->GetOrigin()[0])/mSlicers[0]->GetInput()->GetSpacing()[0];\r
+ double y_index = (y - mSlicers[0]->GetInput()->GetOrigin()[1])/mSlicers[0]->GetInput()->GetSpacing()[1];\r
+ double z_index = (z - mSlicers[0]->GetInput()->GetOrigin()[2])/mSlicers[0]->GetInput()->GetSpacing()[2];\r
+ if (x_index >= mSlicers[0]->GetInput()->GetWholeExtent()[0]-0.5 &&\r
+ x_index <= mSlicers[0]->GetInput()->GetWholeExtent()[1]+0.5 &&\r
+ y_index >= mSlicers[0]->GetInput()->GetWholeExtent()[2]-0.5 &&\r
+ y_index <= mSlicers[0]->GetInput()->GetWholeExtent()[3]+0.5 &&\r
+ z_index >= mSlicers[0]->GetInput()->GetWholeExtent()[4]-0.5 &&\r
+ z_index <= mSlicers[0]->GetInput()->GetWholeExtent()[5]+0.5) {\r
+ double value = this->GetScalarComponentAsDouble(mSlicers[0]->GetInput(), x_index, y_index, z_index);\r
+ this->GetLandmarks()->AddLandmark(x,y,z,t,value);\r
+ emit LandmarkAdded();\r
+ }\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::PrevImage(int slicer)\r
+{\r
+ emit ChangeImageWithIndexOffset(this, slicer, -1);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::NextImage(int slicer)\r
+{\r
+ emit ChangeImageWithIndexOffset(this, slicer, 1);\r
+}\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice)\r
+{\r
+ emit AVerticalSliderHasChanged(slicer, slice);\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+\r
+//----------------------------------------------------------------------------\r
+double vvSlicerManager::GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component)\r
+{\r
+ int ix, iy, iz;\r
+ return mSlicers[0]->GetScalarComponentAsDouble(image, X, Y, Z, ix, iy, iz, component);\r
+}\r
+//----------------------------------------------------------------------------\r