Visualization of Curves and Surfaces in OpenSceneGraph

简介: Visualization of Curves and Surfaces in OpenSceneGraph eryar@163.com 君子性非异也,善假于物也。 在学习计算机辅助几何造型(CAGD)等内容时,总是想把NURBS曲线、曲面显示出来,这样才能领会其中的奥妙。

Visualization of Curves and Surfaces in OpenSceneGraph

eryar@163.com

君子性非异也,善假于物也。

在学习计算机辅助几何造型(CAGD)等内容时,总是想把NURBS曲线、曲面显示出来,这样才能领会其中的奥妙。而现在大部分的教材都只是给出定理及其相关性质的证明,编程实现曲线及曲面显示的书籍很少。

OpenSceneGraph是使用OpenGL技术开发的一套C++编程接口,借助这个工具可以让程序员能够更加快速、便捷的创建高性能、跨平台的交互图形程序。使用OpenSceneGraph可以让程序员只关注其算法,显示部分都由OSG来完成。osgViewer完成了视图操作的大部分功能,如旋转、缩放、移动,另外还有统计功能。

利用OpenSceneGraph中的基本几何图元即OpenGL中的基本几何图元,如GL_LINE_STRIP、GL_TRIANGLE_STRIP等可以将计算的曲线、曲面显示出来,使曲线曲面的概念更形象,便于理解。

以下代码所示为一个简单例子,就这么几行代码,实现了场景的渲染及用户对视图的大部分操作,如缩放、旋转、移动及统计场景中图元信息,还可以用F键在窗口与全屏之间切换,W键使模型在线框、面、点之间切换,S键出现统计数据。

 

 1  /*
 2  *    Copyright (c) 2013 eryar All Rights Reserved.
 3  *
 4  *        File    : Main.cpp
 5  *        Author  : eryar@163.com
 6  *        Date    : 2013-03-22 22:31
 7  *        Version : V1.0
 8  *
 9  *    Description : OpenSceneGraph demo program.              
10  *
11  */
12 
13  #include  < osgDB / ReadFile >
14  #include  < osgViewer / Viewer >
15  #include  < osgGA / StateSetManipulator >
16  #include  < osgViewer / ViewerEventHandlers >
17 
18  #pragma comment(lib,  " osgd.lib " )
19  #pragma comment(lib,  " osgDBd.lib " )
20  #pragma comment(lib,  " osgGAd.lib " )
21  #pragma comment(lib,  " osgViewerd.lib " )
22 
23  int  main( int  argc,  char *  argv[])
24  {
25      osgViewer::Viewer viewer;
26      viewer.setSceneData(osgDB::readNodeFile( " cessna.osg " ));
27 
28      viewer.addEventHandler( new  osgGA::StateSetManipulator(viewer.getCamera() -> getOrCreateStateSet()));
29      viewer.addEventHandler( new  osgViewer::StatsHandler);
30      viewer.addEventHandler( new  osgViewer::WindowSizeHandler);
31 
32       return  viewer.run();
33  }


程序显示效果如下图所示:

wps_clip_image-19685

 

目录
相关文章
|
算法
Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCASCADE algorithms to approximate the NURBS curve to arc spline.
1534 0
|
C++ 算法
OpenCASCADE BRep Projection
OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上。
1757 0
|
图形学
OpenCASCADE Coordinate Transforms
OpenCASCADE Coordinate Transforms eryar@163.com Abstract. The purpose of the OpenGL graphics processing pipeline is to convert 3D descriptions of objects into a 2D image that can be displayed.
1526 0
|
算法 数据可视化 Shell
OpenCASCADE Linear Extrusion Surface
OpenCASCADE Linear Extrusion Surface eryar@163.com Abstract. OpenCASCADE linear extrusion surface is a generalized cylinder.
1314 0
|
算法
OpenCASCADE Conic to BSpline Curves-Hyperbola
OpenCASCADE Conic to BSpline Curves-Hyperbola eryar@163.com Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .
1135 0
|
存储 算法 BI
OpenCASCADE Conic to BSpline Curves-Circle
OpenCASCADE Conic to BSpline Curves-Circle eryar@163.com Abstract. The conic sections and circles play a fundamental role in CAD/CAM applications.
1482 0
|
C语言 Windows 开发工具
OpenCASCADE Conic to BSpline Curves-Parabola
OpenCASCADE Conic to BSpline Curves-Parabola eryar@163.com Abstract. Rational Bezier Curve can represent conic curves such as circle, ellipse, hyperbola, .
1043 0
OpenCASCADE Rational Bezier Curves
OpenCASCADE Rational Bezier Curves eryar@163.com Abstract. Although polynomials offer many advantages, there exist a number of important curve and...
1265 0
OpenCASCADE Gauss Integration
OpenCASCADE Gauss Integration eryar@163.com Abstract. Numerical integration is the approximate computation of an integral using numerical techniques.
1322 0
|
算法 机器人 vr&ar
Visulalize Voronoi in OpenSceneGraph
Visulalize Voronoi in OpenSceneGraph eryar@163.com Abstract. In mathematics a Voronoi diagram is a way of dividing space into a number of regions.
981 0

热门文章

最新文章