[vtkusers] Visualize zbuffer from different viewpoints

alykhantejani alykhan.tejani06 at imperial.ac.uk
Wed Jul 17 10:29:27 EDT 2013


Hi,

I am trying to follow the example here: 
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/ZBuffer
<http://www.vtk.org/Wiki/VTK/Examples/Cxx/Utilities/ZBuffer>   to visualize
the zbuffer. This works fine until I try to change the camera viewpoint. 

My code is as follows: which is the same as the example except for the bit
in bold:


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

Now the entire depth visualization is completely black. However, at this
camera position the mesh renders just fine, so I don't think it's due to
camera being too far away. Any ideas what I am doing wrong?

Thanks




--
View this message in context: http://vtk.1045678.n5.nabble.com/Visualize-zbuffer-from-different-viewpoints-tp5722015.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list