Skip to content

Commit

Permalink
Minor updates (#273)
Browse files Browse the repository at this point in the history
* Added check to ransac model fit

* Added check to half edge index validity

* Added check to validity of vertex indices in computation of normal

* Added additional checks to normals from mesh faces modifier

* Updated PCL normal estimation mesh modifier widget
  • Loading branch information
marip8 authored Oct 8, 2024
1 parent cb0b044 commit ffd8182
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ NormalEstimationPCLMeshModifierWidget::NormalEstimationPCLMeshModifierWidget(QWi
{
auto* layout = new QVBoxLayout(this);

// Create a form layout with the normals radius parameter
{
auto* form_layout = new QFormLayout(this);
auto* form_layout = new QFormLayout();

radius_->setMinimum(0.0);
radius_->setValue(0.010);
Expand All @@ -30,6 +31,8 @@ NormalEstimationPCLMeshModifierWidget::NormalEstimationPCLMeshModifierWidget(QWi
// Set up the Vector3d editor
auto* widget = new QWidget(this);
view_point_->setupUi(widget);
view_point_->group_box->setTitle("View Point");

layout->addWidget(widget);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ Eigen::Vector3f computeFaceNormal(const pcl::PolygonMesh& mesh,

// Get the vertices of this triangle
VAFC v_circ = tri_mesh.getVertexAroundFaceCirculator(face_idx);
const Eigen::Vector3f v1 = getPoint(mesh.cloud, v_circ++.getTargetIndex().get());
const Eigen::Vector3f v2 = getPoint(mesh.cloud, v_circ++.getTargetIndex().get());
const Eigen::Vector3f v3 = getPoint(mesh.cloud, v_circ++.getTargetIndex().get());

const TriangleMesh::VertexIndex v1_idx = v_circ++.getTargetIndex();
const TriangleMesh::VertexIndex v2_idx = v_circ++.getTargetIndex();
const TriangleMesh::VertexIndex v3_idx = v_circ++.getTargetIndex();

// Check the validity of the vertices
if (!v1_idx.isValid() || !v2_idx.isValid() || !v3_idx.isValid())
return Eigen::Vector3f::Constant(std::numeric_limits<float>::quiet_NaN());

const Eigen::Vector3f v1 = getPoint(mesh.cloud, v1_idx.get());
const Eigen::Vector3f v2 = getPoint(mesh.cloud, v2_idx.get());
const Eigen::Vector3f v3 = getPoint(mesh.cloud, v3_idx.get());

// Get the edges v1 -> v2 and v1 -> v3
const Eigen::Vector3f edge_12 = v2 - v1;
Expand All @@ -43,14 +52,23 @@ std::vector<pcl::PolygonMesh> NormalsFromMeshFacesMeshModifier::modify(const pcl

using FAVC = TriangleMesh::FaceAroundVertexCirculator;
FAVC circ = tri_mesh.getFaceAroundVertexCirculator(TriangleMesh::VertexIndex(i));

FAVC circ_end = circ;
do
{
TriangleMesh::FaceIndex face_idx = circ.getTargetIndex();
if (face_idx.isValid())
if (n_faces > mesh.polygons.size())
throw std::runtime_error("Vertex " + std::to_string(i) +
" appears to participate in more faces than exist in the mesh; this mesh likely "
"contains degenerate half-edges.");

if (circ.isValid())
{
avg_face_normal += computeFaceNormal(mesh, tri_mesh, face_idx);
++n_faces;
TriangleMesh::FaceIndex face_idx = circ.getTargetIndex();
if (face_idx.isValid())
{
avg_face_normal += computeFaceNormal(mesh, tri_mesh, face_idx);
++n_faces;
}
}
} while (++circ != circ_end);

Expand Down
3 changes: 2 additions & 1 deletion noether_tpp/src/mesh_modifiers/plane_projection_modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ std::vector<pcl::PolygonMesh> PlaneProjectionMeshModifier::modify(const pcl::Pol
{
// Fit a plane model to the vertices using RANSAC
model->setIndices(remaining_indices);
ransac->computeModel();
if (!ransac->computeModel())
break;

// Extract the inliers
std::vector<int> inliers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ std::vector<typename MeshT::HalfEdgeIndices> getBoundaryHalfEdges(const MeshT& m
IHEAFC circ_end = circ;
do
{
visited[pcl::geometry::toEdgeIndex(circ.getTargetIndex()).get()] = true;
HalfEdgeIndex he_idx = circ.getTargetIndex();
if (!he_idx.isValid())
break;

visited[pcl::geometry::toEdgeIndex(he_idx).get()] = true;
boundary_he.push_back(circ.getTargetIndex());
} while (++circ != circ_end);

Expand Down

0 comments on commit ffd8182

Please sign in to comment.