Code Monkey home page Code Monkey logo

cadop / dhart Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 3.0 233.56 MB

A library for Navigation Graphs, Visibility, Raycasting and other features for Design Humans Analysis RoboTics (DHART).

Home Page: https://cadop.github.io/dhart/

License: GNU General Public License v3.0

C++ 77.11% CMake 1.25% C 0.01% C# 10.13% Python 9.76% CSS 1.72%
navigation raycasting built-environment computational-design navmesh visibility-graph human-navagation path-planning python simulation navgraph navigationgraph

dhart's Introduction

Overview

Welcome to DHART:a C++ package with interfaces to Python, C, and C# for Design, Humans, Analysis, and RoboTics.

There are a few components to the package, but the main focus is in providing fast ray-casting interfaces for python and C# for a variety of analysis and evaluation techniques. Generally, you should be able to build a grid-like structure of the floors for a 3D model, calculate shortest paths by distance/visibility/energy and custom metrics, and use these tools inside of a variety of programs such as Unity, Rhino, and more.

We have extensive documentation on the API, and welcome new contributions and bug fixes. Please make sure to take a look at the contributing guide.

Featured Image

Limitations

  • Currently it is only available on Windows OS. (We happily would accept contributors to help expand to Linux. )
  • Integration with Rhino is currently limited to viewing analysis results through json files.

Coming Soon

  • Rhino and Grasshopper Plugin
  • Additional documentation for how to simulate LIDAR in python
  • Dedicated Releases for each language
  • Revit Plugin

Features

  • Python, C, C#, C++ interface
  • Extract connected grid-based graphs from 3d models
  • Calculate shortest path based on Distance, Energy, Visibility, and others
  • Graph parsing traverses stairs and slopes
  • Easily generate visibility graphs and analyze locations of environment
  • Calculate view scores, percentage of view, and points of interest
  • Uses Embree raytracer for fast raycasting
  • Has switchable backend to use nanoRT for raycasting with double precision
  • Demos and instructions for integrating with Rhino 3D and Unity

Credits

This repository contains work that was supported in part by the U.S. Army Combat Capabilities Development Command (CCDC) Armaments Center and the U.S. Army ManTech Office under Contract Delivery Order W15QKN19F0002 - Advanced Development of Asset Protection Technologies (ADAPT).

Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the Army Contracting Command - New Jersey.

If you find this repo useful, please cite using the following bibtex

@article{schwartz2021human,
  title={Human centric accessibility graph for environment analysis},
  author={Schwartz, Mathew},
  journal={Automation in Construction},
  volume={127},
  pages={103557},
  year={2021},
  publisher={Elsevier}
}

Example Usage

Once the python package is installed, the basic setup for loading a model (e.g. obj), setting its rotation (if its not default z up), and creating a BVH (the accelerated structure of the mesh) is done by:

from dhart.geometry import LoadOBJ, CommonRotations
from dhart.raytracer import (EmbreeBVH,Intersect,
                                        IntersectForPoint,
                                        IntersectOccluded)
import dhart

# Get model path
obj_path = dhart.get_sample_model('plane.obj')
# Load mesh
loaded_obj = LoadOBJ(obj_path, rotation=CommonRotations.Yup_to_Zup)
# Create BVH
bvh = EmbreeBVH(loaded_obj)

After this, different methods for casting a ray can be used:

# Define point to start ray
p1 = (0, 0, 2)
# Define direction to cast ray
dir = (0, 0, -1)

# Cast a ray for the hitpoint
hit_point = IntersectForPoint(bvh, p1, dir, -1)
print(f"Hit point: {hit_point}")

# Cast a ray for distance/meshid
distance, mesh_id = Intersect(bvh, p1, dir, -1)
print(f"distance is {distance}, meshid is {mesh_id}")

# See if it occludes
does_occlude = IntersectOccluded(bvh, p1, (0, 0, -1), 9999)
print(f"Does the ray connect? {does_occlude}")

which would output

Hit point: (0.0, 0.0, 0.0)
distance is 2.0, meshid is 0
Does the ray connect? True

Getting started

Installing

  • Requires Windows 10
  • Tested on Python 3.8 +

For Python you can use

pip install dhart

In the latest release you can additionally use pip install dhart[dev] to install packages needed for visualization of examples and documentation.

  • However, if you would like to use Python with Rhino Grasshopper, you will need to follow the install instructions in the Python Docs.

For C# you can download from the Releases page.

  • Of course, you can always clone this repo and build the project yourself.

We supply .dll's to try and make the installation and linking process as easy as possible.

Building from Source

You can use cmake on the commandline or Visual Studio, follow the instructions in BUILD.md to get started.

dhart's People

Contributors

actions-user avatar cadop avatar db368 avatar galudino avatar mariuszhermansdorfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dhart's Issues

Add tests to CI

Pytest, doctest, and google tests are used within the repo, but they currently aren't integrated with workflows. Need to add them to pull request on main.

C API crashes when invalid mesh is used by a BVH or can't be cleaned up

Currently just experienced with Unity when creating a BVH with 0 vertices, the C API will crash when trying to use this invalid mesh for raycasting.

While this isn't a priority since it only happens when incorrectly setting the BVH, it would be nice to have a more graceful exit.

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at DHARTAPI.RayTracing.NativeMethods:DestroyRayTracer <0x00126>
	  at DHARTAPI.RayTracing.NativeMethods:C_DestroyRayTracer <0x00072>
	  at DHARTAPI.RayTracing.EmbreeBVH:ReleaseHandle <0x00072>
	  at System.Runtime.InteropServices.SafeHandle:DangerousReleaseInternal <0x00670>
	  at System.Runtime.InteropServices.SafeHandle:InternalFinalize <0x0009a>
	  at System.Runtime.InteropServices.SafeHandle:Dispose <0x000e2>
	  at System.Runtime.InteropServices.SafeHandle:Finalize <0x0006b>
	  at DHARTAPI.NativeUtils.NativeObject:Finalize <0x00142>
	  at System.Object:runtime_invoke_virtual_void__this__ <0x0018b>
=================================================================

and


0x00007FF88F7446DF (embree3) rtcReleaseScene
0x00007FF8A36CE273 (DHARTAPI) GetPathInfo
0x00007FF8A36C5573 (DHARTAPI) DestroyRayTracer

Documentation for Build missing visuals

There is a build.md in the main directory, but it does not contain any image guides and is not included in the C++/C#/Python docs.

Need to add a walkthrough of using visual studio to build the project from source, regenerating cmake, opening the build solution, using the cmake install (in VS).

Add support for stream of rays in Embree

Currently, DHART only shoots single rays with the rtcOccluded1 method:

bool EmbreeRayTracer::Occluded_IMPL(float x, float y, float z, float dx, float dy, float dz, float distance, int mesh_id)
{
auto ray = ConstructRay(x, y, z, dx, dy, dz, distance);
rtcOccluded1(scene, &context, &ray);
return ray.tfar == -INFINITY;
}

Embree, however, supports shooting streams of rays in various configurations:
rtcOccluded1M
rtcOccluded1Mp
rtcOccludedNp

Furthermore, 3 flags can be passed to the intersection context to speed up ray traversal:
https://spec.oneapi.io/oneart/latest/embree-spec.html#rtcinitintersectcontext

enum RTCIntersectContextFlags
{
  RTC_INTERSECT_CONTEXT_FLAG_NONE,
  RTC_INTERSECT_CONTEXT_FLAG_INCOHERENT,
  RTC_INTERSECT_CONTEXT_FLAG_COHERENT,
}; 

It would be great if these could be added to the c# wrapper as well.

Missing Rhino and Grasshopper Plugin

Currently users need to export the mesh data from grasshopper and load in visualization results. We need to add a build of the plugin for direct access.

Website needs better buttons

The current index.html simply defines some HTML buttons to navigate to individual docs. It would be nice to improve this landing/splash page.

Expose Save OBJ options

The Load OBJ functions are available for an obj file and create a mesh info. It would be helpful to debug and recognize what is being used in an analysis if mesh info was able to be stored as an obj file (which can then be loaded in a graphics tool).

Git functionality not working in VS 2022

When trying to switch between branches or committing to the active one from VS 2022 I get the following error:

Git failed with a fatal error.
Git failed with a fatal error.
unable to parse command-line config

Error reading git config: error running C:\Users\MRHE\AppData\Local\Programs\Git\mingw64\bin\git.exe 'config' '-l': 'error: bogus format in GIT_CONFIG_PARAMETERS
unable to parse command-line config' 'exit status 128'

The Git for Windows Desktop App works fine.
This is the first time I encounter a similar problem and unfortunately don't really know how to troubleshoot it.

EDIT, here is the error message when I try to pull from remote:

Remote: Total 74 (delta 52), reused 71 (delta 49), pack-reused 0        
From https://github.com/mariuszhermansdorfer/dhart
   f78e70523..5155c7795  support-for-stream-of-rays-in-embree -> origin/support-for-stream-of-rays-in-embree
Updating f78e70523..5155c7795
Error: failed to call git rev-parse --git-dir: exit status 128 : error: bogus format in GIT_CONFIG_PARAMETERS
Git failed with a fatal error.
Git failed with a fatal error.
unable to parse command-line config

Error reading git config: error running C:\Users\MRHE\AppData\Local\Programs\Git\mingw64\bin\git.exe 'config' '-l': 'error: bogus format in GIT_CONFIG_PARAMETERS
unable to parse command-line config' 'exit status 128'

Consider adding a method to modify an existing BVH in embree

Use case description:

I'm working with a large mesh (500.000 quads) against which I constantly cast single rays from mouse cursor's position. This mesh is then modified while the mouse moves. At any given time only a few dozen vertices are affected. Only vertex position changes, face indices remain unchanged.

Wish

I'd like to be able to keep the existing BVH and only update a subset of vertices.

@cadop, do you have any ideas on how to approach this?

Unity integration is not supported in Editor

The current unity integration demo requires users to build and run the project, so it works for releasing and running a Unity project, but not for running with the editor.

The issue is when users drag the DLLs into Assets, there is no error, and can use the DLL in visual studio. However, when pressing play in the editor, it says that the C DLL is not found and errors with DLLNotFoundException: DHARTAPI.dll. When using build and run the target project does work.

I am not sure how to solve it, or how to make the process easier.

Missing individual package build explanation

There was an early decision to make packages that were not reliant on all the other packages.

There needs to be documentation showing how to compile and build only one part, such as the raytracing package.

Python Examples

Need two sets of examples:

  • One setup showing just the python side.
  • One setup for Rhino python, using the repo to save through json

Add Release workflow

Setup github actions to automatically create release/tags on pull to the main branch.

Old C Interface unittests are commented out

CMake config comments out c_interface tests:

dhart/src/CMakeLists.txt

Lines 416 to 422 in 8aa1655

# ${C_TEST_DRIVER_DIR}/embree_raytracer_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/objloader_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/analysis_C_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/pathfinder_C_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/view_analysis_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/visibility_graph_cinterface.cpp
# ${C_TEST_DRIVER_DIR}/spatialstructures_C_cinterface.cpp

Need to look back and find when this happened and if all tests are covered by other ones, as the interface seems to be an older version:

status = LoadOBJ(obj_path_str.c_str(), obj_length, rot[0], rot[1], rot[2], &loaded_obj);

Add built-in for object distance in graph

From the SHAPE paper, it shows how to make a path in the center of the room without removing nodes. This should be a default edge set value that takes in a specified distance and perhaps a falloff coefficient (function?)

Building in command line places build folder outside of repo

Describe the bug
Building from the command line produces warnings. Build completes successfully but places build folder in unexpected directory.

To Reproduce
Follow build instructions for Python Release

Expected behavior
No warnings are expected
Build folder is expected at dhart/build/Python/

Screenshots
The following output is produced by the first step:

-- Selecting Windows SDK version 10.0.20348.0 to target Windows 10.0.19044.
cmake : CMake Warning:
At line:1 char:1
+ cmake ./src/  -G"Visual Studio 16 2019"  -DCMAKE_GENERATOR_PLATFORM=" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CMake Warning::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
  Ignoring extra path from command line:
   ".\"
-- The C compiler identification is MSVC 19.29.30146.0
-- The CXX compiler identification is MSVC 19.29.30146.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
 EIGEN DIR 
 ROBIN_HOOD 
[STATUS]All Selected as the current DHARTAPI_Configuration
[STATUS]Generating all packages
[STATUS]Setting embree dir to C:/Users/USER/Documents/GitHub/dhart/src/external/Embree
Installing Python!
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:
    INSTALL_GTEST
-- Build files have been written to: C:/Users/USER/Documents/GitHub/dhart

Build and install complete successfully.

Build folder appears in the parent directory.

Additional context

Some of the Visual Studio tools required in BUILD.md are not listed in the Visual Studio Community 2019 Installer by name. As many as could be found + anything related was used.

consider changing C_Interface to use floats

Another idea I had was to simplify another data conversion on the c++ side. What is the rationale behind the conversions in lines 273 & 274?

C_INTERFACE CastOcclusionRays(EmbreeRayTracer* ert, const float* origins, const float* directions, int origin_size, int direction_size, float max_distance, bool* result_array)
{
auto origin_array = ConvertRawFloatArrayToPoints(origins, origin_size);
auto direction_array = ConvertRawFloatArrayToPoints(directions, direction_size);
const auto results = ert->Occlusions(origin_array, direction_array, max_distance, true);
std::copy(results.begin(), results.end(), result_array);
return OK;
}

In the end, we need float values anyway:

bool EmbreeRayTracer::Occluded_IMPL(float x, float y, float z, float dx, float dy, float dz, float distance, int mesh_id)
{
auto ray = ConstructRay(x, y, z, dx, dy, dz, distance);
rtcOccluded1(scene, &context, &ray);
return ray.tfar == -INFINITY;
}

If it's only to make looping over data more convenient, then it could be restructured to operating directly on a pointer to the float array we pass from c#. This could shave off another few ms per call.

Originally posted by @mariuszhermansdorfer in #33 (reply in thread)

Expose Edge Types

Edge type for step etc. is not exposed in C API.

EdgeSet is using intedge, which is 'lightweight', probably for performance. If performance isn't too bad, include an edgeset with cost type stored. Doesn't need to be returned with graph, but should act like a custom attribute or energy expenditure for query on an edge id.

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.