<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. </div><div>I get the error: Access violation reading location 0x0000004c. </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<class> obj = vtkSmartPointer<class>::New();</p><p> int main (int argc, char *argv[])
{</p><p>         // Read .mhd file</p><p>Instantiate(fileReader, vtkMetaImageReader); </p><p> const char filename[] = "./ID_1.mhd";</p><p>fileReader->SetFileName(filename);        </p><p>fileReader->Update();</p><p>        // Visualization </p><p>Instantiate(imageData, vtkImageData); </p><p>imageData = fileReader->GetOutput();</p><p> // Build 3d Object</p><p>Instantiate(marchingCubes,vtkMarchingCubes ); </p><p>marchingCubes->SetValue(0,1); </p><p>marchingCubes->SetInput( imageData );</p><p>// Locator </p><p> Instantiate(pointLocator, vtkPointLocator); </p><p> pointLocator->SetDataSet(marchingCubes->GetOutput()); </p><p> pointLocator->BuildLocator();</p><p>// Mapper </p><p> Instantiate(imageDataMapper,vtkPolyDataMapper); </p><p>imageDataMapper->ScalarVisibilityOff(); </p><p>imageDataMapper->SetInput( marchingCubes->GetOutput() ); </p><p>// Actor </p><p>Instantiate(actorImageDataActor,vtkActor); </p><p>actorImageDataActor->SetMapper( imageDataMapper );</p><p><br></p><p>double testPoint[3] = {100.0, 100.0, 100.0};</p><p>         // Find the closest points to TestPoint </p><p>vtkIdType iD = pointLocator->FindClosestPoint(testPoint); </p><p> std::cout << "The closest point is point " << iD << std::endl; </p><p>
        //Get the coordinates of the closest point </p><p> double closestPoint[3]; </p><p>pointLocator->GetDataSet()->GetPoint(iD, closestPoint); </p><p>std::cout << "Coordinates: " << closestPoint[0] << " "
<< closestPoint[1] << " " << closestPoint[2] <<
std::endl; </p><p>// actor for closest point </p><p>vtkSmartPointer<vtkActor> actCube3 =
vtkSmartPointer<vtkActor>::New(); </p><p>actCube3->SetMapper(mapCube);</p><p> actCube3->GetProperty()->SetColor(1, 0,0); </p><p>actCube3->SetPosition(closestPoint[0],closestPoint[1],closestPoint[2]);</p><p>// Renderer </p><p> Instantiate(renderer, vtkRenderer); </p><p> renderer->AddActor(actorImageDataActor); </p><p> renderer->AddActor(actCube3); </p><p> renderer->SetBackground(.9, .5, .0); </p><p>// RenderWindow</p><p> Instantiate(renderWindow, vtkRenderWindow); </p><p> renderWindow->AddRenderer(renderer);</p><p>        
        // Interactor </p><p> Instantiate(renderWindowInteractor, vtkRenderWindowInteractor); </p><p> renderWindowInteractor->SetRenderWindow(renderWindow); </p><p> renderWindowInteractor->Initialize(); </p><p> renderWindowInteractor->Start();
</p><p> return EXIT_SUCCESS;</p><p> }</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><<a href="mailto:Susanne.Schmalkalt@gmx.de">Susanne.Schmalkalt@gmx.de</a>> 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>