Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map
Chronological Thread
- From: Yaoyu Hu <>
- To:
- Subject: Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map
- Date: Sun, 28 Nov 2021 21:33:39 -0500
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-data: A9a23:76gyX6v8FtA3CmDvD4fNc2cYvOfnVDlfMUV32f8akzHdYEJGY0x3nGcWDzrXO/qOamD3KNx+PN/g/RxVsMSHmNFjS1RqqnxEQiMRo6IpJ/zJdxaqZ3v6wu7rFR88sZ1GMrEsFC2FJ5Pljk/F3oPJ8D8sislkepKmULSdY3krFVc/IMscoUsLd9AR0tYAbeeRWFvlVePa+6UzCXf9s9JGGjp8B5Gr9HuDiM/PVAYw5TTSUxzkUGj2zBH5BLpHTU24wuCRroN8RoZWTM6bpF21E/+wwvsjNj+luu6TnkwiR7fTOU2WiCMTVfX5xBdFoSM23+AwM/90hUV/0W3Y2YAsjo8U69rtEm/FPYWU8AgZexlFAih5LLAfqe+ZCXe6uM2XiUbBdhMAxt0wUxlqZNBAkgpwKTgWqaZwxCo2RhuMjubzzLOgQfR3new4PczzNcUevGthxHfXF54brTrrV/2fv5kHyG5l3oYWCayLP4xDOGs2eE+VO1sSLghCIYwat+KMqnnbUjR+lEixm6sS9zGLmVUrlOH5WDbOUtmDRMEQhkTB42ybpCL2BRYVMNHZwj2Amk9AT9TnxUvTML/+3pXhnhKrvLGS+oDXIBgfVF/+ufvgz0DjAJRQLEsb/idopq83nKBuZrERQDXgyENofDZFMzaTLwH+wA6Iw6vQpQ2eAwDoixZfPcc+upZeqSMCjze0chCAOdCrmLKQQHOZsLyTqFte/AB9wXAqPUc5cOfO3zUvTEzfQP4CohaP3ZNZVuHIJAw=
- Ironport-hdrordr: A9a23:OwUMk6OCgpLIH8BcTu+jsMiBIKoaSvp037FhvHoBLiC9E/bo8vxG+c5xvyMc5wxwZJheo6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d1T+Y5YB7UbLP/wWkL9rsLUAgI4PgCuw+vqBs1x1oYEVmKOBq+ZPrnSsViN5u83I+mMeY8Utyz6K/kl+v7ikHs0lFwccKSy0psXbWq3HvViI0mDfXXshdIBHX8QvgUiVOzqlEGCUTlLanmuUKIz/DU7BJu7AofCXYCinKGB3DygHpBNfWBHClWMEW/yeImeWvcMbjiSIs57nTAeW7ihUdxp6Be1qQWvy6Z7NvGGvWoDpJf73Z504ffSnFc873tvHsGF2iaMSW9z2WgHTjtz0KFkqlFm0QS+17NlialYCcBL/KEOFQs9PtjXwOV+TdfoVUXFd8uEU0rhetKnBy0GVd8t9IRJW0F8HcmVlR3f6HGdWacSlrqXM4c57pXExX/pKtxh2kGW37E5ylQ2S85XMWDghrJ681vuAZXUmWWFkqL/dbgAxDWfsyCY3G+WtQdZVhRxWOPLRzcEd07OpJP44E3FCLShALBiPgpawtOZMfh3bMb0h2lLVOu2OMjCe3nj3CC8Ah3OzbyFaMztYWpa2CzBBVMY1DgU/HCaAhMzGhD65FrZDTpyIknif3S3xrNmr3K9Ungvwh29d1dmz7ev5g8i1feEU7YezrsBoCMs7TVoGVLu4tTNFtC8qhp9KaVAfcsmshAAznPcrwU7P5q6LqkkiERZaBVyp0qp1hN5DcJLnsEu6X8r1wFvMrnL7FQUfDyR2dX8O6bcN3Lp1BGpca/fnF/Eg/iM/aJa2f0/ukirnBzhQko/4nxgwsQMgivCzprPBQsWF5n2VxBkpFBBu7jGb3xltMvv3np2PPzo41cqNPomAeIkzlCreNINacts9Sf3GsweQtCscakkxgPvYRUDM+RfsqUzOpH+HxNj8KGuNedk2jmhiDYfiL0=
Hi Sebastien,
Thank you for the reply. You are right, I need to put the elements that need to be removed into a container like std::vector then remove the elements in one go.
In my last question, I was trying to follow the example here: https://doc.cgal.org/latest/Point_set_3/Point_set_3_2point_set_property_8cpp-example.html
In the example, the points in a Point_set_3 are directly removed inside a while-loop by calling the remove() function. So I thought I can do the same. But it did not work. Do you think the example code needs some revision regarding the correct way of explicitly removing a bunch of points from Point_set_3?
Thank you!
Yaoyu
On Tue, Nov 23, 2021 at 1:01 PM Sebastien Loriot <> wrote:
You should not iterate on a range and remove elements at the same time.
Put elements to be removed in a std::vector and remove them after the
main loop over all elements. Removing an element may invalidate its
iterator for any container.
Something like that:
for ( auto it = cloud.begin(); it != cloud.end(); ++it )
{
if ( c_size <= size_limit ) to_remove.push_back(*it);
}
for(auto i : to_remove)
cloud.remove(i);
Best,
Sebastien.
On 11/18/21 4:18 PM, Yaoyu Hu ( via cgal-discuss
Mailing List) wrote:
> Hi,
>
> I am trying to clean the points of a Point_set_3 by removing small
> clusters of points.
>
> The way I did it is first computing the clusters
> by CGAL::cluster_point_set() and saving the cluster indices to a
> property map with the name "cluster". Then I count the number of points
> in each cluster. Finally, the points belonging to a cluster that has a
> small cluster size are removed by issuing the remove() function (
> followed by collect_garbage() after all remove() calls).
>
> The problem is when I iterate through the Point_set_3 point cloud and
> send the de-referenced iterator value to the property map, the property
> map throws an exception triggered by a CGAL::assertion_fail(). The
> following is the code I use to do the small cluster removal. And I also
> create a gist if that is more convenient.
>
> https://gist.github.com/huyaoyu/ea9919a1ff6e4c4b49d55020998d1e46
> <https://gist.github.com/huyaoyu/ea9919a1ff6e4c4b49d55020998d1e46>
>
> === Code begins. ===
>
> template < typename Iterable_t >
> static std::map<int, int>
> compute_cluster_size(const Iterable_t& cluster_map) {
> std::map<int, int> cluster_size;
>
> for ( const auto& idx : cluster_map ) {
> if ( cluster_size.find(idx) == cluster_size.end() ) {
> // New idx.
> cluster_size[idx] = 1;
> } else {
> // Existing cluster.
> cluster_size[idx]++;
> }
> }
>
> return cluster_size;
> }
>
> // sr::PointSet_t is CGAL::Point_set_3.
> void sr::compute_and_remove_small_clusters(
> sr::PointSet_t& cloud,
> double avg_spacing,
> int size_limit,
> std::ostream& os ) {
> sr::PointSet_t::Property_map<int> cluster_map;
>
> // Reset or create a new property map.
> if ( cloud.has_property_map<int>("cluster") ) {
> boost::tie( cluster_map, boost::tuples::ignore ) =
> cloud.property_map<int>("cluster");
>
> cloud.remove_property_map(cluster_map);
> }
>
> bool success = false;
> boost::tie( cluster_map, success ) =
> cloud.add_property_map<int>("cluster", -1);
>
> if ( !success ) {
> os << "Cannot add cluster property map. \n";
> return;
> }
>
> // Clustering.
> CGAL::Real_timer rt; rt.start();
> std::size_t n_clusters =
> CGAL::cluster_point_set(
> cloud,
> cluster_map,
> cloud.parameters().neighbor_radius(avg_spacing)
> );
> rt.stop();
> os << "Find " << n_clusters << " clusters in " << rt.time() << "
> seoncds. \n";
>
> // Compute the cluster size.
> std::map<int, int> cluster_size = compute_cluster_size( cluster_map );
>
> // Remove small clusters.
> for ( auto it = cloud.begin(); it != cloud.end(); ++it ) {
> // Get the cluster index.
> const auto c_idx = cluster_map[*it];
>
> // Get the cluster size.
> const auto c_size = cluster_size[c_idx];
>
> if ( c_size <= size_limit ) cloud.remove(it);
> }
>
> cloud.collect_garbage();
> }
>
> === Code ends. ===
>
> In the above code, the line *const auto c_idx =
> cluster_map[*it];* triggers the assertion failure in
> *CGAL::Property_array<int>::operator[]()*.
>
> I am assuming that *cluster_map* has all the points in the point cloud
> as the key and as long as the iterator *it* comes from the point cloud,
> **it* should be a valid key for *cluster_map*.
>
> The assertion failure does not always get triggered. Most of my point
> clouds are OK. Only some point clouds trigger this error. I have
> uploaded one sample point cloud that causes this error to my Google
> Drive for your reference.
> https://drive.google.com/file/d/1rfQP0mo7pj84YgAX1CZtorr6IMpsslyo/view?usp=sharing
> <https://drive.google.com/file/d/1rfQP0mo7pj84YgAX1CZtorr6IMpsslyo/view?usp=sharing>
>
> Please help me. Any suggestions are appreciated. Thank you!
>
> Yaoyu
>
>
> --
> You are currently subscribed to cgal-discuss.
> To unsubscribe or access the archives, go to
> https://sympa.inria.fr/sympa/info/cgal-discuss
>
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
- [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Yaoyu Hu, 11/18/2021
- Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Sebastien Loriot, 11/23/2021
- Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Yaoyu Hu, 11/29/2021
- Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Sebastien Loriot, 11/29/2021
- Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Yaoyu Hu, 11/29/2021
- Re: [cgal-discuss] Assertion failed when try to access a Point_set_3 property map, Sebastien Loriot, 11/23/2021
Archive powered by MHonArc 2.6.19+.