Browse Source

one more push to go!

master
cailean 4 months ago
parent
commit
e148d0aa12
  1. 1
      bin/data/camera_angles.txt
  2. 48434
      bin/data/json/embeddings.json
  3. BIN
      bin/data/new_tree.bin
  4. 9
      bin/data/shaders/vertex_snap.frag
  5. BIN
      bin/image-to-mesh
  6. 40
      src/Bullet.cpp
  7. 6
      src/Bullet.h
  8. 5
      src/network/Server.cpp
  9. 51
      src/ofApp.cpp
  10. 6
      src/ofApp.h
  11. 6
      src/vp/VP.cpp

1
bin/data/camera_angles.txt

@ -0,0 +1 @@
-131.228, 502.624, 706.1 : 0.898726, -0.436474, -0.0351978, -0.0170607 : 0.313542, 0.313542, 0.313542

48434
bin/data/json/embeddings.json

File diff suppressed because it is too large

BIN
bin/data/new_tree.bin

Binary file not shown.

9
bin/data/shaders/vertex_snap.frag

@ -1,6 +1,7 @@
#version 150
uniform sampler2D tex0;
uniform float greyscale;
in vec2 tex_c;
@ -16,5 +17,11 @@ void main()
discard;
}
outputColor = texColor;
// Convert to grayscale if is_nearest is true
if (greyscale < 0.5) { // Using 0.5 as threshold since GLSL doesn't have bool
float gray = dot(texColor.rgb, vec3(0.299, 0.587, 0.114)); // Standard grayscale conversion
outputColor = vec4(vec3(gray), texColor.a);
} else {
outputColor = texColor;
}
}

BIN
bin/image-to-mesh

Binary file not shown.

40
src/Bullet.cpp

@ -30,7 +30,10 @@ void Bullet::setup(vector<Node>& _nodes){
contr_active = false;
}
void Bullet::update(bool& is_controller_active, Node& chosen_node) {
void Bullet::update(bool& is_controller_active, Node& chosen_node, vector<Node*> nn) {
nn_nodes = nn;
static float blend_factor = 0.0f;
contr_active = is_controller_active;
@ -170,29 +173,41 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) {
void Bullet::draw(){
std::lock_guard<std::mutex> lock(shapeMutex);
float shapes_drawn = 0;
gridSize = calculateGridSize(camera.getScale().x);
camera.begin();
glEnable( GL_DEPTH_TEST );
ofSetLineWidth(10.f);
ofSetLineWidth(20.f);
ofNoFill();
ofSetColor(ofColor::yellow);
ofNoFill();
ofSetColor(ofColor::yellow);
for(const auto& n : nodes){
if(checkNodeVisibility(n)){
// Compare pointers directly
bool is_nearest = false;
for(const auto* nn : nn_nodes) {
if(nn->tsne_position == n.tsne_position) { // or if you store the address differently, adjust this comparison
is_nearest = true;
break;
}
}
ofPushStyle();
ofSetColor(ofColor::orange); // Yellow for others
ofPushMatrix();
n.collider->transformGL();
ofScale(n.scale * 1.4);
n.col_mesh.draw();
n.collider->restoreTransformGL();
ofPopMatrix();
ofPopStyle();
}
}
@ -204,10 +219,20 @@ void Bullet::draw(){
for(const auto& n : nodes){
if(checkNodeVisibility(n)){
bool is_nearest = false;
for(const auto* nn : nn_nodes) {
if(nn->tsne_position == n.tsne_position) { // or if you store the address differently, adjust this comparison
is_nearest = true;
break;
}
}
ofPushMatrix();
shader.begin();
shader.setUniform1f("greyscale", is_nearest);
shader.setUniform1f("gridSize", gridSize);
shader.setUniform2f("resolution", glm::vec2(1920.0/2, 960.0));
shader.setUniform2f("resolution", glm::vec2(1920.0/2.0, 960.0));
shader.setUniformTexture("tex0", n.tex, 0);
n.collider->transformGL();
ofScale(n.scale);
@ -236,7 +261,8 @@ void Bullet::draw(){
ss << "Conotroller Active: " << contr_active << std::endl;
ss << "Random Walk: " << is_random_walking << std::endl;
ofSetColor(ofColor::blue);
ofDrawBitmapString(ss.str().c_str(), 20, 20);
if(print_debug)
ofDrawBitmapString(ss.str().c_str(), 20, 20);
now = false;
}
@ -301,7 +327,7 @@ float Bullet::easeInOutCubic(float t) {
float Bullet::calculateGridSize(float zoom){
const float ref_zoom = 0.01;
const float ref_scale = 40;
const float ref_scale = 20;
float new_grid_size = (ref_zoom * ref_scale) / zoom;
if(new_grid_size < 5){
new_grid_size = 5;

6
src/Bullet.h

@ -21,13 +21,14 @@ struct Node {
struct CameraPosition {
glm::vec3 position;
glm::quat rotation;
float scale;
float time;
};
class Bullet{
public:
void setup(vector<Node>& _nodes);
void update(bool& is_camera_active, Node& chosen_node);
void update(bool& is_camera_active, Node& chosen_node, vector<Node*> nn);
void draw();
void addMesh(ofMesh _mesh, ofMesh _simple_mesh, Node& _node);
float easeInOutCubic(float t);
@ -65,6 +66,7 @@ class Bullet{
float deceleration_start_time = 0.0f;
glm::vec3 initial_velocity = glm::vec3(0.0f);
bool was_camera_active = false;
bool print_debug = false;
float current_zoom = 0.03f;
glm::vec3 transition_start_pos;
glm::vec3 camera_velocity = glm::vec3(0.0f);
@ -83,6 +85,8 @@ class Bullet{
glm::vec4 cameraBounds;
vector<Node*> nn_nodes;
void updateRepulsionNode() {
static int frameCount = 0;
static const int repulsionInterval = 180; // Apply repulsion every 60 frames

5
src/network/Server.cpp

@ -119,7 +119,6 @@ void Server::print(){
std::ostringstream ss;
ss << "Connected Clients: " << num_of_clients << endl;
ss << "Embedding [";
for (size_t i = 0; i < emotionNames.size(); ++i) {
@ -130,7 +129,7 @@ void Server::print(){
ss << "]" << endl;
ofSetColor(255, 255, 255);
ofDrawBitmapString(ss.str(), (ofGetWindowWidth() / 2) + 20 , 20);
ofDrawBitmapString(ss.str(), 20 , 20);
}
/* check if the controllers are in use */
@ -145,7 +144,7 @@ void Server::checkActivity(){
vp_queries.push_back(embedding.to_vector());
vector<int> ids = tree.query(vp_queries, 1);
chosen_node = &nodes[ids[0]];
//Notice() << chosen_node->tsne_position;
// ofLog() << chosen_node->collider->getPosition();
} else {
// Calculate the time since the last change

51
src/ofApp.cpp

@ -7,11 +7,13 @@ void ofApp::setup(){
map_fbo.allocate(ofGetWindowWidth() / 2, map_h, GL_RGB);
map_fbo_alpha.allocate(map_fbo.getWidth(), map_h, GL_RGBA);
map_fbo_post.allocate(map_fbo.getWidth(), map_h, GL_RGBA);
portrait_fbo.allocate((ofGetWindowWidth() / 2), map_h, GL_RGBA); // this shoould be full with
portrait_pre_fbo.allocate((ofGetWindowWidth() / 3) * 1, map_h, GL_RGB); // this should be full, and same below
portrait_pre_fbo_alpha.allocate((ofGetWindowWidth() / 3) * 1, map_h, GL_RGBA);
portrait_cropped.allocate((ofGetWindowWidth() / 3) * 1, map_h, GL_RGB);
portrait_cropped_alpha.allocate((ofGetWindowWidth() / 3) * 1, map_h, GL_RGBA);
comp_fbo.allocate(ofGetWindowWidth(), map_h, GL_RGBA);
model_outptut_fbo.allocate(map_fbo.getWidth(), map_h, GL_RGB);
@ -28,7 +30,6 @@ void ofApp::setup(){
model_image_portrait.allocate(portrait_pre_fbo_alpha.getWidth(), portrait_pre_fbo_alpha.getHeight(), OF_IMAGE_COLOR);
model_image_portrait_cropped.allocate(portrait_pre_fbo_alpha.getWidth(), portrait_pre_fbo_alpha.getHeight(), OF_IMAGE_COLOR);
map_pixels.allocate(map_fbo.getWidth(), map_h, OF_PIXELS_RGB);
alpha_demo.allocate(portrait_pre_fbo_alpha.getWidth(), portrait_pre_fbo_alpha.getHeight(), OF_IMAGE_COLOR_ALPHA);
/* allocated ofImages in esp_images */
@ -81,8 +82,9 @@ void ofApp::setup(){
/* camera settings for portrait */
CameraPosition cp;
cp.position = glm::vec3(116.388, -441.054, 967.724);
cp.rotation = glm::quat(0.9155, 0.3170, 0.02, -0.035);
cp.position = glm::vec3(-131.228, 502.624, 706.1);
cp.rotation = glm::quat(0.898726, -0.436474, -0.0351978, -0.0170607);
cp.scale = 0.313542;
cam_positions.push_back(cp);
cp.position = glm::vec3(7.987, -195.329, 813.56);
@ -99,9 +101,9 @@ void ofApp::setup(){
portrait_camera.setFarClip(10000);
portrait_camera.setPosition(cam_positions[0].position);
portrait_camera.setOrientation(cam_positions[0].rotation);
portrait_camera.setScale(0.5);
// portrait_camera.removeAllInteractions();
// portrait_camera.disableMouseInput();
portrait_camera.setScale(cam_positions[0].scale);
portrait_camera.removeAllInteractions();
portrait_camera.disableMouseInput();
createNodes("data/json/sv_embeddings.json");
@ -134,7 +136,7 @@ void ofApp::update(){
}
if(current_time - last_updated_time >= 3){
if(current_time - last_updated_time >= 1){
buildKDTree();
getNearestImages();
depth_esp.update();
@ -153,6 +155,7 @@ void ofApp::update(){
/* write pixels to model input image */
try{
map_pixels.allocate(map_fbo.getWidth(), map_h, OF_PIXELS_RGB);
map_fbo.readToPixels(map_pixels);
model_image.setFromPixels(map_pixels);
} catch (exception e) {
@ -172,10 +175,7 @@ void ofApp::update(){
}
//mapper.update();
bullet.update(server->is_active, server->getChosenNode());
//std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< std::endl;
bullet.update(server->is_active, server->getChosenNode(), nn_nodes);
}
//--------------------------------------------------------------
@ -223,8 +223,6 @@ void ofApp::draw(){
drawPortrait();
comp_fbo.begin();
ofClear(ofColor::lightGrey); //uncommet when changing to map
ofBackgroundGradient(ofColor::darkGrey, ofColor::whiteSmoke, OF_GRADIENT_LINEAR);
shaders.begin();
portrait_fbo.draw(ofGetWindowWidth() / 2, 0);
shaders.setUniformTexture("tex0", t, 0);
@ -233,7 +231,6 @@ void ofApp::draw(){
shaders.setUniform1f("time", ofGetElapsedTimef());
shaders.setUniform1i("frame", ofGetFrameNum());
map_fbo_post.draw(0, 0);
/* actual map */
map_fbo_alpha.draw(0,0);
shaders.end();
comp_fbo.end();
@ -245,7 +242,8 @@ void ofApp::draw(){
ofTranslate(0, 60);
comp_fbo.draw(0, 0);
//server->print();
if(bullet.print_debug)
server->print();
}
void ofApp::drawPortrait(){
@ -446,6 +444,7 @@ void ofApp::drawPortraitZ(){
/* creates an fbo with four cropped images, to preprare for model input */
void ofApp::getNearestImages(){
nn_nodes.clear();
glm::vec3 cam_position = bullet.getCameraPosition();
queryKD(cam_position, 4);
@ -456,6 +455,9 @@ void ofApp::getNearestImages(){
int imageIndex = 0;
for(auto& img : esp_images){
/* add to nn_nodes array */
nn_nodes.push_back(&nodes[kd_result[imageIndex].second]);
selected_image = nodes[kd_result[imageIndex].second].img;
// Calculate the scaling factor
float widthRatio = 128.0f / selected_image.getWidth();
@ -649,11 +651,20 @@ void ofApp::keyPressed(int key) {
ofLog() << "Plane Size: " << plane_size;
break;
case 'c':
cam_pos_idx++;
if(cam_pos_idx > cam_positions.size() - 1)
cam_pos_idx = 0;
portrait_camera.setPosition(cam_positions[cam_pos_idx].position);
portrait_camera.setOrientation(cam_positions[cam_pos_idx].rotation);
// cam_pos_idx++;
// if(cam_pos_idx > cam_positions.size() - 1)
// cam_pos_idx = 0;
// portrait_camera.setPosition(cam_positions[cam_pos_idx].position);
// portrait_camera.setOrientation(cam_positions[cam_pos_idx].rotation);
// portrait_camera.setScale(cam_positions[cam_pos_idx].scale);
case 'p':
if(bullet.print_debug){
bullet.print_debug = false;
} else {
bullet.print_debug = true;
}
std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< " : " << portrait_camera.getScale() << std::endl;
break;
}
//mapper.keyPressed(key);
}

6
src/ofApp.h

@ -47,6 +47,7 @@ class ofApp : public ofBaseApp{
ofFbo map_fbo;
ofFbo map_fbo_alpha;
ofFbo map_fbo_post;
ofFbo portrait_fbo;
ofFbo portrait_pre_fbo;
ofFbo portrait_pre_fbo_alpha;
@ -121,7 +122,7 @@ class ofApp : public ofBaseApp{
/* settings */
float g_size = 5;
float plane_size = 55;
float plane_size = 70;
float past_plane_size;
/* pi mapper */
@ -144,4 +145,7 @@ class ofApp : public ofBaseApp{
ofImage alpha_demo;
ofPixels alpha_pixels;
/* n-neighbour */
vector<Node*> nn_nodes;
};

6
src/vp/VP.cpp

@ -48,9 +48,9 @@ vector<int> VP::query(vector<vector<float>> _embedding, int k){
for (const auto& q : query_double) {
auto [distances, indices] = t->getNearestNeighbors(q, k);
//std::cout << "Query: ";
//for (double d : q) std::cout << d << " ";
//std::cout << "\nNearest neighbors:\n";
// std::cout << "Query: ";
// for (double d : q) std::cout << d << " ";
for (int i = 0; i < k; ++i) {
indexes.push_back(indices[i]);

Loading…
Cancel
Save