Skip to content

Commit

Permalink
centroid function cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-jfisher committed Nov 15, 2023
1 parent 17d3a6a commit 778a1f1
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions pasture-algorithms/src/normal_estimation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,43 +210,21 @@ where
return None;
}

let mut centroid = Vector3::<F>::zeros();
let mut temp_centroid = Vector3::<F>::zeros();

let points_in_cloud = if is_dense(attribute_view) {
if is_dense(attribute_view) {
// add all points up
let points_in_cloud = attribute_view.len();
for point in attribute_view.into_iter() {
temp_centroid[0] += point.x;
temp_centroid[1] += point.y;
temp_centroid[2] += point.z;
}

// normalize over all points
centroid[0] = temp_centroid[0] / points_in_cloud.as_();
centroid[1] = temp_centroid[1] / points_in_cloud.as_();
centroid[2] = temp_centroid[2] / points_in_cloud.as_();
points_in_cloud
Some(attribute_view.into_iter().sum::<Vector3<F>>() / points_in_cloud.as_())
} else {
let mut temp_centroid = Vector3::<F>::zeros();
let mut points_in_cloud = 0;
for point in attribute_view.into_iter() {
if is_finite(&point) {
// add all points up
temp_centroid[0] += point.x;
temp_centroid[1] += point.y;
temp_centroid[2] += point.z;
temp_centroid += point;
points_in_cloud += 1;
}
}
points_in_cloud
};

// normalize over all points
centroid[0] = temp_centroid[0] / points_in_cloud.as_();
centroid[1] = temp_centroid[1] / points_in_cloud.as_();
centroid[2] = temp_centroid[2] / points_in_cloud.as_();

Some(centroid)
Some(temp_centroid / points_in_cloud.as_())
}
}

/// compute the covariance matrix for a given point cloud which is a measure of spread out the points are
Expand Down

0 comments on commit 778a1f1

Please sign in to comment.