Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
    def calculate_floors_position(self):
        logging.debug(
            'START Class FloorStructure, method calculate_floors_position')
        points_base_node = [
            list(p.position())
            for p in self.get_base_node().geometry().points()
        ]
        lowest_point = list(
            self.get_base_node().geometry().boundingBox().minvec())

        # Now we stract the points of the floor from the building
        structure_of_floor = []
        for point in points_base_node:
            # If the point has the same y position than the lowest point, the
            # point will be a floor point
            # We cant do that beacuse the points returned from geometry of houdini
            # node are ordered, and the points can be the structure of the floor
            # just as it is
            if (point[1] == lowest_point[1]):
                # Mapping to y=0
                structure_of_floor.append(list(point))

        logging.debug("Structure of floor " + str(structure_of_floor))
        #======================================================================
        # Now we want to found the lowest virtual plant with a crack primitive
        # touching it. Also we want the previous of this floor, because this
        # floor will be visible trough the hole of the next floor
        #======================================================================
        # Initialize position of the first virtual floor in the center point of the base
        virtual_floor = floor.Floor(self.get_floor_params(),
                                    structure_of_floor)
        previous_virtual_floor = virtual_floor
        connected_prims_with_crack = virtual_floor.intersections_with_crack(
            self.get_crack().patternCrack, self.get_path())
        floor_inside = virtual_floor.inside(self.get_base_node())

        # MAYFIX: structure points are the same for each floor, we assume that
        # the building have the same boundary for each floor
        increment = GeoMath.vecScalarProduct(
            [0, 1, 0],
            self.extract_parm_from_user_restrictions(
                'floor_default_put_each_y'))
        logging.debug("Increment " + str(increment))
        acumulated_increment = [0, 0, 0]
        while (not connected_prims_with_crack and floor_inside):
            logging.debug("Acumulated increment " + str(acumulated_increment))
            acumulated_increment = GeoMath.vecPlus(acumulated_increment,
                                                   increment)
            new_structure_of_floor = [
                GeoMath.vecPlus(position, acumulated_increment)
                for position in structure_of_floor
            ]
            previous_virtual_floor = virtual_floor
            virtual_floor = floor.Floor(self.get_floor_params(),
                                        new_structure_of_floor)
            connected_prims_with_crack = (
                virtual_floor.intersections_with_crack(
                    self.get_crack().patternCrack, self.get_path()))
            floor_inside = virtual_floor.inside(self.get_base_node())

        # If not inside, delete it
        if (not floor_inside):
            logging.debug("Floor_outside")
            virtual_floor = None
        #=======================================================================
        # #=======================================================================
        # # once we found the first virtual floor, we check if is it the same
        # # than the previous virtual floor. If it is the same will assign the
        # # next virtual floor possible. Then we check if this floor is outside
        # # the building. If the virtual floor reside outside building we delete it
        # # and not continue working with floors
        # #=======================================================================
        # if(previous_virtual_floor == virtual_floor):
        #    #Check if it is inside building
        #    floor_inside = virtual_floor.inside(points_base_node)
        #    #If not inside, delete it
        #    if(not floor_inside):
        #        virtual_floor = None
        #=======================================================================

        # The first floor is untouched
        destroyed_virtual_floors = [previous_virtual_floor]
        #=======================================================================
        # Now we have to create the other floors until we reached the first floor
        # outside building or not connected with crack prims
        #=======================================================================
        if (virtual_floor):
            connected_prims_with_crack = True
            floor_inside_building = True

            while (connected_prims_with_crack and floor_inside_building):
                destroyed_virtual_floors.append(virtual_floor)
                logging.debug("Acumulated increment " +
                              str(acumulated_increment))
                acumulated_increment = GeoMath.vecPlus(acumulated_increment,
                                                       increment)
                new_structure_of_floor = [
                    GeoMath.vecPlus(position, acumulated_increment)
                    for position in structure_of_floor
                ]
                previous_virtual_floor = virtual_floor
                virtual_floor = floor.Floor(self.get_floor_params(),
                                            new_structure_of_floor)
                connected_prims_with_crack = (
                    virtual_floor.intersections_with_crack(
                        self.get_crack().patternCrack, self.get_path()))
                floor_inside = virtual_floor.inside(self.get_base_node())

            # Now add the last floor if needed
            if (virtual_floor.inside(self.get_base_node())):
                destroyed_virtual_floors.append(virtual_floor)

        else:
            # Only one floor
            destroyed_virtual_floors.append(previous_virtual_floor)
        # Display floors in houdini as a cubes
        #createfloors.CreateFloors(destroyed_virtual_floors, self.get_geo())
        self.floors = destroyed_virtual_floors
        logging.debug(
            'END Class FloorStructure, method calculate_floors_position')