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 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
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)
def mappingToPrimitive(self, prim): # If ttexture have not erasable points, return this points if (not self.get_absolute_points_not_erasable()): # If not, map to prim global primnumber global epsilon logging.debug('Start method mappingToPrimitive, class Texture') vertices = [list(p.point().position()) for p in prim.vertices()] logging.debug('Prim: ' + str(prim.number()) + ' points object space: ' + str(vertices)) # Convert prim to tangent space of patterns tbnCalculated = CreateTBN.CreateTBN(prim) tbnCalculated.do() absolutePoints = [] for point in self.get_delimited_proportions(): pRotateAndScaled = tbnCalculated.get_tbn().mulPoint3ToMatrix3( point) pointInPrim = GeoMath.vecPlus( tbnCalculated.get_point_which_is_relative(), pRotateAndScaled) absolutePoints.append(pointInPrim) logging.debug('Point without tbn ' + str(point)) logging.debug('Points converted ' + str(pointInPrim)) self.set_absolute_points(absolutePoints) else: self.set_absolute_points(self.get_absolute_points_not_erasable()) self.prim = prim
def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False): try: if not self.get_prim(): raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after") except Errors.CantBeNoneError as e: Errors.Error.display_exception(e) exit() if not self.get_points_tangent_space(): self.create_3D_to_2D_rectangle(self.get_prim()) this_point_relative = self.get_tbn_class().get_point_which_is_relative() this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse() param_bounding_box_points_in_this_tangent_space = [] for point in bounding_box.get_rectangle_object_space(): point_relative = GeoMath.vecSub(point, this_point_relative) this_tbn_inverse_matrix.printAttributes() point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative) param_bounding_box_points_in_this_tangent_space.append(point_tangent_space) intersections = GeoMath.getIntersectionsBetweenEdges2D( GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space), ) if DISPLAY: # TEMP: exit 1 / 0 exit() for intersection in intersections: this_tbn_matrix = self.get_tbn_class().get_tbn() point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection) point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative) self.to_display_intersections.append(point_absolute) self.display_intersections() return intersections
def mappingToPrimitive(self, prim): # If ttexture have not erasable points, return this points if(not self.get_absolute_points_not_erasable()): # If not, map to prim global primnumber global epsilon logging.debug('Start method mappingToPrimitive, class Texture') vertices = [list(p.point().position()) for p in prim.vertices()] logging.debug('Prim: ' + str(prim.number()) + ' points object space: ' + str(vertices)) # Convert prim to tangent space of patterns tbnCalculated = CreateTBN.CreateTBN(prim) tbnCalculated.do() absolutePoints = [] for point in self.get_delimited_proportions(): pRotateAndScaled = tbnCalculated.get_tbn().mulPoint3ToMatrix3(point) pointInPrim = GeoMath.vecPlus(tbnCalculated.get_point_which_is_relative(), pRotateAndScaled) absolutePoints.append(pointInPrim) logging.debug('Point without tbn ' + str(point)) logging.debug('Points converted ' + str(pointInPrim)) self.set_absolute_points(absolutePoints) else: self.set_absolute_points(self.get_absolute_points_not_erasable()) self.prim = prim
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
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)
def intersect_bounding_box_with_limits_3D(self, bounding_box, DISPLAY=False): try: if (not self.get_prim()): raise Errors.CantBeNoneError( 'Prim cant be none', 'We need a prim to calculate tbn some steps after') except Errors.CantBeNoneError as e: Errors.Error.display_exception(e) exit() if (not self.get_points_tangent_space()): self.convert_3D_to_2D(self.get_prim()) this_point_relative = self.get_tbn_class().get_point_which_is_relative( ) this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse() param_bounding_box_points_in_this_tangent_space = [] for point in bounding_box.get_rectangle_object_space(): point_relative = GeoMath.vecSub(point, this_point_relative) point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3( point_relative) param_bounding_box_points_in_this_tangent_space.append( point_tangent_space) intersections = GeoMath.getIntersectionsBetweenEdges2D(self.get_edges_tangent_space(), \ GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)) #======================================================================= # work in object space because we only has to know if the bounding boxes # share some edge between #======================================================================= edges_shared_between_bounding_boxes = \ GeoMath.getEdgesBetweenEdges(self.get_edges_tangent_space(), \ GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)) if (DISPLAY): # TEMP: exit 1 / 0 exit() for intersection in intersections: this_tbn_matrix = self.get_tbn_class().get_tbn() point_object_space = this_tbn_matrix.mulPoint3ToMatrix3( intersection) point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative) self.to_display_intersections.append(point_absolute) self.display_intersections() return intersections, edges_shared_between_bounding_boxes
def 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 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
def intersect_bounding_box_with_limits_3D(self, bounding_box, DISPLAY=False): try: if not self.get_prim(): raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after") except Errors.CantBeNoneError as e: Errors.Error.display_exception(e) exit() if not self.get_points_tangent_space(): self.convert_3D_to_2D(self.get_prim()) this_point_relative = self.get_tbn_class().get_point_which_is_relative() this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse() param_bounding_box_points_in_this_tangent_space = [] for point in bounding_box.get_rectangle_object_space(): point_relative = GeoMath.vecSub(point, this_point_relative) point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative) param_bounding_box_points_in_this_tangent_space.append(point_tangent_space) intersections = GeoMath.getIntersectionsBetweenEdges2D( self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space) ) # ======================================================================= # work in object space because we only has to know if the bounding boxes # share some edge between # ======================================================================= edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges( self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space) ) if DISPLAY: # TEMP: exit 1 / 0 exit() for intersection in intersections: this_tbn_matrix = self.get_tbn_class().get_tbn() point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection) point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative) self.to_display_intersections.append(point_absolute) self.display_intersections() return intersections, edges_shared_between_bounding_boxes
def intersect_bounding_box_3D(self, bounding_box, DISPLAY=False): try: if (not self.get_prim()): raise Errors.CantBeNoneError( 'Prim cant be none', 'We need a prim to calculate tbn some steps after') except Errors.CantBeNoneError as e: Errors.Error.display_exception(e) exit() if (not self.get_points_tangent_space()): self.create_3D_to_2D_rectangle(self.get_prim()) this_point_relative = self.get_tbn_class().get_point_which_is_relative( ) this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse() param_bounding_box_points_in_this_tangent_space = [] for point in bounding_box.get_rectangle_object_space(): point_relative = GeoMath.vecSub(point, this_point_relative) this_tbn_inverse_matrix.printAttributes() point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3( point_relative) param_bounding_box_points_in_this_tangent_space.append( point_tangent_space) intersections = GeoMath.getIntersectionsBetweenEdges2D( GeoMath.getEdgesFromPoints(self.get_rectangle_tangent_space()), GeoMath.getEdgesFromPoints( param_bounding_box_points_in_this_tangent_space)) if (DISPLAY): # TEMP: exit 1 / 0 exit() for intersection in intersections: this_tbn_matrix = self.get_tbn_class().get_tbn() point_object_space = this_tbn_matrix.mulPoint3ToMatrix3( intersection) point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative) self.to_display_intersections.append(point_absolute) self.display_intersections() return intersections
def 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 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
def calculate_tubes_position(self): for floor in self.floor_structure.get_floors(): center = GeoMath.centerOfPoints(floor.get_absolute_points()) # ================================================================== # Guess how many tubes for each part. We divide the floor into 4 parts # in a half in x direction and in a half in z direction. # ================================================================== boun = GeoMath.boundingBox(floor.get_absolute_points()) height_x_tubes = boun.sizevec()[2] height_z_tubes = boun.sizevec()[0] orientation_x_tubes = "z" orientation_z_tubes = "x" size_x_half_section = boun.sizevec()[0] / 2.0 put_tube_each_x = self.extract_parm_from_user_restrictions( "tube_default_put_each_x", DEFAULT_PUT_TUBE_EACH_X ) n_tubes_x_half_section = int(math.floor(size_x_half_section / put_tube_each_x)) size_z_half_section = boun.sizevec()[2] / 2.0 put_tube_each_z = self.extract_parm_from_user_restrictions( "tube_default_put_each_z", DEFAULT_PUT_TUBE_EACH_Z ) n_tubes_z_half_section = int(math.floor(size_z_half_section / put_tube_each_z)) # The first time putting tubes in x we put a tube in the middle tube_instance = tube.Tube(self.tube_params, center, height_x_tubes, orientation_x_tubes) self.tubes["x"].append(tube_instance) # To the right in x, so we will adding 'x' value to the center # point increment = [put_tube_each_x, 0, 0] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_x_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_x_tubes, orientation_x_tubes) self.tubes["x"].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # To the left increment = [-put_tube_each_x, 0, 0] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_x_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_x_tubes, orientation_x_tubes) self.tubes["x"].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # The first time putting tubes in z we put a tube in the middle tube_instance = tube.Tube(self.tube_params, center, height_z_tubes, orientation_z_tubes) self.tubes["z"].append(tube_instance) # To the right in x, so we will adding 'x' value to the center # point increment = [0, 0, put_tube_each_z] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_z_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_z_tubes, orientation_z_tubes) self.tubes["z"].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # To the left increment = [0, 0, -put_tube_each_z] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_z_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_z_tubes, orientation_z_tubes) self.tubes["z"].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment)
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')
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)
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)
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')
def calculate_tubes_position(self): for floor in self.floor_structure.get_floors(): center = GeoMath.centerOfPoints(floor.get_absolute_points()) #================================================================== # Guess how many tubes for each part. We divide the floor into 4 parts # in a half in x direction and in a half in z direction. #================================================================== boun = GeoMath.boundingBox(floor.get_absolute_points()) height_x_tubes = boun.sizevec()[2] height_z_tubes = boun.sizevec()[0] orientation_x_tubes = 'z' orientation_z_tubes = 'x' size_x_half_section = boun.sizevec()[0] / 2.0 put_tube_each_x = self.extract_parm_from_user_restrictions( 'tube_default_put_each_x', DEFAULT_PUT_TUBE_EACH_X) n_tubes_x_half_section = int( math.floor(size_x_half_section / put_tube_each_x)) size_z_half_section = boun.sizevec()[2] / 2.0 put_tube_each_z = self.extract_parm_from_user_restrictions( 'tube_default_put_each_z', DEFAULT_PUT_TUBE_EACH_Z) n_tubes_z_half_section = int( math.floor(size_z_half_section / put_tube_each_z)) # The first time putting tubes in x we put a tube in the middle tube_instance = tube.Tube(self.tube_params, center, height_x_tubes, orientation_x_tubes) self.tubes['x'].append(tube_instance) # To the right in x, so we will adding 'x' value to the center # point increment = [put_tube_each_x, 0, 0] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_x_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_x_tubes, orientation_x_tubes) self.tubes['x'].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # To the left increment = [-put_tube_each_x, 0, 0] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_x_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_x_tubes, orientation_x_tubes) self.tubes['x'].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # The first time putting tubes in z we put a tube in the middle tube_instance = tube.Tube(self.tube_params, center, height_z_tubes, orientation_z_tubes) self.tubes['z'].append(tube_instance) # To the right in x, so we will adding 'x' value to the center # point increment = [0, 0, put_tube_each_z] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_z_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_z_tubes, orientation_z_tubes) self.tubes['z'].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment) # To the left increment = [0, 0, -put_tube_each_z] tube_center = GeoMath.vecPlus(center, increment) for _ in range(n_tubes_z_half_section): tube_instance = tube.Tube(self.tube_params, tube_center, height_z_tubes, orientation_z_tubes) self.tubes['z'].append(tube_instance) tube_center = GeoMath.vecPlus(tube_center, increment)
def intersect_bounding_box_without_limits_3D(self, bounding_box, DISPLAY=False): global littleEpsilon try: if not self.get_prim(): raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after") except Errors.CantBeNoneError as e: Errors.Error.display_exception(e) exit() if not self.get_points_tangent_space(): self.convert_3D_to_2D(self.get_prim()) this_point_relative = self.get_tbn_class().get_point_which_is_relative() this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse() param_bounding_box_points_in_this_tangent_space = [] for point in bounding_box.get_rectangle_object_space(): point_relative = GeoMath.vecSub(point, this_point_relative) point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative) param_bounding_box_points_in_this_tangent_space.append(point_tangent_space) intersections = GeoMath.getIntersectionsBetweenEdges2D( self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space) ) if intersections: # =============================================================== # Check if the limits are touching and if it are touching it, # check if the intersection is in there. If it is in there, # the intersection lie in the limit, so we dont consider an # intersection # =============================================================== edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges( self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space), ) inside = False print "Edges shared between" print edges_shared_between_bounding_boxes for intersection in intersections: inside = GeoMath.pointInEdges(intersection, edges_shared_between_bounding_boxes) if not inside: break # =============================================================== # If all intersections lie in the edges shared between bounding # boxes we discart its # =============================================================== if inside: intersections = [] else: # check if intersections are in the corner, because we consider corner as limit shared_points_between_bounding_boxes = GeoMath.getSharedPoints( self.get_rectangle_tangent_space(), param_bounding_box_points_in_this_tangent_space ) # If all intersections lie in the corner we doen't consider intersections as intersections true_intersections = list(intersections) for intersection in intersections: for corner in shared_points_between_bounding_boxes: if GeoMath.vecModul(GeoMath.vecSub(corner, intersection)) <= littleEpsilon: true_intersections.remove(intersection) break intersections = true_intersections if DISPLAY: # TEMP: exit 1 / 0 exit() for intersection in intersections: this_tbn_matrix = self.get_tbn_class().get_tbn() point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection) point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative) self.to_display_intersections.append(point_absolute) self.display_intersections() return intersections
def intersect_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