vtk:如何使vtkProjectedTexture类起作用?

时间:2018-11-20 11:16:05

标签: graphics textures vtk texture-mapping

我在vtk用户论坛中用我的代码发布了类似的问题。我找不到答案,因此无法在此处发布。

我想将图像作为纹理投影到大型3D上的小区域 模型。我有3D模型作为演员。我写了下面的功能来测试 投影的纹理类。我按照链接中的示例 https://lorensen.github.io/VTKExamples/site/Cxx/Texture/ProjectedTexture/

作为第一步,我能够将所需的摄像机视图设置为该设置。但是,我 然后无法正确叠加纹理。质地好像 拉伸,似乎并没有集中在焦点上。同样,纹理已应用于整个模型,而不是应用于相机焦点区域。我什至画了 展示各种相机参数正确性的视锥 位置,焦点和向上向量。请找到截图 附加渲染场景。为什么会发生这种拉伸?什么是 需要设置其他参数吗?我找不到很多例子,或者 有关此类的文档。

//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); 
}

Image and 3D model on which the image is overlayed

在上述情况下,3D模型已经具有一些颜色信息,但我试图将纹理文件覆盖在模型顶部。

0 个答案:

没有答案