Nitta-K-git / vcglib_samples

samples of vcglib and meshlab.
MIT License
22 stars 4 forks source link
cmake cpp meshlab vcglib

vcglib_samples

sample codes of vcglib and MeshLab function.

Introduction

The Visualization and Computer Graphics Library (VCG for short) is a open source portable C++ templated library for manipulation, processing and displaying with OpenGL of triangle and tetrahedral meshes.

Get started

Requirements

Get library from github

Clone vcglib from github. You should select develbranch (master branch is too old).

$ git clone -b devel https://github.com/cnr-isti-vclab/vcglib.git
Cloning into 'vcglib'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 42007 (delta 0), reused 1 (delta 0), pack-reused 42002
Receiving objects: 100% (42007/42007), 17.24 MiB | 1.23 MiB/s, done.
Resolving deltas: 100% (28087/28087), done.
Checking out files: 100% (1063/1063), done.

$ cd vcglib

$ git branch
* devel

How to build with cmake

First, you have to set below environment values

see this sample for details.

Samples

Basic data structure

Read/Write file

Basic algorithm (vcglib functions)

Extra algorithm (implemented in MeshLab)

use MeshLab data structure.

Visualize with Qt

Visualize with three.js

Error handling

Missing Component Exception -FFAdjacency-のようなケース

// adjacency関連を有効にする(頂点と面でそれぞれ有効化しないといけないものもある)
mesh.vert.EnableVFAdjacency();
mesh.face.EnableFFAdjacency();
mesh.vert.EnableCurvature();
mesh.vert.EnableCurvatureDir();

Assertion failed: f.cFFp(j) != 0, file C:/Users/Public/Documents/GitHub/vcglib/vcg/simplex/face/topology.h, line 39 のようなケース

// 初期化時と関係性が変わった場合は更新が必要
tri::UpdateTopology<CMeshO>::FaceFace(mesh);
tri::UpdateTopology<CMeshO>::VertexFace(mesh);
tri::UpdateNormal<CMeshO>::PerFace(mesh);
tri::UpdateNormal<CMeshO>::NormalizePerFace(mesh);

How to port the function of MeshLab

MeshLab implements many functions in a plugin format. A list of plugins can be found here.

Let's take a look at the structure of the mlsplugin.cpp file as an example. The name of the implemented function is defined here. The function for plugins is the applyFilter function.

The process branches according to the ID contained in the filter variable. The applyFiter function is the starting point of each plug-in process, so if you follow the process from here, you can check all the implementation details.

When searching for the function you want to know how to be implemented on MeshLab, it is recommended way that search function name by using grep command in source directory.


残り

020_trackball

トラックボール表示するだけのサンプル

視点操作はトラックボール使うと楽にできるが、固定シェーダ前提になる

021_trackball_mesh

トラックボールとメッシュデータ表示するサンプル

光源用の処理も追加

メッシュ間の干渉判定

// mesh1においてmesh2との干渉面が選択される(mesh2はそのまま)
mesh2.face.EnableMark();
int a = vcg::tri::Clean<CMeshO>::SelectIntersectingFaces(mesh1, mesh2);

end