Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PipeGeom:
- @staticmethod
- def GetPipeDiameter(elementid):
- """
- Get Diameter by circular face
- Args: elementid
- Return: Diameter(number) in meter
- """
- if not ("segment" in str(GetObjectByElementId(elementid).ElementData["elementtype"]).lower()):
- print "expected segment, got "+ GetObjectByElementId(elementid).ElementData["elementtype"]
- return None
- diameter = 0
- circleFaces = PipeGeom.GetCircularFaces(elementid)
- if circleFaces:
- for i in circleFaces:
- if i['centroid'] is not None:
- cntrPnt = i['centroid']
- outerPnt = i['face'].OuterVertices[0]
- currDiam = (LineSegment3D(cntrPnt, outerPnt).extent) * 2
- # GET THE SMALLEST DIAMETER. POSSIBLE THAT 1 PIPE HAVE DIFFERENT CIRCLE FACE
- if diameter == 0:
- diameter = currDiam
- else:
- if currDiam < diameter:
- diameter = currDiam
- else:
- faceP = i['face']
- if type(faceP) == Polyhedron:
- # GET DIAMETER: BY GETTING THE LONGESTLINE IN BROKEN FACES
- # 2 POINTS NEAR HIGHPOS AND LOWPOS OF faceP.boundingBox
- highPnt = faceP.boundingBox.LLB
- lowPnt = faceP.boundingBox.URT
- pnt1 = Point3D()
- pnt2 = Point3D()
- nearDist1 = sys.float_info.epsilon
- nearDist2 = sys.float_info.epsilon
- pntL = faceP.Vertices
- for pnt in pntL:
- currDist1 = Point3D().sqDistance(pnt, highPnt)
- currDist2 = Point3D().sqDistance(pnt, lowPnt)
- if nearDist1 == sys.float_info.epsilon:
- nearDist1 = currDist1
- else:
- if nearDist1 > currDist1:
- nearDist1 = currDist1
- pnt1 = pnt
- if nearDist2 == sys.float_info.epsilon:
- nearDist2 = currDist2
- else:
- if nearDist2 > currDist2:
- nearDist2 = currDist2
- pnt2 = pnt
- diameter = Point3D().distance(pnt1, pnt2)
- return diameter
- @staticmethod
- def GetCircularFaces(elementid):
- """
- Get circular face using IsFaceCircular API or using broken faces near portlocation (alternative solution)
- Args: elementid
- Return: List["face":(Face3D), "centroid":(Point3D)]
- """
- query = """SELECT topo.polygon, topo.centroid, port.connectingportlocation
- FROM bimrl_topo_face topo, bimrl_relconnection port
- WHERE topo.elementid = '{0}' AND topo.type = 'BODY'
- AND topo.elementid = port.connectingelementid""".format(elementid)
- qResult = FXBIMRL.GetJsonObjFromQuery(query)
- if qResult is None: return None
- circleFaces = []
- # GET CIRCULAR FACE USING IsFaceCircular API
- circleFaces = filter(lambda x: FXGeometry.IsFaceCircular(FXGeometry.CreatePolygonFace(x["polygon"]), 0.1), qResult["Table1"])
- if len(circleFaces) > 0:
- circleFaces = map(lambda x: {
- "face": FXGeometry.CreatePolygonFace(x["polygon"]),
- "centroid": Point3D(x["centroid"]["X"], x["centroid"]["Y"], x["centroid"]["Z"]) },
- circleFaces)
- return circleFaces
- # GET CIRCULAR FACE USING BROKEN FACES NEAR PORTLOCATION (ALTERNATIVE SOLUTION)
- faceL = List[Face3D]()
- portL = []
- for row in qResult["Table1"]:
- face = FXGeometry.CreatePolygonFace(row["polygon"])
- faceL.Add(face)
- portL.append(Point3D(row["connectingportlocation"]["X"], row["connectingportlocation"]["Y"], row["connectingportlocation"]["Z"]))
- faceNearPort = {}
- portL = list(set(portL))
- # GET FACES NEAR PORTLOCATION
- for face in faceL:
- portNearFace = None
- centerPnt = face.boundingBox.Center
- distTemp = sys.float_info.epsilon
- for port in portL:
- currDist = Point3D().sqDistance(port, centerPnt)
- if distTemp == sys.float_info.epsilon:
- distTemp = currDist
- portNearFace = port
- else:
- if distTemp > currDist:
- distTemp = currDist
- portNearFace = port
- if portNearFace:
- if faceNearPort.get(portNearFace) is None:
- tempL = []
- faceNearPort[portNearFace] = tempL
- faceNearPort[portNearFace].append(face)
- for port, faceL in faceNearPort.items():
- # SORT BY FACES NORMAL
- faceDict = {}
- for face in faceL:
- fNormal = round(face.basePlane.normalVector.Z,1)
- if faceDict.get(fNormal) is None:
- tempL = []
- faceDict[fNormal] = tempL
- faceDict[fNormal].append(face)
- # GET THE NORMAL WITH MANY FACES
- maxCntFace = 0
- maxFaceL = List[Face3D]()
- for _, faces in faceDict.iteritems():
- if maxCntFace < len(faces):
- maxCntFace = len(faces)
- for face in faces:
- maxFaceL.Add(face)
- lastFacePoly = Polyhedron(maxFaceL)
- if lastFacePoly.IsSolid:
- circleFaces.append(
- { "face": lastFacePoly, "centroid": None })
- break
- return circleFaces
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement