[vtkusers] Build depth map of a 3D model

Wenlong Wang scc.wwl at gmail.com
Mon May 7 10:24:09 EDT 2012


Hi, David

Thank you for your reply. The error is gone now. But it turns out the
result image is just a black one.

Here is what I do,

*vtkPolyData* polydata = vtkPolyData::New();
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
vtkActor* actor = vtkActor::New();
vtkRenderer* renderer = vtkRenderer::New();
vtkRenderWindow* renWin = vtkRenderWindow::New();
vtkLight* frontLight = vtkLight::New();
vtkLight* backLight = vtkLight::New();
vtkCamera* camera = vtkCamera::New();
vtkGenericDataObjectReader* fileReader = vtkGenericDataObjectReader::New();
vtkBMPWriter* imageWriter = vtkBMPWriter::New();
vtkWindowToImageFilter* filter = vtkWindowToImageFilter::New();
vtkImageCast* cast = vtkImageCast::New();


fileReader->SetFileName("C:\\Users\\Wenlong\\Desktop\\surface.vtk");
//Open .vtk file
fileReader->OpenVTKFile();
fileReader->Update();

polydata = fileReader->GetPolyDataOutput();                     //Get
polydata

frontLight->SetFocalPoint(0, 1, 0);                                     //
Set illuminations
frontLight->SetPosition(0, 0, 1000000);
frontLight->SetIntensity(1.0);

backLight->SetFocalPoint(0, 1, 0);
backLight->SetPosition(0, 0, -1000000);
backLight->SetIntensity(1.0);

mapper->SetInput(polydata);
//Set mapper

actor->SetMapper(mapper);                                             //Set
actor
actor->GetProperty()->SetColor(0.9, 0.9, 0.9);

camera->SetViewUp(0, 1, 0);                                           //Set
camera

renderer->SetBackground(0, 0, 0);                                   //Set
renderer
renderer->AddActor(actor);
renderer->AddLight(frontLight);
renderer->AddLight(backLight);
renderer->SetActiveCamera(camera);
renderer->ResetCamera();

renWin->AddRenderer(renderer);                                      //Set
render window
renWin->SetSize(512, 512);
renWin->Render();

filter->SetInput(renWin);
//Set window to image filter
filter->SetMagnification(1);
filter->SetInputBufferTypeToZBuffer();
filter->Update();

cast->SetInput(filter->GetOutput());
cast->SetOutputScalarTypeToUnsignedChar();                  //Set image cast
cast->Update();

imageWriter->SetFileName("C:\\Users\\Wenlong\\Desktop\\DepthMap.bmp");
imageWriter->SetInput(cast->GetOutput());
imageWriter->Update();
imageWriter->Write();
//Write image*

The outcoming image is a 512x512 black image. I'm not sure which part of
the code cause such a problem. Please correct me.

Many thanks for your kindly help.

Best wishes
Wenlong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120507/bd1b1cc0/attachment.htm>


More information about the vtkusers mailing list