<DIV id=RTEContent>hello,</DIV> <DIV> </DIV> <DIV><STRONG>Problem I am trying to solve:</STRONG></DIV> <DIV> </DIV> <DIV>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.</DIV> <DIV> </DIV> <DIV>These surfaces are extracted from the mesh of a human body.</DIV> <DIV> </DIV> <DIV>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.</DIV> <DIV> </DIV> <DIV><STRONG>Approach i am following: </STRONG></DIV> <DIV> </DIV> <DIV>To simplify my problem, here are the steps i am following</DIV> <DIV> </DIV> <OL> <LI>I first created a hemisphere actor using vtkSphereSource</LI> <LI>Next i create a square Plane actor which represents the base of the hemispherical surface.</LI> <LI>Now i create an off screen
render window using <STRONG>vtkWin32OpenGLRenderWindow. </STRONG></LI> <LI>I make the renderer to use OrthographicProjection using vtkRenderer::ParallelProjectionOn.</LI> <LI>Then i first render both actors to the renderer.</LI> <LI>I get the z-buffer data of the render window using vtkRenderWindow::GetZBufferData with the hemisphere and cache it.</LI> <LI>Then i hide the hemipherical actor using vtkActor::VisibilityOff.</LI> <LI>Then i get the z-buffer data of the plane actor.</LI> <LI>Now i compute the difference which is an estimate of the volume.</LI></OL> <div><STRONG>Difficulty:</STRONG></div> <DIV> </DIV> <DIV>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.</DIV> <DIV> </DIV> <DIV><STRONG><EM>Now the difficulty is, i am getting a negative cumulative difference.</EM></STRONG></DIV>
<DIV><EM></EM> </DIV> <DIV><STRONG><EM>Also this estimate of the volume is relative to the graphic world i created.</EM></STRONG></DIV> <DIV><STRONG><EM></EM></STRONG> </DIV> <DIV><STRONG><EM>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 ?</EM></STRONG></DIV> <DIV> </DIV> <DIV>Below is the code i used..............</DIV> <DIV> </DIV> <DIV>Can Anyone tell me whats going wrong ?</DIV> <DIV> </DIV> <DIV>What do those z-values mean ??</DIV> <DIV> </DIV> <DIV>*************************************************************************************************</DIV> <DIV> </DIV> <DIV> </DIV><FONT color=#008000 size=2> <div>// create Sphere actor first</div></FONT><FONT size=2> <div>vtkSphereSource *pSphere = vtkSphereSource::New();</div> <div>pSphere->SetCenter( 0.0 , 0.0 , 0.0 );</div> <div>pSphere->SetRadius( 8.0 );</div>
<div>pSphere->SetStartTheta( 0.0 );</div> <div>pSphere->SetEndTheta( 360.0 );</div> <div>pSphere->SetThetaResolution( 30.0 );</div> <div>pSphere->SetStartPhi( 0.0 );</div> <div>pSphere->SetEndPhi( 90.0 );</div> <div>pSphere->SetPhiResolution( 30.0 );</div> <div> </div> <div>vtkPolyDataMapper *pSphereMapper = vtkPolyDataMapper::New();</div> <div>pSphereMapper->SetInput( pSphere->GetOutput() );</div> <div>pSphereMapper->Update();</div> <div> </div> <div>vtkOpenGLActor *pSphereActor = vtkOpenGLActor::New();</div> <div>pSphereActor->SetMapper( pSphereMapper );</div> <div>pSphereActor->GetProperty()->SetColor( 1.0 , 0.0 , 0.0 );</div> <div></FONT><FONT color=#0000ff size=2></FONT> </div> <div><FONT color=#0000ff size=2>float</FONT><FONT size=2> sphereBounds[6];</div> <div>pSphereActor->GetBounds( sphereBounds );</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>//
build coons plane actor</div></FONT><FONT size=2> <div>vtkPolyData *pCoonsPlane = vtkPolyData::New();</div> <div>vtkPoints *pMeshPoints;</div> <div>vtkCellArray *pMeshCells;</div> <div> </div> <div></div> <div></FONT><FONT color=#008000 size=2>// allocate space for points</div></FONT><FONT size=2> <div>pMeshPoints = vtkPoints::New();</div> <div>pMeshPoints->Allocate( 4 );</div> <div>pMeshPoints->InsertNextPoint( sphereBounds[0] , sphereBounds[2] , 0.0 );</div> <div>pMeshPoints->InsertNextPoint( sphereBounds[0] , sphereBounds[3] , 0.0 );</div> <div>pMeshPoints->InsertNextPoint( sphereBounds[1] , sphereBounds[3] , 0.0 );</div> <div>pMeshPoints->InsertNextPoint( sphereBounds[1] , sphereBounds[2] , 0.0 );</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// allocate space for cells</div></FONT><FONT size=2> <div>pMeshCells = vtkCellArray::New();</div> <div>pMeshCells->Allocate(
pMeshCells->EstimateSize( 1 , 4 ) );</div> <div>vtkIdType pts[4];</div> <div></div> <div>pts[0] = 0;</div> <div>pts[1] = 1;</div> <div>pts[2] = 2;</div> <div>pts[3] = 3;</div> <div>pMeshCells->InsertNextCell( 4 , pts ); </div> <div></div> <div> </div> <div>pCoonsPlane->SetPoints( pMeshPoints );</div> <div>pCoonsPlane->SetPolys( pMeshCells );</div> <div> </div> <div>pMeshPoints->Delete();</div> <div>pMeshCells->Delete();</div> <div> </div> <div>vtkPolyDataMapper *pCoonsMapper = vtkPolyDataMapper::New();</div> <div>pCoonsMapper->SetInput( pCoonsPlane );</div> <div>pCoonsMapper->Update();</div> <div> </div> <div>vtkOpenGLActor *pCoonsActor = vtkOpenGLActor::New();</div> <div>pCoonsActor->SetMapper( pCoonsMapper );</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// setup rendering</div></FONT><FONT size=2> <div>vtkOpenGLRenderer *pOffScreenRenderer =
vtkOpenGLRenderer::New();</div> <div></div> <div></FONT><FONT color=#0000ff size=2></FONT> </div> <div><FONT color=#0000ff size=2>double</FONT><FONT size=2> wx, wy;</div> <div>wx = 500;</div> <div>wy = 500;</div> <div> </div> <div>vtkWin32OpenGLRenderWindow *pOffScreenRenderWindow = vtkWin32OpenGLRenderWindow::New();</div> <div>pOffScreenRenderWindow->OffScreenRenderingOn();</div> <div>pOffScreenRenderWindow->AddRenderer( pOffScreenRenderer );</div> <div>pOffScreenRenderWindow->Start();</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// add actors</div></FONT><FONT size=2> <div>pOffScreenRenderer->AddActor( pSphereActor );</div> <div>pOffScreenRenderer->AddActor( pCoonsActor );</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// set up projection attributes</div></FONT><FONT size=2>
<div>pOffScreenRenderer->GetActiveCamera()->ParallelProjectionOn();</div> <div>pOffScreenRenderWindow->SetSize( wx , wy );</div> <div>pOffScreenRenderer->ResetCamera();</div> <div></div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// show sphere and coons plane actor first</div></FONT><FONT size=2> <div>pOffScreenRenderer->Render();</div> <div></div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// write window to disk image</div></FONT><FONT size=2> <div>vtkWindowToImageFilter *pSphereWindowImageFilter = vtkWindowToImageFilter::New();</div> <div>pSphereWindowImageFilter->SetInput( pOffScreenRenderWindow );</div> <div>vtkJPEGWriter *pSphereImageWriter = vtkJPEGWriter::New();</div> <div>pSphereImageWriter->SetInput( pSphereWindowImageFilter->GetOutput() );</div> <div>pSphereImageWriter->SetQuality( 100.0 );</div>
<div>pSphereImageWriter->SetFileName( "Sphere_image.jpg" );</div> <div>pSphereImageWriter->ProgressiveOff();</div> <div>pSphereImageWriter->Write();</div> <div>pSphereImageWriter->Delete();</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// get Sphere zbuffer </div></FONT><FONT size=2> <div></FONT><FONT color=#0000ff size=2>float</FONT><FONT size=2> *pSphereZBuffer = pOffScreenRenderWindow->GetZbufferData( 0 , 0 , wx , wy );</div> <div></div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// show only coons actor</div></FONT><FONT size=2> <div>pSphereActor->VisibilityOff();</div> <div>pOffScreenRenderer->Render();</div> <div></div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// write window to disk image</div></FONT><FONT size=2> <div>vtkWindowToImageFilter *pCoonsWindowImageFilter =
vtkWindowToImageFilter::New();</div> <div>pCoonsWindowImageFilter->SetInput( pOffScreenRenderWindow );</div> <div>vtkJPEGWriter *pCoonsImageWriter = vtkJPEGWriter::New();</div> <div>pCoonsImageWriter->SetInput( pCoonsWindowImageFilter->GetOutput() );</div> <div>pCoonsImageWriter->SetQuality( 100.0 );</div> <div>pCoonsImageWriter->SetFileName( "coons_image.jpg" );</div> <div>pCoonsImageWriter->ProgressiveOff();</div> <div>pCoonsImageWriter->Write();</div> <div>pCoonsImageWriter->Delete();</div> <div></FONT><FONT color=#008000 size=2></FONT> </div> <div><FONT color=#008000 size=2>// get Sphere zbuffer </div></FONT><FONT size=2> <div></FONT><FONT color=#0000ff size=2>float</FONT><FONT size=2> *pCoonsZBuffer = pOffScreenRenderWindow->GetZbufferData( 0 , 0 , wx , wy );</div> <div> </div><FONT color=#008000 size=2> <div>// compute diffrence</div></FONT></FONT><FONT color=#0000ff size=2></FONT> <div><FONT color=#0000ff
size=2>double</FONT><FONT size=2> dblSphereVolume = 0.0;</div> <div></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>( </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> i = 0 ; i < wx ; i++ )</div> <div>{</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>( </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> j = 0 ; j < wy ; j++ )</div> <div>{</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div></FONT><FONT color=#0000ff size=2>long</FONT><FONT size=2> index = i * j;</div> <div></FONT><FONT color=#0000ff size=2>double</FONT><FONT size=2> coons_depth, Sphere_depth;</div> <div>Sphere_depth = pSphereZBuffer[index];</div> <div></div></BLOCKQUOTE></BLOCKQUOTE></FONT> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div><FONT color=#008000 size=2></div></FONT><FONT size=2> <div></div> <div>coons_depth = pCoonsZBuffer[index];</div>
<div></div> <div></FONT> <div><FONT color=#008000 size=2></div></FONT><FONT size=2> <div></div></FONT><FONT color=#0000ff size=2>double</FONT><FONT size=2> diff = ( Sphere_depth - coons_depth );</div></FONT><FONT size=2> <div>dblSphereVolume += diff;</div></BLOCKQUOTE> <div>}</div></BLOCKQUOTE> <div>}</div> <div> </div> <div>printf( "\ncomputed Sphere volume = %lf\n" , dblSphereVolume );</div> <div>getch();</div></FONT> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV> <DIV> </DIV><p>
                <hr size=1> <B>Yahoo! Personals</B><BR>
Skip the bars and set-ups and <a href="http://us.rd.yahoo.com/evt=36107/*http://personals.yahoo.com/us/reg/free7days
">start using Yahoo! Personals for free</a>