27 if (*out_raytracer != NULL)
28 delete *out_raytracer;
32 if (*out_raytracer != NULL)
33 delete *out_raytracer;
47 for (
int i = 0; i < num_meshes; i++) {
49 bool should_commit = (i == num_meshes - 1);
51 (*out_raytracer)->AddMesh(*(meshes[i]), should_commit);
58 if (*out_raytracer != NULL)
59 delete* out_raytracer;
63 if (*out_raytracer != NULL)
64 delete* out_raytracer;
75 for (
int i = 0; i < number_of_meshes; i++) {
76 bool should_commit = (i == number_of_meshes - 1);
78 ERT->
AddMesh(*(MI[i]), should_commit);
101 const float* direction,
102 const float max_distance,
117 std::vector<RayResult>** out_results,
127 if (num_origins == num_directions)
129 else if (num_origins == 1 && num_directions > 1)
131 else if (num_origins > 1 && num_directions == 1)
132 type = ONE_DIRECTION;
134 fprintf(stderr,
"[C++] Invalid input. num_origins = %d, num_directions = %d\n", num_origins, num_directions);
137 std::vector<RayResult>* output_results;
145 output_results =
new std::vector<RayResult>(num_origins);
147#pragma omp parallel for schedule(dynamic)
148 for (
int i = 0; i < num_origins; i++) {
149 float out_distance = -1;
152 (*output_results)[i].SetHit(origin_pts[i], direction_pts[i], out_distance, out_id);
159 std::array<float, 3> origin = { origins[0], origins[1], origins[2] };
162 output_results =
new std::vector<RayResult>(num_origins);
163 #pragma omp parallel for schedule(dynamic)
164 for (
int i = 0; i < num_directions; i++) {
165 float out_distance = -1;
int out_id = -1;
167 (*output_results)[i].SetHit(origin, direction_pts[i], out_distance, out_id);
173 std::array<float, 3> direction = { directions[0], directions[1], directions[2] };
176 output_results =
new std::vector<RayResult>(num_origins);
177 #pragma omp parallel for schedule(dynamic)
178 for (
int i = 0; i < num_origins; i++) {
179 float out_distance = -1;
int out_id = -1;
181 (*output_results)[i].SetHit(origin_pts[i], direction, out_distance, out_id);
188 *out_results = output_results;
189 *results_data = output_results->data();
202 const float* directions,
209 auto results = ert->
PointIntersections(origin_array, dir_array, size,
true, max_distance);
211 for (
int i = 0; i < size; i++) {
214 const int offset = i * 3;
215 const auto& hit_point = origin_array[i];
216 origins[offset] = hit_point[0];
217 origins[offset + 1] = hit_point[1];
218 origins[offset + 2] = hit_point[2];
219 result_array[i] =
true;
222 result_array[i] =
false;
231 auto results = ert->
PointIntersections(origin_array, dir_array, size,
true, max_distance);
233 for (
int i = 0; i < size; i++) {
236 const int offset = i * 3;
237 const auto& hit_point = origin_array[i];
238 origins[offset] = hit_point[0];
239 origins[offset + 1] = hit_point[1];
240 origins[offset + 2] = hit_point[2];
241 result_array[i] =
true;
244 result_array[i] =
false;
253 auto results = ert->
PointIntersections(origin_array, dir_array, size,
true, max_distance);
255 for (
int i = 0; i < size; i++) {
258 const int offset = i * 3;
259 const auto& hit_point = dir_array[i];
260 directions[offset] = hit_point[0];
261 directions[offset + 1] = hit_point[1];
262 directions[offset + 2] = hit_point[2];
263 result_array[i] =
true;
266 result_array[i] =
false;
275 const auto results = ert->
Occlusions(origin_array, direction_array, max_distance,
true);
277 std::copy(results.begin(), results.end(), result_array);
294 double * out_distance)
297 *out_distance = -1.0;
Contains definitions for the Exceptions namespace.
Contains definitions for the MeshInfo class.
Contains definitions for the EmbreeRayTracer
std::vector< std::array< float, 3 > > ConvertRawFloatArrayToPoints(const float *raw_array, int size)
Convert a raw array from an external caller to an organized vector of points
void DeleteRawPtr(T *ptr)
Delete some object pointed to by ptr
C Interface header file for Raytracer functionality.
C_INTERFACE AddMeshes(HF::RayTracer::EmbreeRayTracer *ERT, MeshInfo **MI, int number_of_meshes)
Add a new mesh to a raytracer.
C_INTERFACE CastSingleRayDistance(HF::RayTracer::EmbreeRayTracer *ert, const float *origin, const float *direction, const float max_distance, float *out_distance, int *out_meshid)
Cast a single ray and get the distance to its hit and the mesh ID if it hit anything....
C_INTERFACE CreateRaytracer(MeshInfo *mesh, EmbreeRayTracer **out_raytracer, bool use_precise)
Create a new raytracer using several meshes.
C_INTERFACE DestroyRayResultVector(std::vector< RayResult > *var)
Destroy a vector of rayresults.
C_INTERFACE CastMultipleRays(EmbreeRayTracer *ert, float *origins, const float *directions, int size, float max_distance, bool *result_array)
Cast multiple rays at once in parallel and receive their hitpoints in return. The number of direction...
C_INTERFACE AddMesh(HF::RayTracer::EmbreeRayTracer *ERT, MeshInfo *MI)
Add a new mesh to a raytracer.
C_INTERFACE CastRaysDistance(HF::RayTracer::EmbreeRayTracer *ert, float *origins, int num_origins, float *directions, int num_directions, std::vector< RayResult > **out_results, RayResult **results_data)
Cast rays for each node in origins/directions as ordered pairs and get distance back as a result.
C_INTERFACE CastMultipleDirectionsOneOrigin(EmbreeRayTracer *ert, const float *origin, float *directions, int size, float max_distance, bool *result_array)
Cast rays from a single origin point in multiple directions and get a the points where they intersect...
C_INTERFACE CastRay(EmbreeRayTracer *ert, float &x, float &y, float &z, float dx, float dy, float dz, float max_distance, bool &result)
Cast a single ray from the raytracer and receive a point in return.
C_INTERFACE CreateRaytracerMultiMesh(MeshInfo **meshes, int num_meshes, EmbreeRayTracer **out_raytracer, bool use_precise)
Create a new raytracer using several meshes.
C_INTERFACE DestroyRayTracer(HF::RayTracer::EmbreeRayTracer *rt_to_destroy)
Delete an existing raytracer.
C_INTERFACE PreciseIntersection(HF::RayTracer::EmbreeRayTracer *RT, double x, double y, double z, double dx, double dy, double dz, double *out_distance)
C_INTERFACE CastOcclusionRays(EmbreeRayTracer *ert, const float *origins, const float *directions, int origin_size, int direction_size, float max_distance, bool *result_array)
Cast one or more occlusion rays in parallel.
C_INTERFACE CastMultipleOriginsOneDirection(EmbreeRayTracer *ert, float *origins, const float *direction, int size, float max_distance, bool *result_array)
Cast rays from each origin point in the given direction.
Custom exceptions and error codes used interally by DHARTAPI.
@ INVALID_OBJ
The given path did not point to a valid obj file.
@ OK
Operation was successful.
@ MISSING_DEPEND
A dependency for this object is missing.
@ GENERIC_ERROR
Not sure what happened here (If this gets thrown, either fix it or give it a status code!...
The OBJ file was not valid.
Thrown when a dependency is missing such as Embree.
A collection of vertices and indices representing geometry.
A wrapper for Intel's Embree Library.
std::vector< char > PointIntersections(std::vector< std::array< float, 3 > > &origins, std::vector< std::array< float, 3 > > &directions, bool use_parallel=true, float max_distance=-1, int mesh_id=-1)
Cast multiple rays and recieve hitpoints in return.
bool AddMesh(std::vector< std::array< float, 3 > > &Mesh, int ID, bool Commit=false)
Add a new mesh to this raytracer's BVH with the specified ID.
bool IntersectOutputArguments(const N &node, const V &direction, return_type &out_distance, int &out_meshid, float max_distance=-1.0f)
Cast a ray from origin in direction and update the parameters instead of returning a hitstruct.
bool PointIntersection(std::array< float, 3 > &origin, const std::array< float, 3 > &dir, float distance=-1, int mesh_id=-1)
Cast a ray and overwrite the origin with the hitpoint if it intersects any geometry.
HitStruct< return_type > Intersect(const N &node, const V &direction, float max_distance=-1.0f, int mesh_id=-0.1f)
Cast a ray from origin in direction.
std::vector< char > Occlusions(const std::vector< std::array< float, 3 > > &origins, const std::vector< std::array< float, 3 > > &directions, float max_distance=-1, bool use_parallel=true)
Cast multiple occlusion rays in parallel.
A simple hit struct to carry all relevant information about hits.
numeric_type distance
Distance from the origin point to the hit point. Set to -1 if no hit was recorded.
The result of casting a ray at an object. Contains distance to the hitpoint and the ID of the mesh.