def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False):
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.create_3D_to_2D_rectangle(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            this_tbn_inverse_matrix.printAttributes()
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()),
            GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
        )
        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
Example #2
0
 def intersect_bounding_box_2D(self, bounding_box, DISPLAY=False):
     intersection = GeoMath.getIntersectionsBetweenEdges2D(
         self.get_edges_object_space(),
         bounding_box.get_edges_object_edges(), 1)
     if (DISPLAY):
         # TEMP: exit
         1 / 0
         exit()
         self.to_display_intersections.append(intersection)
     return intersection != []
 def intersect_bounding_box_2D(self, bounding_box, DISPLAY=False):
     intersection = GeoMath.getIntersectionsBetweenEdges2D(
         self.get_edges_object_space(), bounding_box.get_edges_object_edges(), 1
     )
     if DISPLAY:
         # TEMP: exit
         1 / 0
         exit()
         self.to_display_intersections.append(intersection)
     return intersection != []
Example #4
0
    def intersect_bounding_box_with_limits_3D(self,
                                              bounding_box,
                                              DISPLAY=False):
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_tangent_space(), \
                       GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))

        #=======================================================================
        # work in object space because we only has to know if the bounding boxes
        # share some edge between
        #=======================================================================
        edges_shared_between_bounding_boxes = \
        GeoMath.getEdgesBetweenEdges(self.get_edges_tangent_space(), \
        GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))

        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections, edges_shared_between_bounding_boxes
Example #5
0
    def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False):
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.create_3D_to_2D_rectangle(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            this_tbn_inverse_matrix.printAttributes()
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()),
            GeoMath.getEdgesFromPoints(
                param_bounding_box_points_in_this_tangent_space))
        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
    def intersect_bounding_box_with_limits_3D(self, bounding_box, DISPLAY=False):
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )

        # =======================================================================
        # work in object space because we only has to know if the bounding boxes
        # share some edge between
        # =======================================================================
        edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )

        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections, edges_shared_between_bounding_boxes
    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
Example #8
0
    def intersect_bounding_box_without_limits_3D(self,
                                                 bounding_box,
                                                 DISPLAY=False):
        global littleEpsilon
        try:
            if (not self.get_prim()):
                raise Errors.CantBeNoneError(
                    'Prim cant be none',
                    'We need a prim to calculate tbn some steps after')
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if (not self.get_points_tangent_space()):
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative(
        )
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            param_bounding_box_points_in_this_tangent_space.append(
                point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_tangent_space(), \
                       GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))
        if (intersections):
            #===============================================================
            # Check if the limits are touching and if it are touching it,
            # check if the intersection is in there. If it is in there,
            # the intersection lie in the limit, so we dont consider an
            # intersection
            #===============================================================
            edges_shared_between_bounding_boxes = \
            GeoMath.getEdgesBetweenEdges(self.get_edges_tangent_space(), \
            GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space))
            inside = False
            print "Edges shared between"
            print edges_shared_between_bounding_boxes
            for intersection in intersections:
                inside = GeoMath.pointInEdges(
                    intersection, edges_shared_between_bounding_boxes)
                if (not inside):
                    break
            #===============================================================
            # If all intersections lie in the edges shared between bounding
            # boxes we discart its
            #===============================================================
            if (inside):
                intersections = []
            else:
                # check if intersections are in the corner, because we consider corner as limit
                shared_points_between_bounding_boxes = GeoMath.getSharedPoints(
                    self.get_rectangle_tangent_space(),
                    param_bounding_box_points_in_this_tangent_space)
                # If all intersections lie in the corner we doen't consider intersections as intersections
                true_intersections = list(intersections)
                for intersection in intersections:
                    for corner in shared_points_between_bounding_boxes:
                        if (GeoMath.vecModul(
                                GeoMath.vecSub(corner, intersection)) <=
                                littleEpsilon):
                            true_intersections.remove(intersection)
                            break
                intersections = true_intersections

        if (DISPLAY):
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(
                    intersection)
                point_absolute = GeoMath.vecPlus(point_object_space,
                                                 this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
Example #9
0
 def intersect_edge_2D(self, edge):
     intersection = GeoMath.getIntersectionsBetweenEdges2D(
         self.get_edges_object_space(), [edge], 1)
     return intersection
    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
    def intersect_bounding_box_without_limits_3D(self, bounding_box, DISPLAY=False):
        global littleEpsilon
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )
        if intersections:
            # ===============================================================
            # Check if the limits are touching and if it are touching it,
            # check if the intersection is in there. If it is in there,
            # the intersection lie in the limit, so we dont consider an
            # intersection
            # ===============================================================
            edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
                self.get_edges_tangent_space(),
                GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
            )
            inside = False
            print "Edges shared between"
            print edges_shared_between_bounding_boxes
            for intersection in intersections:
                inside = GeoMath.pointInEdges(intersection, edges_shared_between_bounding_boxes)
                if not inside:
                    break
            # ===============================================================
            # If all intersections lie in the edges shared between bounding
            # boxes we discart its
            # ===============================================================
            if inside:
                intersections = []
            else:
                # check if intersections are in the corner, because we consider corner as limit
                shared_points_between_bounding_boxes = GeoMath.getSharedPoints(
                    self.get_rectangle_tangent_space(), param_bounding_box_points_in_this_tangent_space
                )
                # If all intersections lie in the corner we doen't consider intersections as intersections
                true_intersections = list(intersections)
                for intersection in intersections:
                    for corner in shared_points_between_bounding_boxes:
                        if GeoMath.vecModul(GeoMath.vecSub(corner, intersection)) <= littleEpsilon:
                            true_intersections.remove(intersection)
                            break
                intersections = true_intersections

        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
 def intersect_edge_2D(self, edge):
     intersection = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_object_space(), [edge], 1)
     return intersection