def __init__(self,
                 firstPrim,
                 lastPrim,
                 partDes,
                 refPrim,
                 minimum=True,
                 aperture=150,
                 volume=None,
                 DEBUG=False):

        # Convert all in InfoPathPrims
        indexFirst = partDes.index(firstPrim.prim)
        indexLast = partDes.index(lastPrim.prim)

        self.firstPrim = firstPrim
        self.lastPrim = lastPrim
        self.partDes = InfoPathPrim.convertListIntoInfoPrim(partDes)
        self.partDes[indexFirst] = firstPrim
        self.partDes[indexLast] = lastPrim
        self.refPrim = InfoPathPrim.InfoPathPrim(refPrim)
        self.minimum = minimum
        self.aperture = aperture
        self.volume = volume
        self.DEBUG = DEBUG
Beispiel #2
0
 def getExtremPrims(self,
                    Ipoint,
                    primOfIpoint,
                    partDes,
                    refPrim,
                    notDes,
                    volume=None):
     '''
     We can't ensure that the primitives have a posible path, but we ensure that last primitive
     have at least 2 adjacent primitives and first primitive is connected with the last primitive
     '''
     logging.debug("Start method getExtremPrims, class DefPath")
     firstPrim = None
     lastPrim = None
     if (primOfIpoint and Ipoint):
         # NOT YET TOTALLY IMPLEMENTED
         edge = GeoMath.getEdgeWithPointInPrim(primOfIpoint, Ipoint)
         lastPrim = primOfIpoint
         for prim in partDes:
             if (prim != lastPrim):
                 sharedEdges = GeoMath.getSharedEdgesPrims(lastPrim, prim)
                 rs_lP_fP = False
                 if (volume):
                     for edge in sharedEdges:
                         rs = RejectionSampling.RejectionSampling(
                             edge, volume)
                         rs.do()
                         point = rs.getValue()
                         if (point):
                             rs_lP_fP = True
                             break
                 if (len(sharedEdges >= 1) and (edge in sharedEdges)
                         and (volume == None or rs_lP_fP)):
                     firstPrim = prim
     else:
         # Automatically decision of extrem prims.
         # Ensure that 2 prims is connected to another primitive in
         # group of partially destroyed.
         # Didn't use "getConnectedPrims" because need ramdonless in choice of prims.
         stopSearch = False
         tempList1 = list(partDes)
         # minimum of 4 prims to get a path
         while (len(tempList1) > 4 and not stopSearch):
             numPrim1 = random.randint(0, len(tempList1) - 1)
             prim1 = tempList1[numPrim1]
             del tempList1[numPrim1]
             # We have to ensure that first prim has at least two conected prims
             if (True):  # prim1.number()>17 and prim1.number()<27
                 while (
                     (len(GeoMath.getConnectedPrims(prim1, list(partDes),
                                                    2)) < 2)
                         and (len(tempList1) > 4)):
                     numPrim1 = random.randint(0, len(tempList1) - 1)
                     prim1 = tempList1[numPrim1]
                     del tempList1[numPrim1]
                 # If prim1 has at least two conected prims
                 if (len(tempList1) > 4):
                     conectedToPrim1 = GeoMath.getConnectedPrims(
                         prim1, list(tempList1))
                     while (len(conectedToPrim1) > 0 and not stopSearch):
                         numPrim2 = random.randint(0,
                                                   len(conectedToPrim1) - 1)
                         prim2 = conectedToPrim1[numPrim2]
                         if (prim2 != prim1):
                             # If prim2 has at least 2 conected prims
                             if (len(
                                     GeoMath.getConnectedPrims(
                                         prim2, list(tempList1), 2)) >= 2):
                                 stopSearch = True
                                 if (volume):
                                     rs_lP_fP = False
                                     for edge in GeoMath.getEdgesBetweenPrims(
                                             prim1, prim2):
                                         logging.debug(
                                             "Edge: %s", str(edge))
                                         rs = RejectionSampling.RejectionSampling(
                                             edge, volume)
                                         rs.do()
                                         point = rs.getValue()
                                         if (point):
                                             rs_lP_fP = True
                                             break
                                     if (not rs_lP_fP):
                                         stopSearch = False
                                 if (stopSearch):
                                     # Assign the last evaluate because we have it now in a variable.
                                     firstPrim = InfoPathPrim.InfoPathPrim(
                                         prim2)
                                     # Last prim sure has two adjacent primitives.
                                     lastPrim = InfoPathPrim.InfoPathPrim(
                                         prim1)
                                     firstPrim.setiPoint(list(point))
                                     lastPrim.setfPoint(list(point))
                         del conectedToPrim1[numPrim2]
         if (firstPrim and lastPrim):
             logging.debug(
                 "End method getExtremPrims, class DefPath. State: good")
         else:
             logging.debug(
                 "End method getExtremPrims, class DefPath. State: no extrem prims"
             )
         return firstPrim, lastPrim