-
- switch (i)
- {
- case 0:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > mSlice)
- {
- mSquaresActor->SetPosition(1,0,0);
- }
- else
- {
- mSquaresActor->SetPosition(-1,0,0);
- }
- break;
- case 2:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > mSlice)
- {
- mSquaresActor->SetPosition(0,1,0);
- }
- else
- {
- mSquaresActor->SetPosition(0,-1,0);
- }
- break;
- case 4:
- if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > mSlice)
- {
- mSquaresActor->SetPosition(0,0,1);
- }
- else
- {
- mSquaresActor->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];