[vtkusers] findclosestpoint

Susi Schmalkalt Susanne.Schmalkalt at gmx.de
Tue Nov 26 06:58:24 EST 2013


Dear David,
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. 
I get the error: Access violation reading location 0x0000004c. 
It seems as if the filter produces an empty output. I just can't see why.
Here is the code:
#define Instantiate(obj, class) vtkSmartPointer<class> obj = vtkSmartPointer<class>::New();

int main (int argc, char *argv[]) {

// Read .mhd file

Instantiate(fileReader, vtkMetaImageReader); 

 const char filename[] = "./ID_1.mhd";

fileReader->SetFileName(filename);

fileReader->Update();

// Visualization 

Instantiate(imageData, vtkImageData); 

imageData = fileReader->GetOutput();

// Build 3d Object

Instantiate(marchingCubes,vtkMarchingCubes ); 

marchingCubes->SetValue(0,1); 

marchingCubes->SetInput( imageData );

// Locator 

 Instantiate(pointLocator, vtkPointLocator); 

 pointLocator->SetDataSet(marchingCubes->GetOutput()); 

 pointLocator->BuildLocator();

// Mapper 

 Instantiate(imageDataMapper,vtkPolyDataMapper); 

imageDataMapper->ScalarVisibilityOff(); 

imageDataMapper->SetInput( marchingCubes->GetOutput() ); 

// Actor 

Instantiate(actorImageDataActor,vtkActor); 

actorImageDataActor->SetMapper( imageDataMapper );



double testPoint[3] = {100.0, 100.0, 100.0};

// Find the closest points to TestPoint 

vtkIdType iD = pointLocator->FindClosestPoint(testPoint); 

 std::cout << "The closest point is point " << iD << std::endl;

//Get the coordinates of the closest point 

 double closestPoint[3]; 

pointLocator->GetDataSet()->GetPoint(iD, closestPoint); 

std::cout << "Coordinates: " << closestPoint[0] << " " << closestPoint[1] << " " << closestPoint[2] << std::endl; 

// actor for closest point 

vtkSmartPointer<vtkActor> actCube3 = vtkSmartPointer<vtkActor>::New(); 

actCube3->SetMapper(mapCube);

actCube3->GetProperty()->SetColor(1, 0,0);  

actCube3->SetPosition(closestPoint[0],closestPoint[1],closestPoint[2]);

// Renderer 

 Instantiate(renderer, vtkRenderer); 

 renderer->AddActor(actorImageDataActor); 

 renderer->AddActor(actCube3); 

 renderer->SetBackground(.9, .5, .0); 

// RenderWindow

 Instantiate(renderWindow, vtkRenderWindow); 

 renderWindow->AddRenderer(renderer);

// Interactor 

 Instantiate(renderWindowInteractor, vtkRenderWindowInteractor); 

 renderWindowInteractor->SetRenderWindow(renderWindow); 

 renderWindowInteractor->Initialize(); 

 renderWindowInteractor->Start();

return EXIT_SUCCESS;

 }




Am 25.11.2013 um 13:54 schrieb David Doria:

> On Mon, Nov 25, 2013 at 7:09 AM, Susanne Schmalkalt
> <Susanne.Schmalkalt at gmx.de> wrote:
>> Dear all,
>> 
>> I have a metaobject, which I read with vtkMetaImageReader. I then use
>> vtkMarchingContourFilter to extract its surface. Then I have a point A close
>> to this surface. How can I find the closest point to A on the surface? When
>> I use vtkPointLocator and findClosestPoint, I get a point that lies on the
>> outline of my metaobject, but not on the object itself.
>> Does anyone have an idea why this might be and how to solve it?
>> 
>> Thanks!
>> Susi
> 
> Are you sure you're calling FindClosestPoint on a locator created with
> the output of the vtkMarchingContourFilter?
> 
> This example does what you're looking for (it should be the same once
> you have a vtkPolyData as the output of the vtkMarchingContourFilter):
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/CellLocator
> 
> David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131126/db04e591/attachment.htm>


More information about the vtkusers mailing list