PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwtin_is_closed()

int lwtin_is_closed ( const LWTIN tin)

Definition at line 80 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().

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