def create_pyramid(): primitives = [] # create the sphere primitive material = None object_to_world = Transform() world_to_object = Transform() sphere = Sphere(object_to_world, world_to_object, False, 1.0, -1.0, 1.0, 360) primitive = GeometricPrimitive(sphere, material, None) # now create the instances # create the objects, with this layout (shown in 2D) # O O O O level 0, width 4, pos_x -6 # O O O level 1, width 3, pos_x -4 # O O level 2, width 2, pos_x -2 # O level 3, width 1, pos_x 0 for level in range(4): width_array = 4 - level start_pos = Point(-2.0 * (3 - level), -2.0 * (3 - level), level * 2.0) for i in range(width_array): start_pos_i = start_pos + i * Vector(2.0, 0.0, 0.0) for j in range(width_array): pos = start_pos_i + j * Vector(0.0, 2.0, 0.0) transform = translate(pos).inverse() world_to_primitive = AnimatedTransform(transform, 0.0, transform, 1.0) instance = TransformedPrimitive(primitive, world_to_primitive) primitives.append(instance) return primitives
def test__get_invert_by_transpose_(self): foo1 = Transform.create_rot_z(math.radians(90)) foo2 = Transform.create_identity() foo3 = foo1.mat * foo1.mat_inv self.assertEqual(foo3, foo2.mat)
def test__get_invert__(self): from core.transform import Transform foo0 = Transform.create_rot_z(math.radians(90)) foo1 = Transform.create_identity() foo2 = foo0.get_invert() foo3 = foo0 * foo2 self.assertEqual(foo3, foo1)
def __init__(self, object_to_world, world_to_object, reverse_orientation): """Constructs a Shape.""" self.object_to_world = Transform.from_transform(object_to_world) self.world_to_object = Transform.from_transform(world_to_object) self.reverse_orientation = reverse_orientation self.transform_swap_handedness = object_to_world.swap_handedness() self.shape_id = Shape._get_shape_id()
def __init__(self, cam2world: Transform, projection_matrix: Transform, screen_window: [float]*4, shutter_open: float, shutter_close: float, lensr: float, focald: float, film: Film): super().__init__(cam2world, shutter_open, shutter_close, film) self.cameraToScreen = projection_matrix self.screenToRaster = \ Transform.create_translate(-screen_window[0], -screen_window[3], 0.0) * \ Transform.create_scale(1.0 / (screen_window[1] - screen_window[0]), 1.0 / (screen_window[2] - screen_window[3]), 1.0) * \ Transform.create_scale(film.width, film.height, 1.0) self.rasterToScreen = Transform.get_invert(self.screenToRaster) self.rasterToCamera = self.rasterToScreen * Transform.get_invert(self.cameraToScreen) self.lensRadius = lensr self.focalDistance= focald
def test__perspective(self): from core.transform import Transform from maths.vector3d import Vector3d p = Vector3d(0.0, 0.0, 500.0) t = Transform.create_perspective(60.0, 1000.0) a = p * t self.assertEqual(a, Vector3d(0.0, 0.0, 0.5)) p = Vector3d(0.0, 0.0, 000.0) t = Transform.create_perspective(60.0, 1000.0) print(p*t) self.assertEqual(p * t, Vector3d(0.0, 0.0, 1.0))
def __init__(self): """Default constructor for Intersection.""" self.dg = DifferentialGeometry() self.primitive = None self.world_to_object = Transform() self.object_to_world = Transform() self.shape_id = 0 self.primitive_id = 0 self.ray_epsilon = 0.0
def Sample2(self, p: Point3d, u: (float, float), Ns: Normal) -> Point3d: # Compute coordinate system for sphere sampling Pcenter = Point3d(0, 0, 0) * self.objectToWorld wc = (Pcenter - p).get_normalized() wcX, wcY = Transform.create_coordinateSystem(wc) # Sample uniformly on sphere if $\pt{}$ is inside it if (p - Pcenter).get_length_squared() - self.radius * self.radius < 1e-40: return self.Sample1(u, Ns) # Sample sphere uniformly inside subtended cone sinThetaMax2 = self.radius * self.radius / (p - Pcenter).get_length_squared() cosThetaMax = math.sqrt(max(0.0, 1.0 - sinThetaMax2)) dgSphere = DifferentialGeometry() thit = 1.0 r = Ray(p, UniformSampleCone2(u, cosThetaMax, wcX, wcY, wc), 1e-3) b, t = self.get_intersection(r, dgSphere) # if not b: #bug thit = Vector3d.dot(Pcenter - p, r.direction.get_normalized()) ps = r.get_at(thit) nn = (ps - Pcenter).get_normalized() Ns.Set(nn) # if (ReverseOrientation) *ns *= -1.f; return ps
def test_mul_transform(self): #=========================================== point3d * transform foo1 = Point3d(0.0, 0.0, 0.0) foo2 = Transform.create_translate(1.0, 2.0, 3.0) foo3 = foo1 * foo2 self.assertEqual(foo3, Point3d(1.0, 2.0, 3.0))
def test_mul_transform(self): #=========================================== Vector4 * transform(tr) foo1 = Vector4d(0.0, 0.0, 0.0, 1.0) foo2 = Transform.create_translate(1.0, 2.0, 3.0) foo3 = foo1 * foo2 self.assertEqual(foo3.x, 1.0) self.assertEqual(foo3.y, 2.0) self.assertEqual(foo3.z, 3.0) #=========================================== Vector4 * transform(rtZ 90) foo1 = Vector4d(0.0, 1.0, 0.0, 1.0) foo2 = Transform.create_rot_z(math.radians(90)) foo3 = foo1 * foo2 self.assertEqual(foo3, Vector4d(-1.0, 0.0, 0.0, 1.0))
def __init__(self, dg: DifferentialGeometry, ngeom: Normal): self.bxdfs = list() self.dgShading = dg self.ng = ngeom self.nn = self.dgShading.normal # self.sn = self.dgShading.normal # self.tn = Vector3d.cross(self.nn, self.sn) self.sn, self.tn = Transform.create_coordinateSystem(self.nn)
def test__orthographic(self): from core.transform import Transform from maths.vector3d import Vector3d t = Transform.create_orthographic(0.0, 1000.0) p = Vector3d(0.0, 0.0, 500.0) self.assertEqual(p * t, Vector3d(0.0, 0.0, 0.5)) p = Vector3d(5.0, 5.0, 1000.0) self.assertEqual(p * t, Vector3d(5.0, 5.0, 1.0))
def test_inverse(self): m1 = scale(2.0, 3.0, 4.0) m2 = scale(1.0/2.0, 1.0/3.0, 1.0/4.0) self.assertEqual(m1.inverse(), m2) self.assertEqual(m1.m_inv, m2.m) self.assertEqual(m2.m_inv, m1.m) m3 = translate(Point(5, 6, 7)) * scale(2, -3 , 4) * rotate(17, Vector(-1, 4, -2)) m4 = m3.inverse() identity = Transform() self.assertTrue((m3*m4).is_identity()) self.assertTrue((m4*m3).is_identity())
def create_spotLight(paramSet: ParamSet, light2world: Transform) -> PointLight: from maths.matrix44 import Matrix44 from maths.vector4d import Vector4d I = paramSet.find_spectrum("I", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) coneangle = paramSet.find_float("coneangle", 30.0) conedelta = paramSet.find_float("conedeltaangle", 5.0) # Compute spotlight world to light transformation frome = paramSet.find_point("from", Point3d(0.0, 0.0, 0.0)) to = paramSet.find_point("to", Point3d(0.0, 0.0, 1.0)) direction = (to - frome).get_normalized() du, dv = Transform.create_coordinateSystem(dir) m = Matrix44.create_from_vector4d( Vector4d(du.x, du.y, du.z, 0.0), Vector4d(dv.x, dv.y, dv.z, 0.0), Vector4d(direction.x, direction.y, direction.z, 0.0), Vector4d(0.0, 0.0, 0.0, 1.0)) dirToZ = Transform(m) light2world = light2world * Transform.create_translate(frome.ex, frome.ey, frome.ez) * dirToZ.get_invert() return SpotLight(light2world, I * sc, coneangle, coneangle - conedelta)
def test_set_to_identity(self): from core.transform import Transform foo = Transform.create_identity() for i in range(0, 4): for j in range(0, 4): if i == j: self.assertEqual(foo.mat[i][j], 1.0) self.assertEqual(foo.mat_inv[i][j], 1.0) else: self.assertEqual(foo.mat[i][j], 0.0) self.assertEqual(foo.mat_inv[i][j], 0.0)
def test__look_at(self): from core.transform import Transform from maths.point3d import Point3d from maths.vector3d import Vector3d pos = Point3d(1.0, 0.0, 0.0) at = Point3d(1.0, 0.0, 1.0) up = Vector3d.get_up() t = Transform.create_look_at(pos, at, up) foo = Vector3d(1.0, 0.0, 0.0) self.assertEqual(foo * t, Vector3d(0.0, 0.0, 0.0))
def test__mat_invert_(self): foo1 = Transform.create_translate(10.0,2.0,3.0) foo2 = Transform.create_rot_x(math.radians(37)) foo3 = Transform.create_translate(1.0,-2.0,-6.0) foo4 = Transform.create_rot_y(math.radians(7)) foo5 = Transform.create_translate(1.0,7.0,2.0) foo6 = Transform.create_rot_z(math.radians(137)) foo7 = foo1 * foo2 * foo3 * foo4 * foo5 * foo6 self.assertEqual(foo7.mat.get_invert(), foo7.mat_inv) self.assertEqual(foo7.mat_inv, foo7.mat_inv)
def __init__(self): self.filterName = None self.filterParams = ParamSet() self.filmName = None self.filmParams = ParamSet() self.samplerName = None self.samplerParams = ParamSet() self.acceleratorName = None self.acceleratorParams = ParamSet() self.rendererName = None self.rendererParams = ParamSet() self.surfIntegratorName = None self.surfIntegratorParams = ParamSet() self.volIntegratorName = None self.volIntegratorParams = ParamSet() self.cameraName = None self.cameraParams = ParamSet() self.primitives = [] self.instances = [] self.cameraToWorld = Transform.create_identity() self.volumeRegions = [] self.lights = []
def __init__(self, name, vertices, vertex_indices, normals, normal_indices, transform=None): self.name = name # we have triangle mesh assert len(vertex_indices) % 3 == 0 assert len(normal_indices) == len(vertex_indices) self.v = np.array(vertices, dtype=np.single) self.n = np.array(normals, dtype=np.single) self.vi = np.array(vertex_indices, dtype=np.uint32) self.ni = np.array(normal_indices, dtype=np.uint32) + len(vertices) self.coords = np.concatenate((self.v, self.n)) self.indices = np.concatenate((self.vi, self.ni)) self.normal_index_offset = len(vertex_indices) self.transform = transform or Transform()
def test__get_real_invert_(self): foo1 = Transform.create_translate(1.0,2.0,3.0) foo2 = foo1.mat.get_invert() self.assertEqual(foo2, foo1.mat_inv)
import logging from core.extract import Extract from core.load import Load from core.transform import Transform from utils.file_tools import FileTools from utils import log_tools log_tools.ajustar_log() transform = Transform(key_google_maps='key') load = Load() file_tools = FileTools() file_tools.diretorio_arquivos = 'resources' file_tools.diretorio_arquivos_movidos = 'resources/arquivos_extraidos' while True: logging.info(f'Escaneando diretório: ({file_tools.diretorio_arquivos})') arquivos = file_tools.escanear_diretorio(intervalo=0.5) if len(arquivos) > 0: logging.info(f'Arquivo txt encontrado: ({arquivos[0]})') lista_de_coordenadas = Extract('resources/' + arquivos[0]).get_lista_de_coordenadas() logging.info(f'Extraído conteúdo do arquivo: ({arquivos[0]})') for latitude, longitude in lista_de_coordenadas:
def __init__(self): self.transform = Transform(Transform.create_identity(), Transform.create_identity())
def pbrtWorldBegin(): global curTransform for i in range(len(curTransform)): curTransform[i] = Transform.create_identity()
def __init__(self, l2w: Transform, samples_count: int=1): self.lightToWorld = l2w self.worldToObject = l2w.get_invert() self.samples_count = max(1, samples_count)
def pbrtScale(sx: float, sy: float, sz: float): global curTransform for i in range(len(curTransform)): curTransform[i] = curTransform[i] * Transform.create_scale(sx, sy, sz)
def pbrtLookAt(e: Vector3d, l: Vector3d, u: Vector3d): global curTransform for i in range(len(curTransform)): curTransform[i] = curTransform[i] * Transform.create_look_at(e, l, u)
def pbrtTranslate(dx: float, dy: float, dz: float): global curTransform for i in range(len(curTransform)): curTransform[i] = curTransform[i] * Transform.create_translate(dx, dy, dz)
def pbrtRotate(angle: float, ax: float, ay: float, az: float): global curTransform for i in range(len(curTransform)): curTransform[i] = curTransform[i] * Transform.create_rotate(angle, Vector3d(ax, ay, az))
def test___mul__(self): from core.transform import Transform from maths.matrix44 import Matrix44 from maths.vector4d import Vector4d # //////////////////////////////////////////////////////I *I = I foo1 = Transform.create_identity() foo2 = Transform.create_identity() foo3 = foo1 * foo2 for i in range(0, 4): for j in range(0, 4): if i == j: self.assertEqual(foo3.mat[i][j], 1.0) self.assertEqual(foo3.mat_inv[i][j], 1.0) else: self.assertEqual(foo3.mat[i][j], 0.0) self.assertEqual(foo3.mat_inv[i][j], 0.0) #//////////////////////////////////////////////////////Ta * Tb = Tab foo1 = Transform.create_translate(1.0, 0.0, 0.0) foo2 = Transform.create_translate(0.0, 2.0, 0.0) foo0 = foo1 * foo2 for i in range(0, 3): for j in range(0, 4): if i == j: self.assertEqual(foo3.mat[i][j], 1.0) else: self.assertEqual(foo3.mat[i][j], 0.0) self.assertEqual(foo0.mat[3][0], 1.0) self.assertEqual(foo0.mat[3][1], 2.0) self.assertEqual(foo0.mat[3][2], 0.0) self.assertEqual(foo0.mat[3][3], 1.0) self.assertEqual(foo0.mat[3], Vector4d(1.0, 2.0, 0.0, 1.0)) #//////////////////////////////////////////////////////RotXa * RotXb = RotXab foo0 = Transform.create_rot_x(math.radians(90)) foo1 = Transform.create_rot_x(math.radians(45)) foo2 = Transform.create_rot_x(math.radians(45)) foo3 = foo1 * foo2 self.assertEqual(foo0, foo3) #//////////////////////////////////////////////////////RotZ(a) * RotZ(-a) = I foo0 = Transform.create_rot_z(math.radians(90)) foo1 = Transform.create_rot_z(math.radians(-90)) foo2 = foo0 * foo1 foo3 = Transform.create_identity() self.assertEqual(foo2, foo3) #//////////////////////////////////////////////////////Tr(a) * Tr(-a) = I foo0 = Transform.create_translate(1.0, 0.0, 0.0) foo1 = Transform.create_translate(-1.0, 0.0, 0.0) foo2 = foo0 * foo1 foo3 = Transform.create_identity() self.assertEqual(foo2, foo3) #//////////////////////////////////////////////////////RotXa * T = RotXab foo0 = Transform.create_translate(1.0, 2.0, 3.0) foo1 = Transform.create_rot_x(math.radians(90)) foo2 = Transform.create_rot_z(math.radians(22)) foo3 = Transform.create_translate(1.0, 2.0, 3.0) foo4 = foo0 * foo1 * foo2 * foo3 self.assertEqual(foo4.mat_inv, foo4.mat.get_invert())
def create_light_point(paramSet: ParamSet, light2world: Transform) -> PointLight: I = paramSet.find_spectrum("I", Spectrum(1.0)) sc = paramSet.find_spectrum("scale", Spectrum(1.0)) P = paramSet.find_point("from", Point3d(0.0, 0.0, 0.0)) l2w = Transform.create_translate(P.x, P.y, P.z) * light2world return PointLight(l2w, I * sc)
from samplers.bestcandidateSampler import BestcandidateSampler from samplers.haltonSampler import HaltonSampler from samplers.lowdiscrepancySampler import LowDiscrepancySampler from samplers.randomSampler import RandomSampler from samplers.stratifiedSampler import StratifiedSampler from shapes.plane import Plane from shapes.sphere import Sphere from shapes.triangle import TriangleMesh from surface_integrator.ambient_occlusion_integrator import AmbientOcclusionIntegrator from surface_integrator.direct_lighting_integrator import DirectLightingIntegrator from surface_integrator.path import PathIntegrator from textures.constant_texture import ConstantTexture renderOptions = RenderOptions() curTransform = [Transform.create_identity()] namedCoordinateSystems = {} pushedActiveTransformBits = [] pushedTransforms = [] graphicsState = GraphicsState() pushedGraphicsStates = [GraphicsState()] # ==========================camera def create_environment_camera(paramset: ParamSet, cam2world: Transform, film: Film) -> EnvironmentCamera: return None def create_perspective_camera(paramset: ParamSet, cam2world: Transform, film: Film) -> PerspectiveCamera: shutteropen = paramset.find_float("shutteropen", 0.0) shutterclose = paramset.find_float("shutterclose", 1.0)
def __init__(self, cam2world: Transform, screen_window: [float]*4, shutter_open: float, shutter_close: float, lensr: float, focald: float, fov: float, film: Film): super().__init__(cam2world, Transform.create_orthographic(0.0, 1.0), screen_window, shutter_open, shutter_close, lensr, focald, film) self.dxCamera = (Point3d(1.0, 0.0 ,0.0) * self.rasterToCamera) - (Point3d(0.0, 0.0, 0.0) * self.rasterToCamera) self.dyCamera = (Point3d(0.0, 1.0 ,0.0) * self.rasterToCamera) - (Point3d(0.0, 0.0, 0.0) * self.rasterToCamera)
def test___mul__(self): # ///////////////////////////////////////////__mul__ float foo1 = Vector4d(1.0, 2.0, 3.0, 4.0) foo2 = foo1 * 2.0 self.assertEqual(foo2, Vector4d(2.0, 4.0, 6.0, 8.0)) #///////////////////////////////////////////__imul__ float foo1 = Vector4d(1.0, 2.0, 3.0, 4.0) foo1 *= 2.0 self.assertEqual(foo1, Vector4d(2.0, 4.0, 6.0, 8.0)) #///////////////////////////////////////////__mul__ vector4d foo1 = Vector4d(1.0, 2.0, 3.0, 4.0) foo2 = Vector4d(2.0, 3.0, 4.0, 5.0) foo3 = foo1 * foo2 self.assertEqual(foo3, Vector4d(2.0, 6.0, 12.0, 20.0)) #///////////////////////////////////////////__imul__ vector4d foo1 = Vector4d(1.0, 2.0, 3.0, 4.0) foo1 *= Vector4d(2.0, 3.0, 4.0, 5.0) self.assertEqual(foo1, Vector4d(2.0, 6.0, 12.0, 20.0)) #///////////////////////////////////////////__mul__ matrix44 Rotz foo1 = Vector4d(0.0, 2.0, 0.0, 1.0) foo2 = Transform.create_rot_z(math.radians(90)) foo3 = foo1 * foo2.mat self.assertEqual(foo3, Vector4d(-2.0, 0.0, 0.0, 1.0)) foo3 = foo3 * foo2.mat self.assertEqual(foo3, Vector4d(0.0, -2.0, 0.0, 1.0)) #///////////////////////////////////////////__mul__ matrix44 Roty foo1 = Vector4d(2.0, 0.0, 0.0, 1.0) foo2 = Transform.create_rot_y(math.radians(90)) foo3 = foo1 * foo2.mat self.assertEqual(foo3, Vector4d(0.0, 0.0, -2.0, 1.0)) foo3 = foo3 * foo2.mat self.assertEqual(foo3, Vector4d(-2.0, 0.0, 0.0, 1.0)) #///////////////////////////////////////////__mul__ matrix44 Rotx foo1 = Vector4d(0.0, 2.0, 0.0, 1.0) foo2 = Transform.create_rot_x(math.radians(90)) foo3 = foo1 * foo2.mat self.assertEqual(foo3, Vector4d(0.0, 0.0, 2.0, 1.0)) foo3 = foo3 * foo2.mat self.assertEqual(foo3, Vector4d(0.0, -2.0, 0.0, 1.0)) #///////////////////////////////////////////__mul__ matrix44 Rotx * Roty * Rotz foo1 = Vector4d(2.0, 0.0, 0.0, 1.0) foo2 = Transform.create_rot_x(math.radians(90)) foo3 = Transform.create_rot_y(math.radians(90)) foo4 = Transform.create_rot_z(math.radians(90)) foo5 = foo2 * foo3 * foo4 foo6 = foo1 * foo5.mat foo7 = Vector4d(0.0, 0.0, -2.0, 1.0) self.assertEqual(foo6, foo7) #///////////////////////////////////////////__mul__ matrix44 Tr * Rotz foo1 = Vector4d(0.0, 0.0, 0.0, 1.0) foo2 = Transform.create_translate(1.0, 0.0, 0.0) foo4 = Transform.create_rot_z(math.radians(90)) foo5 = foo1 * foo2 * foo4 foo7 = Vector4d(0.0, 1.0, 0.0, 1.0) self.assertEqual(foo5, foo7)