{"id":13541736,"url":"https://github.com/InteractiveComputerGraphics/Discregrid","last_synced_at":"2025-04-02T09:32:29.846Z","repository":{"id":26908339,"uuid":"110241488","full_name":"InteractiveComputerGraphics/Discregrid","owner":"InteractiveComputerGraphics","description":"A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields. ","archived":false,"fork":false,"pushed_at":"2023-08-31T10:30:00.000Z","size":12273,"stargazers_count":285,"open_issues_count":2,"forks_count":62,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-08-01T10:15:58.616Z","etag":null,"topics":["collision-detection","discretization","signed-distance-fields"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InteractiveComputerGraphics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-10T11:49:26.000Z","updated_at":"2024-06-20T14:15:11.000Z","dependencies_parsed_at":"2024-07-28T11:40:41.388Z","dependency_job_id":null,"html_url":"https://github.com/InteractiveComputerGraphics/Discregrid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InteractiveComputerGraphics%2FDiscregrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InteractiveComputerGraphics%2FDiscregrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InteractiveComputerGraphics%2FDiscregrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InteractiveComputerGraphics%2FDiscregrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InteractiveComputerGraphics","download_url":"https://codeload.github.com/InteractiveComputerGraphics/Discregrid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222818707,"owners_count":17042228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collision-detection","discretization","signed-distance-fields"],"created_at":"2024-08-01T10:00:55.708Z","updated_at":"2024-11-03T07:30:41.539Z","avatar_url":"https://github.com/InteractiveComputerGraphics.png","language":"C++","readme":"# Discregrid\n\n\u003cp align=center\u003e\u003cimg src=\"https://github.com/InteractiveComputerGraphics/Discregrid/workflows/build-linux/badge.svg\"\u003e\u0026nbsp;\u0026nbsp; \u003cimg src=\"https://github.com/InteractiveComputerGraphics/Discregrid/workflows/build-windows/badge.svg\"\u003e\u003c/p\u003e\n\n![](https://www.animation.rwth-aachen.de/media/resource_files/DragonSDFDM.png)\n**Figure 1**: Left: Slice of a three-dimensional discrete signed distance field of the Stanford dragon. Right: Density map for SPH boundary handling of Stanford dragon.\n\n**Discregrid** is a static C++ library for the parallel discretization of (preferably smooth) functions on regular grids.\nThe library generates a (cubic) polynomial discretization given a box-shaped domain, a grid resolution, and a function that maps a three-dimensional position in space to a real scalar value.\nIsoparametric cubic polynomials of Serendipity type for the cell-wise discretization are employed.\nThe coefficient vector for the discrete polynomial basis is computed using regular sampling of the input function at the higher-order grid's nodes.\nThe algorithm to generate the discretization is moreover *fully parallelized* using OpenMP and especially well-suited for the discretization of signed distance functions.\nThe library moreover provides the functionality to serialize and deserialize the a generated discrete grid.\nDiscregrid ships with [TriangleMeshDistance](https://github.com/InteractiveComputerGraphics/TriangleMeshDistance) to directly provide the capability to compute and discretize signed distance fields to triangle meshes.\n\nBesides the library, the project includes three executable programs that serve the following purposes:\n* *GenerateSDF*: Computes a discrete (cubic) signed distance field from a triangle mesh in OBJ format.\n* *DiscreteFieldToBitmap*: Generates an image in bitmap format of a two-dimensional slice of a previously computed discretization.\n* *GenerateDensityMap*: Generates a density map according to the approach presented in [KB17] from a previously generated discrete signed distance field using the widely adopted cubic spline kernel. The program can be easily extended to work with other kernel function by simply replacing the implementation in sph_kernel.hpp.\n\n**Author**: Dan Koschier, **License**: MIT\n\n## Libraries using Discregrid\n* [PBD] - A C++ library for physically-based simulation of rigid bodies, deformables, cloth and fluids using Position-Based Dynamics. Discregrid is used to compute discrete signed distance fields of rigid objects for collision handling purposes.\n* [SPlisHSPlasH] - A C++ library for the physically-based simulation of fluids using Smoothed Particle Hydrodynamics. Discregrid is used to compute density maps according to my paper [KB17] for boundary handling.\n\n## Build Instructions\n\nThis project is based on [CMake](https://cmake.org/). Simply generate project, Makefiles, etc. using [CMake](https://cmake.org/) and compile the project with the compiler of your choice. The code was tested with the following configurations:\n- Windows 10 64-bit, CMake 3.8, Visual Studio 2017\n- Debian 9 64-bit, CMake 3.8, GCC 6.3.\n\n## Usage\nIn order to use the library, the main header has to be included and the static library has to be compiled and linked against the client program.\nIn this regard a find script for CMake is provided, i.e. FindDiscregrid.cmake.\nThe main header can be included as follows:\n```c++\n#include \u003cDiscregrid/All\u003e\n```\n\nA base class for the data structure that generates and holds a discretization of a function f: R^3 -\u003e R can be constructed as follows:\n```c++\n// Firstly, create a domain on which a discretization will be generated.\nEigen::AlignedBox3d domain;\n// Then specify domain extents using e.g. domain.extend(...).\n// Secondly, specify a grid resolution.\nstd::array\u003cunsigned int, 3\u003e resolution = {{10, 10, 10}}\n// Finally, instantiate the grid.\nDiscregrid::CubicLagrangeDiscreteGrid discrete_grid(domain, resolution);\n```\nThen, an arbitrary number of functions can be discretized on the initiated grid:\n```c++\nDiscregrid::DiscreteGrid::ContinuousFunction func1 = ...;\nDiscregrid::DiscreteGrid::ContinuousFunction func2 = ...;\n\nauto df_index1 = discrete_grid.addFunction(func1);\nauto df_index2 = discrete_grid.addFunction(func2);\n```\nOptionally, only coefficients at nodes fulfilling a certain predicate can be generated by specifying the predicate:\n```c++\nDiscregrid::DiscreteGrid::ContinuousFunction func3 = ...;\nauto df_index3 = discrete_grid.addFunction(func3, false, [\u0026](Vector3d const\u0026 x)\n{\n\t...\n\t// Return true if a certain criterion for the node location x is fulfilled, e.g.\n\treturn x.y() \u003e 0.0;\n});\n```\nA value of a discrete field can be evaluated by interpolation.\nAdditionally, the gradient at the given query point can be computed if desired.\n```c++\nauto val1 = sdf-\u003einterpolate(df_index1, {0.1, 0.2, 0.3});\nEigen::Vector3d grad2;\nauto val2 = sdf-\u003einterpolate(df_index2, {0.3, 0.2, 0.1}, \u0026grad2);\n```\n\nIf a discretization of the input function is only required in certain regions of the given domain, the discretization can be reduced resulting in a sparsely populated grid to save memory:\n```c++\ndiscrete_grid.reduce_field(df_index1, [](Eigen::Vector3d const\u0026 x, double v)\n{\n\t// E.g.\n\treturn x.x() \u003c 0.0 \u0026\u0026 v \u003e 0.0;\n});\n```\nHere x represents the location of sample point in the grid and v represents the sampled value of the input function. If the predicated function evaluates to true the sample point is kept but discarded otherwise.\n\nOptionally, the data structure can be serialized and deserialized via\n```c++\ndiscrete_grid.save(filename);\ndiscrete_grid.load(filename); // or\ndiscrete_grid = Discregrid::CubicLagrangeDiscreteGrid(filename);\n```\n\n## Citation \n\nTo cite DiscreGrid you can use this BibTeX entry:\n\n```bibtex\n@software{Discregrid_Library,\n   author = {Koschier, Dan and others},\n   license = {MIT},\n   title = {{Discregrid Library}},\n   url = {https://github.com/InteractiveComputerGraphics/Discregrid}\n}\n```\n\n## References\n\n* [KDBB17] D. Koschier, C. Deul, M. Brand and J. Bender, 2017. \"An hp-Adaptive Discretization Algorithm for Signed Distance Field Generation\", IEEE Transactions on Visualiztion and Computer Graphics 23, 10, 2208-2221.\n* [KB17] D. Koschier and J. Bender, 2017. \"Density Maps for Improved SPH Boundary Handling\", ACM SIGGRAPH/Eurographics Symposium on Computer Animation, 1-10.\n\n[PBD]: \u003chttps://github.com/InteractiveComputerGraphics/PositionBasedDynamics\u003e\n[SPlisHSPlasH]: \u003chttps://github.com/InteractiveComputerGraphics/SPlisHSPlasH\u003e\n","funding_links":[],"categories":["ComputerGraphics \u0026\u0026 Shadingv","Algorithms","Voxelizers","GameProgramming"],"sub_categories":["Google Analytics","Spatial Data Structures"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInteractiveComputerGraphics%2FDiscregrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FInteractiveComputerGraphics%2FDiscregrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInteractiveComputerGraphics%2FDiscregrid/lists"}