First functioning pass at connectivity.
- added unittests (passing) - updated run script to take int for number of subds
This commit is contained in:
parent
2b3ab866b2
commit
285c6c7254
@ -11,6 +11,7 @@ if __name__ == '__main__':
|
|||||||
'(first argument) and dump json to stdout')
|
'(first argument) and dump json to stdout')
|
||||||
parser.add_argument('type', choices=('cc', 'butterfly'))
|
parser.add_argument('type', choices=('cc', 'butterfly'))
|
||||||
parser.add_argument('mesh')
|
parser.add_argument('mesh')
|
||||||
|
parser.add_argument('refines', type=int)
|
||||||
opt = parser.parse_args()
|
opt = parser.parse_args()
|
||||||
|
|
||||||
cube = json.load(open(opt.mesh, 'r'))
|
cube = json.load(open(opt.mesh, 'r'))
|
||||||
@ -21,5 +22,6 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
refine = butterfly.refine
|
refine = butterfly.refine
|
||||||
|
|
||||||
q = refine(p)
|
for i in range(opt.refines):
|
||||||
print(q)
|
p = refine(p)
|
||||||
|
print(p)
|
||||||
|
@ -152,6 +152,8 @@ class PolygonMesh(object):
|
|||||||
self._edges_for_vert = kwargs.get('edges for vert', None)
|
self._edges_for_vert = kwargs.get('edges for vert', None)
|
||||||
self._faces_for_vert = kwargs.get('faces for vert', None)
|
self._faces_for_vert = kwargs.get('faces for vert', None)
|
||||||
|
|
||||||
|
self._edge_map = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def faces_for_edge(self):
|
def faces_for_edge(self):
|
||||||
"""returns a list of face indices for a given edge index.
|
"""returns a list of face indices for a given edge index.
|
||||||
@ -168,17 +170,14 @@ class PolygonMesh(object):
|
|||||||
where 0 and 1 are indices into the face list
|
where 0 and 1 are indices into the face list
|
||||||
"""
|
"""
|
||||||
if self._faces_for_edge is None:
|
if self._faces_for_edge is None:
|
||||||
# TODO: eventually support generating this ourselves ...
|
self._set_up_face_edge_connectivity()
|
||||||
raise NotImplementedError
|
|
||||||
return self._faces_for_edge
|
return self._faces_for_edge
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def edges_for_face(self):
|
def edges_for_face(self):
|
||||||
"""returns a list of edge indices for a given face index."""
|
"""returns a list of edge indices for a given face index."""
|
||||||
# XXX
|
|
||||||
if self._edges_for_face is None:
|
if self._edges_for_face is None:
|
||||||
self._edges_for_face = [[] for i in range(len(self.faces))]
|
self._set_up_face_edge_connectivity()
|
||||||
|
|
||||||
return self._edges_for_face
|
return self._edges_for_face
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -201,6 +200,27 @@ class PolygonMesh(object):
|
|||||||
self._faces_for_vert[vid].append(i)
|
self._faces_for_vert[vid].append(i)
|
||||||
return self._faces_for_vert
|
return self._faces_for_vert
|
||||||
|
|
||||||
|
def _make_edge_map(self):
|
||||||
|
self._edge_map = {}
|
||||||
|
for i, edge in enumerate(self.edges):
|
||||||
|
self._edge_map[tuple(sorted(edge))] = i
|
||||||
|
|
||||||
|
def _set_up_face_edge_connectivity(self):
|
||||||
|
if self._edge_map is None:
|
||||||
|
self._make_edge_map()
|
||||||
|
self._edges_for_face = [[] for i in range(len(self.faces))]
|
||||||
|
self._faces_for_edge = [[] for i in range(len(self.edges))]
|
||||||
|
for face_id, face in enumerate(self.faces):
|
||||||
|
for i in range(len(face) -1):
|
||||||
|
cur_edge = tuple(sorted([face[i], face[i+1]]))
|
||||||
|
edge_id = self._edge_map[cur_edge]
|
||||||
|
self._edges_for_face[face_id].append(edge_id)
|
||||||
|
self._faces_for_edge[edge_id].append(face_id)
|
||||||
|
cur_edge = tuple(sorted([face[-1], face[0]]))
|
||||||
|
edge_id = self._edge_map[cur_edge]
|
||||||
|
self._edges_for_face[face_id].append(edge_id)
|
||||||
|
self._faces_for_edge[edge_id].append(face_id)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
# TODO: perhaps also add connectivity here?
|
# TODO: perhaps also add connectivity here?
|
||||||
d = {
|
d = {
|
||||||
|
@ -43,6 +43,14 @@ class TestPM(unittest.TestCase):
|
|||||||
for pi, qi in zip(self.skel.edges_for_vert, self.cube.edges_for_vert):
|
for pi, qi in zip(self.skel.edges_for_vert, self.cube.edges_for_vert):
|
||||||
self.assertEqual(sorted(pi), sorted(qi))
|
self.assertEqual(sorted(pi), sorted(qi))
|
||||||
|
|
||||||
|
def test_edges_for_face(self):
|
||||||
|
for pi, qi in zip(self.skel.edges_for_face, self.cube.edges_for_face):
|
||||||
|
self.assertEqual(sorted(pi), sorted(qi))
|
||||||
|
|
||||||
|
def test_faces_for_edge(self):
|
||||||
|
for pi, qi in zip(self.skel.faces_for_edge, self.cube.faces_for_edge):
|
||||||
|
self.assertEqual(sorted(pi), sorted(qi))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main(verbosity=3)
|
unittest.main(verbosity=3)
|
||||||
|
Loading…
Reference in New Issue
Block a user