OpenNURBS to OpenCASCADE
OpenNURBS to OpenCASCADE
Abstract. The OpenNURBS initiative provides CAD/CAM/CAE and computer graphics software developers the tools to accurately transfer 3D geometry between applications. The OpenNURBS C++ source code is clean and fairly simple. The OpenNURBS Toolkit is intended for use by C++ and .NET programmers. The toolkit includes complete source code to create a library that will read and write 3dm files. OpenCASCADE providing services for 3D surface and solid modeling, CAD data exchange, and visulization. Most of OCCT functionality is available in the form of C++ libraries. If can convert OpenNURBS curve/surface to OpenCASCADE, then it will fill the gap of data exchange between OpenNURBS and OpenCASCADE.
Key Words. OpenCASCADE, OpenNURBS, NURBS, 3DM, DataExchange
1. Introduction
OpenNURBS 旨在为CAD、CAM、CAE与计算机图形软件开发人员提供一个在不同的软件间精确转换 3D 几何的工具。OpenNURBS 所提供的功能包括:
v 可以读、写3DM文件格式的C ++原代码库,支持目前的 Microsoft、Apple与 Gnu for Windows、Windows X64、Mac与Linux编绎器...
v 可以读、写3DM文件格式的.NET 源代码库。
v 品质保证与版本控制。
v 技术支持。
与其他开源产品的开发平台不同之处:
v 鼓励使用在商业用途。
v 提供免费的开发工具与技术支持。
v 无任何约束,不受版权与公共版权(copyleft )条款约束。
v 鼓励但不强迫用户分享自己的研发成果。
NURBS是当前流行几何造型系统中通用的曲线曲面表达形式,OpenNURBS开源库提供了NURBS曲线曲面的数据表达,但缺少一些造型算法,而OpenCASCADE中提供了大量的造型算法。通过将OpenNURBS中的曲线曲面转换到OpenCASCADE中,就可以将OpenNURBS和OpenCASCADE结合起来使用了。
OpenNURBS中的代码简洁,易懂;OpenCASCADE的造型功能强大。所以先将OpenNURBS中的曲线曲面转换到OpenCASCADE中,为OpenCASCADE的3DM格式的数据交换打下基础。
2.Convert OpenNURBS Curve
OpenNURBS中统一使用NURBS方式来表达曲线和曲面。OpenCASCADE中对应NURBS曲线的类为Geom_BSplineCurve。因此,可以将OpenNURBS的曲线转换到OpenCASCADE中。转换时需要注意节点矢量Knot Vector的方式有很大的不同。OpenNURBS中的节点矢量是所有的节点值,包括了重节点,而且在节点矢量的首尾还少了两个节点。OpenCASCADE中的节点矢量由不包含重复节点的节点矢量及其重数来构造。其它数据基本相同,将转换曲线的示例代码列出如下:
/**
* @breif Convert OpenNURBS NURBS curve to OpenCASCADE Geom_BSplineCurve.
* @param [in] theCurve opennurbs nurbs curve;
* @param [in] theBRepFile the curve is in brep file of opencascade;
* @note pay attention to the knots of opennurbs nurbs curve/surface.
*/
void ConvertCurve(const ON_NurbsCurve& theCurve, const std::string& theBRepFile)
{
TColgp_Array1OfPnt aPoles(, theCurve.CVCount());
TColStd_Array1OfReal aWeights(, theCurve.CVCount()); TColStd_Array1OfReal aKnotSequence(, theCurve.KnotCount() + ); bool IsRational = theCurve.IsRational();
bool IsPeriodic = (theCurve.IsPeriodic()) ? true: false; // Control point and its weight.
for (int i = ; i < theCurve.CVCount(); ++i)
{
if (IsRational)
{
ON_4dPoint aPole; theCurve.GetCV(i, aPole); aPoles.SetValue(i + , gp_Pnt(aPole.x / aPole.w, aPole.y / aPole.w, aPole.z / aPole.w));
aWeights.SetValue(i + , aPole.w);
}
else
{
ON_3dPoint aPole; theCurve.GetCV(i, aPole); aPoles.SetValue(i + , gp_Pnt(aPole.x, aPole.y, aPole.z));
}
} // Knot vector and its multiplicity.
for (int i = ; i < theCurve.KnotCount(); ++i)
{
aKnotSequence.SetValue(i + , theCurve.Knot(i));
} aKnotSequence.SetValue(aKnotSequence.Lower(), theCurve.Knot());
aKnotSequence.SetValue(aKnotSequence.Upper(), theCurve.Knot(theCurve.KnotCount() - )); TColStd_Array1OfReal aKnots(, BSplCLib::KnotsLength(aKnotSequence, IsPeriodic));
TColStd_Array1OfInteger aMultiplicities(, aKnots.Upper()); BSplCLib::Knots(aKnotSequence, aKnots, aMultiplicities); Handle_Geom_BSplineCurve aBSplineCurve = new Geom_BSplineCurve(
aPoles, aWeights, aKnots, aMultiplicities,
theCurve.Degree(), theCurve.IsPeriodic()); GeomTools_CurveSet::PrintCurve(aBSplineCurve, std::cout); TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aBSplineCurve); BRepTools::Write(anEdge, theBRepFile.c_str());
}
程序先转换控制顶点,若是有理曲线,还要设置控制顶点的权值w。在转换节点矢量时,使用了BSplCLib::Knots()函数将OpenNURBS的节点矢量转换为OpenCASCADE的形式,并补齐了缺少的端部的两个节点。最后为了在OpenCASCADE中显示转换结果,将曲线生成TopoDS_Edge并保存为BRep格式,方便在Draw Test Harness中查看结果如下图所示:
![]()
Figure 2.1 OpenNURBS nurbs circle in OpenCASCADE Draw Test Harness
3.Convert OpenNURBS Surface
OpenNURBS曲面的转换同样也需要注意u, v方向上的节点矢量的问题,和曲线的转换类似。除此之外就是把相同的属性分别赋值即可,列出代码如下所示:
/**
* @breif Convert OpenNURBS NURBS surface to OpenCASCADE Geom_BSplineSurface.
* @param [in] theSurface opennurbs nurbs surface;
* @param [in] theBRepFile the surface is in the brep file of opencascade;
* @note pay attention to the knots of opennurbs nurbs curve/surface.
*/
void ConvertSurface(const ON_NurbsSurface& theSurface, const std::string& theBRepFile)
{
TColgp_Array2OfPnt aPoles(, theSurface.CVCount(), , theSurface.CVCount());
TColStd_Array2OfReal aWeights(, theSurface.CVCount(), , theSurface.CVCount()); TColStd_Array1OfReal aUKnotSequence(, theSurface.KnotCount() + );
TColStd_Array1OfReal aVKnotSequence(, theSurface.KnotCount() + ); bool IsRational = theSurface.IsRational();
bool IsUPeriodic = (theSurface.IsPeriodic()) ? true: false;
bool IsVPeriodic = (theSurface.IsPeriodic()) ? true: false; // control point and its weight.
for (int i = ; i < theSurface.CVCount(); ++i)
{
for (int j = ; j < theSurface.CVCount(); ++j)
{
if (IsRational)
{
ON_4dPoint aPole; theSurface.GetCV(i, j, aPole); aPoles.SetValue(i + , j + , gp_Pnt(aPole.x / aPole.w, aPole.y / aPole.w, aPole.z / aPole.w));
aWeights.SetValue(i + , j + , aPole.w);
}
else
{
ON_3dPoint aPole; theSurface.GetCV(i, j, aPole); aPoles.SetValue(i + , j + , gp_Pnt(aPole.x, aPole.y, aPole.z));
} }
} // Knot vector and its multiplicity.
for (int i = ; i < theSurface.KnotCount(); ++i)
{
aUKnotSequence.SetValue(i + , theSurface.Knot(, i));
} aUKnotSequence.SetValue(aUKnotSequence.Lower(), theSurface.Knot(, ));
aUKnotSequence.SetValue(aUKnotSequence.Upper(), theSurface.Knot(, theSurface.KnotCount() - )); TColStd_Array1OfReal aUKnots(, BSplCLib::KnotsLength(aUKnotSequence, IsUPeriodic));
TColStd_Array1OfInteger aUMults(, aUKnots.Upper()); BSplCLib::Knots(aUKnotSequence, aUKnots, aUMults); for (int j = ; j < theSurface.KnotCount(); ++j)
{
aVKnotSequence.SetValue(j + , theSurface.Knot(, j));
} aVKnotSequence.SetValue(aVKnotSequence.Lower(), theSurface.Knot(, ));
aVKnotSequence.SetValue(aVKnotSequence.Upper(), theSurface.Knot(, theSurface.KnotCount() - )); TColStd_Array1OfReal aVKnots(, BSplCLib::KnotsLength(aVKnotSequence, IsVPeriodic));
TColStd_Array1OfInteger aVMults(, aVKnots.Upper()); BSplCLib::Knots(aVKnotSequence, aVKnots, aVMults); Handle_Geom_BSplineSurface aBSplineSurface = new Geom_BSplineSurface(aPoles,
aWeights, aUKnots, aVKnots, aUMults, aVMults,
theSurface.Degree(), theSurface.Degree(),
IsUPeriodic, IsVPeriodic); GeomTools_SurfaceSet::PrintSurface(aBSplineSurface, std::cout); TopoDS_Face aFace = BRepBuilderAPI_MakeFace(aBSplineSurface, Precision::Confusion());
BRepTools::Write(aFace, theBRepFile.c_str());
}
转换过程与曲线的类似,只是多了v方向上的处理。以上两个函数分别实现曲线曲面的转换,完整程序可以在本文后面的链接中下载。以圆柱面和球面为例,测试了一下转换效果,在Draw Test Harness中显示结果如下图所示:
![]()
Figure 3.1 OpenNURBS nurbs sphere in OpenCASCADE Draw Test Harness
![]()
Figure 3.2 OpenNURBS nurbs cylinder in OpenCASCADE Draw Test Harness
由上图可知,OpenCASCADE中的Geom_BSplineCurve/Geom_BSplineSurface可以完美表示OpenNURBS中的曲线曲面,不过有最高次数为25次的限制。
4.Conclusion
现可看出,OpenNURBS中的曲线曲面可以转换成OpenCASCADE中。不过在转换时需要注意OpenNURBS的节点矢量数据与教科书中及OpenCASCADE中不同,需要做些处理。还有需要注意的事项就是OpenNURBS中数组是从0开始的,而在OpenCASCADE中可以指定为从1开始。
将OpenNURBS的曲线曲面转换成OpenCASCADE的曲线曲面后,下一步准备将OpenNURBS中的BRep体也转换到OpenCASCADE中,从而对BRep表示形式做进一步的学习。
5. References
1. OpenNURBS Web: http://www.rhino3d.com/opennurbs
2. Les Piegl, Wayne Tiller. The NURBS Book. Springer-Verlag. 1997
3. 赵罡,穆国旺,王拉柱译. 非均匀有理B样条. 清华大学出版社. 2010
PDF Version and Code: OpenNURBS to OpenCASCADE
OpenNURBS to OpenCASCADE的更多相关文章
- OpenCASCADE BRep vs. OpenNURBS BRep
OpenCASCADE BRep vs. OpenNURBS BRep eryar@163.com Abstract. BRep short for Boundary Representation. ...
- OpenCASCADE Make Primitives-Box
OpenCASCADE Make Primitives-Box eryar@163.com Abstract. By making a simple box to demonstrate the BR ...
- OpenCASCADE BRepTools
OpenCASCADE BRepTools eryar@163.com Abstract. OpenCASCADE BRepTools provides utilities for BRep data ...
- OpenCASCADE AIS Manipulator
OpenCASCADE AIS Manipulator eryar@163.com Abstract. OpenCASCADE7.1.0 introduces new built-in interac ...
- Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...
- OpenCASCADE Shape Location
OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...
- OpenCASCADE BRep Projection
OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上. ...
- OpenCASCADE Expression Interpreter by Flex & Bison
OpenCASCADE Expression Interpreter by Flex & Bison eryar@163.com Abstract. OpenCASCADE provide d ...
- OpenCASCADE Data Exchange - 3D PDF
OpenCASCADE Data Exchange - 3D PDF eryar@163.com Abstract. Today most 3D engineering model data are ...
随机推荐
- Windows中使用TortoiseGit提交项目到GitLab配置
下文来给各位介绍Windows中使用TortoiseGit提交项目到GitLab配置过程,下在全部图片希望对各位带来方便面. Gitlab默认的配置推荐使用shell命令行与server端进行交互,作 ...
- bzoj3673可持久化线段树实现可持久化数组实现可持久化并查集(好长)
线段树只用叶子节点感觉莫名浪费,,, 感觉真好写(刚从未来程序逃回来的人) #include <cstdio> #define mid ((l+r)>>1) ,ca,x,y; ...
- Shell脚本基础
特别变量: $# 传递到脚本的参数个数$* 以一个单字符串显示所有向脚本传递的参数$$ 脚本运行的当前进程ID号$! 后台运行的最后一个进程的ID号$@ 与$#相同,但是使用时加引号,并在引号中返回每 ...
- Android图书应用-西游记
下载App 屏幕截图: 功能介绍:1. 侧边滑动目录导航2. 阅读偏好设置3. 记忆阅读进度 内容介绍: 西游记,中国古典名著,内容分三大部分: 第一部分(一到七回)介绍孙悟空的神通 ...
- yoman 创建generator
yoman作为一个模板工具,能够创建自己的模板,下面具体介绍下. 首先 安装一个模板工具(npm install -g generator-generator),此工具会自动创建一些必要的文件.安装完 ...
- dotnetcore 单元测试
dotnetcore的单元测试目前支持的比较好的是xunit,首先通过nuget添加组件dotnet-test-xunit 和 xunit.如果有依赖注入可在构造方法中,相当于Nunit中的[Setu ...
- C# Listview 数据绑定
今天搞Winform,有串数据需要绑定到TabControl里面,原来用datatable,组长说这玩意会有问题不让用,菜鸟实在不会,百度查的Listview用法,写了个数组进去绑定 using Sy ...
- 求N个数的最大公约数和最小公倍数(转)
除了分解质因数,还有另一种适用于求几个较小数的最大公约数.最小公倍数的方法 下面是数学证明及算法实现 令[a1,a2,..,an] 表示a1,a2,..,an的最小公倍数,(a1,a2,..,an)表 ...
- MYSQL 5.0 USING BTREE 错误
今天遇到个错误,导入数据库的时候报错,最后发现是php版本的问题导致包含 KEY `uniacid` (`uniacid`) USING BTREE 的SQL命令报错 5.1之前的写法: KEY `u ...
- ZXing二维码生成在Unity3D中出错,数组超出界限的解决办法
错误截图: IndexOutOfRangeException: Array index is out of range.ZXing.Color32Renderer.Render (ZXing.Comm ...