Terrain Rasterizer
Conversion of GPS data into 2.5D topographic maps
Loading...
Searching...
No Matches
rasterizer.cpp File Reference

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>
Include dependency graph for rasterizer.cpp:

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.
 

Detailed Description

Implementation of the rasterization process (coloring, shading, and image generation).

Function Documentation

◆ calculateShade()

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.

Computes the normal vector of the triangle (cross product of edges) and takes the dot product with a fixed light direction (from NW).

Parameters
p1First vertex.
p2Second vertex.
p3Third vertex.
Returns
double Shading factor (0.4 to 1.0).

◆ generateImage()

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.

Parameters
filenameThe output filename (e.g., "output.ppm").
widthThe desired width of the output image in pixels.
meshThe triangulated mesh to rasterize.
Here is the call graph for this function:

◆ getColor()

Color getColor ( double  z,
double  minZ,
double  maxZ 
)

Maps an altitude to a color using a Haxby-like colormap.

Parameters
zCurrent altitude.
minZMinimum altitude in the dataset.
maxZMaximum altitude in the dataset.
Returns
Color The corresponding RGB color.

◆ interpolateZ()

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.

Parameters
pxX coordinate of the target point.
pyY coordinate of the target point.
p1First vertex of the triangle.
p2Second vertex of the triangle.
p3Third vertex of the triangle.
Returns
double The interpolated altitude (Z).