[Insight-users] How get vertex in stl file

shi yuan shiyuan001 at hotmail.com
Thu Jun 7 00:02:28 EDT 2007


Hi All,
In my program, I want to import a STL format file and get the vertex in the 
file, but I cannot get it correctly, I don’t know how to solve it, code 
segment as follows:
=====================================================================
//Create the reader and read a data file
vtkSmartPointer<vtkSTLReader> sr = vtkSmartPointer<vtkSTLReader>::New();
sr->SetFileName(strModelPath);
sr->Update();
	
vtkSmartPointer<vtkPolyData> stlPolyData = 
vtkSmartPointer<vtkPolyData>::New();
stlPolyData = sr->GetOutput();
stlPolyData->Update();
	
vtkSmartPointer<vtkCellArray> stlCellArray = 
vtkSmartPointer<vtkCellArray>::New();
stlCellArray = stlPolyData->GetPolys();
	
//Obtaining number of all cells (triangular facets)
int nCellsNum;
nCellsNum = stlCellArray->GetNumberOfCells();
	
//Definting pointer which is points to vertex in the cell
double* dpPointA;
double* dpPointB;
double* dpPointC;
	
for (int nCellID = 0; nCellID < nCellsNum; nCellID++) 
{
   vtkCell* cell;
   cell = stlPolyData->GetCell(nCellID);
		
   vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New();
   Points = cell->GetPoints();
		
   vtkSmartPointer<vtkIdList> PointsIDList = 
vtkSmartPointer<vtkPoints>::New();
   stlPolyData->GetCellPoints(nCellID,PointsIDList);
		
   int a = 0;
   int b = 0;
   int c = 0;
		
   a = PointsIDList->GetId(0);
   b = PointsIDList->GetId(1);
   c = PointsIDList->GetId(2);

   dpPointA = Points->GetPoint(a);
   dpPointB = Points->GetPoint(b);
   dpPointC = Points->GetPoint(c);
}
===================================================================
I find dpPointA , dpPointB and dpPointC has the same value, Why?

Thanks in advance for any help.

Regards,
Yuan SHI

_________________________________________________________________
免费下载 MSN Explorer:   http://explorer.msn.com/lccn  



More information about the Insight-users mailing list