+
+//------------------------------------------------------------------------------
+void vvImageContour::initializeCacheMode() {
+ DD("vvImageContour::initializeCacheMode");
+
+ mPreviousSlice = mPreviousOrientation = 0;
+ int dim;
+ if (mHiddenImageIsUsed) dim = mHiddenImage->GetNumberOfDimensions();
+ else dim = mSlicer->GetImage()->GetNumberOfDimensions();
+ DD(dim);
+
+ mListOfCachedContourActors.resize(dim);
+ for(int d=0; d<dim; d++) {
+ DD(d);
+ int size;
+ if (mHiddenImageIsUsed) size = mHiddenImage->GetSize()[d];
+ else size = mSlicer->GetImage()->GetSize()[d];
+ DD(size);
+ mListOfCachedContourActors[d].resize(size);
+ for(int j=0; j<size; j++) {
+ mListOfCachedContourActors[d][j] = NULL;
+ DD(mListOfCachedContourActors.size());
+ DD(mListOfCachedContourActors[d].size());
+ }
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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;
+ // DD(orientation);
+ return orientation;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::updateWithFastCacheMode() {
+ DD("vvImageContour::updateWithFastCacheMode");
+
+ // Compute orientation
+ int orientation = computeCurrentOrientation();
+
+ // Turn off previous actor
+ DD(mPreviousOrientation);
+ DD(mPreviousSlice);
+ if (mListOfCachedContourActors[mPreviousOrientation][mPreviousSlice] != NULL)
+ mListOfCachedContourActors[mPreviousOrientation][mPreviousSlice]->VisibilityOff();
+ mPreviousSlice = mSlice;
+ mPreviousOrientation = orientation;
+
+ // Display actor if it exist
+ vtkActor * actor = mListOfCachedContourActors[orientation][mSlice];
+ if (actor != NULL) {
+ DD("Actor exist");
+ mListOfCachedContourActors[orientation][mSlice]->VisibilityOn();
+ }
+ else {
+ vtkImageClip * mClipper;
+ vtkMarchingSquares * mSquares;
+ vtkActor * mSquaresActor;
+ createNewActor(&mSquaresActor, &mSquares, &mClipper);
+ updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
+ mListOfCachedContourActors[orientation][mSlice] = mSquaresActor;
+ mSquaresActor->VisibilityOn();
+ }
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvImageContour::createNewActor(vtkActor ** actor,
+ vtkMarchingSquares ** squares,
+ vtkImageClip ** clipper) {
+ // DD("vvImageContour::CreateNewActor");
+ 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()[0]);
+ 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,
+ int threshold, int orientation, int slice) {
+ // DD("Update Actor according to extend/threshold");
+
+ int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
+ clipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
+ extent[3],extent[4],extent[5]);
+ squares->SetValue(0, threshold);
+
+ switch (orientation) {
+ case 0: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
+ actor->SetPosition(1,0,0);
+ }
+ else {
+ actor->SetPosition(-1,0,0);
+ }
+ break;
+ case 1: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
+ actor->SetPosition(0,1,0);
+ }
+ else {
+ actor->SetPosition(0,-1,0);
+ }
+ break;
+ case 2: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
+ actor->SetPosition(0,0,1);
+ }
+ else {
+ actor->SetPosition(0,0,-1);
+ }
+ break;
+ }
+ squares->Update();
+}
+//------------------------------------------------------------------------------
+
+