Why does number of segments==number of faces ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Why does number of segments==number of faces ?

Iasonm
Hello ,

I am trying to segment a mesh using the following code:

 void segmentMesh(){
        typedef boost::graph_traits<CGALSurfaceMesh>::face_descriptor face_descriptor;
        typedef CGALSurfaceMesh::Property_map<face_descriptor,double> Facet_double_map;
        Facet_double_map sdf_property_map;

        sdf_property_map=M.add_property_map<face_descriptor,double>("f:sdf").first;

        // compute SDF values
        // We can't use default parameters for number of rays, and cone angle
        // and the postprocessing
        CGAL::sdf_values(M, sdf_property_map, 2.0 / 3.0 * CGAL_PI, 25, true);
        // create a property-map for segment-ids
        typedef CGALSurfaceMesh::Property_map<face_descriptor, std::size_t> Facet_int_map;
        Facet_int_map segment_property_map =M.add_property_map<face_descriptor,std::size_t>("f:sid").first;;

        // segment the mesh using default parameters for number of levels, and smoothing lambda
        // Any other scalar values can be used instead of using SDF values computed using the CGAL function
        std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(M, sdf_property_map, segment_property_map);

        std::cout << "Number of segments: " << number_of_segments << std::endl;
    }
Everytime number_of_segments equals number of faces. This does not change when I load another .obj ,
The sdf values seem ok:
        sdf_property_map
                                        [0] 0.8370299962032144 double
                                        [1] 0.8302092195108647 double
                                        [2] 0 double
                                        [3] 0 double
                                        [4] 0.8409042568287671 double
                                        [5] 0.8408585619378204 double
                                        [6] 0 double
                                        [7] 0 double
                                        [8] 0.7682886461557734 double
                                        [9] 1 double
                                        [10] 0 double
                                        [11] 0 double
                                        [12] 0.6922190247566234 double
                                        [13] 0.6946973322833983 double
                                        [14] 0.7329067924334197 double
                                        [15] 0.7766550861844591 double
                                        [16] 0.6946973322833983 double
                                        [17] 0.6922190247566236 double
                                        [18] 0.7766550861844591 double
                                        [19] 0.7329067924334197 double
                                        [20] 0.7223775647174728 double
                                        [21] 0.7132597505108464 double
                                        [22] 0 double
                                        [23] 0.7544947132430431 double
                                        [24] 0.7187772404286814 double
                                        [25] 0.7518370088577582 double
                                        [26] 0.651523966538904 double
                                        [27] 0.6388096368864299 double
                                        [28] 0.7320518183718274 double
                                        [29] 0.7274001899698522 double
                                        [30] 0.642578387110068 double
                                        [31] 0.6491369547477115 double
                                        [32] 0 double
                                        [33] 0 double
                                        [34] 0.4715324806384383 double
                                        [35] 0.4709893975524506 double
                                        [36] 0.7046211151331574 double
                                        [37] 0.6863547051607206 double
                                        [38] 0.503769122276115 double
                                        [39] 0.5220265562441847 double
                                        [40] 0.6863547051607206 double
                                        [41] 0.7046211151331574 double
                                        [42] 0 double
                                        [43] 0 double
                                        [44] 0.439175491328876 double
                                        [45] 0.4547852145305106 double
                                        [46] 0.4674809609375916 double
                                        [47] 0.4319148395824393 double
                                        [48] 0.7816054032559208 double
                                        [49] 0.7481725761853011 double
                                        [50] 5.466811527473978e-17 double
                                        [51] 5.564433161893157e-17 double
                                        [52] 0.7481725761853011 double
                                        [53] 0.7816054032559208 double
                                        [54] 0.531941346270403 double
                                        [55] 0.5176809398969037 double
                                        [56] 0.5631417370150187 double
                                        [57] 0.3711396563719775 double
                                        [58] 0.5792711145774221 double
                                        [59] 0.393846048669109 double
                                        [60] 0.280795207809901 double
                                        [61] 0.2755911468606309 double
                                        [62] 0.2808547577076206 double
                                        [63] 0.2756548453890119 double
                                        [64] 0.275591146860631 double
                                        [65] 0.280795207809901 double
                                        [66] 0.2756548453890119 double
                                        [67] 0.2808547577076206 double
                                        [68] 0 double
                                        [69] 0 double
                                        [70] 0 double
                                        [71] 0 double
                                        [72] 0.6744300542068228 double
                                        [73] 0.6580958382600026 double
                                        [74] 0.3423945508066144 double
                                        [75] 0.4668586784283277 double
                                        [76] 0.7919433486621358 double
                                        [77] 0.7733719654580617 double
                                        [78] 0.4563102973815411 double
                                        [79] 0.2796173080630547 double
                                        [80] 0 double
                                        [81] 0 double
                                        [82] 0 double
                                        [83] 0 double
                                        [84] 0.7720729114423587 double
                                        [85] 0.7964883503765292 double
                                        [86] 0.6479947042483273 double
                                        [87] 0.6553937510618364 double
                                        [88] 0.7904543847051128 double
                                        [89] 0.7919075146603214 double
                                        [90] 0.6570894870135487 double
                                        [91] 0.6506725916476378 double
                                        [92] 0 double
                                        [93] 0 double
                                        [94] 0.4937888701326119 double
                                        [95] 0.486533941862835 double

Since I successfully ran the cactus example,
I suspect there is something wrong with how I build M (the surface mesh).
I build the surface mesh using the following code:

void buildPolygonMesh() {
        M.clear();
        std::cout << "Building CGALPolygonMesh.." << std::endl;
        std::vector<Kernel::Point_3> points;
        std::vector<std::vector<std::size_t>> polygons;

        for (auto const &vert : vertices) {
            points.push_back(
                        Kernel::Point_3((vert.Position.x - centerOfMass.x) / maxDim,
                                        (vert.Position.y - centerOfMass.y) / maxDim,
                                        (vert.Position.z - centerOfMass.z) / maxDim));
        }
        for (size_t i = 0; i < indices.size(); i += 3) {
            std::vector<std::size_t> tri{indices[i], indices[i + 1], indices[i + 2]};
            polygons.push_back(tri);
        }
        std::cout << "is polygon soup polygon mesh:"
                  << CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(
                         polygons)
                  << std::endl;
        CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,
                                                                    polygons, M);
        std::cout << "Finished building Polygon Mesh." << std::endl;
    }

Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Why does number of segments==number of faces ?

Sebastien Loriot (GeometryFactory)
Check that your mesh is actually a mesh and not a triangle soup.
For example your mesh should not have any border edge.

Sebastien.

On 04/27/2017 05:39 PM, Iasonm wrote:

> Hello ,
>
> I am trying to segment a mesh using the following code:
>
>  void segmentMesh(){
>         typedef boost::graph_traits<CGALSurfaceMesh>::face_descriptor
> face_descriptor;
>         typedef CGALSurfaceMesh::Property_map<face_descriptor,double>
> Facet_double_map;
>         Facet_double_map sdf_property_map;
>
>
> sdf_property_map=M.add_property_map<face_descriptor,double>("f:sdf").first;
>
>         // compute SDF values
>         // We can't use default parameters for number of rays, and cone
> angle
>         // and the postprocessing
>         CGAL::sdf_values(M, sdf_property_map, 2.0 / 3.0 * CGAL_PI, 25,
> true);
>         // create a property-map for segment-ids
>         typedef CGALSurfaceMesh::Property_map<face_descriptor, std::size_t>
> Facet_int_map;
>         Facet_int_map segment_property_map
> =M.add_property_map<face_descriptor,std::size_t>("f:sid").first;;
>
>         // segment the mesh using default parameters for number of levels,
> and smoothing lambda
>         // Any other scalar values can be used instead of using SDF values
> computed using the CGAL function
>         std::size_t number_of_segments =
> CGAL::segmentation_from_sdf_values(M, sdf_property_map,
> segment_property_map);
>
>         std::cout << "Number of segments: " << number_of_segments <<
> std::endl;
>     }
> Everytime number_of_segments equals number of faces. This does not change
> when I load another .obj ,
> The sdf values seem ok:
> sdf_property_map
> [0] 0.8370299962032144 double
> [1] 0.8302092195108647 double
> [2] 0 double
> [3] 0 double
> [4] 0.8409042568287671 double
> [5] 0.8408585619378204 double
> [6] 0 double
> [7] 0 double
> [8] 0.7682886461557734 double
> [9] 1 double
> [10] 0 double
> [11] 0 double
> [12] 0.6922190247566234 double
> [13] 0.6946973322833983 double
> [14] 0.7329067924334197 double
> [15] 0.7766550861844591 double
> [16] 0.6946973322833983 double
> [17] 0.6922190247566236 double
> [18] 0.7766550861844591 double
> [19] 0.7329067924334197 double
> [20] 0.7223775647174728 double
> [21] 0.7132597505108464 double
> [22] 0 double
> [23] 0.7544947132430431 double
> [24] 0.7187772404286814 double
> [25] 0.7518370088577582 double
> [26] 0.651523966538904 double
> [27] 0.6388096368864299 double
> [28] 0.7320518183718274 double
> [29] 0.7274001899698522 double
> [30] 0.642578387110068 double
> [31] 0.6491369547477115 double
> [32] 0 double
> [33] 0 double
> [34] 0.4715324806384383 double
> [35] 0.4709893975524506 double
> [36] 0.7046211151331574 double
> [37] 0.6863547051607206 double
> [38] 0.503769122276115 double
> [39] 0.5220265562441847 double
> [40] 0.6863547051607206 double
> [41] 0.7046211151331574 double
> [42] 0 double
> [43] 0 double
> [44] 0.439175491328876 double
> [45] 0.4547852145305106 double
> [46] 0.4674809609375916 double
> [47] 0.4319148395824393 double
> [48] 0.7816054032559208 double
> [49] 0.7481725761853011 double
> [50] 5.466811527473978e-17 double
> [51] 5.564433161893157e-17 double
> [52] 0.7481725761853011 double
> [53] 0.7816054032559208 double
> [54] 0.531941346270403 double
> [55] 0.5176809398969037 double
> [56] 0.5631417370150187 double
> [57] 0.3711396563719775 double
> [58] 0.5792711145774221 double
> [59] 0.393846048669109 double
> [60] 0.280795207809901 double
> [61] 0.2755911468606309 double
> [62] 0.2808547577076206 double
> [63] 0.2756548453890119 double
> [64] 0.275591146860631 double
> [65] 0.280795207809901 double
> [66] 0.2756548453890119 double
> [67] 0.2808547577076206 double
> [68] 0 double
> [69] 0 double
> [70] 0 double
> [71] 0 double
> [72] 0.6744300542068228 double
> [73] 0.6580958382600026 double
> [74] 0.3423945508066144 double
> [75] 0.4668586784283277 double
> [76] 0.7919433486621358 double
> [77] 0.7733719654580617 double
> [78] 0.4563102973815411 double
> [79] 0.2796173080630547 double
> [80] 0 double
> [81] 0 double
> [82] 0 double
> [83] 0 double
> [84] 0.7720729114423587 double
> [85] 0.7964883503765292 double
> [86] 0.6479947042483273 double
> [87] 0.6553937510618364 double
> [88] 0.7904543847051128 double
> [89] 0.7919075146603214 double
> [90] 0.6570894870135487 double
> [91] 0.6506725916476378 double
> [92] 0 double
> [93] 0 double
> [94] 0.4937888701326119 double
> [95] 0.486533941862835 double
>
> Since I successfully ran the cactus example,
> I suspect there is something wrong with how I build M (the surface mesh).
> I build the surface mesh using the following code:
>
> void buildPolygonMesh() {
>         M.clear();
>         std::cout << "Building CGALPolygonMesh.." << std::endl;
>         std::vector<Kernel::Point_3> points;
>         std::vector<std::vector&lt;std::size_t>> polygons;
>
>         for (auto const &vert : vertices) {
>             points.push_back(
>                         Kernel::Point_3((vert.Position.x - centerOfMass.x) /
> maxDim,
>                                         (vert.Position.y - centerOfMass.y) /
> maxDim,
>                                         (vert.Position.z - centerOfMass.z) /
> maxDim));
>         }
>         for (size_t i = 0; i < indices.size(); i += 3) {
>             std::vector<std::size_t> tri{indices[i], indices[i + 1],
> indices[i + 2]};
>             polygons.push_back(tri);
>         }
>         std::cout << "is polygon soup polygon mesh:"
>                   <<
> CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(
>                          polygons)
>                   << std::endl;
>         CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,
>
> polygons, M);
>         std::cout << "Finished building Polygon Mesh." << std::endl;
>     }
>
> Any ideas?
>
>
>
> --
> View this message in context: http://cgal-discuss.949826.n4.nabble.com/Why-does-number-of-segments-number-of-faces-tp4662701.html
> Sent from the cgal-discuss mailing list archive at Nabble.com.
>


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Why does number of segments==number of faces ?

Iasonm
 std::cout << "is polygon soup polygon mesh:"
                  << CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(
                         polygons)
                  << std::endl;
Prints is polygon soup polygon mesh:1

and also if it was a polygon soup and not a polygon mesh wouldn't the following function remove that problem?
        CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,
                                                                    polygons, M);

Reply | Threaded
Open this post in threaded view
|

Re: Why does number of segments==number of faces ?

Sebastien Loriot (GeometryFactory)
On 04/27/2017 05:50 PM, Iasonm wrote:

>  std::cout << "is polygon soup polygon mesh:"
>                   <<
> CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(
>                          polygons)
>                   << std::endl;
> Prints is polygon soup polygon mesh:1
>
> and also if it was a polygon soup and not a polygon mesh wouldn't the
> following function remove that problem?
>         CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points,
>
> polygons, M);
>
>

I mean are you sure the edge shared by two triangles is not duplicated.
In this case you would have one connected component per face.
Check the output of CGAL::is_closed(pmesh).

Sebastien.

>
>
>
> --
> View this message in context: http://cgal-discuss.949826.n4.nabble.com/Why-does-number-of-segments-number-of-faces-tp4662701p4662703.html
> Sent from the cgal-discuss mailing list archive at Nabble.com.
>


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss