[vtkusers] Need help in using vtkProjectedTexture class. Texture missaligned.

vinmean iamdpak at gmail.com
Sun Nov 18 20:40:23 EST 2018


I want to project an image as a texture to a small region on a large 3D
model. I have the 3D model as an actor. I wrote the below function to test
the projected texture class. I followed the example in the link 
https://lorensen.github.io/VTKExamples/site/Cxx/Texture/ProjectedTexture/
<https://lorensen.github.io/VTKExamples/site/Cxx/Texture/ProjectedTexture/>  

I am able to set the set the desired camera view as a first step. However, I
am then unable to overlay the texture properly. The texture seems to be
stretched and doesn't seem to be centered at the point of focus. I even drew
a frustum to demonstrate the correctness of the camera parameters like
position, focal point and up vector. Please find the screenshot of the
rendered scene attached. Why would this stretching happen? What are the
other parameters that needs to be set? I couldn't find much examples or
documentation on this. 

//viz is my visuzalizer class. It has access to renderwindow, renderer,
interactor
//This function sets the camera pose and then applies projected texture to
the polydata of input actor
void test_projected_texture(vtkSmartPointer<vtkActor> actor, viz* v, pose&
pv_cam)
{
        //I am able to set the camera view using pv_cam variable and the
view looks as I expected
	vtkSmartPointer<vtkCamera> camera =
v->renderWindow->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
	v->setCameraPose(pv_cam.pp);
	v->renderWindow->Render();

       //using actor 
	vtkPolyData*  polyData =
vtkPolyData::SafeDownCast(actor->GetMapper()->GetInput());
	vtkSmartPointer<vtkProjectedTexture>  projectedTexture =
vtkSmartPointer<vtkProjectedTexture>::New();


	double aspect[3];
	aspect[1] = 1;
	aspect[2] = 1;
	aspect[0] = (1.0/
(vtkMath::RadiansFromDegrees(std::tan(camera->GetViewAngle())))) / 2.0;

	projectedTexture->SetAspectRatio(aspect);
	projectedTexture->SetPosition(camera->GetPosition());
	projectedTexture->SetFocalPoint(camera->GetFocalPoint());
	projectedTexture->SetUp(camera->GetViewUp()[0], camera->GetViewUp()[1],
camera->GetViewUp()[2]);

	projectedTexture->SetInputData( polyData); //this can be the same as the
one to project on
	projectedTexture->Update();

	//Map Texture on Surface

polyData->GetPointData()->SetTCoords(projectedTexture->GetOutput()->GetPointData()->GetTCoords());

	// Read texture file
	vtkSmartPointer<vtkImageReader2Factory> readerFactory =
vtkSmartPointer<vtkImageReader2Factory>::New();
	vtkImageReader2 *imageReader =
readerFactory->CreateImageReader2("images/0003.jpg");
	imageReader->SetFileName("images/0003.jpg");
	imageReader->Update();

	vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
	texture->SetInputData(imageReader->GetOutput());
	texture->RepeatOff();
	actor->SetTexture(texture);
}
<http://vtk.1045678.n5.nabble.com/file/t342070/projected_texture2.png> 




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list