This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinents.py
89 lines (68 loc) · 2.52 KB
/
continents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pymesh
import numpy as np
import sys
import random
import uuid
def genContinents(mesh):
# Add the Continent ID attribute to the Mesh
mesh.add_attribute("continentID")
val = np.zeros(mesh.num_faces)
mesh.set_attribute("continentID",val);
nContinents = random.randint(4,12)
Continents = []
for x in range(nContinents):
continentid = uuid.uuid4()
randomFaceElementNumber = random.randint(0,len(mesh.faces))
Continents.append(Continent(continentid,randomFaceElementNumber))
Continents[x].mesh = mesh
spaceRemain = True
while spaceRemain == True:
for continent in Continents:
if( continent.stepFill() == False ):
spaceRemain = False
else:
spaceRemain = True
return Continents
class Continent:
faces = []
nFaces = 0
mesh = None
def __init__(self,continentid,startface):
self.faces.append(startface)
self.id = continentid
def doesContain(self,faceID):
if faceID in faces:
return True
else:
return False
def sizeOfContinent(self):
size = 0.0
self.mesh.add_attribute("face_area")
facesizes = self.mesh.get_face_attribute("face_area")
for face in self.faces:
size += facesizes[face]
return size
def stepFill(self):
# Get an array of the IDs of all the adjacent faces
adjfaces = []
for curface in self.faces:
adjfaces.extend( self.mesh.get_face_adjacent_faces( curface ) )
# Get the current continent ID array
continentIDtoFace = self.mesh.get_face_attribute("continentID")
# Now to go and check how many of these adjfaces are currently unassigned and remove the ones already assigned
newlist = [ x for x in adjfaces if continentIDtoFace[x] == 0.0 ]
adjfaces = newlist
del(newlist)
# Return False if there are no more unassigned empty faces
if len(adjfaces) == 0:
return False
# Create a temporary copy of said attributes
tmp = continentIDtoFace[:].copy()
# Now we need change the attribute on the new adjfaces to reflect the correct id
for adjface in adjfaces:
tmp[adjface] = int(self.id)
# Set the attribute data back to the mesh
self.mesh.set_attribute("continentID",tmp);
self.faces.extend(adjfaces)
self.faces = list(set(self.faces))
return True