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

eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 603, comments - 590, trackbacks - 0, articles - 0

OpenCascade Shape Representation in OpenSceneGraph

Posted on 2013-12-04 21:45 eryar 閱讀(6011) 評論(6)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

OpenCascade Shape Representation in OpenSceneGraph

eryar@163.com

摘要Abstract:本文通過程序實例,將OpenCascade中的拓樸數據(邊、面)離散化后在OpenSceneGraph中進行顯示。有了這些離散數據,就可以不用OpenCascade的顯示模塊了,可以使用其他顯示引擎對形狀進行顯示。即若要線框模式顯示形狀時,就繪制離散形狀拓樸邊后得到的多段線;若要實體渲染模式顯示形狀時,就繪制離散形狀拓樸面得到的三角網格。理解這些概念也有助于理解顯示模塊的實現,及拓樸數據中包含的幾何數據的意義。

關鍵字 Key Words:OpenCascade, polygon curve, triangulation,discrete edge, discrete face,  OpenSceneGraph, OSG

一、引言 Introduction

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

以前看《計算機圖形學》相關的書時,從數學概念到具體實現的橋梁總是無法銜接。現在,通過學習OpenCascade,終于把這些都串起來了。正如上面網友所說,面和邊要在OpenGL中顯示出來就需要離散化,即把邊離散為多段線,把面離散為三角網格。這樣就可以把用參數精確表示的幾何數據在計算機布滿像素點的屏幕上逼近顯示了。

本文通過程序實例,將OpenCascade中的拓樸數據(邊、面)離散化后在OpenSceneGraph中進行顯示。有了這些離散數據,就可以不用OpenCascade的顯示模塊了,可以使用其他顯示引擎對形狀進行顯示。即若要線框模式顯示形狀時,就繪制離散形狀拓樸邊后得到的多段線;若要實體渲染模式顯示形狀時,就繪制離散形狀拓樸面得到的三角網格。理解這些概念也有助于理解顯示模塊的實現,及拓樸數據中包含的幾何數據的意義。

二、程序示例

以下通過一個具體程序實例,來對OpenCascade中的拓樸邊和拓樸面進行離散化。

 

/*
*    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();
}

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

wps_clip_image-26176

Figure 2.1 Edge and Face representation in OpenSceneGraph

從圖中可知,離散精度越高,離散后得到線上的點或三角網格就越多,顯示越細膩。

wps_clip_image-26179

Figure 2.2 Edge and Face representation in OpenSceneGraph

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

三、結論

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

四、參考資料

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  回復  更多評論   

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

# re: OpenCascade Shape Representation in OpenSceneGraph  回復  更多評論   

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

# re: OpenCascade Shape Representation in OpenSceneGraph  回復  更多評論   

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


這些都沒有 怎么看呀

# re: OpenCascade Shape Representation in OpenSceneGraph  回復  更多評論   

2013-12-15 22:52 by eryar

沒有安裝OpenCascade和OpenSceneGraph的庫,可以下載安裝一下。
@123523058

# re: OpenCascade Shape Representation in OpenSceneGraph  回復  更多評論   

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

# re: OpenCascade Shape Representation in OpenSceneGraph  回復  更多評論   

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

您好!

可以參考這里的回復:
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>
            欧美成人国产| 日韩一区二区福利| 欧美高清在线一区| 91久久黄色| 亚洲精品永久免费| 亚洲精品久久| 国产精品久久久久三级| 性伦欧美刺激片在线观看| 久久精品国产第一区二区三区最新章节| 亚洲精品一区二区网址 | 国产精品久久久久婷婷| 亚洲一级高清| 亚洲第一成人在线| 一本大道久久a久久精品综合| 欧美天天影院| 欧美一区二区三区久久精品| 欧美在线视频不卡| 亚洲一区欧美一区| 一本色道久久综合| 亚洲精品影视在线观看| 99视频在线观看一区三区| 国产一区二区三区在线观看免费| 亚洲伦理网站| 国产农村妇女毛片精品久久麻豆| 欧美二区在线播放| 午夜精品美女久久久久av福利| 一本久久综合| 亚洲中字黄色| 欧美伊久线香蕉线新在线| 亚洲一区区二区| 亚洲欧美国产制服动漫| 一本久道久久综合婷婷鲸鱼| 亚洲欧洲综合另类在线| 一区二区免费看| 国产精品久久久久一区| 欧美精品日韩三级| 久久一综合视频| 欧美日韩精品久久久| 欧美电影电视剧在线观看| 中文日韩在线视频| 欧美成人69av| 日韩视频精品| 久久久噜噜噜久久中文字免| 亚洲欧美另类综合偷拍| 农村妇女精品| 亚洲国产91精品在线观看| 亚洲自拍偷拍麻豆| 久久一区二区视频| 欧美日韩高清在线| 99视频精品| 久久久一二三| 免费人成精品欧美精品| 免费试看一区| 亚洲激情黄色| 欧美日韩亚洲一区二区三区| 麻豆国产精品va在线观看不卡| 欧美一区二区视频97| 欧美丰满少妇xxxbbb| 国产老肥熟一区二区三区| 在线观看成人av电影| 亚洲欧美国产精品专区久久| 亚洲清纯自拍| 欧美va亚洲va国产综合| 欧美性一区二区| 亚洲看片网站| 精品成人一区二区三区| 国产性色一区二区| 亚洲另类在线视频| 亚洲综合视频在线| 亚洲国产精品一区二区尤物区 | 欧美激情精品久久久久久大尺度| 韩国一区二区三区在线观看| 国产精品99久久久久久宅男| 亚洲黄色尤物视频| 欧美一级成年大片在线观看| 久久午夜羞羞影院免费观看| 欧美午夜精品久久久久久超碰| 美女日韩在线中文字幕| 欧美日韩成人在线视频| 亚洲动漫精品| 老司机精品视频网站| 欧美激情精品久久久久久大尺度| 久久久久国内| 欧美1区2区| 99精品视频免费观看| 欧美日韩精品三区| 99热这里只有成人精品国产| 在线性视频日韩欧美| 国产精品国产三级国产专区53 | 免费欧美网站| 免费国产自线拍一欧美视频| 美女视频黄a大片欧美| 欧美一区二区三区免费视| 国产伦精品一区二区三区视频黑人 | 99精品国产在热久久下载| 中文精品视频一区二区在线观看| 国产美女高潮久久白浆| 香港久久久电影| 国产精品天天看| 久久精品国产精品亚洲精品| 欧美一区二区三区在线看| 欧美视频在线一区| 亚洲欧美一区二区原创| 久久字幕精品一区| 久久偷看各类wc女厕嘘嘘偷窃| 亚洲免费激情| 国外精品视频| 老司机午夜精品视频| 亚洲三级性片| 噜噜噜躁狠狠躁狠狠精品视频| 国产精品欧美日韩久久| 国产欧美91| av成人免费在线观看| 欧美大色视频| 亚洲看片免费| 欧美.www| 久久国产精品久久w女人spa| 欧美精品日韩一本| 久久夜色精品国产欧美乱| 欧美一区二区国产| 亚洲欧美乱综合| 亚洲欧美日韩久久精品| 亚洲国产精品久久精品怡红院| 亚洲视频www| 久久精品日韩欧美| 伊人成人在线| 欧美国产在线观看| 亚洲精品国产精品国自产观看| 国产一区二区三区直播精品电影| 久久久999国产| 99re热这里只有精品免费视频| 国产精品国产福利国产秒拍| 亚洲综合电影| 午夜精品短视频| 国产视频一区三区| 性欧美激情精品| 国产亚洲一本大道中文在线| 蜜桃视频一区| 欧美精品午夜视频| 欧美一区二区三区精品电影| av成人免费在线| 美女精品视频一区| 亚洲女性喷水在线观看一区| 亚洲精品九九| 99国产精品久久久| 欧美激情亚洲精品| 欧美一区二区在线观看| 久久欧美中文字幕| 日韩视频在线免费观看| 鲁大师影院一区二区三区| 一本色道久久88综合亚洲精品ⅰ| 欧美国产一区视频在线观看| 国语自产精品视频在线看8查询8| 麻豆国产精品一区二区三区| 免费成人av在线| 亚洲欧美日本在线| 久久精品伊人| 久久久99久久精品女同性| 性色一区二区| 欧美四级剧情无删版影片| 国产欧美精品va在线观看| 在线观看成人av| 一区二区三区欧美在线观看| 亚洲男人第一av网站| 亚洲欧美日韩精品久久| 欧美激情一区三区| 亚洲——在线| 欧美18av| 午夜在线观看免费一区| 国产精品美女| 亚洲图中文字幕| 国产曰批免费观看久久久| 久久综合九色九九| 久久一区二区精品| 国产日韩欧美综合一区| 久久手机免费观看| 毛片一区二区三区| 红桃视频国产精品| 欧美韩国在线| 久久精品免费播放| 国产一区在线看| 久久久www成人免费无遮挡大片| 亚洲精品久久久久久久久| 亚洲欧洲视频在线| 亚洲一区二区影院| 久久精品在线视频| 久久久久久穴| 国产精品伦子伦免费视频| 美日韩精品视频| 国内精品久久久久久久97牛牛| 一区二区三区|亚洲午夜| 久久久久看片| 国产一区视频在线看| 免费欧美日韩国产三级电影| 亚洲第一黄网| 免费一区二区三区| 激情偷拍久久| 国产精品亚洲综合一区在线观看| 一区二区不卡在线视频 午夜欧美不卡在 | 久久九九精品99国产精品|