[vtkusers] vtkPolyData::GetPointCells segmentation fault
Miguel Sotaquirá
msotaquira at gmail.com
Sun Jul 10 22:15:23 EDT 2011
Hi!
I'm trying to build the 1-ring neighborhood of each point on a mesh by using
a modified version of the VertexConnectivity example
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity),
actually is the same version, the only thing I've changed is the source
(instead of a "SphereSource" I'm using a vtkXMLPolyDataReader). See the my
code below...
My mesh has 40938 points, and the code behaves well until it arrives to the
point 38454. At this point I always get a run-time error "Segmentation
fault". I've managed to isolate the problem and I'm pretty sure it happens
when calling the function:
mesh->GetPointCells(id, cellIdList),
where "id" is, in my case, 38454...
I've also tried with other meshes (with different number of points) and I
ALWAYS get the same "Segmentation Fault" error... The strangest thing is
that when implementing the original example (using the sphere) I do not get
any errors at all!
Am I doing something wrong? There might be a problem with my meshes? It
might be a bug in vtkPolyData::GetPointCells()???
Heres the code:
vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkPolyData>
mesh, int id);
int main(int, char* argv[])
{
// vtkSmartPointer<vtkSphereSource> sphereSource =
// vtkSmartPointer<vtkSphereSource>::New();
// sphereSource->Update();
vtkSmartPointer<vtkXMLPolyDataReader> sphereSource =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
sphereSource->SetFileName(argv[1]);
sphereSource->Update();
vtkSmartPointer<vtkTriangleFilter> triangleFilter =
vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputConnection(sphereSource->GetOutputPort());
triangleFilter->Update();
vtkSmartPointer<vtkExtractEdges> extractEdges =
vtkSmartPointer<vtkExtractEdges>::New();
extractEdges->SetInputConnection(triangleFilter->GetOutputPort());
extractEdges->Update();
vtkSmartPointer<vtkPolyData> mesh = extractEdges->GetOutput();
vtkSmartPointer<vtkIdList> connectedVertices = GetConnectedVertices(mesh,
38455);
vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
std::cout << "Connected vertices: ";
for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); i++)
{
std::cout << connectedVertices->GetId(i) << " ";
ids->InsertNextValue(connectedVertices->GetId(i));
}
std::cout << std::endl;
vtkSmartPointer<vtkDataSetMapper> connectedVertexMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
{
vtkSmartPointer<vtkSelectionNode> selectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::POINT);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractSelection =
vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInput(0, extractEdges->GetOutput());
extractSelection->SetInput(1, selection);
extractSelection->Update();
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
glyphFilter->Update();
connectedVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
}
vtkSmartPointer<vtkActor> connectedVertexActor =
vtkSmartPointer<vtkActor>::New();
connectedVertexActor->SetMapper(connectedVertexMapper);
connectedVertexActor->GetProperty()->SetColor(1,0,0);
connectedVertexActor->GetProperty()->SetPointSize(5);
vtkSmartPointer<vtkDataSetMapper> queryVertexMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
{
vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
ids->SetNumberOfComponents(1);
ids->InsertNextValue(0);
vtkSmartPointer<vtkSelectionNode> selectionNode =
vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::POINT);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(ids);
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractSelection =
vtkSmartPointer<vtkExtractSelection>::New();
extractSelection->SetInput(0, extractEdges->GetOutput());
extractSelection->SetInput(1, selection);
extractSelection->Update();
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(extractSelection->GetOutputPort());
glyphFilter->Update();
queryVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());
}
vtkSmartPointer<vtkActor> queryVertexActor =
vtkSmartPointer<vtkActor>::New();
queryVertexActor->SetMapper(queryVertexMapper);
queryVertexActor->GetProperty()->SetColor(0,1,0);
queryVertexActor->GetProperty()->SetPointSize(5);
vtkSmartPointer<vtkDataSetMapper> sphereMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
sphereMapper->SetInputConnection(extractEdges->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
//Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//Add the actors to the scene
renderer->AddActor(sphereActor);
renderer->AddActor(queryVertexActor);
renderer->AddActor(connectedVertexActor);
renderer->SetBackground(.3, .2, .1); // Background color dark red
//Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkPolyData>
mesh, int id)
{
vtkSmartPointer<vtkIdList> connectedVertices =
vtkSmartPointer<vtkIdList>::New();
//get all cells that vertex 'id' is a part of
vtkSmartPointer<vtkIdList> cellIdList =
vtkSmartPointer<vtkIdList>::New();
mesh->GetPointCells(id, cellIdList);
/*
cout << "Vertex 0 is used in cells ";
for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++)
{
cout << cellIdList->GetId(i) << ", ";
}
cout << endl;
*/
for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++)
{
//cout << "id " << i << " : " << cellIdList->GetId(i) << endl;
vtkSmartPointer<vtkIdList> pointIdList =
vtkSmartPointer<vtkIdList>::New();
mesh->GetCellPoints(cellIdList->GetId(i), pointIdList);
//cout << "End points are " << pointIdList->GetId(0) << " and " <<
pointIdList->GetId(1) << endl;
if(pointIdList->GetId(0) != id)
{
//cout << "Connected to " << pointIdList->GetId(0) << endl;
connectedVertices->InsertNextId(pointIdList->GetId(0));
}
else
{
//cout << "Connected to " << pointIdList->GetId(1) << endl;
connectedVertices->InsertNextId(pointIdList->GetId(1));
}
}
return connectedVertices;
}
Thanks!
Miguel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110711/96b01e3a/attachment.htm>
More information about the vtkusers
mailing list