+vvImageContour::~vvImageContour()
+{
+ for (unsigned int i = 0; i < mSlicer->GetImage()->GetVTKImages().size(); i++) {
+ mSlicer->GetRenderer()->RemoveActor(mSquaresActorList[i]);
+ }
+ mSquaresActorList.clear();
+ mSquaresList.clear();
+ mClipperList.clear();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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++) {
+ vtkImageClip * mClipper = vtkImageClip::New();
+ vtkMarchingSquares * mSquares = vtkMarchingSquares::New();
+ vtkActor * mSquaresActor = vtkActor::New();
+ CreateNewActor(&mSquaresActor, &mSquares, &mClipper, numImage);
+ mSquaresActorList.push_back(mSquaresActor);
+ mSquaresList.push_back(mSquares);
+ mClipperList.push_back(mClipper);
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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; d<mListOfCachedContourActors.size(); d++)
+ mListOfCachedContourActors[d].clear();
+ mListOfCachedContourActors.clear();
+ ShowActors();
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::SetColor(double r, double g, double b) {
+ for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
+ mSquaresActorList[i]->GetProperty()->SetColor(r,g,b);
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::SetLineWidth(double w)
+{
+ for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
+ mSquaresActorList[i]->GetProperty()->SetLineWidth(w);
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::HideActors() {
+ if (!mSlicer) return;
+ mSlice = mSlicer->GetSlice();
+ for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
+ mSquaresActorList[i]->VisibilityOff();
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::ShowActors() {
+ if (!mSlicer) return;
+ mSlice = mSlicer->GetSlice();
+ mTSlice = mSlicer->GetTSlice();
+ // for(unsigned int i=0; i<mSquaresActorList.size(); i++) {
+ mSquaresActorList[mTSlice]->VisibilityOn();
+ Update(mValue);
+ //}
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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
+ //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; d<dim; d++) {
+ int size = mSlicer->GetImage()->GetSize()[d];
+ //DD(size);
+ mListOfCachedContourActors[d].resize(size);
+ for(int j=0; j<size; j++) {
+ mListOfCachedContourActors[d][j] = NULL;
+ }
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+int vvImageContour::ComputeCurrentOrientation() {
+ // Get extent of image in the slicer
+ int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
+
+ // Compute orientation
+ int orientation;
+ for (orientation = 0; orientation < 6; orientation = orientation+2) {
+ if (extent[orientation] == extent[orientation+1]) {
+ break;
+ }
+ }
+ orientation = orientation/2;
+ return orientation;