LoginSignup
10
6

More than 5 years have passed since last update.

[CGAL01] CGAL Set up for Visual studio 2017 (Windows 10 64 bit)

Last updated at Posted at 2017-09-25

前提

  • Windows 10 pro x64
  • Visual studio Enterprise 2017 (v15.2)

手順

1.ディレクトリの作成
2.CMakeのインストール
3.Boostのインストールと設定
4.CGALのインストールと設定
5.Visual studioにてソリューションファイルの作成

ディレクトリの作成

c:\dev\

を作成

CMakeのインストール

https://cmake.org/download/
上記URLよりダウンロード.
今回は最新版cmake-3.9.3-win64-x64.msiをインストール.
das.PNG
Nextをクリック
fadsfdsa.PNG
Agreeをクリック
fsadfvds.PNG
Add CMake to the system PATH for all usersを選択しNextをクリック
fsadfvds.PNG
Nextをクリック
instal;l.PNG
Installをクリック
gidiash.PNG
Finishをクリックすると終了

Qt5のインストール

https://download.qt.io/archive/qt/5.9/5.9.1/
より,qt-opensource-windows-x86-5.9.1.exeをダウンロードして実行.
(Qtが必要なサンプルの実行に必要,使用しない場合はインストール不要)

Boostのインストールと設定

インストール

https://sourceforge.net/projects/boost/files/boost-binaries/
上記URLよりダウンロード.
今回はバージョン1.65.1を選択
色々とわからないので,とりあえずall-msvc-32-64の7zを,と思ったら,解凍に7時間なので,
boost_1_65_1-msvc-14.1-64.exeをダウンロードし実行.
IDPbig.png
となるので,そのまま進む.(Next)
awef.PNG
インストールの進行.
ewqqagr.PNG
Finishで終了.

設定

環境変数を設定する.
Windowsマークの上で右クリック→システム→システムの詳細設定→詳細設定タブの環境変数(N)をクリック
(http://www.wannko.net/windows10/etc/kankyo.html)
grdsadfgfda.PNG
新規をクリック

BOOST_LIBRARYDIR=C:\local\boost_1_65_1\lib64-msvc-14.1
BOOST_INCLUDEDIR=C:\local\boost_1_65_1

上記2つの環境変数を追加する.
fgedsg.PNG
(例:BOOST_INCLUDEDIR)
また,既に存在するPATHに,

C:\local\boost_1_65_1\lib64-msvc-14.1

を追加する.これは,変数Pathを選択し,編集をクリック.
既に存在する変数の後ろに

;

をはさみ,追加する.
全て終わったら,OKを押して終了する.
間違っても既存のPathの内容を消去しないようにする.

CGALのインストール

CGALのダウンロードとインストール

https://www.cgal.org/download.html
https://github.com/CGAL/cgal/releases
CGAL-4.11-Setup.exeをダウンロード,実行.
gess.PNG
Next
gwerag.PNG
Agree
gaer4h.PNG
個人的には,HTML Manualも欲しいので,すべてチェックを入れ,Nextをクリック.
grfasddga.PNG
64bitを選択.
edsgargyhdrf.PNG
ディレクトリを

C:\local\CGAL-4.11

Boostと同じC:\local\にする.
garedgra.PNG
(なんとなく)all usersにした.ほかは変更しない.
grewgre.PNG
CompleteしたらNext
bhiubvaedrd.PNG
Downloadingが完了しただけなので,CMakeでコンパイルしていく.
guibnl.PNG
これが出た.私の環境では,環境変数にgmpが入っていなかったので,あとで設定する.

設定

Source codeを

C:/local/CGAL-4.11

とし,Build the binariesを

C:/local/CGAL-4.11/build

とする.Configureを押す.
harejhtfrshr.PNG
ここで,Visual studio 15 2017 Win64を選択し,Finishをクリック.
hreahreas.PNG
真っ赤になるけど,DONEなので,エラーではない.Generateをクリックする.
C:\local\CGAL-4.11\buildにCGAL.slnが登場するので,VS2017で開く.
hbarera..PNG
これのなかで,ALL_BUILDのみをビルドする.(プロジェクトのみをリビルド)

5>------ すべてのリビルド開始: プロジェクト:ALL_BUILD, 構成: Debug x64 ------
5>Building Custom Rule C:/local/CGAL-4.11/CMakeLists.txt
5>CMake does not need to re-run because C:/local/CGAL-4.11/build/CMakeFiles/generate.stamp is up-to-date.
========== すべてリビルド: 5 正常終了、0 失敗、0 スキップ ==========

といった出力が出る.
これが完了したら,環境変数"Path"に"C:\local\CGAL-4.11\build\bin"と"C:\local\CGAL-4.11\auxiliary\gmp\lib"を追加する.
hraehertashrt.PNG
先ほどと同じ手順で環境変数設定画面に移動し,Pathに対し編集をクリック.新規をクリックすると入力欄が点滅するので,そこに上記2つの環境変数を追加する.
※ 既に存在する変数は決して消さないこと!!

Test building

設定

新規作成→プロジェクト→win32 コンソールアプリケーション
※ 空のプロジェクトにする.プリコンパイル済みにはしない

gedsgda.PNG
プロジェクトの設定から,インクルードディレクトリに

C:\local\CGAL-4.11\auxiliary\gmp\include
C:\local\boost_1_65_1
C:\local\CGAL-4.11\build\include
C:\local\CGAL-4.11\include

を追加する.ライブラリディレクトリに

C:\local\CGAL-4.11\auxiliary\gmp\lib
C:\local\boost_1_65_1\libs
C:\local\CGAL-4.11\build\lib

を追加する.
依存ライブラリディレクトリに

libgmp-10.lib
libmpfr-4.lib
kernel32.lib
user32.lib
CGAL_Core-vc140-mt-gd-4.11.lib
CGAL_ImageIO-vc140-mt-gd-4.11.lib
CGAL-vc140-mt-gd-4.11.lib

を追加する.
これらにより,インテリセンスのエラーなく,全ての関数を参照・実行可能となる.
jhsrtujhtsr.PNG

サンプルプログラム

メッシュの自己交差(self-intersection)が発生している三角形の数を教えてくれるCGALに最初から付属のサンプルプログラムです.

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3>             Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char* argv[])
{
    const char* filename = (argc > 1) ? argv[1] : "./data/pig.off";
    std::ifstream input(filename);
    Mesh mesh;

    if (!input || !(input >> mesh) || !CGAL::is_triangle_mesh(mesh))
    {
        std::cerr << "Not a valid input file." << std::endl;
        return 1;
    }

    bool intersecting = PMP::does_self_intersect(mesh,
        PMP::parameters::vertex_point_map(get(CGAL::vertex_point, mesh)));
    std::cout
        << (intersecting ? "There are self-intersections." : "There is no self-intersection.")
        << std::endl;
    std::vector<std::pair<face_descriptor, face_descriptor> > intersected_tris;
    PMP::self_intersections(mesh, std::back_inserter(intersected_tris));
    std::cout << intersected_tris.size() << " pairs of triangles intersect." << std::endl;

    return 0;
} 

を,C:\local\CGAL-4.11\examples\Polygon_mesh_processing\data\pig.offを用いて実行すると,
grafdasgrdsf.PNG
の結果を得られる.
サンプルのVS2017実行ファイル:http://www.mediafire.com/file/38wahkfkap5qx94/20170925_test01.rar

References

special thanks to
http://mimismgn.hatenablog.com/entry/2016/09/17/001534
https://www.cgal.org/download/windows.html
http://www.wannko.net/windows10/etc/kankyo.html

10
6
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6