Thursday, February 10, 2011

NaroCAD shape locations on scene

Lately we had a lot of problems at tools like Trim and Mirror caused by the way we generate shapes vs the way Opencascade generates shapes:
- when building a line let's say as example the (10, 10, 0) to (20, 20, 0) line we generate internally the (0, 0, 0) to (10, 10, 0) line and hold on some transformation interpreter the transformations applied on the shape, in our case a translation to (10, 10, 0). In this way we can expose to the user on the property grid the shape transformations and allow user to change them. A simulated shape in Draw Test Harness is like the following:

vertex v1 0 0 0
vertex v2 10 10 0
edge e1 v1 v2
ttranslate e1 10 10 0
dump e1

The dump result is:

Dump of 1 Curves
-------
1 : Line
Origin :0, 0, 0
Axis :0.707106781186547, 0.707106781186547, 0
Dump of 1 Locations
-------
1 :
Elementary location
( 1 0 0 10 )
( 0 1 0 10 )
( 0 0 1 0 )

The shape geometry is generated on (0, 0, 0) and holds the shape transformation on Location.

- When applying Opencascade algorithms like Trim or Mirror on our geometry like the one described above the result is a shape with Geometry generated in (10, 10, 0) and Location to (0, 0, 0). This creates us a lot of problems because we don't know where geometry is located, we don't have access to transformations, we have problems when a shape generated like this is passed to an algorithm together with a shape generated like in the case below. A Draw Test Harness sample of this type of shape:

vertex v1 10 10 0
vertex v1 20 20 0
edge e1 v1 v2
dump e1

The dump result:

Dump of 1 Curves
-------

1 : Line
Origin :20, 20, 0
Axis :-0.707106781186547, -0.707106781186547, 0

-------
Dump of 0 Locations
-------

The solution:

We decided to use everywhere only shapes located on (0, 0, 0) and hold transformations on our internal interpreter. That assumes an extra step on our side to prepare geometry before using OCC API: we have to save current transformations, translate all shapes involved towards origin, apply the API, translate the result at the saved transformations by applying the transformations on the interpreter.

Modified the Pipe and Trim tool to work like this and it seems to work well even on shapes that have rotations applied on them. If testing passes successfully we'll start modifying tools like mirror, extrude, cut to use this approach.

No comments: