Hi!<div><br></div><div>I'm trying to build the 1-ring neighborhood of each point on a mesh by using a modified version of the VertexConnectivity example <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/VertexConnectivity</a>), 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...</div>
<div><br></div><div>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:</div>
<div><br></div><div>mesh->GetPointCells(id, cellIdList), </div><div><br></div><div>where "id" is, in my case, 38454... </div><div><br></div><div>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!</div>
<div><br></div><div>Am I doing something wrong? There might be a problem with my meshes? It might be a bug in vtkPolyData::GetPointCells()???</div><div><br></div><div>Heres the code:</div><div><br></div><div><div>vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkPolyData> mesh, int id);</div>
<div> </div><div>int main(int, char* argv[])</div><div>{</div><div> // vtkSmartPointer<vtkSphereSource> sphereSource =</div><div> // vtkSmartPointer<vtkSphereSource>::New();</div><div> // sphereSource->Update();</div>
<div> vtkSmartPointer<vtkXMLPolyDataReader> sphereSource = <span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkXMLPolyDataReader>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>sphereSource->SetFileName(argv[1]);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>sphereSource->Update();</div><div> </div><div>
vtkSmartPointer<vtkTriangleFilter> triangleFilter =</div><div> vtkSmartPointer<vtkTriangleFilter>::New();</div><div> triangleFilter->SetInputConnection(sphereSource->GetOutputPort());</div><div> triangleFilter->Update();</div>
<div> </div><div> vtkSmartPointer<vtkExtractEdges> extractEdges =</div><div> vtkSmartPointer<vtkExtractEdges>::New();</div><div> extractEdges->SetInputConnection(triangleFilter->GetOutputPort());</div>
<div> extractEdges->Update();</div><div> </div><div> vtkSmartPointer<vtkPolyData> mesh = extractEdges->GetOutput();</div><div><br></div><div> vtkSmartPointer<vtkIdList> connectedVertices = GetConnectedVertices(mesh, 38455);</div>
<div> </div><div> vtkSmartPointer<vtkIdTypeArray> ids =</div><div> vtkSmartPointer<vtkIdTypeArray>::New();</div><div> ids->SetNumberOfComponents(1);</div><div> </div><div> std::cout << "Connected vertices: ";</div>
<div> for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); i++)</div><div> {</div><div> std::cout << connectedVertices->GetId(i) << " ";</div><div> ids->InsertNextValue(connectedVertices->GetId(i));</div>
<div> }</div><div> std::cout << std::endl;</div><div> </div><div> vtkSmartPointer<vtkDataSetMapper> connectedVertexMapper =</div><div> vtkSmartPointer<vtkDataSetMapper>::New();</div><div> </div><div>
{</div><div> vtkSmartPointer<vtkSelectionNode> selectionNode =</div><div> vtkSmartPointer<vtkSelectionNode>::New();</div><div> selectionNode->SetFieldType(vtkSelectionNode::POINT);</div><div> selectionNode->SetContentType(vtkSelectionNode::INDICES);</div>
<div> selectionNode->SetSelectionList(ids);</div><div> </div><div> vtkSmartPointer<vtkSelection> selection =</div><div> vtkSmartPointer<vtkSelection>::New();</div><div> selection->AddNode(selectionNode);</div>
<div> </div><div> vtkSmartPointer<vtkExtractSelection> extractSelection =</div><div> vtkSmartPointer<vtkExtractSelection>::New();</div><div> </div><div> extractSelection->SetInput(0, extractEdges->GetOutput());</div>
<div> extractSelection->SetInput(1, selection);</div><div> extractSelection->Update();</div><div> </div><div> vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =</div><div> vtkSmartPointer<vtkVertexGlyphFilter>::New();</div>
<div> glyphFilter->SetInputConnection(extractSelection->GetOutputPort());</div><div> glyphFilter->Update();</div><div> </div><div> connectedVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());</div>
<div> }</div><div> </div><div> vtkSmartPointer<vtkActor> connectedVertexActor =</div><div> vtkSmartPointer<vtkActor>::New();</div><div> connectedVertexActor->SetMapper(connectedVertexMapper);</div><div>
connectedVertexActor->GetProperty()->SetColor(1,0,0);</div><div> connectedVertexActor->GetProperty()->SetPointSize(5);</div><div> </div><div> vtkSmartPointer<vtkDataSetMapper> queryVertexMapper =</div>
<div> vtkSmartPointer<vtkDataSetMapper>::New();</div><div> </div><div> {</div><div> vtkSmartPointer<vtkIdTypeArray> ids =</div><div> vtkSmartPointer<vtkIdTypeArray>::New();</div><div> ids->SetNumberOfComponents(1);</div>
<div> ids->InsertNextValue(0);</div><div> </div><div> vtkSmartPointer<vtkSelectionNode> selectionNode =</div><div> vtkSmartPointer<vtkSelectionNode>::New();</div><div> selectionNode->SetFieldType(vtkSelectionNode::POINT);</div>
<div> selectionNode->SetContentType(vtkSelectionNode::INDICES);</div><div> selectionNode->SetSelectionList(ids);</div><div> </div><div> vtkSmartPointer<vtkSelection> selection =</div><div> vtkSmartPointer<vtkSelection>::New();</div>
<div> selection->AddNode(selectionNode);</div><div> </div><div> vtkSmartPointer<vtkExtractSelection> extractSelection =</div><div> vtkSmartPointer<vtkExtractSelection>::New();</div><div> </div>
<div> extractSelection->SetInput(0, extractEdges->GetOutput());</div><div> extractSelection->SetInput(1, selection);</div><div> extractSelection->Update();</div><div> </div><div> vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =</div>
<div> vtkSmartPointer<vtkVertexGlyphFilter>::New();</div><div> glyphFilter->SetInputConnection(extractSelection->GetOutputPort());</div><div> glyphFilter->Update();</div><div> </div><div> queryVertexMapper->SetInputConnection(glyphFilter->GetOutputPort());</div>
<div> }</div><div> </div><div> vtkSmartPointer<vtkActor> queryVertexActor =</div><div> vtkSmartPointer<vtkActor>::New();</div><div> queryVertexActor->SetMapper(queryVertexMapper);</div><div> queryVertexActor->GetProperty()->SetColor(0,1,0);</div>
<div> queryVertexActor->GetProperty()->SetPointSize(5);</div><div> </div><div> vtkSmartPointer<vtkDataSetMapper> sphereMapper =</div><div> vtkSmartPointer<vtkDataSetMapper>::New();</div><div> sphereMapper->SetInputConnection(extractEdges->GetOutputPort());</div>
<div> vtkSmartPointer<vtkActor> sphereActor =</div><div> vtkSmartPointer<vtkActor>::New();</div><div> sphereActor->SetMapper(sphereMapper);</div><div> </div><div> //Create a renderer, render window, and interactor</div>
<div> vtkSmartPointer<vtkRenderer> renderer =</div><div> vtkSmartPointer<vtkRenderer>::New();</div><div> vtkSmartPointer<vtkRenderWindow> renderWindow =</div><div> vtkSmartPointer<vtkRenderWindow>::New();</div>
<div> renderWindow->AddRenderer(renderer);</div><div> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =</div><div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div> renderWindowInteractor->SetRenderWindow(renderWindow);</div>
<div> </div><div> //Add the actors to the scene</div><div> renderer->AddActor(sphereActor);</div><div> renderer->AddActor(queryVertexActor);</div><div> renderer->AddActor(connectedVertexActor);</div><div> renderer->SetBackground(.3, .2, .1); // Background color dark red</div>
<div> </div><div> //Render and interact</div><div> renderWindow->Render();</div><div> renderWindowInteractor->Start();</div><div> </div><div> return EXIT_SUCCESS;</div><div>}</div><div> </div><div>vtkSmartPointer<vtkIdList> GetConnectedVertices(vtkSmartPointer<vtkPolyData> mesh, int id)</div>
<div>{</div><div> vtkSmartPointer<vtkIdList> connectedVertices =</div><div> vtkSmartPointer<vtkIdList>::New();</div><div> </div><div> //get all cells that vertex 'id' is a part of</div><div> vtkSmartPointer<vtkIdList> cellIdList =</div>
<div> vtkSmartPointer<vtkIdList>::New();</div><div> mesh->GetPointCells(id, cellIdList);</div><div> </div><div> /*</div><div> cout << "Vertex 0 is used in cells ";</div><div> for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++)</div>
<div> {</div><div> cout << cellIdList->GetId(i) << ", ";</div><div> }</div><div> cout << endl;</div><div> */</div><div> </div><div> for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++)</div>
<div> {</div><div> //cout << "id " << i << " : " << cellIdList->GetId(i) << endl;</div><div> </div><div> vtkSmartPointer<vtkIdList> pointIdList =</div><div>
vtkSmartPointer<vtkIdList>::New();</div><div> mesh->GetCellPoints(cellIdList->GetId(i), pointIdList);</div><div> </div><div> //cout << "End points are " << pointIdList->GetId(0) << " and " << pointIdList->GetId(1) << endl;</div>
<div> </div><div> if(pointIdList->GetId(0) != id)</div><div> {</div><div> //cout << "Connected to " << pointIdList->GetId(0) << endl;</div><div> connectedVertices->InsertNextId(pointIdList->GetId(0));</div>
<div> }</div><div> else</div><div> {</div><div> //cout << "Connected to " << pointIdList->GetId(1) << endl;</div><div> connectedVertices->InsertNextId(pointIdList->GetId(1));</div>
<div> }</div><div> }</div><div> </div><div> return connectedVertices;</div><div>}</div></div><div><br></div><div>Thanks!</div><div><br></div><div>Miguel</div><div><br></div><div><br></div>