[vtkusers] vtk get_cell_neighbors returns always null

azmagillian87 xrysafenia.malliastolidou at gmail.com
Sat Nov 30 08:22:03 EST 2013


Thanks for replying

that's my code
my obj file consists of 3 separate leaves , each leaf has many cells 

int main (int, char *[])
{
   


	vtkSmartPointer<vtkPlaneSource> planeSource =
	vtkSmartPointer<vtkPlaneSource>::New();
	planeSource->Update();

	std::string filename ;
	filename="D:\\leaves.obj";
	cout << filename;
	vtkSmartPointer<vtkOBJReader> reader =
	vtkSmartPointer<vtkOBJReader>::New();
	reader->SetFileName(filename.c_str());
	reader->Update();
  
		
	
	
	vtkSmartPointer<vtkPolyData> polydata=
		vtkSmartPointer<vtkPolyData> :: New();
	polydata=reader->GetOutput();
		
	
	

	cout << polydata->GetNumberOfPolys();
	vtkSmartPointer<vtkTriangleFilter> triangleFilter =
		vtkSmartPointer<vtkTriangleFilter>::New();
	triangleFilter->SetInputData(polydata);
	triangleFilter->Update();
    
	
	for(vtkIdType i = 0; i < triangleFilter->GetOutput()->GetNumberOfCells();
i++)
	{
		vtkSmartPointer<vtkIdList> cellPointIds =
			vtkSmartPointer<vtkIdList>::New();
		triangleFilter->GetOutput()->GetCellPoints(i, cellPointIds);
        int kl = cellPointIds->GetNumberOfIds();
		list<vtkIdType> neighbors;

		for(vtkIdType j = 0; j < cellPointIds->GetNumberOfIds(); j++)
		{
			vtkSmartPointer<vtkIdList> idList =
				vtkSmartPointer<vtkIdList>::New();

			//add one of the edge points
			idList->InsertNextId(cellPointIds->GetId(j));

			//add the other edge point
			if(j+1 == cellPointIds->GetNumberOfIds())
			{
				idList->InsertNextId(cellPointIds->GetId(0));
			}
			else
			{
				idList->InsertNextId(cellPointIds->GetId(j+1));
			}

			
			
			//get the neighbors of the cell
			vtkSmartPointer<vtkIdList> neighborCellIds =
				vtkSmartPointer<vtkIdList>::New();

			

			triangleFilter->GetOutput()->GetCellNeighbors(i, idList,
neighborCellIds);
            //cout <<  neighborCellIds->GetNumberOfIds()<< "\n";

			int l=idList->GetNumberOfIds();
			vtkIdType jsdhfg = neighborCellIds->GetNumberOfIds();
			for(vtkIdType k = 0; k < jsdhfg; k++)
			{
				neighbors.push_back(neighborCellIds->GetId(k));
				cout << neighborCellIds->GetId(k)<< " mplampla";
			}

		}

		cout << "Edge neighbor ids for "<< i<< "cell are: " << std::endl;
		
			for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
			{
				cout << " " << *it1;
			}
			cout << endl;
		vtkSmartPointer<vtkIdTypeArray> neighbors_ids =
					vtkSmartPointer<vtkIdTypeArray>::New();
		neighbors_ids->SetNumberOfComponents(1);
		for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
		{
		neighbors_ids->InsertNextValue(*it1);
		}
		 
	}
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtk-get-cell-neighbors-returns-always-null-tp5724696p5724737.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list