kilikila / vcglib_samples

samples of vcglib and meshlab.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  • cmake
  • Eigen
  • C++ compiler(visual studio, gcc, ... etc.)
  • Qt (not necessary but it's easy to visualize)

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

  • VCGLIB_DIR : path/to/vcglib (e.g. C:/Users/Public/Documents/GitHub/vcglib)
  • MESHLAB_DIR : path/to/MeshLab/source (e.g. C:/Users/Public/Documents/GitHub/meshlab/src)
  • EIGEN3_INCLUDE_DIR : path/to/Eigen3 (e.g. C:/eigen-3.3.7)

see this sample for details.

Samples

Basic data structure

  • template data structure : CODE
  • template data structure from MeshLab : CODE
  • access mesh vertices/faces : CODE
  • set flag of vertices/faces : CODE
  • expand select function : CODE
  • get adjacent vertices/faces : CODE
  • create mesh using just a vector of coords and a vector of indexes : CODE
  • user defined attribute : CODE
  • add and delete vertices/faces : CODE
  • set color each vertex/face and save as ply: CODE
  • set vertex value and save as ply format : CODE
  • copy and merge mesh data : CODE

Read/Write file

  • read and write basic file formats : CODE
  • create preset object : CODE

Basic algorithm (vcglib functions)

  • convert degree and radian: CODE
  • distance between two points : CODE
  • distance between point and line : CODE
  • distance between point and plane : CODE
  • angle between two vectors : CODE
  • quaternion : CODE
  • transformation matrix : CODE
  • translate matrix with Eigen : CODE
  • remove non manifold vertices and faces : CODE 未完成

Extra algorithm (implemented in MeshLab)

use MeshLab data structure.

  • template data structure from MeshLab : CODE
  • calculate curvature : CODE
  • hole filing : [CODE]
  • mesh simplification : CODE 未完成
  • calculate Hausdorff distance : CODE 内容整理 sample target
  • mesh intersection : [CODE]
  • select boundary line : [CODE]
  • simplification : CODE
  • subdivision : CODE

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

About

samples of vcglib and meshlab.

License:MIT License