Skip to content

Commit

Permalink
style_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrishastin committed Oct 22, 2023
1 parent d7d8d44 commit b80c5a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 51 deletions.
91 changes: 42 additions & 49 deletions cpp/open3d/t/geometry/RaycastingScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void ListIntersectionsFunc(const RTCFilterFunctionNArguments* args) {
reinterpret_cast<const ListIntersectionsContext*>(args->context);
struct RTCRayN* rayN = args->ray;
struct RTCHitN* hitN = args->hit;
const unsigned int N = args->N;
const unsigned int N = args->N;

// Avoid crashing when debug visualizations are used.
if (context == nullptr) return;
Expand All @@ -138,7 +138,7 @@ void ListIntersectionsFunc(const RTCFilterFunctionNArguments* args) {
unsigned int* ray_ids = context->ray_ids;
unsigned int* geometry_ids = context->geometry_ids;
unsigned int* primitive_ids = context->primitive_ids;
float* t_hit = context->t_hit;
float* t_hit = context->t_hit;
Eigen::VectorXi cumsum = context->cumsum;
unsigned int* track_intersections = context->track_intersections;

Expand All @@ -162,20 +162,19 @@ void ListIntersectionsFunc(const RTCFilterFunctionNArguments* args) {
if (std::get<0>(prev_gpIDtfar) != hit.geomID ||
(std::get<1>(prev_gpIDtfar) != hit.primID &&
std::get<2>(prev_gpIDtfar) != ray.tfar)) {
size_t idx = cumsum[ray_id] + track_intersections[ray_id];
ray_ids[idx] = ray_id;
geometry_ids[idx] = hit.geomID;
primitive_ids[idx] = hit.primID;
t_hit[idx] = ray.tfar;
previous_geom_prim_ID_tfar->operator[](ray_id) = gpID;
++(track_intersections[ray_id]);
size_t idx = cumsum[ray_id] + track_intersections[ray_id];
ray_ids[idx] = ray_id;
geometry_ids[idx] = hit.geomID;
primitive_ids[idx] = hit.primID;
t_hit[idx] = ray.tfar;
previous_geom_prim_ID_tfar->operator[](ray_id) = gpID;
++(track_intersections[ray_id]);
}
// Always ignore hit
valid[ui] = 0;
}
}


// Adapted from common/math/closest_point.h
inline Vec3fa closestPointTriangle(Vec3fa const& p,
Vec3fa const& a,
Expand Down Expand Up @@ -547,18 +546,17 @@ struct RaycastingScene::Impl {
LoopFn);
}
}



void ListIntersections(const float* const rays,
const size_t num_rays,
const size_t num_intersections,
Eigen::VectorXi cumsum,
unsigned int* track_intersections,
unsigned int* ray_ids,
unsigned int* geometry_ids,
unsigned int* primitive_ids,
float* t_hit,
const int nthreads) {
const size_t num_rays,
const size_t num_intersections,
Eigen::VectorXi cumsum,
unsigned int* track_intersections,
unsigned int* ray_ids,
unsigned int* geometry_ids,
unsigned int* primitive_ids,
float* t_hit,
const int nthreads) {
CommitScene();

memset(track_intersections, 0, sizeof(uint32_t) * num_rays);
Expand Down Expand Up @@ -621,8 +619,7 @@ struct RaycastingScene::Impl {
tbb::blocked_range<size_t>(0, num_rays, BATCH_SIZE),
LoopFn);
}
}

}

void ComputeClosestPoints(const float* const query_points,
const size_t num_query_points,
Expand Down Expand Up @@ -833,59 +830,55 @@ core::Tensor RaycastingScene::CountIntersections(const core::Tensor& rays,
return intersections;
}


std::unordered_map<std::string, core::Tensor>
RaycastingScene::ListIntersections(const core::Tensor& rays,
const int nthreads) {
const int nthreads) {
AssertTensorDtypeLastDimDeviceMinNDim<float>(rays, "rays", 6,
impl_->tensor_device_);
auto shape = rays.GetShape();
shape.pop_back(); // Remove last dim, we want to use this shape for the
// results.
size_t num_rays = shape.NumElements();

// determine total number of intersections
core::Tensor intersections(shape, core::Dtype::FromType<int>());
core::Tensor track_intersections(shape, core::Dtype::FromType<uint32_t>());
auto data = rays.Contiguous();
impl_->CountIntersections(data.GetDataPtr<float>(), num_rays,
intersections.GetDataPtr<int>(), nthreads);
// prepare shape with that number of elements
intersections.GetDataPtr<int>(), nthreads);

// prepare shape with that number of elements
// not sure how to do proper conversion
const core::SizeVector dim = {0};
const core::SizeVector dim = {0};
Eigen::Map<Eigen::VectorXi> intersections_vector(
intersections.GetDataPtr<int>(), num_rays);
intersections.GetDataPtr<int>(), num_rays);
Eigen::Map<Eigen::VectorXi> num_intersections(
intersections.Sum(dim).GetDataPtr<int>(), 1);
intersections.Sum(dim).GetDataPtr<int>(), 1);
shape = {num_intersections[0], 1};

// prepare ray allocations (cumsum)
Eigen::VectorXi cumsum = Eigen::MatrixXi::Zero(num_rays, 1);
std::partial_sum(intersections_vector.begin(), intersections_vector.end() - 1,
cumsum.begin() + 1, std::plus<int>());

std::partial_sum(intersections_vector.begin(),
intersections_vector.end() - 1, cumsum.begin() + 1,
std::plus<int>());

// generate results structure
std::unordered_map<std::string, core::Tensor> result;
result["ray_ids"] = core::Tensor(shape, core::UInt32);
result["geometry_ids"] = core::Tensor(shape, core::UInt32);
result["geometry_ids"] = core::Tensor(shape, core::UInt32);
result["primitive_ids"] = core::Tensor(shape, core::UInt32);
result["t_hit"] = core::Tensor(shape, core::Float32);

impl_->ListIntersections(data.GetDataPtr<float>(),
num_rays,
num_intersections[0],
cumsum,
track_intersections.GetDataPtr<uint32_t>(),
result["ray_ids"].GetDataPtr<uint32_t>(),
result["geometry_ids"].GetDataPtr<uint32_t>(),
result["primitive_ids"].GetDataPtr<uint32_t>(),
result["t_hit"].GetDataPtr<float>(),
nthreads);

impl_->ListIntersections(data.GetDataPtr<float>(), num_rays,
num_intersections[0], cumsum,
track_intersections.GetDataPtr<uint32_t>(),
result["ray_ids"].GetDataPtr<uint32_t>(),
result["geometry_ids"].GetDataPtr<uint32_t>(),
result["primitive_ids"].GetDataPtr<uint32_t>(),
result["t_hit"].GetDataPtr<float>(), nthreads);
return result;
}


std::unordered_map<std::string, core::Tensor>
RaycastingScene::ComputeClosestPoints(const core::Tensor& query_points,
const int nthreads) {
Expand Down
5 changes: 3 additions & 2 deletions cpp/open3d/t/geometry/RaycastingScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class RaycastingScene {
/// closest triangle . The shape is {.., 3}.
std::unordered_map<std::string, core::Tensor> ListIntersections(
const core::Tensor &rays, const int nthreads = 0);

/// \brief Lists the intersections of the rays with the scene
/// \param query_points A tensor with >=2 dims, shape {.., 3} and Dtype
/// Float32 describing the query points. {..} can be any number of
Expand All @@ -138,7 +138,8 @@ class RaycastingScene {
/// {..}.
/// - \b primitive_ids A tensor with the primitive IDs, which
/// corresponds to the triangle index. The shape is {..}.
/// - \b t_hit A tensor with the distance to the hit. The shape is {..}.
/// - \b t_hit A tensor with the distance to the hit. The shape is
/// {..}.
std::unordered_map<std::string, core::Tensor> ComputeClosestPoints(
const core::Tensor &query_points, const int nthreads = 0);

Expand Down

0 comments on commit b80c5a9

Please sign in to comment.