File: vis.cpp

package info (click to toggle)
nageru 2.3.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,120 kB
  • sloc: cpp: 39,131; perl: 94; sh: 18; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Visualize a .flo file.

#include "util.h"

#include <assert.h>
#include <memory>
#include <stdio.h>

using namespace std;

int main(int argc, char **argv)
{
	if (argc != 3) {
		fprintf(stderr, "Usage: ./vis input.flo out.ppm\n");
		abort();
	}

	Flow flow = read_flow(argv[1]);

	FILE *fp = fopen(argv[2], "wb");
	fprintf(fp, "P6\n%d %d\n255\n", flow.width, flow.height);
	for (unsigned y = 0; y < unsigned(flow.height); ++y) {
		for (unsigned x = 0; x < unsigned(flow.width); ++x) {
			float du = flow.flow[y * flow.width + x].du;
			float dv = flow.flow[y * flow.width + x].dv;

			uint8_t r, g, b;
			flow2rgb(du, dv, &r, &g, &b);
			putc(r, fp);
			putc(g, fp);
			putc(b, fp);
		}
	}
	fclose(fp);
}