OpenCASCADE Shape Location

eryar@163.com

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

对于三维空间中的各种模型,总是想要摆放到合适的位置,最终形成一个工厂的模型,一艘船的模型,一个建筑物的模型,等等。目前来看,所有的几何相关的库对模型变换的实现一般都是使用了矩阵变换。有的可能只保留了最终变换的结果矩阵数据,而OpenCASCADE的TopoDS_Shape中保留了Location信息。从其文档可以看出,Location中保留了模型变换一系列的变换组合,并可以对这个变换进行Track追踪。如何来正确理解这个Location的意义呢?下面结合Draw Test Harness来进行说明。

2.Draw Test

在Draw Test Harness中对模型进行变换的命令有:ttranslate, trotate, tmove, reset, tmirror, tscale.其中ttranslate, trotate, tmove, reset命令只会对模型位置进行调整,并不能让模型发生变形,即是刚性变换。下面就通过对一个Box进行移动和旋转,来看看TopoDS_Shape中的Location是如何变化的。在Draw Test Harness中输入以下命令:

pload ALL
box b
vdisplay b
vtrihedron vt
dump b

可以看到此时box的Location是没有的:

Figure 2.1 Box Location in Original

当将box沿X方向移动一段距离后:

# translate by x direction
ttranslate b
vdisplay b
dump b

Figure 2.2 Location of the translation box

由上图可知,当对模型进行变换后,TopoDS_Shape中即有了Location数据,变换矩阵的平移部分(第4列数据)发生了变化。下面继续沿X轴方向移动10:

# translate by x direction
ttranslate b
vdisplay b
dump b

Figure 2.3 Translate Box in X Direction

由图2.3可知,模型现在的位置是通过两个Elementary变换得来的。最后一个Complex变换是上述所有变换的复合。下面再对模型进行绕Y轴旋转45度:

# rotate by y axis
trotate b
vdisplay b
dump b

Figure 2.4 Rotate the Box

由上图可知,经过旋转变换后的模型有了4个Location:三个基本变换和一个复合变换,复合变换是所有基本变换的组合。

通过上面的示例,已经可以清晰理解OpenCASCADE中的Location的概念,虽然处理得有点复杂,通过Location可以对模型的变换轨迹有个详细的跟踪。这样处理的好处就是对模型的变换过程进行了记录,可以方便地回到历史上的任意一个时刻;不好的地方就是程序理解起来麻烦,而且还需要有额外的内存来保存这些数据。
以下为上述所有Tcl脚本:

#
# test TopoDS_Shape location.
# Shing Liu(eryar@163.com)
# 2016-09-06 22:50
# pload ALL # initialize
box b
vdisplay b
vtrihedron vt
dump b # translate by x direction
ttranslate b
vdisplay b
dump b # translate by x direction
ttranslate b
vdisplay b
dump b # rotate by y axis
trotate b
vdisplay b
dump b

3.Draw Code

每个Draw Test Harness命令都可以方便地找到其实现代码,其中模型变换命令的实现代码如下:

//=======================================================================
// transform
//======================================================================= static Standard_Integer transform(Draw_Interpretor& ,Standard_Integer n,const char** a)
{
if (n <= ) return ; gp_Trsf T;
Standard_Integer last = n;
const char* aName = a[]; Standard_Boolean isBasic = Standard_False; if (!strcmp(aName,"reset")) {
}
else {
isBasic = (aName[] == 'b');
aName++; if (!strcmp(aName,"move")) {
if (n < ) return ;
TopoDS_Shape SL = DBRep::Get(a[n-]);
if (SL.IsNull()) return ;
T = SL.Location().Transformation();
last = n-;
}
else if (!strcmp(aName,"translate")) {
if (n < ) return ;
T.SetTranslation(gp_Vec(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-])));
last = n-;
}
else if (!strcmp(aName,"rotate")) {
if (n < ) return ;
T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-])),
gp_Vec(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-]))),
Draw::Atof(a[n-])* (M_PI / 180.0));
last = n-;
}
else if (!strcmp(aName,"mirror")) {
if (n < ) return ;
T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-])),
gp_Vec(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-]))));
last = n-;
}
else if (!strcmp(aName,"scale")) {
if (n < ) return ;
T.SetScale(gp_Pnt(Draw::Atof(a[n-]),Draw::Atof(a[n-]),Draw::Atof(a[n-])),Draw::Atof(a[n-]));
last = n-;
}
} if (T.Form() == gp_Identity || isBasic) {
TopLoc_Location L(T);
for (Standard_Integer i = ; 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 ;
}
else
DBRep::Set(a[i],S.Located(L));
}
}
else {
BRepBuilderAPI_Transform trf(T);
for (Standard_Integer i = ; 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 ;
}
else {
trf.Perform(S);
if (!trf.IsDone())
return ;
DBRep::Set(a[i],trf.Shape());
}
}
}
return ;
}

对模型的变换主要使用类BRepBuilderAPI_Transform来完成。

4.Conclusion

通过上面的示例,已经可以清晰理解OpenCASCADE中的Location的概念,虽然处理得有点复杂,通过Location可以对模型的变换轨迹有个详细的跟踪。这样处理的好处就是对模型的变换过程进行了记录,可以方便地回到历史上的任意一个时刻;不好的地方就是程序理解起来麻烦,而且还需要有额外的内存来保存这些数据。

理解了Location的概念,也就理解了OpenCASCADE的Brep文件中的一项基本内容,方便开发一些转换接口。

关于矩阵变换在图形学中的应用可以参考《3D数学基础:图形与游戏开发》。

5.References

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

2.OpenCASCADE Draw Test Harness User Guide.

OpenCASCADE Shape Location的更多相关文章

  1. OpenCascade Shape Representation in OpenSceneGraph

    OpenCascade Shape Representation in OpenSceneGraph eryar@163.com 摘要Abstract:本文通过程序实例,将OpenCascade中的拓 ...

  2. Locations Section of OpenCascade BRep

    Locations Section of OpenCascade BRep eryar@163.com 摘要Abstract:本文结合OpenCascade的BRep格式描述文档和源程序,对BRep格 ...

  3. Open Cascade DataExchange IGES

    Open Cascade DataExchange IGES eryar@163.com 摘要Abstract:本文结合OpenCascade和Initial Graphics Exchange Sp ...

  4. Scipy教程 - 统计函数库scipy.stats

    http://blog.csdn.net/pipisorry/article/details/49515215 统计函数Statistical functions(scipy.stats) Pytho ...

  5. scipy.stats

    scipy.stats Scipy的stats模块包含了多种概率分布的随机变量,随机变量分为连续的和离散的两种.所有的连续随机变量都是rv_continuous的派生类的对象,而所有的离散随机变量都是 ...

  6. elasticsearch 口水篇(6) Mapping 定义索引

    前面我们感觉ES就想是一个nosql数据库,支持Free Schema. 接触过Lucene.solr的同学这时可能会思考一个问题——怎么定义document中的field?store.index.a ...

  7. cvpr2015papers

    @http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...

  8. elasticsearch Mapping 定义索引

    Mapping is the process of defining how a document should be mapped to the Search Engine, including i ...

  9. Split Shape by Plane in OpenCASCADE

    Split Shape by Plane in OpenCASCADE eryar@163.com Abstract. Sometimes you want to split a shape by p ...

随机推荐

  1. ABP文档 - Javascript Api - AJAX

    本节内容: AJAX操作相关问题 ABP的方式 AJAX 返回信息 处理错误 HTTP 状态码 WrapResult和DontWrapResult特性 Asp.net Mvc 控制器 Asp.net ...

  2. CoreCRM 开发实录——Travis-CI 实现 .NET Core 程度在 macOS 上的构建和测试 [无水干货]

    上一篇文章我提到:为了使用"国货",我把 Linux 上的构建和测试委托给了 DaoCloud,而 Travis-CI 不能放着不用啊.还好,这货支持 macOS 系统.所以就把 ...

  3. 步入angularjs directive(指令)--准备工作熟悉hasOwnProperty

    在讲解directive之前,先做一下准备工作,为何要这样呢? 因为我们不是简单的说说directive怎么用,还要知道为什么这么用!(今天我们先磨磨刀!). 首先我们讲讲js 基础的知识--hasO ...

  4. 玩转spring boot——AOP与表单验证

    AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...

  5. Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part2:clusterware安装和升级

    Linux平台 Oracle 10gR2(10.2.0.5)RAC安装 Part2:clusterware安装和升级 环境:OEL 5.7 + Oracle 10.2.0.5 RAC 3.安装Clus ...

  6. SQL*Plus生成html文件

    最近使用SQL*Plus命令生成html文件,遇到一些有意思的知识点,顺便记录一下,方便以后需要的时候而这些知识点又忘记而捉急.好记性不如烂笔头吗! 为什么要用SQL*Plus生成html文件?   ...

  7. .NET跨平台之旅:将示例站点升级至 .NET Core 1.1 Preview 1

    今天微软发布了 .NET Core 1.1 Preview 1(详见 Announcing .NET Core 1.1 Preview 1 ),紧跟 .NET Core 前进的步伐,我们将示例站点 h ...

  8. Mono for Android—初体验之“电话拨号器”

    1.Main.axml文件: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmln ...

  9. Handlebars 模板引擎之前后端用法

    前言 不知不觉间,居然已经这么久没有写博客了,坚持还真是世界上最难的事情啊. 不过我最近也没闲着,辞工换工.恋爱失恋.深圳北京都经历了一番,这有起有落的生活实在是太刺激了,就如拿着两把菜刀剁洋葱一样, ...

  10. iOS开发系列文章(持续更新……)

    iOS开发系列的文章,内容循序渐进,包含C语言.ObjC.iOS开发以及日后要写的游戏开发和Swift编程几部分内容.文章会持续更新,希望大家多多关注,如果文章对你有帮助请点赞支持,多谢! 为了方便大 ...