[vtkusers] Question about outputting triangles
William Segars
wsegars1 at jhmi.edu
Fri Oct 24 11:50:53 EDT 2003
I would like to output triangles created for a model into a raw text file containing the vertices of each triangle. I tried using the following code I found on this list, but it didn't work. I got an error saying I accessed memory that wasn't there. I checked the output up until the error, and it looks like the order of the vertices is wrong (mismatched) anyway. Does anyone know what I'm doing wrong or have any suggestions. I appreciate any help you can give. Thanks!!!
/*Code trying to print out triangles*/
vtkPolyData *mypoly = skinMapper->GetInput();
vtkPoints *mypoints = mypoly->GetPoints();
vtkCellArray *mystrips = mypoly->GetStrips();
int *indices=mystrips->GetPointer();
int numindices=mystrips->GetNumberOfConnectivityEntries(); //Whoa!
int idx=0;
while (idx<numindices){
int striplen=indices[idx]; //Get length of next strip
idx++;
for (int jj=0;jj<striplen-2;jj++){
float A[3],B[3],C[3]; //coordinates of triangle vertices
mypoints->GetPoint(indices[idx],A);
mypoints->GetPoint(indices[idx+1],B);
mypoints->GetPoint(indices[idx+2],C);
cout <<"\n" << A[0] << " " << A[1] << " " << A[2] << " " << B[0] << " " << B[1] << " " << B[2] << " " << C[0] << " " << C[1] << " " << C[2];
idx++;
}
}
}
More information about the vtkusers
mailing list