• VS2010下配置OpenMesh


    1. www.openmesh.org下载最新版的安装包或者源代码,注意下载与自己系统匹配的版本,我下的是VS2010预编译版的,下载源码自己编译是一样的。安装好Visual Studio。

    2. 安装OpenMesh,预编译版的是一个安装包,直接打开下一步安装就行。

    3. 配置VS,以VS2010为例,打开 项目 —> 项目属性 —> 配置属性 —> VC++目录,在包含目录库目录中依次添加 C:Program Files (x86)OpenMesh 3.2include 和 C:Program Files (x86)OpenMesh 3.2lib 目录,具体由自己的OpenMesh安装目录决定。

    4. 配置属性下,打开 C/C++ —> 预处理器定义,添加_USE_MATH_DEFINES,再打开链接器 —> 输入, 在附加依赖项中输入OpenMeshCored.lib 和 OpenMeshToolsd.lib。

    5. 从OpenMesh官网提供的code examples (First Steps-Building a cube) 中拷贝cube的测试代码,如下,放到工程中编译执行即可。

    6. 运行后会在当前目录下生成一个 output.off 文件。说明执行成功,用OpenMesh目录下自带的 QTviewer 可以打开生成的off文件。

    //=============================================================================
    //                                                                            
    //                               OpenMesh                                     
    //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen       
    //                           www.openmesh.org                                 
    //                                                                            
    //-----------------------------------------------------------------------------
    //                                                                            
    //                                License                                     
    //                                                                            
    //   This library is free software; you can redistribute it and/or modify it 
    //   under the terms of the GNU Library General Public License as published  
    //   by the Free Software Foundation, version 2.                             
    //                                                                             
    //   This library is distributed in the hope that it will be useful, but       
    //   WITHOUT ANY WARRANTY; without even the implied warranty of                
    //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
    //   Library General Public License for more details.                          
    //                                                                            
    //   You should have received a copy of the GNU Library General Public         
    //   License along with this library; if not, write to the Free Software       
    //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 
    //                                                                            
    //-----------------------------------------------------------------------------
    //                                                                            
    //   $Revision: 83 $
    //   $Date: 2009-02-27 17:31:45 +0100 (Fri, 27 Feb 2009) $
    //                                                                            
    //=============================================================================
    #include <iostream>
    // -------------------- OpenMesh
    #include <OpenMesh/Core/IO/MeshIO.hh>
    #include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
    // ----------------------------------------------------------------------------
    typedef OpenMesh::PolyMesh_ArrayKernelT<>  MyMesh;
    // ----------------------------------------------------------------------------
    // Build a simple cube and write it to std::cout
    
    int main()
    {
        MyMesh mesh;
        // generate vertices
        MyMesh::VertexHandle vhandle[8];
        vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1,  1));
        vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1,  1));
        vhandle[2] = mesh.add_vertex(MyMesh::Point( 1,  1,  1));
        vhandle[3] = mesh.add_vertex(MyMesh::Point(-1,  1,  1));
        vhandle[4] = mesh.add_vertex(MyMesh::Point(-1, -1, -1));
        vhandle[5] = mesh.add_vertex(MyMesh::Point( 1, -1, -1));
        vhandle[6] = mesh.add_vertex(MyMesh::Point( 1,  1, -1));
        vhandle[7] = mesh.add_vertex(MyMesh::Point(-1,  1, -1));
        // generate (quadrilateral) faces
        std::vector<MyMesh::VertexHandle>  face_vhandles;
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[0]);
        face_vhandles.push_back(vhandle[1]);
        face_vhandles.push_back(vhandle[2]);
        face_vhandles.push_back(vhandle[3]);
        mesh.add_face(face_vhandles);
    
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[7]);
        face_vhandles.push_back(vhandle[6]);
        face_vhandles.push_back(vhandle[5]);
        face_vhandles.push_back(vhandle[4]);
        mesh.add_face(face_vhandles);
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[1]);
        face_vhandles.push_back(vhandle[0]);
        face_vhandles.push_back(vhandle[4]);
        face_vhandles.push_back(vhandle[5]);
        mesh.add_face(face_vhandles);
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[2]);
        face_vhandles.push_back(vhandle[1]);
        face_vhandles.push_back(vhandle[5]);
        face_vhandles.push_back(vhandle[6]);
        mesh.add_face(face_vhandles);
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[3]);
        face_vhandles.push_back(vhandle[2]);
        face_vhandles.push_back(vhandle[6]);
        face_vhandles.push_back(vhandle[7]);
        mesh.add_face(face_vhandles);
        face_vhandles.clear();
        face_vhandles.push_back(vhandle[0]);
        face_vhandles.push_back(vhandle[3]);
        face_vhandles.push_back(vhandle[7]);
        face_vhandles.push_back(vhandle[4]);
        mesh.add_face(face_vhandles);
        // write mesh to output.obj
        try
        {
            if ( !OpenMesh::IO::write_mesh(mesh, "output.off") )
            {
                std::cerr << "Cannot write mesh to file 'output.off'" << std::endl;
                return 1;
            }
        }
        catch( std::exception& x )
        {
            std::cerr << x.what() << std::endl;
            return 1;
        }
        return 0;
    }

    运行结果(经QTviewer打开)
    cube

    文章修改自 leomass 的文档。

  • 相关阅读:
    css布局
    常用正则表达式
    读书笔记Hadoop实战1
    C++ IDE for Linux
    由计算机的锁是怎么实现的
    pthread
    转:C++反汇编揭秘2 – VC编译器的运行时错误检查(RTC)
    PyDev Python 开发的IDE
    转:C++反汇编揭秘1 一个简单的C++程序反汇编解析
    如何查找命令对应的软件包
  • 原文地址:https://www.cnblogs.com/VVingerfly/p/4382229.html
Copyright © 2020-2023  润新知