OpenCASCADE Make Face With Holes

eryar@163.com

OpenCASCADE提供了构造Face的类BRepBuilderAPI_MakeFace,使用这个类可以构造出带孔的面。如下图所示:

当然,要得到上图所示的结果,还可以使用Boolean操作,用一个面去Cut几个圆柱。当使用布尔操作就会涉及到一些复杂算法,如求交,重构Topo体等,比较耗时。既然可以直接在生成面的时候挖孔,这个不涉及复杂算法,速度、稳定性都比使用布尔操作要好。本文主要来介绍如何使用BRepBuilderAPI_MakeFace来生成带孔的面,及其注意事项。直接上代码:

#include <gp_Circ.hxx>
#include <gp_Pln.hxx> #include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> #include <BRepTools.hxx> #pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib") #pragma comment(lib, "TKG2d.lib")
#pragma comment(lib, "TKG3d.lib")
#pragma comment(lib, "TKGeomBase.lib")
#pragma comment(lib, "TKGeomAlgo.lib") #pragma comment(lib, "TKBRep.lib")
#pragma comment(lib, "TKTopAlgo.lib") void makeFaceTest()
{
gp_Pln aPlane; gp_Circ aCircle1(gp::XOY(), 1.0);
gp_Circ aCircle2(gp::XOY(), 1.0);
gp_Circ aCircle3(gp::XOY(), 1.0); aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0));
aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0));
aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0)); BRepBuilderAPI_MakeEdge anEdgeMaker1(aCircle1);
BRepBuilderAPI_MakeEdge anEdgeMaker2(aCircle2);
BRepBuilderAPI_MakeEdge anEdgeMaker3(aCircle3); BRepBuilderAPI_MakeWire aWireMaker1(anEdgeMaker1.Edge());
BRepBuilderAPI_MakeWire aWireMaker2(anEdgeMaker2.Edge());
BRepBuilderAPI_MakeWire aWireMaker3(anEdgeMaker3.Edge()); BRepBuilderAPI_MakeFace aFaceMaker(aPlane, 0.0, 10.0, 0.0, 10.0); if (aWireMaker1.IsDone())
{
aFaceMaker.Add(aWireMaker1.Wire());
} if (aWireMaker2.IsDone())
{
aFaceMaker.Add(aWireMaker2.Wire());
} if (aWireMaker3.IsDone())
{
aFaceMaker.Add(aWireMaker3.Wire());
} if (aFaceMaker.IsDone())
{
BRepTools::Write(aFaceMaker.Shape(), "d:/face.brep");
} } int main(int argc, char* argv[])
{ makeFaceTest(); return ; }

上面代码就是在一个平面上开三个孔,最后在D盘生成face.brep文件。在Draw Test Harness中加载并显示这个文件得到:

当切换到线框显示模式时,和预期效果一致。但是当切换到着色显示模式时,发现生成的面和预期的效果刚好相反。这是什么原因呢?

在Draw Test Harness中输入命令pcruve来检查,如下图所示:

根据pcurve命令的提示得知,蓝色的方向应该反向,红色的为外环。所以得知,内环孔的方向反了。修改代码,直接将Wire的方向Reverse。修改后的代码如下:

#include <gp_Circ.hxx>
#include <gp_Pln.hxx> #include <TopoDS_Wire.hxx> #include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> #include <BRepTools.hxx> #pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib") #pragma comment(lib, "TKG2d.lib")
#pragma comment(lib, "TKG3d.lib")
#pragma comment(lib, "TKGeomBase.lib")
#pragma comment(lib, "TKGeomAlgo.lib") #pragma comment(lib, "TKBRep.lib")
#pragma comment(lib, "TKTopAlgo.lib") void makeFaceTest()
{
gp_Pln aPlane; gp_Circ aCircle1(gp::XOY(), 1.0);
gp_Circ aCircle2(gp::XOY(), 1.0);
gp_Circ aCircle3(gp::XOY(), 1.0); aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0));
aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0));
aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0)); BRepBuilderAPI_MakeEdge anEdgeMaker1(aCircle1);
BRepBuilderAPI_MakeEdge anEdgeMaker2(aCircle2);
BRepBuilderAPI_MakeEdge anEdgeMaker3(aCircle3); BRepBuilderAPI_MakeWire aWireMaker1(anEdgeMaker1.Edge());
BRepBuilderAPI_MakeWire aWireMaker2(anEdgeMaker2.Edge());
BRepBuilderAPI_MakeWire aWireMaker3(anEdgeMaker3.Edge()); BRepBuilderAPI_MakeFace aFaceMaker(aPlane, 0.0, 10.0, 0.0, 10.0);
if (aWireMaker1.IsDone())
{
TopoDS_Wire aWire1 = aWireMaker1.Wire();
aWire1.Reverse(); aFaceMaker.Add(aWire1);
} if (aWireMaker2.IsDone())
{
TopoDS_Wire aWire2 = aWireMaker2.Wire();
aWire2.Reverse(); aFaceMaker.Add(aWire2);
} if (aWireMaker3.IsDone())
{
TopoDS_Wire aWire3 = aWireMaker3.Wire();
aWire3.Reverse(); aFaceMaker.Add(aWire3);
} if (aFaceMaker.IsDone())
{
BRepTools::Write(aFaceMaker.Shape(), "d:/face.brep");
}
} int main(int argc, char* argv[])
{
makeFaceTest(); return ;
}

重新加载新生成的face.brep并使用pcurve查看,得到如下图所示的效果:

从上图可知,这时得到的为预期的效果。综上所述,如果要直接使用BRepBuilderAPI_MakeFace来生成带有孔的面,需要自己为外环和内环的方向负责,opencascade对此不作检查。当面显示不正确时,可以使用Draw Test Harness的pcurve命令来检查。一个带孔的面的pcurve的规则为:外环为逆时针方向;内环孔的方向为顺时针方向。

基于直接生成的带孔的面,还可以进一步使用放样算法来造型,如拉伸,旋转等,如下图所示。这样就可以避免使用布尔操作,提高造型算法的性能和稳定性。

OpenCASCADE Make Face With Holes的更多相关文章

  1. OpenCASCADE PCurve of Topological Face

    OpenCASCADE PCurve of Topological Face eryar@163.com Abstract. OpenCASCADE provides a class BRepBuil ...

  2. OpenCASCADE AIS Manipulator

    OpenCASCADE AIS Manipulator eryar@163.com Abstract. OpenCASCADE7.1.0 introduces new built-in interac ...

  3. 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 ...

  4. OpenCASCADE Shape Location

    OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...

  5. OpenCASCADE BRep Projection

    OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上. ...

  6. OpenCASCADE Expression Interpreter by Flex & Bison

    OpenCASCADE Expression Interpreter by Flex & Bison eryar@163.com Abstract. OpenCASCADE provide d ...

  7. OpenCASCADE Data Exchange - 3D PDF

    OpenCASCADE Data Exchange - 3D PDF eryar@163.com Abstract. Today most 3D engineering model data are ...

  8. OpenCASCADE Interpolations and Approximations

    OpenCASCADE Interpolations and Approximations eryar@163.com Abstract. In modeling, it is often requi ...

  9. OpenCASCADE Ring Type Spring Modeling

    OpenCASCADE Ring Type Spring Modeling eryar@163.com Abstract. The general method to directly create ...

随机推荐

  1. Kali linux 2016.2(Rolling)中metasploit的搜集特定地址的邮件地址

    不多说,直接上干货! 使用search_email_collector搜集特定地址的邮件地址 search_email_collector 要求提供一个邮箱后缀,通过多个搜索引擎的查询结果分析使用此后 ...

  2. <Sicily>Pair

    一.题目描述 The N cities of Estiah are connected by N-1 roads. The roads are built in a way that it's alw ...

  3. Signal programming

    Signal programming is used in the same sense as dataflow programming, and is similar to event-driven ...

  4. tomcat动态查看服务器打印日志

    [root@localhost ~]# cd /usr/local/tomcat/logs [root@localhost logs]# tail -f catalina.out   FROM:htt ...

  5. 今日SGU 6.5

    sgu 160 题意:给你n个数字 数字范围 1 到 m 问你从中取出任意数量的数字使得这些数字的积取模m最大 收获:dp,记录dp的路径 #include<bits/stdc++.h> ...

  6. FOJ1205 小鼠迷宫问题 (BFD+递推)

    FOJ1205 小鼠迷宫问题 (BFD+递推) 小鼠a与小鼠b身处一个m×n的迷宫中,如图所示.每一个方格表示迷宫中的一个房间.这m×n个房间中有一些房间是封闭的,不允许任何人进入.在迷宫中任何位置均 ...

  7. 网络project1101班2014-2015学年《网络软件开发实训》期末考试

    注意事项: *考试时间:2014年11月20日 第5.6节. *在计算机D盘,新建目录.并命名"学号+姓名".如:(称为考生目录.下同).考试中全部文件必须保存在此目录下. *启动 ...

  8. hdoj2066一个人的旅行

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  9. vim插件之delimitMate.vim

    delimitMate.vim--这个插件主要是在插入模式下,用来自动补全括号.引号等 下载地址 http://www.vim.org/scripts/script.php?script_id=275 ...

  10. nyoj--20--吝啬的国度(搜索dfs)

    吝啬的国度 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市,他有 ...