2
我想要按照這裏的示例:http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/ZBuffer可視化zbuffer。這工作正常,直到我試圖改變相機的觀點。VTK:可視化深度緩衝區
我的代碼如下:其是相同,除了用於以粗體顯示的位的例子:
// 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;
}
現在整個深度的可視化是完全的黑色。然而,在這個相機位置,網格呈現得很好,所以我不認爲這是由於相機太遠。任何想法我做錯了什麼?