[vtkusers] how to get vertex coordinates in stl file

付文宇 fuwenyu at emails.bjut.edu.cn
Sun Jun 17 10:25:07 EDT 2007


Hi everyone:
   I have a stl file and  I want to  get the coordinates of every vertex  in 
 the file. I only can get one point coordinate of one triangle facet, and I 
can not get the other two points coordinates. I don¡¯t know how to solve it. 
 code segment as follows:
 =====================================================================
 //Create the reader and read a data file
 int main()
{
vtkSTLReader *fran=vtkSTLReader::New();
	fran->SetFileName("D:\\paper of qiao\\aneurysm1.stl");
	fran->Update();

vtkPolyData *stlPolyData =vtkPolyData::New(); 
	stlPolyData = fran->GetOutput(); 
	stlPolyData->Update();
//int numofpoints=stlPolyData->GetNumberOfVerts();
vtkCellArray *stlCellArray =vtkCellArray::New();
	stlCellArray = stlPolyData->GetPolys(); 
//Obtaining number of all cells (triangular facets) 
int nCellsNum; 
	nCellsNum = stlCellArray->GetNumberOfCells(); 
        
//Definting pointer which  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); 
                
   vtkPoints *Points = vtkPoints::New(); 
	  Points = cell->GetPoints(); 
                
   vtkIdList *PointsIDList =vtkIdList::New(); 
//	  stlPolyData->GetCellPoints(nCellID,PointsIDList); 
      PointsIDList=cell->GetPointIds();             
   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); 
   double x1,y1,z1,x2,y2,z2,x3,y3,z3;
   x1=dpPointA[0];
   y1=dpPointA[1];
   z1=dpPointA[2];
   x2=dpPointB[0];
   y2=dpPointB[1];
   z2=dpPointB[2];
   x3=dpPointC[0];
   y3=dpPointC[1];
   z3=dpPointC[2];
} 
 ===================================================================
 I find dpPointA , dpPointB and dpPointC point to the same address, so
I only get one point coordinate of one triangle facet ,Why?
 
 Thanks in advance for any help.
 
 Fu Wenyu 
2007.06.17





More information about the vtkusers mailing list