struct Subset
{
std::vector<float> vertexs;//位置
std::vector<float> normals;//法向
std::vector<float> texCoords;//纹理
std::vector<unsigned int> indices;//索引下标
std::vector<unsigned int> faceMtrls;//面材质索引
}; class GetSimplifySTLDataVisitor : public osg::NodeVisitor
{
public:
GetSimplifySTLDataVisitor(Subset &s):dstSubset(s),
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
} virtual void apply(osg::Geode& geode)
{
unsigned int count = geode.getNumDrawables();
for ( unsigned int i = ; i < count; i++ )
{
osg::Geometry *geometry = geode.getDrawable( i )->asGeometry();
if ( !geometry )
continue;
// 顶点数据
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
int vertexlNum = vertices->size();
for ( int i=; i<vertexlNum; i++) {
dstSubset.vertexs.push_back( vertices->at(i).x() );
dstSubset.vertexs.push_back( vertices->at(i).y() );
dstSubset.vertexs.push_back( vertices->at(i).z() );
}
// 法向量
osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(geometry->getNormalArray());
int normalNum = normals->size();
for (int i=; i<normalNum; i++) {
dstSubset.normals.push_back( normals->at(i).x() );
dstSubset.normals.push_back( normals->at(i).y() );
dstSubset.normals.push_back( normals->at(i).z() );
}
normalBindKinds.insert(geometry->getNormalBinding());
if(osg::Geometry::BIND_PER_VERTEX != geometry->getNormalBinding() )
{
std::string msg="未处理的法向量绑定方式";
MessageBox(, LPCTSTR(msg.c_str()), "警告", MB_OK);
}
// 索引数组
for ( unsigned int i = ; i < geometry->getNumPrimitiveSets(); ++i )
{
osg::PrimitiveSet* ps = geometry->getPrimitiveSet( i );
if ( !ps ) continue;
pts.insert(ps->getType());
modes.insert(ps->getMode());
switch( ps->getType() )
{
case osg::PrimitiveSet::DrawElementsUIntPrimitiveType :
{
osg::DrawElementsUInt* deui = dynamic_cast<osg::DrawElementsUInt*>(ps);
const unsigned indexNum = deui->getNumIndices();
switch( deui->getMode() )
{
case osg::PrimitiveSet::TRIANGLES :
{
for (unsigned int i=; i<indexNum; i++)
{
dstSubset.indices.push_back( deui->at(i) );
}
break;
}
default:
{
std::string msg="未处理的绘制模式";
MessageBox(, LPCTSTR(msg.c_str()), "警告", MB_OK);
}
}
break;
}
case osg::PrimitiveSet::DrawElementsUShortPrimitiveType :
{
osg::DrawElementsUShort* de = dynamic_cast<osg::DrawElementsUShort*>(ps);
const unsigned indexNum = de->getNumIndices();
switch( de->getMode() )
{
case osg::PrimitiveSet::TRIANGLES :
{
for (unsigned int i=; i<indexNum; i++)
{
dstSubset.indices.push_back( de->at(i) );
}
break;
}
case osg::PrimitiveSet::TRIANGLE_STRIP :
{
for (unsigned int i=; i<indexNum-; i++)
{
//此处索引为何与基数偶数有关,可百度GL_TRIANGLE_STRIP
if (i%==)
{
dstSubset.indices.push_back( de->at(i) );
dstSubset.indices.push_back( de->at(i+) );
dstSubset.indices.push_back( de->at(i+) );
}
else
{
dstSubset.indices.push_back( de->at(i) );
dstSubset.indices.push_back( de->at(i+) );
dstSubset.indices.push_back( de->at(i+) );
}
}
break;
}
default:
{
std::string msg="未处理的绘制模式";
MessageBox(, LPCTSTR(msg.c_str()), "警告", MB_OK);
}
}
break;
}
case osg::PrimitiveSet::DrawArraysPrimitiveType :
{
osg::DrawArrays* da = dynamic_cast<osg::DrawArrays*>(ps);
int first=da->getFirst();
int count=da->getCount();
switch( da->getMode() )
{
case osg::PrimitiveSet::TRIANGLES :
{
for ( int i=first; i<first+count; i++) {
dstSubset.indices.push_back( i );
}
break;
}
case osg::PrimitiveSet::TRIANGLE_STRIP :
{
for ( int i=first; i<first+count-; i++) {
if(i%==)
{
dstSubset.indices.push_back( i );
dstSubset.indices.push_back( i+ );
dstSubset.indices.push_back( i+ );
}
else
{
dstSubset.indices.push_back( i );
dstSubset.indices.push_back( i+ );
dstSubset.indices.push_back( i+ );
}
}
break;
}
default:
{
std::string msg="未处理的绘制模式";
MessageBox(, LPCTSTR(msg.c_str()), "警告", MB_OK);
}
}
break;
}
default:
{
std::string msg="未处理的图元类型";
MessageBox(, LPCTSTR(msg.c_str()), "警告", MB_OK);
}
}
}
}
}
private:
Subset &dstSubset;
//以下三个数组用来测试
std::set<osg::Geometry::AttributeBinding> normalBindKinds;
std::set<osg::PrimitiveSet::Type> pts;
std::set<GLenum> modes;
};

NodeVisitor的使用-遍历Geode节点下的Geometry并获取顶点、法向量等数据的更多相关文章

  1. NodeVisitor的使用-遍历Geode节点并在它与父节点之间添加一个LOD节点

    #include <osg\NodeVisitor>#include <osg\MatrixTransform>#include <osg\PagedLOD>#in ...

  2. PHP遍历文件夹下的文件和获取到input name的值

    <?php$dir = dirname(__FILE__); //要遍历的目录名字 ->当前文件所在的文件夹//$dir='D:\PHP\wamp\www\admin\hosts\admi ...

  3. Extjs4.x Ext.tree.Panel 遍历当前节点下的所有子节点

    Ext.define('WMS.controller.Org', { extend: 'Ext.app.Controller', stores: ['OrgUser', 'OrgTree'], mod ...

  4. PAT树_层序遍历叶节点、中序建树后序输出、AVL树的根、二叉树路径存在性判定、奇妙的完全二叉搜索树、最小堆路径、文件路由

    03-树1. List Leaves (25) Given a tree, you are supposed to list all the leaves in the order of top do ...

  5. VBS获取Ini配置文件一个节点下的所有字段的值

    ''* 功能:使用VBS读取ini文件中指定节点下的所有值'* 输入参数:inipath :ini文件的地址'*           initypes :ini文件中包含在"["和 ...

  6. 遍历树节点(多层)的方法(java)

    前序遍历,后序遍历,广度遍历,深度遍历,遍历一级节点.以及按钮如何响应点击事件. import java.awt.*; import java.awt.event.*; import java.uti ...

  7. asp.net 遍历文件夹下全部子文件夹并绑定到gridview上

    遍历文件夹下所有子文件夹,并且遍历配置文件某一节点中所有key,value并且绑定到GridView上 Helper app_Helper = new Helper(); DataSet ds = n ...

  8. 记录JS如何使用广度遍历找到节点的所有父节点

    我们在实际的工作业务场景中经常遇到这样的场景,求取树数据中某个节点的父亲节点以及所有的父亲节点,这样的场景下不建议使用深度遍历,使用广度遍历可以更快找到. 1.案例解说 比如树的长相是这样的: 树的数 ...

  9. C#遍历文件夹下所有文件

    FolderForm.cs的代码如下: using System; using System.Collections.Generic; using System.Diagnostics; using ...

随机推荐

  1. IGV软件

    它支持各种各样的数据类型,包括基于芯片测序.二代测序数据和基因组注释数据等.整合基因组浏览器(IGV,Integrative Genomics Viewer)进行可视化浏览,它支持各种各式的数据类型, ...

  2. Spring的问题解决记录

    问题:在MyEclipse中项目工程重命名以后,例如 原来叫HttpService,改为GameApp,但是项目跑起来发现,tomcat服务器依旧为GameApp目录结构,访问也只能GameApp访问 ...

  3. http之错误码

    http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型 ...

  4. Java File 常用操作回顾

    最近项目中要用到File这个类,温故而知新,回过头来回顾下这个File类,File类主要是对磁盘目录,文件进行操作的Api,具体其实查JDK api 的File全能获取到. 下面写一些文件目录的基本操 ...

  5. /etc/bashrc和/etc/profile傻傻分不清楚?

    导读 在一般的 linux 或者 unix 系统中, 都可以通过编辑 bashrc 和 profile来设置用户的工作环境, 很多文章对于 profile 和 bashrc 也都有使用, 但究竟每个文 ...

  6. 添加Mysql到Windows系统服务

    下载了免安装版的MySQL后,将压缩包加压.到这一步mysql还不能工作,我们还需要做一些工作: 1.     安装mysql服务 新建一个批处理文件StartMysql.bat,文件内容如下: @E ...

  7. HDU 1710 二叉树三种遍历

    Binary Tree Traversals Problem Description A binary tree is a finite set of vertices that is either ...

  8. OI总结(垃圾排版就忽略了吧)

    学OI一年了,到现在联赛所需要的知识已经基本学完了.现在,有必要回过头来,总结总结自己一年来学到的知识以及得到的经验教训. 基础 语言基础 C++的语言基础啥的就略了吧. 算法复杂度分析 O:复杂度的 ...

  9. PyQt4关闭最大化最小化取消双击最大化

    self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...

  10. 泛型约束 where T : class,new()

    假如有这样一个方法签名 public List<T> GetSomethingList<T> (int a,int b,string c) where T:class,new( ...