From ec3b9435d2b52860156df29f294d8fc8e8f10978 Mon Sep 17 00:00:00 2001 From: Roshan Patel Date: Tue, 4 Apr 2023 19:22:42 -0400 Subject: [PATCH] simple change --- PPMImageExporter.h | 78 ++++++++++++++++++++++++++++++++++++++ sgraph/RaycastRenderer.hpp | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 PPMImageExporter.h diff --git a/PPMImageExporter.h b/PPMImageExporter.h new file mode 100644 index 0000000..5480658 --- /dev/null +++ b/PPMImageExporter.h @@ -0,0 +1,78 @@ +// +// Created by Roshan Patel on 4/4/23. +// + +#ifndef CS4300_RAYTRACER_PPMIMAGEEXPORTER_H +#define CS4300_RAYTRACER_PPMIMAGEEXPORTER_H + +#include +#include +#include +#include +#include + +class PPMImageExporter { + +public: + PPMImageExporter() { + + } + + void export(std::string path, int width, int height, int factor, vector data) { + string out = ""; + std::ofstream op; + std::string str; + int i,j; + int r,g,b; + int factor; + + fp.open(filename.c_str()); + + if (!fp.is_open()) + throw std::invalid_argument("File not found!"); + + std::cout << "Image file opened" << std::endl; + + //read line by line and ignore comments + std::stringstream input; + std::string line; + + while (std::getline(fp,line)) { + if ((line.length()>0) && (line[0]!='#')) { + input << line << std::endl; + } + } + fp.close(); + + + //read in the word P3 + + input >> str; + + + //now read in the width and height + + input >> width >> height; + + //read in the factor + input >> factor; + + image = new GLubyte[3*width*height]; + + for (i=0;i> r >> g >> b; + image[3*((height-1-i)*width+j)] = r; + image[3*((height-1-i)*width+j)+1] = g; + image[3*((height-1-i)*width+j)+2] = b; + // << "r=" << (int)r << ", g=" << (int)g << ",b=" << (int)b << endl; + } + } + //fp.close(); + } + +}; + +#endif //CS4300_RAYTRACER_PPMIMAGEEXPORTER_H diff --git a/sgraph/RaycastRenderer.hpp b/sgraph/RaycastRenderer.hpp index e3a0625..3d6ee9a 100644 --- a/sgraph/RaycastRenderer.hpp +++ b/sgraph/RaycastRenderer.hpp @@ -15,7 +15,7 @@ #include #include #include -#include "Ray3D.hpp" +#include "../Ray3D.hpp" using namespace std;