[vtkusers] Unable to apply transforms to PolyData

Lonni Besançon lonni.besancon at gmail.com
Thu Jun 25 08:18:50 EDT 2015


Hello everyone, 

I had a previous post on that topic that I was not able to solve since then.

I want to be able to apply tranformations to Polydata but no matter how I
try to do it, it just doesn't work.

Here is what I have for "drawing" my polydata in a class call Drawing.cpp:

/vtkSmartPointer<vtkPlane> clipPlane;
vtkSmartPointer<vtkImplicitPlaneRepresentation> planeRep;
vtkSmartPointer<vtkActor> actorPlaneSource;
vtkSmartPointer<vtkActor> mainActor;

vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter;
vtkSmartPointer<vtkTransform> translation ;
vtkContextView* ctxView ;
vtkRenderWindow* win ;
vtkRenderer* ren ;
vtkCamera* cam ;
vtkSmartPointer<vtkPolyData> inputPolyData;/

Then the read function is called and starts the rendering, here is the
function:

/void Drawing::read(){

	std::string filename = BUNNY;
	// Read all the data from the file
	vtkSmartPointer<vtkXMLPolyDataReader> reader
=vtkSmartPointer<vtkXMLPolyDataReader>::New();
	reader->SetFileName(filename.c_str());
	reader->Update();
	inputPolyData = reader->GetOutput();

	cout << "File Found and Loaded : " << filename << endl ;

	vtkSmartPointer<vtkTransform> translation =
vtkSmartPointer<vtkTransform>::New();
	translation->Translate(0.3, -0.05, 0);
	transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
	//transformFilter->SetInputConnection(reader->GetOutputPort());
	transformFilter->SetInputData(inputPolyData);
	transformFilter->SetTransform(translation);
	//transformFilter->Update();

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

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

	ren->AddActor(mainActor);

	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(win);
	vtkInteractorStyleMultiTouchCamera *style =
	vtkInteractorStyleMultiTouchCamera::New();
	iren->SetInteractorStyle(style);
	
	//Start the event loop
	iren->Initialize();
	iren->Start();

	defineClipping();
	win->PolygonSmoothingOn();
	win->Render();
	win->Start();
}
/

>From this, I have an other thread running a server that gets messages and
has a pointer to my drawing object and is supposed to call one of these
three functions depending on the message it gets from its clients:

/void Drawing::scale(float k){
	vtkSmartPointer<vtkTransform> transform
=vtkSmartPointer<vtkTransform>::New();
	transform->Scale(5,1,1);
	vtkSmartPointer<vtkTransformFilter> transformFilter =
vtkSmartPointer<vtkTransformFilter>::New();
	transformFilter->SetInputConnection(cone->GetOutputPort());
	transformFilter->SetTransform(transform);
	mapper->SetInputConnection(transformFilter->GetOutputPort());
	ren->GetActiveCamera();
}

void Drawing::translate(float x, float y, float z){
	cout << "Translate: " << x << " - " << " - " << y << " - " << z << endl ;
	vtkSmartPointer<vtkTransform> transform1a =
vtkSmartPointer<vtkTransform>::New();
	//transform1a->Translate(x,y,z);
	//transformFilter->SetTransform(transform1a);
	//transformFilter->Update();
	double* position = mainActor->GetPosition();
	mainActor->SetPosition(position[0]+x,position[1]+y,position[2]+z);
}

void Drawing::rotate(float x, float y, float z){
	cout << "Rotate: " << x << " - " << " - " << y << " - " << z << endl ;
	vtkSmartPointer<vtkTransform> transform1a =
vtkSmartPointer<vtkTransform>::New();
	//transform1a->PostMultiply();
	//transform1a->RotateX(x);
	//transform1a->RotateY(y);
	//transform1a->RotateZ(z);
	//mainActor->SetUserTransform(transform1a);
	mainActor->RotateWXYZ(20,1,0,0);
	
}/

None of these functions work because nothing is changing in the rendering
windows *unless I click in the rendering window itself.*
So I thought maybe I should try and add to every transformation functions:
/ctxView->Render();/
But when I do I get: Error the ressource is already busy. 

I'm a newbie in VTK but I really don't find the answer to my questions
anywhere else and I'm quite puzzled not to be able to at least use some
simple transformations.

Any help will be greatly appreciated.

Thanks in advance



--
View this message in context: http://vtk.1045678.n5.nabble.com/Unable-to-apply-transforms-to-PolyData-tp5732537.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list