青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

eryar

PipeCAD - Plant Piping Design Software.
PlantAssistant - Translate AVEVA RVM/SP3D VUE to glTF, STEP, etc.
posts - 606, comments - 590, trackbacks - 0, articles - 0

OpenCascade Shape Representation in OpenSceneGraph

eryar@163.com

摘要Abstract:本文通過(guò)程序?qū)嵗瑢penCascade中的拓樸數(shù)據(jù)(邊、面)離散化后在OpenSceneGraph中進(jìn)行顯示。有了這些離散數(shù)據(jù),就可以不用OpenCascade的顯示模塊了,可以使用其他顯示引擎對(duì)形狀進(jìn)行顯示。即若要線框模式顯示形狀時(shí),就繪制離散形狀拓樸邊后得到的多段線;若要實(shí)體渲染模式顯示形狀時(shí),就繪制離散形狀拓樸面得到的三角網(wǎng)格。理解這些概念也有助于理解顯示模塊的實(shí)現(xiàn),及拓樸數(shù)據(jù)中包含的幾何數(shù)據(jù)的意義。

關(guān)鍵字 Key Words:OpenCascade, polygon curve, triangulation,discrete edge, discrete face,  OpenSceneGraph, OSG

一、引言 Introduction

“實(shí)體造型技術(shù)主流的是邊界表達(dá)BRep,就是模型由面和邊組成,這些面和邊都是參數(shù)化的解析曲面和曲線,當(dāng)拉伸或切割實(shí)體操作時(shí)候,就是用生成的實(shí)體和已有的實(shí)體進(jìn)行實(shí)體布爾運(yùn)算,其實(shí)是進(jìn)行的面和邊的相交運(yùn)算,從而算出到新的面或者邊。比如圓柱面和平面相交,以前的圓柱面分成了兩個(gè),同時(shí)產(chǎn)生出一條相交的空間橢圓曲線段,這些解析面/線邊要通過(guò)三角化算法離散成三角網(wǎng)格或者線段條作為逼近表達(dá),才能用OpenGL畫(huà)出來(lái)。”以上內(nèi)容來(lái)自博客:http://yrcpp.blog.163.com/blog/static/126045259201310199515969/ ,感謝網(wǎng)友的分享,言簡(jiǎn)意賅地把造型的核心進(jìn)行了說(shuō)明。

以前看《計(jì)算機(jī)圖形學(xué)》相關(guān)的書(shū)時(shí),從數(shù)學(xué)概念到具體實(shí)現(xiàn)的橋梁總是無(wú)法銜接。現(xiàn)在,通過(guò)學(xué)習(xí)OpenCascade,終于把這些都串起來(lái)了。正如上面網(wǎng)友所說(shuō),面和邊要在OpenGL中顯示出來(lái)就需要離散化,即把邊離散為多段線,把面離散為三角網(wǎng)格。這樣就可以把用參數(shù)精確表示的幾何數(shù)據(jù)在計(jì)算機(jī)布滿像素點(diǎn)的屏幕上逼近顯示了。

本文通過(guò)程序?qū)嵗瑢penCascade中的拓樸數(shù)據(jù)(邊、面)離散化后在OpenSceneGraph中進(jìn)行顯示。有了這些離散數(shù)據(jù),就可以不用OpenCascade的顯示模塊了,可以使用其他顯示引擎對(duì)形狀進(jìn)行顯示。即若要線框模式顯示形狀時(shí),就繪制離散形狀拓樸邊后得到的多段線;若要實(shí)體渲染模式顯示形狀時(shí),就繪制離散形狀拓樸面得到的三角網(wǎng)格。理解這些概念也有助于理解顯示模塊的實(shí)現(xiàn),及拓樸數(shù)據(jù)中包含的幾何數(shù)據(jù)的意義。

二、程序示例

以下通過(guò)一個(gè)具體程序?qū)嵗瑏?lái)對(duì)OpenCascade中的拓樸邊和拓樸面進(jìn)行離散化。

 

/*
*    Copyright (c) 2013 eryar All Rights Reserved.
*
*           File : Main.cpp
*         Author : eryar@163.com
*           Date : 2013-12-03 18:09
*        Version : 1.0v
*
*    Description : Draw OpenCascade polygon Curves of the edge
*                  and triangulations of the face in OpenSceneGraph.
*                  When you want to display the shape in the computer,
*                  you can not display the geometry exactly, the only
*                  way to show them is in the approximation form.
*
*      Key Words : OpenCascade, polygon curve, triangulation, 
*                  discrete edge, discrete face, OpenSceneGraph, OSG
*                  
*/

// OpenCascade library.
#define WNT
#include 
<gp_Circ.hxx>
#include 
<gp_Elips.hxx>
#include 
<gp_Sphere.hxx>

#include 
<Poly_Polygon3D.hxx>
#include 
<Poly_Triangulation.hxx>

#include 
<TopoDS_Edge.hxx>
#include 
<TopoDS_Face.hxx>

#include 
<BRep_Tool.hxx>
#include 
<BRepMesh.hxx>
#include 
<BRepBuilderAPI_MakeEdge.hxx>
#include 
<BRepBuilderAPI_MakeFace.hxx>

#pragma comment(lib, 
"TKernel.lib")
#pragma comment(lib, 
"TKMath.lib")
#pragma comment(lib, 
"TKBRep.lib")
#pragma comment(lib, 
"TKMesh.lib")
#pragma comment(lib, 
"TKTopAlgo.lib")

// OpenSceneGraph library.
#include <osgDB/ReadFile>
#include 
<osgViewer/Viewer>
#include 
<osgGA/StateSetManipulator>
#include 
<osgViewer/ViewerEventHandlers>

#pragma comment(lib, 
"osgd.lib")
#pragma comment(lib, 
"osgDBd.lib")
#pragma comment(lib, 
"osgGAd.lib")
#pragma comment(lib, 
"osgViewerd.lib")

/*
* @breif Descret the shape: edge.
*        For Edge will be discreted to polylines; (GCPnts_TangentialDeflection)
*        To get the polyline of the edge, use BRep_Tool::Polygon3D(Edge, L);
*/
osg::Node
* BuildPolyline(const TopoDS_Edge& edge, double deflection = 0.1)
{
    osg::ref_ptr
<osg::Geode> geode = new osg::Geode();
    osg::ref_ptr
<osg::Geometry> linesGeom = new osg::Geometry();
    osg::ref_ptr
<osg::Vec3Array> pointsVec = new osg::Vec3Array();

    TopLoc_Location location;

    BRepMesh::Mesh(edge, deflection);
    Handle_Poly_Polygon3D polyline 
= BRep_Tool::Polygon3D(edge, location);

    
for (int i = 1; i < polyline->NbNodes(); i++)
    {
        gp_Pnt point 
= polyline->Nodes().Value(i);

        pointsVec
->push_back(osg::Vec3(point.X(), point.Y(), point.Z()));
    }

    
// Set the color of the polyline.
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    colors
->push_back(osg::Vec4(1.0f1.0f0.0f0.0f));
    linesGeom
->setColorArray(colors.get());
    linesGeom
->setColorBinding(osg::Geometry::BIND_OVERALL);

    
// Set vertex array.
    linesGeom->setVertexArray(pointsVec);
    linesGeom
->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, pointsVec->size()));
    
    geode
->addDrawable(linesGeom.get());

    
return geode.release();
}

/*
* @breif Descret the shape: face.
*        For Face will be discreted to triangles; (BRepMesh_FastDiscret)
*        To get the triangles of the face, use BRep_Tool::Triangulation(Face, L);
*/
osg::Node
* BuildMesh(const TopoDS_Face& face, double deflection = 0.1)
{
    osg::ref_ptr
<osg::Geode> geode = new osg::Geode();
    osg::ref_ptr
<osg::Geometry> triGeom = new osg::Geometry();
    osg::ref_ptr
<osg::Vec3Array> vertices = new osg::Vec3Array();
    osg::ref_ptr
<osg::Vec3Array> normals = new osg::Vec3Array();

    TopLoc_Location location;
    BRepMesh::Mesh(face, deflection);

    Handle_Poly_Triangulation triFace 
= BRep_Tool::Triangulation(face, location);

    Standard_Integer nTriangles 
= triFace->NbTriangles();

    gp_Pnt vertex1;
    gp_Pnt vertex2;
    gp_Pnt vertex3;

    Standard_Integer nVertexIndex1 
= 0;
    Standard_Integer nVertexIndex2 
= 0;
    Standard_Integer nVertexIndex3 
= 0;

    TColgp_Array1OfPnt nodes(
1, triFace->NbNodes());
    Poly_Array1OfTriangle triangles(
1, triFace->NbTriangles());

    nodes 
= triFace->Nodes();
    triangles 
= triFace->Triangles();       

    
for (Standard_Integer i = 1; i <= nTriangles; i++)
    {
        Poly_Triangle aTriangle 
= triangles.Value(i);
        
        aTriangle.Get(nVertexIndex1, nVertexIndex2, nVertexIndex3);

        vertex1 
= nodes.Value(nVertexIndex1).Transformed(location.Transformation());
        vertex2 
= nodes.Value(nVertexIndex2).Transformed(location.Transformation());
        vertex3 
= nodes.Value(nVertexIndex3).Transformed(location.Transformation());

        gp_XYZ vector12(vertex2.XYZ() 
- vertex1.XYZ());
        gp_XYZ vector13(vertex3.XYZ() 
- vertex1.XYZ());
        gp_XYZ normal 
= vector12.Crossed(vector13);
        Standard_Real rModulus 
= normal.Modulus();

        
if (rModulus > gp::Resolution())
        {
            normal.Normalize();
        }
        
else
        {
            normal.SetCoord(
0., 0., 0.);
        }

        
//if (face.Orientable() != TopAbs_FORWARD)
        
//{
        
//    normal.Reverse();
        
//}

        vertices
->push_back(osg::Vec3(vertex1.X(), vertex1.Y(), vertex1.Z()));
        vertices
->push_back(osg::Vec3(vertex2.X(), vertex2.Y(), vertex2.Z()));
        vertices
->push_back(osg::Vec3(vertex3.X(), vertex3.Y(), vertex3.Z()));

        normals
->push_back(osg::Vec3(normal.X(), normal.Y(), normal.Z()));
    }

    triGeom
->setVertexArray(vertices.get());
    triGeom
->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, vertices->size()));

    triGeom
->setNormalArray(normals);
    triGeom
->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    geode
->addDrawable(triGeom);

    
return geode.release();
}

osg::Node
* BuildScene(void)
{
    osg::ref_ptr
<osg::Group> root = new osg::Group();

    gp_Ax2 axis;

    
// 1. Test circle while deflection is default 0.1;
    TopoDS_Edge circleEdge1 = BRepBuilderAPI_MakeEdge(gp_Circ(axis, 6.0));
    root
->addChild(BuildPolyline(circleEdge1));

    
// 2. Test circle while deflection is 0.001.
    axis.SetLocation(gp_Pnt(8.00.00.0));
    axis.SetDirection(gp_Dir(
1.01.01.0));

    TopoDS_Edge circleEdge2 
= BRepBuilderAPI_MakeEdge(gp_Circ(axis, 6.0));
    root
->addChild(BuildPolyline(circleEdge2, 0.001));

    
// 3. Test ellipse while deflection is 1.0.
    TopoDS_Edge ellipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(gp::XOY(), 16.08.0));
    root
->addChild(BuildPolyline(ellipseEdge, 1.0));

    
// 4. Test sphere face while deflection is default 0.1.
    axis.SetLocation(gp_Pnt(26.00.00.0));
    TopoDS_Face sphereFace1 
= BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
    root
->addChild(BuildMesh(sphereFace1));

    
// 5. Test sphere face while deflection is 2.0.
    axis.SetLocation(gp_Pnt(26.018.00.0));
    TopoDS_Face sphereFace2 
= BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
    root
->addChild(BuildMesh(sphereFace2, 2.0));

    
// 6. Test sphere face while deflection is 0.001.
    axis.SetLocation(gp_Pnt(26.0-18.00.0));
    TopoDS_Face sphereFace3 
= BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
    root
->addChild(BuildMesh(sphereFace3, 0.001));

    
return root.release();
}

int main(void)
{
    osgViewer::Viewer myViewer;

    myViewer.setSceneData(BuildScene());

    myViewer.addEventHandler(
new osgGA::StateSetManipulator(myViewer.getCamera()->getOrCreateStateSet()));
    myViewer.addEventHandler(
new osgViewer::StatsHandler);
    myViewer.addEventHandler(
new osgViewer::WindowSizeHandler);

    
return myViewer.run();
}

示例程序測(cè)試了不同的離散精度情況下同一個(gè)形狀的顯示效果,程序結(jié)果如下圖所示:

wps_clip_image-26176

Figure 2.1 Edge and Face representation in OpenSceneGraph

從圖中可知,離散精度越高,離散后得到線上的點(diǎn)或三角網(wǎng)格就越多,顯示越細(xì)膩。

wps_clip_image-26179

Figure 2.2 Edge and Face representation in OpenSceneGraph

其中,邊的離散化使用到了類:GCPnts_TangentialDeflection;面的離散化使用到了類:BRepMesh_FastDiscret。有興趣的讀者可跟蹤調(diào)試,理解其具體實(shí)現(xiàn)的算法。邊的離散應(yīng)該很好理解,面的離散使用了Delauney三角剖分算法。關(guān)于Delauney三角剖分算法的介紹可參考博客:http://m.shnenglu.com/eryar/archive/2013/05/26/200605.aspx

三、結(jié)論

通過(guò)把OpenCascade中的拓樸邊和面離散化用OpenSceneGraph顯示,填補(bǔ)了形狀數(shù)學(xué)精確表示與在計(jì)算機(jī)屏幕上近似顯示之間的隔閡。也有助于理解拓樸結(jié)構(gòu)中包含幾何數(shù)據(jù)的BRep_TFace、BRep_TEdge、BRep_TVertex中除了包含面、邊的精確的參數(shù)表示數(shù)據(jù)外,還包含了用于近似顯示的離散數(shù)據(jù)的意義。

四、參考資料

1. 博客:http://yrcpp.blog.163.com/blog/static/126045259201310199515969/

2. 博客:http://m.shnenglu.com/eryar/archive/2013/05/26/200605.aspx

 

Feedback

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2013-12-06 09:54 by opencascade.net
樓主到http://ask.opencascade.net吧

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2013-12-06 14:26 by eryar
okay
@opencascade.net

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2013-12-15 20:29 by 123523058
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Sphere.hxx>

#include <Poly_Polygon3D.hxx>
#include <Poly_Triangulation.hxx>

#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>

#include <BRep_Tool.hxx>
#include <BRepMesh.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers


這些都沒(méi)有 怎么看呀

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2013-12-15 22:52 by eryar

沒(méi)有安裝OpenCascade和OpenSceneGraph的庫(kù),可以下載安裝一下。
@123523058

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2016-03-05 12:26 by Fei_Love_Nan
博主您好,我看到BRepMesh::Mesh(face, deflection);這個(gè)接口在occ6.8中已經(jīng)去掉了,那再6.8中如何實(shí)現(xiàn)這步操作呢?

# re: OpenCascade Shape Representation in OpenSceneGraph  回復(fù)  更多評(píng)論   

2016-03-05 18:27 by eryar
@Fei_Love_Nan
Hi,

您好!

可以參考這里的回復(fù):
http://m.shnenglu.com/eryar/archive/2013/05/26/200605.aspx#208954
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产一区二区黄色| 亚洲欧美国产日韩中文字幕| 久久女同精品一区二区| 午夜一区在线| 午夜精品久久久久久久久| 亚洲——在线| 老司机午夜精品视频在线观看| 亚洲国产一区二区a毛片| 国产一区二区三区久久久久久久久 | 欧美精品在线免费| 欧美乱妇高清无乱码| 亚洲欧美综合另类中字| 亚洲免费在线视频| 欧美一区二区久久久| 午夜精品久久久久影视| 欧美一区不卡| 欧美电影在线观看| 国产视频一区在线观看| 久久精品亚洲热| 美日韩精品免费| 亚洲免费观看高清完整版在线观看熊| 99国产精品国产精品久久| 中文久久乱码一区二区| 久久精品国产欧美亚洲人人爽| 免播放器亚洲一区| 国产精品网站一区| 亚洲国产欧美国产综合一区| 91久久精品一区二区别| 国产拍揄自揄精品视频麻豆| 亚洲高清电影| 翔田千里一区二区| 女人色偷偷aa久久天堂| 亚洲网站在线播放| 国产欧美日韩一级| 蜜臀91精品一区二区三区| 久久人体大胆视频| 亚洲日本视频| 小处雏高清一区二区三区 | 在线一区日本视频| 久久精品久久99精品久久| 欧美日韩亚洲成人| 亚洲欧洲日韩在线| 久久五月天婷婷| 亚洲永久精品国产| 欧美日韩精品免费观看| 在线观看三级视频欧美| 午夜精品亚洲一区二区三区嫩草| 亚洲福利视频网站| 欧美呦呦网站| 国产伦精品一区二区三| 亚洲视频在线看| 亚洲国产欧美在线人成| 久久婷婷av| 一区二区亚洲欧洲国产日韩| 欧美自拍丝袜亚洲| 亚洲男女自偷自拍图片另类| 欧美视频中文字幕在线| 日韩视频一区二区| 欧美国产精品久久| 你懂的网址国产 欧美| 亚洲经典一区| 亚洲电影免费在线 | 亚洲视频在线一区观看| 欧美搞黄网站| 亚洲欧洲一区二区在线播放| 噜噜噜躁狠狠躁狠狠精品视频 | 亚洲第一区中文99精品| 羞羞色国产精品| 亚洲综合色婷婷| 欧美日韩成人网| 亚洲国产精品热久久| 欧美**字幕| 美女国内精品自产拍在线播放| 加勒比av一区二区| 久热综合在线亚洲精品| 久久久夜色精品亚洲| 亚洲欧洲视频| 日韩一区二区精品| 国产精品嫩草久久久久| 久久精品国产精品| 久久亚洲精品欧美| 亚洲精品一区二区三区樱花| 亚洲国产视频一区二区| 欧美激情一区二区三级高清视频 | 国产精品乱看| 午夜精品视频| 久久er精品视频| 亚洲人成欧美中文字幕| av成人免费在线| 国产日韩精品视频一区二区三区| 欧美一二区视频| 久久全球大尺度高清视频| 一本久久综合亚洲鲁鲁| 亚洲欧美视频| 亚洲精品欧美日韩| 亚洲自拍偷拍麻豆| 在线日本成人| 中文一区字幕| 亚洲大胆女人| 亚洲图片欧美午夜| 亚洲国产精品久久久| 亚洲视频一区二区| 在线观看亚洲视频| 亚洲无限av看| 亚洲人在线视频| 欧美一级成年大片在线观看| 99re热这里只有精品免费视频| 亚洲欧美日本另类| 亚洲美女免费精品视频在线观看| 午夜精品久久| 宅男精品视频| 蜜桃av综合| 欧美在线精品一区| 欧美黄色免费网站| 久久久蜜臀国产一区二区| 欧美日韩一区在线| 欧美91福利在线观看| 国产精品一香蕉国产线看观看| 亚洲国产片色| 亚洲国产综合在线| 久久精品夜色噜噜亚洲aⅴ| 亚洲一区成人| 欧美人体xx| 欧美h视频在线| 国产欧美日韩高清| 老牛影视一区二区三区| 国产亚洲一区精品| 99这里有精品| 日韩视频在线观看国产| 久久久人成影片一区二区三区观看| 亚洲欧美日韩中文视频| 欧美精品国产| 亚洲国产精品久久久久秋霞影院| 韩国三级在线一区| 欧美一区二区视频免费观看| 欧美一区二区三区日韩| 国产精品日韩一区二区| 亚洲最新在线视频| 亚洲一区二区成人| 国产精品久久久久久久浪潮网站| 一本到12不卡视频在线dvd| 亚洲深夜福利视频| 国产精品成人播放| 亚洲香蕉视频| 久久www成人_看片免费不卡| 国产女主播一区二区三区| 午夜精品久久| 久久中文字幕一区| 亚洲国产精品电影在线观看| 国产一区二区欧美日韩| 在线日本成人| 午夜一区二区三区不卡视频| 亚洲制服丝袜在线| 欧美亚州一区二区三区| 99视频在线观看一区三区| 日韩视频―中文字幕| 欧美精品在线播放| 一二三四社区欧美黄| 午夜精品久久久久久久白皮肤| 国产精品久久久久aaaa樱花| 亚洲调教视频在线观看| 久久国产婷婷国产香蕉| 在线看日韩av| 欧美激情一区在线观看| 亚洲一区二区视频在线| 久久综合九色九九| 亚洲精品在线免费| 国产精品毛片高清在线完整版| 午夜欧美不卡精品aaaaa| 毛片基地黄久久久久久天堂| 99视频精品全国免费| 国产嫩草一区二区三区在线观看 | 欧美国产日韩一区二区三区| 亚洲国产老妈| 欧美日韩一区二区在线观看视频| 亚洲午夜久久久| 久久综合久久久| 一本色道久久综合亚洲91| 国产精品有限公司| 另类天堂av| 一区二区三区国产精华| 欧美1区3d| 小黄鸭精品aⅴ导航网站入口| 伊人成人开心激情综合网| 欧美日韩国产综合视频在线观看 | 精品91在线| 久久不射电影网| 亚洲字幕一区二区| 久久电影一区| 亚洲欧美激情一区| 久久亚洲综合网| 亚洲午夜精品视频| 一区二区在线视频观看| 国产精品福利网站| 久久综合精品国产一区二区三区| 亚洲视频第一页| 亚洲人成亚洲人成在线观看图片| 欧美在线视屏| 亚洲午夜精品在线| 99精品国产在热久久婷婷|