<div>Hello Will,</div>
<div>&nbsp;</div>
<div>A million thanks for your reply. I greatly appreciate it.</div>
<div>&nbsp;</div>
<div>Let us keep the discussion on the mailing list, so other members can benefit from it. Because this is a problem, that could&nbsp;quite possibly be faced by anyone who is working on the zbuffer.</div>
<div>&nbsp;</div>
<div><strong>&gt;&gt;&gt;&gt; Regarding the use of vtkWorldPointPicker</strong></div>
<div>&nbsp;</div>
<div>I tried the vtkWorldPointPicker and it was very slow ( render window size 500 x 500 ).</div>
<div>&nbsp;</div>
<div>But what i interpret from the information given in the vtk textbook ( &quot;The VisualizationToolkit - 2nd edition&quot; An Object oriented approach to 3D graphics - Page Number = 343 ) is that vtkWorldPointPicker just finds the z-buffer value of the given&nbsp;( x , y )&nbsp;position in the render window. 
</div>
<div>&nbsp;</div>
<div>Which i think is in no way&nbsp;different from the information obtained from vtkRenderWindow::GetZBufferData.</div>
<div>&nbsp;</div>
<div>Please&nbsp;correct me if i am wrong ?</div>
<div>&nbsp;</div>
<div>If all i get from the vtkWorldPointPicker is the&nbsp;z-buffer value, dont you think calling vtkWorldPointPicker &nbsp;at each ( x , y&nbsp;) position in my offscreen render window would be slower than fetching the z-buffer values all at once by calling&nbsp; vtkRenderWindow::GetZBufferData. 
</div>
<div>&nbsp;</div>
<div>Please correct me if i am wrong ?</div>
<div>&nbsp;</div>
<div>
<div><strong>&gt;&gt;&gt;&gt; Regarding the use of vtkCoordinate</strong></div>
<div><strong></strong>&nbsp;</div>
<div>The farthest place i can&nbsp;get using the vtkCoordinate, is to the world coordinates.</div>
<div>&nbsp;</div>
<div>Which is the same as, what your vtkWorldPointPicker returns which is also similar to the zbuffer information obtained by vtkRenderWindow::GetZBufferData. Also when i tried using vtkCoordinate earlier it was very slow. 
</div>
<div>&nbsp; </div>
<div>Now the difference between the two zbuffers i am computing ( to find the volume ) is relative to the current graphics world i created ( the clipping plane positions, dimensions of the viewport ). Rememeber i am using Orthographic 
i.e. Parallel projection.</div>
<div>&nbsp;</div>
<div>My goal is to transform this volume estimate ( which is now relative to the graphics world i created ) to be independent of the graphics world. So even if i change the size of the render window, the volume estimate should still be the same.&nbsp; 
</div>
<div>&nbsp;</div>
<div>If you have not looked at the transformation, i am currently using, here is the pseudocode :</div>
<div><font color="#0000ff" size="2"></font>&nbsp;</div>
<div>***************************************************************************************************************</div>
<div>&nbsp;</div>
<div><font color="#0000ff" size="2">// converts the given zBuffer value to the world coordinates</font></div>
<div><font color="#0000ff" size="2">#define</font><font size="2"> REAL_DEPTH_ORTHO( zBufferVal , zNear , zFar ) ( zNear + zBufferVal * (zFar - zNear) )</font></div>
<div>&nbsp;</div>
<div>// computes difference between the two zbuffers</div>
<div>for( int x = 0 ; x &lt; wx ; x++ )<br>{<br>&nbsp;for( int y = 0 ; y &lt; wy ; y++ ) <br>&nbsp;{<br>&nbsp;&nbsp;float coons_depth, sphere_depth;<br>&nbsp;&nbsp;long index = y * wx + x;</div>
<p>&nbsp;&nbsp;sphere_depth = pSphereZBuffer[index];<br>&nbsp;&nbsp;coons_depth = pCoonsZBuffer[index];</p>
<p>&nbsp;&nbsp;if( !( CHECK_DEPTH( coons_depth ) &amp;&amp; CHECK_DEPTH( sphere_depth ) ) || CHECK_DEPTH_SIMILARITY( coons_depth , sphere_depth ) )<br>&nbsp;&nbsp;&nbsp;continue;</p>
<p>&nbsp;&nbsp;coons_depth = REAL_DEPTH_ORTHO( coons_depth , zNear , zFar );<br>&nbsp;&nbsp;sphere_depth = REAL_DEPTH_ORTHO( sphere_depth , zNear , zFar );</p>
<p>&nbsp;&nbsp;float diff = ( coons_depth - sphere_depth );</p>
<p>&nbsp;&nbsp;if( diff &gt; 0 )<br>&nbsp;&nbsp;&nbsp;dblSphereVolume += diff;<br>&nbsp;}<br>}</p>
<p>// transform the computed volume estimate to be independent of the graphics world<br>float scale = pOffScreenRenderer-&gt;GetActiveCamera()-&gt;GetParallelScale();<br>float aspect = wx / wy;<br>float world_x = 2 * scale * aspect;
<br>float world_y = 2 * scale;</p>
<p>dblSphereVolume *= (world_x/wx) * (world_y/wy);</p>
<p>float actual_sphere_volume = ( 2 * vtkMath::Pi() / 3 ) * pow( radius , 3 );</p>
<p>float relative_error = ( actual_sphere_volume - dblSphereVolume ) * 100.0 / actual_sphere_volume;<br></p>
<p>************************************************************************************************************************************************</p></div>
<div>
<div>Is this conversion code right ?</div>
<div>&nbsp;</div>
<div>Very, Very, Very eagerly waiting for your reply ?</div>
<div>&nbsp;</div>
<div>Regards,</div>
<div>&nbsp;</div>
<div>Deepak Roy</div>
<div>&nbsp;</div>
<div><br><b><i>Will Schroeder &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:will.schroeder@kitware.com" target="_blank">will.schroeder@kitware.com</a>&gt;</i></b> wrote:</div></div>
<blockquote style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">I recommend looking at the vtkWorldPointPicker and other pickers for how to do this. Also look at vtkCoordinate and vtkRenderer for coordinae transformations. 
<br>Will<br><br>At 12:12 PM 1/12/2006, Deepak Roy wrote:<br>
<blockquote cite="http://" type="cite">Hello,<br>&nbsp;<br>My name is Deepak Roy. I am a graduate student in the department of computer science at university of houston and a research assistant in the Computational Biomedicine Lab ( 
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.cbl.uh.edu/" target="_blank"><font color="#003399">www.cbl.uh.edu</font></a> ) at university of houston.<br>&nbsp;<br>I have sent numerous emails to the mailing list regarding a question in VTK, but recieved no reply. I have also sent an email before to you and recieved no reply either. 
<br>&nbsp;<br>It would be kind of you if you could look into the question. Below is a brief description of it.<br>&nbsp;<br>It would also be helpful, if you could give me a contact number of the VTK Tech support people.<br>&nbsp;<br>Very Eagerly waiting for a reply, from the VTK Tech Support. 
<br>&nbsp;<br>Regards,<br>&amp;nbs!<br>p;<br>Deepak Roy<br>&nbsp;<br>Email:<br>&nbsp;<br><font color="#003399"><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.f303.mail.yahoo.com/ym/Compose?To=cdeepakroy@yahoo.com" target="_blank">
cdeepakroy@yahoo.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.f303.mail.yahoo.com/ym/Compose?To=drchitta@mail.uh.edu" target="_blank">drchitta@mail.uh.edu</a><br></font>&nbsp;<br>*************************************************************************************************
<br>&nbsp;<br><b>Subject:</b>&nbsp; <br>&nbsp;<br>How to convert the z-buffer depth values to z-values in the world coordinate system ? <br>&nbsp;<br><b>Problem I am trying to solve:<br></b>&nbsp;<br>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.
<br>&nbsp;<br>These surfaces are extracted from the mesh of a human body. <br>&nbsp;<br>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. I very well know this can be done with other alternatives, but i want to use the z-buffer difference only first to see how it works. 
<br>&nbsp;<br><b>Approach i am following: <br></b>&nbsp;<br>To simplify my problem, here are the steps i am following<br>&nbsp; 
<ol>
<li>I first created a simple hemisphere actor using vtkSphereSource 
<li>Next i create a simple square Plane actor which represents the base of the hemispherical surface. 
<li>Now i create an off screen render window using <b>vtkWin32OpenGLRenderWindow. </b>
<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 cumulative difference between the two zbuffers which is an estimate of the volume. </li></li></li></li></li></li></li></li></li></ol><b>Difficulty:<br></b>&nbsp;<br>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. 
<br>&nbsp;<br><b><i>Now the difficulty is this estimate of the volume is relative to the graphic world i created.<br></i></b>&nbsp;<br><b><i>How do i convert it to an est! imate of the real volume ? which factor or scales should i multiply the z-buffer differnce with to get the volume ? 
<br></i></b>&nbsp;<br>How do i back transform the ZBuffer values? I came to know there is something called gluUnProject&nbsp; in opengl GLUT. Is there anything similar in VTK.<br>&nbsp;<br>Can i use opengl commands amidst VTK code ?<br>
&nbsp;<br><b>Email Attachments:<br></b>&nbsp;<br>
<dl>
<dd>- the C++ test code i am using - zbuffer_test.cxx. You can run and test the C++ file if you want.<br>
<dd><br>&nbsp; 
<dd>- the z-buffer image i obtained for the hemisphere - sphere-zbuffer.jpg<br>
<dd><br>&nbsp; 
<dd>- the z-buffer image i obtained for the underlying plane - coons_zbuffer.jpg<br><br></dd></dd></dd></dd></dd></dl>&nbsp;<br>Can Anyone tell me whats going wrong ? It would be a great help .... <br>&nbsp;<br>What do! those z-values mean ?? 
<br>&nbsp;<br>Thanks in Advance.<br>&nbsp;<br>Regards,<br>&nbsp;<br>Deepak<br><br><br>Yahoo! Photos<br>Ring in the New Year with <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/mail_us/taglines/photos/*http://pa.yahoo.com/*http://us.rd.yahoo.com/mail_us/taglines/photos/evt=38087/*http://pg.photos.yahoo.com/ph//page?.file=calendar_splash.html&amp;.dir=" target="_blank">
Photo Calendars</a>. Add photos, events, holidays, whatever. <br><br><br>// VTK INCLUDES<br>#include &quot;vtkOpenGLRenderer.h&quot;<br>#include &quot;vtkWin32OpenGLRenderWindow.h&quot;<br>#include &quot;vtkRenderWindowInteractor.h
 &quot;<br>#include &quot;vtkOpenGLActor.h&quot;<br>#include &quot;vtkCamera.h&quot;<br>#include &quot;vtkProperty.h&quot;<br>#include &quot;vtkMatrix4x4.h&quot;<br><br>#include &quot;vtkSphereSource.h&quot;<br>#include &quot; 
vtkPolyData.h&quot;<br>#include &quot;vtkPolyDataMapper.h&quot;<br>#include &quot;vtkCellArray.h&quot;<br>#include &quot;vtkImageData.h&quot;<br>#include &quot;vtkPointData.h&quot;<br>#include &quot;vtkCoordinate.h&quot;<br>
#include &quot;vtkMath.h&quot;<br><br>#include &quot;vtkWindowToImageFilter.h&quot;<br>#include &quot;vtkJPEGWriter.h&quot;<br><br>// STD INCLUDES<br>#include &quot;conio.h&quot;<br><br>// CUSTOM MACROS<br>#define CHECK_DEPTH( depth ) ( depth &gt; 
0.0 &amp;&amp; depth &lt; 1.0 ) <br>#define CHECK_DEPTH_SIMILARITY( d1 , d2 ) ( d1 == d2 )<br>#define REAL_DEPTH( zBufferVal , zNear , zFar ) ( zNear * zFar / ( zBufferVal * (zNear - zFar ) + zFar ) )<br><br>void WriteZBufferToImage( int wx , int wy , float *pBuffer , const char *strImageFile ) 
<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkImageData *pZImage = vtkImageData::New();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pZImage-&gt;SetExtent( 0 , wx , 0 , wy , 0 , 0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pZImage-&gt;SetOrigin( 0.0 , 0.0 , 0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pZImage-&gt;SetSpacing( 1.0
 , 1.0 , 1.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pZImage-&gt;SetScalarTypeToUnsignedChar();<br>&nbsp;&nbsp;&nbsp; pZImage-&gt;SetNumberOfScalarComponents( 1 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pZImage-&gt;AllocateScalars();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsigned char *zPtr = (unsigned char *) pZImage-&gt;GetScalarPointer( 0 , 0 , 0 ); 
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( int i = 0 ; i &lt; (wx * wy) ; i++ )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zPtr[i] = pBuffer[i] * 255;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkJPEGWriter *pSphereImageWriter = vtkJPEGWriter::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetInput( pZImage ); 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetQuality( 40.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetFileName( strImageFile );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;ProgressiveOff();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;Write();<br><br>
}<br><br>void WriteWindowToImage( vtkWindow *pWindow , const char *strImageFile )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// write window to disk image<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkWindowToImageFilter *pWindowImageFilter = vtkWindowToImageFilter::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pWindowImageFilter-&gt;SetInput( pWindow );
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkImageData *pImage = pWindowImageFilter-&gt;GetOutput();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkJPEGWriter *pSphereImageWriter = vtkJPEGWriter::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetInput( pImage ); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetQuality( 
100.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;SetFileName( strImageFile );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;ProgressiveOff();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;Write();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereImageWriter-&gt;Delete();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pWindowImageFilter-&gt;Delete();<br>}<br><br>vtkActor *BuildSphereActor( float radius )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkSphereSource *pSphere = vtkSphereSource::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetCenter( 0.0 , 0.0 , 0.0 );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetRadius( radius );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetStartTheta( 0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetEndTheta( 360.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetThetaResolution( 30.0 );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetStartPhi( 
0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetEndPhi( 90.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphere-&gt;SetPhiResolution( 30.0 );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkPolyDataMapper *pSphereMapper = vtkPolyDataMapper::New(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereMapper-&gt;SetInput( pSphere-&gt;GetOutput() );
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereMapper-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkOpenGLActor *pSphereActor = vtkOpenGLActor::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereActor-&gt;SetMapper( pSphereMapper ); <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereActor-&gt;GetProperty()-&gt;SetColor( 
1.0 , 0.0 , 0.0 );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return pSphereActor;<br>}<br><br>vtkActor *BuildPlaneActor( float sphereBounds[6] )<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkPolyData *pCoonsPlane = vtkPolyData::New(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vtkPoints *pMeshPoints;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkCellArray *pMeshCells;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// allocate space for points<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pMeshPoints = vtkPoints::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;Allocate( 4 ); <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;InsertNextPoint( sphereBounds[0] , sphereBounds[2] , 
0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;InsertNextPoint( sphereBounds[0] , sphereBounds[3] , 0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;InsertNextPoint( sphereBounds[1] , sphereBounds[3] , 0.0 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;InsertNextPoint( sphereBounds[1] , sphereBounds[2] , 
0.0 );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// allocate space for cells<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pMeshCells = vtkCellArray::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshCells-&gt;Allocate( pMeshCells-&gt;EstimateSize( 1 , 4 ) );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vtkIdType pts[4];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pts[0] = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pts[1] = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pts[2] = 2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pts[3] = 3;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshCells-&gt;InsertNextCell( 4 , pts ); <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pCoonsPlane-&gt;SetPoints( pMeshPoints );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pCoonsPlane-&gt;SetPolys( pMeshCells ); <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshPoints-&gt;Delete();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pMeshCells-&gt;Delete();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkPolyDataMapper *pCoonsMapper = vtkPolyDataMapper::New();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pCoonsMapper-&gt;SetInput( pCoonsPlane );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pCoonsMapper-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkOpenGLActor *pCoonsActor = vtkOpenGLActor::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pCoonsActor-&gt;SetMapper( pCoonsMapper );<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return pCoonsActor;<br>}<br><br><br>void main()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// create Sphere actor first<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float radius = 10.0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vtkActor *pSphereActor = BuildSphereActor( radius );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float sphereBounds[6];
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereActor-&gt;GetBounds( sphereBounds ); <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// build coons actor<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vtkActor *pCoonsActor = BuildPlaneActor( sphereBounds );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// setup rendering<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkOpenGLRenderer *pOffScreenRenderer = vtkOpenGLRenderer::New();
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// add actors<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;AddActor( pSphereActor );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;AddActor( pCoonsActor );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// set parallel projection<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;GetActiveCamera()-&gt;ParallelProjectionOn(); 
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double wx, wy;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wx = 500;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wy = 500;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkWin32OpenGLRenderWindow *pOffScreenRenderWindow = vtkWin32OpenGLRenderWindow::New();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderWindow-&gt;OffScreenRenderingOn(); 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderWindow-&gt;AddRenderer( pOffScreenRenderer );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderWindow-&gt;SetSize( wx , wy );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderWindow-&gt;Start();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// show only breast actor 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;Render();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// write window to disk image<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WriteWindowToImage( pOffScreenRenderWindow , &quot;sphere_window.jpg&quot; );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// get Sphere zbuffer <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float *pSphereZBuffer = pOffScreenRenderWindow-&gt;GetZbufferData( 0 , 0 , wx , wy );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; WriteZBufferToImage( wx , wy , pSphereZBuffer , &quot;sphere_zbuffer.jpg&quot; );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// show only coons actor 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSphereActor-&gt;VisibilityOff();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;Render();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// write window to disk image<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WriteWindowToImage( pOffScreenRenderWindow , &quot;coons_window.jpg&quot; ); 
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// get Sphere zbuffer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float *pCoonsZBuffer = pOffScreenRenderWindow-&gt;GetZbufferData( 0 , 0 , wx , wy );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// write z buffer to disk<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WriteZBufferToImage( wx , wy , pCoonsZBuffer , &quot;coons_zbuffer.jpg&quot; ); 
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// compute diffrence<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double dblSphereVolume = 0.0;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float clip_range[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pOffScreenRenderer-&gt;GetActiveCamera()-&gt;GetClippingRange( clip_range );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float zNear = clip_range[0]; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float zFar = clip_range[1];<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf( &quot;\n zNear = %f , zFar = %f&quot; , zNear , zFar );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( int x = 0 ; x &lt; wx ; x++ )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( int y = 0 ; y &lt; wy ; y++ ) 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float coons_depth, sphere_depth;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long index = y * wx + x;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sphere_depth = pSphereZBuffer[index];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coons_depth = pCoonsZBuffer[index];
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( !( CHECK_DEPTH( coons_depth ) &amp;&amp; CHECK_DEPTH( sphere_depth ) ) || CHECK_DEPTH_SIMILARITY( coons_depth , sphere_depth ) )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float diff = ( coons_depth - sphere_depth );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( diff &gt; 0 )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dblSphereVolume += diff;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float sphere_volume = ( 2 * vtkMath::Pi() / 3 ) * pow( radius , 3 );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf( &quot;\ncomputed Sphere volume = %f, actual sphere volume = %f\n&quot; , dblSphereVolume , sphere_volume ); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();
<br>}</blockquote></blockquote>
<div><br>&nbsp;</div>