# eryar

posts - 348, comments - 537, trackbacks - 0, articles - 0

Abstract. The TopLoc package of OpenCASCADE gives resources to handle 3D local coordinate systems called Locations. A Location is a composition of elementary coordinate systems, each one is called a Datum. The Location keeps track of this composition. The paper will use the Draw Test Harness to illustrate the Location concept.

Key Words. Transformation, Location, Local Coordinate Systems

1.Introduction

2.Draw Test

box b 10 20 30
vdisplay b
vtrihedron vt
dump b

Figure 2.1 Box Location in Original

# translate by x direction
ttranslate b 10 0 0
vdisplay b
dump b

Figure 2.2 Location of the translation box

# translate by x direction
ttranslate b 10 0 0
vdisplay b
dump b

Figure 2.3 Translate Box in X Direction

# rotate by y axis
trotate b 0 0 0 0 1 0 45
vdisplay b
dump b

Figure 2.4 Rotate the Box

#
# test TopoDS_Shape location.
# Shing Liu(eryar@163.com)
# 2016-09-06 22:50

# initialize
box b 10 20 30
vdisplay b
vtrihedron vt
dump b

# translate by x direction
ttranslate b 10 0 0
vdisplay b
dump b

# translate by x direction
ttranslate b 10 0 0
vdisplay b
dump b

# rotate by y axis
trotate b 0 0 0 0 1 0 45
vdisplay b
dump b

3.Draw Code

//=======================================================================
// transform
//=======================================================================

static Standard_Integer transform(Draw_Interpretor& ,Standard_Integer n,const char** a)
{
if (n <= 1) return 1;

gp_Trsf T;
Standard_Integer last = n;
const char* aName = a[0];

Standard_Boolean isBasic = Standard_False;

if (!strcmp(aName,"reset")) {
}
else {
isBasic = (aName[0] == 'b');
aName++;

if (!strcmp(aName,"move")) {
if (n < 3) return 1;
TopoDS_Shape SL = DBRep::Get(a[n-1]);
if (SL.IsNull()) return 0;
T = SL.Location().Transformation();
last = n-1;
}
else if (!strcmp(aName,"translate")) {
if (n < 5) return 1;
T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])));
last = n-3;
}
else if (!strcmp(aName,"rotate")) {
if (n < 9) return 1;
T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])),
gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))),
Draw::Atof(a[n-1])* (M_PI / 180.0));
last = n-7;
}
else if (!strcmp(aName,"mirror")) {
if (n < 8) return 1;
T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])),
gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))));
last = n-6;
}
else if (!strcmp(aName,"scale")) {
if (n < 6) return 1;
T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1]));
last = n-4;
}
}

if (T.Form() == gp_Identity || isBasic) {
TopLoc_Location L(T);
for (Standard_Integer i = 1; i < last; i++) {
TopoDS_Shape S = DBRep::Get(a[i]);
if (S.IsNull())
{
std::cerr << "Error: " << a[i] << " is not a valid shape\n";
return 1;
}
else
DBRep::Set(a[i],S.Located(L));
}
}
else {
BRepBuilderAPI_Transform trf(T);
for (Standard_Integer i = 1; i < last; i++) {
TopoDS_Shape S = DBRep::Get(a[i]);
if (S.IsNull()) {
std::cerr << "Error: " << a[i] << " is not a valid shape\n";
return 1;
}
else {
trf.Perform(S);
if (!trf.IsDone())
return 1;
DBRep::Set(a[i],trf.Shape());
}
}
}
return 0;
}

4.Conclusion

5.References

1.Fletcher Dunn, Ian Parberry. 3D Math Primer for Graphics and Game Development. 清华大学出版社. 2005

2.OpenCASCADE Draw Test Harness User Guide.