Skip to content

Commit

Permalink
minor speed improvement by combining two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTesla committed Aug 10, 2024
1 parent b1fed9b commit decdaa6
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions xyzcad/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,25 @@ def TrIdx2TrCoord(trList, cutCedgeIdxList, precTrPnts):
return coord_lst


@njit(cache=True)
def tridx2triangle(tr_lst, cutCedgeIdxList, precTrPnts):
cutCedgeIdxRevDict = {e: i for i, e in enumerate(cutCedgeIdxList)}
tr_arr = np.zeros((len(tr_lst) * 8, 3, 3))
c = 0
for k in range(len(tr_lst)):
poly = [
precTrPnts[cutCedgeIdxRevDict[f]]
for f in tr_lst[k]
if f in cutCedgeIdxRevDict
]
for i in range(len(poly) - 2):
tr_arr[c][0] = poly[0]
tr_arr[c][1] = poly[i + 1]
tr_arr[c][2] = poly[i + 2]
c += 1
return tr_arr[:c]


@njit(cache=True)
def filter_single_edge(poly_edge_list):
s1 = set(poly_edge_list)
Expand Down Expand Up @@ -850,16 +869,17 @@ def all_njit_func(func, res, tlt):
print("calc_closed_surface time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
polyPtsCoordList = TrIdx2TrCoord(corCircList, cCeI, precTrPtsList)
print(f"len(polyPtsCoordList)={len(polyPtsCoordList)}")
with objmode():
print("TrIdx2TrCoord time: {}".format(time.perf_counter() - time1))
with objmode(time1="f8"):
time1 = time.perf_counter()
verticesArray = poly2triangle(polyPtsCoordList)
verticesArray = tridx2triangle(corCircList, cCeI, precTrPtsList)
# polyPtsCoordList = TrIdx2TrCoord(corCircList, cCeI, precTrPtsList)
# print(f"len(polyPtsCoordList)={len(polyPtsCoordList)}")
# with objmode():
# print("TrIdx2TrCoord time: {}".format(time.perf_counter() - time1))
# with objmode(time1="f8"):
# time1 = time.perf_counter()
# verticesArray = poly2triangle(polyPtsCoordList)
print(f"len(verticesArray)={len(verticesArray)}")
with objmode():
print("poly2triangle time: {}".format(time.perf_counter() - time1))
print("tridx2triangle time: {}".format(time.perf_counter() - time1))
with objmode():
print("all_njitINTERN time: {}".format(time.perf_counter() - time0))
return verticesArray
Expand Down

0 comments on commit decdaa6

Please sign in to comment.