//------------------------------------------------------------------------------
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();
- // vtkPolyDataMapper * mSquaresMapper = vtkPolyDataMapper::New();
vtkActor * mSquaresActor = vtkActor::New();
-
- createNewActor(&mSquaresActor, &mSquares, &mClipper);
- /*
- 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);
//------------------------------------------------------------------------------
void vvImageContour::setImage(vvImage::Pointer image) {
- DD("vvImageContour::setImage");
for (unsigned int numImage = 0; numImage < image->GetVTKImages().size(); numImage++) {
mClipperList[numImage]->SetInput(image->GetVTKImages()[numImage]);
}
//------------------------------------------------------------------------------
-void vvImageContour::setPreserveModeEnabled(bool b) {
- DD("setPreserveModeEnabled");
- DD(b);
- DD(mDisplayModeIsPreserveMemory);
+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::update(double value) {
if (!mSlicer) return;
+ if (mPreviousValue == value) {
+ if (mPreviousSlice == mSlicer->GetSlice()) {
+ if (mPreviousTSlice == mSlicer->GetTSlice()) {
+ return; // Nothing to do
+ }
+ }
+ }
+
// Get current threshold value
- mValue= value;
+ mValue = value;
+
// Get current slice
mSlice = mSlicer->GetSlice();
else {
updateWithFastCacheMode();
}
+ mSlicer->Render();
+ 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);
-
updateActor(mSquaresActor, mSquares, mClipper, mValue, orientation, mSlice);
-
- return;
-
- // Do it
- mSquares->SetValue(0, mValue );
-
- int* extent = mSlicer->GetImageActor()->GetDisplayExtent();
- // DD(extent[0]);
- // DD(extent[1]);
- // DD(extent[2]);
- // DD(extent[3]);
- // DD(extent[4]);
- // DD(extent[5]);
-
- // int* extent2 = mClipper->GetInput()->GetDisplayExtent();
- // DD(extent2[0]);
- // DD(extent2[1]);
- int* extent2 = new int[6];
- if (mHiddenImageIsUsed) {
- int * extent3;
- extent3 = mHiddenImage->GetFirstVTKImageData()->GetExtent();
- for(int i=0; i<6; i++) extent2[i] = extent3[i];
- // DD(extent2[0]);
- // DD(extent2[1]);
- // DD(extent2[2]);
- // DD(extent2[3]);
- // DD(extent2[4]);
- // DD(extent2[5]);
- for(int i=0; i<6; i+=2) {
- if (extent[i] != extent[i+1]) {
- // extent[i] = extent2[i];
- // extent[i+1] = extent2[i+1];
- }
- else {
- // DD(extent[i]);
- // DD(mSlicer->GetImage()->GetSpacing()[i/2]);
- // DD(mHiddenImage->GetFirstVTKImageData()->GetSpacing()[i/2]);
-
- double s = (double)extent[i]*(double)mSlicer->GetImage()->GetSpacing()[i/2]; // in mm
- // DD(s);
- s = s+mSlicer->GetImage()->GetOrigin()[i/2]; // from origin
- // DD(s);
- s = s-mHiddenImage->GetFirstVTKImageData()->GetOrigin()[i/2]; // from corner second image
- s = s/mHiddenImage->GetFirstVTKImageData()->GetSpacing()[i/2]; // in voxel
- // DD(s);
-
- if (s == floor(s)) {
- extent2[i] = extent2[i+1] = (int)floor(s);
- }
- else {
- extent2[i] = (int)floor(s);
- extent2[i+1] = extent2[i];
- }
- // DD(extent2[i]);
- }
- }
- }
- else extent2 = extent;
- // DD(extent2[0]);
- // DD(extent2[1]);
- // DD(extent2[2]);
- // DD(extent2[3]);
- // DD(extent2[4]);
- // DD(extent2[5]);
-
-
- mClipper->SetOutputWholeExtent(extent2[0],extent2[1],extent2[2],
- extent2[3],extent2[4],extent2[5]);
- int i;
- for (i = 0; i < 6;i = i+2) {
- if (extent[i] == extent[i+1]) {
- break;
- }
+ mSquaresActorList[mTSlice]->VisibilityOn();
+ if (mPreviousTslice != mTSlice) {
+ if (mPreviousTslice != -1) mSquaresActorList[mPreviousTslice]->VisibilityOff();
}
-
- 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;
- }
- mSquares->Update();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvImageContour::initializeCacheMode() {
- DD("vvImageContour::initializeCacheMode");
-
mPreviousSlice = mPreviousOrientation = 0;
- int dim;
- if (mHiddenImageIsUsed) dim = mHiddenImage->GetNumberOfDimensions();
- else dim = mSlicer->GetImage()->GetNumberOfDimensions();
- DD(dim);
+ int dim = mSlicer->GetImage()->GetNumberOfDimensions();
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);
+ int 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());
}
}
}
}
}
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;
+ if ((mPreviousSlice == mSlice) && (mPreviousOrientation == orientation)) return;
- // 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);
+ 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) {
- // DD("vvImageContour::CreateNewActor");
+ vtkImageClip ** clipper,
+ int numImage) {
vtkActor * mSquaresActor = (*actor = vtkActor::New());
vtkImageClip * mClipper = (*clipper = vtkImageClip::New());
vtkMarchingSquares * mSquares = (*squares = vtkMarchingSquares::New());
if (mHiddenImageIsUsed)
mClipper->SetInput(mHiddenImage->GetVTKImages()[0]);
else
- mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[0]);
+ mClipper->SetInput(mSlicer->GetImage()->GetVTKImages()[numImage]);
mSquares->SetInput(mClipper->GetOutput());
mSquaresMapper->SetInput(mSquares->GetOutput());
mSquaresMapper->ScalarVisibilityOff();
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]);
+
+ // 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];
+ }
+ }
+ 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: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[0] > slice) {
+ 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: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[1] > slice) {
+ 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: if (mSlicer->GetRenderer()->GetActiveCamera()->GetPosition()[2] > slice) {
+ 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();
}
//------------------------------------------------------------------------------
mLandmarks = NULL;
mLinkedId.resize(0);
- for ( int i = 0; i < numberOfSlicers; i++)
- {
- vvSlicer *slicer = vvSlicer::New();
- mSlicers.push_back(slicer);
- }
+ for ( int i = 0; i < numberOfSlicers; i++) {
+ vvSlicer *slicer = vvSlicer::New();
+ mSlicers.push_back(slicer);
+ }
+ mPreviousSlice.resize(numberOfSlicers);
+ mPreviousTSlice.resize(numberOfSlicers);
}
//----------------------------------------------------------------------------
mFileName.append("_"+clitk::toString(n));
// DD(mFileName);
}
- return true;
+ return true;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool vvSlicerManager::SetVF(vvImage::Pointer vf,std::string filename)
{
- if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions())
- {
- mLastError = " Vector field dimension cannot be greater then reference image!";
+ if (vf->GetNumberOfDimensions() > mImage->GetNumberOfDimensions()) {
+ mLastError = "Sorry, vector field dimension cannot be greater then reference image.";
+ return false;
+ }
+ if (vf->GetNumberOfDimensions() == 4) {
+ // DD(vf->GetSpacing()[3]);
+ // DD(mImage->GetSpacing()[3]);
+ // DD(vf->GetOrigin()[3]);
+ // DD(mImage->GetOrigin()[3]);
+ 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);
- }
+ for ( unsigned int i = 0; i < mSlicers.size(); i++) {
+ mSlicers[i]->SetVF(vf);
+ }
return true;
}
//----------------------------------------------------------------------------
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);
smc->Delete();
}
//----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+void vvSlicerManager::LeftButtonReleaseEvent(int slicer) {
+ emit LeftButtonReleaseSignal(slicer);
+}
+//----------------------------------------------------------------------------
+
+
//----------------------------------------------------------------------------
void vvSlicerManager::SetTSlice(int slice)
{
mLandmarks->SetTime(slice);
for ( unsigned int i = 0; i < mSlicers.size(); i++)
{
- mSlicers[i]->SetTSlice(slice);
- if (mSlicers[i]->GetImageActor()->GetVisibility())
- UpdateTSlice(i);
+ if (slice != mSlicers[i]->GetTSlice()) {
+ mSlicers[i]->SetTSlice(slice);
+ if (mSlicers[i]->GetImageActor()->GetVisibility())
+ UpdateTSlice(i);
+ }
}
}
//----------------------------------------------------------------------------
t++;
if (t > mSlicers[0]->GetTMax())
t = 0;
+ // DD("SetNextTSlice");
+// DD(originating_slicer);
+// DD(t);
emit UpdateTSlice(originating_slicer,t);
}
//----------------------------------------------------------------------------
tslice = mSlicers[slicer]->GetTMax();
if (mLandmarks)
mLandmarks->SetTime(tslice);
+
+ if (mSlicers[slicer]->GetTSlice() == tslice) return;
+
mSlicers[slicer]->SetTSlice(tslice);
if (mSlicers[slicer]->GetImageActor()->GetVisibility())
UpdateTSlice(slicer);
void vvSlicerManager::UpdateSlice(int slicer)
{
// DD("vvSlicerManager::UpdateSlice emit UpdateSlice");
- // DD(slicer);
- // DD(mSlicers[slicer]->GetSlice());
+// DD(slicer);
+// DD(mSlicers[slicer]->GetSlice());
+ if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
+ //DD("============= NOTHING");
+ return;
+ }
emit UpdateSlice(slicer, mSlicers[slicer]->GetSlice());
+ mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void vvSlicerManager::UpdateTSlice(int slicer)
{
- emit UpdateTSlice(slicer,mSlicers[0]->GetTSlice());
+ // DD("vvSlicerManager::UpdateTSlice emit UpdateTSlice");
+// DD(slicer);
+// DD(mSlicers[slicer]->GetTSlice());
+// DD(mSlicers[slicer]->GetSlice());
+ if (mPreviousSlice[slicer] == mSlicers[slicer]->GetSlice()) {
+ if (mPreviousTSlice[slicer] == mSlicers[slicer]->GetTSlice()) {
+ // DD("************** NOTHING ***********");
+ return;
+ }
+ }
+ mPreviousSlice[slicer] = mSlicers[slicer]->GetSlice();
+ mPreviousTSlice[slicer] = mSlicers[slicer]->GetTSlice();
+ emit UpdateTSlice(slicer,mSlicers[slicer]->GetTSlice());
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
+
//----------------------------------------------------------------------------
void vvSlicerManager::NextImage(int slicer)
{
emit ChangeImageWithIndexOffset(this, slicer, 1);
}
//----------------------------------------------------------------------------
+
+
+//----------------------------------------------------------------------------
+void vvSlicerManager::VerticalSliderHasChanged(int slicer, int slice) {
+ emit AVerticalSliderHasChanged(slicer, slice);
+}
+//----------------------------------------------------------------------------