[vtkusers] vtkContourWidget with vtkImageViewer2
Lars Friedrich Lars
lars-friedrich at gmx.net
Wed Jul 16 07:41:09 EDT 2008
hi,
as I wrote yesterday (posting: 'vtkContourWidget on 3D-images') I face some problems with vtkContourWidget and vtkImageViewer2. I thought that this is eventually due to the 'overhead' of my implementation with KWWidgets and so on.
So I decided to write an as-short-as-possible VTK-based application with the critical features to try it this way (see attached code). But here I have the same problem: when I visualize slice 46 of the VTKData-headsq, and then draw contours using the widget I do not see the contour. When I finish the contouring using the right mouse button and then use the slider to navigate to slice 0 I see the contour I've blindly drawn.
How can I configure the vtkContourWidget (or its representation) to draw on the actual displayed slice?
I inspected the world coordinates of the drawn contour and found out that the z-coordinates of all points are always set to zero.
Has someone an idea what the problem is?
best regards,
lars
////////////////////////////////////////////
// TestContours.cxx
// lars
////////////////////////////////////////////
#include "vtkImageData.h"
#include "vtkVolume16Reader.h"
#include "vtkImageShiftScale.h"
#include "vtkImageViewer2.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSliderRepresentation.h"
#include "vtkSliderRepresentation2D.h"
#include "vtkSliderWidget.h"
#include "vtkCommand.h"
#include "vtkContourWidget.h"
class vtkSliderCallback : public vtkCommand
{
public:
static vtkSliderCallback *New()
{ return new vtkSliderCallback; }
void Delete()
{ delete this; }
void SetImageViewer(vtkImageViewer2 *viewer)
{ m_Viewer = viewer; }
virtual void Execute(vtkObject *caller, unsigned long ul, void* vd)
{
vtkSliderWidget *slider = (vtkSliderWidget *)caller;
vtkSliderRepresentation *sliderRepres = (vtkSliderRepresentation *)slider->GetRepresentation();
int pos = (int)sliderRepres->GetValue();
m_Viewer->SetSlice(pos);
}
protected:
vtkImageViewer2 *m_Viewer;
};
int main(int argc, char *argv[])
{
//char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter");
char* fname = "/home/philipp/libs/vtk/VTKData/Data/headsq/quarter";
vtkVolume16Reader* v16 = vtkVolume16Reader::New();
v16->SetDataDimensions(64, 64);
v16->SetDataByteOrderToLittleEndian();
v16->SetImageRange(1, 93);
v16->SetDataSpacing(3.2, 3.2, 1.5);
v16->SetFilePrefix(fname);
v16->ReleaseDataFlagOn();
v16->SetDataMask(0x7fff);
v16->Update();
//delete[] fname;
double range[2];
v16->GetOutput()->GetScalarRange(range);
vtkImageShiftScale* shifter = vtkImageShiftScale::New();
shifter->SetShift(-1.0*range[0]);
shifter->SetScale(255.0/(range[1]-range[0]));
shifter->SetOutputScalarTypeToUnsignedChar();
shifter->SetInputConnection(v16->GetOutputPort());
shifter->ReleaseDataFlagOff();
shifter->Update();
vtkImageViewer2 *ImageViewer = vtkImageViewer2::New();
ImageViewer->SetInput(shifter->GetOutput());
ImageViewer->SetColorLevel(127);
ImageViewer->SetColorWindow(255);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
ImageViewer->SetupInteractor(iren);
ImageViewer->Render();
ImageViewer->GetRenderer()->ResetCamera();
ImageViewer->Render();
int *dims = v16->GetOutput()->GetDimensions();
std::cout << dims[0] << "," << dims[1] << "," << dims[2] << "\n";
vtkSliderRepresentation2D *SliderRepres = vtkSliderRepresentation2D::New();
int min = ImageViewer->GetSliceMin();
int max = ImageViewer->GetSliceMax();
SliderRepres->SetMinimumValue(min);
SliderRepres->SetMaximumValue(max);
SliderRepres->SetValue((int)((min + max) / 2));
SliderRepres->SetTitleText("Slice");
SliderRepres->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();
SliderRepres->GetPoint1Coordinate()->SetValue(0.3, 0.05);
SliderRepres->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();
SliderRepres->GetPoint2Coordinate()->SetValue(0.7, 0.05);
SliderRepres->SetSliderLength(0.02);
SliderRepres->SetSliderWidth(0.03);
SliderRepres->SetEndCapLength(0.01);
SliderRepres->SetEndCapWidth(0.03);
SliderRepres->SetTubeWidth(0.005);
SliderRepres->SetLabelFormat("%3.0lf");
SliderRepres->SetTitleHeight(0.02);
SliderRepres->SetLabelHeight(0.02);
vtkSliderWidget *SliderWidget = vtkSliderWidget::New();
SliderWidget->SetInteractor(iren);
SliderWidget->SetRepresentation(SliderRepres);
SliderWidget->KeyPressActivationOff();
SliderWidget->SetAnimationModeToAnimate();
SliderWidget->SetEnabled(true);
vtkSliderCallback *SliderCb = vtkSliderCallback::New();
SliderCb->SetImageViewer(ImageViewer);
SliderWidget->AddObserver(vtkCommand::InteractionEvent, SliderCb);
ImageViewer->SetSlice((int)SliderRepres->GetValue());
vtkContourWidget *ContourWidget = vtkContourWidget::New();
ContourWidget->SetInteractor(iren);
ContourWidget->SetEnabled(true);
ContourWidget->ProcessEventsOn();
iren->Start();
return -1;
}
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
More information about the vtkusers
mailing list