def test_specularReflection2(self): #Light light = Light(0, 0, 0, 1) # Sphere 1 c1 = Vector(0, 0, 12) s1 = Sphere(c1, 1, Color(0, 1, 0), 0) scene = Scene() scene.addObject3D(s1) scene.addLight(light) camera = Camera(Vector(0, 0, 0), Vector(0, 0, 1), 30) imagepl = Imageplane(500, 500) raytracer = RayTracer(imagepl, scene, camera) pixelRay = Ray(camera.position, Vector(0.001, 0, 1)) sphereIntersection = s1.intersection(pixelRay, 1, math.inf) arrColor = raytracer.getColorForIntersection(sphereIntersection, 0) testColor = arrColor green = Color() green.green() testValue = testColor.isBrighterOrEqualTo(green) self.assertFalse(testValue)
def deserializeCamera(self, json): cameraJSON = json["Camera"] position = self.deserializeVector(cameraJSON["position"]) pointOfView = self.deserializeVector(cameraJSON["pointOfView"]) cameraRightAngle = self.deserializeVector( cameraJSON["cameraRightAngle"]) return Camera(position, pointOfView, cameraRightAngle, math.pi / 8)
def test_diffusion1(self): #Light light = Light(0, 0, 0, 1) # Sphere 1 c1 = Vector(0, 0, 12) s1 = Sphere(c1, 1, Color(0, 1, 0), 1000) scene = Scene() scene.addObject3D(s1) scene.addLight(light) camera = Camera(Vector(0, 0, 0), Vector(0, 0, 1), 30) imagepl = Imageplane(500, 500) raytracer = RayTracer(imagepl, scene, camera) pixelRay1 = Ray(camera.position, Vector(0.001, 0, 1)) pixelRay2 = Ray(camera.position, Vector(0.01, 0, 1)) pixelRay3 = Ray(camera.position, Vector(0.02, 0, 1)) pixelRay4 = Ray(camera.position, Vector(0.03, 0, 1)) sphereIntersection1 = s1.intersection(pixelRay1, 0, 1000) sphereIntersection2 = s1.intersection(pixelRay2, 0, 1000) sphereIntersection3 = s1.intersection(pixelRay3, 0, 1000) sphereIntersection4 = s1.intersection(pixelRay4, 0, 1000) arrColor1 = raytracer.getColorForIntersection(sphereIntersection1, 0) arrColor2 = raytracer.getColorForIntersection(sphereIntersection2, 0) arrColor3 = raytracer.getColorForIntersection(sphereIntersection3, 0) arrColor4 = raytracer.getColorForIntersection(sphereIntersection4, 0) testColor1 = arrColor1 testColor2 = arrColor2 testColor3 = arrColor3 testColor4 = arrColor4 testValue3 = testColor3.isBrighterOrEqualTo(testColor4) self.assertTrue(testValue3) testValue2 = testColor2.isBrighterOrEqualTo(testColor3) self.assertTrue(testValue2) testValue1 = testColor1.isBrighterOrEqualTo(testColor2) self.assertTrue(testValue1)
def __init__(self, imageplane=Imageplane(), mainscene=Scene(), camera=Camera(), antialiasing=False): self.recursionLimit = 3 self.backgroundColor = Color(0, 0, 0) self.imageplane = imageplane self.scene = mainscene self.camera = camera self.imageAspectRatio = imageplane.width / imageplane.height self.img = numpy.zeros( (imageplane.getHeight(), imageplane.getWidth(), 3)) self.antialiasing = antialiasing
def test_largeScene(self): light = Light(0, 2, 6, 1) ambientLight = AmbientLight(0.3) # Sphere 1 c1 = Vector(.8, .5, 1.5) s1 = Sphere(c1, .4, Color(0, 1, 0), 10) # Sphere 2 c2 = Vector(.7, .1, 1.) s2 = Sphere(c2, .7, Color(0, 0, 1), 10) # Sphere 3 c3 = Vector(.4, .4, .7) s3 = Sphere(c3, .2, Color(1, 0, 0), 10) # Create Scene scene = Scene() scene.addObject3D(s1) scene.addObject3D(s2) scene.addObject3D(s3) scene.addLight(light) scene.addLight(ambientLight) camera = Camera(Vector(0, 0, 0), Vector(0, 0, 1), Vector(1, 0, 0), math.pi / 4) imagepl = Imageplane(500, 500) raytracer = RayTracer(imagepl, scene, camera) startTime = time.time() raytracer.startRayTracing() endTime = time.time() self.assertLessEqual(endTime - startTime, 200)
def test_SimpleScene(self): light = Light(0, 2, 6, 1) center = Vector(.8, .1, 1.) sphere = Sphere(center, .4, Color(1, 0, 0), 0) scene = Scene() scene.addObject3D(sphere) scene.addLight(light) camera = Camera(Vector(0, 0, 0), Vector(0, 0, 1), Vector(1, 0, 0), math.pi / 4) imagepl = Imageplane(500, 500) raytracer = RayTracer(imagepl, scene, camera) startTime = time.time() raytracer.startRayTracing() endTime = time.time() self.assertLessEqual(endTime - startTime, 100)
scene.addObject3D(cylinder) scene.addObject3D(cone) scene.addObject3D(cube) scene.addObject3D(p1) #scene.addObject3D(p2) #scene.addObject3D(p3) #scene.addObject3D(p4) #scene.addObject3D(p5) #scene.addObject3D(p6) imagepl = Imageplane(300, 300) camera = Camera(Vector(0, 0, 0), Vector(0, 0, 1), Vector(1, 0, 0), math.pi / 8) #camera = Camera(Vector(0, 10, 10), Vector(0, 0, 10), Vector(1, 0, 0), math.pi/8) #camera = Camera(Vector(10, 0, 10), Vector(0, 0, 10), Vector(0, 0, 1), math.pi / 4) #camera = Camera(Vector(3, -4, 2), Vector(0, 0, 10), Vector(1, 1, 1), math.pi / 4) #camera = Camera(Vector(-10, 0, 10), Vector(1, 0, 10), Vector(0, 0, -1), math.pi / 4) #camera = Camera(Vector(-7, 3, 8), Vector(1, 0, 5), Vector(0, 1, 0), math.pi / 4) #camera = Camera(Vector(3, 5, 10), Vector(0, 0, 7), Vector(0, 1, 0), math.pi / 4) raytrace = RayTracer(imagepl, scene, camera) plt.imsave('FirstImages.png', raytrace.startRayTracing()) #raytrace = RayTracer(imagepl, scene, camera) #plt.imsave('FirstImages2.png', raytrace.startRayTracing2()) #unittest.main()
def test_calculateAngle(self): c = Camera(Vector(0, 0, 0), Vector(1, 2, 3), Vector(1, 0, 0), 30) self.assertEqual(0.2679491924311227, c.getAngle())