[vtkusers] How to interpret Z buffer data ?????? Please Help......................
Deepak Roy
cdeepakroy at yahoo.com
Wed Dec 7 12:51:06 EST 2005
hello,
Problem I am trying to solve:
I am trying to get the volume enclosed between a hemisphere like surface and a plane like surface which lies at the base of the hemispherical surface.
These surfaces are extracted from the mesh of a human body.
I want to use the z-buffer difference to estimate the enclosed volume, since it is more quick compared to vtkMassProperties. At the end i will compare with vtkMassProperties estimate.
Approach i am following:
To simplify my problem, here are the steps i am following
I first created a hemisphere actor using vtkSphereSource
Next i create a square Plane actor which represents the base of the hemispherical surface.
Now i create an off screen render window using vtkWin32OpenGLRenderWindow.
I make the renderer to use OrthographicProjection using vtkRenderer::ParallelProjectionOn.
Then i first render both actors to the renderer.
I get the z-buffer data of the render window using vtkRenderWindow::GetZBufferData with the hemisphere and cache it.
Then i hide the hemipherical actor using vtkActor::VisibilityOff.
Then i get the z-buffer data of the plane actor.
Now i compute the difference which is an estimate of the volume.
Difficulty:
I rendered the off screen render window for both actors to a disk image using vtkWindowToImageFilter and both the images come perfectly as expected. The images are attached to the message if you want to take a look.
Now the difficulty is, i am getting a negative cumulative difference.
Also this estimate of the volume is relative to the graphic world i created.
How do i convert it to an estimate of the real volume ? which factor or scales should i multiply the z-buffer differnce with to get the volume ?
Below is the code i used..............
Can Anyone tell me whats going wrong ?
What do those z-values mean ??
*************************************************************************************************
// create Sphere actor first
vtkSphereSource *pSphere = vtkSphereSource::New();
pSphere->SetCenter( 0.0 , 0.0 , 0.0 );
pSphere->SetRadius( 8.0 );
pSphere->SetStartTheta( 0.0 );
pSphere->SetEndTheta( 360.0 );
pSphere->SetThetaResolution( 30.0 );
pSphere->SetStartPhi( 0.0 );
pSphere->SetEndPhi( 90.0 );
pSphere->SetPhiResolution( 30.0 );
vtkPolyDataMapper *pSphereMapper = vtkPolyDataMapper::New();
pSphereMapper->SetInput( pSphere->GetOutput() );
pSphereMapper->Update();
vtkOpenGLActor *pSphereActor = vtkOpenGLActor::New();
pSphereActor->SetMapper( pSphereMapper );
pSphereActor->GetProperty()->SetColor( 1.0 , 0.0 , 0.0 );
float sphereBounds[6];
pSphereActor->GetBounds( sphereBounds );
// build coons plane actor
vtkPolyData *pCoonsPlane = vtkPolyData::New();
vtkPoints *pMeshPoints;
vtkCellArray *pMeshCells;
// allocate space for points
pMeshPoints = vtkPoints::New();
pMeshPoints->Allocate( 4 );
pMeshPoints->InsertNextPoint( sphereBounds[0] , sphereBounds[2] , 0.0 );
pMeshPoints->InsertNextPoint( sphereBounds[0] , sphereBounds[3] , 0.0 );
pMeshPoints->InsertNextPoint( sphereBounds[1] , sphereBounds[3] , 0.0 );
pMeshPoints->InsertNextPoint( sphereBounds[1] , sphereBounds[2] , 0.0 );
// allocate space for cells
pMeshCells = vtkCellArray::New();
pMeshCells->Allocate( pMeshCells->EstimateSize( 1 , 4 ) );
vtkIdType pts[4];
pts[0] = 0;
pts[1] = 1;
pts[2] = 2;
pts[3] = 3;
pMeshCells->InsertNextCell( 4 , pts );
pCoonsPlane->SetPoints( pMeshPoints );
pCoonsPlane->SetPolys( pMeshCells );
pMeshPoints->Delete();
pMeshCells->Delete();
vtkPolyDataMapper *pCoonsMapper = vtkPolyDataMapper::New();
pCoonsMapper->SetInput( pCoonsPlane );
pCoonsMapper->Update();
vtkOpenGLActor *pCoonsActor = vtkOpenGLActor::New();
pCoonsActor->SetMapper( pCoonsMapper );
// setup rendering
vtkOpenGLRenderer *pOffScreenRenderer = vtkOpenGLRenderer::New();
double wx, wy;
wx = 500;
wy = 500;
vtkWin32OpenGLRenderWindow *pOffScreenRenderWindow = vtkWin32OpenGLRenderWindow::New();
pOffScreenRenderWindow->OffScreenRenderingOn();
pOffScreenRenderWindow->AddRenderer( pOffScreenRenderer );
pOffScreenRenderWindow->Start();
// add actors
pOffScreenRenderer->AddActor( pSphereActor );
pOffScreenRenderer->AddActor( pCoonsActor );
// set up projection attributes
pOffScreenRenderer->GetActiveCamera()->ParallelProjectionOn();
pOffScreenRenderWindow->SetSize( wx , wy );
pOffScreenRenderer->ResetCamera();
// show sphere and coons plane actor first
pOffScreenRenderer->Render();
// write window to disk image
vtkWindowToImageFilter *pSphereWindowImageFilter = vtkWindowToImageFilter::New();
pSphereWindowImageFilter->SetInput( pOffScreenRenderWindow );
vtkJPEGWriter *pSphereImageWriter = vtkJPEGWriter::New();
pSphereImageWriter->SetInput( pSphereWindowImageFilter->GetOutput() );
pSphereImageWriter->SetQuality( 100.0 );
pSphereImageWriter->SetFileName( "Sphere_image.jpg" );
pSphereImageWriter->ProgressiveOff();
pSphereImageWriter->Write();
pSphereImageWriter->Delete();
// get Sphere zbuffer
float *pSphereZBuffer = pOffScreenRenderWindow->GetZbufferData( 0 , 0 , wx , wy );
// show only coons actor
pSphereActor->VisibilityOff();
pOffScreenRenderer->Render();
// write window to disk image
vtkWindowToImageFilter *pCoonsWindowImageFilter = vtkWindowToImageFilter::New();
pCoonsWindowImageFilter->SetInput( pOffScreenRenderWindow );
vtkJPEGWriter *pCoonsImageWriter = vtkJPEGWriter::New();
pCoonsImageWriter->SetInput( pCoonsWindowImageFilter->GetOutput() );
pCoonsImageWriter->SetQuality( 100.0 );
pCoonsImageWriter->SetFileName( "coons_image.jpg" );
pCoonsImageWriter->ProgressiveOff();
pCoonsImageWriter->Write();
pCoonsImageWriter->Delete();
// get Sphere zbuffer
float *pCoonsZBuffer = pOffScreenRenderWindow->GetZbufferData( 0 , 0 , wx , wy );
// compute diffrence
double dblSphereVolume = 0.0;
for( int i = 0 ; i < wx ; i++ )
{
for( int j = 0 ; j < wy ; j++ )
{
long index = i * j;
double coons_depth, Sphere_depth;
Sphere_depth = pSphereZBuffer[index];
coons_depth = pCoonsZBuffer[index];
double diff = ( Sphere_depth - coons_depth );
dblSphereVolume += diff;
}
}
printf( "\ncomputed Sphere volume = %lf\n" , dblSphereVolume );
getch();
---------------------------------
Yahoo! Personals
Skip the bars and set-ups and start using Yahoo! Personals for free
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051207/6e73de14/attachment.htm>
More information about the vtkusers
mailing list