![]() |
Terrain Rasterizer
Conversion of GPS data into 2.5D topographic maps
|
Implementation of the rasterization process (coloring, shading, and image generation). More...
#include "rasterizer.hpp"#include "quadtree.hpp"#include <algorithm>#include <cmath>#include <fstream>#include <iostream>#include <limits>
Classes | |
| struct | Color |
Functions | |
| Color | getColor (double z, double minZ, double maxZ) |
| Maps an altitude to a color using a Haxby-like colormap. | |
| double | interpolateZ (double px, double py, const Point &p1, const Point &p2, const Point &p3) |
| Computes the Z coordinate at point (px, py) within a triangle using barycentric interpolation. | |
| double | calculateShade (const Point &p1, const Point &p2, const Point &p3) |
| Calculates a shading factor based on the triangle's normal and a fixed light source. | |
| void | generateImage (const std::string &filename, int width, const Mesh &mesh) |
| Generates a colorized raster image (PPM) from the triangulated mesh. | |
Implementation of the rasterization process (coloring, shading, and image generation).
Calculates a shading factor based on the triangle's normal and a fixed light source.
Computes the normal vector of the triangle (cross product of edges) and takes the dot product with a fixed light direction (from NW).
| p1 | First vertex. |
| p2 | Second vertex. |
| p3 | Third vertex. |
| void generateImage | ( | const std::string & | filename, |
| int | width, | ||
| const Mesh & | mesh | ||
| ) |
Generates a colorized raster image (PPM) from the triangulated mesh.
Rasterizes the mesh into a PPM image of the specified width. The height is calculated automatically to maintain aspect ratio. Altitude is visualized using a color map.
| filename | The output filename (e.g., "output.ppm"). |
| width | The desired width of the output image in pixels. |
| mesh | The triangulated mesh to rasterize. |

| Color getColor | ( | double | z, |
| double | minZ, | ||
| double | maxZ | ||
| ) |
Maps an altitude to a color using a Haxby-like colormap.
| z | Current altitude. |
| minZ | Minimum altitude in the dataset. |
| maxZ | Maximum altitude in the dataset. |
Computes the Z coordinate at point (px, py) within a triangle using barycentric interpolation.
| px | X coordinate of the target point. |
| py | Y coordinate of the target point. |
| p1 | First vertex of the triangle. |
| p2 | Second vertex of the triangle. |
| p3 | Third vertex of the triangle. |