Exemple #1
0
 def isThisPrimMaybeValid(self, prim):
     # Has each edge of prim a connected prim? if not, track edges will not work!, so the prim
     # will not valid
     allGroups = []
     allGroups.extend(self.setNotDestroyed)
     allGroups.extend(self.setPartiallyDestroyed)
     allGroups.extend(self.setTotDestroyed)
     edgesHavingPrimitiveConnected = len(
         GeoMath.getConnectedPrimsOneForEachEdge(prim, allGroups))
     connectedWithNot = len(
         GeoMath.getConnectedPrims(prim, self.setNotDestroyed, 1))
     connectedWithTot = len(
         GeoMath.getConnectedPrims(prim, self.setTotDestroyed, 1))
     connectedWithPartially = len(
         GeoMath.getConnectedPrimsOneForEachEdge(
             prim, self.setPartiallyDestroyed))
     connectedWithPath = len(
         GeoMath.getConnectedPrimsOneForEachEdge(prim, self.path))
     # Prim must to acomplished that the number of connected with partially destroyed plus
     # connected with not destroyed plus connected with totally destroyed minus connecte with path
     # must to be greater than 2 primitives (at least two wanted primitives to do recursion after)
     logging.debug("Method isThisPrimMaybeValid, prim %s , with:",
                   str(prim.number()))
     logging.debug(
         "Connected with not: %s, connected with tot: %s, connected with partially: %s, connected with path: %s, edges having primitive: %s",
         str(connectedWithNot), str(connectedWithTot),
         str(connectedWithPartially), str(connectedWithPath),
         str(edgesHavingPrimitiveConnected))
     return (((connectedWithPartially + connectedWithTot +
               connectedWithNot - connectedWithPath) >= 2)
             and (edgesHavingPrimitiveConnected == len(
                 GeoMath.getEdgesFromPrim(prim))))
    def doValidation(self, setNotDestroyed, setPartiallyDestroyed, setTotDestroyed, path):
        logging.debug("Start method doValidation. Class ValidatePath")
        '''
        We have to generate two branch for each primitive. One for one group of edges from prim, which
        all of its edges shared a group of primitives (not destroyed or tot destroyed), the other
        set of edges shared the other group of primitives (not destroyed or tot destroyed)
        
        To disjoin the two sets of edges, we take into account that each primitive is connected with
        two primitives more, that lies in set of path primitives. From one shared edge between this prim
        and one prim conected to this prim in the path set to the other edge shared to the other path prim
        we have a set of edges, and equal in the other side.
        '''
        validPrim1 = None
        validPrim2 = None
        find = False
        provePath = list(path)
        while(not (validPrim1 and validPrim2) and len(provePath) > 0):
            num = int(random.random() * len(provePath))
            prim = provePath[num]
            del provePath[num]
            '''
            h=HouInterface.HouInterface()
            h.showPoint(GeoMath.primBoundingBox(prim).center(), name='prim_'+str(prim.number()), color=[0,1,0])
            '''
            if(len(GeoMath.getEdgesFromPrim(prim)) <= 3):
                prim = self.tryToCollapseTwoTrianglesInOneQuad(prim, path)
                # NOT IMPLEMENTED YET
                logging.debug("Collapse in one quad NOT IMPLEMENTED YET")
            else:
                validPrim1, validPrim2 = self.getPrimsSharingGroupOfEdges(prim, setNotDestroyed, setPartiallyDestroyed, setTotDestroyed)
        if(not (validPrim1 and validPrim2)):
            logging.debug("Not valid path, because any prim is valid to do the validation, with groups:")
            logging.debug("Group not destroyed: %s", str([p.number() for p in setNotDestroyed]))
            logging.debug("Group partially destroyed: %s", str([p.number() for p in setPartiallyDestroyed]))
            logging.debug("Group totally destroyed: %s", str([p.number() for p in setTotDestroyed]))
            logging.debug("Path: %s", str([p.number() for p in path]))
            logging.debug("End method doValidation. Class ValidatePath. State: no valid path")
            #ONLY FOR DEBUGGING!!! IN FACT, IT MUST TO RETURN FALSE!!!!
            return True
        logging.debug("Valid primitives: %s, %s", str(validPrim1.number()), str(validPrim2.number()))
        matchNotDes1, matchTotDes1 = self.findSomeGroupRecursively(validPrim1, setNotDestroyed, setPartiallyDestroyed, setTotDestroyed)
        matchNotDes2, matchTotDes2 = self.findSomeGroupRecursively(validPrim2, setNotDestroyed, setPartiallyDestroyed, setTotDestroyed)
        if((matchNotDes1 and matchTotDes2) or (matchNotDes2 and matchTotDes1)):
            logging.debug("Valid path")
            logging.debug("End method doValidation. Class ValidatePath. State: good")
            find = True
        if (not find):
            logging.debug("Not valid path with groups:")
            logging.debug("Group not destroyed: %s", str([p.number() for p in setNotDestroyed]))
            logging.debug("Group partially destroyed: %s", str([p.number() for p in setPartiallyDestroyed]))
            logging.debug("Group totally destroyed: %s", str([p.number() for p in setTotDestroyed]))
            logging.debug("Path: %s", str([p.number() for p in path]))
            logging.debug("End method doValidation. Class ValidatePath. State: no valid path")

        return find
 def tryToCollapseTwoTrianglesInOneQuad(self, prim, path):
     index = 0
     while(index < len(path) and path[index] != prim):
         index += 1
     if (index == len(path)):
         # If error ocurred and no prim mathched
         return None
     nextPrim = (index + 1) % len(path)
     if(index != 0):
         previousPrim = len(path) - 1
     else:
         previousPrim = index - 1
     nextPrimEdges = GeoMath.getEdgesFromPrim(path[nextPrim])
     previousPrimEdges = GeoMath.getEdgesFromPrim(path[previousPrim])
     if(len(nextPrimEdges) >= 3 and len(previousPrimEdges) >= 3):
         return None
     else:
         # Case when we can to collapse two connected triangles
         # NOT IMPLEMENTED YET
         pass
Exemple #4
0
 def tryToCollapseTwoTrianglesInOneQuad(self, prim, path):
     index = 0
     while (index < len(path) and path[index] != prim):
         index += 1
     if (index == len(path)):
         # If error ocurred and no prim mathched
         return None
     nextPrim = (index + 1) % len(path)
     if (index != 0):
         previousPrim = len(path) - 1
     else:
         previousPrim = index - 1
     nextPrimEdges = GeoMath.getEdgesFromPrim(path[nextPrim])
     previousPrimEdges = GeoMath.getEdgesFromPrim(path[previousPrim])
     if (len(nextPrimEdges) >= 3 and len(previousPrimEdges) >= 3):
         return None
     else:
         # Case when we can to collapse two connected triangles
         # NOT IMPLEMENTED YET
         pass
 def isThisPrimMaybeValid(self, prim):
     # Has each edge of prim a connected prim? if not, track edges will not work!, so the prim
     # will not valid
     allGroups = []
     allGroups.extend(self.setNotDestroyed)
     allGroups.extend(self.setPartiallyDestroyed)
     allGroups.extend(self.setTotDestroyed)
     edgesHavingPrimitiveConnected = len(GeoMath.getConnectedPrimsOneForEachEdge(prim, allGroups))
     connectedWithNot = len(GeoMath.getConnectedPrims(prim, self.setNotDestroyed, 1))
     connectedWithTot = len(GeoMath.getConnectedPrims(prim, self.setTotDestroyed, 1))
     connectedWithPartially = len(GeoMath.getConnectedPrimsOneForEachEdge(prim, self.setPartiallyDestroyed))
     connectedWithPath = len(GeoMath.getConnectedPrimsOneForEachEdge(prim, self.path))
     # Prim must to acomplished that the number of connected with partially destroyed plus
     # connected with not destroyed plus connected with totally destroyed minus connecte with path
     # must to be greater than 2 primitives (at least two wanted primitives to do recursion after)
     logging.debug("Method isThisPrimMaybeValid, prim %s , with:", str(prim.number()))
     logging.debug("Connected with not: %s, connected with tot: %s, connected with partially: %s, connected with path: %s, edges having primitive: %s",
                   str(connectedWithNot), str(connectedWithTot), str(connectedWithPartially), str(connectedWithPath), str(edgesHavingPrimitiveConnected))
     return (((connectedWithPartially + connectedWithTot + connectedWithNot - connectedWithPath) >= 2) and (edgesHavingPrimitiveConnected == len(GeoMath.getEdgesFromPrim(prim))))
    def find_path(self, gridName, startPoint, finalPoint):
        reload(GeoMath)
        path = []
        grid = self.hout.grids[gridName][0]
        logging.debug('grid name ' + str(grid))
        prims = grid.geometry().prims()
        startPrim, finalPrim = self.findExtremePrims(startPoint, finalPoint, prims)
        if (startPrim == None or finalPrim == None):
            logging.debug("Start and final prims can't be ensured since the intersections_with_crack with the crack are a little misplaced, and that cause pointInEdge to fail when trying to know which primitive is the start and the final")
        # Unique prim
        if (finalPrim.number() == startPrim.number()):
            uniquePrim = InfoPathPrim.InfoPathPrim(startPrim)
            uniquePrim.setiPoint(startPoint)
            uniquePrim.setfPoint(finalPoint)
            return [uniquePrim]
            
        logging.debug("prims with floor " + str(
            [startPrim.number(), finalPrim.number()]))
        navigationLine = GeoMath.vecSub(finalPoint, startPoint)

        mappedStartPoint = [startPoint[0], startPoint[2], 0]
        mappedFinalPoint = [finalPoint[0], finalPoint[2], 0]

        primsInPath = []
        for prim in prims:
            if (prim.number() == startPrim.number() or prim.number() == finalPrim.number()):
                continue
            edges = GeoMath.getEdgesFromPrim(prim)
            mappedEdges = [[[edge[0][0], edge[0][2], 0], [edge[1][0], edge[1][2], 0]]
                           for edge in edges]
            logging.debug("prim number " + str(prim.number()))
            inters = GeoMath.getIntersectionsBetweenEdges2D(
                mappedEdges, [[mappedStartPoint, mappedFinalPoint]])

            if (inters):
                logging.debug("Inter in path " + str(inters))
                # Demap again to original 'y' component, which both start point or
                # final point have
                demappedInters = [[inter[0], startPoint[1], inter[1]]
                                for inter in inters]
                distPoint0 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[0], startPoint))
                distPoint1 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[1], startPoint))
                if (distPoint0 < distPoint1):
                    startPrimPoint = demappedInters[0]
                    finalPrimPoint = demappedInters[1]
                else:
                    startPrimPoint = demappedInters[1]
                    finalPrimPoint = demappedInters[0]
                infoPrim = InfoPathPrim.InfoPathPrim(prim)
                infoPrim.setiPoint(startPrimPoint)
                infoPrim.setfPoint(finalPrimPoint)
                primsInPath.append(infoPrim)
                logging.debug("Prim intersects " + str(prim.number()) + " " + str(startPrimPoint) + " " + str(finalPrimPoint)) 

        sorted(primsInPath, key=lambda infoPrim:
               GeoMath.vecModul(GeoMath.vecSub(infoPrim.iPoint, startPoint)))
        logging.debug("Testing??")
        if (not primsInPath):
            logging.debug("No intersections " + str(primsInPath))
            return
            
        startInfoPrim = InfoPathPrim.InfoPathPrim(startPrim)
        finalInfoPrim = InfoPathPrim. InfoPathPrim(finalPrim)
        
        startInfoPrim.setiPoint(startPoint)
        startInfoPrim.setfPoint(primsInPath[0].iPoint)
        finalInfoPrim.setiPoint(primsInPath[len(primsInPath) - 1].fPoint)
        finalInfoPrim.setfPoint(finalPoint)
        
        primsInPath.append(finalInfoPrim)
        primsInPath.insert(0, startInfoPrim)
        
        logging.debug([prim.prim.number() for prim in primsInPath])
        
        #DEBUG:
        logging.debug("Before showing path")
        self.showPath(gridName, InfoPathPrim.convertListFromInfoPrimToPrim(primsInPath))
        
        return primsInPath
Exemple #7
0
    def doValidation(self, setNotDestroyed, setPartiallyDestroyed,
                     setTotDestroyed, path):
        logging.debug("Start method doValidation. Class ValidatePath")
        '''
        We have to generate two branch for each primitive. One for one group of edges from prim, which
        all of its edges shared a group of primitives (not destroyed or tot destroyed), the other
        set of edges shared the other group of primitives (not destroyed or tot destroyed)
        
        To disjoin the two sets of edges, we take into account that each primitive is connected with
        two primitives more, that lies in set of path primitives. From one shared edge between this prim
        and one prim conected to this prim in the path set to the other edge shared to the other path prim
        we have a set of edges, and equal in the other side.
        '''
        validPrim1 = None
        validPrim2 = None
        find = False
        provePath = list(path)
        while (not (validPrim1 and validPrim2) and len(provePath) > 0):
            num = int(random.random() * len(provePath))
            prim = provePath[num]
            del provePath[num]
            '''
            h=HouInterface.HouInterface()
            h.showPoint(GeoMath.primBoundingBox(prim).center(), name='prim_'+str(prim.number()), color=[0,1,0])
            '''
            if (len(GeoMath.getEdgesFromPrim(prim)) <= 3):
                prim = self.tryToCollapseTwoTrianglesInOneQuad(prim, path)
                # NOT IMPLEMENTED YET
                logging.debug("Collapse in one quad NOT IMPLEMENTED YET")
            else:
                validPrim1, validPrim2 = self.getPrimsSharingGroupOfEdges(
                    prim, setNotDestroyed, setPartiallyDestroyed,
                    setTotDestroyed)
        if (not (validPrim1 and validPrim2)):
            logging.debug(
                "Not valid path, because any prim is valid to do the validation, with groups:"
            )
            logging.debug("Group not destroyed: %s",
                          str([p.number() for p in setNotDestroyed]))
            logging.debug("Group partially destroyed: %s",
                          str([p.number() for p in setPartiallyDestroyed]))
            logging.debug("Group totally destroyed: %s",
                          str([p.number() for p in setTotDestroyed]))
            logging.debug("Path: %s", str([p.number() for p in path]))
            logging.debug(
                "End method doValidation. Class ValidatePath. State: no valid path"
            )
            #ONLY FOR DEBUGGING!!! IN FACT, IT MUST TO RETURN FALSE!!!!
            return True
        logging.debug("Valid primitives: %s, %s", str(validPrim1.number()),
                      str(validPrim2.number()))
        matchNotDes1, matchTotDes1 = self.findSomeGroupRecursively(
            validPrim1, setNotDestroyed, setPartiallyDestroyed,
            setTotDestroyed)
        matchNotDes2, matchTotDes2 = self.findSomeGroupRecursively(
            validPrim2, setNotDestroyed, setPartiallyDestroyed,
            setTotDestroyed)
        if ((matchNotDes1 and matchTotDes2)
                or (matchNotDes2 and matchTotDes1)):
            logging.debug("Valid path")
            logging.debug(
                "End method doValidation. Class ValidatePath. State: good")
            find = True
        if (not find):
            logging.debug("Not valid path with groups:")
            logging.debug("Group not destroyed: %s",
                          str([p.number() for p in setNotDestroyed]))
            logging.debug("Group partially destroyed: %s",
                          str([p.number() for p in setPartiallyDestroyed]))
            logging.debug("Group totally destroyed: %s",
                          str([p.number() for p in setTotDestroyed]))
            logging.debug("Path: %s", str([p.number() for p in path]))
            logging.debug(
                "End method doValidation. Class ValidatePath. State: no valid path"
            )

        return find
    def find_path(self, gridName, startPoint, finalPoint):
        reload(GeoMath)
        path = []
        grid = self.hout.grids[gridName][0]
        logging.debug('grid name ' + str(grid))
        prims = grid.geometry().prims()
        startPrim, finalPrim = self.findExtremePrims(startPoint, finalPoint,
                                                     prims)
        if (startPrim == None or finalPrim == None):
            logging.debug(
                "Start and final prims can't be ensured since the intersections_with_crack with the crack are a little misplaced, and that cause pointInEdge to fail when trying to know which primitive is the start and the final"
            )
        # Unique prim
        if (finalPrim.number() == startPrim.number()):
            uniquePrim = InfoPathPrim.InfoPathPrim(startPrim)
            uniquePrim.setiPoint(startPoint)
            uniquePrim.setfPoint(finalPoint)
            return [uniquePrim]

        logging.debug(
            "prims with floor " +
            str([startPrim.number(), finalPrim.number()]))
        navigationLine = GeoMath.vecSub(finalPoint, startPoint)

        mappedStartPoint = [startPoint[0], startPoint[2], 0]
        mappedFinalPoint = [finalPoint[0], finalPoint[2], 0]

        primsInPath = []
        for prim in prims:
            if (prim.number() == startPrim.number()
                    or prim.number() == finalPrim.number()):
                continue
            edges = GeoMath.getEdgesFromPrim(prim)
            mappedEdges = [[[edge[0][0], edge[0][2], 0],
                            [edge[1][0], edge[1][2], 0]] for edge in edges]
            logging.debug("prim number " + str(prim.number()))
            inters = GeoMath.getIntersectionsBetweenEdges2D(
                mappedEdges, [[mappedStartPoint, mappedFinalPoint]])

            if (inters):
                logging.debug("Inter in path " + str(inters))
                # Demap again to original 'y' component, which both start point or
                # final point have
                demappedInters = [[inter[0], startPoint[1], inter[1]]
                                  for inter in inters]
                distPoint0 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[0], startPoint))
                distPoint1 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[1], startPoint))
                if (distPoint0 < distPoint1):
                    startPrimPoint = demappedInters[0]
                    finalPrimPoint = demappedInters[1]
                else:
                    startPrimPoint = demappedInters[1]
                    finalPrimPoint = demappedInters[0]
                infoPrim = InfoPathPrim.InfoPathPrim(prim)
                infoPrim.setiPoint(startPrimPoint)
                infoPrim.setfPoint(finalPrimPoint)
                primsInPath.append(infoPrim)
                logging.debug("Prim intersects " + str(prim.number()) + " " +
                              str(startPrimPoint) + " " + str(finalPrimPoint))

        sorted(primsInPath,
               key=lambda infoPrim: GeoMath.vecModul(
                   GeoMath.vecSub(infoPrim.iPoint, startPoint)))
        logging.debug("Testing??")
        if (not primsInPath):
            logging.debug("No intersections " + str(primsInPath))
            return

        startInfoPrim = InfoPathPrim.InfoPathPrim(startPrim)
        finalInfoPrim = InfoPathPrim.InfoPathPrim(finalPrim)

        startInfoPrim.setiPoint(startPoint)
        startInfoPrim.setfPoint(primsInPath[0].iPoint)
        finalInfoPrim.setiPoint(primsInPath[len(primsInPath) - 1].fPoint)
        finalInfoPrim.setfPoint(finalPoint)

        primsInPath.append(finalInfoPrim)
        primsInPath.insert(0, startInfoPrim)

        logging.debug([prim.prim.number() for prim in primsInPath])

        #DEBUG:
        logging.debug("Before showing path")
        self.showPath(gridName,
                      InfoPathPrim.convertListFromInfoPrimToPrim(primsInPath))

        return primsInPath