Find unique peaks from the soup triangle

I am creating a CAD file converter on top of two libraries (Opencascade and DWF Toolkit).

However, my question is the agnostic plattform:

Given:

I created a grid, since the list of triangular faces forms the model created in my application. Each triangle is defined by three vertices, which consist of three floats (x, y and z coordinates). Since triangles form a grid, most vertices are separated by more than one triangle.

Purpose:

I need to find a list of unique vertices and generate an array of faces consisting of tuples of three indices in this list.

What I want to do is:

//step 1: build a list of unique vertices
for each triangle
   for each vertex in triangle
      if not vertex in listOfVertices
         Add vertex to listOfVertices

//step 2: build a list of faces 
for each triangle
   for each vertex in triangle
      Get Vertex Index From listOfvertices
      AddToMap(vertex Index, triangle)

, , step1 ( ) O (n!), , . : ", - " std:: map, ! ", , - .

stackoverflow: - -, 3 , 3d-.

+5
3

, unique(sort(array)). O (k n log (n)), k - , , k < 7.

, , , unique , , , ,

distance(vertex1, vertex2) < threshold

OK.

+3

. , ,

  • -. , " "
  • .

2 3, , . BSP , , , . , . , , " ".

+2

, float prime . - :

unsigned int hash_point(float x, float y, float z)
{
   unsigned int* px = (unsigned int*)&x;
   unsigned int* py = (unsigned int*)&y;
   unsigned int* pz = (unsigned int*)&z;

   return (*px)*PRIME1 + (*py)*PRIME2 + (*pz)*PRIME3;
}

, sizeof (unsigned int) sizeof (float) . , .

0

All Articles