Skip to content

Commit

Permalink
cleanup, speed optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTesla committed Aug 3, 2024
1 parent ec4ab67 commit 13611cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
3 changes: 3 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,8 @@ def cube(x, y, z):

# render.renderAndSave(cube, 'demo.stl', 1)
render.renderAndSave(f, "demo.stl", 0.5)
render.renderAndSave(f, "demo1.stl", 0.6)
render.renderAndSave(f, "demo2.stl", 0.4)
render.renderAndSave(f, "demo3.stl", 0.1)

print(time.time() - t0)
51 changes: 31 additions & 20 deletions xyzcad/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,22 @@ def getSurface(func, startPnt, res=1.3):
return cubeCornerValsDict


@njit(cache=True, parallel=True)
# removed convert to set() - may trigger numba bug
@njit(cache=True)
def convert_corners2cubes(cubes_coord2cornersval_dict):
return np.asarray(list(cubes_coord2cornersval_dict.keys())), \
np.asarray(list(cubes_coord2cornersval_dict.values()))

# cubes_coord_arr = np.asarray(list(set(cubes_coord2cornersval_dict.keys())))
# cubes_cornersval_arr = np.zeros(cubes_coord_arr.shape[0], dtype=np.uint8)
# for i in prange(cubes_coord_arr.shape[0]):
# c = cubes_coord_arr[i]
# cubes_cornersval_arr[i] = cubes_coord2cornersval_dict[(c[0], c[1], c[2])]
# return cubes_coord_arr, cubes_cornersval_arr



@njit(cache=True)
def convert_corners2pts(cubeCornerValsDict, r):

ptsResDict = Dict()
Expand All @@ -556,21 +571,13 @@ def convert_corners2pts(cubeCornerValsDict, r):
ptsResDict[(xh, yh, z)] = 0 < (v & 64) # v110
ptsResDict[(xh, yh, zh)] = 0 < (v & 128) # v111

cubesList = list(set(cubeCornerValsDict.keys()))

print(f"len(cubesList)={len(cubesList)}")
cubesArray = np.asarray(cubesList)
ptCoordDictKeys = np.asarray(list(ptsResDict.keys()))
ptCoordDictVals = np.asarray(list(ptsResDict.values()))
cvArr = np.zeros(cubesArray.shape[0], dtype=np.uint8)
for i in prange(cubesArray.shape[0]):
c = cubesArray[i]
cvArr[i] = cubeCornerValsDict[(c[0], c[1], c[2])]
return cubesArray, ptCoordDictKeys, ptCoordDictVals, cvArr
return ptCoordDictKeys, ptCoordDictVals


@njit(cache=True, parallel=True)
def coords2relations(cubeCoordArray, ptCoordArray, ptValueArray, res):
def coords2relations(cubeCoordArray, ptCoordArray, res):
r = res

arr_split = 16
Expand Down Expand Up @@ -652,8 +659,6 @@ def coords2relations(cubeCoordArray, ptCoordArray, ptValueArray, res):
cube2ptIdxArray,
cube2edgeIdxArray,
edge2ptIdxArray,
ptCoordArray,
ptValueArray,
)


Expand Down Expand Up @@ -779,19 +784,25 @@ def all_njit_func(func, res, tlt):
print("getSurface time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
cubesArray, ptsKeys, ptsVals, cvList = convert_corners2pts(corners, res)
ptsKeys, pv = convert_corners2pts(corners, res)
print(
f"len(cubesArray, ptsKeys, ptsVals, cvList)={len(cubesArray)}, "
+ f"{len(ptsKeys)}, {len(ptsVals)},{len(cvList)}"
f"len(ptsKeys, pv)={len(ptsKeys)}, {len(pv)}"
)
with objmode():
print("convert_corners2pts time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
c2p, c2e, e2p, pc, pv = coords2relations(cubesArray, ptsKeys, ptsVals, res)
cubesArray, cvList = convert_corners2cubes(corners)
print(
f"len(cubesArray, cvList)={len(cubesArray)}, {len(cvList)}"
)
with objmode():
print("convert_corners2cubes time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
c2p, c2e, e2p = coords2relations(cubesArray, ptsKeys, res)
print(
f"len(c2p, c2e, e2p, pc, pv)={len(c2p)}, {len(c2e)}, {len(e2p)}, "
+ f"{len(pc)}, {len(pv)}"
f"len(c2p, c2e, e2p)={len(c2p)}, {len(c2e)}, {len(e2p)}"
)
with objmode():
print("coords2relations time: {}".format(time.perf_counter() - time1))
Expand All @@ -803,7 +814,7 @@ def all_njit_func(func, res, tlt):
print("cutCedgeIdx time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
precTrPtsList = precTrPnts(func, cCeI, e2p, pc)
precTrPtsList = precTrPnts(func, cCeI, e2p, ptsKeys)
print(f"len(precTrPtsList)={len(precTrPtsList)}")
with objmode():
print("precTrPnts time: {}".format(time.perf_counter() - time1))
Expand Down

0 comments on commit 13611cc

Please sign in to comment.