CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

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

CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Hello,

i have mesh  mesh_to_cut.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_to_cut.off>  
and i want to cut two ends from it  cut_end_1.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/cut_end_1.off>   and
cut_end_2.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/cut_end_2.off>   .

so i am using
CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..).

when i cut single end:
CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
*cut_end_1, *result);
or
CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
*cut_end_2, *result);

i get correct result mesh with single cut end.

If i try to cut second end using result mesh from firs call:
CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
*cut_end_1, *mesh_to_cut_2nd_end);

mesh_to_cut_2nd_end.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_to_cut_2nd_end.off>  

CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut_2nd_end,
*cut_end_2, *result);

i get empty result shape and return false ( tm1_minus_tm2_is_valid()  ==
false )

I can not understand, what causes this failure. After first cut mesh end for
second cut is not even touched but somehow it is distorted and not valid for
second cut.

Maybe I'm doing something wrong?




--
Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

Sebastien Loriot (GeometryFactory)
Your three meshes are self-intersecting. I try calling our
non-documented function
CGAL::Polygon_mesh_processing::remove_self_intersections() from
CGAL/Polygon_mesh_processing/repair.h and at first sight it gives
good repaired models.

Sebastien.

On 4/27/20 3:22 PM, stiklaz wrote:

> Hello,
>
> i have mesh  mesh_to_cut.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_to_cut.off>
> and i want to cut two ends from it  cut_end_1.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/cut_end_1.off>   and
> cut_end_2.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/cut_end_2.off>   .
>
> so i am using
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..).
>
> when i cut single end:
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
> *cut_end_1, *result);
> or
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
> *cut_end_2, *result);
>
> i get correct result mesh with single cut end.
>
> If i try to cut second end using result mesh from firs call:
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut,
> *cut_end_1, *mesh_to_cut_2nd_end);
>
> mesh_to_cut_2nd_end.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_to_cut_2nd_end.off>
>
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference(*mesh_to_cut_2nd_end,
> *cut_end_2, *result);
>
> i get empty result shape and return false ( tm1_minus_tm2_is_valid()  ==
> false )
>
> I can not understand, what causes this failure. After first cut mesh end for
> second cut is not even touched but somehow it is distorted and not valid for
> second cut.
>
> Maybe I'm doing something wrong?
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Sebastien Loriot (GeometryFactory) wrote
> Your three meshes are self-intersecting. I try calling our
> non-documented function
> CGAL::Polygon_mesh_processing::remove_self_intersections() from
> CGAL/Polygon_mesh_processing/repair.h and at first sight it gives
> good repaired models.

i have tried to call
CGAL::Polygon_mesh_processing::remove_self_intersections()
for all meshes before calling
CGAL::Polygon_mesh_processing::corefine_and_compute_difference()
and after for the intermediate result mesh i also tried to call
CGAL::Polygon_mesh_processing::remove_degenerate_faces(*result);
but still having the same invalid result when i try to call
CGAL::Polygon_mesh_processing::corefine_and_compute_difference() for a
second cut.




--
Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

Sebastien Loriot (GeometryFactory)
Start by switching throw_on_self_intersection(true) in the named
parameters of corefine_and_XXX. Then you'll get an exception if
you are trying to do something invalid. If you have self-intersections
then try to fix them. I used the master version of
remove_self_intersections() which might explain why you still have
some.

Sebastien.

On 4/27/20 4:31 PM, stiklaz wrote:

> Sebastien Loriot (GeometryFactory) wrote
>> Your three meshes are self-intersecting. I try calling our
>> non-documented function
>> CGAL::Polygon_mesh_processing::remove_self_intersections() from
>> CGAL/Polygon_mesh_processing/repair.h and at first sight it gives
>> good repaired models.
>
> i have tried to call
> CGAL::Polygon_mesh_processing::remove_self_intersections()
> for all meshes before calling
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference()
> and after for the intermediate result mesh i also tried to call
> CGAL::Polygon_mesh_processing::remove_degenerate_faces(*result);
> but still having the same invalid result when i try to call
> CGAL::Polygon_mesh_processing::corefine_and_compute_difference() for a
> second cut.
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Sebastien Loriot (GeometryFactory) wrote
> Start by switching throw_on_self_intersection(true) in the named
> parameters of corefine_and_XXX. Then you'll get an exception if
> you are trying to do something invalid. If you have self-intersections
> then try to fix them. I used the master version of
> remove_self_intersections() which might explain why you still have
> some.

I have tried to use remove_self_intersections() from the master version and
also switched throw_on_self_intersection(true). I don`t get any exception so
meshes are not self intersecting, but still having the same invalid result.
Do you have any more ideas what`s can cause this?



--
Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

Sebastien Loriot (GeometryFactory)
Could you create a gist.github.com containing the main.cpp you are using?

Thanks,

Sebastien.

On 4/29/20 11:31 AM, stiklaz wrote:

> Sebastien Loriot (GeometryFactory) wrote
>> Start by switching throw_on_self_intersection(true) in the named
>> parameters of corefine_and_XXX. Then you'll get an exception if
>> you are trying to do something invalid. If you have self-intersections
>> then try to fix them. I used the master version of
>> remove_self_intersections() which might explain why you still have
>> some.
>
> I have tried to use remove_self_intersections() from the master version and
> also switched throw_on_self_intersection(true). I don`t get any exception so
> meshes are not self intersecting, but still having the same invalid result.
> Do you have any more ideas what`s can cause this?
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Sebastien Loriot (GeometryFactory) wrote
> Could you create a gist.github.com containing the main.cpp you are using?

It turns out i need to provide you original meshes not the ones i save,
because after save/load they are slight different.

After save/load meshes are somehow fixed and that`s why for you everything
works.

In my case, before saving, original meshes are not self intersecting, but
after save / load they become self intersecting.
Calling
CGAL::Polygon_mesh_processing::experimental::remove_self_intersections()
fixes self intersecting issue
and CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) works
as expected and gives correct result.

Maybe you know what save/load does to the mesh and maybe there is some
function to fix this kind of issue to avoid save/load (regenerate) mesh?




--
Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

Sebastien Loriot (GeometryFactory)
To avoid unwanted rounding, try:

stream << std::setprecision(17) << my_mesh;

Sebastien.

On 4/30/20 1:15 PM, stiklaz wrote:

> Sebastien Loriot (GeometryFactory) wrote
>> Could you create a gist.github.com containing the main.cpp you are using?
>
> It turns out i need to provide you original meshes not the ones i save,
> because after save/load they are slight different.
>
> After save/load meshes are somehow fixed and that`s why for you everything
> works.
>
> In my case, before saving, original meshes are not self intersecting, but
> after save / load they become self intersecting.
> Calling
> CGAL::Polygon_mesh_processing::experimental::remove_self_intersections()
> fixes self intersecting issue
> and CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) works
> as expected and gives correct result.
>
> Maybe you know what save/load does to the mesh and maybe there is some
> function to fix this kind of issue to avoid save/load (regenerate) mesh?
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Sebastien Loriot (GeometryFactory) wrote
> To avoid unwanted rounding, try:
>
> stream << std::setprecision(17) << my_mesh;

Yes, now i get the same mesh after save/load.
So here are the original meshes:
mesh_end1.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_end1.off>  
mesh_end2.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_end2.off>  
mesh_main.off
<http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_main.off>  

and here is the code snippet where second cut fails:  link
<https://gist.github.com/stiklaz/39ee8ecf6827d25502900831d9f3e3aa>  




--
Sent from: http://cgal-discuss.949826.n4.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: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

Sebastien Loriot (GeometryFactory)
If you look at the return value of the function, it will tell you that
the second operation could not be computed. Looking in details, there is
a small non-manifold edge that prevents the operation to be performed.

In you case, this happens because of rounding issues after the first
operation.

Two solutions:
1) you know that mesh_end1 and mesh_end2 are disjoint, you can call
mesh_end1.join(mesh_end2) as in the attached example and do only one
difference operation.

2) you have more operations to do and you want to use an exact vertex
point map to avoid issues. The following example shows how to create
an exact vertex point map that also maintains the rounded version:

https://doc.cgal.org/latest/Polygon_mesh_processing/Polygon_mesh_processing_2corefinement_consecutive_bool_op_8cpp-example.html


Note that in your case your input was valid but if you have some
non-manifold edges in the output no result can be computed with
the current version of the code.

Best,

Sebastien.



On 4/30/20 3:40 PM, stiklaz wrote:

> Sebastien Loriot (GeometryFactory) wrote
>> To avoid unwanted rounding, try:
>>
>> stream << std::setprecision(17) << my_mesh;
>
> Yes, now i get the same mesh after save/load.
> So here are the original meshes:
> mesh_end1.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_end1.off>
> mesh_end2.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_end2.off>
> mesh_main.off
> <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh_main.off>
>
> and here is the code snippet where second cut fails:  link
> <https://gist.github.com/stiklaz/39ee8ecf6827d25502900831d9f3e3aa>
>
>
>
>
> --
> Sent from: http://cgal-discuss.949826.n4.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



ex.cpp (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: CGAL::Polygon_mesh_processing::corefine_and_compute_difference(..) unable to calc second time

stiklaz
Sebastien Loriot (GeometryFactory) wrote

> Two solutions:
> 1) you know that mesh_end1 and mesh_end2 are disjoint, you can call
> mesh_end1.join(mesh_end2) as in the attached example and do only one
> difference operation.
>
> 2) you have more operations to do and you want to use an exact vertex
> point map to avoid issues. The following example shows how to create
> an exact vertex point map that also maintains the rounded version:
>
> https://doc.cgal.org/latest/Polygon_mesh_processing/Polygon_mesh_processing_2corefinement_consecutive_bool_op_8cpp-example.html
>
> Note that in your case your input was valid but if you have some
> non-manifold edges in the output no result can be computed with
> the current version of the code.

Thank you!

I have tried both solutions and both works and gives visually the same
result.
Result mesh looks almost good, but i get some almost zero depth parts:
mesh.png <http://cgal-discuss.949826.n4.nabble.com/file/t376212/mesh.png>  
Maybe there is some util to remove such parts?

Also even with exact vertex point map solution the result mesh has some self
intersections and remove_self_intersections(..) makes the result mesh look
even worse.




--
Sent from: http://cgal-discuss.949826.n4.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