Skip to content

Commit

Permalink
Merge pull request BRL-CAD#2 from SP23-CSCE482/perspective_render
Browse files Browse the repository at this point in the history
Perspective render
  • Loading branch information
zhuodannychen authored Mar 22, 2023
2 parents 26a80f8 + 3dbd992 commit 0e46f3d
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 7 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added output/moss_ambient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/moss_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/moss_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/moss_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 100 additions & 5 deletions src/PerspectiveGatherer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,106 @@
#include "PerspectiveGatherer.h"

std::string renderAmbientOcclusion()
{
return "";
}
// std::string renderAmbientOcclusion()
// {
// // hardcode filename until options come out
// std::string component = "all.g";
// std::string pathToInput = "../db/";
// std::string fileInput = "moss.g";
// std::string pathToOutput = "../output/";
// std::string fileOutput = "moss.png";
// std::cout << "Processing file: " << fileInput << std::endl;

// // FIX security vulnerability
// std::string inputname = pathToInput + fileInput;
// std::string outputname = pathToOutput + fileOutput;

// std::ifstream file;
// file.open(outputname);
// if (file) {
// std::string rmFile = "rm " + outputname;
// auto result2 = system(rmFile.c_str());
// }
// file.close();
// // TODO Need to somehow decide what to render if there are multiple components.
// // Maybe let user choose which one to render e.g. pass in all.g?

// // EX: ../../../../../build/bin/rt -C 255/255/255 -s 1024 -c "set ambSamples=64" ../db/moss.g all.g
// std::string render = "../../../../../build/bin/rt -C 255/255/255 -s 1024 -c \"set ambSamples=64\" -o " + outputname + " " + inputname + " " + component;
// auto result2 = system(render.c_str());
// std::cout << "Successlly generated ambient occlusion file\n";
// return outputname;
// }

std::string renderPerspective(RenderingFace face)
{
return "";
// hardcode filename until options come out
std::string component = "all.g";
std::string pathToInput = "../db/";
std::string fileInput = "moss.g";
std::string pathToOutput = "../output/";
std::string fileOutput = "moss";

// do directory traversal checks
if (fileOutput.find("../") != std::string::npos) {
std::cout << "ERROR: Output file name cannot contain ../\n";
return "";
}

std::cout << "Processing file: " << fileInput << std::endl;

// FIX security vulnerability
std::string inputname = pathToInput + fileInput;
std::string outputname = pathToOutput + fileOutput;
std::string render;

int a, e;
switch (face) {
case FRONT:
a = 0, e = 0;
outputname += "_front.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case RIGHT:
a = 90, e = 0;
outputname += "_right.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case BACK:
a = 180, e = 0;
outputname += "_back.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case LEFT:
a = 270, e = 0;
outputname += "_left.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case TOP:
a = 0, e = 90; // may need to change "a"?
outputname += "_top.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case BOTTOM:
a = 0, e = 270;
outputname += "_bottom.png";
render = "../../../../../build/bin/rtedge -s 1024 -W -R -a " + std::to_string(a) + " -e " + std::to_string(e) + " -o " + outputname + " " + inputname + " " + component;
break;
case AMBIENT:
a = 45, e = 45;
outputname += "_ambient.png";
render = "../../../../../build/bin/rt -C 255/255/255 -s 1024 -c \"set ambSamples=64\" -o " + outputname + " " + inputname + " " + component;
break;
}

std::ifstream file;
file.open(outputname);
if (file) {
std::string rmFile = "rm " + outputname;
auto result2 = system(rmFile.c_str());
}
file.close();

auto result2 = system(render.c_str());
std::cout << "Successlly generated perspective rendering png file\n";
return outputname;
}
3 changes: 2 additions & 1 deletion src/PerspectiveGatherer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum RenderingFace
RIGHT,
LEFT,
BACK,
BOTTOM
BOTTOM,
AMBIENT
};

// TODO: add correct parameters and return type
Expand Down
6 changes: 5 additions & 1 deletion src/RenderHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

void makeRenderSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height)
{

// std::string ambOccImg = renderAmbientOcclusion();
std::string ambOccImg = renderPerspective(AMBIENT);
std::string frontImg = renderPerspective(FRONT);
std::string rightImg = renderPerspective(RIGHT);
std::string topImg = renderPerspective(TOP);
}

int selectLayout(int secWidth, int secHeight, int modelLength, int modelWidth, int modelHeight)
Expand Down
Binary file modified src/a.out
Binary file not shown.
1 change: 1 addition & 0 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>

// Visualization project header files
#include "Options.h"
Expand Down

0 comments on commit 0e46f3d

Please sign in to comment.