How I get the right normals of facet?

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

How I get the right normals of facet?

WChXiong
Hi, I'm new on CGAL.
When I use CGAL::make_surface_mesh() to get surface mesh, I need to get consistency normals of every facets.Here my code:
        for (C2t3::Facet_iterator face= c2t3.facets_begin(); face != c2t3.facets_end(); ++face)
        {
                C2t3::Cell_handle ch;
                ch = face->first;
                int index = face->second;
                Point pt0 = ch->vertex((index+1)&3)->point();
                Point pt1 = ch->vertex((index+2)&3)->point();
                Point pt2 = ch->vertex((index+3)&3)->point();

                Vector normals = CGAL::cross_product(pt1 - pt0, pt2- pt0);
                normals = normals / CGAL::sqrt(normals * normals );
       }
But the result is not correct. The normals is not consistent. The points(pt0, pt1, pt2) of face are not oriented ?? How I can get consistency normals of every facets. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: How I get the right normals of facet?

teillaud
Administrator
Hi

see http://doc.cgal.org/latest/TDS_3/index.html#title0
and in particular a sentence in paragraph "Validity"
====
The set σ 4 of permutations of (0,1,2,3) has cardinality 24, and the set
of positive permutations A4 has cardinality 12. Thus, for a given
orientation, there are up to 12 different orderings of the four vertices
of a cell.
Note that cyclic permutations are negative and so do not preserve the
orientation of a cell.
====

whether vertices (i,i+1,i+2,i+3) (mod 4) are positively oriented depends
on the parity of i

--
Monique Teillaud
http://www.inria.fr/sophia/members/Monique.Teillaud/
INRIA Sophia Antipolis - Méditerranée
Institut National de Recherche en Informatique et Automatique

Le 29/11/13 04:17, WChXiong a écrit :

> Hi, I'm new on CGAL.
> When I use CGAL::make_surface_mesh() to get surface mesh, I need to get
> consistency normals of every facets.Here my code:
>          for (C2t3::Facet_iterator face= c2t3.facets_begin(); face !=
> c2t3.facets_end(); ++face)
> {
> C2t3::Cell_handle ch;
> ch = face->first;
> int index = face->second;
> Point pt0 = ch->vertex((index+1)&3)->point();
> Point pt1 = ch->vertex((index+2)&3)->point();
> Point pt2 = ch->vertex((index+3)&3)->point();
>
> Vector normals = CGAL::cross_product(pt1 - pt0, pt2- pt0);
> normals = normals / CGAL::sqrt(normals * normals );
>         }
> But the result is not correct. The normals is not consistent. The
> points(pt0, pt1, pt2) of face are not oriented ?? How I can get consistency
> normals of every facets. Thank you.
>
>
>
> --
> View this message in context: http://cgal-discuss.949826.n4.nabble.com/How-I-get-the-right-normals-of-facet-tp4658491.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: How I get the right normals of facet?

quaternionboy
Tried to manage parity but still get not consistent normals... Any ideas?

for (CGALTriangulation::Finite_facets_iterator it = T.finite_facets_begin();
        it != T.finite_facets_end();
        it++)
    {
        std::pair<CGALTriangulation::Cell_handle, int> f = *it;
       
        const Point& p0 = f.first->vertex((f.second))->point(); //not a
facet point, opposite
        const Point& p1 = f.first->vertex((f.second+1)&3)->point();
        const Point& p2 = f.first->vertex((f.second+2)&3)->point();
        const Point& p3 = f.first->vertex((f.second+3)&3)->point();
       
        //normals
        auto n = ( f.second % 2 == 1) ?
        CGAL::normal(p1, p2, p3) :
        CGAL::normal(p1, p3, p2);
        n = n/std::sqrt(n.squared_length());



teillaud wrote

> Hi
>
> see http://doc.cgal.org/latest/TDS_3/index.html#title0
> and in particular a sentence in paragraph "Validity"
> ====
> The set σ 4 of permutations of (0,1,2,3) has cardinality 24, and the set
> of positive permutations A4 has cardinality 12. Thus, for a given
> orientation, there are up to 12 different orderings of the four vertices
> of a cell.
> Note that cyclic permutations are negative and so do not preserve the
> orientation of a cell.
> ====
>
> whether vertices (i,i+1,i+2,i+3) (mod 4) are positively oriented depends
> on the parity of i
>
> --
> Monique Teillaud
> http://www.inria.fr/sophia/members/Monique.Teillaud/
> INRIA Sophia Antipolis - Méditerranée
> Institut National de Recherche en Informatique et Automatique
>
> Le 29/11/13 04:17, WChXiong a écrit :
>> Hi, I'm new on CGAL.
>> When I use CGAL::make_surface_mesh() to get surface mesh, I need to get
>> consistency normals of every facets.Here my code:
>>          for (C2t3::Facet_iterator face= c2t3.facets_begin(); face !=
>> c2t3.facets_end(); ++face)
>> {
>> C2t3::Cell_handle ch;
>> ch = face->first;
>> int index = face->second;
>> Point pt0 = ch->vertex((index+1)&3)->point();
>> Point pt1 = ch->vertex((index+2)&3)->point();
>> Point pt2 = ch->vertex((index+3)&3)->point();
>>
>> Vector normals = CGAL::cross_product(pt1 - pt0, pt2- pt0);
>> normals = normals / CGAL::sqrt(normals * normals );
>>         }
>> But the result is not correct. The normals is not consistent. The
>> points(pt0, pt1, pt2) of face are not oriented ?? How I can get
>> consistency
>> normals of every facets. Thank you.
>>
>>
>>
>> --
>> View this message in context:
>> http://cgal-discuss.949826.n4.nabble.com/How-I-get-the-right-normals-of-facet-tp4658491.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





--
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: How I get the right normals of facet?

Sebastien Loriot (GeometryFactory)
If you have a manifold surface, you can use this function:
https://doc.cgal.org/latest/Surface_mesher/group__PkgSurfaceMesher3FunctionsIO.html#ga39a105bd1817a9200ec5df208888e8aa
with Surface_mesh for example:
https://doc.cgal.org/latest/Surface_mesh/
Then you can use the normal computation function:
https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__normal__grp.html#ga14a7730a996879ba6e7589dfeaccff82


If not, then you can use this one and load back the file as a triangle soup:

https://doc.cgal.org/latest/Surface_mesher/group__PkgSurfaceMesher3FunctionsIO.html#ga7718d4e2047939882540d89fb5f28934


Sebastien.

On 8/17/20 6:56 PM, quaternionboy ([hidden email] via
cgal-discuss Mailing List) wrote:

> Tried to manage parity but still get not consistent normals... Any ideas?
>
> for (CGALTriangulation::Finite_facets_iterator it = T.finite_facets_begin();
>          it != T.finite_facets_end();
>          it++)
>      {
>          std::pair<CGALTriangulation::Cell_handle, int> f = *it;
>          
>          const Point& p0 = f.first->vertex((f.second))->point(); //not a
> facet point, opposite
>          const Point& p1 = f.first->vertex((f.second+1)&3)->point();
>          const Point& p2 = f.first->vertex((f.second+2)&3)->point();
>          const Point& p3 = f.first->vertex((f.second+3)&3)->point();
>          
>          //normals
>          auto n = ( f.second % 2 == 1) ?
>          CGAL::normal(p1, p2, p3) :
>          CGAL::normal(p1, p3, p2);
>          n = n/std::sqrt(n.squared_length());
>
>
>
> teillaud wrote
>> Hi
>>
>> see http://doc.cgal.org/latest/TDS_3/index.html#title0
>> and in particular a sentence in paragraph "Validity"
>> ====
>> The set σ 4 of permutations of (0,1,2,3) has cardinality 24, and the set
>> of positive permutations A4 has cardinality 12. Thus, for a given
>> orientation, there are up to 12 different orderings of the four vertices
>> of a cell.
>> Note that cyclic permutations are negative and so do not preserve the
>> orientation of a cell.
>> ====
>>
>> whether vertices (i,i+1,i+2,i+3) (mod 4) are positively oriented depends
>> on the parity of i
>>
>> --
>> Monique Teillaud
>> http://www.inria.fr/sophia/members/Monique.Teillaud/
>> INRIA Sophia Antipolis - Méditerranée
>> Institut National de Recherche en Informatique et Automatique
>>
>> Le 29/11/13 04:17, WChXiong a écrit :
>>> Hi, I'm new on CGAL.
>>> When I use CGAL::make_surface_mesh() to get surface mesh, I need to get
>>> consistency normals of every facets.Here my code:
>>>           for (C2t3::Facet_iterator face= c2t3.facets_begin(); face !=
>>> c2t3.facets_end(); ++face)
>>> {
>>> C2t3::Cell_handle ch;
>>> ch = face->first;
>>> int index = face->second;
>>> Point pt0 = ch->vertex((index+1)&3)->point();
>>> Point pt1 = ch->vertex((index+2)&3)->point();
>>> Point pt2 = ch->vertex((index+3)&3)->point();
>>>
>>> Vector normals = CGAL::cross_product(pt1 - pt0, pt2- pt0);
>>> normals = normals / CGAL::sqrt(normals * normals );
>>>          }
>>> But the result is not correct. The normals is not consistent. The
>>> points(pt0, pt1, pt2) of face are not oriented ?? How I can get
>>> consistency
>>> normals of every facets. Thank you.
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://cgal-discuss.949826.n4.nabble.com/How-I-get-the-right-normals-of-facet-tp4658491.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
>
>
>
>
>
> --
> 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: How I get the right normals of facet?

quaternionboy
I'll.
For now this works:

Vector v(p0,p1);
if (CGAL::angle(n,v) != CGAL::ACUTE){
    n = n * -1;
}


Sebastien Loriot (GeometryFactory) wrote

> If you have a manifold surface, you can use this function:
> https://doc.cgal.org/latest/Surface_mesher/group__PkgSurfaceMesher3FunctionsIO.html#ga39a105bd1817a9200ec5df208888e8aa
> with Surface_mesh for example:
> https://doc.cgal.org/latest/Surface_mesh/
> Then you can use the normal computation function:
> https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__normal__grp.html#ga14a7730a996879ba6e7589dfeaccff82
>
>
> If not, then you can use this one and load back the file as a triangle
> soup:
>
> https://doc.cgal.org/latest/Surface_mesher/group__PkgSurfaceMesher3FunctionsIO.html#ga7718d4e2047939882540d89fb5f28934
>
>
> Sebastien.
>
> On 8/17/20 6:56 PM, quaternionboy (

> quaternionboy@

>  via
> cgal-discuss Mailing List) wrote:
>> Tried to manage parity but still get not consistent normals... Any ideas?
>>
>> for (CGALTriangulation::Finite_facets_iterator it =
>> T.finite_facets_begin();
>>          it != T.finite_facets_end();
>>          it++)
>>      {
>>          std::pair&lt;CGALTriangulation::Cell_handle, int&gt; f = *it;
>>          
>>          const Point& p0 = f.first->vertex((f.second))->point(); //not a
>> facet point, opposite
>>          const Point& p1 = f.first->vertex((f.second+1)&3)->point();
>>          const Point& p2 = f.first->vertex((f.second+2)&3)->point();
>>          const Point& p3 = f.first->vertex((f.second+3)&3)->point();
>>          
>>          //normals
>>          auto n = ( f.second % 2 == 1) ?
>>          CGAL::normal(p1, p2, p3) :
>>          CGAL::normal(p1, p3, p2);
>>          n = n/std::sqrt(n.squared_length());
>>
>>
>>
>> teillaud wrote
>>> Hi
>>>
>>> see http://doc.cgal.org/latest/TDS_3/index.html#title0
>>> and in particular a sentence in paragraph "Validity"
>>> ====
>>> The set σ 4 of permutations of (0,1,2,3) has cardinality 24, and the set
>>> of positive permutations A4 has cardinality 12. Thus, for a given
>>> orientation, there are up to 12 different orderings of the four vertices
>>> of a cell.
>>> Note that cyclic permutations are negative and so do not preserve the
>>> orientation of a cell.
>>> ====
>>>
>>> whether vertices (i,i+1,i+2,i+3) (mod 4) are positively oriented depends
>>> on the parity of i
>>>
>>> --
>>> Monique Teillaud
>>> http://www.inria.fr/sophia/members/Monique.Teillaud/
>>> INRIA Sophia Antipolis - Méditerranée
>>> Institut National de Recherche en Informatique et Automatique
>>>
>>> Le 29/11/13 04:17, WChXiong a écrit :
>>>> Hi, I'm new on CGAL.
>>>> When I use CGAL::make_surface_mesh() to get surface mesh, I need to get
>>>> consistency normals of every facets.Here my code:
>>>>           for (C2t3::Facet_iterator face= c2t3.facets_begin(); face !=
>>>> c2t3.facets_end(); ++face)
>>>> {
>>>> C2t3::Cell_handle ch;
>>>> ch = face->first;
>>>> int index = face->second;
>>>> Point pt0 = ch->vertex((index+1)&3)->point();
>>>> Point pt1 = ch->vertex((index+2)&3)->point();
>>>> Point pt2 = ch->vertex((index+3)&3)->point();
>>>>
>>>> Vector normals = CGAL::cross_product(pt1 - pt0, pt2- pt0);
>>>> normals = normals / CGAL::sqrt(normals * normals );
>>>>          }
>>>> But the result is not correct. The normals is not consistent. The
>>>> points(pt0, pt1, pt2) of face are not oriented ?? How I can get
>>>> consistency
>>>> normals of every facets. Thank you.
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://cgal-discuss.949826.n4.nabble.com/How-I-get-the-right-normals-of-facet-tp4658491.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
>>
>>
>>
>>
>>
>> --
>> 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





--
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