Skip to content

Commit

Permalink
Added more error checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielshervheim committed Mar 26, 2020
1 parent 9184ce9 commit d96b9f2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ build/

*.exr
*.bin
results.txt
*results.txt
40 changes: 30 additions & 10 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <ImfRgba.h>
#include <half.h>


int main(int argc, char* argv[])
{
Atmosphere atmosphere;
Expand Down Expand Up @@ -77,9 +76,18 @@ int main(int argc, char* argv[])
int j = i / 3;
pixels[j] = Imf::Rgba(rayleigh[i+0], rayleigh[i+1], rayleigh[i+2], 1.0);
}
Imf::RgbaOutputFile rayleigh_file(rayleigh_path, DIM, DIM, Imf::WRITE_RGBA);
rayleigh_file.setFrameBuffer(pixels, 1, DIM);
rayleigh_file.writePixels(DIM);

try
{
Imf::RgbaOutputFile rayleigh_file(rayleigh_path, DIM, DIM, Imf::WRITE_RGBA);
rayleigh_file.setFrameBuffer(pixels, 1, DIM);
rayleigh_file.writePixels(DIM);
}
catch (const std::exception &exc)
{
(void)exc;
std::cout << "ERROR: failed to write rayleigh table to .exr file." << std::endl;
}

// Write the mie table to an OpenEXR file.
double* mie = atmosphere.GetPrecomputedMieTable();
Expand All @@ -90,9 +98,17 @@ int main(int argc, char* argv[])
int j = i / 3;
pixels[j] = Imf::Rgba(mie[i+0], mie[i+1], mie[i+2], 1.0);
}
Imf::RgbaOutputFile mie_file(mie_path, DIM, DIM, Imf::WRITE_RGBA);
mie_file.setFrameBuffer(pixels, 1, DIM);
mie_file.writePixels(DIM);
try
{
Imf::RgbaOutputFile mie_file(mie_path, DIM, DIM, Imf::WRITE_RGBA);
mie_file.setFrameBuffer(pixels, 1, DIM);
mie_file.writePixels(DIM);
}
catch (const std::exception &exc)
{
(void)exc;
std::cout << "ERROR: failed to write rayleigh table to .exr file." << std::endl;
}

delete [] pixels;
}
Expand Down Expand Up @@ -133,7 +149,8 @@ int main(int argc, char* argv[])
std::ofstream info(output_path + "results.txt", std::ios::out);
if(!info)
{
std::cout << "ERROR: Could not write information to file." << std::endl;
std::cout << "ERROR: Could not write precomputed parameter results to file." << std::endl;
return -1;
}

// If normalization was enabled, write the formulas needed to reconstruct
Expand All @@ -143,8 +160,9 @@ int main(int argc, char* argv[])
info << "NORMALIZATION" << std::endl;
info << std::scientific << std::endl;

info << "rayleigh = rayleigh_from_table*(" << maxR << " - " << minR << ") + " << minR << std::endl;
info << "mie = mie_from_table*(" << maxM << " - " << minM << ") + " << minM << std::endl;
info << "Rayleigh min, max = (" << minR << ", " << maxR << ")" << std::endl;
info << "Mie min, max = (" << minM << ", " << maxM << ")" << std::endl;

info << std::endl;
}

Expand All @@ -167,4 +185,6 @@ int main(int argc, char* argv[])

// Close the file.
info.close();

return 0;
}
12 changes: 10 additions & 2 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ bool Utilities::WriteFloatArrayToFile(std::string file_path, float* array, int a
return false;
}

out.write((char*)array, sizeof array[0] * array_length);
out.close();
try
{
out.write((char*)array, sizeof array[0] * array_length);
out.close();
}
catch(const std::exception &exc)
{
(void)exc;
return false;
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Utilities
// calling `delete [] ARRAYNAME`.
static float* ConvertDoubleArrayToFloatArray(double* array, int array_length);

// TODO: document this.
static void ConvertXyzToRgb(double x, double y, double z, double& r, double& g, double& b);
};

Expand Down

0 comments on commit d96b9f2

Please sign in to comment.