Sunday, February 14, 2010

IGES import

A geometry kernel has got to have some way to import geometry. This gives the kernel a burst of much needed entropy when developing tests for different algorithms. Since the first working geometry algorithm in FreeREP will be the meshing utilities. It seemed only logical to start importing some models. I considered both STEP and IGES for the first model format. While STEP is much more modern and well thought out. It is sickeningly complicated. They have gone ahead and defined there own version of Backus-Naur form, called Express. Which they use to define the grammar for both Express, and the application protocols. Writing a parser generator for these would need to be done to get a standards compliant parser, and is probably the easiest way to do it. But I'm a little more interested in geometry, so lets flash back to the 1970's when programmers did some even more rediculous crap, but at least it doesn't require 50,000 lines of code to parse your first model.

You know its bad when the only people with a copy of specification refer to themselves as a preservation society. But it's even worse when the preservation society doesn't seem to have a copy of the previous 20 versions of the specification. Get all your IGES info at the archive http://www.iges5x.org/ There are some illusions to the state of the previous specifications in the current one. Fortunately that can all be ignored for now because the models I am using for testing are generated in Catia, which outputs IGES 5.3. So parsing this stuff is pretty easy if strange. It's 80 column formatted, for use with punch cards (don't fold spindle or mutilate), uses Holerith code strings, and has to use this weird line pointer system because double precision numbers don't tend to fit in fixed width fields very well. I guess you never have to worry about running out of memory as this all breaks when there are more than 49,999 entities.

So the first order of business was loading all the wires. Just a bunch of lines and arcs and all went pretty smoothly. Except with the peculiarity that Catia seems to export planar arcs using a transfomation matrix. They are always located at 0,0,0 with a start angle of 0. Then you have to tranaform them to where they go in world space. That needed to get implemented anyways, so no big deal. Then I moved on to turning the edges into faces. Needed some flashy math here, as IGES defines a plane as Ax+By+Cd=D, and FreeREP uses something like a Geom_Ax2, if you are familiar with opencascade. If not, it is a location, a norm, and a perpendicular vector to the norm which defines the x axis. This gives a better basis for rotations and such. As the cartesian plane doesn't really define a mapping, just what set is on the plane. That leaves us at the screen shot. You can see it is not rendering the cylindrical face yet, we will need surfaces of revolution for that. What it is doing, is loading the IGES file, meshing it, and drawing it to the screen, in a little less than 5ms.

No comments:

Post a Comment