<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Dear David,</div><div>of course I am sure. I was building my example just like the one you have posted. The only difference being the data I put in the filter.&nbsp;</div><div>I get the error: Access violation reading location 0x0000004c.&nbsp;</div><div>It seems as if the filter produces an empty output. I just can't see why.</div><div>Here is the code:</div><div><span class="null"><p>#define Instantiate(obj, class) vtkSmartPointer&lt;class&gt; obj = vtkSmartPointer&lt;class&gt;::New();</p><p> int main (int argc, char *argv[])
 {</p><p>         // Read .mhd file</p><p>Instantiate(fileReader, vtkMetaImageReader);&nbsp;</p><p>&nbsp;const char filename[] = "./ID_1.mhd";</p><p>fileReader-&gt;SetFileName(filename);        </p><p>fileReader-&gt;Update();</p><p>        // Visualization&nbsp;</p><p>Instantiate(imageData, vtkImageData);&nbsp;</p><p>imageData = fileReader-&gt;GetOutput();</p><p>   // Build 3d Object</p><p>Instantiate(marchingCubes,vtkMarchingCubes );&nbsp;</p><p>marchingCubes-&gt;SetValue(0,1);&nbsp;</p><p>marchingCubes-&gt;SetInput( imageData );</p><p>// Locator&nbsp;</p><p>&nbsp;Instantiate(pointLocator, vtkPointLocator);&nbsp;</p><p>&nbsp;pointLocator-&gt;SetDataSet(marchingCubes-&gt;GetOutput());&nbsp;</p><p>&nbsp;pointLocator-&gt;BuildLocator();</p><p>// Mapper&nbsp;</p><p>&nbsp;Instantiate(imageDataMapper,vtkPolyDataMapper);&nbsp;</p><p>imageDataMapper-&gt;ScalarVisibilityOff();&nbsp;</p><p>imageDataMapper-&gt;SetInput( marchingCubes-&gt;GetOutput() );&nbsp;</p><p>// Actor&nbsp;</p><p>Instantiate(actorImageDataActor,vtkActor);&nbsp;</p><p>actorImageDataActor-&gt;SetMapper( imageDataMapper );</p><p><br></p><p>double testPoint[3] = {100.0, 100.0, 100.0};</p><p>          // Find the closest points to TestPoint&nbsp;</p><p>vtkIdType iD = pointLocator-&gt;FindClosestPoint(testPoint);&nbsp;</p><p>&nbsp;std::cout &lt;&lt; "The closest point is point " &lt;&lt; iD &lt;&lt; std::endl; </p><p>
        //Get the coordinates of the closest point&nbsp;</p><p>&nbsp;double closestPoint[3];&nbsp;</p><p>pointLocator-&gt;GetDataSet()-&gt;GetPoint(iD, closestPoint);&nbsp;</p><p>std::cout &lt;&lt; "Coordinates: " &lt;&lt; closestPoint[0] &lt;&lt; " "
 &lt;&lt; closestPoint[1] &lt;&lt; " " &lt;&lt; closestPoint[2] &lt;&lt;
 std::endl;&nbsp;</p><p>// actor for closest point&nbsp;</p><p>vtkSmartPointer&lt;vtkActor&gt; actCube3 = 
vtkSmartPointer&lt;vtkActor&gt;::New();&nbsp;</p><p>actCube3-&gt;SetMapper(mapCube);</p><p>    actCube3-&gt;GetProperty()-&gt;SetColor(1, 0,0); &nbsp;</p><p>actCube3-&gt;SetPosition(closestPoint[0],closestPoint[1],closestPoint[2]);</p><p>// Renderer&nbsp;</p><p>&nbsp;Instantiate(renderer, vtkRenderer);&nbsp;</p><p>&nbsp;renderer-&gt;AddActor(actorImageDataActor);&nbsp;</p><p>&nbsp;renderer-&gt;AddActor(actCube3);&nbsp;</p><p>&nbsp;renderer-&gt;SetBackground(.9, .5, .0);&nbsp;</p><p>// RenderWindow</p><p>&nbsp;Instantiate(renderWindow, vtkRenderWindow);&nbsp;</p><p>&nbsp;renderWindow-&gt;AddRenderer(renderer);</p><p>        
        // Interactor&nbsp;</p><p>&nbsp;Instantiate(renderWindowInteractor, vtkRenderWindowInteractor);&nbsp;</p><p>&nbsp;renderWindowInteractor-&gt;SetRenderWindow(renderWindow);&nbsp;</p><p>&nbsp;renderWindowInteractor-&gt;Initialize();&nbsp;</p><p>&nbsp;renderWindowInteractor-&gt;Start();
 </p><p>   return EXIT_SUCCESS;</p><p>&nbsp;}</p></span></div><div><br></div><div><br></div><br><div><div>Am 25.11.2013 um 13:54 schrieb David Doria:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Mon, Nov 25, 2013 at 7:09 AM, Susanne Schmalkalt<br>&lt;<a href="mailto:Susanne.Schmalkalt@gmx.de">Susanne.Schmalkalt@gmx.de</a>&gt; wrote:<br><blockquote type="cite">Dear all,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I have a metaobject, which I read with vtkMetaImageReader. I then use<br></blockquote><blockquote type="cite">vtkMarchingContourFilter to extract its surface. Then I have a point A close<br></blockquote><blockquote type="cite">to this surface. How can I find the closest point to A on the surface? When<br></blockquote><blockquote type="cite">I use vtkPointLocator and findClosestPoint, I get a point that lies on the<br></blockquote><blockquote type="cite">outline of my metaobject, but not on the object itself.<br></blockquote><blockquote type="cite">Does anyone have an idea why this might be and how to solve it?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks!<br></blockquote><blockquote type="cite">Susi<br></blockquote><br>Are you sure you're calling FindClosestPoint on a locator created with<br>the output of the vtkMarchingContourFilter?<br><br>This example does what you're looking for (it should be the same once<br>you have a vtkPolyData as the output of the vtkMarchingContourFilter):<br><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/CellLocator">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/CellLocator</a><br><br>David<br></div></blockquote></div><br></body></html>