cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Unknown information " -wrongvalue:-nan"

Open MenglinQiu opened this issue 1 year ago • 2 comments

Issue Details

I modified the sample code region_growing_planes_on_point_set_3.cpp and used an array to assign the instance input_range instead of reading the point cloud directly from the file. When I ran the code, an message "-wrongvalue:-nan" appeared, as well as an incorrect result. I located the specific location of the error, which was generated when region_growing.detect(std::back_inserter(result.regions)) was executed. Is it because the point cloud instance input_range is not initialized correctly? Please help me determine the source of the problem.

Describe your issue. Please be specific (compilation error, runtime error, unexpected behavior, wrong results, etc.).

Source Code


    RegionGrowingResult pcRegionGrowing(
    const pybind11::array_t<double>& points_np,
    double pc_distance_to_plane,
    double pc_accepted_angle,
    std::size_t pc_minimum_region_size = 1,
    std::size_t knn = 10
)
{
    // Default parameter.
    const std::size_t k                     = knn;
    const FT          max_distance_to_plane = FT(pc_distance_to_plane);
    const FT          max_accepted_angle    = FT(pc_accepted_angle);
    const std::size_t min_region_size       = pc_minimum_region_size;

    CGAL::Timer timer;

    timer.start();
    // Get the pointer to the data
    auto points_buf = points_np.request();
    auto points_ptr = static_cast<double*>(points_buf.ptr);

    if (points_buf.ndim != 2 || points_buf.shape[1] != 3) {
        throw std::runtime_error("Input points array must be of shape (n, 3)");
    }

    const bool with_normal_map = true;
    Input_range input_range(with_normal_map);

    // Create the input point set from the numpy array
    for (ssize_t i = 0; i < points_buf.shape[0]; ++i) {
        input_range.insert(Point_3(points_ptr[i * 3], points_ptr[i * 3 + 1], points_ptr[i * 3 + 2]));
    }

    std::cout << "* Point clouds with " << input_range.number_of_points() << " vertices is loaded" << std::endl;
    // auto points = points_np.unchecked<2>();
    // for (ssize_t i = 0; i < points.shape(0); ++i) {
    //     input_range.insert(Point_3(points(i, 0), points(i, 1), points(i, 2)));
    // }

    RegionGrowingResult result(input_range.number_of_points());

    // Create instances of the classes Neighbor_query and Region_type.
    Neighbor_query_pc neighbor_query(
            input_range,
            k,
            input_range.point_map());

    Region_type_pc region_type(
            input_range,
            max_distance_to_plane, max_accepted_angle, min_region_size,
            input_range.point_map(), input_range.normal_map());

    // Create an instance of the region growing class.
    Region_growing_pc region_growing(input_range, neighbor_query, region_type);

    std::cout << "* " << " regions have been found in " << input_range.size() << std::endl;
    // Run the algorithm.
    region_growing.detect(std::back_inserter(result.regions));
    timer.stop();

    // Print the number of found regions.
    std::cout << "* " << result.regions.size() <<
              " regions have been found in " << timer.time() << " seconds"
              << std::endl;

    // Get all unassigned items.
    Region unassigned_items;
    region_growing.unassigned_items(std::back_inserter(unassigned_items));

    // Print the number of unassigned items.
    std::cout << "* " << unassigned_items.size() <<
              " points do not belong to any region"
              << std::endl;

    for (std::size_t rg_ind = 0; rg_ind < result.regions.size(); ++rg_ind) {
        for (const auto& index : result.regions[rg_ind]) {
            if (index < result.incomponent.size()) {
                result.incomponent[index] = static_cast<int32_t>(rg_ind);
            } else {
                std::cerr << "Warning: Face index " << index << " out of range." << std::endl;
            }
        }
    }

    return result;
}

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Ubuntu 18.04 64
  • Compiler: gcc 7.5.0
  • Release or debug mode: Release
  • Specific flags used (if any):
  • CGAL version: v5.5
  • Boost version: 1.78.0
  • Other libraries versions if used (Eigen, TBB, etc.):

MenglinQiu avatar Jun 24 '24 10:06 MenglinQiu

for (ssize_t i = 0; i < points_buf.shape[0]; ++i) {
    Point_3 point(points_ptr[i * 3], points_ptr[i * 3 + 1], points_ptr[i * 3 + 2]);
    input_range.insert(point, Kernel::Vector_3(normals(i, 0), normals(i, 1), normals(i, 2)));
} # add normal vector

MenglinQiu avatar Jun 24 '24 14:06 MenglinQiu

Does the problem still occur?

The error message "-wrongvalue:-nan" is not created from CGAL, do you know where it may come from? Please provide a self contained example for us to reproduce the error.

soesau avatar Sep 24 '24 07:09 soesau

bump @MenglinQiu

MaelRL avatar Dec 12 '24 11:12 MaelRL