现在的位置: 首页 > 综合 > 正文

vs2010配置trimesh2-2.10和rtsc-1.5

2013年08月14日 ⁄ 综合 ⁄ 共 6001字 ⁄ 字号 评论关闭
文章目录

 

trimesh2是一个开源的网格三维模型库,支持PLYOFFOBJ 等三维模型文件的读写,查看、拼接等操作,为学习和研究提供了有用的工具。更多关于trimesh2的信息见官网

trimesh2windows下编译时常出现各种错误,并且官方尚未提供使用vs2010编译的源码,给trimesh2的使用者带来了麻烦。本文使用vs2010配置目前最新版本trimesh2-2.10

获取源码:

最新版的trimesh2trimesh2-2.10.zip

说明:trimesh2-2.10.zip中包含了freeglutglui和本身的trimesh三个库。trimesh2-2.10使用的glui版本为2.01f,并添加了glui_add_controls.cc等内容,trimesh2-2.10提供的demo中只需编译freeglut库,其自带的glui库在编译rtsc时才需编译。本文配置仅使用trimesh2-2.10.zip文件即可。

编译trimesh2静态链接库项目:

一、创建项目

1、打开Microsoft Visual Studio 2010,选择File->New->Project

2、在New Project中选择Installed Templates->Visual C++->Win32

3、选择Win32 Console Application,设置名称:trimesh,设置解决方案名:trimesh2

4、单击OK,在出现的Win32 Application WizardOverview对话框中点击Next

5、在Application Settings中,选择Application type下的Static library。

6、勾选Additional options下的Empty project

7、单击Finish创建项目。

二、添加源码

1、解压trimesh2-2.10.zip,将~\trimesh2\include文件夹拷贝到刚才新建的项目路径路径~\trimesh2\之下。

2、将~\trimesh2\libsrc\目录下的所有文件拷贝到项目路径~\trimesh2\trimesh\之下。

3、右键单击项目,将~\trimesh2\trimesh\目录下刚才拷贝的所有.cc文件添加到项目中。

4、右键单击项目,选择属性,在VC++ Directories下的Include Directories中添加$(SolutionDir)include

5、在项目路径~\trimesh2\下新建文件夹binlibbin存放可执行文件,lib存放库文件。

6、右键单击项目,选择属性,将Configuration Properties->General下的Output Directory值改为$(SolutionDir)lib

7、单击应用,确定,添加完毕。

三、编译trimesh2

右键单击项目,Build,生成链接库,若没有错误并且~\trimesh2\lib目录下出现trimesh.lib文件,则编译成功。

编译freeglut动态链接库项目:

一、创建项目

1、在New Project中选择Installed Templates->Visual C++->Win32

2、选择Win32 Console Application,设置名称:freeglutAdd to solution

3、单击OK,在出现的Win32 Application WizardOverview对话框中点击Next

4、在Application Settings中,选择Application type下的Console application

5、取消Additional options下的Precompiled header,勾选Empty project

6、单击Finish创建项目。

二、添加源码

1、将~\trimesh2\gluit\目录下的所有以freeglut_开头的文件拷贝到项目路径~\trimesh2\freeglut\之下。注意源码gluit中包含了freeglut库文件和glui库文件,此处仅编译freeglut

2、单击freeglut项目,将~\trimesh2\freeglut\目录下刚才拷贝的所有.h.cc文件添加到项目中。

3、单击freeglut项目,选择Add->Existing Item,将~\trimesh2\include\GL目录下的freeglut.hfreeglut_ext.hfreeglut_std.hglut.h添加到项目中来。

4 右键单击freeglut项目,选择属性,在VC++ Directories下的Include Directories中添加$(SolutionDir)include

5、右键单击freeglut项目,选择属性,将Configuration Properties->General下的Output Directory值改为$(SolutionDir)lib

6、单击应用,确定,添加完毕。

三、编译freeglut

此时若编译项目,则会出现链接错误: cannot open file 'freeglut_static.lib'

解决方法为:将freeglut_std.h 文件头中的宏定义#define FREEGLUT_STATIC注释掉。

重新编译通过,~\trimesh2\lib目录下出现freeglut.libfreeglut.dll

创建mesh_view项目进行测试:

一、创建项目

1、选择File->New->Project

2、在New Project中选择Installed Templates->Visual C++->Win32

3、选择Win32 Console Application,设置名称:mesh_view。选择Add to solution

4、单击OK,在出现的Win32 Application WizardOverview对话框中点击Next

5、在Application Settings中,选择Application type下的Console application

6、取消Additional options下的Precompiled header,勾选Empty project

7、单击Finish创建项目。

二、添加源码

1、将\trimesh2-2.10\trimesh2\utilsrc\下的mesh_view.cc拷贝到~\trimesh2\mesh_view项目目录下。

2、右键单击mesh_view项目并将mesh_view.cc添加到项目。

3、右键单击mesh_view项目,选择属性,在VC++ Directories下的Include Directories中添加$(SolutionDir)include

4、将Configuration Properties->General下的Output Directory值改为$(SolutionDir)bin

5、在Linker->InputAdditional Dependencies下添加:$(SolutionDir)lib\freeglut.lib

$(SolutionDir)lib\trimesh.lib

单击应用,确定,添加完毕。

三、编译运行

编译项目,在bin目录下生成mesh_view.exe

~\trimesh2\lib\下的freeglut.dll拷贝到~\trimesh2\bin\中,将mesh_view项目设置为Set up StartUp ProjectAlt+F5运行。

trimesh2提供的其它工具编译

1trimesh2提供的mesh_catmesh_checkmesh_crunchmesh_infomesh_makemesh_shape都可按编译mesh_view的方法进行编译。

2mesh_alignmesh_ccmesh_hf,由于使用了<unistd.h>中的库函数getopt函数而编译不通过,则可重写类似功能的window版本方法如下。

       头文件:

/*
POSIX getopt for Windows

AT&T Public License

Code given out at the 1985 UNIFORUM conference in Dallas.  
*/

#ifdef __GNUC__
#include <getopt.h>
#endif
#ifndef __GNUC__

#ifndef _WINGETOPT_H_
#define _WINGETOPT_H_

#ifdef __cplusplus
extern "C" {
#endif

  extern int opterr;
  extern int optind;
  extern int optopt;
  extern char *optarg;
  extern int getopt(int argc, char **argv, char *opts);

#ifdef __cplusplus
}
#endif

#endif  /* _GETOPT_H_ */
#endif  /* __GNUC__ */

源文件:

/*
POSIX getopt for Windows

AT&T Public License

Code given out at the 1985 UNIFORUM conference in Dallas.  
*/

#ifndef __GNUC__

#include "wingetopt.h"
#include <stdio.h>

#define NULL 0
#define EOF (-1)
#define ERR(s, c) if(opterr){\
  char errbuf[2];\
  errbuf[0] = c; errbuf[1] = '\n';\
  fputs(argv[0], stderr);\
  fputs(s, stderr);\
  fputc(c, stderr);}
//(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
//(void) write(2, s, (unsigned)strlen(s));\
//(void) write(2, errbuf, 2);}

int opterr = 1;
int optind = 1;
int optopt;
char *optarg;

int
getopt(argc, argv, opts)
int argc;
char **argv, *opts;
{
  static int sp = 1;
  register int c;
  register char *cp;

  if(sp == 1)
    if(optind >= argc ||
      argv[optind][0] != '-' || argv[optind][1] == '\0')
      return(EOF);
    else if(strcmp(argv[optind], "--") == NULL) {
      optind++;
      return(EOF);
    }
    optopt = c = argv[optind][sp];
    if(c == ':' || (cp=strchr(opts, c)) == NULL) {
      ERR(": illegal option -- ", c);
      if(argv[optind][++sp] == '\0') {
        optind++;
        sp = 1;
      }
      return('?');
    }
    if(*++cp == ':') {
      if(argv[optind][sp+1] != '\0')
        optarg = &argv[optind++][sp+1];
      else if(++optind >= argc) {
        ERR(": option requires an argument -- ", c);
        sp = 1;
        return('?');
      } else
        optarg = argv[optind++];
      sp = 1;
    } else {
      if(argv[optind][++sp] == '\0') {
        sp = 1;
        optind++;
      }
      optarg = NULL;
    }
    return(c);
}

#endif  /* __GNUC__ */

并在其文件头添加如下宏:

	#ifdef _WIN32
	#include "WinGetopt.h"
	#else
	#include <unistd.h>
	#endif

 

另外mesh_cc.cc 文件中find_comps 和 TriMesh_algo.h中方法重名,请为其重新命名。

mesh_hf.cc文件中有用使用了back_inserter方法,需添加头文件:#include <iterator> //zdd++

3、mesh_shape工具中缺少如下宏:

	//zdd++
	#ifndef M_PI_2
	#define M_PI_2 1.57079632679489661923 /* pi/2 */
	#endif
	
	#ifndef M_2_PI
	#define M_2_PI 6.283185307179586232    /* 2*pi  */
	#endif
	//zdd++

 

编译rtsc项目:

编译静态链接库glui。按照编译freeglut的方法,使用~\trimesh2\gluit\目录下的所有以glui_开头的所有.h.cc文件和~\include\GL下的glui.h文件,选择Static library。创建并编译glui。在bin中生成glui.lib库文件。

下载rtsc-1.5.zip ,并使用其提供的(~.h\~.cc)创建rtsc项目。将$(SolutionDir)lib\freeglut.lib$(SolutionDir)lib\trimesh.lib$(SolutionDir)lib\glui.lib加到Linker->InputAdditional Dependencies中。其它按上述方法处理。

1、在apparentridge.h文件开头添加:

	//zdd++
	#include <vector>
	using namespace std;

 

apparentridge.cc文件中的

	extern bool draw_faded; 
	//改成
	extern int draw_faded;  //zdd++

 

rtsc.cc开头添加宏:

	//zdd++
	#ifndef M_PI_2
	#	define M_PI_2 1.57079632679489661923 /* pi/2 */
	#endif
	
	#ifndef M_2_PI
	#	define M_2_PI 6.283185307179586232    /* 2*pi  */
	#endif
	
	#ifndef M_SQRT1_2 
	#	define M_SQRT1_2 0.707106781186547524401 /* 1/sqrt(2)*/
	#endif
	//zdd++

 

编译运行即可。

现在,跟我一起开始研究tremesh2rtsc吧。


本教程源码

 

抱歉!评论已关闭.