help with odgiworldgeometrydumper:

line
help with odgiworldgeometrydumper:

line
i'm hoping someone can point out what i am missing in my implementation. the attached dwg file has two line in it, which when drawn in autocad and in the sample viewer provided with the dwgdirect libraries draw correctly, yet in my application one of the lines is in the wrong location. when i look at the vertices for each line, they are all positive in both the x and y position. when i walk through the pline method one line has all the x's negated. the only difference i can tell from looking in autocad is that one line has a positive elevation, and the one drawing in the wrong location has a negative elevation. i've stripped this method down to the bare essentials and am just printing points.
code:
void odgiworldgeometrydumper:

line(const odgipolyline& lwbuf, oduint32 fromindex, oduint32 numsegs)
{
printf("odgiworldgeometrydumper:

line(const odgipolyline& lwbuf, oduint32 fromindex, oduint32 numsegs)\n");
odgepoint3d tranpoint3d;
for (unsigned int i = 0; i < lwbuf.numverts(); i++) {
double bulge = lwbuf.getbulgeat(i);
if (bulge != 0.0) {
// <snip code to handle bulges>
}
else {
odgepoint2d pt;
lwbuf.getpointat(i, pt);
if (!transformationmatrices.empty()) {
const odgematrix3d &tranmatrix = this->transformationmatrices.top();
tranpoint3d.x = pt.x;
tranpoint3d.y = pt.y;
tranpoint3d.z = 0;
tranpoint3d.transformby(tranmatrix);
fprintf(f,"transforming point (%f,%f) to (%f,%f)\n",pt.x,pt.y,tranpoint3d.x,tranpoint3d.x);
}
else {
printf("no transform: (%f,%f)\n",pt.x,pt.y);
}
}
}
// handle case of lwbuf.isclosed() == true here....
}
when walking through with the debugger, neither line has a transformation matrix available.
nether line
a sample of the outout i get is:
odgiworldgeometrydumper:line(const odgipolyline& lwbuf, oduint32 fromindex, oduint32 numsegs)
no transform: (5151.730000,6974.130000)
no transform: (5151.344926,6973.008073)
no transform: (5151.136486,6972.637777)
no transform: (5150.145891,6971.881780)
<snip rest of points....they all look good>
odgiworldgeometrydumper:line(const odgipolyline& lwbuf, oduint32 fromindex, oduint32 numsegs)
no transform: (-5152.180000,7071.630000)
no transform: (-5151.856777,7071.135259)
no transform: (-5149.646174,7067.999632)
no transform: (-5149.480483,7067.894589)
thanks for any help you can provide.
steve
attached files
both odgipolyline and oddbpolyline have methods returning 2d and 3d geometry (point, line segment, arc segment).
3d methods return geometry in world coordinate system (wcs). 2d methods return geometry in object coordinate system (ocs).
ocs is defined by polyline's normal. and elevation z in ocs.
to get transformation matrices between ocs and wcs you can use odgematrix3d:lanetoworld(normal) and odgematrix3d::worldtoplane(normal).
or you can use 3d methods but this is less efficient. coordinates are stored in ocs and transformation matrix will be calculated each time you call getpointat(n, odgepoint3d&).
sergey slezkin
is doing the following valid? it works in this particular case, but i just want to verify that i won't be messing something else up.
at the start of the method, i added:
code:
if (lwbuf.elevation() != 0) {
this->pushmodeltransform(odgematrix3d::worldtoplane(lwbuf.normal()));
}
then at the end:
code:
if (lwbuf.elevation() != 0) {
this->popmodeltransform();
}
thanks,
steve
this is incorrect. for example if polyline's plane contains wcs point (0,0,0) elevation will be zero.
ocs plane differs from xy plane if normal is not equal to z axis. and elevation is distance from from (0,0,0) to ocs plane.
so you need to push transform is normal is not equal to (0,0,1). and make 3d point from 2d one using elevation as z coordinate.
sergey slezkin