[vtkusers] How to find the vtkSphereSource object

madz madaramh at gmail.com
Fri Nov 22 03:11:18 EST 2013


Here's a complete program.

#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h> 
#include <vtkObjectFactory.h>
#include <vtkProperty.h>

vtkSmartPointer<vtkRenderer> renderer;
vtkSmartPointer<vtkSphereSource> sphereSource;

vtkSmartPointer<vtkPolyDataMapper> mapper ;

vtkSmartPointer<vtkActor> actor;
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor ;
bool isDeleted;
class MouseInteractorStyle4 : public vtkInteractorStyleTrackballCamera
{
public:
	static MouseInteractorStyle4* New();
	vtkTypeMacro(MouseInteractorStyle4, vtkInteractorStyleTrackballCamera);

	virtual void OnLeftButtonDown() 
	{

		// Forward events
		vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
	}

	virtual void OnMiddleButtonDown() 
	{

		vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
	}

	virtual void OnRightButtonDown() 
	{
		renderer->RemoveActor(actor);

		if(!isDeleted)
		{
			isDeleted = true;
			sphereSource->Delete();
			mapper->Delete();
			actor->Delete();
		}

		renderWindowInteractor->GetRenderWindow()->Render();
	}
};

vtkStandardNewMacro(MouseInteractorStyle4);


int main(int, char *[])
{

	sphereSource =  vtkSmartPointer<vtkSphereSource>::New();
	sphereSource->SetCenter(0.0, 0.0, 0.0);
	sphereSource->SetRadius(5.0);

	mapper = 
		vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(sphereSource->GetOutputPort());

	actor = 
		vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);

	renderer = 
		vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renderWindow = 
		vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer);


	renderWindowInteractor = 
		vtkSmartPointer<vtkRenderWindowInteractor>::New();

	vtkSmartPointer<MouseInteractorStyle4> style =
vtkSmartPointer<MouseInteractorStyle4>::New();

	renderWindowInteractor->SetInteractorStyle(style);
	renderWindowInteractor->SetRenderWindow(renderWindow);

	renderer->AddActor(actor);
	renderer->SetBackground(.3, .6, .3); // Background color green

	renderWindow->Render();
	renderWindowInteractor->Start();


	return EXIT_SUCCESS;
}







--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-find-the-vtkSphereSource-object-tp5724567p5724570.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list