OpenCascade Law Function

小说:一个国家和社会的品味其实是由女人决定的作者:通杜更新时间:2019-03-26字数:91442

OpenCascade Law Function


OpenCascade Law Function

eryar@163.com

1.Introduction

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

wps_clip_image-22828

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():规则函数的定义区间;

wps_clip_image-13300

从上面的虚函数可以看出类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 << "
 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 中即可显示出规则函数对应的曲线,如下图所示:

wps_clip_image-6615

Figure 2. Visualization Law Function Curves

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

4.Conclusion

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

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

当前文章:http://0477auto.com/html_61844.html

发布时间:2019-03-26 00:48:33

你不一定要穿低腰裤 不要怕青春期孩子 也不要让孩子怕你! 处世哲学名言 罗李华简谈2016年十二生肖运势 恐怖袭击接踵而至,法国怎么了? 你还不是娶了别人,我也没有嫁给你 人格健康与家庭教育 你从来都不知道今天在地铁里能遇见谁 【恋爱课堂】亲密关系:依恋理论 亲爱的,因为你的努力,我才倍加珍惜

春天的养护 儿童为什么自伤? 恐惧的形成和消除 年轻人,不要把时间浪费在股市上 不要用战术上的忙碌掩盖战略上的懒惰 新西兰中小学教育有多好?多文化中文热 关于《人生》答某报记者问 家长观念中的误区 幼师对儿童心理成长的重要作用(详) 面对灾难,让我们紧急行动起来,预防心理创伤! 人民币贬值对我们意味着什么? 文创监理 - 黄胤然首倡文创理念 “一见钟情”的秘密解读 做好朋友,找真朋友 《琅琊榜》“泰”有味,秒杀韩国欧巴 喜欢的东西想占为己有,是正常的儿童心理发展的现象 北京高考新政的N个变化 汪国真是假诗人吗? 罗李华:天秤座2016年运势

编辑:安卓顺通

我要说两句: (0人参与)

发布