[Shortest Paths] There are situations where there is no return point set and a large number of duplicate points occur

Open
#8,979 5 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 3 days

@sloriot is already working on this.

Since Jul 18, 2025.

Assessment

This issue has not been assessed yet.

Description

Hello, I encountered a series of problems when testing the function of Triangulated Surface Mesh Shortest Paths to find the shortest path of any two points on the model surface using other models. For example, when using the bathtub model, the path point returned by the algorithm was 0. When testing with the hilbert_cube2_pds_100k_surface.obj model provided by your KSR, a large number of duplicate points occurred, and some points drifted off the surface of the model. The following are my running environment, code and model file

Runtime environment

  • Operating system:Windows 11
  • Compiler:Visual Studio2022
  • CGAL version:6.0.1
  • Boost version:1.88.0

Code

  • The code when using the bathtub model
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>

#include <CGAL/Surface_mesh_shortest_path.h>
#include <CGAL/Random.h>

#include <boost/lexical_cast.hpp>

#include <cstdlib>
#include <iostream>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Triangle_mesh;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Triangle_mesh> Traits;
typedef CGAL::Surface_mesh_shortest_path<Traits> Surface_mesh_shortest_path;
typedef boost::graph_traits<Triangle_mesh> Graph_traits;
typedef Graph_traits::vertex_iterator vertex_iterator;
typedef Graph_traits::face_iterator face_iterator;

int main(int argc, char** argv)
{
    const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("bathtub_0001.obj");

    Triangle_mesh tmesh;
    if (!CGAL::IO::read_polygon_mesh(filename, tmesh))
    {
        std::cerr << "Invalid input file1." << std::endl;
        return EXIT_FAILURE;
    }

    const int target_face_index = 79;
    face_iterator face_it = faces(tmesh).first;
    std::advance(face_it, target_face_index);
    // ... and define a barycentric coordinates inside the face
    Traits::Barycentric_coordinates face_location1 = { {0.04761892557144165,0.5907313227653503,0.36164984107017517} };
    Traits::Barycentric_coordinates face_location2 = { {0.3858107328414917, 0.3522464334964752,0.2619428336620331} };

    // construct a shortest path query object and add a source point
    Surface_mesh_shortest_path shortest_paths(tmesh);
    shortest_paths.add_source_point(*face_it, face_location1);
    std::cout << *face_it << std::endl;
    // For all vertices in the tmesh, compute the points of
    // the shortest path to the source point and write them
    // into a file readable using CGAL Lab
    std::ofstream output("shortest_paths.txt");
    face_iterator f_it = faces(tmesh).first;
    std::advance(f_it, 750);
    std::vector<Traits::Point_3> points;
    std::cout << *f_it << std::endl;
    shortest_paths.shortest_path_points_to_source_points(*f_it, face_location2, std::back_inserter(points));

    // print the points
    output << points.size() << " ";
    for (std::size_t i = 0; i < points.size(); ++i)
        output << " " << points[i];
    output << std::endl;
}
  • The code when using the cube model
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>

#include <CGAL/Surface_mesh_shortest_path.h>
#include <CGAL/Random.h>

#include <boost/lexical_cast.hpp>

#include <cstdlib>
#include <iostream>
#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Triangle_mesh;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Triangle_mesh> Traits;
typedef CGAL::Surface_mesh_shortest_path<Traits> Surface_mesh_shortest_path;
typedef boost::graph_traits<Triangle_mesh> Graph_traits;
typedef Graph_traits::vertex_iterator vertex_iterator;
typedef Graph_traits::face_iterator face_iterator;

int main(int argc, char** argv)
{
    const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("hilbert_cube2_pds_100k_surface.obj");

    Triangle_mesh tmesh;
    if (!CGAL::IO::read_polygon_mesh(filename, tmesh))
    {
        std::cerr << "Invalid input file1." << std::endl;
        return EXIT_FAILURE;
    }

    const int target_face_index = 4880;
    face_iterator face_it = faces(tmesh).first;
    std::advance(face_it, target_face_index);
    // ... and define a barycentric coordinates inside the face
    Traits::Barycentric_coordinates face_location1 = { {0.46936893463134766,0.11540794372558594,0.4152231216430664} };
    Traits::Barycentric_coordinates face_location2 = { {0.16719023883342743, 0.47327518463134766,0.3595345914363861} };

    // construct a shortest path query object and add a source point
    Surface_mesh_shortest_path shortest_paths(tmesh);
    shortest_paths.add_source_point(*face_it, face_location1);
    std::cout << *face_it << std::endl;
    // For all vertices in the tmesh, compute the points of
    // the shortest path to the source point and write them
    // into a file readable using CGAL Lab
    std::ofstream output("shortest_paths.txt");
    face_iterator f_it = faces(tmesh).first;
    std::advance(f_it, 5749);
    std::vector<Traits::Point_3> points;
    std::cout << *f_it << std::endl;
    shortest_paths.shortest_path_points_to_source_points(*f_it, face_location2, std::back_inserter(points));

    // print the points
    output << points.size() << " ";
    for (std::size_t i = 0; i < points.size(); ++i)
        output << " " << points[i];
    output << std::endl;
}

Files

shortest_paths_bath.txt

shortest_paths_cube.txt

Model file.zip

Dominant language
C++
Stars
6.1k
Forks
1.6k
Avg merge
3d 19h
Merged PRs (30d)
55

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CGAL/cgal

All issues in CGAL/cgal

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.