Ejemplo n.º 1
0
    def goToPrimPattern(self, curPoint, nextPoint, pat, tbn, pointWhichIsRelative):
        '''
        TBN aplication
        '''
        global epsilon
        for num in range(len(pat.points)):
            pat.points[num] = tbn.mulPoint3ToMatrix3(pat.points[num])
            pat.points[num] = GeoMath.vecPlus(pointWhichIsRelative, pat.points[num])
        # Transform normal vector also
        logging.debug("Changing normal" + str(pat.getNormal()))
        transformed_normal = tbn.mulPoint3ToMatrix3(pat.getNormal())
        logging.debug("Transformed normal" + str(transformed_normal))
        normalized_normal = GeoMath.vecNormalize(transformed_normal)
        logging.debug("normalized normal" + str(normalized_normal))
        pat.setNormal(normalized_normal)
        logging.debug("normalized normal set?? " + str(pat.getNormal()))
        trans = GeoMath.vecSub(curPoint, pat.getFirstPoint())
        likelyPointF = GeoMath.vecPlus(pat.getLastPoint(), trans)
        if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
            trans = GeoMath.vecSub(curPoint, pat.getLastPoint())

        for num in range(len(pat.getPoints())):
            pat.points[num] = self.translatePointToPrim(pat.points[num], trans)

        if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
            pat.points.reverse()
    def detVec(prim, dirVec, exception):
        global epsilon
        reload(GeoMath)
        vec1 = GeoMath.vecNormalize(GeoMath.vecSub(list(prim.vertices()[0].point().position()), list(prim.vertices()[1].point().position())))
        vec2 = GeoMath.vecNormalize(GeoMath.vecSub(list(prim.vertices()[2].point().position()), list(prim.vertices()[1].point().position())))
        prim_normal = list(prim.normal())
        if(list(prim_normal) != [0, 1, 0]):
            # We consider that y is vertical and x horizontal
            if(math.fabs(vec1[1]) > math.fabs(vec2[1])):
                # If the vectors are dependent
                if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
                    # Quads!!
                    if(GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
                else:
                    vecV = vec1
                vecH = vec2
            else:
                # If the vectors are dependent
                if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
                    # Quads!!
                    if(GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
                else:
                    vecV = vec2
                vecH = vec1
        else:
            # We consider that x is vertical and z horizontal
            if(math.fabs(vec1[0]) > math.fabs(vec2[0])):
                # If the vectors are dependent
                if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
                    # Quads!!
                    if(GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
                else:
                    vecV = vec1
                vecH = vec2
            else:
                # If the vectors are dependent
                if(math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
                    #Quads!!!
                    if(GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
                else:
                    vecV = vec2
                vecH = vec1

        if(GeoMath.vecDotProduct(dirVec, vecH) < 0):
            vecH = GeoMath.vecSub([0, 0, 0], vecH)
        if(GeoMath.vecDotProduct(dirVec, vecV) < 0):
            vecV = GeoMath.vecSub([0, 0, 0], vecV)
        vecH = GeoMath.vecNormalize(vecH)
        vecV = GeoMath.vecNormalize(vecV)
        return vecH, vecV
Ejemplo n.º 3
0
 def calculateDisplacement(self, curEdge, nextEdge):
     '''
         Edges are correlatives and in wise direction
     '''
     curEdgeNor = GeoMath.vecSub(curEdge[1], curEdge[0])
     curEdgeNor = GeoMath.vecNormalize(curEdgeNor)
     nextEdgeNor = GeoMath.vecSub(nextEdge[1], nextEdge[0])
     nextEdgeNor = GeoMath.vecNormalize(nextEdgeNor)
     return GeoMath.vecSub(curEdgeNor, nextEdgeNor)
Ejemplo n.º 4
0
 def calculateDisplacement(self, curEdge, nextEdge):
     """
         Edges are correlatives and in wise direction
     """
     curEdgeNor = GeoMath.vecSub(curEdge[1], curEdge[0])
     curEdgeNor = GeoMath.vecNormalize(curEdgeNor)
     nextEdgeNor = GeoMath.vecSub(nextEdge[1], nextEdge[0])
     nextEdgeNor = GeoMath.vecNormalize(nextEdgeNor)
     return GeoMath.vecSub(curEdgeNor, nextEdgeNor)
Ejemplo n.º 5
0
 def bresenham(Ipoint, point1, fPoint, xSize, ySize, prim, exception):
     reload (GeoMath)
     reload (DetermineVectors)
     reload (Validator)
     curPoint = point1
     dirVec = GeoMath.vecNormalize(GeoMath.vecSub(fPoint, Ipoint))
     # Get the horizontal and vertical vectors
     xVec, yVec = DetermineVectors.DetermineVectors.detVec(prim, dirVec, exception)
     xSizeVec = GeoMath.vecScalarProduct(xVec, xSize)
     ySizeVec = GeoMath.vecScalarProduct(yVec, ySize)
     vecToFinal = GeoMath.vecSub(curPoint, fPoint)
     sizeToFinalx = abs(GeoMath.vecDotProduct(vecToFinal, xVec) / GeoMath.vecModul(xVec))
     sizeToFinaly = abs(GeoMath.vecDotProduct(vecToFinal, yVec) / GeoMath.vecModul(yVec))
     if(sizeToFinalx > xSize or sizeToFinaly > ySize):
         pointx = GeoMath.vecPlus(curPoint, xSizeVec)
         pointy = GeoMath.vecPlus(curPoint, ySizeVec)
         pointxy = GeoMath.vecPlus(curPoint, xSizeVec)
         pointxy = GeoMath.vecPlus(pointxy, ySizeVec)
         curxVec = GeoMath.vecNormalize(GeoMath.vecSub(pointx, Ipoint))
         curyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointy, Ipoint))
         curxyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointxy, Ipoint))
         # We get the max dot product, the vector nearest to line
         dotx = GeoMath.vecDotProduct(curxVec, dirVec)
         doty = GeoMath.vecDotProduct(curyVec, dirVec)
         dotxy = GeoMath.vecDotProduct(curxyVec, dirVec)
         pointsTemp = {}
         if(Validator.Validator.pointInsidePrim(pointx, prim)): pointsTemp[dotx] = pointx
         if(Validator.Validator.pointInsidePrim(pointy, prim)): pointsTemp[doty] = pointy
         if(Validator.Validator.pointInsidePrim(pointxy, prim)): pointsTemp[dotxy] = pointxy
         if(not pointsTemp):
             point = list(fPoint)
         else:
             bestPoint = list(pointsTemp[sorted(pointsTemp)[len(pointsTemp) - 1]])
             point = bestPoint
     else:
         point = list(fPoint)
         '''   
         if(prim.number()==54):
         print "Ipoint, fpoint"
         print Ipoint, fPoint
         print "pointx, pointy, pointxy"
         print pointx, pointy, pointxy
         print "Dots"
         print dotx, doty, dotxy
         print "sizes"
         print sizeToFinalx, sizeToFinaly            
         print "Point"
         print point
         '''
     return point
Ejemplo n.º 6
0
    def getRandomPattern(self,
                         wavelength,
                         pointI,
                         pointF,
                         normal,
                         height=None):
        logging.debug("Class Data, method getRandomPattern")

        add_noise = Add_noise()

        # Calculate height if not get
        if (not height):
            height = self.sizey / 2
        transformed_points = add_noise.apply_noise([pointI, pointF],
                                                   normal,
                                                   height,
                                                   True,
                                                   frequency='medium')
        # Now we add the heigth for each point, because the noise lies between [-sizey/2, sizey/2]
        # and we want [0, sizey]
        # So we get the direction of the noise and multiply by the heigth/2 and plus to the points
        positive_points = []
        # Calculate the sum to each point
        normal_with_module = GeoMath.vecScalarProduct(normal, height / 2)
        for point in transformed_points:
            positive_points.append(GeoMath.vecPlus(point, normal_with_module))
        logging.debug("Generated pattern finish: " + str(positive_points))

        dirWithModule = GeoMath.vecSub(pointF, pointI)
        # normal points size wavelenght
        pattern = GlassPatternDynamic(normal, positive_points,
                                      [dirWithModule[0], dirWithModule[1]],
                                      wavelength)

        return pattern
Ejemplo n.º 7
0
    def calculate_bounding_box_tangent_space(self):
        # Calculate bounding box in tangent space
        points_tangent_space = self.get_points_tangent_space()
        self.x_min_tangent = points_tangent_space[0][0]
        self.x_max_tangent = points_tangent_space[0][0]
        self.y_min_tangent = points_tangent_space[0][1]
        self.y_max_tangent = points_tangent_space[0][1]
        try:
            if not (
                self.x_max_tangent > 0 and self.y_max_tangent > 0 and self.x_min_tangent > 0 and self.y_min_tangent > 0
            ):
                raise Errors.NegativeValueError(
                    "Size cant be negtive",
                    "We need a positive size to do a" + " correct management of the size" + " after in other functions",
                )
        except Errors.NegativeValueError as e:
            Errors.Error.display_exception(e)
            # MAYFIX:Non negative values?
            # exit()
        for point in points_tangent_space:
            self.x_min_tangent = min(self.x_min_tangent, point[0])
            self.y_min_tangent = min(self.y_min_tangent, point[1])
            self.x_max_tangent = max(self.x_max_tangent, point[0])
            self.y_max_tangent = max(self.y_max_tangent, point[1])

        bounding_box_space_tangent_size = GeoMath.vecSub(
            [self.x_max_tangent, self.y_max_tangent, 0], [self.x_min_tangent, self.y_min_tangent, 0]
        )

        self.set_vector_size_tangent_space(bounding_box_space_tangent_size)
Ejemplo n.º 8
0
    def contain_bounding_box_3D(self, bounding_box):
        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()

        inside = True
        if (not self.get_rectangle_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_points_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(
                list(point_tangent_space))

        for point in param_bounding_box_points_in_this_tangent_space:
            logging.debug("Rectangle tangent space" +
                          str(self.get_rectangle_tangent_space()))
            inside = GeoMath.pointInPoints(point,
                                           self.get_rectangle_tangent_space())
            if (not inside):
                break
        return inside
Ejemplo n.º 9
0
    def calculate_bounding_box_tangent_space(self):
        # Calculate bounding box in tangent space
        points_tangent_space = self.get_points_tangent_space()
        self.x_min_tangent = points_tangent_space[0][0]
        self.x_max_tangent = points_tangent_space[0][0]
        self.y_min_tangent = points_tangent_space[0][1]
        self.y_max_tangent = points_tangent_space[0][1]
        try:
            if (not (self.x_max_tangent > 0 and self.y_max_tangent > 0
                     and self.x_min_tangent > 0 and self.y_min_tangent > 0)):
                raise Errors.NegativeValueError(
                    'Size cant be negtive', 'We need a positive size to do a' +
                    ' correct management of the size' +
                    ' after in other functions')
        except Errors.NegativeValueError as e:
            Errors.Error.display_exception(e)
            # MAYFIX:Non negative values?
            # exit()
        for point in points_tangent_space:
            self.x_min_tangent = min(self.x_min_tangent, point[0])
            self.y_min_tangent = min(self.y_min_tangent, point[1])
            self.x_max_tangent = max(self.x_max_tangent, point[0])
            self.y_max_tangent = max(self.y_max_tangent, point[1])

        bounding_box_space_tangent_size = GeoMath.vecSub(
            [self.x_max_tangent, self.y_max_tangent, 0],
            [self.x_min_tangent, self.y_min_tangent, 0])

        self.set_vector_size_tangent_space(bounding_box_space_tangent_size)
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def contain_bounding_box_3D(self, bounding_box):
        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()

        inside = True
        if not self.get_rectangle_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_points_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(list(point_tangent_space))

        for point in param_bounding_box_points_in_this_tangent_space:
            logging.debug("Rectangle tangent space" + str(self.get_rectangle_tangent_space()))
            inside = GeoMath.pointInPoints(point, self.get_rectangle_tangent_space())
            if not inside:
                break
        return inside
Ejemplo n.º 12
0
    def create_3D_to_2D_rectangle(self, prim):
        try:
            if (not 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()
        tbn_class = CreateTBN.CreateTBN(prim)
        tbn_class.do(scale=True)
        tbn_matrix = tbn_class.get_tbn()
        tbn_inverse_matrix = tbn_class.get_tbn_inverse()
        temporary_list = []
        for point in self.get_points_object_space():
            point_relative = GeoMath.vecSub(
                point, tbn_class.get_point_which_is_relative())
            point_tangent_space = tbn_inverse_matrix.mulPoint3ToMatrix3(
                point_relative)
            temporary_list.append(point_tangent_space)

        self.set_points_tangent_space(temporary_list)
        self.calculate_bounding_box_tangent_space()
        #=======================================================================
        # Tranform to object space
        #=======================================================================
        rectangle_tangent_space = self.create_rectangle('tangent')
        rectangle_object_space = []
        for point_tangent_space in rectangle_tangent_space:
            point_object_space_relative = tbn_matrix.mulPoint3ToMatrix3(
                point_tangent_space)
            point_object_space = GeoMath.vecPlus(
                point_object_space_relative,
                tbn_class.get_point_which_is_relative())
            rectangle_object_space.append(point_object_space)

        self.set_rectangle_object_space(rectangle_object_space)
        bounding_box_object_space_size = GeoMath.vecSub(
            rectangle_object_space[2], rectangle_object_space[0])
        self.set_vector_size_object_space(bounding_box_object_space_size)
        self.set_rectangle_tangent_space(rectangle_tangent_space)
        self.set_edges_object_space(
            GeoMath.getEdgesFromPoints(rectangle_object_space))
        self.set_edges_tangent_space(
            GeoMath.getEdgesFromPoints(rectangle_tangent_space))
        self.tbn_class = tbn_class
    def create_grid(self, floor_):
        global FLOOR_SIZE
        reload(HouInterface)

        points = floor_.get_absolute_points()
        center = GeoMath.centerOfPoints(points)

        vec1 = GeoMath.vecSub(points[0], points[1])
        vec2 = GeoMath.vecSub(points[2], points[1])

        if (vec1[0] != 0):
            vecx = GeoMath.vecModul(vec1)
            vecz = GeoMath.vecModul(vec2)
        else:
            vecx = GeoMath.vecModul(vec2)
            vecz = GeoMath.vecModul(vec1)
        columns = vecx / TILE_SIZE
        rows = vecz / TILE_SIZE
        gridName = self.hout.showGrid('floor', center, vecx, vecz, rows, columns)

        return gridName
    def create_grid(self, floor_):
        global FLOOR_SIZE
        reload(HouInterface)

        points = floor_.get_absolute_points()
        center = GeoMath.centerOfPoints(points)

        vec1 = GeoMath.vecSub(points[0], points[1])
        vec2 = GeoMath.vecSub(points[2], points[1])

        if (vec1[0] != 0):
            vecx = GeoMath.vecModul(vec1)
            vecz = GeoMath.vecModul(vec2)
        else:
            vecx = GeoMath.vecModul(vec2)
            vecz = GeoMath.vecModul(vec1)
        columns = vecx / TILE_SIZE
        rows = vecz / TILE_SIZE
        gridName = self.hout.showGrid('floor', center, vecx, vecz, rows,
                                      columns)

        return gridName
Ejemplo n.º 15
0
    def create_3D_to_2D_rectangle(self, prim):
        try:
            if not 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()
        tbn_class = CreateTBN.CreateTBN(prim)
        tbn_class.do(scale=True)
        tbn_matrix = tbn_class.get_tbn()
        tbn_inverse_matrix = tbn_class.get_tbn_inverse()
        temporary_list = []
        for point in self.get_points_object_space():
            point_relative = GeoMath.vecSub(point, tbn_class.get_point_which_is_relative())
            point_tangent_space = tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            temporary_list.append(point_tangent_space)

        self.set_points_tangent_space(temporary_list)
        self.calculate_bounding_box_tangent_space()
        # =======================================================================
        # Tranform to object space
        # =======================================================================
        rectangle_tangent_space = self.create_rectangle("tangent")
        rectangle_object_space = []
        for point_tangent_space in rectangle_tangent_space:
            point_object_space_relative = tbn_matrix.mulPoint3ToMatrix3(point_tangent_space)
            point_object_space = GeoMath.vecPlus(point_object_space_relative, tbn_class.get_point_which_is_relative())
            rectangle_object_space.append(point_object_space)

        self.set_rectangle_object_space(rectangle_object_space)
        bounding_box_object_space_size = GeoMath.vecSub(rectangle_object_space[2], rectangle_object_space[0])
        self.set_vector_size_object_space(bounding_box_object_space_size)
        self.set_rectangle_tangent_space(rectangle_tangent_space)
        self.set_edges_object_space(GeoMath.getEdgesFromPoints(rectangle_object_space))
        self.set_edges_tangent_space(GeoMath.getEdgesFromPoints(rectangle_tangent_space))
        self.tbn_class = tbn_class
Ejemplo n.º 16
0
    def findBestPattern(self, curPoint, nextPoint, setClass, prim, patternCrack,
                         tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim):
        logging.debug("Start method finBestPattern, class Autopattern")
        global epsilon
        global primnumber
        setPat = setClass.getPatternsWavelength(self.wavelength)
        # We have to convert vector, because the patterns are defined into positive xy plane
        goodPatterns = []
        vector = GeoMath.vecSub(nextPoint, curPoint)
        vectorRotated = tbnInverse.mulPoint3ToMatrix3(vector)
        for pat in setPat:
            goodPattern = self.getPossiblePatterns(curPoint, nextPoint, setClass,
                                                    epsilon, setPat, vector,
                                                     vectorRotated, pat)
            if(goodPattern):
                goodPatterns.append(goodPattern)

        # Validate patterns with prim
        validatedPatterns = []
        for pat in goodPatterns:
            validatedPattern = self.validateAndAdjustPatterns(
                                           curPoint, nextPoint, setClass, prim,
                                            patternCrack, tbn, pointWhichIsRelative,
                                            texture, texturePrim, pat)
            if(validatedPattern):
                validatedPatterns.append(validatedPattern)

        if(not validatedPatterns):
            # Apply the joker pattern!
            vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(nextPoint, curPoint), [0, 0, 1])
            validatedPatterns.append(setClass.applyJoker(curPoint, nextPoint, vecH, vecV))
            logging.debug("End method finBestPattern, class Autopattern. State: Joker applied")
        else:
            logging.debug("End method finBestPattern, class Autopattern. State: good")

        return validatedPatterns[random.randint(0, len(validatedPatterns) - 1)]
Ejemplo n.º 17
0
 def applyJoker(self, point1, point2, vecH, vecV):
     vec = GeoMath.vecSub(point2, point1)
     dotH = GeoMath.vecDotProduct(vec, vecH) / GeoMath.vecModul(vecH)
     dotV = GeoMath.vecDotProduct(vec, vecV) / GeoMath.vecModul(vecV)
     if(math.fabs(dotH) < math.fabs(dotV)):
         normal = GeoMath.vecNormalize(vecH)
     else:
         normal = GeoMath.vecNormalize(vecV)
     norV = GeoMath.vecNormalize(vecV)
     norH = GeoMath.vecNormalize(vecH)
     sizeX = GeoMath.vecModul(GeoMath.vecScalarProduct(norH, dotH))
     sizeY = GeoMath.vecModul(GeoMath.vecScalarProduct(norV, dotV))
     pointI1 = GeoMath.vecPlus(point1, GeoMath.vecScalarProduct(norH, dotH / 2))
     pointI2 = GeoMath.vecPlus(pointI1, GeoMath.vecScalarProduct(norV, dotV))
     return WallPattern(normal, [list(point1), pointI1, pointI2, list(point2)], [sizeX, sizeY], 0)
Ejemplo n.º 18
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
Ejemplo n.º 19
0
    def checkTexture(self, texture, previousTexture, genPattern, Fpoint, nextPoint):

        tex, nearestPointIntersect, minDistance = texture.findIntersectionWithNearestTexture(genPattern.getPoints())
        logging.debug("Start method checkTexture, class Crack")
        if(tex):
            logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'Texture: ' + str(tex.get_material().get_name()))
        else:
            logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'No Texture')

        # If we found some interect point we clip the pattern to this point
        if(nearestPointIntersect):
            achieved = genPattern.clipPattern(nearestPointIntersect)
            if(not achieved):
                logging.error("No clipping achieved")
                return None, previousTexture
        else:
            return None, previousTexture
        # Now we have to ensure that the next texture is correct, because possibly the intersection
        # is correct and the next texture in pattern direction is correct, but maybe the direction
        # has changed due to the clipping of the pattern and the point clipped. The direction now is
        # the direction between point clipped-intersected with next texture and the final point of
        # the crack in prim.
        # also, in the NORMAL case, maybe the pattern intersect with his texture, because are exiting
        # from it, so we have to do a point in polygon to search what texture is the next

        # Check texture, for do that get the vector direction and do it little and do a point in
        # polygon with the texture
        nextDir = GeoMath.vecSub(Fpoint, nearestPointIntersect)
        logging.debug('next dir before', str(nextDir))
        if(GeoMath.vecModul(nextDir) > 0):
            nextDir = GeoMath.vecNormalize(nextDir)
            # make it little, not more little than the epsilon used at GeoMath pointInSegmentDistance method,
            # so we use a 10x bigger than epsilon, so 0.05
            nextDir = GeoMath.vecScalarProduct(nextDir, 0.05)
            nextPoint = GeoMath.vecPlus(nextDir, nearestPointIntersect)
            nextTex = texture.findUpperTextureContainingPoint(nextPoint)
            logging.debug('Direction and texture , next point: %s, next direction', str(nextPoint), str(nextDir))
        else:
            nextTex = None
            # We get the final point, so we not have to ensure anything


        logging.debug("End method checkTexture, class Crack")
        if(nearestPointIntersect):
            self.intersectionPoints.append(nearestPointIntersect)
        return nearestPointIntersect, nextTex
Ejemplo n.º 20
0
 def applyJoker(self, point1, point2, vecH, vecV):
     vec = GeoMath.vecSub(point2, point1)
     dotH = GeoMath.vecDotProduct(vec, vecH) / GeoMath.vecModul(vecH)
     dotV = GeoMath.vecDotProduct(vec, vecV) / GeoMath.vecModul(vecV)
     if (math.fabs(dotH) < math.fabs(dotV)):
         normal = GeoMath.vecNormalize(vecH)
     else:
         normal = GeoMath.vecNormalize(vecV)
     norV = GeoMath.vecNormalize(vecV)
     norH = GeoMath.vecNormalize(vecH)
     sizeX = GeoMath.vecModul(GeoMath.vecScalarProduct(norH, dotH))
     sizeY = GeoMath.vecModul(GeoMath.vecScalarProduct(norV, dotV))
     pointI1 = GeoMath.vecPlus(point1,
                               GeoMath.vecScalarProduct(norH, dotH / 2))
     pointI2 = GeoMath.vecPlus(pointI1,
                               GeoMath.vecScalarProduct(norV, dotV))
     return WallPattern(normal,
                        [list(point1), pointI1, pointI2,
                         list(point2)], [sizeX, sizeY], 0)
Ejemplo n.º 21
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
Ejemplo n.º 22
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
Ejemplo n.º 23
0
    def getRandomPattern(self, wavelength, pointI, pointF, normal, height=None):
        logging.debug("Class Data, method getRandomPattern")

        add_noise = Add_noise()

        # Calculate height if not get
        if(not height):
            height = self.sizey / 2
        transformed_points = add_noise.apply_noise([pointI, pointF], normal, height, True, frequency='medium')
        # Now we add the heigth for each point, because the noise lies between [-sizey/2, sizey/2]
        # and we want [0, sizey]
        # So we get the direction of the noise and multiply by the heigth/2 and plus to the points
        positive_points = []
        # Calculate the sum to each point
        normal_with_module = GeoMath.vecScalarProduct(normal, height / 2)
        for point in transformed_points:
            positive_points.append(GeoMath.vecPlus(point, normal_with_module))
        logging.debug("Generated pattern finish: " + str(positive_points))

        dirWithModule = GeoMath.vecSub(pointF, pointI)
        # normal points size wavelenght
        pattern = GlassPatternDynamic(normal, positive_points, [dirWithModule[0], dirWithModule[1]], wavelength)

        return pattern
Ejemplo n.º 24
0
    def getPossiblePatterns(self, curPoint, nextPoint, setClass, epsilon, setPat, vector, vectorRotated, pat):
        match = False
        goodPattern = None
        copyPat = pat.copy()
        vecPat = GeoMath.vecSub(copyPat.points[len(copyPat.points) - 1], copyPat.points[0])
        vecPatIn = GeoMath.vecSub(copyPat.points[0], pat.points[len(copyPat.points) - 1])
        logging.debug("Index pat %s", str(setPat.index(pat)))
        logging.debug("Vectors")
        logging.debug("Vector in prim %s", str(vector))
        logging.debug("Pattern vector %s", str(vecPat))
        logging.debug("Vector rotated %s", str(vectorRotated))
        logging.debug("Curpooint %s", str(curPoint))
        logging.debug("NextPoint %s", str(nextPoint))
        # Same length
        if (math.fabs(GeoMath.vecModul(vecPat) - GeoMath.vecModul(vectorRotated)) < epsilon):
            rest = GeoMath.vecSub(vectorRotated, vecPat)
            restIn = GeoMath.vecSub(vectorRotated, vecPatIn)
            # Same direction
            if ((GeoMath.vecModul(rest) < epsilon) or (GeoMath.vecModul(restIn) < epsilon)):
                goodPattern = copyPat
                match = True  # No same direction
            if (match == False):
                '''
            See simetry in this order:
            1-rot in z
            2-rot in y
            3-rot in x
            '''
                anglez = setClass.getRotz()
                if (anglez != 0):
                    Rzva = GeoMath.Matrix(4, 4)
                    Rzva.singleRotz(anglez)
                    copyVecPat = list(vecPat)
                    copyVecPat.append(0)
                    numRotations = 0
                    if (anglez == 0):
                        maxRot = 0
                    else:
                        maxRot = (360 / anglez) - 1
                    while numRotations < (maxRot) and not match:
                        copyVecPat = Rzva.mulPoint4ToMatrix4(copyVecPat)  # Not necesary to delete the last number in vector(which added for homogeneous)
                        restRz = GeoMath.vecSub(copyVecPat, vectorRotated)
                        restInRz = GeoMath.vecSub(GeoMath.vecSub([0, 0, 0], copyVecPat), vectorRotated)
                        numRotations += 1

                    if ((numRotations <= maxRot) and (GeoMath.vecModul(restRz) < epsilon or GeoMath.vecModul(restInRz) < epsilon)):
                        anglezTot = numRotations * anglez
                        copyPat.rotatePattern([0, 0, 1], anglezTot)
                        goodPattern = copyPat
                        match = True
                # Rotation in y if in z is not valid
                simRoty = setClass.getSimY(copyPat)
                if (not match and simRoty):
                    Ry = GeoMath.Matrix(4, 4)
                    Ry.singleRoty(180)
                    copyVecPat = list(vecPat)
                    copyVecPatIn = list(vecPatIn)
                    copyVecPat.append(0)
                    copyVecPatIn.append(0)
                    copyVecPat = Ry.mulPoint4ToMatrix4(copyVecPat)
                    copyVecPatIn = Ry.mulPoint4ToMatrix4(copyVecPatIn)  # Not necesary to delete the last number in vector(which added for homogeneous)
                    restRy = GeoMath.vecSub(copyVecPat, vectorRotated)
                    restRyIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
                    if (GeoMath.vecModul(restRy) < epsilon or (GeoMath.vecModul(restRyIn) < epsilon)):
                        copyPat.rotatePattern([0, 1, 0], 180)
                        goodPattern = copyPat
                        match = True  # Rotation in x if in z neither y is valid
                simRotx = setClass.getSimX(copyPat)
                if (not match and simRotx):
                    Rx = GeoMath.Matrix(4, 4)
                    Rx.singleRotx(180)
                    copyVecPat = list(vecPat)
                    copyVecPatIn = list(vecPatIn)
                    copyVecPat.append(0)
                    copyVecPatIn.append(0)
                    copyVecPat = Rx.mulPoint4ToMatrix4(copyVecPat)
                    copyVecPatIn = Rx.mulPoint4ToMatrix4(copyVecPatIn)  # Not necesary to delete the last number in vector(which added for homogeneous)
                    restRx = GeoMath.vecSub(copyVecPat, vectorRotated)
                    restRxIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
                    if (GeoMath.vecModul(restRx) < epsilon or (GeoMath.vecModul(restRxIn) < epsilon)):
                        copyPat.rotatePattern([1, 0, 0], 180)
                        goodPattern = copyPat
                        match = True
        return goodPattern
Ejemplo n.º 25
0
    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 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
Ejemplo n.º 27
0
 def calculate_absolute_points(self):
     translation = GeoMath.vecSub(self.get_position(), [0, 0, 0])
     new_structure = []
     for point in self.get_relative_points():
         new_structure.append(GeoMath.vecPlus(point, translation))
     self.set_absolute_points(new_structure)
Ejemplo n.º 28
0
 def calculate_absolute_points(self):
     translation = GeoMath.vecSub(self.get_position(), [0, 0, 0])
     new_structure = []
     for point in self.get_relative_points():
         new_structure.append(GeoMath.vecPlus(point, translation))
     self.set_absolute_points(new_structure)
Ejemplo n.º 29
0
    def do(self, scale=False):
        # Calcule points to tbn matrix
        self.calculatePoints()
        # Get some arbitrary vectors conected from vertices of prim

        vec1 = GeoMath.vecSub(self.get_previous_point(), self.get_point_which_is_relative())
        vec2 = GeoMath.vecSub(self.get_next_point(), self.get_point_which_is_relative())
        # logging.debug('Two arbitrary vec1 and vec2:' + str(vec1) + ' ' + str(vec2))

        # We have to know which angle reside between the two coencted vectors, to know if suposed vectors
        # in tangent space will be correct

        angle = GeoMath.vecDotProduct(vec1, vec2) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vec2))
        angle = math.acos(angle)
        angle = math.degrees(angle)
        # logging.debug('Angle between vecs:' + str(angle))

        # We put relative one arbitrary point to tangent space


        # logging.debug('Point relative:' + str(self.get_point_which_is_relative()))
        # Determine x and y vectors, now we'll have suposed horizontal and vertical vectors acording to
        # prim and direction of the crack
        hasTheNormalToY = GeoMath.vecDotProduct(list(self.get_prim().normal()), [0, 1, 0])
        # logging.debug('Has the normal to y?:' + str(hasTheNormalToY))
        if(hasTheNormalToY < (1 - epsilon) and hasTheNormalToY > (-1 + epsilon)):
            vecH, vecV = DetermineVectors.DetermineVectors.detVec(self.get_prim(), [0, 1, 0], [0, 0, 1])
            # logging.debug('Yes, it has the normal to y and vecs are:' + str(vecH) + ' ' + str(vecV))
        else:
            vecH, vecV = DetermineVectors.DetermineVectors.detVec(self.get_prim(), [0, 0, 1], [0, 0, 1])
            # logging.debug('No, it isnt has the normal to y and vecs are:' + str(vecH) + ' ' + str(vecV))
        # CHAPUZA CON NUMEROS COMPLEJOS!!! Precision de python pésima, 1.000000001>1?? no! y math.acos error
        cosAngle = GeoMath.vecDotProduct(vecH, vec1) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vecH))
        complexAngle = cmath.acos(cosAngle)
        if(complexAngle.imag == 0):
            angleBetweenDetVecAndVecH = math.acos(cosAngle)
        else:
            if(cosAngle < 0):
                angleBetweenDetVecAndVecH = math.acos(-1)
            else:
                angleBetweenDetVecAndVecH = math.acos(1)

        # Now we have to ensure that the vec1 has the same direction that the horizontal vector, if not, we
        # change and the horizontal vector will be vec2. Also we have to check if the prim is not a quad,
        # in this case we have to get the vertical vector from horizontal vector, rotating the known angle
        # between the two vectors conected in prim (in quad we know that the angle is 90 and we already have the
        # good vectors)
        if((math.fabs(angleBetweenDetVecAndVecH) < epsilon) or (math.fabs(angleBetweenDetVecAndVecH) > (math.pi - epsilon))):
            if(scale):
                x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec1))
            x = [1, 0, 0]
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            if(scale):
                y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec2))
            tbn = GeoMath.createTBNmatrix(self.get_previous_point(), self.get_point_which_is_relative(), self.get_next_point(), x, [0, 0], y)
        else:
            if(scale):
                x = [1, 0, 0]
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            if(scale):
                y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec1))
            tbn = GeoMath.createTBNmatrix(self.get_previous_point(), self.get_point_which_is_relative(), self.get_next_point(), y, [0, 0], x)
        # logging.debug('tbn: ' + str(tbn.printAttributes()))
        tbnInverse = GeoMath.Matrix(3, 3)
        tbnInverse.copy(tbn)
        tbnInverse.matrix3Inverse()

        self.set_tbn(tbn)
        self.set_tbn_inverse(tbnInverse)
Ejemplo n.º 30
0
    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
Ejemplo n.º 31
0
 def getDir(self):
     return GeoMath.vecSub(self.points[len(self.points) - 1], self.points[0])
    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
Ejemplo n.º 33
0
    def defCrack(self, prim, Ipoint, Fpoint, texturePrim):
        reload(AutoPattern)
        reload(Bresenham)
        reload(Data)
        reload(GeoMath)
        reload(HouInterface)
        global epsilon
        global primnumber
        # TEMP: only for debug the patterns
        # Size x and size y is the valor of some material with the minor wavelength(bigger pattern)
        curPoint = Ipoint
        self.patternCrack[prim] = []
        vertices = [list(p.point().position()) for p in prim.vertices()]
        print "vertices"
        print vertices
        # Convert prim to tangent space of patterns
        # Get some arbitrary vectors conected from vertices of prim
        vec1 = GeoMath.vecSub(vertices[0], vertices[1])
        vec2 = GeoMath.vecSub(vertices[2], vertices[1])
        # We have to know which angle reside between the two coencted vectors, to know if suposed vectors
        # in tangent space will be correct
        angle = GeoMath.vecDotProduct(vec1, vec2) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vec2))
        angle = math.acos(angle)
        angle = math.degrees(angle)

        # We put relative one arbitrary point to tangent space
        pointWhichIsRelative = vertices[1]
        # Determine x and y vectors, now we'll have suposed horizontal and vertical vectors acording to
        # prim and direction of the crack

        vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(Ipoint, Fpoint), [0, 0, 1])
        # CHAPUZA CON NUMEROS COMPLEJOS!!! Precision de python pésima, 1.000000001>1?? no! y math.acos error

        cosAngle = GeoMath.vecDotProduct(vecH, vec1) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vecH))
        complexAngle = cmath.acos(cosAngle)
        if(complexAngle.imag == 0):
            angleBetweenDetVecAndVecH = math.acos(cosAngle)
        else:
            if(cosAngle < 0):
                angleBetweenDetVecAndVecH = math.acos(-1)
            else:
                angleBetweenDetVecAndVecH = math.acos(1)

        #=======================================================================
        # Now we have to ensure that the vec1 has the same direction that the horizontal vector, if not, we
        # change and the horizontal vector will be vec2. Also we have to check if the prim is not a quad,
        # in this case we have to get the vertical vector from horizontal vector, rotating the known angle
        # between the two vectors conected in prim (in quad we know that the angle is 90 and we already have the
        # good vectors)
        #=======================================================================
        print "Create TBN"
        if((math.fabs(angleBetweenDetVecAndVecH) < epsilon) or (math.fabs(angleBetweenDetVecAndVecH) > (math.pi - epsilon))):
            x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec1))
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec2))
            tbn = GeoMath.createTBNmatrix(vertices[0], vertices[1], vertices[2], x, [0, 0], y)
        else:
            x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec2))
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec1))
            tbn = GeoMath.createTBNmatrix(vertices[0], vertices[1], vertices[2], y, [0, 0], x)

        print "Edn create tbn"
        tbnInverse = GeoMath.Matrix(3, 3)
        tbnInverse.copy(tbn)
        tbnInverse.matrix3Inverse()

        # Get the first material:
        print "texture get first layer"
        texture = texturePrim.getFirstLayer(Ipoint)
        nextMaterial = texture.get_material()
        print "end get material"
        # Create status of the process to show to the user
        distance_to_complete = GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint))
        ui_process_status = UIProcessStatus.UIProcessStatus('crack for prim',
                                                                distance_to_complete)
        while(GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint)) > epsilon):
            # Print status of the process
            dist = GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint))
            ui_process_status.calculate_status(dist, inverse=True)
            ui_process_status.print_status()

            genPattern = Data.GeneralPattern()
            for wavelength in nextMaterial.mat.keys():
                singleMat = nextMaterial.mat[wavelength]
                setOfTypeOfPattern = CDF.cdf([[singleMat.classesAndPercentage[k], k] for k in singleMat.classesAndPercentage.keys()])
                if(wavelength == 0):
                    nextPoint = Bresenham.Bresenham.bresenham(Ipoint, curPoint, Fpoint, setOfTypeOfPattern.getSizex(), setOfTypeOfPattern.getSizey(), prim, [1, 0, 0])
                    pat = AutoPattern.AutoPattern(curPoint, nextPoint, setOfTypeOfPattern, prim, wavelength, self.patternCrack, tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim).pattern
                genPattern.applyPattern(pat, wavelength)

            # Check texture
            previousTexture = texture
            pii, texture = self.checkTexture(texturePrim, previousTexture, genPattern, Fpoint, nextPoint)
            logging.debug('Pii defcrack: ' + str(pii))
            logging.debug('CurPoint defcrack: ' + str(curPoint))
            logging.debug('genPattern ' + str(genPattern.getPoints()))
            '''
            if(not curPoint):
                curPoint=genPattern.getLastPoint()
            '''
            curPoint = genPattern.getLastPoint()
            if(texture):
                nextMaterial = texture.get_material()
            else:
                if(not (GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint)) > epsilon)):
                    logging.error('Texture no matched, previous texture applied')
            # version 4
            self.patternCrack[prim].append(genPattern)
Ejemplo n.º 34
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
Ejemplo n.º 35
0
    def findBestPatternDynamic(self, curPoint, nextPoint, setClass, prim, patternCrack, tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim):
        '''
        Get the best dynamic pattern
        
        @param curPoint:
        @type curPoint:
        @param nextPoint:
        @type nextPoint:
        @param setClass:
        @type setClass:
        @param prim:
        @type prim:
        @param patternCrack:
        @type patternCrack:
        @param tbn:
        @type tbn:
        @param tbnInverse:
        @type tbnInverse:
        @param pointWhichIsRelative:
        @type pointWhichIsRelative:
        @param texture:
        @type texture:
        @param texturePrim:
        @type texturePrim:
        '''
        logging.debug('Class AutoPattern, method findBestPatternDinamically')
        logging.debug('cur_point: ' + str(curPoint) + "next_point: " + str(nextPoint))

        # Direction of the crack
        vector = GeoMath.vecSub(nextPoint, curPoint)
        vector_rotated = tbnInverse.mulPoint3ToMatrix3(vector)
        logging.debug("vector_rotated: " + str(vector_rotated))
        # Number of attemps to try to find a good pattern
        attempts = 2
        # Get a pattern generated dynamically
        # TODO: wavelength now only 0, but it can be any number
        wavelenght = 0
        first_point = [0, 0, 0]
        # Calculate normal of pattern
        direction = GeoMath.vecNormalize(GeoMath.vecSub(vector_rotated, first_point))
        normal_of_pattern = GeoMath.vecCrossProduct(list(prim.normal()), direction)
        pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern)
        validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)

        if(not validatedPattern):
            # Try 10 times variing random offset(seed) in the noise function to get a valid pattern
            for _ in range(attempts):
                pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern)
                validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)
                if(validatedPattern):
                    break

        if(not validatedPattern):
            # Try "attemps" times varying the random offset(seed) of the noise funcion and do the height little to
            # increase posibilities to get a valid pattern
            height = setClass.getSizey() / 2
            reduction_height = 2
            for _ in range(attempts):
                pattern = setClass.getRandomPattern(wavelenght, first_point, vector_rotated, normal_of_pattern, height)

                validatedPattern = self.validateAndAdjustPatterns(curPoint, nextPoint, setClass, prim, patternCrack, tbn, pointWhichIsRelative, texture, texturePrim, pattern)
                # Make the height half, for get more possibilities to do a good pattern
                height = height / reduction_height
                if(validatedPattern):
                    break
        if(not validatedPattern):
            # Apply the joker pattern!
            vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(nextPoint, curPoint), [0, 0, 1])
            validatedPattern = setClass.applyJoker(curPoint, nextPoint, vecH, vecV)
            logging.debug("End method finBestPatternDynamic, class Autopattern. State: Joker applied")
        else:
            logging.debug("End method finBestPatternDynamic, class Autopattern. State: good")

        return validatedPattern
Ejemplo n.º 36
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
Ejemplo n.º 37
0
    def detVec(prim, dirVec, exception):
        global epsilon
        reload(GeoMath)
        vec1 = GeoMath.vecNormalize(
            GeoMath.vecSub(list(prim.vertices()[0].point().position()),
                           list(prim.vertices()[1].point().position())))
        vec2 = GeoMath.vecNormalize(
            GeoMath.vecSub(list(prim.vertices()[2].point().position()),
                           list(prim.vertices()[1].point().position())))
        prim_normal = list(prim.normal())
        if (list(prim_normal) != [0, 1, 0]):
            # We consider that y is vertical and x horizontal
            if (math.fabs(vec1[1]) > math.fabs(vec2[1])):
                # If the vectors are dependent
                if (math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
                    # Quads!!
                    if (GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
                else:
                    vecV = vec1
                vecH = vec2
            else:
                # If the vectors are dependent
                if (math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
                    # Quads!!
                    if (GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
                else:
                    vecV = vec2
                vecH = vec1
        else:
            # We consider that x is vertical and z horizontal
            if (math.fabs(vec1[0]) > math.fabs(vec2[0])):
                # If the vectors are dependent
                if (math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec2, prim_normal, 90)
                    # Quads!!
                    if (GeoMath.vecDotProduct(vecV, vec1) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec2, prim_normal, -90)
                else:
                    vecV = vec1
                vecH = vec2
            else:
                # If the vectors are dependent
                if (math.fabs(GeoMath.vecDotProduct(vec1, vec2)) > epsilon):
                    vecV = GeoMath.rotateVecByVec(vec1, prim_normal, 90)
                    #Quads!!!
                    if (GeoMath.vecDotProduct(vecV, vec2) < -epsilon):
                        vecV = GeoMath.rotateVecByVec(vec1, prim_normal, -90)
                else:
                    vecV = vec2
                vecH = vec1

        if (GeoMath.vecDotProduct(dirVec, vecH) < 0):
            vecH = GeoMath.vecSub([0, 0, 0], vecH)
        if (GeoMath.vecDotProduct(dirVec, vecV) < 0):
            vecV = GeoMath.vecSub([0, 0, 0], vecV)
        vecH = GeoMath.vecNormalize(vecH)
        vecV = GeoMath.vecNormalize(vecV)
        return vecH, vecV
Ejemplo n.º 38
0
 def getDir(self):
     return GeoMath.vecSub(self.points[len(self.points) - 1],
                           self.points[0])