Fix classify_overlap interface & re-test

This commit is contained in:
Chris Hodapp 2019-12-13 16:58:04 +01:00
parent 4115df52ed
commit 664ccfe468
3 changed files with 337 additions and 66 deletions

View File

@ -13,7 +13,7 @@
- CageFork may need to supply some 'opening' cage that I use as - CageFork may need to supply some 'opening' cage that I use as
a basis for how I subdivide a 'closing' cage. If I subdivide a basis for how I subdivide a 'closing' cage. If I subdivide
the closing cage, then I must triangulate *after*, not before. the closing cage, then I must triangulate *after*, not before.
- I just need a point-to-line-segment check for classify_overlap - classify_overlap tells what's needed, but I need to *use* it
- https://en.wikipedia.org/wiki/Polygon_triangulation - do this to - https://en.wikipedia.org/wiki/Polygon_triangulation - do this to
fix my wave example! fix my wave example!
- http://www.polygontriangulation.com/2018/07/triangulation-algorithm.html - http://www.polygontriangulation.com/2018/07/triangulation-algorithm.html

File diff suppressed because one or more lines are too long

71
cage.py
View File

@ -67,57 +67,68 @@ class Cage(object):
def transform(self, xform): def transform(self, xform):
"""Apply a Transform to all vertices, returning a new Cage.""" """Apply a Transform to all vertices, returning a new Cage."""
return Cage(xform.apply_to(self.verts), self.splits) return Cage(xform.apply_to(self.verts), self.splits)
def classify_overlap(self, cage): def classify_overlap(self, cages):
"""Classifies each vertex in a second cage according to some rules. """Classifies each vertex in a list of cages according to some rules.
Returns v, an array of equal length to cage.verts, for which v[i] will
equal 0, 1, 2, or 3 based on how cage.verts[i] was classified.
(This is mostly used in order to verify that certain rules are (This is mostly used in order to verify that certain rules are
followed when a mesh is undergoing forking/branching.) followed when a mesh is undergoing forking/branching.)
The meaning of v[i] is as follows: Returns:
0 -- None of the below apply to cage.verts[i]. v -- List of length len(cages). v[i] is a numpy array of shape (N,)
1 -- cage.verts[i] lies on an edge in this Cage (i.e. self). where N is the number of vertices in cages[i] (i.e. rows of
2 -- cage.verts[i] equals another (different) vertex in cage.verts, cages[i].verts). Element v[i][j] gives a classification of
and case 1 does not apply. X=l[i].verts[j] that will take values below:
3 -- cage.verts[i] equals a vertex in self.verts.
0 -- None of the below apply to X.
1 -- X lies on an edge in this Cage (i.e. self).
2 -- X equals another (different) vertex somewhere in 'cages', and
case 1 does not apply.
3 -- X equals a vertex in self.verts.
""" """
v = numpy.zeros((cage.verts.shape[0],), dtype=numpy.uint8) v = [numpy.zeros((cage.verts.shape[0],), dtype=numpy.uint8)
for i,vert in enumerate(cage.verts): for cage in cages]
# Check against every vert in self.verts: # for cage i of all the cages...
for j,vert2 in enumerate(self.verts): for i, cage in enumerate(cages):
# for vertex j within cage i...
for j, vert in enumerate(cage.verts):
# Check against every vert in our own (self.verts):
for vert2 in self.verts:
if numpy.allclose(vert, vert2): if numpy.allclose(vert, vert2):
v[i] = 3 v[i][j] = 3
break break
if v[i] > 0: if v[i][j] > 0:
continue continue
# Check against every edge of our own polygons: # Check against every edge of our own polygons:
for poly in self.polys(): for poly in self.polys():
for j,_ in enumerate(poly): for k,_ in enumerate(poly):
j2 = (j + 1) % len(poly) # Below is because 'poly' is cyclic (last vertex
# has an edge to the first):
k2 = (k + 1) % len(poly)
# Find distance from 'vert' to each vertex of the edge: # Find distance from 'vert' to each vertex of the edge:
d1 = numpy.linalg.norm(poly[j,:] - vert) d1 = numpy.linalg.norm(poly[k,:] - vert)
d2 = numpy.linalg.norm(poly[j2,:] - vert) d2 = numpy.linalg.norm(poly[k2,:] - vert)
# Find the edge's length: # Find the edge's length:
d = numpy.linalg.norm(poly[j2,:] - poly[j,:]) d = numpy.linalg.norm(poly[k2,:] - poly[k,:])
# These are equal if and only if the vertex lies along # These are equal if and only if the vertex lies along
# that edge: # that edge:
if numpy.isclose(d, d1 + d2): if numpy.isclose(d, d1 + d2):
v[i] = 1 v[i][j] = 1
break break
if v[i] > 0: if v[i][j] > 0:
break break
if v[i] > 0: if v[i][j] > 0:
continue continue
# Check against every *other* vert in cage.verts: # Check against every *other* vert in cages:
for j,vert2 in enumerate(cage.verts): for i2, cage2 in enumerate(cages):
if i == j: for j2, vert2 in enumerate(cage.verts):
if i == i2 and j == j2:
# same cage, same vertex - ignore:
continue continue
if numpy.allclose(vert, vert2): if numpy.allclose(vert, vert2):
v[i] = 2 v[i][j] = 2
break
if v[i][j] > 0:
break break
if v[i] > 0:
continue
return v return v
class CageFork(object): class CageFork(object):