def patternInsideTexture(pat, prim, texture, textureForPrim):
        #BUT IS OK FOR MORE THAN THE FIRST POINT!!! WE HAVE TO DO THE CLIP, IF NOT WE DOESN?T ANYTHING!!!
        #IMPLEMENTS!!!!
        inside = True
        valid = False
        # We have to check if the pattern (is inside of the texture except the first and the last point,
        # because by definition this points are always inside) OR (intersect with his texture) OR
        # (intersect with a texture in upper level than his texture)
        # In the three cases the pattern will be valid, in other case the pattern will be invalid
        for index in range(len(pat.getPoints()) - 2):
            # check if the upper texture containign the point of pattern is his texture
            inside = (textureForPrim.findUpperTextureContainingPoint(pat.getPoints()[index + 1]) == texture)
            if (not inside):
                tex = textureForPrim.findUpperTextureContainingPoint(pat.getPoints()[index + 1])
                logging.debug("MUST TO BE")
                logging.debug(str(texture))
                logging.debug(str(texture.get_is_default_texture()))
                logging.debug(str(texture.get_absolute_points()))
                logging.debug(str(texture.get_absolute_points_not_erasable()))
                logging.debug(str(texture.get_delimited_proportions()))
                logging.debug(str(texture.get_obj()))
                logging.debug("IS")
                logging.debug(str(tex))
                logging.debug(str(tex.get_is_default_texture()))
                logging.debug(str(tex.get_absolute_points()))
                logging.debug(str(tex.get_absolute_points_not_erasable()))
                logging.debug(str(tex.get_delimited_proportions()))
                logging.debug(str(tex.get_obj()))
                firstIndexOutside = index
                break

        if(inside):
            valid = True
        else:
            # Check if the pattern intersect with his texture
            # To do that, we have to check if it intersects, and if it intersects, the point which intersect
            # the texture has to be before than the first point outside the texture
            minDistance, nearestPointIntersect, allIntersections = texture.checkIntersectionWithTexture(pat.getPoints(), prim)  # @UnusedVariable
            outsidePointDistance = GeoMath.takeDistanceInTrackToPoint(pat.getPoints(), pat.getPoints()[firstIndexOutside], pat.getPoints()[0])
            valid = (minDistance <= outsidePointDistance)
            if(not valid):
                logging.debug("Texture not inside")
                # Check if intersect with upper texture
                upperLayer = textureForPrim.get_upper_texture(texture)
                if(upperLayer):
                    logging.debug("Texture has upper layer")
                    logging.debug(str(upperLayer))
                    logging.debug(str(upperLayer.get_is_default_texture()))
                    logging.debug(str(upperLayer.get_absolute_points()))
                    logging.debug(str(upperLayer.get_absolute_points_not_erasable()))
                    logging.debug(str(upperLayer.get_delimited_proportions()))
                    logging.debug(str(upperLayer.get_obj()))
                    # If exsits upper layer than the current texture
                    minDistance, nearestPointIntersect, allIntersections = upperLayer.checkIntersectionWithTexture(pat.getPoints(), prim)  # @UnusedVariable
                    # Now check if the point intersection is before than the first point outside of his texture
                    if(nearestPointIntersect):
                        valid = (minDistance <= outsidePointDistance)
                        if(not valid):
                            logging.debug('Texture upper layer doesnt intersect before the first point outside')
                        else:
                            logging.debug('Texture upper layer intersect')
                    else:
                        logging.debug('Texture upper layer doesnt intersect')
                else:
                    # If not exists upper layer of texture, we check the intersection before,
                    # so if it doesn't intersect, the pattern will be invalid
                    logging.debug('Texture has not upper layer, so its incorrect')
                    valid = False
        return valid
    def checkIntersectionWithTexture(self, points, prim):
        global DEBUG
        global epsilon
        logging.debug("Start method checkIntersectionWithTexture, class Texture")
        # First we check intersection with boundingBox
        if(self.get_prim() and self.get_absolute_points()):
            param_points_bounding_box = BoundingBox.BoundingBox2D(points, prim)
            texture_bounding_box = BoundingBox.BoundingBox2D(
                                                        self.get_absolute_points(),
                                                         self.get_prim())
            intersections = (
            texture_bounding_box.intersect_bounding_box_without_limits_3D(
            param_points_bounding_box))

            if (not intersections):
                return None, None, []
        else:
            if(not self.get_prim()):
                logging.debug("Class Texture, not prim in method check intersection with texture")
            else:
                logging.debug("No object points")
                logging.debug(str(self))
                logging.debug(str(self.get_is_default_texture()))
                logging.debug(str(self.get_absolute_points()))
                logging.debug(str(self.get_absolute_points_not_erasable()))
                logging.debug(str(self.get_delimited_proportions()))
                logging.debug(str(self.get_obj()))

        pointsIntersect = []
        for n in range(len(points) - 1):
            edge = [points[n], points[n + 1]]
            for texIndex in range(len(self.absolutePoints)):
                nextTexIndex = (texIndex + 1) % len(self.absolutePoints)
                texEdge = [self.absolutePoints[texIndex], self.absolutePoints[nextTexIndex]]
                pointIntersect = GeoMath.getFalseIntersectionBetweenTwoEdges3D(edge, texEdge, prim)
                # We have to avoid first point, that surely intersect with some texture.
                # Also avoid the case where two texture are together and pattern intersect with
                # the first texture, but when 'exit' from this texture, it intersect with the
                # other texture anda pattern of length 0 is used; with this method we avoid this
                if(pointIntersect):
                    distacenToLastPoint = GeoMath.vecModul(GeoMath.vecSub(
                                        points[len(points) - 1], pointIntersect))
                    if(GeoMath.vecModul(GeoMath.vecSub(pointIntersect, points[0]))
                        > epsilon and distacenToLastPoint > epsilon):
                        pointsIntersect.append(pointIntersect)

        if(pointsIntersect):
            nearestPointIntersect = None
            # Big number
            minDistance = 999999

            # For each point we look if intersection is the minimum distance intersection
            for pointIntersect in pointsIntersect:
                distance, achieved = GeoMath.takeDistanceInTrackToPoint(points,
                                                     pointIntersect, points[0])
                if(achieved and distance < minDistance and distance > epsilon):
                    # We need the minimun distance, but to avoid errors, we have
                    # to discard the first point and the last
                    minDistance = distance
                    nearestPointIntersect = pointIntersect

            if(not nearestPointIntersect):
                minDistance = None
        else:
            nearestPointIntersect = None
            minDistance = None

        if(nearestPointIntersect):
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: Intersection')
        else:
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: No intersection')

        return minDistance, nearestPointIntersect, pointsIntersect
    def checkIntersectionWithTexture(self, points, prim):
        global DEBUG
        global epsilon
        logging.debug(
            "Start method checkIntersectionWithTexture, class Texture")
        # First we check intersection with boundingBox
        if (self.get_prim() and self.get_absolute_points()):
            param_points_bounding_box = BoundingBox.BoundingBox2D(points, prim)
            texture_bounding_box = BoundingBox.BoundingBox2D(
                self.get_absolute_points(), self.get_prim())
            intersections = (
                texture_bounding_box.intersect_bounding_box_without_limits_3D(
                    param_points_bounding_box))

            if (not intersections):
                return None, None, []
        else:
            if (not self.get_prim()):
                logging.debug(
                    "Class Texture, not prim in method check intersection with texture"
                )
            else:
                logging.debug("No object points")
                logging.debug(str(self))
                logging.debug(str(self.get_is_default_texture()))
                logging.debug(str(self.get_absolute_points()))
                logging.debug(str(self.get_absolute_points_not_erasable()))
                logging.debug(str(self.get_delimited_proportions()))
                logging.debug(str(self.get_obj()))

        pointsIntersect = []
        for n in range(len(points) - 1):
            edge = [points[n], points[n + 1]]
            for texIndex in range(len(self.absolutePoints)):
                nextTexIndex = (texIndex + 1) % len(self.absolutePoints)
                texEdge = [
                    self.absolutePoints[texIndex],
                    self.absolutePoints[nextTexIndex]
                ]
                pointIntersect = GeoMath.getFalseIntersectionBetweenTwoEdges3D(
                    edge, texEdge, prim)
                # We have to avoid first point, that surely intersect with some texture.
                # Also avoid the case where two texture are together and pattern intersect with
                # the first texture, but when 'exit' from this texture, it intersect with the
                # other texture anda pattern of length 0 is used; with this method we avoid this
                if (pointIntersect):
                    distacenToLastPoint = GeoMath.vecModul(
                        GeoMath.vecSub(points[len(points) - 1],
                                       pointIntersect))
                    if (GeoMath.vecModul(
                            GeoMath.vecSub(pointIntersect, points[0])) >
                            epsilon and distacenToLastPoint > epsilon):
                        pointsIntersect.append(pointIntersect)

        if (pointsIntersect):
            nearestPointIntersect = None
            # Big number
            minDistance = 999999

            # For each point we look if intersection is the minimum distance intersection
            for pointIntersect in pointsIntersect:
                distance, achieved = GeoMath.takeDistanceInTrackToPoint(
                    points, pointIntersect, points[0])
                if (achieved and distance < minDistance
                        and distance > epsilon):
                    # We need the minimun distance, but to avoid errors, we have
                    # to discard the first point and the last
                    minDistance = distance
                    nearestPointIntersect = pointIntersect

            if (not nearestPointIntersect):
                minDistance = None
        else:
            nearestPointIntersect = None
            minDistance = None

        if (nearestPointIntersect):
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: Intersection')
        else:
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: No intersection')

        return minDistance, nearestPointIntersect, pointsIntersect
Example #4
0
    def patternInsideTexture(pat, prim, texture, textureForPrim):
        #BUT IS OK FOR MORE THAN THE FIRST POINT!!! WE HAVE TO DO THE CLIP, IF NOT WE DOESN?T ANYTHING!!!
        #IMPLEMENTS!!!!
        inside = True
        valid = False
        # We have to check if the pattern (is inside of the texture except the first and the last point,
        # because by definition this points are always inside) OR (intersect with his texture) OR
        # (intersect with a texture in upper level than his texture)
        # In the three cases the pattern will be valid, in other case the pattern will be invalid
        for index in range(len(pat.getPoints()) - 2):
            # check if the upper texture containign the point of pattern is his texture
            inside = (textureForPrim.findUpperTextureContainingPoint(
                pat.getPoints()[index + 1]) == texture)
            if (not inside):
                tex = textureForPrim.findUpperTextureContainingPoint(
                    pat.getPoints()[index + 1])
                logging.debug("MUST TO BE")
                logging.debug(str(texture))
                logging.debug(str(texture.get_is_default_texture()))
                logging.debug(str(texture.get_absolute_points()))
                logging.debug(str(texture.get_absolute_points_not_erasable()))
                logging.debug(str(texture.get_delimited_proportions()))
                logging.debug(str(texture.get_obj()))
                logging.debug("IS")
                logging.debug(str(tex))
                logging.debug(str(tex.get_is_default_texture()))
                logging.debug(str(tex.get_absolute_points()))
                logging.debug(str(tex.get_absolute_points_not_erasable()))
                logging.debug(str(tex.get_delimited_proportions()))
                logging.debug(str(tex.get_obj()))
                firstIndexOutside = index
                break

        if (inside):
            valid = True
        else:
            # Check if the pattern intersect with his texture
            # To do that, we have to check if it intersects, and if it intersects, the point which intersect
            # the texture has to be before than the first point outside the texture
            minDistance, nearestPointIntersect, allIntersections = texture.checkIntersectionWithTexture(
                pat.getPoints(), prim)  # @UnusedVariable
            outsidePointDistance = GeoMath.takeDistanceInTrackToPoint(
                pat.getPoints(),
                pat.getPoints()[firstIndexOutside],
                pat.getPoints()[0])
            valid = (minDistance <= outsidePointDistance)
            if (not valid):
                logging.debug("Texture not inside")
                # Check if intersect with upper texture
                upperLayer = textureForPrim.get_upper_texture(texture)
                if (upperLayer):
                    logging.debug("Texture has upper layer")
                    logging.debug(str(upperLayer))
                    logging.debug(str(upperLayer.get_is_default_texture()))
                    logging.debug(str(upperLayer.get_absolute_points()))
                    logging.debug(
                        str(upperLayer.get_absolute_points_not_erasable()))
                    logging.debug(str(upperLayer.get_delimited_proportions()))
                    logging.debug(str(upperLayer.get_obj()))
                    # If exsits upper layer than the current texture
                    minDistance, nearestPointIntersect, allIntersections = upperLayer.checkIntersectionWithTexture(
                        pat.getPoints(), prim)  # @UnusedVariable
                    # Now check if the point intersection is before than the first point outside of his texture
                    if (nearestPointIntersect):
                        valid = (minDistance <= outsidePointDistance)
                        if (not valid):
                            logging.debug(
                                'Texture upper layer doesnt intersect before the first point outside'
                            )
                        else:
                            logging.debug('Texture upper layer intersect')
                    else:
                        logging.debug('Texture upper layer doesnt intersect')
                else:
                    # If not exists upper layer of texture, we check the intersection before,
                    # so if it doesn't intersect, the pattern will be invalid
                    logging.debug(
                        'Texture has not upper layer, so its incorrect')
                    valid = False
        return valid