forked from BRL-CAD/brlcad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BRL-CAD#10 from SP23-CSCE482/parameters
Started working with top and bottom headers
- Loading branch information
Showing
9 changed files
with
223 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.