VCGlib入门记录一

来源:互联网 发布:霸业传奇降级转生数据 编辑:程序博客网 时间:2024/05/23 19:19

1、今天遇到obj文件打不开的问题,主要是在这一步,验证为0,跳过了读取步骤。

“if (header.rfind("OFF") != std::basic_string<char>::npos)”

查一查npos是个什么鬼?

basic_string::npos

static const size_type npos = -1;

The constant is the largest representable value of type size_type. It is assuredly larger than max_size(); hence it serves as either a very large value or as a special code.

也有通俗的解释:npos是一个常数,用来表示不存在的位置,类型一般是std::container_type::size_type,许多容器都提供这个东西。取值由实现决定,一般是-1,这样做,就不会存在移植的问题了。

2、

rfind全名reversefind

与find相反,

[cpp] view plaincopy
  1. size_type rfind( const basic_string &str, size_type index );  
  2. size_type rfind( const char *str, size_type index );  
  3. size_type rfind( const char *str, size_type index, size_type num );  
  4. size_type rfind( char ch, size_type index );  

 

rfind()函数:

  • 返回最后一个与str中的某个字符匹配的字符,从index开始查找。如果没找到就返回string::npos
  • 返回最后一个与str中的某个字符匹配的字符,从index开始查找,最多查找num个字符。如果没找到就返回string::npos
  • 返回最后一个与ch匹配的字符,从index开始查找。如果没找到就返回string::npos
3、发现vcg::tri::io::ImporterOFF<MyMesh>::Open(m, argv[1])函数 打开的底层代码是针对OFF文件,而非OBJ文件,
OFF,Object File Format,即物体文件格式,是一种三维模型文件格式。

物体文件格式(.off)文件通过描述物体表面的多边形来表示一个模型的几何结构,这里的多边形可以有任意数量的顶点。

普林斯顿形状 Banchmark(Princeton Shape Benchmark)中的 .off 文件遵循以下标准:

  • OFF文件全是以OFF关键字开始的ASCII文件。
  • 下一行说明顶点的数量、面片的数量、边的数量。边的数量可以安全地省略。
  • 顶点按每行一个列出x、y、z坐标。
  • 在顶点列表后,面片按照每行一个列表,对于每个面片,顶点的数量是指定的,接下来是顶点索引列表。

详见 一个立方体的简单例子 cube.off:
  OFF
  顶点数 面片数 边数
  x y z
  x y z
  ...
  n个顶点 顶点1的索引 顶点2的索引 … 顶点n的索引
  ...
注意:顶点标号是从0开始(不是从1开始)的,边数总是0。
代码:
*****************************cube.off****************************************
OFF
8 12 0
-0.274878 -0.274878 -0.274878
-0.274878  0.274878 -0.274878
 0.274878  0.274878 -0.274878
 0.274878 -0.274878 -0.274878
-0.274878 -0.274878  0.274878
-0.274878  0.274878  0.274878
 0.274878  0.274878  0.274878
 0.274878 -0.274878  0.274878
3  0 1 3
3  3 1 2
3  0 4 1
3  1 4 5
3  3 2 7
3  7 2 6
3  4 0 3
3  7 4 3
3  6 4 7
3  6 5 4
3  1 5 6
3  2 1 6

0 0
原创粉丝点击