[vtkusers] Anyone knows the 'off' file format?

Tim Hutton T.Hutton at eastman.ucl.ac.uk
Wed Feb 18 06:58:44 EST 2004


Hi Pingkun,

I use the following code to read OFF files. I'm not sure it copes with 
everything possible in the OFF format. I could very easily make this into a 
vtkOFFReader if there was much desire in the community.

Tim.


FILE *in = fopen(filename,"r");
if(!in) return FALSE;

int n_pts,n_polys;
fscanf(in,"OFF\n%d %d 0\n",&n_pts,&n_polys);

vtkPolyData *poly = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
vtkCellArray *polys = vtkCellArray::New();
// read the points from the file
float p[3];
int i,j;
for(i=0;i<n_pts;i++)
{
    fscanf(in,"%f %f %f\n",&p[0],&p[1],&p[2]);
    points->InsertPoint(i,p);
}
for(i=0;i<n_polys;i++)
{
    vtkIdType n_vertices;
    fscanf(in,"%d ",&n_vertices);
    polys->InsertNextCell(n_vertices);
    vtkIdType vertex_id;
    for(j=0;j<n_vertices;j++)
    {
       fscanf(in,"%d ",&vertex_id);
       polys->InsertCellPoint(vertex_id);
    }
}
poly->SetPoints(points);
points->Delete();
poly->SetPolys(polys);
polys->Delete();

mapper->SetInput(poly);
poly->Delete();

etc..


At 19:43 18/02/2004 +0800, Yan Pingkun wrote:

>Hi,
>
>Has anyone experienced the 'off' file format? The file stores 3D points 
>and geometry for an object. I got an illustration file for it. But I still 
>can't figure out what are the data after reading it. Also, how to 
>visualize the data with vtk?
>
>Thanks!
>
>Regards,
>Pingkun

---------------------------------------------------------------------------
Tim Hutton,                           http://www.eastman.ucl.ac.uk/~thutton
Research Fellow & PhD student,                   T.Hutton at eastman.ucl.ac.uk
MINORI Project, Biomedical Informatics Unit,
Eastman Dental Institute, UCL,                   Tel: [+44] (0)20 7915 2344
256 Gray's Inn Road, London WC1X 8LD, UK         Fax: on request
---------------------------------------------------------------------------
This email represents the views of the sender alone and must not be 
construed as representing the views of the Eastman Dental Institute. It may 
contain confidential information and may be protected by law as a legally 
privileged document and copyright work. Its content should not be disclosed 
and it should not be given or copied to anyone other than the person(s) 
named or referenced above. If you have received this email in error, please 
contact the sender.





More information about the vtkusers mailing list