Giter VIP home page Giter VIP logo

cinolib's Introduction

CinoLib

MacOS Ubuntu Linux

CinoLib is a C++ library for processing polygonal and polyhedral meshes. It supports surface meshes made of triangles, quads or general polygons as well as volumetric meshes made of tetrahedra, hexahedra or general polyhedra.

A distinctive feature of the library is that all supported meshes inherit from a unique base class that implements their common traits, permitting to deploy algorithms that operate on abstract meshes that may be any of the above. This allows to implement algorithms just once and run the same code on any possible mesh, thus avoiding code duplication and reducing the debugging effort.

Positioning

Github hosts a whole variety of great academic libraries for mesh processing. If you do mainly geometry processing on triangle meshes, then tools like libigl, GeometryCentral or VCG may be what you want. If you are interested in rendering, Yocto/GL is extremely fast and implements many relevant algorithms. OpenMesh, CGoGN2 and PMP have a slightly broader scope and can handle general polygonal surfaces. For volumes, tiny portions of libigl and GeometryCentral offer rudimentary support for specific solid elements such as tetrahedra or hexahedra, but most of the library is focused on surfaces. Conversely, OpenVolumeMesh and CGoGN3 are focused on volumes and can operate on general polyhedral elements, but they do not support surface meshes. To the best of my knowledge, only Geogram has a unified data structure that can host both surface and volume elements, but it only supports hexahedra, tetrahedra, prisms and pyramids as volume cells. Differently from all these alternatives, CinoLib has a unique data structure that is designed to host any type of surface and volumetric element. If this comes handy to you, I am not aware of any existing alternative. Data structures based on combinatorial maps have the potential to offer similar capabilities, but these are not fully implemented yet (#171). Note that CinoLib trades generality for efficiency, hence all this flexibilty comes at a cost. Many optimizations that are possible when one operates on a restricted set of mesh elements cannot be applied here, especially memory-wise, where generic elements with an unpredictable number of vertices edges and faces demand the use of dynamic allocators. For this reason, in some cases CinoLib may be sligthly less efficient than the aforementioned alternatives.

Getting started

CinoLib is header only. It does not need to be installed, all you have to do is to clone the repo with

git clone https://github.com/mlivesu/cinolib.git

and include in your C++ application the header files you need. For small projects this could already be done by instructing the compiler on where to find the library sources, e.g. with the -I option. For more convoluted projects it is suggested to rely on a building system such as CMake, that can also handle optional external dependencies and compilation flags or symbols.

Build a sample project (with CMake)

Here is an example of a toy program that reads a triangle mesh and displays it on a window

#include <cinolib/meshes/drawable_trimesh.h>
#include <cinolib/gl/glcanvas.h>

int main()
{
    using namespace cinolib;
    DrawableTrimesh<> m("bunny.obj");
    GLcanvas gui;
    gui.push(&m);
    return gui.launch();
}

and this is the CMakeLists.txt that can be used to compile it

cmake_minimum_required(VERSION 3.2)
project(cinolib_demo)
add_executable(${PROJECT_NAME} main.cpp)
set(CINOLIB_USES_OPENGL_GLFW_IMGUI ON)
find_package(cinolib REQUIRED)
target_link_libraries(${PROJECT_NAME} cinolib)

Compiling should be as easy as opening a terminal in the folder containing the two files above and type

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -Dcinolib_DIR=<absolute-path-to-cinolib>
make

Note that for the rendering part CinoLib uses GLFW, which will be automatically installed and linked by the script cinolib-config.cmake, contained in the main directory of the library. The same script can automatically download and install any other external dependency, meaning that if you want to access a functionality that depends on some external library XXX, all you have to do is setting to ON a cmake variable that looks like CINOLIB_USES_XXX. Valid options are:

  • CINOLIB_USES_OPENGL_GLFW_IMGUI, used for rendering with OpenGL
  • CINOLIB_USES_TRIANGLE, used for polygon triangulation
  • CINOLIB_USES_TETGEN, used for tetrahedralization
  • CINOLIB_USES_SHEWCHUK_PREDICATES, used for exact geometric tests on input points
  • CINOLIB_USES_INDIRECT_PREDICATES, used for exact geometric tests on implicit points
  • CINOLIB_USES_GRAPH_CUT, used for graph clustering
  • CINOLIB_USES_BOOST, used for 2D polygon operations (e.g. thickening, clipping, 2D booleans...)
  • CINOLIB_USES_VTK, used just to support VTK file formats
  • CINOLIB_USES_SPECTRA, used for matrix eigendecomposition
  • CINOLIB_USES_CGAL, used for rational numbers with a lazy kernel

GUI

CinoLib is designed for researchers in computer graphics and geometry processing that need to quickly realize software prototypes that demonstate a novel algorithm or technique. In this context a simple OpenGL window and a side bar containing a few buttons and sliders are often more than enough. The library uses ImGui for the GUI and GLFW for OpenGL rendering. Typical visual controls for the rendering of a mesh (e.g. shading, wireframe, texturing, planar slicing, ecc) are all encoded in two classes cinolib::SurfaceMeshControls and cinolib::VolumeMeshControls, that operate on surface and volume meshes respectively. To add a side bar that displays all such controls one can modify the sample progam above as follows:

#include <cinolib/meshes/drawable_trimesh.h>
#include <cinolib/gl/glcanvas.h>
#include <cinolib/gl/surface_mesh_controls.h>

int main()
{
    using namespace cinolib;
    DrawableTrimesh<> m("bunny.obj");
    GLcanvas gui;
    SurfaceMeshControls<DrawableTrimesh<>> mesh_controls(&m, &gui);
    gui.push(&m);
    gui.push(&mesh_controls);
    return gui.launch();
}

The canvas can host multiple mesh controls, ideally one of each mesh in the scene. Additional GUI elements that may be necessary to control the application (e.g. the parameters of your algorithm) can be added by implementing a dedicated callback:

#include <cinolib/meshes/drawable_trimesh.h>
#include <cinolib/gl/glcanvas.h>
#include <cinolib/gl/surface_mesh_controls.h>

int main()
{
    using namespace cinolib;
    DrawableTrimesh<> m("bunny.obj");
    GLcanvas gui;
    SurfaceMeshControls<DrawableTrimesh<>> mesh_controls(&m, &gui);
    gui.push(&m);
    gui.push(&mesh_controls);
    float val = 1.0, min = 0.0, max = 10.0;
    gui.callback_app_controls = [&]()
    {
        if(ImGui::Button("MyButton"))
        {
            // button clicked: do something
        }
        if(ImGui::SliderFloat("MySlider", &val, min, max))
        {
            // slider moved: do something
        }       
    };
    return gui.launch();
}

The full list of callbacks exposed by GLcanvas to interact with user events (e.g. for scene navigation, mouse picking, ecc) are:

  • callback_key_pressed(int key, int modifiers)
  • callback_mouse_left_click(int modifiers)
  • callback_mouse_left_click2(int modifiers) => double click
  • callback_mouse_right_click(int modifiers)
  • callback_mouse_right_click2(int modifiers) => double click
  • callback_mouse_moved(double x_pos, double y_pos)
  • callback_mouse_scroll(double x_offset, double y_offset)
  • callback_app_controls(void)

Other examples

A tutorial with detailed info on how to use the library is under developement. In the meanwhile, you can explore the examples folder, which contains a constantly growing number of sample projects that showcase the core features of the library, and will be the backbone of the forthcoming tutorial.

Contributors

Marco Livesu is the creator and lead developer of the library. CinoLib has also received contributions from: Daniela Cabiddu (CNR IMATI), Claudio Mancinelli and Enrico Puppo (University of Genoa), Chrystiano Araújo (UBC), Thomas Alderighi (CNR ISTI), Fabrizio Corda (University of Cagliari), Gianmarco Cherchi (University of Cagliari) and Tommaso Sorgente (CNR IMATI).

Citing us

If you use CinoLib in your academic projects, please consider citing the library using the following BibTeX entry:

@article{cinolib,
  title   = {cinolib: a generic programming header only C++ library for processing polygonal and polyhedral meshes},
  author  = {Livesu, Marco},
  journal = {Transactions on Computational Science XXXIV},
  series  = {Lecture Notes in Computer Science},
  editor  = {Springer},
  note    = {https://github.com/mlivesu/cinolib/},
  year    = {2019},
  doi     = {10.1007/978-3-662-59958-7_4}}

Acknowledgment

The software collected in CinoLib spans across a large period of time, starting from the beginning of my PhD to today. Since 2015, this work has been partly supported by various research projects, such as

cinolib's People

Contributors

bbrrck avatar daichi-ishida avatar danielacabiddu avatar gcherchi avatar hartmannathan avatar islam0mar avatar marzer avatar mlivesu avatar pizza1994 avatar tommasosorgente avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cinolib's Issues

All-hexahedral meshing?

Reading your paper Optimal Dual Schemes for Adaptive Grid Based Hexmeshing, it mentions that it's implemented in cinolib (in hex_transition_schemes.h), but does cinolib come "with batteries included" for obtaining a fully automatic hexmesh from, for example, a trimesh stored in OBJ? I'm asking this question because I found the repository used for the paper (https://github.com/cg3hci/Gen-Adapt-Ref-for-Hexmeshing) but however that code has quite a few external dependencies that I'd like to avoid.

If cinolib has all the necessary stuff, can you show some example for hexmeshing a triangle mesh? (I suppose the first step would be generating an adaptive grid, but that can be done with cinolib as well, can't it?

Imgui control hidden

I've compiled cinolub successfuly,but ImGUI control cannot be visible,What's wrong? other is OK

cut mesh

possible to cut mesh with set of 3d points on it.
if possible , example ??

How to implement algorithms such as QEM

hi,I am trying to implement the QEM with cinolib, here is my question
I stored vid pair to collapse in the priority queue like this

struct contract {
	double cost, x, y, z;
	unit vid1, vid2;
}

I noticed that when deleting elements, the switch_id function will execute, causing the element id switch with last id, rendering the contract operation related to the last vid invalid. How can i solve this problem

Embed a polyline into a mesh

Thanks for putting this great library together @mlivesu!

I'm trying to adopt it to terrain modelling applications where curve-based mesh manipulation is a common task.

Consider this example. Given a terrain mesh and a curve in arbitrary 3d space:
image

Embed the curve into the mesh:
image

Do you have any suggestions on how to approach it?

how to use the hex_transition_install function?

I want to achieve a simple subdivision schme on hexmesh. I think the ‘'hex_transition_install’' function may help me a lot.But i don't know which verts should be set to true in transition_verts. Is there any examples?

Link errors

Hello,

I have linking errors (VS 2017, WIn10), when building examples, related to imgui lib:
Do you have an idea ?

Thank you

image

image

Cut a volume mesh based on embedded level set

Hi, I would like to cut a volume mesh based a level set embedded on its vertices (at isovalue zero). To do so I have tried implementing it as seem bellow. While it compiles and runs without issues the mesh is not being split. I am probably missing something pretty trivial but I can’t seem figure out what it is. Hopefully you can shed some light on it.

std::vector<double> isovalues;
for (uint vid=1; vid<MyTetMesh.num_verts(); ++vid) {
    // Get coordinates of current point
    vec3d point = MyTetMesh.vert(vid);
    Point p(point.x(), point.y(), point.z());

    // Compute isovalue for current point
    double isovalue = my_function(p);
    isovalues.push_back(isovalue);
}

// Copy the field on the mesh?
ScalarField f = ScalarField(isovalues);
f.copy_to_mesh(MyTetMesh);

// Slice the mesh?
MeshSlicer ss;
ss.Z_thresh = 0;
ss.slice(MyTetMesh);

OpenGL rendering: soft shadows

Hello,

Do you think it would be possible to add soft shadows effects to the rendering system of Cinolib viewer ? Or do we have to send request to glfw ?

thank you.

compile error!

Win10, Qt5.10, vs2017, 02_base_app_quadmesh.pro

There are lots of compile error about GL.h(Windows Kits\10\Include\10.0.17134.0\um\gl\GL.h), I think it is a question.

How to generate a cinolib?

I cannot find a CMakeLists.txt under cinolib to cmake/make and thus cannot build examples. How to generate **so and *.a of the cinolib? Thanks.

Undefined reference to `orient2d' / `orient3d'

Files predicates.h/cpp

Functions

       double orient2d(const double * pa, const double * pb, const double * pc);
       double orient3d(const double * pa, const double * pb, const double * pc, const double * pd);

are implemented if and only if CINOLIB_USES_EXACT_PREDICATES are not defined.

If CINOLIB_USES_EXACT_PREDICATES is defined, building errors occur : Undefined reference to orient2d' / orient3d'.

Support for Semantic Versioning

Hello,

thank you very much for your tremendous work on this library!
Would it be possible to add support for semantic versioning?
I know that there is the 1.0 tag. However, it seems to be out of date.

Example 23 of Sharp Creases

Hello,

While I was able to run most of the example, I am unable to see sharp edges in the example 23. The value on the webpage is set to 60 which I also did (on the same example), but nothing changed.

information

Hello,
This repository was suggested to me by github and I just read the readme.
Looking at your research oriented list of mesh libraries, I wanted to suggest you CGOGN_2 and CGoGN_3 as "unified data structure for multiple dimension handling".
In fact, these libraries implement a mesh data structure (based on a theoretical model) that can handle 0D, 1D, 2D and 3D oriented open or closed manifolds whatever their discretization (polygons or polyhedrons). There is also a cgal package based on the same theoretical data model that can handle nD objects. A while ago we made some benchmarks also.

Shadow casting question

Hello,

i would like to compute the covered area by a triangle mesh A on a second mesh B (made of either triangles or quads). Expected output is the covering ratio for each mesh B element.

I was wondering of your shadow casting (OpenGL) could be used for that need, and if yes how ?

thank you

can we train an AI assisatnt for CAX?

like cinolib we could have more interfaces for CAX software, if we have interfaces, comments and the books, if we use nanogpt, maybe we could train an AI assistant?

no member named 'update_hex_quality'

Hi,
When I try to compile LoopyCuts, I got a error from cinolib, the error is shown blow.
In file included from ./definitions.h:30: In file included from ../lib/cinolib/include/cinolib/meshes/meshes.h:49: In file included from ../lib/cinolib/include/cinolib/meshes/hexmesh.h:124: ../lib/cinolib/include/cinolib/meshes/hexmesh.cpp:405:19: error: no member named 'update_hex_quality' in 'cinolib::Hexmesh<cinolib::Mesh_std_attributes, MV, ME, MF, MP>' this->update_hex_quality(pid); ~~~~ ^ export_helper.cpp:37:12: note: in instantiation of member function 'cinolib::Hexmesh<cinolib::Mesh_std_attributes, MV, ME, MF, MP>::poly_fix_orientation' requested here hm.poly_fix_orientation(); // meta mesh does not have globally consistent winding numbers... ^ In file included from export_helper.cpp:27: In file included from ./export_helper.h:30: In file included from ./state.h:36: In file included from ./definitions.h:30: In file included from ../lib/cinolib/include/cinolib/meshes/meshes.h:49: In file included from ../lib/cinolib/include/cinolib/meshes/hexmesh.h:124: ../lib/cinolib/include/cinolib/meshes/hexmesh.cpp:415:19: error: no member named 'update_hex_quality' in 'cinolib::Hexmesh<cinolib::Mesh_std_attributes, MV, ME, MF, MP>' this->update_hex_quality(); ~~~~ ^ 21 warnings and 2 errors generated. make: *** [export_helper.o] Error 1

I tried to search the function in 3D5378, But I can not find this function.
Any suggestion?
Thank you.

Interactive Selection in the viewer

If the selected elements could be shown or hidden, The inside of the model could be seen. It is useful for some applications. Will cinolib add the mouse selction api or functions? For example

  1. Interactive rectangle selection of nodes or elements;
  2. Hiding the selected nodes and elements.
    image

How to use remesh_Botsch_Kobbelt_2004 without gl

Hi, I would like to use remesh_Botsch_Kobbelt_2004 to remesh a surface using the api. The issue I am having is that remesh_Botsch_Kobbelt_2004 seems to require a DrawableTrimesh which in turn is dependent on gl (my understanding is that gl is required for the GUI stuff, which I am not interested in). Is there a way of using remesh_Botsch_Kobbelt_2004 without needing gl?

Mesh duality: m_poly faces not planar nor perpendicular to the corresponding m_tet edge

First of all, thank you for this great project! It spared me a lot of trouble during my research.

I was investigating the duality of the meshes from the example 13, m_tet and m_poly.

I observed every edge from the m_tet mesh and its corresponding face from the m_poly mesh (shared face between edge points). I realized that:

  • the face is not perpendicular to the edge and
  • the face is not always planar

Is that a desired behaviour? Am I doing it wrong?

This is the code snippet I inserted into the example code for the purpose of this analysis:

    for (int i=0; i<m_tet.num_edges(); ++i)
      {
	std::vector<uint> vert_ids = m_tet.edge_vert_ids(i);
	uint fid = m_poly.poly_shared_face(vert_ids.at(0), vert_ids.at(1));

	std::vector<vec3d> edgev = m_tet.edge_verts(i);
	std::vector<vec3d> facev = m_poly.face_verts(fid);

	std::ofstream edgeout ("/tmp/cino/edge-" + std::to_string(i) + ".txt");
	for (auto v: edgev)
	    edgeout << v.x() << " " << v.y() << " " << v.z() << "\n";
	std::ofstream faceout ("/tmp/cino/face-" + std::to_string(i) + ".txt");
	for (auto v: facev)
	    faceout << v.x() << " " << v.y() << " " << v.z() << "\n";
      }

And some screenshots from Paraview:
cino2
cino3

Custom data in Tetmesh

Hi!
Is there a way to associate some metadata with tetrahedrons in Tetmesh?
E.g I have 2 Tetmeshes:
изображение
For each tetrahedron in tetmesh1 I need to store the same thermal conductivity which equals X, and for each tetrahedron in tetmesh2 I need to store the same thermal conductivity which equals Y.

Example 22 : Core dump

Hello,

The most important example (remesher) fails:

22_remesher.pro main.cpp main.o Makefile remesher
csverma@blackhole:$ ./remesher ~/Disk/DataSets/Chair.off
new mesh 147428V / 444576E / 296384P
388249 edges longer than 0.0430667 were split.
142714 edges shorter than 0.02584 were collapsed.
250670 edge flip were performed to normalize vertex valence to 6
tangential smoothing
Remesh iteration [10.939885s]
1122279 edges longer than 0.0430667 were split.
231838 edges shorter than 0.02584 were collapsed.
remesher: ../../include/cinolib/meshes/abstract_polygonmesh.cpp:1347: uint cinolib::AbstractPolygonMesh<M, V, E, P>::poly_add(const std::vector<unsigned int, std::allocator >&) [with M = cinolib::Mesh_std_attributes; V = cinolib::Vert_std_attributes; E = cinolib::Edge_std_attributes; P = cinolib::Polygon_std_attributes; uint = unsigned int]: Assertion `poly_id(vlist)==-1' failed.
Aborted (core dumped)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.