X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=vv%2FvvImageContour.cxx;h=99da398bf92518b3bb5bfa6d8430dba2e34d619f;hb=dad240d633996ba10087d96ece317415086f5a59;hp=85a9f2bb05767de4d46f7931dfcc4460a2d873bd;hpb=0a85e47a06c7d046d06a4645b724c4e81b19998d;p=clitk.git
diff --git a/vv/vvImageContour.cxx b/vv/vvImageContour.cxx
index 85a9f2b..99da398 100644
--- a/vv/vvImageContour.cxx
+++ b/vv/vvImageContour.cxx
@@ -1,47 +1,46 @@
/*=========================================================================
+ Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Program: vv
- Module: $RCSfile: vvImageContour.cxx,v $
- Language: C++
- Date: $Date: 2010/02/24 11:42:42 $
- Version: $Revision: 1.3 $
- Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+ 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
- Copyright (C) 2010
- Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- CREATIS 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.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, version 3 of the License.
+ It is distributed under dual licence
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
- =========================================================================*/
+ - BSD See included LICENSE.txt file
+ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ ======================================================================-====*/
#include "vvImageContour.h"
+#include "vvImage.h"
#include
#include
+#include
#include
#include
#include
+#include
+#include
//------------------------------------------------------------------------------
-vvImageContour::vvImageContour() {
+vvImageContour::vvImageContour()
+{
mTSlice = -1;
mSlice = 0;
+ mHiddenImageIsUsed = false;
+ mDisplayModeIsPreserveMemory = true;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-vvImageContour::~vvImageContour() {
+vvImageContour::~vvImageContour()
+{
for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
}
@@ -53,120 +52,327 @@ vvImageContour::~vvImageContour() {
//------------------------------------------------------------------------------
-void vvImageContour::setSlicer(vvSlicer * slicer) {
+void vvImageContour::SetSlicer(vvSlicer * slicer) {
mSlicer = slicer;
-
+ // Create an actor for each time slice
for (unsigned int numImage = 0; numImage < mSlicer->GetImage()->GetVTKImages().size(); numImage++) {
- // DD(numImage);
vtkImageClip * mClipper = vtkImageClip::New();
vtkMarchingSquares * mSquares = vtkMarchingSquares::New();
- vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
vtkActor * mSquaresActor = vtkActor::New();
-
- mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
- mSquares->SetInput(mClipper->GetOutput());
- mSquaresMapper->SetInput(mSquares->GetOutput());
- mSquaresMapper->ScalarVisibilityOff();
- mSquaresActor->SetMapper(mSquaresMapper);
- mSquaresActor->GetProperty()->SetColor(1.0,0,0);
- mSquaresActor->SetPickable(0);
- mSquaresActor->VisibilityOff();
- mSlicer->GetRenderer()->AddActor(mSquaresActor);
-
+ CreateNewActor(&mSquaresActor, &mSquares, &mClipper, numImage);
mSquaresActorList.push_back(mSquaresActor);
mSquaresList.push_back(mSquares);
mClipperList.push_back(mClipper);
}
- //mSquares->Update();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvImageContour::removeActors() {
- // DD("removeActors");
+void vvImageContour::SetImage(vvImage::Pointer image) {
+ for (unsigned int numImage = 0; numImage < image->GetVTKImages().size(); numImage++) {
+ mClipperList[numImage]->SetInput(image->GetVTKImages()[numImage]);
+ }
+ mHiddenImageIsUsed = true;
+ mHiddenImage = image;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::SetPreserveMemoryModeEnabled(bool b) {
+ // FastCache mode work only if threshold is always the same
+ if (mDisplayModeIsPreserveMemory == b) return;
+ mDisplayModeIsPreserveMemory = b;
+ if (!b) {
+ HideActors();
+ InitializeCacheMode();
+ }
+ else {
+ for(unsigned int d=0; dGetProperty()->SetColor(r,g,b);
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::SetLineWidth(double w)
+{
+ for(unsigned int i=0; iGetProperty()->SetLineWidth(w);
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::HideActors() {
if (!mSlicer) return;
mSlice = mSlicer->GetSlice();
- // DD(mSlice);
for(unsigned int i=0; iVisibilityOff();
- //mSquaresActorList[i]->Update();
}
}
//------------------------------------------------------------------------------
-
+
+//------------------------------------------------------------------------------
+void vvImageContour::ShowActors() {
+ if (!mSlicer) return;
+ mSlice = mSlicer->GetSlice();
+ mTSlice = mSlicer->GetTSlice();
+ // for(unsigned int i=0; iVisibilityOn();
+ Update(mValue);
+ //}
+}
+//------------------------------------------------------------------------------
+
+
//------------------------------------------------------------------------------
-void vvImageContour::update(int value) {
+void vvImageContour::Update(double value) {
// DD(value);
if (!mSlicer) return;
+ if (mPreviousValue == value) {
+ if (mPreviousSlice == mSlicer->GetSlice()) {
+ if (mPreviousTSlice == mSlicer->GetTSlice()) {
+ // DD("vvImageContour::update nothing");
+ return; // Nothing to do
+ }
+ }
+ }
+
+ // Get current threshold value
+ mValue = value;
+
+ // Get current slice
mSlice = mSlicer->GetSlice();
+ // DD(mDisplayModeIsPreserveMemory);
+ if (mDisplayModeIsPreserveMemory) {
+ UpdateWithPreserveMemoryMode();
+ }
+ else {
+ UpdateWithFastCacheMode();
+ }
+
+ // mSlicer->Render(); //DS ---> REMOVE ??
+ mPreviousTSlice = mSlicer->GetTSlice();
+ mPreviousSlice = mSlicer->GetSlice();
+ mPreviousValue = value;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::UpdateWithPreserveMemoryMode() {
// Only change actor visibility if tslice change
- if (mTSlice != mSlicer->GetTSlice()) {
- if (mTSlice != -1)
- mSquaresActorList[mTSlice]->VisibilityOff();
- mTSlice = mSlicer->GetTSlice();
- mSquaresActorList[mTSlice]->VisibilityOn();
- }
-
+ //DD(mTSlice);
+ //DD(mSlice);
+ int mPreviousTslice = mTSlice;
+ // ;
+ // if (mTSlice != mSlicer->GetTSlice()) {
+ // if (mTSlice != -1) mTsliceToSetOff = mTSlice;
+ // mSquaresActorList[mTSlice]->VisibilityOff();
+ mTSlice = mSlicer->GetTSlice();
+ // }
+ // else return;
+ // DD(mTSlice);
vtkMarchingSquares * mSquares = mSquaresList[mTSlice];
vtkImageClip * mClipper = mClipperList[mTSlice];
vtkActor * mSquaresActor = mSquaresActorList[mTSlice];
+ int orientation = ComputeCurrentOrientation();
+ // DD(orientation);
+ //DD(mValue);
+ //DD(mSlice);
+ //DD(mPreviousTslice);
+ UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+ mSquaresActorList[mTSlice]->VisibilityOn();
+ if (mPreviousTslice != mTSlice) {
+ if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::InitializeCacheMode() {
+ mPreviousSlice = mPreviousOrientation = 0;
+ int dim = mSlicer->GetImage()->GetNumberOfDimensions();
+
+ mListOfCachedContourActors.resize(dim);
+ for(int d=0; dGetImage()->GetSize()[d];
+ //DD(size);
+ mListOfCachedContourActors[d].resize(size);
+ for(int j=0; jSetValue(0,value);
+//------------------------------------------------------------------------------
+int vvImageContour::ComputeCurrentOrientation() {
+ // Get extent of image in the slicer
int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
- mClipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
- extent[3],extent[4],extent[5]);
- int i;
- for (i = 0; i < 6;i = i+2) {
- if (extent[i] == extent[i+1]) {
+
+ // Compute orientation
+ int orientation;
+ for (orientation = 0; orientation < 6; orientation = orientation+2) {
+ if (extent[orientation] == extent[orientation+1]) {
break;
}
}
-
- switch (i)
- {
- case 0:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
- {
- mSquaresActor->SetPosition(1,0,0);
- // mSquaresActor2->SetPosition(1,0,0);
- }
- else
- {
- mSquaresActor->SetPosition(-1,0,0);
- // mSquaresActor2->SetPosition(-1,0,0);
- }
- break;
- case 2:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
- {
- mSquaresActor->SetPosition(0,1,0);
- // mSquaresActor2->SetPosition(0,1,0);
- }
- else
- {
- mSquaresActor->SetPosition(0,-1,0);
- // mSquaresActor2->SetPosition(0,-1,0);
- }
- break;
- case 4:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
- {
- mSquaresActor->SetPosition(0,0,1);
- // mSquaresActor2->SetPosition(0,0,1);
- }
- else
- {
- mSquaresActor->SetPosition(0,0,-1);
- // mSquaresActor2->SetPosition(0,0,-1);
- }
- break;
+ orientation = orientation/2;
+ return orientation;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::UpdateWithFastCacheMode() {
+ // Compute orientation
+ int orientation = ComputeCurrentOrientation();
+
+ if ((mPreviousSlice == mSlice) && (mPreviousOrientation == orientation)) return;
+
+ vtkActor * actor = mListOfCachedContourActors[orientation][mSlice];
+ if (actor != NULL) {
+ mListOfCachedContourActors[orientation][mSlice]->VisibilityOn();
+ } else {
+ vtkImageClip * mClipper;
+ vtkMarchingSquares * mSquares;
+ vtkActor * mSquaresActor;
+ CreateNewActor(&mSquaresActor, &mSquares, &mClipper, 0);
+ UpdateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+ mListOfCachedContourActors[orientation][mSlice] = mSquaresActor;
+ mSquaresActor->VisibilityOn();
+ }
+
+ if (mListOfCachedContourActors[mPreviousOrientation][mPreviousSlice] != NULL)
+ mListOfCachedContourActors[mPreviousOrientation][mPreviousSlice]->VisibilityOff();
+ mPreviousSlice = mSlice;
+ mPreviousOrientation = orientation;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::CreateNewActor(vtkActor ** actor,
+ vtkMarchingSquares ** squares,
+ vtkImageClip ** clipper,
+ int numImage) {
+ vtkActor * mSquaresActor = (*actor = vtkActor::New());
+ vtkImageClip * mClipper = (*clipper = vtkImageClip::New());
+ vtkMarchingSquares * mSquares = (*squares = vtkMarchingSquares::New());
+ vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
+
+ if (mHiddenImageIsUsed)
+ mClipper->SetInput(mHiddenImage->GetVTKImages()[0]);
+ else
+ mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
+ mSquares->SetInput(mClipper->GetOutput());
+ mSquaresMapper->SetInput(mSquares->GetOutput());
+ mSquaresMapper->ScalarVisibilityOff();
+ mSquaresActor->SetMapper(mSquaresMapper);
+ mSquaresActor->GetProperty()->SetColor(1.0,0,0);
+ mSquaresActor->SetPickable(0);
+ mSquaresActor->VisibilityOff();
+ mSlicer->GetRenderer()->AddActor(mSquaresActor);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::UpdateActor(vtkActor * actor,
+ vtkMarchingSquares * squares,
+ vtkImageClip * clipper,
+ double threshold, int orientation, int slice) {
+ // Set parameter for the MarchigSquare
+ squares->SetValue(0, threshold);
+
+ // Get image extent
+ int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
+
+ // Change extent if needed
+ int* extent2;
+ if (mHiddenImageIsUsed) {
+ extent2 = new int[6];
+ int * extent3;
+ extent3 = mHiddenImage->GetFirstVTKImageData()->GetExtent();
+ for(int i=0; i<6; i++) extent2[i] = extent3[i];
+
+ double s = (double)extent[orientation*2]*(double)mSlicer->GetImage()->GetSpacing()[orientation]; // in mm
+ s = s+mSlicer->GetImage()->GetOrigin()[orientation]; // from origin
+ s = s-mHiddenImage->GetFirstVTKImageData()->GetOrigin()[orientation]; // from corner second image
+ s = s/mHiddenImage->GetFirstVTKImageData()->GetSpacing()[orientation]; // in voxel
+
+ if (s == floor(s)) {
+ extent2[orientation*2] = extent2[orientation*2+1] = (int)floor(s);
+ } else {
+ extent2[orientation*2] = (int)floor(s);
+ extent2[orientation*2+1] = extent2[orientation*2];
}
- mSquares->Update();
+ } else {
+ extent2 = extent;
+ }
+ clipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
+ extent2[3],extent2[4],extent2[5]);
+
+ if (mHiddenImage) delete extent2;
+
+ // Move the actor to be visible
+ // DD(orientation);
+ // DD(slice);
+
+ //TO SIMPLiFY :!!!!!!!!! == ???????
+ // actor->SetPosition(-1,-1,-1);
+
+ switch (orientation) {
+ case 0:
+ // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0]);
+ if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
+ actor->SetPosition(1,0,0);
+ } else {
+ actor->SetPosition(-1,0,0);
+ }
+ break;
+ case 1:
+ // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1]);
+ if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
+ actor->SetPosition(0,1,0);
+ } else {
+ actor->SetPosition(0,-1,0);
+ }
+ break;
+ case 2:
+ // DD(mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2]);
+ if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
+ // DD("1");
+ actor->SetPosition(0,0,1);
+ } else {
+ // DD("-1");
+ actor->SetPosition(0,0,-1);
+ }
+ break;
+ }
+
+ squares->Update();
}
//------------------------------------------------------------------------------
+