OpenCascade Law Function

eryar@163.com

1.Introduction

在OpenCASCADE的TKGeomAlgo Toolkit中提供了一个Law Package,在Law包中有一个基类:Law_Function,字面上翻译为 规则函数。其类图如下所示:

Figure 1. Law Function class diagram

本文主要对Law_Function的子类进行介绍,进一步理解OpenCASCADE中Law相关类的作用。

2.Law Functions

根据Law_Function可知,Law_Function的子类有常量规则Law_Constant、线性规则Law_Linear、组合规则Law_Composite及B样条规则Law_BSpFunc。抽象类Law_Function的纯虚函数有:

l Continuity(): 规则函数的连续性;

l Value():计算对应参数X的函数值Y;

l D1():计算规则函数在参数X处的一阶导数;

l D2():计算规则函数在参数X处的二阶导数;

l Bounds():规则函数的定义区间;

从上面的虚函数可以看出类Law_Function是一个一元变量的函数,与类math_Function的功能类似。

3.Test Code

下面的代码将规则函数Law_Function的几个子类通过生成Draw脚本,在Draw Test Harness中进行可视化,直观地显示出了几个规则函数,便于理解。

/*

Copyright(C) 2018 Shing Liu(eryar@163.com)

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files(the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and / or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

*/

#include <TColgp_Array1OfPnt2d.hxx>

#include <Law_Constant.hxx>

#include <Law_Linear.hxx>

#include <Law_BSpFunc.hxx>

#include <Law_S.hxx>

#include <Law_Interpol.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")

Standard_Integer aId = 0;

void draw(const Handle(Law_Function)& theLaw, std::ostream& theOutput)

{

const Standard_Integer aStep = 20;

Standard_Real aFirst = 0.0;

Standard_Real aLast = 0.0;

Standard_Real aDelta = 0.0;

Standard_Real aX = 0.0;

Standard_Real aY = 0.0;

theLaw->Bounds(aFirst, aLast);

aDelta = (aLast - aFirst) / aStep;

theOutput << "polyline law" << ++aId;

for (Standard_Integer i = 0; i <= aStep; ++i)

{

aX = aFirst + i * aDelta;

aY = theLaw->Value(aX);

theOutput  << " " << aX << " " << aY << " 0.0";

}

theOutput << "\n vdisplay law" << aId << std::endl;

theOutput << "vaspects law" << aId << " -setColor " << ((aId % 2) ? " red " : " yellow ") << std::endl;

}

void test(std::ostream& theOutput)

{

// 1. Constant law.

Handle(Law_Constant) aConstantLaw = new Law_Constant();

aConstantLaw->Set(2.0, 0.0, 1.0);

draw(aConstantLaw, theOutput);

// 2. Linear evolution law.

Handle(Law_Linear) aLinearLaw = new Law_Linear();

aLinearLaw->Set(1.0, 2.0, 3.0, 5.0);

draw(aLinearLaw, theOutput);

// 3. An "S" evolution law.

Handle(Law_S) aSLaw = new Law_S();

aSLaw->Set(3.0, 5.0, 6.0, 8.0);

draw(aSLaw, theOutput);

// 4. Provides an evolution law that interpolates a set of parameter and value pairs (wi, radi)

TColgp_Array1OfPnt2d aPoints(1, 4);

aPoints.SetValue(1, gp_Pnt2d(6.0, 8.0));

aPoints.SetValue(2, gp_Pnt2d(7.0, 5.0));

aPoints.SetValue(3, gp_Pnt2d(8.0, 9.0));

aPoints.SetValue(4, gp_Pnt2d(9.0, 2.0));

Handle(Law_Interpol) anInterpolativeLaw = new Law_Interpol();

anInterpolativeLaw->Set(aPoints);

draw(anInterpolativeLaw, theOutput);

}

int main(int argc, char* argv[])

{

std::ofstream aTclFile("d:/tcl/law.tcl");

test(aTclFile);

return 0;

}

程序会在d:/tcl中生成一个law.tcl文件,将此文件加载到Draw 中即可显示出规则函数对应的曲线,如下图所示:

Figure 2. Visualization Law Function Curves

由图可知,常量规则函数在定义区间内是一条直线;线性规则函数是一条直线;S型函数是S型的B样条曲线;插值函数是根据指定点插值得到的B样条曲线。

4.Conclusion

在OpenCASCADE中经常可以看到一些与Law相关的类,本文介绍了TKGeomAlgo中的Law包,综上所述可知,Law就是一元函数,与math_Function的概念一致。

本文显示规则曲线的方式可供借鉴,提高开发效率。只需要生成一个文本文件,就可以将结果可视化,对于其他三维的也是一样。

OpenCascade Law Function的更多相关文章

  1. Function Set in OPEN CASCADE

    Function Set in OPEN CASCADE eryar@163.com Abstract. The common math algorithms library provides a C ...

  2. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  3. OpenCascade B-Spline Basis Function

    OpenCascade B-Spline Basis Function eryar@163.com Abstract. B-splines are quite a bit more flexible ...

  4. OpenCASCADE Trihedron Law

    OpenCASCADE Trihedron Law eryar@163.com Abstract. In differential geometry the Frenet-Serret formula ...

  5. OpenCASCADE Expression Interpreter by Flex & Bison

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

  6. 齐夫定律, Zipf's law,Zipfian distribution

    齐夫定律(英语:Zipf's law,IPA英语发音:/ˈzɪf/)是由哈佛大学的语言学家乔治·金斯利·齐夫(George Kingsley Zipf)于1949年发表的实验定律. 它可以表述为: 在 ...

  7. OpenCASCADE Interpolation - Lagrange

    OpenCASCADE Interpolation - Lagrange eryar@163.com Abstract. Power basis polynomial is the most simp ...

  8. OpenCASCADE BRepTools

    OpenCASCADE BRepTools eryar@163.com Abstract. OpenCASCADE BRepTools provides utilities for BRep data ...

  9. A Simple OpenCASCADE Qt Demo-occQt

    A Simple OpenCASCADE Qt Demo-occQt eryar@163.com Abstract. OpenCASCADE have provided the Qt samples ...

随机推荐

  1. 实战DeviceIoControl 之二:获取软盘/硬盘/光盘的参数

    Q 在MSDN的那个demo中,将设备名换成"A:"取A盘参数,先用资源管理器读一下盘,再运行这个程序可以成功,但换一张盘后就失败:换成"CDROM0"取CDR ...

  2. Meet Python

    关于python 入门书<Head First Python>的一些读书笔记,用以备忘. 下载安装Python 下载地址: https://www.python.org/downloads ...

  3. c# 处理空白字符,空白字符是指在屏幕不会显示出来的字符

    空白字符是指在屏幕不会显示出来的字符(如空格,制表符tab,回车换行等).空格.制表符.换行符.回车.换页垂直制表符和换行符称为 "空白字符",因为它们为与间距单词和行在打印的页 ...

  4. “var arr = []; ”和 “var arr = {};” 的区别

    1.面试题    var arr = [];    var arr = {};    比较上述代码有什么区别? 2.解析    var arr = [];是一个数组对象    var arr = {} ...

  5. ORA-00904:"T1"."AREA_ID" :标识符无效

    1.错误描述 ORA-00904:"T1"."AREA_ID" :标识符无效 00904 . 00000 - "%s:invalid identifi ...

  6. BUAA软工第0次作业

    第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢?(必答) 我在大学之前甚至连一个萌新都算不上,根本没有任何一点计算机专业的基础. 因此在进入大学之前,计算机对于我 ...

  7. 最新的 iOS 申请证书与发布流程

    申请流程. 1. 申请钥匙串文件 进入  (Launchpad),找到   (我的是在其他里面找到的),运行后再左上角 存储在桌面就好了,然后就完成退出钥匙串工具就可以了. 2.申请开发证书,发布证书 ...

  8. 用yeoman搭建react画廊项目笔记

    1.安装yeoman   npm install yo -g yo --version //检测 yeoman版本,成功显示版本号,则安装成功 2.到yeoman官网 http://yeoman.io ...

  9. 5 分钟让你秒懂 Docker !

    Docker是啥? 打开翻译君输入Docker 结果显示码头工人,没错!码头工人搬运的是集装箱,那么今天要讲的Docker其操作的也是集装箱,这个集装箱就静态而言就是一个应用镜像文件,就动态而言,就是 ...

  10. bzoj2969 矩形粉刷

    学习一波用markdown写题解的姿势QAQ 题意 给你一个w*h的矩形网格,每次随机选择两个点,将以这两个点为顶点的矩形内部的所有小正方形染黑,问染了k次之后期望有多少个黑色格子. 分析 一开始看错 ...