示例#1
0
    def __init__(self, firstPrim, lastPrim, partDes, totDes, volume=None, max_iterations=None):
        global DEBUG
        if(DEBUG):
            reload(GeoMath)
            reload(InfoPathPrim)
        self.volume = volume
        #Convert all in InfoPathPrims
        indexFirst = partDes.index(firstPrim.prim)
        indexLast = partDes.index(lastPrim.prim)
        infoPartDes = InfoPathPrim.convertListIntoInfoPrim(partDes)
        infoTotDes = InfoPathPrim.convertListIntoInfoPrim(totDes)
        infoPartDes[indexFirst] = firstPrim
        infoPartDes[indexLast] = lastPrim
        firstInfoPrim = firstPrim
        lastInfoPrim = lastPrim

        self.firstPrim = firstInfoPrim
        self.lastPrim = lastInfoPrim
        self.partDes = infoPartDes
        self.totDes = infoTotDes
        self.clockwise = False
        self.goodPath = False
        self.path = []
        self.max_iterations_exceeded = False
        self.currentIteration = 0
        if(max_iterations):
            self.max_interations = max_iterations
        else:
            self.auto_choose_max_iterations()
示例#2
0
 def showCrack(self, node, groupOfInfoPrimsOrdered, allInOne):
     groupOfPrimsOrdered = InfoPathPrim.convertListFromInfoPrimToPrim(groupOfInfoPrimsOrdered)
     for countPrim in range(len(groupOfPrimsOrdered)):
         pointsString = ""
         prim = groupOfPrimsOrdered[countPrim]
         if(allInOne):
             crackNode = node.createNode('curve', 'crack_patternPrim_' + str(prim.number()))
             if(prim in self.linePerPrim):
                 listOfPoints = self.linePerPrim[prim]
             for point in listOfPoints:
                 pointsString = pointsString + str(point[0]) + "," + str(point[1]) + "," + str(point[2]) + " "
             crackNode.parm('coords').set(pointsString)
             crackNode.moveToGoodPosition()
             crackNode.setTemplateFlag(True)
             self.showCrackNodes.append(crackNode)
         else:
             count = 0
             if(prim in self.patternCrack):
                 for patt in self.patternCrack[prim]:
                 # Show crack
                     crackNode = node.createNode('curve', 'crack_pattern_' + str(prim.number()) + "_" + str(count))
                     pointsString = ""
                     for point in patt.getPoints():
                         pointsString = pointsString + str(point[0]) + "," + str(point[1]) + "," + str(point[2]) + " "
                     crackNode.parm('coords').set(pointsString)
                     crackNode.moveToGoodPosition()
                     crackNode.setTemplateFlag(True)
                     self.showCrackNodes.append(crackNode)
                     count += 1
示例#3
0
 def getPathAstar(self,
                  firstPrim,
                  lastPrim,
                  notDes,
                  partDes,
                  totDes,
                  refPrim,
                  minimum=True,
                  aperture=150,
                  volume=None,
                  DEBUG=False):
     p = PathAstar.PathAstar(firstPrim, lastPrim, partDes, refPrim, minimum,
                             aperture, volume)
     p.do()
     if (len(p.path) > 3):
         if (ValidatePath.ValidatePath(
                 notDes, partDes, totDes,
                 InfoPathPrim.convertListFromInfoPrimToPrim(
                     p.path)).getisValid()):
             logging.debug(
                 "End method getPathBackTracking, class DefPath. State: good"
             )
             goodPath = True
         else:
             logging.debug("Path have not closure around totally destroyed")
             goodPath = False
     else:
         logging.error("No path")
         logging.debug(
             "End method getPathBackTracking, class DefPath. State: path < 4"
         )
         goodPath = False
     return p.getPath(), goodPath
示例#4
0
 def doLineCrackPerPrim(self, groupOfInfoPrimsOrdered):
     groupOfPrimsOrdered = InfoPathPrim.convertListFromInfoPrimToPrim(groupOfInfoPrimsOrdered)
     for prim in groupOfPrimsOrdered:
         self.linePerPrim[prim] = []
         if(prim in self.patternCrack):
             for patt in self.patternCrack[prim]:
                 for point in patt.getPoints():
                         self.linePerPrim[prim].append(point)
示例#5
0
 def getPathAstar(self, firstPrim, lastPrim, notDes, partDes, totDes, refPrim, minimum=True, aperture=150, volume=None, DEBUG=False):
     p = PathAstar.PathAstar(firstPrim, lastPrim, partDes, refPrim, minimum, aperture, volume)
     p.do()
     if(len(p.path) > 3):
         if(ValidatePath.ValidatePath(notDes, partDes, totDes, InfoPathPrim.convertListFromInfoPrimToPrim(p.path)).getisValid()):
             logging.debug("End method getPathBackTracking, class DefPath. State: good")
             goodPath = True
         else:
             logging.debug("Path have not closure around totally destroyed")
             goodPath = False
     else:
         logging.error("No path")
         logging.debug("End method getPathBackTracking, class DefPath. State: path < 4")
         goodPath = False
     return p.getPath(), goodPath
    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
    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
示例#8
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
示例#9
0
 def getPathInPrims(self):
     return InfoPathPrim.convertListFromInfoPrimToPrim(self.path)
示例#10
0
 def getPathInPrims(self):
     return InfoPathPrim.convertListFromInfoPrimToPrim(self.path)
示例#11
0
    def backTracking(self, curPrim, path):
        global TimeExecutionFirst
        global TimeExecutionCurrent
        global MAXTIMEFORONEPATH
        global DEBUG
        logging.debug("Start method backTracking, class PathBackTracking")
        logging.debug("Current prim from parm: %s", str(curPrim.prim.number()))

        conPrims = GeoMath.getConnectedInfoPrims(curPrim, self.partDes)
        indexPrims = 0
        pathAchieved = False
        startPoint = None
        max_iterations_exceeded = False
        while (not pathAchieved and indexPrims < len(conPrims) and not max_iterations_exceeded):
            logging.debug("Current iteration: " + str(self.currentIteration))
            self.currentIteration += 1
            nextPrim = conPrims[indexPrims]
            #Now, choose the best prim reference
            refPrim = self.getBestPrimReference(curPrim)
            logging.debug("Current prim: %s. Next prim: %s", str(curPrim.prim.number()), str(nextPrim.prim.number()))
            logging.debug("Conected prims: %s. Count: %s", str([p.prim.number() for p in conPrims]), str(indexPrims))
            logging.debug("Reference prim: %s", str(refPrim.prim.number()))
            if(nextPrim not in path):
                if(self.volume):
                    edges = GeoMath.getEdgesBetweenPrims(curPrim.prim, nextPrim.prim)
                    for edge in edges:
                        rs = RejectionSampling.RejectionSampling(edge, self.volume)
                        rs.do()
                        startPoint = rs.getValue()
                        if(startPoint):
                            break
                logging.debug("Inicial point: %s", str(startPoint))

                if(startPoint):
                    angleMin, angleMax = GeoMath.getMinMaxAngleBetweenPointsInPrim(curPrim.prim, nextPrim.prim, refPrim.prim)
                    logging.debug("Current prim: %s. Next prim: s", str(curPrim.prim.number()), str(nextPrim.prim.number()))
                    logging.debug("Min angle: %s. Max angle: %s", str(angleMin), str(angleMax))
                    if(self.clockWise and (angleMin > 0 or angleMin < -(math.pi - math.pi * 0.1))):

                        logging.debug("ignorada por clockwise y revolverse")

                    if(not self.clockWise and (angleMax < 0 and angleMax < (math.pi - math.pi * 0.1))):

                        logging.debug("ignorada por not clockwise y revolverse")


                    if(nextPrim == self.lastPrim and curPrim.sumAngle < (1.4 * math.pi)):

                        logging.debug("ignorada por ultima y angulo no suficiente")


                    if((nextPrim == self.lastPrim and curPrim.sumAngle > (1.4 * math.pi))):

                        logging.debug("aceptada por ultima y angulo suficiente")




                    if((not((self.clockWise and (angleMin > 0 or angleMin < -(math.pi - math.pi * 0.01))) or \
                           (not self.clockWise and (angleMax < 0 or angleMax > (math.pi - math.pi * 0.01))) or \
                           (nextPrim == self.lastPrim and curPrim.sumAngle < (1.4 * math.pi))) or \
                           (nextPrim == self.lastPrim and curPrim.sumAngle > (1.4 * math.pi)))):

                        ch = CalculateHeuristic.CalculateHeuristic(curPrim, nextPrim, refPrim)
                        ch.do()
                        curPrim.next = nextPrim
                        curPrim.setfPoint(list(startPoint))
                        nextPrim.setiPoint(list(startPoint))
                        path.append(nextPrim)
                        logging.debug("Path: %s", str([p.number() for p in InfoPathPrim.convertListFromInfoPrimToPrim(path)]))
                        if(nextPrim == self.lastPrim):
                            #BASE CASE
                            logging.debug("Last prim achieved")
                            pathAchieved = True

                        if((self.currentIteration >= self.max_interations / 2) and not pathAchieved):
                            self.max_iterations_exceeded = True
                            logging.error('Max iterations, no path achieved in the maximum iterations')
                            #path.remove(nextPrim)
                            pathAchieved = False
                        if(not pathAchieved and not self.max_iterations_exceeded and self.backTracking(nextPrim, path)):
                            pathAchieved = True
                        elif (not pathAchieved and not self.max_iterations_exceeded):
                            path.remove(nextPrim)
                            logging.debug("Path: %s", str([p.number() for p in InfoPathPrim.convertListFromInfoPrimToPrim(path)]))

            indexPrims += 1
            if(pathAchieved):
                logging.debug("End ireration of while, method backTracking, class PathBackTracking. State: good")
            else:
                logging.debug("End ireration of while, method backTracking, class PathBackTracking. State: no path achieved")
        return pathAchieved