2

我正在尝试按照此处的示例:http : //www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/ZBuffer 来可视化zbuffer。在我尝试更改相机视点之前,这可以正常工作。

我的代码如下:除了粗体部分外,与示例相同:

// This demo creates depth map for a polydata instance by extracting 
// exact ZBuffer values. 
#include <vtkSmartPointer.h>

#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkBMPWriter.h>
#include <vtkWindowToImageFilter.h>
#include <vtkImageShiftScale.h>

int main(int argc, char *argv[]) { 
        vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); 
        vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); 
        vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); 
        vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); 
        vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); 

        vtkSmartPointer<vtkPLYReader> fileReader = vtkSmartPointer<vtkPLYReader>::New(); 
        vtkSmartPointer<vtkWindowToImageFilter> filter = vtkSmartPointer<vtkWindowToImageFilter>::New(); 
        vtkSmartPointer<vtkBMPWriter> imageWriter = vtkSmartPointer<vtkBMPWriter>::New(); 
        vtkSmartPointer<vtkImageShiftScale> scale = vtkSmartPointer<vtkImageShiftScale>::New(); 

        // Read .vtp file 
        fileReader->SetFileName("mesh.ply"); 

        //Build visualization enviroment 
        mapper->SetInputConnection(fileReader->GetOutputPort()); 
        actor->SetMapper(mapper); 
        renderer->AddActor(actor); 

        //change camera viewpoint 
        vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New(); 
        camera->SetPosition(0, 0, 650); 
        renderer->SetActiveCamera(camera); 


        renWin->AddRenderer(renderer); 
        interactor->SetRenderWindow(renWin); 
        renWin->Render(); 

        // Create Depth Map 
        filter->SetInput(renWin); 
        filter->SetMagnification(1); 
        filter->SetInputBufferTypeToZBuffer();        //Extract z buffer value 

        scale->SetOutputScalarTypeToUnsignedChar(); 
        scale->SetInputConnection(filter->GetOutputPort()); 
        scale->SetShift(0); 
        scale->SetScale(-255); 

        // Write depth map as a .bmp image 
        imageWriter->SetFileName("out2.bmp"); 
        imageWriter->SetInputConnection(scale->GetOutputPort()); 
        imageWriter->Write(); 

        return EXIT_SUCCESS; 
} 

现在整个深度可视化是完全黑色的。然而,在这个相机位置,网格渲染得很好,所以我不认为这是因为相机距离太远。任何想法我做错了什么?

4

1 回答 1

2

这可能是因为您的远平面靠近正在渲染的对象。尝试在创建相机后放置一个更好的剪切平面,例如:

camera->SetClippingRange(640, 1000);
于 2013-07-17T22:27:41.167 回答