PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwtin_is_closed()

int lwtin_is_closed ( const LWTIN tin)

Definition at line 93 of file lwtin.c.

References struct_tin_arcs::ax, struct_tin_arcs::ay, struct_tin_arcs::az, struct_tin_arcs::bx, struct_tin_arcs::by, struct_tin_arcs::bz, struct_tin_arcs::cnt, struct_tin_arcs::face, LWTIN::flags, FLAGS_GET_Z, LWTIN::geoms, getPoint4d_p(), lwalloc(), lwfree(), LWTIN::ngeoms, LWTRIANGLE::points, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by lwgeom_is_closed().

94 {
95  int i, j, k;
96  int narcs, carc;
97  int found;
98  tin_arcs arcs;
99  POINT4D pa, pb;
100  LWTRIANGLE *patch;
101 
102  /* If surface is not 3D, it's can't be closed */
103  if (!FLAGS_GET_Z(tin->flags)) return 0;
104 
105  /* Max theorical arcs number if no one is shared ... */
106  narcs = 3 * tin->ngeoms;
107 
108  arcs = lwalloc(sizeof(struct struct_tin_arcs) * narcs);
109  for (i=0, carc=0; i < tin->ngeoms ; i++)
110  {
111 
112  patch = (LWTRIANGLE *) tin->geoms[i];
113  for (j=0; j < 3 ; j++)
114  {
115 
116  getPoint4d_p(patch->points, j, &pa);
117  getPoint4d_p(patch->points, j+1, &pb);
118 
119  /* Make sure to order the 'lower' point first */
120  if ( (pa.x > pb.x) ||
121  (pa.x == pb.x && pa.y > pb.y) ||
122  (pa.x == pb.x && pa.y == pb.y && pa.z > pb.z) )
123  {
124  pa = pb;
125  getPoint4d_p(patch->points, j, &pb);
126  }
127 
128  for (found=0, k=0; k < carc ; k++)
129  {
130 
131  if ( ( arcs[k].ax == pa.x && arcs[k].ay == pa.y &&
132  arcs[k].az == pa.z && arcs[k].bx == pb.x &&
133  arcs[k].by == pb.y && arcs[k].bz == pb.z &&
134  arcs[k].face != i) )
135  {
136  arcs[k].cnt++;
137  found = 1;
138 
139  /* Look like an invalid TIN
140  anyway not a closed one */
141  if (arcs[k].cnt > 2)
142  {
143  lwfree(arcs);
144  return 0;
145  }
146  }
147  }
148 
149  if (!found)
150  {
151  arcs[carc].cnt=1;
152  arcs[carc].face=i;
153  arcs[carc].ax = pa.x;
154  arcs[carc].ay = pa.y;
155  arcs[carc].az = pa.z;
156  arcs[carc].bx = pb.x;
157  arcs[carc].by = pb.y;
158  arcs[carc].bz = pb.z;
159  carc++;
160 
161  /* Look like an invalid TIN
162  anyway not a closed one */
163  if (carc > narcs)
164  {
165  lwfree(arcs);
166  return 0;
167  }
168  }
169  }
170  }
171 
172  /* A TIN is closed if each edge
173  is shared by exactly 2 faces */
174  for (k=0; k < carc ; k++)
175  {
176  if (arcs[k].cnt != 2)
177  {
178  lwfree(arcs);
179  return 0;
180  }
181  }
182  lwfree(arcs);
183 
184  /* Invalid TIN case */
185  if (carc < tin->ngeoms) return 0;
186 
187  return 1;
188 }
double x
Definition: liblwgeom.h:352
POINTARRAY * points
Definition: liblwgeom.h:433
void lwfree(void *mem)
Definition: lwutil.c:244
double bx
Definition: lwtin.c:86
double by
Definition: lwtin.c:86
double az
Definition: lwtin.c:85
int ngeoms
Definition: liblwgeom.h:585
LWTRIANGLE ** geoms
Definition: liblwgeom.h:587
double bz
Definition: lwtin.c:86
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
double z
Definition: liblwgeom.h:352
double ax
Definition: lwtin.c:85
void * lwalloc(size_t size)
Definition: lwutil.c:229
uint8_t flags
Definition: liblwgeom.h:582
double y
Definition: liblwgeom.h:352
double ay
Definition: lwtin.c:85
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Here is the call graph for this function:
Here is the caller graph for this function: