Skip to content

Commit

Permalink
Merge pull request BRL-CAD#10 from SP23-CSCE482/parameters
Browse files Browse the repository at this point in the history
Started working with top and bottom headers
  • Loading branch information
allyhoskinson authored Mar 26, 2023
2 parents 88a0a71 + d815d2c commit 52b71a1
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 162 deletions.
25 changes: 24 additions & 1 deletion FactsHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#include "FactsHandler.h"

void makeInfoSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height) {
void makeTopSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height) {
//Draw black rectangle
img.drawRect(offsetX, offsetY, offsetX + width, offsetY + height, -1, cv::Scalar(0,0,0));

//Draw text on top
std::string owner = "Owner: " + info.getInfo("owner");
img.drawText(offsetX+150, offsetY + 30, 1, 1, owner, false, true);

std::string version = "Version: " + info.getInfo("version");
img.drawText(offsetX + 550, offsetY + 30, 1, 1, version, false, true);

std::string lastUpdate = "Last Updated: " + info.getInfo("lastUpdate");
img.drawText(offsetX + 900, offsetY + 30, 1, 1, lastUpdate, false, true);

std::string classification = "Classification: " + info.getInfo("classification");
img.drawText(offsetX + 1250, offsetY + 30, 1, 1, classification, false, true);
}

void makeBottomSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height) {
//Draw black rectangle
img.drawRect(offsetX, offsetY, offsetX + width, offsetY + height, -1, cv::Scalar(0, 0, 0));

//Draw text on top
std::string preparer = "Preparer: " + info.getInfo("preparer");
img.drawText(offsetX + 150, offsetY + 30, 1, 1, preparer, false, true);
}
3 changes: 2 additions & 1 deletion FactsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
class InformationGatherer;
class IFPainter;

void makeInfoSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height);
void makeTopSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height);
void makeBottomSection(IFPainter& img, InformationGatherer& info, int offsetX, int offsetY, int width, int height);
304 changes: 154 additions & 150 deletions IFPainter.cpp
Original file line number Diff line number Diff line change
@@ -1,151 +1,155 @@
#include "IFPainter.h"


IFPainter::IFPainter(int width, int height)
: img(width, height, CV_8UC3, cv::Scalar(255, 255, 255))
{
if (img.empty())
{
std::cerr << "ISSUE: Image Frame failed to load (in IFPainter.cpp)" << std::endl;
}
// TODO: this
}

IFPainter::~IFPainter()
{
// TODO: this
}

void IFPainter::drawImage(int x, int y, int width, int height, std::string imgPath)
{
// TODO (Michael): Along with writing this method, figure out the best way to represent images in code.
// 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
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 (...) {
std::cerr << "Trying to create roi out of image boundaries" << std::endl;
return;
}
resized_image.copyTo(destRoi);
}

void IFPainter::drawImageFitted(int x, int y, int width, int height, std::string imgPath)
{
// TODO (Michael): Along with writing this method, figure out the best way to represent images in code.
// 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
cv::Mat lilImage = imread(imgPath, cv::IMREAD_UNCHANGED);
int imgWidth = lilImage.size().width;
int imgHeight = lilImage.size().height;
int heightOffset = 0;
int widthOffset = 0;

if ((double)imgWidth / imgHeight > (double)width / height)
{
// image width is too large; bound on width
int newHeight = (int)(width * (double)imgHeight / imgWidth);
heightOffset = (height - newHeight) / 2;
height = newHeight;
}
else
{
// image height is too large; bound on height
int newWidth = (int)(height * (double)imgWidth / imgHeight);
widthOffset = (width - newWidth) / 2;
width = newWidth;
}

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 + widthOffset, y + heightOffset, resized_image.cols, resized_image.rows));
}
catch (...) {
std::cerr << "Trying to create roi out of image boundaries" << std::endl;
return;
}
resized_image.copyTo(destRoi);
}

void IFPainter::drawText(int x, int y, double fontSize, int font_weight, std::string text, bool italics)
{
// TODO: this
// keep in mind that we'll need options for bold, italics, etc.
// Try to make these methods as intuitive as possible in the idea of "we want text here, so we're confident that text will go here"
// Keep in mind text wrapping.

cv::Point text_position(x, y);
cv::Scalar font_color(0, 0, 0);
//boldness can be adjusted through font_weight
//The italics doesnt look really look like the traditional italics
if (italics == true) {
putText(img, text, text_position, cv::FONT_ITALIC, fontSize, font_color, font_weight);
}
putText(img, text, text_position, cv::FONT_HERSHEY_PLAIN, fontSize, font_color, font_weight);
}

void IFPainter::drawLine(int x1, int y1, int x2, int y2, int width, cv::Scalar color)
{
// TODO: this
int lineType = cv::LINE_8;
cv::Point start(x1, y1);
cv::Point end(x2, y2);
line(img,
start,
end,
color,
width,
lineType);
}

void IFPainter::drawRect(int x1, int y1, int x2, int y2, int width, cv::Scalar color)
{
// TODO: this
//Should I try to fill the rectangle?
cv::Point topLeft(x1, y1);
cv::Point bottomRight(x2, y2);
rectangle(img,
topLeft,
bottomRight,
color,
width,
cv::LINE_8);
}


void IFPainter::openInGUI()
{
cv::namedWindow("Report", cv::WINDOW_AUTOSIZE);
cv::imshow("Report", this->img);

cv::waitKey(0); //wait infinite time for a keypress

try
{
cv::destroyWindow("Report");
}
catch (std::exception& e)
{
}
// TODO: this
}

void IFPainter::exportToFile(std::string filePath)
{
cv::imwrite(filePath, this->img);

// TODO: this
#include "IFPainter.h"


IFPainter::IFPainter(int width, int height)
: img(width, height, CV_8UC3, cv::Scalar(255, 255, 255))
{
if (img.empty())
{
std::cerr << "ISSUE: Image Frame failed to load (in IFPainter.cpp)" << std::endl;
}
// TODO: this
}

IFPainter::~IFPainter()
{
// TODO: this
}

void IFPainter::drawImage(int x, int y, int width, int height, std::string imgPath)
{
// TODO (Michael): Along with writing this method, figure out the best way to represent images in code.
// 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
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 (...) {
std::cerr << "Trying to create roi out of image boundaries" << std::endl;
return;
}
resized_image.copyTo(destRoi);
}

void IFPainter::drawImageFitted(int x, int y, int width, int height, std::string imgPath)
{
// TODO (Michael): Along with writing this method, figure out the best way to represent images in code.
// 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
cv::Mat lilImage = imread(imgPath, cv::IMREAD_UNCHANGED);
int imgWidth = lilImage.size().width;
int imgHeight = lilImage.size().height;
int heightOffset = 0;
int widthOffset = 0;

if ((double)imgWidth / imgHeight > (double)width / height)
{
// image width is too large; bound on width
int newHeight = (int)(width * (double)imgHeight / imgWidth);
heightOffset = (height - newHeight) / 2;
height = newHeight;
}
else
{
// image height is too large; bound on height
int newWidth = (int)(height * (double)imgWidth / imgHeight);
widthOffset = (width - newWidth) / 2;
width = newWidth;
}

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 + widthOffset, y + heightOffset, resized_image.cols, resized_image.rows));
}
catch (...) {
std::cerr << "Trying to create roi out of image boundaries" << std::endl;
return;
}
resized_image.copyTo(destRoi);
}

void IFPainter::drawText(int x, int y, double fontSize, int font_weight, std::string text, bool italics, bool isWhite)
{
// TODO: this
// keep in mind that we'll need options for bold, italics, etc.
// Try to make these methods as intuitive as possible in the idea of "we want text here, so we're confident that text will go here"
// Keep in mind text wrapping.

cv::Point text_position(x, y);
//boldness can be adjusted through font_weight
//The italics doesnt look really look like the traditional italics
if (italics) {
putText(img, text, text_position, cv::FONT_ITALIC, fontSize, cv::Scalar(0, 0, 0), font_weight);
}
else if (isWhite) {
putText(img, text, text_position, cv::FONT_HERSHEY_PLAIN, fontSize, cv::Scalar(255, 255, 255), font_weight);
}
else {
putText(img, text, text_position, cv::FONT_HERSHEY_PLAIN, fontSize, cv::Scalar(0, 0, 0), font_weight);
}
}

void IFPainter::drawLine(int x1, int y1, int x2, int y2, int width, cv::Scalar color)
{
// TODO: this
int lineType = cv::LINE_8;
cv::Point start(x1, y1);
cv::Point end(x2, y2);
line(img,
start,
end,
color,
width,
lineType);
}

void IFPainter::drawRect(int x1, int y1, int x2, int y2, int width, cv::Scalar color)
{
// TODO: this
//Should I try to fill the rectangle?
cv::Point topLeft(x1, y1);
cv::Point bottomRight(x2, y2);
rectangle(img,
topLeft,
bottomRight,
color,
width,
cv::LINE_8);
}


void IFPainter::openInGUI()
{
cv::namedWindow("Report", cv::WINDOW_AUTOSIZE);
cv::imshow("Report", this->img);

cv::waitKey(0); //wait infinite time for a keypress

try
{
cv::destroyWindow("Report");
}
catch (std::exception& e)
{
}
// TODO: this
}

void IFPainter::exportToFile(std::string filePath)
{
cv::imwrite(filePath, this->img);

// TODO: this
}
4 changes: 2 additions & 2 deletions IFPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* The IFPainter class serves to store the actual image frame that will be modified and output in the report.
* All drawing and exporting operations will be done via function calls to this class.
*
*
*/

#pragma once
Expand All @@ -21,8 +21,8 @@ class IFPainter
~IFPainter();

void drawImage(int x, int y, int width, int height, std::string imgPath);
void drawText(int x, int y, double fontSize, int font_weight, std::string text, bool italics, bool isWhite);
void drawImageFitted(int x, int y, int width, int height, std::string imgPath);
void drawText(int x, int y, double fontSize, int font_weight, std::string text, bool italics);
void drawLine(int x1, int y1, int x2, int y2, int width, cv::Scalar color);
void drawRect(int x1, int y1, int x2, int y2, int width, cv::Scalar color);

Expand Down
Loading

0 comments on commit 52b71a1

Please sign in to comment.