Need help in using vtkProjectedTexture class. Texture missaligned.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Need help in using vtkProjectedTexture class. Texture missaligned.

vinmean
This post was updated on .
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. Also, the texture has applied on the entire model instead of the camera focus region. 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

In the above case, the 3D model already has some color information, but I am trying to overlay my texture file on top of the model.


--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers