Skip to content

Commit 0e46f3d

Browse files
Merge pull request BRL-CAD#2 from SP23-CSCE482/perspective_render
Perspective render
2 parents 26a80f8 + 3dbd992 commit 0e46f3d

10 files changed

+108
-7
lines changed

.DS_Store

0 Bytes
Binary file not shown.

output/moss_ambient.png

369 KB
Loading

output/moss_front.png

6.72 KB
Loading

output/moss_right.png

8.18 KB
Loading

output/moss_top.png

7.14 KB
Loading

src/PerspectiveGatherer.cpp

+100-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,106 @@
11
#include "PerspectiveGatherer.h"
22

3-
std::string renderAmbientOcclusion()
4-
{
5-
return "";
6-
}
3+
// std::string renderAmbientOcclusion()
4+
// {
5+
// // hardcode filename until options come out
6+
// std::string component = "all.g";
7+
// std::string pathToInput = "../db/";
8+
// std::string fileInput = "moss.g";
9+
// std::string pathToOutput = "../output/";
10+
// std::string fileOutput = "moss.png";
11+
// std::cout << "Processing file: " << fileInput << std::endl;
12+
13+
// // FIX security vulnerability
14+
// std::string inputname = pathToInput + fileInput;
15+
// std::string outputname = pathToOutput + fileOutput;
16+
17+
// std::ifstream file;
18+
// file.open(outputname);
19+
// if (file) {
20+
// std::string rmFile = "rm " + outputname;
21+
// auto result2 = system(rmFile.c_str());
22+
// }
23+
// file.close();
24+
// // TODO Need to somehow decide what to render if there are multiple components.
25+
// // Maybe let user choose which one to render e.g. pass in all.g?
26+
27+
// // EX: ../../../../../build/bin/rt -C 255/255/255 -s 1024 -c "set ambSamples=64" ../db/moss.g all.g
28+
// std::string render = "../../../../../build/bin/rt -C 255/255/255 -s 1024 -c \"set ambSamples=64\" -o " + outputname + " " + inputname + " " + component;
29+
// auto result2 = system(render.c_str());
30+
// std::cout << "Successlly generated ambient occlusion file\n";
31+
// return outputname;
32+
// }
733

834
std::string renderPerspective(RenderingFace face)
935
{
10-
return "";
36+
// hardcode filename until options come out
37+
std::string component = "all.g";
38+
std::string pathToInput = "../db/";
39+
std::string fileInput = "moss.g";
40+
std::string pathToOutput = "../output/";
41+
std::string fileOutput = "moss";
42+
43+
// do directory traversal checks
44+
if (fileOutput.find("../") != std::string::npos) {
45+
std::cout << "ERROR: Output file name cannot contain ../\n";
46+
return "";
47+
}
48+
49+
std::cout << "Processing file: " << fileInput << std::endl;
50+
51+
// FIX security vulnerability
52+
std::string inputname = pathToInput + fileInput;
53+
std::string outputname = pathToOutput + fileOutput;
54+
std::string render;
55+
56+
int a, e;
57+
switch (face) {
58+
case FRONT:
59+
a = 0, e = 0;
60+
outputname += "_front.png";
61+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
62+
break;
63+
case RIGHT:
64+
a = 90, e = 0;
65+
outputname += "_right.png";
66+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
67+
break;
68+
case BACK:
69+
a = 180, e = 0;
70+
outputname += "_back.png";
71+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
72+
break;
73+
case LEFT:
74+
a = 270, e = 0;
75+
outputname += "_left.png";
76+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
77+
break;
78+
case TOP:
79+
a = 0, e = 90; // may need to change "a"?
80+
outputname += "_top.png";
81+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
82+
break;
83+
case BOTTOM:
84+
a = 0, e = 270;
85+
outputname += "_bottom.png";
86+
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
87+
break;
88+
case AMBIENT:
89+
a = 45, e = 45;
90+
outputname += "_ambient.png";
91+
render = "../../../../../build/bin/rt -C 255/255/255 -s 1024 -c \"set ambSamples=64\" -o " + outputname + " " + inputname + " " + component;
92+
break;
93+
}
94+
95+
std::ifstream file;
96+
file.open(outputname);
97+
if (file) {
98+
std::string rmFile = "rm " + outputname;
99+
auto result2 = system(rmFile.c_str());
100+
}
101+
file.close();
102+
103+
auto result2 = system(render.c_str());
104+
std::cout << "Successlly generated perspective rendering png file\n";
105+
return outputname;
11106
}

src/PerspectiveGatherer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ enum RenderingFace
1616
RIGHT,
1717
LEFT,
1818
BACK,
19-
BOTTOM
19+
BOTTOM,
20+
AMBIENT
2021
};
2122

2223
// TODO: add correct parameters and return type

src/RenderHandler.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
void makeRenderSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height)
44
{
5-
5+
// std::string ambOccImg = renderAmbientOcclusion();
6+
std::string ambOccImg = renderPerspective(AMBIENT);
7+
std::string frontImg = renderPerspective(FRONT);
8+
std::string rightImg = renderPerspective(RIGHT);
9+
std::string topImg = renderPerspective(TOP);
610
}
711

812
int selectLayout(int secWidth, int secHeight, int modelLength, int modelWidth, int modelHeight)

src/a.out

59.7 KB
Binary file not shown.

src/pch.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <iostream>
1010
#include <cstdlib>
1111
#include <string>
12+
#include <fstream>
1213

1314
// Visualization project header files
1415
#include "Options.h"

0 commit comments

Comments
 (0)