Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gridtoppm.cpp

Go to the documentation of this file.
00001 #include <string>
00002 #include <iostream>
00003 #include <istream>
00004 #include <ostream>
00005 #include <fstream>
00006 
00007 #include "global.hpp"
00008 #include "jet.hpp"
00009 #include "parsecl.hpp"
00010 
00015 int main(int argc, char** argv) {
00016   using namespace Arak::Util;
00017   // Parse the command line.
00018   CommandLine cl;
00019   CommandLine::Parameter<double> 
00020     max("-min", "--min-intensity", "the surface value mapped to dark blue", 0.0);
00021   cl.add(max);
00022   CommandLine::Parameter<double> 
00023     min("-max", "--max-intensity", "the surface value mapped to dark red", 1.0);
00024   cl.add(min);
00025   CommandLine::Parameter<std::string> 
00026     inputPath("-i", "--input", 
00027         "the input file of point color estimates", std::string());
00028   cl.add(inputPath);
00029   CommandLine::Parameter<std::string> 
00030     outputPath("-o", "--output", "the output PPM file", std::string());
00031   cl.add(outputPath);
00032   if (!cl.parse(argc, argv, std::cerr)) {
00033     cl.printUsage(std::cerr);
00034     exit(1);
00035   }
00036 
00037   // Grab the input and output streams.
00038   std::istream* in = &std::cin;
00039   if (inputPath.supplied()) {
00040     in = new std::ifstream(inputPath.value().data());
00041     if (!in->good()) {
00042       std::cerr << "Error: cannot open file " << inputPath.value()
00043     << " for reading." << std::endl;
00044       exit(1);
00045     }
00046   }
00047   std::ostream* out = &std::cout;
00048   if (outputPath.supplied()) {
00049     out = new std::ofstream(outputPath.value().data());
00050     if (!out->good()) {
00051       std::cerr << "Error: cannot open file " << outputPath.value()
00052     << " for writing." << std::endl;
00053       exit(1);
00054     }
00055   }
00056 
00057   // Skip the number of samples.
00058   double tmp;
00059   *in >> tmp;
00060   // Read the dimensions.
00061   int rows, cols;
00062   *in >> rows;
00063   *in >> cols;
00064   // Skip the bounding box.
00065   *in >> tmp >> tmp >> tmp >> tmp;
00066 
00067   // Compute the interpolated values and output the file.
00068   *out << "P3" << std::endl;                       // magic number
00069   *out << "# " << outputPath.value() << std::endl; // filename
00070   *out << cols << " " << rows << std::endl;        // resolution
00071   *out << 255 << std::endl;        // max-value
00072   for (int i = 0; i < rows; i++) {
00073     for (int j = 0; j < cols; j++) {
00074       double value;
00075       *in >> value;
00076       double intensity = 
00077   (value - min.value()) / (max.value() - min.value());
00078       intensity = (intensity < 0.0) ? 0.0 : intensity;
00079       intensity = (intensity > 1.0) ? 1.0 : intensity;
00080       int index = int(round((double(Arak::jet_size) - 1) * (1.0 - intensity)));
00081       // Compute the pixel value.
00082       *out << int(Arak::jet_rgb[index][0]) << " " 
00083      << int(Arak::jet_rgb[index][1]) << " " 
00084      << int(Arak::jet_rgb[index][2]) << std::endl; 
00085     }
00086     *out << std::endl;
00087   }
00088   out->flush();  
00089 
00090   // Delete any allocated streams.
00091   if (inputPath.supplied()) delete in;
00092   if (outputPath.supplied()) delete out;
00093   
00094   return 0;
00095 }

Generated on Wed May 25 14:39:17 2005 for Arak by doxygen 1.3.6