using tsne, vp-trees, and cosine similarity to search and visualise a dataset through affection mapping
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
2.0 KiB

#include "ImageViewer.h"
ImageViewer::ImageViewer(){
}
void ImageViewer::setup(){
fbo.allocate(ofGetWindowWidth() / 2, ofGetWindowHeight() / 2, GL_RGBA);
}
void ImageViewer::update(string imagePath){
currentImage = imagePath;
if (currentImage != lastImage){
setImage(currentImage);
lastImage = currentImage;
}
}
void ImageViewer::draw(){
if(displayImage.isAllocated())
calcImageScalePos();
}
void ImageViewer::setImage(std::string imagePath){
if(displayImage.isAllocated())
displayImage.clear();
displayImage.load("images/rte-archive-football/" + imagePath);
}
void ImageViewer::calcImageScalePos(){
// Get the window dimensions
int windowWidth = ofGetWidth();
int windowHeight = ofGetHeight();
// Calculate the target width and height for the bottom left quadrant
int targetWidth = windowWidth / 3;
int targetHeight = windowHeight / 3;
// Calculate scaling factors to cover the entire quadrant
float scaleX = (float)targetWidth / (float)displayImage.getWidth();
float scaleY = (float)targetHeight / (float)displayImage.getHeight();
// Choose the larger scale factor to ensure the image covers the quadrant
float scale = std::max(scaleX, scaleY);
// Calculate the scaled width and height of the image
int scaledWidth = displayImage.getWidth() * scale;
int scaledHeight = displayImage.getHeight() * scale;
// Calculate the position offsets to center the image in the quadrant
int offsetX = (scaledWidth - targetWidth) / 2;
int offsetY = (scaledHeight - targetHeight) / 2;
// Begin drawing into the FBO
fbo.begin();
ofClear(0, 0, 0, 0); // Clear the FBO with a transparent color
// Draw the image, scaled and centered, into the FBO
displayImage.draw(-offsetX, -offsetY, scaledWidth, scaledHeight);
// End drawing into the FBO
fbo.end();
// Draw the FBO onto the screen at the bottom-left quadrant
fbo.draw(0, 2 * windowHeight / 3);
}