| 1 |
# Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions |
| 2 |
# of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 3 |
# NTESS, the U.S. Government retains certain rights in this software. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions are |
| 7 |
# met: |
| 8 |
# |
| 9 |
# * Redistributions of source code must retain the above copyright |
| 10 |
# notice, this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# * Redistributions in binary form must reproduce the above |
| 13 |
# copyright notice, this list of conditions and the following |
| 14 |
# disclaimer in the documentation and/or other materials provided |
| 15 |
# with the distribution. |
| 16 |
# |
| 17 |
# * Neither the name of NTESS nor the names of its |
| 18 |
# contributors may be used to endorse or promote products derived |
| 19 |
# from this software without specific prior written permission. |
| 20 |
# |
| 21 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
|
| 33 |
from phactori import * |
| 34 |
import math |
| 35 |
from .PhactoriVectorLibrary import * |
| 36 |
import vtk |
| 37 |
|
| 38 |
#phactori_combine_to_single_python_file_subpiece_begin_1 |
| 39 |
|
| 40 |
def PhactoriCalculateFaceArea(inInputCsData, targetFace): |
| 41 |
numFaceEdges = targetFace.GetNumberOfEdges() |
| 42 |
if numFaceEdges >= 3: |
| 43 |
#assumes convex polygons, weird answer if not |
| 44 |
retVal = 0.0 |
| 45 |
ptIds = targetFace.GetPointIds() |
| 46 |
ptA = inInputCsData.GetPoint(ptIds.GetId(0)) |
| 47 |
ptB = inInputCsData.GetPoint(ptIds.GetId(1)) |
| 48 |
vecAB = vecFromAToB(ptA, ptB) |
| 49 |
for ii in range(2, numFaceEdges): |
| 50 |
ptC = inInputCsData.GetPoint(ptIds.GetId(ii)) |
| 51 |
vecAC = vecFromAToB(ptA, ptC) |
| 52 |
ABxAC = vecCrossProduct(vecAB, vecAC) |
| 53 |
retVal += vecMagnitude(ABxAC) |
| 54 |
vecAB = vecAC |
| 55 |
retVal *= 0.5 |
| 56 |
else: |
| 57 |
#two or fewer vertices |
| 58 |
retVal = 0.0 |
| 59 |
return retVal |
| 60 |
|
| 61 |
def PhactoriCalculateCellFaceAreas(inInputCsData, oneCell): |
| 62 |
faceAreaList = [] |
| 63 |
numFaces = oneCell.GetNumberOfFaces() |
| 64 |
for faceNdx in range(0, numFaces): |
| 65 |
gsfslTestFace = oneCell.GetFace(faceNdx) |
| 66 |
faceAreaList.append(PhactoriCalculateFaceArea(inInputCsData, gsfslTestFace)) |
| 67 |
return faceAreaList |
| 68 |
|
| 69 |
def PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell): |
| 70 |
faceAreasByIndex = PhactoriCalculateCellFaceAreas(inInputCsData, oneCell) |
| 71 |
faceAreasSorted = sorted(faceAreasByIndex) |
| 72 |
return faceAreasByIndex, faceAreasSorted |
| 73 |
|
| 74 |
class PhactoriCountCellsTouchingFaceData: |
| 75 |
def __init__(self, inInputCsData): |
| 76 |
self.PerFaceData = {} |
| 77 |
self.vtkGrid = inInputCsData |
| 78 |
self.totalNumFaces = 0 |
| 79 |
self.totalNumFacesWithOneCellTouching = 0 |
| 80 |
self.totalNumFacesWithTwoCellsTouching = 0 |
| 81 |
self.totalNumFacesWith3plCellsTouching = 0 |
| 82 |
|
| 83 |
def DoCountForAllCellsInBlock(self): |
| 84 |
numCells = self.vtkGrid.GetNumberOfCells() |
| 85 |
for ii in range(0, numCells): |
| 86 |
self.DoCountForOneCell(ii) |
| 87 |
|
| 88 |
def DoCountForOneCell(self, cellIndex): |
| 89 |
oneCell = self.vtkGrid.GetCell(cellIndex) |
| 90 |
numFaces = oneCell.GetNumberOfFaces() |
| 91 |
for jj in range(0, numFaces): |
| 92 |
self.DoCountForOneFace(oneCell, cellIndex, jj) |
| 93 |
|
| 94 |
def GetFaceHash(self, oneFace): |
| 95 |
#for now we use the average of all face points to uniquely identify the |
| 96 |
#face; we could use all indices of the face but that is more complex |
| 97 |
#and we couldn't match up faces across block/processor boundaries |
| 98 |
#however, it's possible that average of vertices may fail in some |
| 99 |
#circumstances and we could use the x/y/z of all the vertices if necessary |
| 100 |
faceHash = [0.0, 0.0, 0.0] |
| 101 |
numFacePoints = oneFace.GetNumberOfPoints() |
| 102 |
facePointIds = oneFace.GetPointIds() |
| 103 |
facePointIds2 = [] |
| 104 |
for kk in range(0, numFacePoints): |
| 105 |
facePointIds2.append(facePointIds.GetId(kk)) |
| 106 |
facePointIds2 = sorted(facePointIds2) |
| 107 |
for pointId in facePointIds2: |
| 108 |
oneFacePoint = self.vtkGrid.GetPoint(pointId) |
| 109 |
faceHash[0] += oneFacePoint[0] |
| 110 |
faceHash[1] += oneFacePoint[1] |
| 111 |
faceHash[2] += oneFacePoint[2] |
| 112 |
return faceHash |
| 113 |
|
| 114 |
def DoCountForOneFace(self, oneCell, cellIndex, faceIndex): |
| 115 |
oneFace = oneCell.GetFace(faceIndex) |
| 116 |
faceHash = self.GetFaceHash(oneFace) |
| 117 |
self.IncrementCellTouchingFaceCount(faceHash, cellIndex, faceIndex) |
| 118 |
|
| 119 |
def IncrementCellTouchingFaceCount(self, faceHash, cellIndex, faceIndex): |
| 120 |
|
| 121 |
if faceHash[0] not in self.PerFaceData: |
| 122 |
self.PerFaceData[faceHash[0]] = {} |
| 123 |
facelvl1 = self.PerFaceData[faceHash[0]] |
| 124 |
if faceHash[1] not in facelvl1: |
| 125 |
facelvl1[faceHash[1]] = {} |
| 126 |
facelvl2 = facelvl1[faceHash[1]] |
| 127 |
if faceHash[2] not in facelvl2: |
| 128 |
facelvl2[faceHash[2]] = [1, cellIndex, faceIndex, -1, -1] |
| 129 |
self.totalNumFaces += 1 |
| 130 |
self.totalNumFacesWithOneCellTouching += 1 |
| 131 |
else: |
| 132 |
facelvl3 = facelvl2[faceHash[2]] |
| 133 |
if facelvl3[0] == 1: |
| 134 |
self.totalNumFacesWithOneCellTouching -= 1 |
| 135 |
self.totalNumFacesWithTwoCellsTouching += 1 |
| 136 |
elif facelvl3[0] == 2: |
| 137 |
self.totalNumFacesWithTwoCellsTouching -= 1 |
| 138 |
self.totalNumFacesWith3plCellsTouching += 1 |
| 139 |
facelvl3[0] += 1 |
| 140 |
facelvl3[3] = cellIndex |
| 141 |
facelvl3[4] = faceIndex |
| 142 |
|
| 143 |
def GetNumberOfCellsTouchingFace(self, oneFace): |
| 144 |
faceHash = self.GetFaceHash(oneFace) |
| 145 |
returnCount = self.PerFaceData[faceHash[0]][faceHash[1]][faceHash[2]][0] |
| 146 |
return returnCount |
| 147 |
|
| 148 |
def GetNumberOfCellsTouchingEachFaceOfOneCell(self, oneCellIndex): |
| 149 |
oneCell = self.vtkGrid.GetCell(oneCellIndex) |
| 150 |
returnCountPerFace = [] |
| 151 |
numFaces = oneCell.GetNumberOfFaces() |
| 152 |
for ii in range(0, numFaces): |
| 153 |
oneFace = oneCell.GetFace(ii) |
| 154 |
returnCountPerFace.append(self.GetNumberOfCellsTouchingFace(oneFace)) |
| 155 |
return returnCountPerFace |
| 156 |
|
| 157 |
def GetListOfExteriorFacesOnCell(self, oneCell): |
| 158 |
returnExteriorFaceIndices = [] |
| 159 |
numFaces = oneCell.GetNumberOfFaces() |
| 160 |
for ii in range(0, numFaces): |
| 161 |
oneFace = oneCell.GetFace(ii) |
| 162 |
if self.GetNumberOfCellsTouchingFace(oneFace) == 1: |
| 163 |
returnExteriorFaceIndices.append(ii) |
| 164 |
return returnExteriorFaceIndices |
| 165 |
|
| 166 |
def GetListOfExteriorFacesOnCellByIndex(self, cellIndex): |
| 167 |
return self.GetListOfExteriorFacesOnCell(self.vtkGrid.GetCell(cellIndex)) |
| 168 |
|
| 169 |
def PhactoriCountCellTouchingEachFace(inInputCsData): |
| 170 |
"""goes through each cell, and for each cell goes through each face, and for |
| 171 |
each of those faces creates/locates a count for that face and increments |
| 172 |
it. Purpose is to find cells with faces that don't neighbor other cells |
| 173 |
""" |
| 174 |
countCellsTouchingEachFace = PhactoriCountCellsTouchingFaceData(inInputCsData) |
| 175 |
countCellsTouchingEachFace.DoCountForAllCellsInBlock() |
| 176 |
if PhactoriDbg(100): |
| 177 |
cctef = countCellsTouchingEachFace |
| 178 |
myDebugPrint3("PhactoriCountCellTouchingEachFace:" + \ |
| 179 |
"\nnum cells in block: " + str(inInputCsData.GetNumberOfCells()) + \ |
| 180 |
"\nnum faces: " + str(cctef.totalNumFaces) + \ |
| 181 |
"\nnum faces with 1 cell: " + str(cctef.totalNumFacesWithOneCellTouching) + \ |
| 182 |
"\nnum faces with 2 cells: " + str(cctef.totalNumFacesWithTwoCellsTouching) + \ |
| 183 |
"\nnum faces with 3+ cells: " + str(cctef.totalNumFacesWith3plCellsTouching) + "\n") |
| 184 |
|
| 185 |
return countCellsTouchingEachFace |
| 186 |
|
| 187 |
def PhactoriCountCellTouchingEachPoint(inInputCsData): |
| 188 |
numCells = inInputCsData.GetNumberOfCells() |
| 189 |
numPoints = inInputCsData.GetNumberOfPoints() |
| 190 |
cellsTouchingPointCount = [0] * numPoints |
| 191 |
for ii in range(0, numCells): |
| 192 |
oneCell = inInputCsData.GetCell(ii) |
| 193 |
cellPointIds = oneCell.GetPointIds() |
| 194 |
numCellPoints = oneCell.GetNumberOfPoints() |
| 195 |
for jj in range(0, numCellPoints): |
| 196 |
oneCellPointId = cellPointIds.GetId(jj) |
| 197 |
cellsTouchingPointCount[oneCellPointId] += 1 |
| 198 |
return cellsTouchingPointCount |
| 199 |
|
| 200 |
def PhactoriSurfaceCornerCellFaceFacesExterior(oneFace, cellsTouchingPointCount): |
| 201 |
numFacePoints = oneFace.GetNumberOfPoints() |
| 202 |
facePointIds = oneFace.GetPointIds() |
| 203 |
numOutsideVertices = 0 |
| 204 |
for ii in range(0, numFacePoints): |
| 205 |
if cellsTouchingPointCount[facePointIds.GetId(ii)] <= 1: |
| 206 |
return True |
| 207 |
return False |
| 208 |
|
| 209 |
def PhactoriIsOutsideCornerHexCellFaceMaxAreaFace(oneCell, indexFaceListSize, |
| 210 |
sortedFaceSizeList, cellsTouchingPointCount, TestNthLargestFace = 2): |
| 211 |
#faces with 4 2 2 0 need to be tested |
| 212 |
numFaces = oneCell.GetNumberOfFaces() |
| 213 |
for faceIndex in range(0, numFaces): |
| 214 |
oneFace = oneCell.GetFace(faceIndex) |
| 215 |
if PhactoriSurfaceCornerCellFaceFacesExterior(oneFace, cellsTouchingPointCount): |
| 216 |
if indexFaceListSize[faceIndex] >= sortedFaceSizeList[-TestNthLargestFace]: |
| 217 |
#this cell is facing the big area cell side |
| 218 |
return True |
| 219 |
return False |
| 220 |
|
| 221 |
def PhactoriSurfaceEdgeHexCellFaceFacesExterior(oneFace, cellsTouchingPointCount): |
| 222 |
numFacePoints = oneFace.GetNumberOfPoints() |
| 223 |
facePointIds = oneFace.GetPointIds() |
| 224 |
numOutsideVertices = 0 |
| 225 |
for ii in range(0, numFacePoints): |
| 226 |
if cellsTouchingPointCount[facePointIds.GetId(ii)] <= 2: |
| 227 |
numOutsideVertices += 1 |
| 228 |
return (numOutsideVertices >= 2) |
| 229 |
|
| 230 |
def PhactoriIsOutsideEdgeHexCellFaceMaxAreaFace(oneCell, |
| 231 |
indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount, |
| 232 |
TestNthLargestFace = 2): |
| 233 |
#faces with 4 4 2 2 need to be tested |
| 234 |
numFaces = oneCell.GetNumberOfFaces() |
| 235 |
#test cell flatness |
| 236 |
for faceIndex in range(0, numFaces): |
| 237 |
oneFace = oneCell.GetFace(faceIndex) |
| 238 |
if PhactoriSurfaceEdgeHexCellFaceFacesExterior(oneFace, cellsTouchingPointCount): |
| 239 |
if indexFaceListSize[faceIndex] >= sortedFaceSizeList[-TestNthLargestFace]: |
| 240 |
#this cell is exterior and facing the big area cell side |
| 241 |
return True |
| 242 |
return False |
| 243 |
|
| 244 |
def PhactoriIsOutsideSurfaceHexCellFaceMaxAreaFace(oneCell, |
| 245 |
indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount, |
| 246 |
TestNthLargestFace = 2): |
| 247 |
#find face which face faces exterior |
| 248 |
numFaces = oneCell.GetNumberOfFaces() |
| 249 |
for faceIndex in range(0, numFaces): |
| 250 |
oneFace = oneCell.GetFace(faceIndex) |
| 251 |
numFacePoints = oneFace.GetNumberOfPoints() |
| 252 |
facePtNdxs = oneFace.GetPointIds() |
| 253 |
outsideFaceIndex = -1 |
| 254 |
for jj in range(0, numFacePoints): |
| 255 |
outsideFaceIndex = faceIndex |
| 256 |
ptNdx = facePtNdxs.GetId(jj) |
| 257 |
if cellsTouchingPointCount[ptNdx] != 4: |
| 258 |
outsideFaceIndex = -1 |
| 259 |
#this is not the outward facing face |
| 260 |
break |
| 261 |
if outsideFaceIndex >= 0: |
| 262 |
#this is the outward facing face |
| 263 |
break |
| 264 |
if outsideFaceIndex < 0: |
| 265 |
#shouldn't happen, didn't find face with all 4's |
| 266 |
myDebugPrint3AndException("outsideFaceIndex < 0 error\n") |
| 267 |
return False |
| 268 |
#now see if this outward facing face is one of the Nth largest |
| 269 |
if indexFaceListSize[outsideFaceIndex] >= sortedFaceSizeList[-TestNthLargestFace]: |
| 270 |
return True |
| 271 |
else: |
| 272 |
return False |
| 273 |
|
| 274 |
def PhactoriFindSurfaceStatusForOneCellUsingFaceInfo(inInputCsData, |
| 275 |
inCellIndex, countCellsTouchingEachFace, flatnessTestRatio = 100.0, |
| 276 |
TestNthLargestFace = 2): |
| 277 |
oneCell = inInputCsData.GetCell(inCellIndex) |
| 278 |
exteriorFaceList = countCellsTouchingEachFace.GetListOfExteriorFacesOnCell(oneCell) |
| 279 |
numExteriorFaces = len(exteriorFaceList) |
| 280 |
if numExteriorFaces == 0: |
| 281 |
#interior cell |
| 282 |
retStatus = 1 |
| 283 |
else: |
| 284 |
#surface cell (surface, edge, or corner) |
| 285 |
#test cell flatness |
| 286 |
indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell) |
| 287 |
flatnessRatio = sortedFaceSizeList[-1] / sortedFaceSizeList[0] |
| 288 |
if len(sortedFaceSizeList) <= 0: |
| 289 |
retStatus = 11 |
| 290 |
return retStatus |
| 291 |
cellIsFlat = (flatnessRatio >= flatnessTestRatio) |
| 292 |
#see if any of the exterior faces are the biggest |
| 293 |
outsideFaceIsMaxAreaFace = False |
| 294 |
for outsideFaceIndex in exteriorFaceList: |
| 295 |
if indexFaceListSize[outsideFaceIndex] >= sortedFaceSizeList[-TestNthLargestFace]: |
| 296 |
outsideFaceIsMaxAreaFace = True |
| 297 |
break |
| 298 |
if numExteriorFaces == 1: |
| 299 |
#outside surface, not edge or corner |
| 300 |
if outsideFaceIsMaxAreaFace: |
| 301 |
if cellIsFlat: |
| 302 |
retStatus = 11 |
| 303 |
else: |
| 304 |
retStatus = 8 |
| 305 |
else: |
| 306 |
if cellIsFlat: |
| 307 |
retStatus = 5 |
| 308 |
else: |
| 309 |
retStatus = 2 |
| 310 |
elif numExteriorFaces == 2: |
| 311 |
#outside edge, not corner |
| 312 |
if outsideFaceIsMaxAreaFace: |
| 313 |
if cellIsFlat: |
| 314 |
retStatus = 12 |
| 315 |
else: |
| 316 |
retStatus = 9 |
| 317 |
else: |
| 318 |
if cellIsFlat: |
| 319 |
retStatus = 6 |
| 320 |
else: |
| 321 |
retStatus = 3 |
| 322 |
else: |
| 323 |
#outside surface corner |
| 324 |
if outsideFaceIsMaxAreaFace: |
| 325 |
if cellIsFlat: |
| 326 |
retStatus = 13 |
| 327 |
else: |
| 328 |
retStatus = 10 |
| 329 |
else: |
| 330 |
if cellIsFlat: |
| 331 |
retStatus = 7 |
| 332 |
else: |
| 333 |
retStatus = 4 |
| 334 |
return retStatus |
| 335 |
|
| 336 |
|
| 337 |
def PhactoriFindSurfaceStatusForOneCell(inInputCsData, inCellIndex, |
| 338 |
cellsTouchingPointCount, flatnessTestRatio = 100.0): |
| 339 |
oneCell = inInputCsData.GetCell(inCellIndex) |
| 340 |
|
| 341 |
#cells with all 8 are interior |
| 342 |
#cells with 4 and 8 are outside surface |
| 343 |
#cells with 2 (and no 0) are outside edge |
| 344 |
#cells with 1 are corner |
| 345 |
|
| 346 |
#not currently handling inside edge (there are count 6 cells) or inside |
| 347 |
#corner (there are count 7 cells) |
| 348 |
|
| 349 |
#if cell is outside surface (4 and 8), if the face which is all 4 is the |
| 350 |
#largest or second largest area, then it is on the surface we want |
| 351 |
|
| 352 |
#if the cell is edge (2 4 8), there should be two sides which are 2 2 4 4 |
| 353 |
#if either of these sides is the second or largest area then it is on the |
| 354 |
#surface we want. |
| 355 |
|
| 356 |
#if the cell is corner, there should be three sides which are 0 2 2 4 |
| 357 |
#if any of these sides is the second or largest area then it is on the |
| 358 |
#surface we want |
| 359 |
|
| 360 |
numPoints = oneCell.GetNumberOfPoints() |
| 361 |
pointIds = oneCell.GetPointIds() |
| 362 |
minCtpc = 9 |
| 363 |
for ii in range(0, numPoints): |
| 364 |
testCtpc = cellsTouchingPointCount[pointIds.GetId(ii)] |
| 365 |
if testCtpc < minCtpc: |
| 366 |
minCtpc = testCtpc |
| 367 |
|
| 368 |
#if inCellIndex == 172065: |
| 369 |
if inCellIndex == 5056: |
| 370 |
debugFlag = 100 |
| 371 |
else: |
| 372 |
debugFlag = 25 |
| 373 |
if minCtpc >= 8: |
| 374 |
#interior cell |
| 375 |
retStatus = 1 |
| 376 |
else: |
| 377 |
#surface cell (surface, edge, or corner) |
| 378 |
#test cell flatness |
| 379 |
indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell) |
| 380 |
flatnessRatio = sortedFaceSizeList[-1] / sortedFaceSizeList[0] |
| 381 |
if len(sortedFaceSizeList) <= 0: |
| 382 |
retStatus = 11 |
| 383 |
return retStatus |
| 384 |
cellIsFlat = (flatnessRatio >= flatnessTestRatio) |
| 385 |
if minCtpc >= 4: |
| 386 |
#outside surface, not edge or corner |
| 387 |
outsideFaceIsMaxAreaFace = PhactoriIsOutsideSurfaceHexCellFaceMaxAreaFace( |
| 388 |
oneCell, indexFaceListSize, sortedFaceSizeList, |
| 389 |
cellsTouchingPointCount) |
| 390 |
if outsideFaceIsMaxAreaFace: |
| 391 |
if cellIsFlat: |
| 392 |
retStatus = 11 |
| 393 |
else: |
| 394 |
retStatus = 8 |
| 395 |
else: |
| 396 |
if cellIsFlat: |
| 397 |
retStatus = 5 |
| 398 |
else: |
| 399 |
retStatus = 2 |
| 400 |
elif minCtpc >= 2: |
| 401 |
#outside surface edge, not corner |
| 402 |
outsideFaceIsMaxAreaFace = PhactoriIsOutsideEdgeHexCellFaceMaxAreaFace( |
| 403 |
oneCell, indexFaceListSize, sortedFaceSizeList, |
| 404 |
cellsTouchingPointCount) |
| 405 |
if outsideFaceIsMaxAreaFace: |
| 406 |
if cellIsFlat: |
| 407 |
retStatus = 12 |
| 408 |
else: |
| 409 |
retStatus = 9 |
| 410 |
else: |
| 411 |
if cellIsFlat: |
| 412 |
retStatus = 6 |
| 413 |
else: |
| 414 |
retStatus = 3 |
| 415 |
elif minCtpc >= 1: |
| 416 |
#outside surface corner |
| 417 |
outsideFaceIsMaxAreaFace = PhactoriIsOutsideCornerHexCellFaceMaxAreaFace( |
| 418 |
oneCell, indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount) |
| 419 |
if outsideFaceIsMaxAreaFace: |
| 420 |
if cellIsFlat: |
| 421 |
retStatus = 13 |
| 422 |
else: |
| 423 |
retStatus = 10 |
| 424 |
else: |
| 425 |
if cellIsFlat: |
| 426 |
retStatus = 7 |
| 427 |
else: |
| 428 |
retStatus = 4 |
| 429 |
else: |
| 430 |
#should not get here |
| 431 |
myDebugPrint3AndException("bad minCtpc error\n") |
| 432 |
retStatus = -1 |
| 433 |
|
| 434 |
return retStatus |
| 435 |
|
| 436 |
def PhactoriGetCellEdgeVector(inInputCsData, oneFaceOrCell, edgeIndex): |
| 437 |
oneFaceEdgePointIds = oneFaceOrCell.GetEdge(edgeIndex).GetPointIds() |
| 438 |
ptA = inInputCsData.GetPoint(oneFaceEdgePointIds.GetId(0)) |
| 439 |
ptB = inInputCsData.GetPoint(oneFaceEdgePointIds.GetId(1)) |
| 440 |
retVec = vecFromAToB(ptA,ptB) |
| 441 |
return retVec |
| 442 |
|
| 443 |
def PhactoriFindFaceNormal(inInputCsData, oneFace): |
| 444 |
facePointIds = oneFace.GetPointIds() |
| 445 |
#maybe should work harder to find good normal |
| 446 |
ptA = inInputCsData.GetPoint(facePointIds.GetId(0)) |
| 447 |
ptB = inInputCsData.GetPoint(facePointIds.GetId(1)) |
| 448 |
ptC = inInputCsData.GetPoint(facePointIds.GetId(2)) |
| 449 |
vecAB = vecFromAToB(ptA, ptB) |
| 450 |
vecBC = vecFromAToB(ptB, ptC) |
| 451 |
retNormalVec = vecCrossProduct(vecBC, vecAB) |
| 452 |
vecNormalize2(retNormalVec, retNormalVec) |
| 453 |
return retNormalVec |
| 454 |
|
| 455 |
def PhactoriFindLargestCellFaceNormal(inInputCsData, oneCell): |
| 456 |
indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell) |
| 457 |
biggestFaceSize = sortedFaceSizeList[-1] |
| 458 |
for faceForNormalIndex in range(0, len(indexFaceListSize)): |
| 459 |
if indexFaceListSize[faceForNormalIndex] == biggestFaceSize: |
| 460 |
break |
| 461 |
faceForNormal = oneCell.GetFace(faceForNormalIndex) |
| 462 |
retNormalVec = PhactoriFindFaceNormal(inInputCsData, faceForNormal) |
| 463 |
return retNormalVec |
| 464 |
|
| 465 |
def PhactoriGetAverageOfCellPoints(inInputCsData, oneCell): |
| 466 |
numPoints = oneCell.GetNumberOfPoints() |
| 467 |
retAvgPt = [0.0, 0.0, 0.0] |
| 468 |
if numPoints <= 0: |
| 469 |
return retAvgPt |
| 470 |
ptIds = oneCell.GetPointIds() |
| 471 |
for ii in range(0, numPoints): |
| 472 |
ptA = inInputCsData.GetPoint(ptIds.GetId(ii)) |
| 473 |
vecAddInPlace(retAvgPt, ptA) |
| 474 |
avgFac = 1.0/float(numPoints) |
| 475 |
vecScaleInPlace(avgFac, retAvgPt) |
| 476 |
return retAvgPt |
| 477 |
|
| 478 |
def PhactoriFindSelectedAngleBetweenEdgeAndCellNormal(inInputCsData, oneCell, |
| 479 |
compareNormal, paramUseSmallestAngle, paramOffsetIndex): |
| 480 |
edgeCompareDotProdList = [] |
| 481 |
numEdges = oneCell.GetNumberOfEdges() |
| 482 |
for ii in range(0, numEdges): |
| 483 |
oneEdgeVec = PhactoriGetCellEdgeVector(inInputCsData, oneCell, ii) |
| 484 |
vecNormalize2(oneEdgeVec, oneEdgeVec) |
| 485 |
edgeCompareDotProd = abs(vecDotProduct(compareNormal, oneEdgeVec)) |
| 486 |
edgeCompareDotProdList.append(edgeCompareDotProd) |
| 487 |
|
| 488 |
sortedEdgeCompareDotProdList = sorted(edgeCompareDotProdList) |
| 489 |
|
| 490 |
if paramUseSmallestAngle: |
| 491 |
outputIndex = max(0, numEdges - 1 - paramOffsetIndex) |
| 492 |
else: |
| 493 |
outputIndex = min(paramOffsetIndex, numEdges - 1) |
| 494 |
|
| 495 |
outputAngle = 90.0 - math.degrees(math.acos(sortedEdgeCompareDotProdList[outputIndex])) |
| 496 |
return outputAngle |
| 497 |
|
| 498 |
def DebugPrintPhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal): |
| 499 |
if PhactoriDbg(100): |
| 500 |
dbght = [] |
| 501 |
dbglen = [] |
| 502 |
dbgretHeight = -1.0 |
| 503 |
dbgretHeightIndex = -1 |
| 504 |
for ii in range(0, numCellEdges): |
| 505 |
oneCellEdgeVec = PhactoriGetCellEdgeVector(inInputCsData, oneCell, ii) |
| 506 |
dp1 = vecDotProduct(oneCellEdgeVec, compareNormal) |
| 507 |
projectedVec = vecScale(dp1, compareNormal) |
| 508 |
oneCellEdgeHeight = vecMagnitude(projectedVec) |
| 509 |
dbght.append(oneCellEdgeHeight) |
| 510 |
dbglen.append(vecMagnitude(oneCellEdgeVec)) |
| 511 |
if oneCellEdgeHeight > dbgretHeight: |
| 512 |
dbgretHeight = oneCellEdgeHeight |
| 513 |
dbgretHeightIndex = ii |
| 514 |
#how many edges before projection are longer than the height edge, and |
| 515 |
#is the height edge one of the four shortest |
| 516 |
myDebugPrint3("cell height: " + str(dbgretHeight) + " index: " + \ |
| 517 |
str(dbgretHeightIndex) + " edgelen: " + str(dbglen[dbgretHeightIndex]) + "\n") |
| 518 |
myDebugPrint3("all edge length, height pairs:\n") |
| 519 |
numLonger = 0 |
| 520 |
for ii in range(0, numCellEdges): |
| 521 |
if dbglen[ii] >= dbglen[dbgretHeightIndex]: |
| 522 |
numLonger += 1 |
| 523 |
myDebugPrint3(str(ii) + ": " + str(dbglen[ii]) + ", " + str(dbght[ii]) + "\n") |
| 524 |
myDebugPrint3("num edges longer than cell height edge: " + str(numLonger) + "\n") |
| 525 |
|
| 526 |
def PhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal): |
| 527 |
#do we need to discard eight longest sides, or will they project to less |
| 528 |
#than the four shortest sides? |
| 529 |
numCellEdges = oneCell.GetNumberOfEdges() |
| 530 |
|
| 531 |
retHeight = -1.0 |
| 532 |
for ii in range(0, numCellEdges): |
| 533 |
#get edge vectory and project on to normal vector (which is unit length) |
| 534 |
#and find magnitude |
| 535 |
oneCellEdgeVec = PhactoriGetCellEdgeVector(inInputCsData, oneCell, ii) |
| 536 |
dp1 = vecDotProduct(oneCellEdgeVec, compareNormal) |
| 537 |
projectedVec = vecScale(dp1, compareNormal) |
| 538 |
oneCellEdgeHeight = vecMagnitude(projectedVec) |
| 539 |
if oneCellEdgeHeight > retHeight: |
| 540 |
retHeight = oneCellEdgeHeight |
| 541 |
#if PhactoriDbg(100): |
| 542 |
# DebugPrintPhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal) |
| 543 |
return retHeight |
| 544 |
|
| 545 |
def PhactoriFindCellEdgeAngleMetricsForOneCell(inInputCsData, inCellIndex, |
| 546 |
paramUseSmallestAngle, paramOffsetIndex): |
| 547 |
oneCell = inInputCsData.GetCell(inCellIndex) |
| 548 |
numEdges = oneCell.GetNumberOfEdges() |
| 549 |
if numEdges < 6: |
| 550 |
return 90.0, 0.0 |
| 551 |
if oneCell.GetNumberOfFaces() < 4: |
| 552 |
return 90.0, 0.0 |
| 553 |
|
| 554 |
compareNormal = PhactoriFindLargestCellFaceNormal(inInputCsData, oneCell) |
| 555 |
retAngle = PhactoriFindSelectedAngleBetweenEdgeAndCellNormal(inInputCsData, |
| 556 |
oneCell, compareNormal, paramUseSmallestAngle, paramOffsetIndex) |
| 557 |
retHeight = PhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal) |
| 558 |
return retAngle, retHeight |
| 559 |
|
| 560 |
def GetPhactoriVtkCellOperationsProgrammableFilterLines(pfLns): |
| 561 |
pfLns.append("def PhactoriCalculateFaceArea(inInputCsData, targetFace):\n") |
| 562 |
pfLns.append(" numFaceEdges = targetFace.GetNumberOfEdges()\n") |
| 563 |
pfLns.append(" if numFaceEdges >= 3:\n") |
| 564 |
pfLns.append(" retVal = 0.0\n") |
| 565 |
pfLns.append(" ptIds = targetFace.GetPointIds()\n") |
| 566 |
pfLns.append(" ptA = inInputCsData.GetPoint(ptIds.GetId(0))\n") |
| 567 |
pfLns.append(" ptB = inInputCsData.GetPoint(ptIds.GetId(1))\n") |
| 568 |
pfLns.append(" vecAB = vecFromAToB(ptA, ptB)\n") |
| 569 |
pfLns.append(" for ii in range(2, numFaceEdges):\n") |
| 570 |
pfLns.append(" ptC = inInputCsData.GetPoint(ptIds.GetId(ii))\n") |
| 571 |
pfLns.append(" vecAC = vecFromAToB(ptA, ptC)\n") |
| 572 |
pfLns.append(" ABxAC = vecCrossProduct(vecAB, vecAC)\n") |
| 573 |
pfLns.append(" retVal += vecMagnitude(ABxAC)\n") |
| 574 |
pfLns.append(" vecAB = vecAC\n") |
| 575 |
pfLns.append(" retVal *= 0.5\n") |
| 576 |
pfLns.append(" else:\n") |
| 577 |
pfLns.append(" retVal = 0.0\n") |
| 578 |
pfLns.append(" return retVal\n") |
| 579 |
pfLns.append("def PhactoriCalculateCellFaceAreas(inInputCsData, oneCell):\n") |
| 580 |
pfLns.append(" faceAreaList = []\n") |
| 581 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 582 |
pfLns.append(" for faceNdx in range(0, numFaces):\n") |
| 583 |
pfLns.append(" gsfslTestFace = oneCell.GetFace(faceNdx)\n") |
| 584 |
pfLns.append(" faceAreaList.append(PhactoriCalculateFaceArea(inInputCsData, gsfslTestFace))\n") |
| 585 |
pfLns.append(" return faceAreaList\n") |
| 586 |
pfLns.append("def PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell):\n") |
| 587 |
pfLns.append(" faceAreasByIndex = PhactoriCalculateCellFaceAreas(inInputCsData, oneCell)\n") |
| 588 |
pfLns.append(" faceAreasSorted = sorted(faceAreasByIndex)\n") |
| 589 |
pfLns.append(" return faceAreasByIndex, faceAreasSorted\n") |
| 590 |
pfLns.append("class PhactoriCountCellsTouchingFaceData:\n") |
| 591 |
pfLns.append(" def __init__(self, inInputCsData):\n") |
| 592 |
pfLns.append(" self.PerFaceData = {}\n") |
| 593 |
pfLns.append(" self.vtkGrid = inInputCsData\n") |
| 594 |
pfLns.append(" self.totalNumFaces = 0\n") |
| 595 |
pfLns.append(" self.totalNumFacesWithOneCellTouching = 0\n") |
| 596 |
pfLns.append(" self.totalNumFacesWithTwoCellsTouching = 0\n") |
| 597 |
pfLns.append(" self.totalNumFacesWith3plCellsTouching = 0\n") |
| 598 |
pfLns.append(" def DoCountForAllCellsInBlock(self):\n") |
| 599 |
pfLns.append(" numCells = self.vtkGrid.GetNumberOfCells()\n") |
| 600 |
pfLns.append(" for ii in range(0, numCells):\n") |
| 601 |
pfLns.append(" self.DoCountForOneCell(ii)\n") |
| 602 |
pfLns.append(" def DoCountForOneCell(self, cellIndex):\n") |
| 603 |
pfLns.append(" oneCell = self.vtkGrid.GetCell(cellIndex)\n") |
| 604 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 605 |
pfLns.append(" for jj in range(0, numFaces):\n") |
| 606 |
pfLns.append(" self.DoCountForOneFace(oneCell, cellIndex, jj)\n") |
| 607 |
pfLns.append(" def GetFaceHash(self, oneFace):\n") |
| 608 |
pfLns.append(" faceHash = [0.0, 0.0, 0.0]\n") |
| 609 |
pfLns.append(" numFacePoints = oneFace.GetNumberOfPoints()\n") |
| 610 |
pfLns.append(" facePointIds = oneFace.GetPointIds()\n") |
| 611 |
pfLns.append(" facePointIds2 = []\n") |
| 612 |
pfLns.append(" for kk in range(0, numFacePoints):\n") |
| 613 |
pfLns.append(" facePointIds2.append(facePointIds.GetId(kk))\n") |
| 614 |
pfLns.append(" facePointIds2 = sorted(facePointIds2)\n") |
| 615 |
pfLns.append(" for pointId in facePointIds2:\n") |
| 616 |
pfLns.append(" oneFacePoint = self.vtkGrid.GetPoint(pointId)\n") |
| 617 |
pfLns.append(" faceHash[0] += oneFacePoint[0]\n") |
| 618 |
pfLns.append(" faceHash[1] += oneFacePoint[1]\n") |
| 619 |
pfLns.append(" faceHash[2] += oneFacePoint[2]\n") |
| 620 |
pfLns.append(" return faceHash\n") |
| 621 |
pfLns.append(" def DoCountForOneFace(self, oneCell, cellIndex, faceIndex):\n") |
| 622 |
pfLns.append(" oneFace = oneCell.GetFace(faceIndex)\n") |
| 623 |
pfLns.append(" faceHash = self.GetFaceHash(oneFace)\n") |
| 624 |
pfLns.append(" self.IncrementCellTouchingFaceCount(faceHash, cellIndex, faceIndex)\n") |
| 625 |
pfLns.append(" def IncrementCellTouchingFaceCount(self, faceHash, cellIndex, faceIndex):\n") |
| 626 |
pfLns.append(" if faceHash[0] not in self.PerFaceData:\n") |
| 627 |
pfLns.append(" self.PerFaceData[faceHash[0]] = {}\n") |
| 628 |
pfLns.append(" facelvl1 = self.PerFaceData[faceHash[0]]\n") |
| 629 |
pfLns.append(" if faceHash[1] not in facelvl1:\n") |
| 630 |
pfLns.append(" facelvl1[faceHash[1]] = {}\n") |
| 631 |
pfLns.append(" facelvl2 = facelvl1[faceHash[1]]\n") |
| 632 |
pfLns.append(" if faceHash[2] not in facelvl2:\n") |
| 633 |
pfLns.append(" facelvl2[faceHash[2]] = [1, cellIndex, faceIndex, -1, -1]\n") |
| 634 |
pfLns.append(" self.totalNumFaces += 1\n") |
| 635 |
pfLns.append(" self.totalNumFacesWithOneCellTouching += 1\n") |
| 636 |
pfLns.append(" else:\n") |
| 637 |
pfLns.append(" facelvl3 = facelvl2[faceHash[2]]\n") |
| 638 |
pfLns.append(" if facelvl3[0] == 1:\n") |
| 639 |
pfLns.append(" self.totalNumFacesWithOneCellTouching -= 1\n") |
| 640 |
pfLns.append(" self.totalNumFacesWithTwoCellsTouching += 1\n") |
| 641 |
pfLns.append(" elif facelvl3[0] == 2:\n") |
| 642 |
pfLns.append(" self.totalNumFacesWithTwoCellsTouching -= 1\n") |
| 643 |
pfLns.append(" self.totalNumFacesWith3plCellsTouching += 1\n") |
| 644 |
pfLns.append(" facelvl3[0] += 1\n") |
| 645 |
pfLns.append(" facelvl3[3] = cellIndex\n") |
| 646 |
pfLns.append(" facelvl3[4] = faceIndex\n") |
| 647 |
pfLns.append(" def GetNumberOfCellsTouchingFace(self, oneFace):\n") |
| 648 |
pfLns.append(" faceHash = self.GetFaceHash(oneFace)\n") |
| 649 |
pfLns.append(" returnCount = self.PerFaceData[faceHash[0]][faceHash[1]][faceHash[2]][0]\n") |
| 650 |
pfLns.append(" return returnCount\n") |
| 651 |
pfLns.append(" def GetNumberOfCellsTouchingEachFaceOfOneCell(self, oneCellIndex):\n") |
| 652 |
pfLns.append(" oneCell = self.vtkGrid.GetCell(oneCellIndex)\n") |
| 653 |
pfLns.append(" returnCountPerFace = []\n") |
| 654 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 655 |
pfLns.append(" for ii in range(0, numFaces):\n") |
| 656 |
pfLns.append(" oneFace = oneCell.GetFace(ii)\n") |
| 657 |
pfLns.append(" returnCountPerFace.append(self.GetNumberOfCellsTouchingFace(oneFace))\n") |
| 658 |
pfLns.append(" return returnCountPerFace\n") |
| 659 |
pfLns.append(" def GetListOfExteriorFacesOnCell(self, oneCell):\n") |
| 660 |
pfLns.append(" returnExteriorFaceIndices = []\n") |
| 661 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 662 |
pfLns.append(" for ii in range(0, numFaces):\n") |
| 663 |
pfLns.append(" oneFace = oneCell.GetFace(ii)\n") |
| 664 |
pfLns.append(" if self.GetNumberOfCellsTouchingFace(oneFace) == 1:\n") |
| 665 |
pfLns.append(" returnExteriorFaceIndices.append(ii)\n") |
| 666 |
pfLns.append(" return returnExteriorFaceIndices\n") |
| 667 |
pfLns.append(" def GetListOfExteriorFacesOnCellByIndex(self, cellIndex):\n") |
| 668 |
pfLns.append(" return self.GetListOfExteriorFacesOnCell(self.vtkGrid.GetCell(cellIndex))\n") |
| 669 |
pfLns.append("def PhactoriCountCellTouchingEachFace(inInputCsData):\n") |
| 670 |
pfLns.append(" countCellsTouchingEachFace = PhactoriCountCellsTouchingFaceData(inInputCsData)\n") |
| 671 |
pfLns.append(" countCellsTouchingEachFace.DoCountForAllCellsInBlock()\n") |
| 672 |
pfLns.append(" return countCellsTouchingEachFace\n") |
| 673 |
pfLns.append("def PhactoriCountCellTouchingEachPoint(inInputCsData):\n") |
| 674 |
pfLns.append(" numCells = inInputCsData.GetNumberOfCells()\n") |
| 675 |
pfLns.append(" numPoints = inInputCsData.GetNumberOfPoints()\n") |
| 676 |
pfLns.append(" cellsTouchingPointCount = [0] * numPoints\n") |
| 677 |
pfLns.append(" for ii in range(0, numCells):\n") |
| 678 |
pfLns.append(" oneCell = inInputCsData.GetCell(ii)\n") |
| 679 |
pfLns.append(" cellPointIds = oneCell.GetPointIds()\n") |
| 680 |
pfLns.append(" numCellPoints = oneCell.GetNumberOfPoints()\n") |
| 681 |
pfLns.append(" for jj in range(0, numCellPoints):\n") |
| 682 |
pfLns.append(" oneCellPointId = cellPointIds.GetId(jj)\n") |
| 683 |
pfLns.append(" cellsTouchingPointCount[oneCellPointId] += 1\n") |
| 684 |
pfLns.append(" return cellsTouchingPointCount\n") |
| 685 |
pfLns.append("def PhactoriSurfaceCornerCellFaceFacesExterior(oneFace, cellsTouchingPointCount):\n") |
| 686 |
pfLns.append(" numFacePoints = oneFace.GetNumberOfPoints()\n") |
| 687 |
pfLns.append(" facePointIds = oneFace.GetPointIds()\n") |
| 688 |
pfLns.append(" numOutsideVertices = 0\n") |
| 689 |
pfLns.append(" for ii in range(0, numFacePoints):\n") |
| 690 |
pfLns.append(" if cellsTouchingPointCount[facePointIds.GetId(ii)] <= 1:\n") |
| 691 |
pfLns.append(" return True\n") |
| 692 |
pfLns.append(" return False\n") |
| 693 |
pfLns.append("def PhactoriIsOutsideCornerHexCellFaceMaxAreaFace(oneCell, indexFaceListSize,\n") |
| 694 |
pfLns.append(" sortedFaceSizeList, cellsTouchingPointCount, TestNthLargestFace = 2):\n") |
| 695 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 696 |
pfLns.append(" for faceIndex in range(0, numFaces):\n") |
| 697 |
pfLns.append(" oneFace = oneCell.GetFace(faceIndex)\n") |
| 698 |
pfLns.append(" if PhactoriSurfaceCornerCellFaceFacesExterior(oneFace, cellsTouchingPointCount):\n") |
| 699 |
pfLns.append(" if indexFaceListSize[faceIndex] >= sortedFaceSizeList[-TestNthLargestFace]:\n") |
| 700 |
pfLns.append(" return True\n") |
| 701 |
pfLns.append(" return False\n") |
| 702 |
pfLns.append("def PhactoriSurfaceEdgeHexCellFaceFacesExterior(oneFace, cellsTouchingPointCount):\n") |
| 703 |
pfLns.append(" numFacePoints = oneFace.GetNumberOfPoints()\n") |
| 704 |
pfLns.append(" facePointIds = oneFace.GetPointIds()\n") |
| 705 |
pfLns.append(" numOutsideVertices = 0\n") |
| 706 |
pfLns.append(" for ii in range(0, numFacePoints):\n") |
| 707 |
pfLns.append(" if cellsTouchingPointCount[facePointIds.GetId(ii)] <= 2:\n") |
| 708 |
pfLns.append(" numOutsideVertices += 1\n") |
| 709 |
pfLns.append(" return (numOutsideVertices >= 2)\n") |
| 710 |
pfLns.append("def PhactoriIsOutsideEdgeHexCellFaceMaxAreaFace(oneCell,\n") |
| 711 |
pfLns.append(" indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount,\n") |
| 712 |
pfLns.append(" TestNthLargestFace = 2):\n") |
| 713 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 714 |
pfLns.append(" for faceIndex in range(0, numFaces):\n") |
| 715 |
pfLns.append(" oneFace = oneCell.GetFace(faceIndex)\n") |
| 716 |
pfLns.append(" if PhactoriSurfaceEdgeHexCellFaceFacesExterior(oneFace, cellsTouchingPointCount):\n") |
| 717 |
pfLns.append(" if indexFaceListSize[faceIndex] >= sortedFaceSizeList[-TestNthLargestFace]:\n") |
| 718 |
pfLns.append(" return True\n") |
| 719 |
pfLns.append(" return False\n") |
| 720 |
pfLns.append("def PhactoriIsOutsideSurfaceHexCellFaceMaxAreaFace(oneCell,\n") |
| 721 |
pfLns.append(" indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount,\n") |
| 722 |
pfLns.append(" TestNthLargestFace = 2):\n") |
| 723 |
pfLns.append(" numFaces = oneCell.GetNumberOfFaces()\n") |
| 724 |
pfLns.append(" for faceIndex in range(0, numFaces):\n") |
| 725 |
pfLns.append(" oneFace = oneCell.GetFace(faceIndex)\n") |
| 726 |
pfLns.append(" numFacePoints = oneFace.GetNumberOfPoints()\n") |
| 727 |
pfLns.append(" facePtNdxs = oneFace.GetPointIds()\n") |
| 728 |
pfLns.append(" outsideFaceIndex = -1\n") |
| 729 |
pfLns.append(" for jj in range(0, numFacePoints):\n") |
| 730 |
pfLns.append(" outsideFaceIndex = faceIndex\n") |
| 731 |
pfLns.append(" ptNdx = facePtNdxs.GetId(jj)\n") |
| 732 |
pfLns.append(" if cellsTouchingPointCount[ptNdx] != 4:\n") |
| 733 |
pfLns.append(" outsideFaceIndex = -1\n") |
| 734 |
pfLns.append(" break\n") |
| 735 |
pfLns.append(" if outsideFaceIndex >= 0:\n") |
| 736 |
pfLns.append(" break\n") |
| 737 |
pfLns.append(" if outsideFaceIndex < 0:\n") |
| 738 |
pfLns.append(" return False\n") |
| 739 |
pfLns.append(" if indexFaceListSize[outsideFaceIndex] >= sortedFaceSizeList[-TestNthLargestFace]:\n") |
| 740 |
pfLns.append(" return True\n") |
| 741 |
pfLns.append(" else:\n") |
| 742 |
pfLns.append(" return False\n") |
| 743 |
pfLns.append("def PhactoriFindSurfaceStatusForOneCellUsingFaceInfo(inInputCsData,\n") |
| 744 |
pfLns.append(" inCellIndex, countCellsTouchingEachFace, flatnessTestRatio = 100.0,\n") |
| 745 |
pfLns.append(" TestNthLargestFace = 2):\n") |
| 746 |
pfLns.append(" oneCell = inInputCsData.GetCell(inCellIndex)\n") |
| 747 |
pfLns.append(" exteriorFaceList = countCellsTouchingEachFace.GetListOfExteriorFacesOnCell(oneCell)\n") |
| 748 |
pfLns.append(" numExteriorFaces = len(exteriorFaceList)\n") |
| 749 |
pfLns.append(" if numExteriorFaces == 0:\n") |
| 750 |
pfLns.append(" retStatus = 1\n") |
| 751 |
pfLns.append(" else:\n") |
| 752 |
pfLns.append(" indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell)\n") |
| 753 |
pfLns.append(" flatnessRatio = sortedFaceSizeList[-1] / sortedFaceSizeList[0]\n") |
| 754 |
pfLns.append(" if len(sortedFaceSizeList) <= 0:\n") |
| 755 |
pfLns.append(" retStatus = 11\n") |
| 756 |
pfLns.append(" return retStatus\n") |
| 757 |
pfLns.append(" cellIsFlat = (flatnessRatio >= flatnessTestRatio)\n") |
| 758 |
pfLns.append(" outsideFaceIsMaxAreaFace = False\n") |
| 759 |
pfLns.append(" for outsideFaceIndex in exteriorFaceList:\n") |
| 760 |
pfLns.append(" if indexFaceListSize[outsideFaceIndex] >= sortedFaceSizeList[-TestNthLargestFace]:\n") |
| 761 |
pfLns.append(" outsideFaceIsMaxAreaFace = True\n") |
| 762 |
pfLns.append(" break\n") |
| 763 |
pfLns.append(" if numExteriorFaces == 1:\n") |
| 764 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 765 |
pfLns.append(" if cellIsFlat:\n") |
| 766 |
pfLns.append(" retStatus = 11\n") |
| 767 |
pfLns.append(" else:\n") |
| 768 |
pfLns.append(" retStatus = 8\n") |
| 769 |
pfLns.append(" else:\n") |
| 770 |
pfLns.append(" if cellIsFlat:\n") |
| 771 |
pfLns.append(" retStatus = 5\n") |
| 772 |
pfLns.append(" else:\n") |
| 773 |
pfLns.append(" retStatus = 2\n") |
| 774 |
pfLns.append(" elif numExteriorFaces == 2:\n") |
| 775 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 776 |
pfLns.append(" if cellIsFlat:\n") |
| 777 |
pfLns.append(" retStatus = 12\n") |
| 778 |
pfLns.append(" else:\n") |
| 779 |
pfLns.append(" retStatus = 9\n") |
| 780 |
pfLns.append(" else:\n") |
| 781 |
pfLns.append(" if cellIsFlat:\n") |
| 782 |
pfLns.append(" retStatus = 6\n") |
| 783 |
pfLns.append(" else:\n") |
| 784 |
pfLns.append(" retStatus = 3\n") |
| 785 |
pfLns.append(" else:\n") |
| 786 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 787 |
pfLns.append(" if cellIsFlat:\n") |
| 788 |
pfLns.append(" retStatus = 13\n") |
| 789 |
pfLns.append(" else:\n") |
| 790 |
pfLns.append(" retStatus = 10\n") |
| 791 |
pfLns.append(" else:\n") |
| 792 |
pfLns.append(" if cellIsFlat:\n") |
| 793 |
pfLns.append(" retStatus = 7\n") |
| 794 |
pfLns.append(" else:\n") |
| 795 |
pfLns.append(" retStatus = 4\n") |
| 796 |
pfLns.append(" return retStatus\n") |
| 797 |
pfLns.append("def PhactoriFindSurfaceStatusForOneCell(inInputCsData, inCellIndex,\n") |
| 798 |
pfLns.append(" cellsTouchingPointCount, flatnessTestRatio = 100.0):\n") |
| 799 |
pfLns.append(" oneCell = inInputCsData.GetCell(inCellIndex)\n") |
| 800 |
pfLns.append(" numPoints = oneCell.GetNumberOfPoints()\n") |
| 801 |
pfLns.append(" pointIds = oneCell.GetPointIds()\n") |
| 802 |
pfLns.append(" minCtpc = 9\n") |
| 803 |
pfLns.append(" for ii in range(0, numPoints):\n") |
| 804 |
pfLns.append(" testCtpc = cellsTouchingPointCount[pointIds.GetId(ii)]\n") |
| 805 |
pfLns.append(" if testCtpc < minCtpc:\n") |
| 806 |
pfLns.append(" minCtpc = testCtpc\n") |
| 807 |
pfLns.append(" if inCellIndex == 5056:\n") |
| 808 |
pfLns.append(" debugFlag = 100\n") |
| 809 |
pfLns.append(" else:\n") |
| 810 |
pfLns.append(" debugFlag = 25\n") |
| 811 |
pfLns.append(" if minCtpc >= 8:\n") |
| 812 |
pfLns.append(" retStatus = 1\n") |
| 813 |
pfLns.append(" else:\n") |
| 814 |
pfLns.append(" indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell)\n") |
| 815 |
pfLns.append(" flatnessRatio = sortedFaceSizeList[-1] / sortedFaceSizeList[0]\n") |
| 816 |
pfLns.append(" if len(sortedFaceSizeList) <= 0:\n") |
| 817 |
pfLns.append(" retStatus = 11\n") |
| 818 |
pfLns.append(" return retStatus\n") |
| 819 |
pfLns.append(" cellIsFlat = (flatnessRatio >= flatnessTestRatio)\n") |
| 820 |
pfLns.append(" if minCtpc >= 4:\n") |
| 821 |
pfLns.append(" outsideFaceIsMaxAreaFace = PhactoriIsOutsideSurfaceHexCellFaceMaxAreaFace(\n") |
| 822 |
pfLns.append(" oneCell, indexFaceListSize, sortedFaceSizeList,\n") |
| 823 |
pfLns.append(" cellsTouchingPointCount)\n") |
| 824 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 825 |
pfLns.append(" if cellIsFlat:\n") |
| 826 |
pfLns.append(" retStatus = 11\n") |
| 827 |
pfLns.append(" else:\n") |
| 828 |
pfLns.append(" retStatus = 8\n") |
| 829 |
pfLns.append(" else:\n") |
| 830 |
pfLns.append(" if cellIsFlat:\n") |
| 831 |
pfLns.append(" retStatus = 5\n") |
| 832 |
pfLns.append(" else:\n") |
| 833 |
pfLns.append(" retStatus = 2\n") |
| 834 |
pfLns.append(" elif minCtpc >= 2:\n") |
| 835 |
pfLns.append(" outsideFaceIsMaxAreaFace = PhactoriIsOutsideEdgeHexCellFaceMaxAreaFace(\n") |
| 836 |
pfLns.append(" oneCell, indexFaceListSize, sortedFaceSizeList,\n") |
| 837 |
pfLns.append(" cellsTouchingPointCount)\n") |
| 838 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 839 |
pfLns.append(" if cellIsFlat:\n") |
| 840 |
pfLns.append(" retStatus = 12\n") |
| 841 |
pfLns.append(" else:\n") |
| 842 |
pfLns.append(" retStatus = 9\n") |
| 843 |
pfLns.append(" else:\n") |
| 844 |
pfLns.append(" if cellIsFlat:\n") |
| 845 |
pfLns.append(" retStatus = 6\n") |
| 846 |
pfLns.append(" else:\n") |
| 847 |
pfLns.append(" retStatus = 3\n") |
| 848 |
pfLns.append(" elif minCtpc >= 1:\n") |
| 849 |
pfLns.append(" outsideFaceIsMaxAreaFace = PhactoriIsOutsideCornerHexCellFaceMaxAreaFace(\n") |
| 850 |
pfLns.append(" oneCell, indexFaceListSize, sortedFaceSizeList, cellsTouchingPointCount)\n") |
| 851 |
pfLns.append(" if outsideFaceIsMaxAreaFace:\n") |
| 852 |
pfLns.append(" if cellIsFlat:\n") |
| 853 |
pfLns.append(" retStatus = 13\n") |
| 854 |
pfLns.append(" else:\n") |
| 855 |
pfLns.append(" retStatus = 10\n") |
| 856 |
pfLns.append(" else:\n") |
| 857 |
pfLns.append(" if cellIsFlat:\n") |
| 858 |
pfLns.append(" retStatus = 7\n") |
| 859 |
pfLns.append(" else:\n") |
| 860 |
pfLns.append(" retStatus = 4\n") |
| 861 |
pfLns.append(" else:\n") |
| 862 |
pfLns.append(" retStatus = -1\n") |
| 863 |
pfLns.append(" return retStatus\n") |
| 864 |
pfLns.append("def PhactoriGetCellEdgeVector(inInputCsData, oneFaceOrCell, edgeIndex):\n") |
| 865 |
pfLns.append(" oneFaceEdgePointIds = oneFaceOrCell.GetEdge(edgeIndex).GetPointIds()\n") |
| 866 |
pfLns.append(" ptA = inInputCsData.GetPoint(oneFaceEdgePointIds.GetId(0))\n") |
| 867 |
pfLns.append(" ptB = inInputCsData.GetPoint(oneFaceEdgePointIds.GetId(1))\n") |
| 868 |
pfLns.append(" retVec = vecFromAToB(ptA,ptB)\n") |
| 869 |
pfLns.append(" return retVec\n") |
| 870 |
pfLns.append("def PhactoriFindFaceNormal(inInputCsData, oneFace):\n") |
| 871 |
pfLns.append(" facePointIds = oneFace.GetPointIds()\n") |
| 872 |
pfLns.append(" ptA = inInputCsData.GetPoint(facePointIds.GetId(0))\n") |
| 873 |
pfLns.append(" ptB = inInputCsData.GetPoint(facePointIds.GetId(1))\n") |
| 874 |
pfLns.append(" ptC = inInputCsData.GetPoint(facePointIds.GetId(2))\n") |
| 875 |
pfLns.append(" vecAB = vecFromAToB(ptA, ptB)\n") |
| 876 |
pfLns.append(" vecBC = vecFromAToB(ptB, ptC)\n") |
| 877 |
pfLns.append(" retNormalVec = vecCrossProduct(vecBC, vecAB)\n") |
| 878 |
pfLns.append(" vecNormalize2(retNormalVec, retNormalVec)\n") |
| 879 |
pfLns.append(" return retNormalVec\n") |
| 880 |
pfLns.append("def PhactoriFindLargestCellFaceNormal(inInputCsData, oneCell):\n") |
| 881 |
pfLns.append(" indexFaceListSize, sortedFaceSizeList = PhactoriCalculateCellFaceAreasAndSort(inInputCsData, oneCell)\n") |
| 882 |
pfLns.append(" biggestFaceSize = sortedFaceSizeList[-1]\n") |
| 883 |
pfLns.append(" for faceForNormalIndex in range(0, len(indexFaceListSize)):\n") |
| 884 |
pfLns.append(" if indexFaceListSize[faceForNormalIndex] == biggestFaceSize:\n") |
| 885 |
pfLns.append(" break\n") |
| 886 |
pfLns.append(" faceForNormal = oneCell.GetFace(faceForNormalIndex)\n") |
| 887 |
pfLns.append(" retNormalVec = PhactoriFindFaceNormal(inInputCsData, faceForNormal)\n") |
| 888 |
pfLns.append(" return retNormalVec\n") |
| 889 |
pfLns.append("def PhactoriFindSelectedAngleBetweenEdgeAndCellNormal(inInputCsData, oneCell,\n") |
| 890 |
pfLns.append(" compareNormal, paramUseSmallestAngle, paramOffsetIndex):\n") |
| 891 |
pfLns.append(" edgeCompareDotProdList = []\n") |
| 892 |
pfLns.append(" numEdges = oneCell.GetNumberOfEdges()\n") |
| 893 |
pfLns.append(" for ii in range(0, numEdges):\n") |
| 894 |
pfLns.append(" oneEdgeVec = PhactoriGetCellEdgeVector(inInputCsData, oneCell, ii)\n") |
| 895 |
pfLns.append(" vecNormalize2(oneEdgeVec, oneEdgeVec)\n") |
| 896 |
pfLns.append(" edgeCompareDotProd = abs(vecDotProduct(compareNormal, oneEdgeVec))\n") |
| 897 |
pfLns.append(" edgeCompareDotProdList.append(edgeCompareDotProd)\n") |
| 898 |
pfLns.append(" sortedEdgeCompareDotProdList = sorted(edgeCompareDotProdList)\n") |
| 899 |
pfLns.append(" if paramUseSmallestAngle:\n") |
| 900 |
pfLns.append(" outputIndex = max(0, numEdges - 1 - paramOffsetIndex)\n") |
| 901 |
pfLns.append(" else:\n") |
| 902 |
pfLns.append(" outputIndex = min(paramOffsetIndex, numEdges - 1)\n") |
| 903 |
pfLns.append(" outputAngle = 90.0 - math.degrees(math.acos(sortedEdgeCompareDotProdList[outputIndex]))\n") |
| 904 |
pfLns.append(" return outputAngle\n") |
| 905 |
pfLns.append("def PhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal):\n") |
| 906 |
pfLns.append(" numCellEdges = oneCell.GetNumberOfEdges()\n") |
| 907 |
pfLns.append(" retHeight = -1.0 \n") |
| 908 |
pfLns.append(" for ii in range(0, numCellEdges):\n") |
| 909 |
pfLns.append(" oneCellEdgeVec = PhactoriGetCellEdgeVector(inInputCsData, oneCell, ii)\n") |
| 910 |
pfLns.append(" dp1 = vecDotProduct(oneCellEdgeVec, compareNormal)\n") |
| 911 |
pfLns.append(" projectedVec = vecScale(dp1, compareNormal)\n") |
| 912 |
pfLns.append(" oneCellEdgeHeight = vecMagnitude(projectedVec)\n") |
| 913 |
pfLns.append(" if oneCellEdgeHeight > retHeight:\n") |
| 914 |
pfLns.append(" retHeight = oneCellEdgeHeight\n") |
| 915 |
pfLns.append(" return retHeight\n") |
| 916 |
pfLns.append("def PhactoriFindCellEdgeAngleMetricsForOneCell(inInputCsData, inCellIndex,\n") |
| 917 |
pfLns.append(" paramUseSmallestAngle, paramOffsetIndex):\n") |
| 918 |
pfLns.append(" oneCell = inInputCsData.GetCell(inCellIndex)\n") |
| 919 |
pfLns.append(" numEdges = oneCell.GetNumberOfEdges()\n") |
| 920 |
pfLns.append(" if numEdges < 6:\n") |
| 921 |
pfLns.append(" return 90.0, 0.0\n") |
| 922 |
pfLns.append(" if oneCell.GetNumberOfFaces() < 4:\n") |
| 923 |
pfLns.append(" return 90.0, 0.0\n") |
| 924 |
pfLns.append(" compareNormal = PhactoriFindLargestCellFaceNormal(inInputCsData, oneCell)\n") |
| 925 |
pfLns.append(" retAngle = PhactoriFindSelectedAngleBetweenEdgeAndCellNormal(inInputCsData,\n") |
| 926 |
pfLns.append(" oneCell, compareNormal, paramUseSmallestAngle, paramOffsetIndex)\n") |
| 927 |
pfLns.append(" retHeight = PhactoriFindHeightOfCell(inInputCsData, oneCell, compareNormal)\n") |
| 928 |
pfLns.append(" return retAngle, retHeight\n") |
| 929 |
|
| 930 |
#phactori_combine_to_single_python_file_subpiece_end_1 |
| 931 |
|