open3d-0.10.0 + visual studio 2019 + windows

文章目录

  • 下载
    • Tortoisegit
    • cmake
    • open3d
  • 安装
    • Tortoisegit安装和配置
    • cmake
    • open3d
      • 克隆源码
      • CMake编译
      • 生成解决方案
  • 编译测试文件
  • 测试
    • 测试代码
    • 编译
    • 运行
  • 在自己的项目中配置open3d
  • 参考文章

下载

Tortoisegit

TorToiseGit2.12.0 中文版csdn下载

cmake

cmake3.20.0 csdn下载

open3d

open3d csdn下载
open3d官网
open3d github下载

安装

Tortoisegit安装和配置

【TortoiseGit】TortoiseGit安装和配置详细说明

cmake

  • 运行cmake安装包,以下两张图自己设计即可,其他默认安装
    open3d-0.10.0 + visual studio 2019 + windows_第1张图片
    open3d-0.10.0 + visual studio 2019 + windows_第2张图片

open3d

克隆源码

  • 克隆open3d代码,地址:https://github.com/intel-isl/Open3D,目录自己创建即可,如果clone和更新子模块失败可能是网络原因,多试几次
    open3d-0.10.0 + visual studio 2019 + windows_第3张图片
  • 切换版本,我这里采用的是v0.10.0,和vs2019适应
    open3d-0.10.0 + visual studio 2019 + windows_第4张图片
  • 更新子模块,因为3rdparty是第三方库,有很多文件夹是空的,需要更新
    open3d-0.10.0 + visual studio 2019 + windows_第5张图片
    open3d-0.10.0 + visual studio 2019 + windows_第6张图片

CMake编译

  • source code: D:/Open3D/Open3D; build binaries: D:/Open3D
    open3d-0.10.0 + visual studio 2019 + windows_第7张图片
  • 选择vs2019
    open3d-0.10.0 + visual studio 2019 + windows_第8张图片
  • 点击configure,然后设置 CMAKE/CMAKE_INSTALL_PREFIX ,这里设置的是D:/Open3D/install(可以自己设计记住就可以)
  • 然后再点击configure,直到界面没有红色为止,然后点击generate,如果都没问题,点击open project即可(最好是用管理员方式运行)

生成解决方案

VS2019打开 D:/Open3D/Open3D.sln,我这里是release x64,debug改成debug即可
在这里插入图片描述

  • 将CMakePredefinedTargets/ALL_BUILD设为启动项目,然后点击生成
    open3d-0.10.0 + visual studio 2019 + windows_第9张图片
  • 右击 CMakePredefinedTargets/INSTALL,仅用于项目 -> 仅生成INSTALL,在 D:/Open3D/install 中会生成CMake文件、头文件、静态库,如下图
    open3d-0.10.0 + visual studio 2019 + windows_第10张图片

编译测试文件

open3d vs2019版编译后的文件以及测试文件

测试

测试代码

TestVisualizer.cpp文件
需要修改点云路径

#include 
#include 
#include 
 
#include 
 
// A simplified version of examples/Cpp/Visualizer.cpp to demonstrate linking
// an external project to Open3D.
int main(int argc, char *argv[])
{
	/* add by lljydyx */
	argc = 4;
	argv[1] = "pointcloud";
	argv[2] = "F:/rabbit.pcd";    //填写自己的点云路径

    using namespace open3d;
 
    utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
    if (argc < 3)
	{
        utility::LogInfo("Open3D {}\n", OPEN3D_VERSION);
        utility::LogInfo("\n");
        utility::LogInfo("Usage:\n");
        utility::LogInfo("    > TestVisualizer [mesh|pointcloud] [filename]\n");
        // CI will execute this file without input files, return 0 to pass
        return 0;
    }
 
    std::string option(argv[1]);
    if (option == "mesh")
	{
        auto mesh_ptr = std::make_shared<geometry::TriangleMesh>();
        if (io::ReadTriangleMesh(argv[2], *mesh_ptr)) {
            utility::LogInfo("Successfully read {}\n", argv[2]);
        } else {
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        mesh_ptr->ComputeVertexNormals();
        visualization::DrawGeometries({mesh_ptr}, "Mesh", 1600, 900);
    }
	else if (option == "pointcloud")
	{
        auto cloud_ptr = std::make_shared<geometry::PointCloud>();
        if (io::ReadPointCloud(argv[2], *cloud_ptr))
		{
            utility::LogInfo("Successfully read {}\n", argv[2]);
        }
		else
		{
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        cloud_ptr->NormalizeNormals();
        visualization::DrawGeometries({cloud_ptr}, "PointCloud", 1600, 900);
    }
	else
	{
        utility::LogWarning("Unrecognized option: {}\n", option);
        return 1;
    }
    utility::LogInfo("End of the test.\n");
 
    return 0;
}

CMakeLists.txt文件

cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 14)
 
project(TestVisualizer)
 
# Find installed Open3D, this imports
#   Open3D_INCLUDE_DIRS
#   Open3D_LIBRARIES
#   Open3D_LIBRARY_DIRS
#   Open3D_C_FLAGS
#   Open3D_CXX_FLAGS
#   Open3D_EXE_LINKER_FLAGS
if(WIN32)
    find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/CMake)
else()
    find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
    list(APPEND Open3D_LIBRARIES dl)
endif()
 
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
 
# Set OS-specific things here
if(WIN32)
    if (ENABLE_GUI)
        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
        # Filament is built with /MT[d], but by default CMake automatically
        # sets "/MD" and "/MDd". They can't coexist, so we need to replace them.
        string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
        string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
        string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
        string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
    endif()
elseif(CYGWIN)
elseif(APPLE)
elseif(UNIX)
	add_definitions(-DUNIX)
	add_compile_options(-Wno-deprecated-declarations)
	add_compile_options(-Wno-unused-result)
    add_definitions(-O3)
endif(WIN32)
 
# Open3D
if (Open3D_FOUND)
    message(STATUS "Found Open3D ${Open3D_VERSION}")
 
    # link_directories must be before add_executable
    link_directories(${Open3D_LIBRARY_DIRS})
 
    add_executable(TestVisualizer TestVisualizer.cpp)
 
    target_link_libraries(TestVisualizer ${Open3D_LIBRARIES})
 
    target_include_directories(TestVisualizer PUBLIC ${Open3D_INCLUDE_DIRS})
 
    # Hot fix windows dll not found issue, assumming we're using the Release build
    option(BUILD_SHARED_LIBS "Whether Open3D was build as shared library" OFF)
    if(WIN32 AND BUILD_SHARED_LIBS)
        message("Will copy Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/Release")
        add_custom_command(TARGET TestVisualizer POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                                ${CMAKE_INSTALL_PREFIX}/bin/Open3D.dll
                                ${CMAKE_CURRENT_BINARY_DIR}/Release)
    endif()
    if(WIN32 AND ENABLE_GUI)
        message("Will copy SDL2.dll to ${CMAKE_CURRENT_BINARY_DIR}/Release")
        add_custom_command(TARGET TestVisualizer POST_BUILD
                        COMMAND ${CMAKE_COMMAND} -E copy
                                ${CMAKE_INSTALL_PREFIX}/lib/SDL2.dll
                                ${CMAKE_CURRENT_BINARY_DIR}/Release)
    endif()
 
else ()
    message(SEND_ERROR "Open3D not found")
endif ()

编译

  • Open3D_DIR路径为 D:/Open3D/install/CMake(填写自己安装的路径)
    open3d-0.10.0 + visual studio 2019 + windows_第11张图片
  • 点击configure,然后点击generate

运行

tip:如果出现以下问题,使用管理员方式运行vs即可解决
open3d-0.10.0 + visual studio 2019 + windows_第12张图片

  • VS2019打开 F:\testVisualizer\build\TestVisualizer.sln,Release-x64
  • 将ALL_BUILD设置为启动项,右击生成。
  • 将TestVisualizer设置为启动项,运行结果如下
    open3d-0.10.0 + visual studio 2019 + windows_第13张图片
    open3d-0.10.0 + visual studio 2019 + windows_第14张图片

在自己的项目中配置open3d

  • 右键选择属性,点击c/c++,编辑附加包含目录,输入以下路径,填写你自己的路径
    open3d-0.10.0 + visual studio 2019 + windows_第15张图片
  • 点击链接器,选择常规,编辑附加库目录,输入如下路径,填写自己的路径
    open3d-0.10.0 + visual studio 2019 + windows_第16张图片
  • 点击链接器,选择输入,编辑附加依赖项,输入如下文件名
    open3d-0.10.0 + visual studio 2019 + windows_第17张图片
    文件名如下
Open3D.lib
opengl32.lib
glu32.lib
glew.lib
glfw3.lib
turbojpeg-static.lib
jsoncpp.lib
png.lib
zlib.lib
tinyfiledialogs.lib
tinyobjloader.lib
qhullcpp.lib
qhullstatic_r.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib

参考文章

Open3D:读写点云与可视化(C++)
Open3D:Win10 + VS2017配置Open3D(C++、python)
MSB3073 命令setlocal问题的解决
【TortoiseGit】TortoiseGit安装和配置详细说明

你可能感兴趣的:(open3d,VS019,windows10)