From b80c5a90fddc33794616be51cd597dff6eca4e8f Mon Sep 17 00:00:00 2001 From: dmitrishastin Date: Sun, 22 Oct 2023 14:55:34 +0100 Subject: [PATCH] style_checks --- cpp/open3d/t/geometry/RaycastingScene.cpp | 91 +++++++++++------------ cpp/open3d/t/geometry/RaycastingScene.h | 5 +- 2 files changed, 45 insertions(+), 51 deletions(-) diff --git a/cpp/open3d/t/geometry/RaycastingScene.cpp b/cpp/open3d/t/geometry/RaycastingScene.cpp index c2099f72307..2895b7ac2db 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.cpp +++ b/cpp/open3d/t/geometry/RaycastingScene.cpp @@ -128,7 +128,7 @@ void ListIntersectionsFunc(const RTCFilterFunctionNArguments* args) { reinterpret_cast(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; @@ -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; @@ -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, @@ -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); @@ -621,8 +619,7 @@ struct RaycastingScene::Impl { tbb::blocked_range(0, num_rays, BATCH_SIZE), LoopFn); } - } - + } void ComputeClosestPoints(const float* const query_points, const size_t num_query_points, @@ -833,59 +830,55 @@ core::Tensor RaycastingScene::CountIntersections(const core::Tensor& rays, return intersections; } - std::unordered_map RaycastingScene::ListIntersections(const core::Tensor& rays, - const int nthreads) { + const int nthreads) { AssertTensorDtypeLastDimDeviceMinNDim(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()); core::Tensor track_intersections(shape, core::Dtype::FromType()); auto data = rays.Contiguous(); impl_->CountIntersections(data.GetDataPtr(), num_rays, - intersections.GetDataPtr(), nthreads); - - // prepare shape with that number of elements + intersections.GetDataPtr(), 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 intersections_vector( - intersections.GetDataPtr(), num_rays); + intersections.GetDataPtr(), num_rays); Eigen::Map num_intersections( - intersections.Sum(dim).GetDataPtr(), 1); + intersections.Sum(dim).GetDataPtr(), 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()); - + std::partial_sum(intersections_vector.begin(), + intersections_vector.end() - 1, cumsum.begin() + 1, + std::plus()); + // generate results structure std::unordered_map 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(), - num_rays, - num_intersections[0], - cumsum, - track_intersections.GetDataPtr(), - result["ray_ids"].GetDataPtr(), - result["geometry_ids"].GetDataPtr(), - result["primitive_ids"].GetDataPtr(), - result["t_hit"].GetDataPtr(), - nthreads); + + impl_->ListIntersections(data.GetDataPtr(), num_rays, + num_intersections[0], cumsum, + track_intersections.GetDataPtr(), + result["ray_ids"].GetDataPtr(), + result["geometry_ids"].GetDataPtr(), + result["primitive_ids"].GetDataPtr(), + result["t_hit"].GetDataPtr(), nthreads); return result; } - std::unordered_map RaycastingScene::ComputeClosestPoints(const core::Tensor& query_points, const int nthreads) { diff --git a/cpp/open3d/t/geometry/RaycastingScene.h b/cpp/open3d/t/geometry/RaycastingScene.h index 3e102d128f2..527ee90ddb6 100644 --- a/cpp/open3d/t/geometry/RaycastingScene.h +++ b/cpp/open3d/t/geometry/RaycastingScene.h @@ -124,7 +124,7 @@ class RaycastingScene { /// closest triangle . The shape is {.., 3}. std::unordered_map 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 @@ -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 ComputeClosestPoints( const core::Tensor &query_points, const int nthreads = 0);