[vtkusers] Picking Points from a image-based Volume doesn't work

Timo Frenzel rohlof at gmx.de
Tue Sep 28 11:40:04 EDT 2004


Hi,

I want to create a MFC Application, which is visualizing an image-based
Volume and is able to give me information about the position and orientation
of some picked points.
So i used PointPicker...
But I cannot get any Information about picked points, perhaps somebody could
help me with this code:

Thx, Timo.

header-file:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkContourFilter.h"
#include "vtkInteractorStyleTrackballCamera.h"

#include "vtkPointPicker.h"
#include "vtkCellPicker.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataWriter.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkHedgeHog.h"
#include "vtkLookupTable.h"
#include "vtkDataSetToPolyDataFilter.h"
#include "vtkPolyData.h"

class VTK3DView  
{
public:
	VTK3DView();
	virtual ~VTK3DView();

	void Initialize();
	void ShowScene();
	void SetFileData(char* pathname, char *filename);

public:
	vtkRenderWindow				*m_renWin;
	vtkInteractorStyleTrackballCamera	*m_style;
	vtkVolume16Reader		        *m_v16;
	vtkRenderer				*m_ren;
	vtkRenderWindowInteractor		*m_iren;

	vtkContourFilter			*m_skinExtractor;
	vtkPolyDataNormals			*m_skinNormals;
	vtkPolyDataMapper			*m_skinMapper;
	vtkActor				*m_skin;

	vtkContourFilter			*m_boneExtractor;
	vtkPolyDataNormals			*m_boneNormals;
	vtkPolyDataMapper			*m_boneMapper;
	vtkActor				*m_bone;

	vtkPointPicker				*m_ppicker;
	vtkPolyDataMapper			*m_ppickerMapper;

	vtkOutlineFilter			*m_outlineData;
	vtkPolyDataMapper			*m_mapOutline;
	vtkActor				*m_outline;
	vtkCamera				*m_aCamera;
        vtkHedgeHog				*m_hhog;
	vtkLookupTable				*m_lut;
	vtkPolyDataMapper			*m_hhogMapper;
	vtkActor				*m_hhogActor;

	int					m_count;

private:
	char					m_fileprefix[400];
	float					m_ct_spacing[3];
	float					*m_selPt;
	float					*m_pickpos;
};


cpp-file:
VTK3DView::VTK3DView()
{

}

VTK3DView::~VTK3DView()
{

}

void VTK3DView::Initialize()
{
	m_renWin	= vtkRenderWindow::New();
	m_ren		= vtkRenderer::New();
        m_iren		= vtkRenderWindowInteractor::New();
	m_style		= vtkInteractorStyleTrackballCamera::New();
	m_v16		= vtkVolume16Reader::New();
	
	m_skinExtractor = vtkContourFilter::New();
	m_skinNormals	= vtkPolyDataNormals::New();
	m_skinMapper	= vtkPolyDataMapper::New();
	m_skin		= vtkActor::New();

	m_boneExtractor = vtkContourFilter::New();
	m_boneNormals	= vtkPolyDataNormals::New();
	m_boneMapper	= vtkPolyDataMapper::New();
	m_bone		= vtkActor::New();
	
	m_outlineData	= vtkOutlineFilter::New();
	m_mapOutline	= vtkPolyDataMapper::New();
	m_outline	= vtkActor::New();
	m_aCamera	= vtkCamera::New();

	m_ppicker	= vtkPointPicker::New();
	m_ppickerMapper	= vtkPolyDataMapper::New();
	m_hhog		= vtkHedgeHog::New();
	m_lut		= vtkLookupTable::New();
	m_hhogMapper	= vtkPolyDataMapper::New();
	m_hhogActor	= vtkActor::New();

}

void VTK3DView::ShowScene()
{
	//Konfiguration
	//Window
	m_renWin	-> AddRenderer(m_ren);
	m_renWin	-> SetSize(320, 240);
	m_iren		-> SetRenderWindow(m_renWin);
	m_iren		-> SetInteractorStyle(m_style);
	
	//Data
	m_v16	-> SetDataDimensions (64,64);
        m_v16	-> SetImageRange (1, m_count);
        m_v16	-> SetDataByteOrderToLittleEndian();
        m_v16	-> SetFilePrefix(m_fileprefix);
        m_v16	-> SetDataSpacing (m_ct_spacing[0], m_ct_spacing[1],
m_ct_spacing[2]);
	m_v16		-> Update();

	// An isosurface, or contour value of 500 is known to correspond to the
	// skin of the patient. Once generated, a vtkPolyDataNormals filter is
	// is used to create normals for smooth surface shading during rendering.
	m_skinExtractor	->	SetInput((vtkDataSet *) m_v16->GetOutput());
	m_skinExtractor	->	SetValue(0, 500);

	m_skinNormals	->	SetInput(m_skinExtractor->GetOutput());
	m_skinNormals	->	SetFeatureAngle(60.0);
	m_skinNormals	->	FlipNormalsOff();

	m_skinMapper	->	SetInput(m_skinNormals->GetOutput());
	m_skinMapper	->	ScalarVisibilityOff();

	m_skin			->	SetMapper(m_skinMapper);
	m_skin			->	GetProperty()->SetDiffuseColor(1, .49, .25);
        m_skin			->	GetProperty()->SetSpecular(.3);
        m_skin			->	GetProperty()->SetSpecularPower(20);

	
	m_boneExtractor	->	SetInput((vtkDataSet *) m_v16->GetOutput());
	m_boneExtractor	->	SetValue(0, 1150);

	m_boneNormals	->	SetInput(m_boneExtractor->GetOutput());
	m_boneNormals	->	SetFeatureAngle(60.0);
	m_boneNormals	->	FlipNormalsOff();

	m_boneMapper	->	SetInput(m_boneNormals->GetOutput());
	m_boneMapper	->	ScalarVisibilityOff();

	m_bone		->	SetMapper(m_boneMapper);
	m_bone		->	GetProperty()->SetDiffuseColor(1, 1, .9412);

	// An outline provides context around the data.
	//
	m_outlineData	->	SetInput((vtkDataSet *) m_v16->GetOutput());
	m_mapOutline	->	SetInput(m_outlineData->GetOutput());
	m_outline	->	SetMapper(m_mapOutline);
	m_outline	->	GetProperty()->SetColor(0,0,0);

	// It is convenient to create an initial view of the data. The FocalPoint
	// and Position form a vector direction. Later on (ResetCamera() method)
	// this vector is used to position the camera to look at the data in
	// this direction.
	m_aCamera		->	SetViewUp (0, 0, -1);
	m_aCamera		->	SetPosition (0, 1, 0);
	m_aCamera		->	SetFocalPoint (0, 0, 0);
	m_aCamera		->	ComputeViewPlaneNormal();

	// Actors are added to the renderer. An initial camera view is created.
	// The Dolly() method moves the camera towards the FocalPoint,
	// thereby enlarging the image.
	m_ren		->	AddActor(m_outline);
	m_ren		->	AddActor(m_skin);
	m_ren		->	AddActor(m_bone);
	m_ren		->	SetActiveCamera(m_aCamera);
	m_ren		->	ResetCamera ();
	m_aCamera	->	Dolly(1.5);

	// Set a background color for the renderer and set the size of the
	// render window (expressed in pixels).
	m_ren	->	SetBackground(1,1,1);
	m_renWin->	SetSize(640, 480);

	// Note that when camera movement occurs (as it does in the Dolly()
	// method), the clipping planes often need adjusting. Clipping planes
	// consist of two planes: near and far along the view direction. The 
	// near plane clips out objects in front of the plane; the far plane
	// clips out objects behind the plane. This way only what is drawn
	// between the planes is actually rendered.
	m_ren	->	ResetCameraClippingRange ();

	//Picking Points
	m_ppicker	->	SetTolerance(0.001);
	m_ppicker	->	GetPointId();
	m_iren		->	SetPicker(m_ppicker);
//	int p = m_ppicker -> GetPointId();

	//Function Hedgehog to visualize Normals
	m_hhog		->	SetInput((vtkDataSet *) m_boneNormals -> GetOutput());
    m_hhog		->	SetScaleFactor(10.3);
	m_hhog		->	SetVectorModeToUseNormal();

	//LookupTable
	m_lut		->	Build();

	m_hhogMapper	->	SetInput(m_hhog->GetOutput());
    m_hhogMapper	->	SetScalarRange(50, 550);
    m_hhogMapper	->	SetLookupTable(m_lut);
    m_hhogMapper	->	ImmediateModeRenderingOn();

	m_hhogActor	->	SetMapper(m_hhogMapper);
	m_ren		->	AddActor(m_hhogActor);

	
	//Show the picked Points in Scene-Window

	

	//Starte Fenster
	m_iren		-> Initialize();
	m_renWin	-> SetWindowName("View Image");
	m_iren		-> Start();


	//Ende
	m_ren		-> Delete();
	m_renWin	-> Delete();
	m_iren		-> Delete();
	m_style		-> Delete();
	m_v16		-> Delete();
}

-- 
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++




More information about the vtkusers mailing list