Getting triangle indices from Delaunay 3D

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

Getting triangle indices from Delaunay 3D

ahmedtolba
Hi,
I'm trying to draw a 3D mesh using cgal using directx
In DirectX I need three indices of the 3D Mesh.

I'm doing the following, but I get broken triangles

std::vector<unsigned int> triangles;
        std::map<Delaunay3::Vertex_handle, int> Vertices;
        int index = 1;

        for (Delaunay3::Finite_vertices_iterator vit =
dt.finite_vertices_begin(), end = dt.finite_vertices_end(); vit != end;
++vit)
        {
                Vertices[vit] = index;
                index++;
        }

        for (Delaunay3::Finite_cells_iterator cit = dt.finite_cells_begin(),
end = dt.finite_cells_end(); cit != end; ++cit)
        {
                int V1ind = Vertices.find(cit->vertex(0))->second;
                int V2ind = Vertices.find(cit->vertex(1))->second;
                int V3ind = Vertices.find(cit->vertex(2))->second;
                int V4ind = Vertices.find(cit->vertex(3))->second;
                triangles.push_back(V1ind);
                triangles.push_back(V2ind);
                triangles.push_back(V3ind);
  }




--
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: Getting triangle indices from Delaunay 3D

Thomas Morzadec
Hello,

I am Thomas Morzadec. I would like to unsubscribe from the mailing list.

I didn't manage to do it via the website,

How could I do?

best,

T. Morzadec

----- Mail original -----

> De: "ahmedtolba" <[hidden email]>
> À: [hidden email]
> Envoyé: Lundi 22 Janvier 2018 15:52:20
> Objet: [cgal-discuss] Getting triangle indices from Delaunay 3D
>
> Hi,
> I'm trying to draw a 3D mesh using cgal using directx
> In DirectX I need three indices of the 3D Mesh.
>
> I'm doing the following, but I get broken triangles
>
> std::vector<unsigned int> triangles;
>         std::map<Delaunay3::Vertex_handle, int> Vertices;
>         int index = 1;
>
>         for (Delaunay3::Finite_vertices_iterator vit =
> dt.finite_vertices_begin(), end = dt.finite_vertices_end(); vit != end;
> ++vit)
>         {
>                 Vertices[vit] = index;
>                 index++;
>         }
>
>         for (Delaunay3::Finite_cells_iterator cit = dt.finite_cells_begin(),
> end = dt.finite_cells_end(); cit != end; ++cit)
>         {
>                 int V1ind = Vertices.find(cit->vertex(0))->second;
>                 int V2ind = Vertices.find(cit->vertex(1))->second;
>                 int V3ind = Vertices.find(cit->vertex(2))->second;
>                 int V4ind = Vertices.find(cit->vertex(3))->second;
>                 triangles.push_back(V1ind);
>                 triangles.push_back(V2ind);
>                 triangles.push_back(V3ind);
>   }
>
>
>
>
> --
> 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
>
>
>

--
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: Getting triangle indices from Delaunay 3D

MaelRL
In reply to this post by ahmedtolba
Hello,

You can find some inspiration in the triangulation input/output
operators of CGAL, for example:
https://github.com/CGAL/cgal/blob/master/Triangulation_3/include/CGAL/IO/Triangulation_off_ostream_3.h.

On 22/01/2018 15:52, ahmedtolba wrote:

> Hi,
> I'm trying to draw a 3D mesh using cgal using directx
> In DirectX I need three indices of the 3D Mesh.
>
> I'm doing the following, but I get broken triangles
>
> std::vector<unsigned int> triangles;
>          std::map<Delaunay3::Vertex_handle, int> Vertices;
>          int index = 1;
>
>          for (Delaunay3::Finite_vertices_iterator vit =
> dt.finite_vertices_begin(), end = dt.finite_vertices_end(); vit != end;
> ++vit)
>          {
>                  Vertices[vit] = index;
>                  index++;
>          }
>
>          for (Delaunay3::Finite_cells_iterator cit = dt.finite_cells_begin(),
> end = dt.finite_cells_end(); cit != end; ++cit)
>          {
>                  int V1ind = Vertices.find(cit->vertex(0))->second;
>                  int V2ind = Vertices.find(cit->vertex(1))->second;
>                  int V3ind = Vertices.find(cit->vertex(2))->second;
>                  int V4ind = Vertices.find(cit->vertex(3))->second;
>                  triangles.push_back(V1ind);
>                  triangles.push_back(V2ind);
>                  triangles.push_back(V3ind);
>    }
>
>
>
>
> --
> 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: Getting triangle indices from Delaunay 3D

ahmedtolba
This post was updated on .
In reply to this post by ahmedtolba
The code in that header file dosen't should how to use Delaunay 3D to get the
indices of the triangles. to be shown in DirectX


indexofvertex for example is not defined.

--
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: Getting triangle indices from Delaunay 3D

ahmedtolba
I tried the following code
but I have incorrect indices

std::vector<int> triangles;
         
        std::map<Delaunay3::Vertex_handle, int> index_of_vertex;
        int j = 0;
        for (Delaunay3::Finite_vertices_iterator it = dt.finite_vertices_begin();
it != dt.finite_vertices_end(); ++it, ++j)
        {
                index_of_vertex[it.base()] = j;
        }

        for (Delaunay3::Finite_facets_iterator itFacet = dt.finite_facets_begin();
itFacet != dt.finite_facets_end(); itFacet++)
        {
                triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
                triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
  triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);


                triangles.push_back(index_of_vertex[itFacet->first->vertex(0)]);
                triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
                triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);


                triangles.push_back(index_of_vertex[itFacet->first->vertex(1)]);
                triangles.push_back(index_of_vertex[itFacet->first->vertex(2)]);
                triangles.push_back(index_of_vertex[itFacet->first->vertex(3)]);

                 

        }



--
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: Getting triangle indices from Delaunay 3D

andreas.fabri
vertex(0,1,2,3) is definitely wrong. If the facet is the pair vh,I, then the indices are i + 1 modulo 4.  

Reply | Threaded
Open this post in threaded view
|

Re: Getting triangle indices from Delaunay 3D

ahmedtolba
Thanks for your quick reply

I tried the following piece of code, I still get wrong triangles

int j = 0;
        for (Delaunay3::Finite_facets_iterator itFacet = dt.finite_facets_begin();
itFacet != dt.finite_facets_end(); itFacet++)
        {
                triangles.push_back(index_of_vertex[itFacet->first->vertex((j+1)%4)]);
 
                j++;
                if (j == 4)
                {
                        j = 0;
                }


        }



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