Skip to content

Commit

Permalink
Merge pull request BRL-CAD#7 from SP23-CSCE482/Marks_Amazing_Branch
Browse files Browse the repository at this point in the history
Marks amazing branch
  • Loading branch information
zhuodannychen authored Mar 26, 2023
2 parents b6e8cc9 + decac6b commit 729145d
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 48 deletions.
9 changes: 4 additions & 5 deletions IFPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ void IFPainter::drawImage(int x, int y, int width, int height, std::string imgPa
// Perhaps there's a better way to store images; reading in images multiple times is inefficient, though if we only need
// to read in the image once (which I believe is the case), then reading images from a file should also be fine.
// TODO: this

//storing the desired image and resizing it to the desired width and height
cv::Mat lilImage = imread(imgPath , cv::IMREAD_UNCHANGED);
cv::Mat lilImage = imread(imgPath, cv::IMREAD_UNCHANGED);
cv::Mat resized_image;
resize(lilImage, resized_image, cv::Size(width, height), cv::INTER_LINEAR);

//Trying to copyto the image on to the private image frame, img
cv::Mat destRoi;
try {
destRoi = img(cv::Rect(x, y, resized_image.cols, resized_image.rows));
} catch (...) {
}
catch (...) {
std::cerr << "Trying to create roi out of image boundaries" << std::endl;
return;
return;
}
resized_image.copyTo(destRoi);
}
Expand Down
53 changes: 21 additions & 32 deletions PerspectiveGatherer.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
#include "PerspectiveGatherer.h"
#include "Options.h"

// 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::map<char, FaceDetails> getFaceDetails()
{
std::map<char, FaceDetails> output;

// 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?
output['0'] = {FRONT, "Front", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_front.png", LENGTH, HEIGHT};
output['1'] = {TOP, "Top", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_top.png", LENGTH, DEPTH};
output['2'] = {RIGHT, "Right", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_right.png", DEPTH, HEIGHT};
output['3'] = {LEFT, "Left", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_left.png", DEPTH, HEIGHT};
output['4'] = {BACK, "Back", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_back.png", LENGTH, HEIGHT};
output['5'] = {BOTTOM, "Bottom", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_bottom.png", LENGTH, DEPTH};
output['6'] = {BACK_MIRRORED, "Back-Mirrored", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_back_mirrored.png", LENGTH, HEIGHT};
output['7'] = {BOTTOM_MIRRORED, "Bottom-Mirrored", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ortho_bottom_mirrored.png", LENGTH, DEPTH};
output['8'] = {DETAILED, "Ambient Occlusion", "D:\\Mark\\ProgrammingWorkspace\\brlcad\\buildapple\\src\\gtools\\rgen\\visualization\\src\\ambient_occ.png"};

// // 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;
// }
return output;
}

std::string renderPerspective(RenderingFace face)
{
// hardcode filename until options come out
std::string component = "all.g";
std::string pathToInput = Options::getFilepath();
std::string fileInput = Options::getFileName();
std::string pathToInput = "moss.g";
std::string fileInput = "moss.g";
std::string pathToOutput = "../output/";
std::string fileOutput = "moss";
std::cout << "dbg " << pathToInput << " " << std::fileInput << endl;
std::cout << "dbg " << pathToInput << " " << fileInput << std::endl;

// do directory traversal checks
if (fileOutput.find("../") != std::string::npos) {
Expand Down Expand Up @@ -87,11 +73,14 @@ std::string renderPerspective(RenderingFace face)
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:
case DETAILED:
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;
default:
std::cerr<< "mark added this\n";
break;
}

std::ifstream file;
Expand Down
27 changes: 25 additions & 2 deletions PerspectiveGatherer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*
*/

// NOTE: with the exception of the "DETAILED" element, do not change
// the ordering of the elements of RenderingFace. The indices
// of FRONT ... BOTTOM_MIRRORED are hard-coded in initLayouts() in RenderHandler.cpp
enum RenderingFace
{
FRONT,
Expand All @@ -17,9 +20,29 @@ enum RenderingFace
LEFT,
BACK,
BOTTOM,
AMBIENT
BACK_MIRRORED,
BOTTOM_MIRRORED,
DETAILED
};

enum ModelDimension
{
LENGTH,
DEPTH,
HEIGHT
};

struct FaceDetails
{
RenderingFace face;
std::string title;
std::string file_path;

ModelDimension widthContributor;
ModelDimension heightContributor;
};

std::map<char,FaceDetails> getFaceDetails();

// TODO: add correct parameters and return type
std::string renderAmbientOcclusion();
std::string renderPerspective(RenderingFace face);
Loading

0 comments on commit 729145d

Please sign in to comment.