summaryrefslogtreecommitdiff
path: root/hw6/bin
diff options
context:
space:
mode:
Diffstat (limited to 'hw6/bin')
-rw-r--r--hw6/bin/HW1.cpp38
-rw-r--r--hw6/bin/HW2.cpp112
-rw-r--r--hw6/bin/HW3.cpp86
-rw-r--r--hw6/bin/HW4.cpp93
-rw-r--r--hw6/bin/HW5.cpp56
-rw-r--r--hw6/bin/HW6.cpp56
-rw-r--r--hw6/bin/helloworld.cpp9
-rw-r--r--hw6/bin/image_compare.cpp90
8 files changed, 540 insertions, 0 deletions
diff --git a/hw6/bin/HW1.cpp b/hw6/bin/HW1.cpp
new file mode 100644
index 0000000..8e66297
--- /dev/null
+++ b/hw6/bin/HW1.cpp
@@ -0,0 +1,38 @@
+#include <iostream>
+#include "vec3d.h"
+
+int main(int argc, char** argv)
+{
+ std::cout << "CSCI-427/527 Homework 1: Vectors" << std::endl;
+
+ vec3d a(1.0f, 0.0f, -1.0f);
+ vec3d b(-1.0f, 1.0f, 1.0f);
+
+ std::cout << "a = " << a << std::endl;
+ std::cout << "b = " << b << std::endl;
+
+ std::cout << "a+b = " << a+b << std::endl;
+ std::cout << "a-b = " << a-b << std::endl;
+ std::cout << "a*b = " << a*b << std::endl;
+ std::cout << "a/b = " << a/b << std::endl;
+ std::cout << "a*2 = " << a*2.0f << std::endl;
+ std::cout << "b/2 = " << b/2.0f << std::endl;
+
+ std::cout << "a.dot(b) = " << a.dot(b) << std::endl;
+ std::cout << "b.dot(a) = " << b.dot(a) << std::endl;
+ std::cout << "a.squared_length() = " << a.squared_length() << std::endl;
+ std::cout << "b.length() = " << b.length() << std::endl;
+ std::cout << "a.distance(b) = " << a.distance(b) << std::endl;
+ std::cout << "a.cross(b) = " << a.cross(b) << std::endl;
+ std::cout << "b.cross(a) = " << b.cross(a) << std::endl;
+ std::cout << "normalize(a) = " << normalize(a) << std::endl;
+ std::cout << "abs(a) = " << abs(a) << std::endl;
+ std::cout << "b.normalize() = " << b.normalize() << std::endl;
+ std::cout << "b.abs() = " << b.abs() << std::endl;
+
+ std::cout << "a = " << a << std::endl;
+ std::cout << "b = " << b << std::endl;
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/HW2.cpp b/hw6/bin/HW2.cpp
new file mode 100644
index 0000000..247d7d1
--- /dev/null
+++ b/hw6/bin/HW2.cpp
@@ -0,0 +1,112 @@
+#include <iostream>
+
+#include "image.h"
+#include "camera.h"
+#include "imageIO.h"
+#include "triangle.h"
+
+image generateImage(const camera& cam, const triangle& tri)
+{
+ float t;
+ vec3d barycentricCoord;
+ image result(cam.width(), cam.height());
+
+ // for each pixel
+ for(image::size_type y=0; y < result.height(); y++)
+ for(image::size_type x=0; x < result.width(); x++)
+ {
+ // generate view ray
+ ray r = cam(x,y);
+
+ // intersect triangle
+ bool hit = tri.intersect(r, barycentricCoord, t);
+
+ // draw pixel
+ if(hit)
+ result(x,y) = color(barycentricCoord.x, barycentricCoord.y, barycentricCoord.z);
+ else
+ result(x,y) = color(0.0f, 0.0f, 0.0f);
+ }
+
+ // Done.
+ return result;
+}
+
+int main(int argc, char** argv)
+{
+ // setup camera
+ camera cam( vec3d(0.0f, 0.0f, 0.0f),
+ vec3d(0.0f, 0.0f, -1.0f),
+ vec3d(0.0f, 1.0f, 0.0f),
+ 60.0f,
+ 512, 512 );
+
+ // Image 1
+ std::cout << "Generating image 1." << std::endl;
+
+ triangle t1( vec3d(1.0f, -1.0f, -2.0f),
+ vec3d(0.0f, 1.0f, -2.0f),
+ vec3d(-1.0f, -1.0f, -2.0f) );
+
+ image result1 = generateImage(cam, t1);
+ exportImage("HW2-result1.ppm", result1);
+
+
+ // Image 2
+ std::cout << "Generating image 2." << std::endl;
+
+ triangle t2( vec3d(1.0f, -1.0f, 2.0f),
+ vec3d(0.0f, 1.0f, 2.0f),
+ vec3d(-1.0f, -1.0f, 2.0f) );
+
+ image result2 = generateImage(cam, t2);
+ exportImage("HW2-result2.ppm", result2);
+
+
+ // Image 3
+ std::cout << "Generating image 3." << std::endl;
+
+ triangle t3( vec3d(-1.0f, -1.0f, -2.0f),
+ vec3d(1.0f, -1.0f, -2.0f),
+ vec3d(0.0f, 1.0f, -2.0f) );
+
+ image result3 = generateImage(cam, t3);
+ exportImage("HW2-result3.ppm", result3);
+
+
+ // Image 4
+ std::cout << "Generating image 4." << std::endl;
+
+ triangle t4( vec3d(-1.0f, -1.0f, 2.0f),
+ vec3d(0.0f, 1.0f, 2.0f),
+ vec3d(1.0f, -1.0f, 2.0f) );
+
+ image result4 = generateImage(cam, t4);
+ exportImage("HW2-result4.ppm", result4);
+
+
+ // Image 5
+ std::cout << "Generating image 5." << std::endl;
+
+ triangle t5( vec3d(-1.0f, -1.0f, -1.0f),
+ vec3d(1.0f, -1.0f, -1.0f),
+ vec3d(1.0f, 1.0f, -1.0f) );
+
+ image result5 = generateImage(cam, t5);
+ exportImage("HW2-result5.ppm", result5);
+
+
+ // Image 6
+ std::cout << "Generating image 6." << std::endl;
+
+ triangle t6( vec3d(-1.0f, 2.0f, -1.0f),
+ vec3d(0.0f, 2.0f, 1.0f),
+ vec3d(1.0f, 2.0f, -1.0f) );
+
+ image result6 = generateImage(cam, t6);
+ exportImage("HW2-result6.ppm", result6);
+
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/HW3.cpp b/hw6/bin/HW3.cpp
new file mode 100644
index 0000000..c18c2d1
--- /dev/null
+++ b/hw6/bin/HW3.cpp
@@ -0,0 +1,86 @@
+#include <string>
+#include <chrono>
+#include <iostream>
+
+#include "util.h"
+#include "image.h"
+#include "scene.h"
+#include "imageIO.h"
+#include "sceneIO.h"
+
+image generateImage(const scene& s)
+{
+ image result(s.getCamera().width(), s.getCamera().height());
+
+ // for every pixel
+ for(image::size_type y=0; y < result.height(); y++)
+ for(image::size_type x=0; x < result.width(); x++)
+ {
+ // generate view ray
+ ray r = s.getCamera()(x,y);
+
+ // intersect scene
+ intersectionPoint ip = s.intersect(r);
+
+ // shade pixel
+ if(ip.isHit())
+ {
+ // for each light source
+ for(unsigned int l=0; l < s.numberOfLightsources(); l++)
+ {
+ // connect to light source
+ lightSample ls = s.getLightsource(l).intensityAt(ip.position());
+
+ // shade
+ result(x,y) += ip.shade(ls);
+ }
+ }
+ else result(x,y) = color(0.0f, 0.0f, 0.0f);
+ }
+
+
+ // Done.
+ return result;
+}
+
+
+
+int main(int argc, char** argv)
+{
+ // parse command line
+ if(argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <scene.xml> [scene2.xml ...]" << std::endl;
+ return -1;
+ }
+
+ // for each filename, import scene and render
+ unsigned int pos=1;
+ while(pos < argc)
+ {
+ // get filename
+ std::string filename = argv[pos++];
+
+ // import
+ std::cerr << " * Reading " << filename << std::endl;
+ scene s;
+ importScene(filename, s);
+
+ // render
+ std::cerr << " * Rendering... ";
+ auto startTime = std::chrono::system_clock::now();
+
+ image result = generateImage(s);
+
+ auto endTime = std::chrono::system_clock::now();
+ std::chrono::duration<float> duration = endTime - startTime;
+ std::cerr << duration.count() << " seconds." << std::endl;
+
+ // save image
+ std::cerr << " * Writing result." << std::endl;
+ exportImage(getFilename(filename) + ".ppm", result);
+ }
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/HW4.cpp b/hw6/bin/HW4.cpp
new file mode 100644
index 0000000..79f4ecf
--- /dev/null
+++ b/hw6/bin/HW4.cpp
@@ -0,0 +1,93 @@
+#include <string>
+#include <chrono>
+#include <iostream>
+
+#include "util.h"
+#include "image.h"
+#include "scene.h"
+#include "imageIO.h"
+#include "sceneIO.h"
+
+
+image generateImage(const scene& s)
+{
+ image result(s.getCamera().width(), s.getCamera().height());
+
+ // for every pixel
+ for(image::size_type y=0; y < result.height(); y++)
+ for(image::size_type x=0; x < result.width(); x++)
+ {
+ // generate view ray
+ ray r = s.getCamera()(x,y);
+
+ // intersect scene
+ intersectionPoint ip = s.intersect(r);
+
+ // shade pixel
+ if(ip.isHit())
+ {
+ // for each light source
+ for(unsigned int l=0; l < s.numberOfLightsources(); l++)
+ {
+ // connect to light source
+ lightSample ls = s.getLightsource(l).intensityAt(ip.position());
+
+ // shade
+ result(x,y) += ip.shade(ls);
+ }
+ }
+ else result(x,y) = color(0.0f, 0.0f, 0.0f);
+ }
+
+
+ // Done.
+ return result;
+}
+
+
+
+int main(int argc, char** argv)
+{
+ // parse command line
+ if(argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <scene.xml> [scene2.xml ...]" << std::endl;
+ return -1;
+ }
+
+ // for each filename, import scene and render
+ unsigned int pos=1;
+ while(pos < argc)
+ {
+ // get filename
+ std::string filename = argv[pos++];
+
+ // import
+ std::cerr << " * Reading " << filename << "...";
+ auto startImport = std::chrono::system_clock::now();
+
+ scene s;
+ importScene(filename, s);
+
+ auto endImport = std::chrono::system_clock::now();
+ std::chrono::duration<float> durationImport = endImport - startImport;
+ std::cerr << durationImport.count() << " seconds." << std::endl;
+
+ // render
+ std::cerr << " * Rendering... ";
+ auto startTime = std::chrono::system_clock::now();
+
+ image result = generateImage(s);
+
+ auto endTime = std::chrono::system_clock::now();
+ std::chrono::duration<float> duration = endTime - startTime;
+ std::cerr << duration.count() << " seconds." << std::endl;
+
+ // save image
+ std::cerr << " * Writing result." << std::endl;
+ exportImage(getFilename(filename) + ".ppm", result);
+ }
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/HW5.cpp b/hw6/bin/HW5.cpp
new file mode 100644
index 0000000..2908fb6
--- /dev/null
+++ b/hw6/bin/HW5.cpp
@@ -0,0 +1,56 @@
+#include <string>
+#include <chrono>
+#include <iostream>
+
+#include "util.h"
+#include "image.h"
+#include "scene.h"
+#include "imageIO.h"
+#include "sceneIO.h"
+
+int main(int argc, char** argv)
+{
+ // parse command line
+ if(argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <scene.xml> [scene2.xml ...]" << std::endl;
+ return -1;
+ }
+
+ // for each filename, import scene and render
+ unsigned int pos=1;
+ while(pos < argc)
+ {
+ // get filename
+ std::string filename = argv[pos++];
+
+ // import
+ std::cerr << " * Reading " << filename << "...";
+ auto startImport = std::chrono::system_clock::now();
+
+ scene s;
+ importScene(filename, s);
+
+ auto endImport = std::chrono::system_clock::now();
+ std::chrono::duration<float> durationImport = endImport - startImport;
+ std::cerr << durationImport.count() << " seconds." << std::endl;
+
+ // render
+ std::cerr << " * Rendering... ";
+ auto startTime = std::chrono::system_clock::now();
+
+ image result = s.render();
+
+ auto endTime = std::chrono::system_clock::now();
+ std::chrono::duration<float> duration = endTime - startTime;
+ std::cerr << duration.count() << " seconds." << std::endl;
+
+ // save image (both pfm and ppm)
+ std::cerr << " * Writing result." << std::endl;
+ exportImage(getFilename(filename) + ".pfm", result);
+ exportImage(getFilename(filename) + ".ppm", result);
+ }
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/HW6.cpp b/hw6/bin/HW6.cpp
new file mode 100644
index 0000000..3751955
--- /dev/null
+++ b/hw6/bin/HW6.cpp
@@ -0,0 +1,56 @@
+#include <string>
+#include <chrono>
+#include <iostream>
+
+#include "util.h"
+#include "image.h"
+#include "scene.h"
+#include "imageIO.h"
+#include "sceneIO.h"
+
+int main(int argc, char** argv)
+{
+ // parse command line
+ if(argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << " <scene.xml> [scene2.xml ...]" << std::endl;
+ return -1;
+ }
+
+ // for each filename, import scene and render
+ unsigned int pos=1;
+ while(pos < argc)
+ {
+ // get filename
+ std::string filename = argv[pos++];
+
+ // import
+ std::cerr << " * Reading " << filename << "...";
+ auto startImport = std::chrono::system_clock::now();
+
+ scene s;
+ importScene(filename, s);
+
+ auto endImport = std::chrono::system_clock::now();
+ std::chrono::duration<float> durationImport = endImport - startImport;
+ std::cerr << durationImport.count() << " seconds." << std::endl;
+
+ // render
+ std::cerr << " * Rendering... ";
+ auto startTime = std::chrono::system_clock::now();
+
+ image result = s.render();
+
+ auto endTime = std::chrono::system_clock::now();
+ std::chrono::duration<float> duration = endTime - startTime;
+ std::cerr << duration.count() << " seconds." << std::endl;
+
+ // save image
+ std::cerr << " * Writing result." << std::endl;
+ exportImage(getFilename(filename) + ".pfm", result);
+ exportImage(getFilename(filename) + ".ppm", result);
+ }
+
+ // Done.
+ return 0;
+}
diff --git a/hw6/bin/helloworld.cpp b/hw6/bin/helloworld.cpp
new file mode 100644
index 0000000..4911d87
--- /dev/null
+++ b/hw6/bin/helloworld.cpp
@@ -0,0 +1,9 @@
+#include <iostream>
+#include <cassert>
+
+int main(int argc, char** argv)
+{
+ ///////////////////////////
+ std::cout << "Hello World." << std::endl;
+ return(0);
+}
diff --git a/hw6/bin/image_compare.cpp b/hw6/bin/image_compare.cpp
new file mode 100644
index 0000000..4f1a798
--- /dev/null
+++ b/hw6/bin/image_compare.cpp
@@ -0,0 +1,90 @@
+#include <string>
+#include <iostream>
+
+#include "util.h"
+#include "image.h"
+#include "imageIO.h"
+#include "constants.h"
+#include "errorMessage.h"
+
+int main(int argc, char** argv)
+{
+ // parse command line
+ if(argc != 3)
+ {
+ std::cout << "Usage: " << argv[0] << " <image A> <image B>" << std::endl;
+ return -1;
+ }
+
+ std::string nameA(argv[1]);
+ std::string nameB(argv[2]);
+
+ // get image extensions
+ std::string extA = getExtension(nameA);
+ std::string extB = getExtension(nameB);
+
+ // check if both images have the same extension
+ if(extA != extB) errorMessage(" => different image types (PPM vs PFM).");
+
+ // load images
+ image imgA, imgB;
+ importImage(nameA, imgA);
+ importImage(nameB, imgB);
+
+ // check if both have the same dimension
+ if(imgA.width() != imgB.width() || imgA.height() != imgB.height())
+ errorMessage(" => different images sizes (%dx%d) vs (%dx%d).", imgA.width(), imgA.height(), imgB.width(), imgB.height());
+
+ // compute the difference image
+ image diff(imgA.width(), imgA.height());
+ color avgDiff, maxDiff;
+ unsigned long diffCount = 0;
+
+ for(image::size_type y=0; y < diff.height(); y++)
+ for(image::size_type x=0; x < diff.width(); x++)
+ {
+ // per pixel difference
+ color diffColor = imgA(x,y) - imgB(x,y);
+ diff(x,y) = (extA == "ppm") ? abs(diffColor) : diffColor;
+
+ // if different => update average and max (abs value)
+ diffColor.abs();
+ if(diffColor.r > EPSILON || diffColor.g > EPSILON || diffColor.b > EPSILON)
+ {
+ diffCount++;
+ avgDiff += diffColor;
+ maxDiff = color(std::max(maxDiff.r, diffColor.r), std::max(maxDiff.g, diffColor.g), std::max(maxDiff.b, diffColor.b));
+ }
+ }
+
+ // output results if different
+ if(extA == "ppm" && diffCount != 0)
+ {
+ avgDiff /= diffCount;
+ std::cout << " => There are " << diffCount << " pixels that differ." << std::endl;
+ std::cout << " Average difference: " << avgDiff << " [base 256: " << (avgDiff * 256.0f) << "]" << std::endl;
+ std::cout << " Maximum difference: " << maxDiff << " [base 256: " << (maxDiff * 256.0f) << "]" << std::endl;
+
+ // write out difference image
+ exportImage("diff.ppm", diff);
+ }
+
+ else if(extA == "pfm" && diffCount != 0)
+ {
+ avgDiff /= diffCount;
+ std::cout << " => There are " << diffCount << " pixels that differ." << std::endl;
+ std::cout << " Average difference: " << avgDiff << std::endl;
+ std::cout << " Maximum difference: " << maxDiff << std::endl;
+
+ // write out difference image
+ exportImage("diff.pfm", diff);
+ }
+
+ // if equal, let the user know
+ else {
+ std::cout << " => Both images are equal.\r\n";
+ }
+
+ // Done.
+ return 0;
+}