#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
-vtkCxxRevisionMacro(wxvtkImageViewer2, "$Revision: 1.3 $");
+vtkCxxRevisionMacro(wxvtkImageViewer2, "$Revision: 1.5 $");
vtkStandardNewMacro(wxvtkImageViewer2);
//----------------------------------------------------------------------------
{
this->Interactor->UnRegister(this);
}
-
+
this->Interactor = arg;
-
+
if (this->Interactor)
{
this->Interactor->Register(this);
{
this->RenderWindow->UnRegister(this);
}
-
+
this->RenderWindow = arg;
-
+
if (this->RenderWindow)
{
this->RenderWindow->Register(this);
{
this->Renderer->UnRegister(this);
}
-
+
this->Renderer = arg;
-
+
if (this->Renderer)
{
this->Renderer->Register(this);
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetSize(int a,int b)
+void wxvtkImageViewer2::SetSize(int a,int b)
{
this->RenderWindow->SetSize(a, b);
}
//----------------------------------------------------------------------------
-int* wxvtkImageViewer2::GetSize()
+int* wxvtkImageViewer2::GetSize()
{
return this->RenderWindow->GetSize();
}
}
//----------------------------------------------------------------------------
-int wxvtkImageViewer2::GetSliceMin()
+int wxvtkImageViewer2::GetSliceMin()
{
int *range = this->GetSliceRange();
if (range)
}
//----------------------------------------------------------------------------
-int wxvtkImageViewer2::GetSliceMax()
+int wxvtkImageViewer2::GetSliceMax()
{
int *range = this->GetSliceRange();
if (range)
vtkErrorMacro("Error - invalid slice orientation " << orientation);
return;
}
-
+
if (this->SliceOrientation == orientation)
{
return;
this->SliceOrientation = orientation;
- // Update the viewer
+ // Update the viewer
int *range = this->GetSliceRange();
if (range)
cam->SetPosition(0,0,1); // -1 if medical ?
cam->SetViewUp(0,1,0);
break;
-
+
case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
cam->SetFocalPoint(0,0,0);
cam->SetPosition(0,-1,0); // 1 if medical ?
cam->SetViewUp(0,0,1);
break;
-
+
case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
cam->SetFocalPoint(0,0,0);
cam->SetPosition(1,0,0); // -1 if medical ?
if (this->Renderer)
{
- if (this->InteractorStyle &&
+ if (this->InteractorStyle &&
this->InteractorStyle->GetAutoAdjustCameraClippingRange())
{
this->Renderer->ResetCameraClippingRange();
double cpos = cam->GetPosition()[this->SliceOrientation];
double range = fabs(spos - cpos);
double *spacing = input->GetSpacing();
- double avg_spacing =
+ double avg_spacing =
//(spacing[0] + spacing[1] + spacing[2]) / 3.0;
spacing[2]; // JPR??
cam->SetClippingRange(
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetPosition(int a,int b)
+void wxvtkImageViewer2::SetPosition(int a,int b)
{
this->RenderWindow->SetPosition(a, b);
}
//----------------------------------------------------------------------------
-int* wxvtkImageViewer2::GetPosition()
+int* wxvtkImageViewer2::GetPosition()
{
return this->RenderWindow->GetPosition();
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetDisplayId(void *a)
+void wxvtkImageViewer2::SetDisplayId(void *a)
{
this->RenderWindow->SetDisplayId(a);
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetWindowId(void *a)
+void wxvtkImageViewer2::SetWindowId(void *a)
{
this->RenderWindow->SetWindowId(a);
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetParentId(void *a)
+void wxvtkImageViewer2::SetParentId(void *a)
{
this->RenderWindow->SetParentId(a);
}
//----------------------------------------------------------------------------
-double wxvtkImageViewer2::GetColorWindow()
+double wxvtkImageViewer2::GetColorWindow()
{
return this->WindowLevel->GetWindow();
}
//----------------------------------------------------------------------------
-double wxvtkImageViewer2::GetColorLevel()
+double wxvtkImageViewer2::GetColorLevel()
{
return this->WindowLevel->GetLevel();
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetColorWindow(double s)
+void wxvtkImageViewer2::SetColorWindow(double s)
{
this->WindowLevel->SetWindow(s);
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetColorLevel(double s)
+void wxvtkImageViewer2::SetColorLevel(double s)
{
this->WindowLevel->SetLevel(s);
}
{
public:
static wxvtkImageViewer2Callback *New() { return new wxvtkImageViewer2Callback; }
-
- void Execute(vtkObject *caller,
- unsigned long event,
+
+ void Execute(vtkObject *caller,
+ unsigned long event,
void *vtkNotUsed(callData))
{
if (this->IV->GetInput() == NULL)
this->InitialLevel = this->IV->GetColorLevel();
return;
}
-
+
// Adjust the window level here
- vtkInteractorStyleImage *isi =
+ vtkInteractorStyleImage *isi =
static_cast<vtkInteractorStyleImage *>(caller);
int *size = this->IV->GetRenderWindow()->GetSize();
double window = this->InitialWindow;
double level = this->InitialLevel;
-
+
// Compute normalized delta
- double dx = 4.0 *
- (isi->GetWindowLevelCurrentPosition()[0] -
+ double dx = 4.0 *
+ (isi->GetWindowLevelCurrentPosition()[0] -
isi->GetWindowLevelStartPosition()[0]) / size[0];
- double dy = 4.0 *
- (isi->GetWindowLevelStartPosition()[1] -
+ double dy = 4.0 *
+ (isi->GetWindowLevelStartPosition()[1] -
isi->GetWindowLevelCurrentPosition()[1]) / size[1];
-
+
// Scale by current values
if (fabs(window) > 0.01)
{
dy = dy * (level < 0 ? -0.01 : 0.01);
}
-
+
// Abs so that direction does not flip
- if (window < 0.0)
+ if (window < 0.0)
{
dx = -1*dx;
}
- if (level < 0.0)
+ if (level < 0.0)
{
dy = -1*dy;
}
-
+
// Compute new window level
double newWindow = dx + window;
double newLevel;
newLevel = level - dy;
-
+
// Stay away from zero and really
if (fabs(newWindow) < 0.01)
{
newLevel = 0.01*(newLevel < 0 ? -1 : 1);
}
-
+
this->IV->SetColorWindow(newWindow);
this->IV->SetColorLevel(newLevel);
this->IV->Render();
}
-
+
wxvtkImageViewer2 *IV;
double InitialWindow;
double InitialLevel;
vtkCommand::ResetWindowLevelEvent, cbk);
cbk->Delete();
}
-
+
this->Interactor->SetInteractorStyle(this->InteractorStyle);
this->Interactor->SetRenderWindow(this->RenderWindow);
}
// Initialize the size if not set yet
vtkImageData *input = this->GetInput();
- if (this->RenderWindow->GetSize()[0] == 0 &&
+ if (this->RenderWindow->GetSize()[0] == 0 &&
input)
{
-
+
input->UpdateInformation();
int *w_ext = input->GetWholeExtent();
int xs = 0, ys = 0;
-
+
// std::cout << "wxvtkImageViewer2::Render ext = "
// <<w_ext[0]<<" - "<<w_ext[1]<<" ; "
// <<w_ext[2]<<" - "<<w_ext[3]<<" ; "
// <<w_ext[4]<<" - "<<w_ext[5]
// <<std::endl;
-
+
switch (this->SliceOrientation)
{
case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
this->Renderer->GetActiveCamera()->SetParallelScale(
xs < 150 ? 75 : (xs - 1 ) / 2.0);
}
- this->FirstRender = 0;
+ this->FirstRender = 0;
}
}
}
//----------------------------------------------------------------------------
-const char* wxvtkImageViewer2::GetWindowName()
+const char* wxvtkImageViewer2::GetWindowName()
{
return this->RenderWindow->GetWindowName();
}
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetInput(vtkImageData *in)
+void wxvtkImageViewer2::SetInput(vtkImageData *in)
{
// std::cout << "### wxvtkImageViewer2::SetInput"<<std::endl;
this->WindowLevel->SetInput(in);
}
//----------------------------------------------------------------------------
vtkImageData* wxvtkImageViewer2::GetInput()
-{
+{
return vtkImageData::SafeDownCast(this->WindowLevel->GetInput());
}
//----------------------------------------------------------------------------
-void wxvtkImageViewer2::SetInputConnection(vtkAlgorithmOutput* input)
+void wxvtkImageViewer2::SetInputConnection(vtkAlgorithmOutput* input)
{
this->WindowLevel->SetInputConnection(input);
this->UpdateDisplayExtent();