invert-vol.cc |
| The goal is to make a simple program that inverts a volume : each transparent voxel in the original volume will be colored and each colored voxel will become transparent. |
| The program will be designed to be a filter (like grep), so it must read the source volume from standard input (stdin) and write the result to standard output (stdout). Of course, if the user supplies an argument, we will use this file instead of stdin. (And if he supplies a second argument, we will use it as the output file name). |
| We will have to load the file, check that this operation succeeded, invert the volume and write it. |
#include <vol.h>
#include <stdio.h>
int main( int argc, char **argv ) {
char *source_file = "";
char *dest_file = "";
|
|
if (argc > 1) {
source_file = argv[1];
if (argc > 2)
dest_file = argv[2];
}
|
|
Vol v( source_file );
|
|
if (!v.isOK()) {
fprintf( stderr, "Couldn't load \"%s\" file !\n", source_file );
return 1;
}
|
|
voxel alpha_color = v.alpha(); |
|
for (int i = v.minX(); i < v.maxX(); ++i) {
for (int j = v.minY(); j < v.maxY(); ++j) {
for (int k = v.minZ(); k < v.maxZ(); ++k) {
if (v(i, j, k) == alpha_color)
v(i, j, k) = 50;
else
v(i, j, k) = alpha_color;
}
}
}
|
|
v.dumpVol( dest_file );
return 0;
}
|
|
![]() |
![]() |