5

First of all let me clear .. I am not asking about 2D mesh, to determine the winding order of 2D mesh its very easy with normal-z direction.

Second is, I am not asking any optimized algorithm, I do not worry about the time or speed, I just want to do it with my mesh.

When I triangulate a 3D object using Greedy Projection Triangulation algorithm, This problem happens. check the attached images.

If I apply 2D approaches to this model using "Calculate Signed Area" or "Cross production of AB and BC vectors of a triangle", it only solves the 2D mesh but how about a 3D mesh?

First we need to check that which triangles are in wrong winding direction in 3D mesh, then we only consider those triangles, so the issue is, how can we check that which triangles are in wrong winding direction in 3D? We can not just do with 2D approach I have tested it and but no success.

For example in case of a sphere, we can not apply 2D approach to sphere. So is there any way to solve this issue ?

Thanks.

enter image description here enter image description here

Update # 1:

Below is the algorithm to check which edge has the same winding. It doesn't work well, I don't know why. Theoretically it should correct all the triangles but it is not correcting. For example in case of a sphere check in the attached figure. Something is wrong with it.

void GLReversedEdge(int i, int j, GLFace *temp)
{
    //i'th triangle
    int V1 = temp[i].v1;
    int V2 = temp[i].v2;
    int V3 = temp[i].v3;

    //i'th triangle edges
    int E1[] ={V1, V2};
    int E2[] ={V2, V3};
    int E3[] ={V3, V1};

    //adjacent triangle
    int jV1 = temp[j].v1;
    int jV2 = temp[j].v2;
    int jV3 = temp[j].v3;

    //adjacent edges
    int jE1[] ={jV1, jV2};
    int jE2[] ={jV2, jV3};
    int jE3[] ={jV3, jV1};

    // 1st edge of adjacent triangle is checking with all edges of ith triangle
    if((jE1[0] == E1[0] && jE1[1] == E1[1]) ||
       (jE1[0] == E2[0] && jE1[1] == E2[1]) ||
       (jE1[0] == E3[0] && jE1[1] == E3[1]))
    {
       temp[j].set(jV2, jV1, jV3);      // 1st edges orientation is same, so reverse/swap it
    }
    // 2nd edge of adjacent triangle is checking with all edges of ith triangle
    else if((jE2[0] == E1[0] && jE2[1] == E1[1]) ||
            (jE2[0] == E2[0] && jE2[1] == E2[1]) ||
            (jE2[0] == E3[0] && jE2[1] == E3[1]))
    {
            temp[j].set(jV1, jV3, jV2); // 2nd edges orientation is same, so reverse/swap it
    }
    // 3rd edge of adjacent triangle is checking with all edges of ith triangle
    else if((jE3[0] == E1[0] && jE3[1] == E1[1]) ||
            (jE3[0] == E2[0] && jE3[1] == E2[1]) ||
            (jE3[0] == E3[0] && jE3[1] == E3[1]))
    {
            temp[j].set(jV3, jV2, jV1); // 3rd edges orientation is same, so reverse/swap it
    }
}

void GetCorrectWindingOfMesh()
{
    for(int i=0; i<nbF; i++)
    {
        int j1 = AdjacentTriangleToEdgeV1V2;
        if(j1 >= 0) GLReversedEdge(i, j1, temp);

        int j2 = AdjacentTriangleToEdgeV2V3;
        if(j2 >= 0) GLReversedEdge(i, j2, temp);

        int j3 = AdjacentTriangleToEdgeV3V1;
        if(j3 >= 0) GLReversedEdge(i, j3, temp);
    }
}

enter image description here

4
  • To propagate an orientation, you have to start from a triangle which orientation you want to use for whole mesh, and than propagate that orientation through all connected triangles. It is same which (graph) traversal algorithm to use. Code above propagate orientation only to first neighbours.
    – Ante
    Jun 13, 2013 at 7:21
  • What do you mean by "propagate orientation only to first neighbours"? I think a triangle only has three neighbor triangles, and I am checking all three neighbor triangles and if found a wrong edge then swapping that edge? OK In case of a sphere I am starting a triangle which is correct one by checking its normal vector to z-direction.. but still not getting the proper result.. Could you please explain me little bit more.. I have been solving this issue since so many days.. :)
    – maxpayne
    Jun 14, 2013 at 6:40
  • Start from a good oriented triangle, than apply same orientation to it's neighbors, than apply to neighbors of neighbors, ... That is called graph traversal, since triangle connectivity can be seen as a graph.
    – Ante
    Jun 14, 2013 at 14:37
  • Thanks Ante, I really appreciate your effort.. I didn't know about the graph traversal before, but now I know, I tried to learn it but still confused about how can I implement it. Could you please write a short pseudo code for me? I have all edges information in an array, so how to make a loop for checking each triangle with edges ? Its confusing. I really tried hard.. :)
    – maxpayne
    Jun 17, 2013 at 4:52

2 Answers 2

2

To retrieve neighboring information lets assume we have method that returns neighbor of triangle on given edge neighbor_on_egde( next_tria, edge ).

That method can be implemented with information for each vertex in which triangles it is used. That is dictionary structure that maps vertex index to list of triangle indices. It is easily created by passing through list of triangles and setting for each triangle vertex index of triangle in right dictionary element.

Traversal is done by storing which triangles to check for orientation and which triangles are already checked. While there are triangles to check, make check on it and add it's neighbors to be checked if they weren't checked. Pseudo code looks like:

to_process = set of pairs triangle and orientation edge
             initial state is one good oriented triangle with any edge on it
processed = set of processed triangles; initial empty

while to_process is not empty:
    next_tria, orientation_edge = to_process.pop()
    add next_tria in processed
    if next_tria is not opposite oriented than orientation_edge:
        change next_tria (ABC) orientation  (B<->C)
  for each edge (AB) in next_tria:
      neighbor_tria = neighbor_on_egde( next_tria, edge )
      if neighbor_tria exists and neighbor_tria not in processed:
          to_process add (neighbor_tria, edge opposite oriented (BA))
1
  • Thanks a lot. I will let you know after implementation. I think I got the idea. Let me implement. :)
    – maxpayne
    Jun 18, 2013 at 5:40
2

Does your mesh include edge adjacency information? i.e. each triangle T contains three vertices A,B,C and three edges AB, BC and CA, where AB is a link to the triangle T1 which shares common vertices A,B and includes a new vertex D. Something like

struct Vertex 
{
 double x,y,z;
};

struct Triangle
{
   int vertices[3],edges[3];
};


struct TriangleMesh
{
   Vertex Vertices[];
   Triangle Triangles[];
};

If this is the case, for any triangle T = {{VA,VB,VC},{TAB,TBC,TCA}} with neighbour TE = &TAB at edge AB, A and B must appear in the reverse order for T and TE to have the same winding. e.g. TAB = {{VB,VA,VD},{TBA,TAD,TDA}} where TBA = &T. This can be used to give all the triangles the same winding.

3
  • Thanks shane. Yes I have adjacent triangles and edges. I think I can understand what you mean. Could you please tell me how can I check winding of edges ? means how can I know that the edges are in same or in reverse direction ? with normal vector ? I tried to understand but I think it looks complicated.. if(AB BC CA) correct triangle and (BC CD DB) is wrong one then what you saying here. Do i need to check that whether any of edge share the same vertices if they do then I should make that tri reverse ? Could you write some small pseudo code. Thanks alot.
    – maxpayne
    Jun 11, 2013 at 10:35
  • @furqan, where you have two adjacent triangles with different windings, to make the winding the same, simply change the vertex order on the adjacent edge e.g. T={{VA,VB,VC},{TAB,TBC,TCA}} becomes T={{VB,VA,VC},{TAB,TBC,TCA}} assuming the change is being done after inspecting edge AB. Note the adjacencies remain the same. This needs to be checked for every triangle in the TIN, marking corrected and checked triangles as you go.
    – SmacL
    Jun 12, 2013 at 7:16
  • please check my update.. I have updated the results of my algorithm. I think the algorithm is OK, because it tries to correct but I think I should check some more cases. Why it is not correcting the sphere triangles winding.. Please check my algorithm and guide me now. where did I do wrong ? Thanks.
    – maxpayne
    Jun 12, 2013 at 13:07

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.