[vtkusers] RE: vtkImagePlaneWidget problem

Peter Kok peter.kok at gmail.com
Mon Sep 25 17:03:45 EDT 2006


>Peter, if you can provide a c++ test app using only VTK and data from
>VTKData
>that illustrates the problem, I will be happy to take a look...

I've finally managed to reproduce the problem in a simple program. It is
included below.

The behaviour to look for is when you try to start cursoring. On one plane,
the one that has the focus, the cursoring state is entered, but on the other
two planes, the cursor appears to be "Off image".

The problem seems to occur in the following cases:
-if the checkerboard is changed (SetNumberOfDivisions) after a render. If
the aRenderer->Render() call is removed, the problem disappears.
-if checkers->Update() is not called at all.


-Peter


#include "stdafx.h"
#include "vtkImageCheckerboard.h"
#include "vtkCellPicker.h"
#include "vtkImagePlaneWidget.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkProperty.h"
#include "vtkImageData.h"
#include "vtkImageMapToColors.h"

int _tmain(int argc, const char** argv)
{
	vtkRenderer *aRenderer = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
	renWin->AddRenderer(aRenderer);
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);

	vtkVolume16Reader *v16 = vtkVolume16Reader::New();
	v16->SetDataDimensions(64,64);
	v16->SetDataByteOrderToLittleEndian();
	v16->SetFilePrefix("C:\\vtk\\Data\\Data\\headsq\\quarter");
	v16->SetImageRange(1, 93);
	v16->SetDataSpacing (3.2, 3.2, 1.5);

	vtkImageCheckerboard *checkers = vtkImageCheckerboard::New();
	checkers->SetInput(0, v16->GetOutput());
	checkers->SetInput(1, v16->GetOutput());
	checkers->SetNumberOfDivisions(50, 50, 50);
	checkers->Update(); //First checkers update

	vtkCellPicker *cellPicker = vtkCellPicker::New();
	cellPicker->SetTolerance(0.005);
	//vtkDataSet *data = v16->GetOutput();
	vtkDataSet *data = checkers->GetOutput();

	vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
	planeWidgetX->DisplayTextOn();
	planeWidgetX->SetInput(data);
	planeWidgetX->SetPlaneOrientationToXAxes();
	planeWidgetX->SetSliceIndex(0);
	planeWidgetX->SetPicker(cellPicker);
	planeWidgetX->SetKeyPressActivationValue('x');
	planeWidgetX->GetPlaneProperty()->SetColor(1, 0, 0);
	planeWidgetX->SetWindowLevel(2000, 500);
	planeWidgetX->GetColorMap()->PassAlphaToOutputOff();
	planeWidgetX->SetInteractor(iren);
	planeWidgetX->On();

	vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
	planeWidgetY->DisplayTextOn();
	planeWidgetY->SetInput(data);
	planeWidgetY->SetPlaneOrientationToYAxes();
	planeWidgetY->SetSliceIndex(0);
	planeWidgetY->SetPicker(cellPicker);
	planeWidgetY->SetKeyPressActivationValue('y');
	planeWidgetY->GetPlaneProperty()->SetColor(1, 1, 0);
	planeWidgetY->SetWindowLevel(2000, 500);
	planeWidgetY->GetColorMap()->PassAlphaToOutputOff();
	planeWidgetY->SetInteractor(iren);
	planeWidgetY->On();

	vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
	planeWidgetZ->DisplayTextOn();
	planeWidgetZ->SetInput(data);
	planeWidgetZ->SetPlaneOrientationToZAxes();
	planeWidgetZ->SetSliceIndex(0);
	planeWidgetZ->SetPicker(cellPicker);
	planeWidgetZ->SetKeyPressActivationValue('z');
	planeWidgetZ->GetPlaneProperty()->SetColor(0, 0, 1);
	planeWidgetZ->SetWindowLevel(2000, 500);
	planeWidgetZ->GetColorMap()->PassAlphaToOutputOff();
	planeWidgetZ->SetInteractor(iren);
	planeWidgetZ->On();

	aRenderer->Render(); //Render
	checkers->SetNumberOfDivisions(4, 4, 4); //Change checkerboard
	checkers->Update(); //Second checkers update

	iren->Initialize();
	iren->Start(); 

	v16->Delete();
	aRenderer->Delete();
	renWin->Delete();
	iren->Delete();
	cellPicker->Delete();
	planeWidgetX->Delete();
	planeWidgetY->Delete();
	planeWidgetZ->Delete();

	return 0;
}





More information about the vtkusers mailing list