<DIV id=RTEContent> <DIV id=RTEContent> <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>Next i create a square Plane actor which represents the base of the hemispherical surface.
<LI>Now i create an off screen render window using <STRONG>vtkWin32OpenGLRenderWindow. </STRONG> <LI>I make the renderer to use OrthographicProjection using vtkRenderer::ParallelProjectionOn. <LI>Then i first render both actors to the renderer. <LI>I get the z-buffer data of the render window using vtkRenderWindow::GetZBufferData with the hemisphere and cache it. <LI>Then i hide the hemipherical actor using vtkActor::VisibilityOff. <LI>Then i get the z-buffer data of the plane actor. <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>Thanks in Advance.</DIV> <DIV> </DIV> <DIV>Regards,</DIV> <DIV> </DIV> <DIV>Deepak</DIV> <DIV> </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><p>
        
                <hr size=1>Yahoo! Shopping<br>
Find Great Deals on Gifts at <a href="http://shopping.yahoo.com/;_ylc=X3oDMTE2bzVzaHJtBF9TAzk1OTQ5NjM2BHNlYwNtYWlsdGFnBHNsawNob2xpZGF5LTA1
">Yahoo! Shopping</a>