[vtkusers] vtkObjReader doesn't support obj. files

Tim Hutton tim.hutton at gmail.com
Mon Feb 4 11:07:48 EST 2008


On Feb 1, 2008 11:31 PM, Iryna Pavlyshak <iryna at andrew.cmu.edu> wrote:
> > I rewrote the OBJ reader, so I'm probably to blame. Take a look at
> > vtkOBJReader.cxx to see the parts of the OBJ format it supports.
>   Where can I download you Reader? I found only vtkOBJReader in repository (http://www.itk.org/cgi-bin/viewcvs.cgi/IO/), but it is the same as I have.
>
> > One thing I notice is that your file doesn't have any vn lines (unless
> > you've skipped them), so referencing them in the faces will cause a
> > problem. If each line was as e.g. f 9 10 198 then it would be a valid OBJ
> > file.
>
>   NO,  i didn't skip anything, I included all different lines in my .obj file. A double slash in a face line 145703//145703 shows that the number is omitted.It must be vertex normal.
> Can VTK cope with the following situation?

Please take a look at the vtkOBJReader.cxx file:
http://www.itk.org/cgi-bin/viewcvs.cgi/IO/vtkOBJReader.cxx?view=markup

It contains the following section:
/*--------------------------------------------------------

This is only partial support for the OBJ format, which is
quite complicated. To find a full specification,
search the net for "OBJ format", eg.:

http://netghost.narod.ru/gff/graphics/summary/waveobj.htm

We support the following types:

v <x> <y> <z>              vertex

vn <x> <y> <z>             vertex normal

vt <x> <y>                 texture coordinate

f <v_a> <v_b> <v_c> ...

polygonal face linking vertices v_a, v_b, v_c, etc. which
are 1-based indices into the vertex list

f <v_a>/<t_a> <v_b>/<t_b> ...

polygonal face as above, but with texture coordinates for
each vertex. t_a etc. are 1-based indices into the texture
coordinates list (from the vt lines)

f <v_a>/<t_a>/<n_a> <v_b>/<t_b>/<n_b> ...

polygonal face as above, with a normal at each vertex, as a
1-based index into the normals list (from the vn lines)

f <v_a>//<n_a> <v_b>//<n_b> ...

polygonal face as above but without texture coordinates.

Per-face tcoords and normals are supported by duplicating
the vertices on each face as necessary.

---------------------------------------------------------*/

See also: http://people.scs.fsu.edu/~burkardt/txt/obj_format.txt

You can see that your file is not legal, since it refers to vertex
normals that don't exist.

As a workaround, try:

obj_reader->Update();
obj_reader->GetOutput()->GetPointData()->SetNormals(NULL);

after reading the file, before rendering it or doing anything else with it.

By the way, 'g' lines and other OBJ things are ignored, so shouldn't
be a problem.

Tim

> After rendering, I am going to do further processing of this data.
>
>
> > The fact that other readers support this file is not so surprising - the
> > OBJ format is remarkably complicated and often abused. (And often cannot
> > be read straight into VTK since it supports per-face normals and tcoords
> > and VTK doesn't - vtkOBJReader duplicates vertices as necessary for this.)
> When opening in Maya, the following massage appeared:
> Your obj file contains faces shared by multiple groups.
> Single mesh will be created.
> In the Output window it is written:
> Wrong vertex normal index 9 in OBJ file line 145720
>
> I must add, that my obj. file is accompanied by mtl. file,  and .obj.color which is responsible for color.
>
> I just started working with obj. data, so this stuff is quite confusing for me.
>
> I am attaching a zip file, which consists of the data I was talking about.
>
>
> If you have time,  please have a look at it.
>
> thanks,
> Iryna
>
>
>
> >
> > Tim
> >
> > On 30/01/2008, Iryna Pavlyshak <iryna at andrew.cmu.edu> wrote:
> >> Hello all,
> >>
> >> I use vtkObjReader for opening and rendering the .obj file, which
> >> represents set of Vertices and Polygons. My code can open without
> >> problems 3DMax  obj.,  Poser obj. and so on. But when opening wanted
> >> obj. file, which is represented as: # File Generated By Veridian
> >> write_wave v 1.1 # 145711 Vertices, 283595 Polygons
> >>
> >> mtllib csr0125a.mtl
> >>
> >> g csr0125a.obj vertices v 626.4 -62.8 -1000.0 1 1 3 v 627.0 -59.0 -1000.0
> >> 1 1 3 ........ v 72.6 41.9 626.0 12 5 1 g csr0125a.obj faces usemtl m1 f
> >> 9//9 10//10 198//198 f 199//199 198//198 10//10 .................... f
> >> 145703//145703 145704//145704 145708//145708
> >>
> >> the following massage appears: Unhanded exception at ..:Access violation
> >> reading location... So the problem is with the pointer...and as it
> >> follows with normals.
> >>
> >> The file is not impossible for opening. I tried others software and
> >> they open this obj. file.
> >>
> >> Maybe somebody has already been faced with similar problem.. There is a
> >> possibility that somebody rewritten vtkObjReader. It would be great.
> >>
> >> waiting for any tips, Iryna
> >>
> >> _______________________________________________ This is the private VTK
> >> discussion list. Please keep messages on-topic. Check the FAQ at:
> >> http://www.vtk.org/Wiki/VTK_FAQ Follow this link to
> >> subscribe/unsubscribe: http://www.vtk.org/mailman/listinfo/vtkusers
> >>
> >
> >
> > -- Tim Hutton - http://www.sq3.org.uk
> >
> > Take the Organic Builder challenge -
> > http://www.sq3.org.uk/Evolution/Squirm3/OrganicBuilder/
> >
> >



-- 
Tim Hutton - http://www.sq3.org.uk

Take the Organic Builder challenge -
http://www.sq3.org.uk/Evolution/Squirm3/OrganicBuilder/



More information about the vtkusers mailing list