Browse Source

update compisition

master
cailean 2 months ago
parent
commit
50f9610971
  1. 3
      .gitignore
  2. BIN
      bin/data/debug_binaryMat.png
  3. 90675
      bin/data/json/sv_embeddings.json
  4. BIN
      bin/data/new_tree.bin
  5. BIN
      bin/image-to-mesh
  6. 160
      src/Bullet.cpp
  7. 14
      src/Bullet.h
  8. 2
      src/network/Server.cpp
  9. 51
      src/ofApp.cpp
  10. 3
      src/ofApp.h
  11. 6
      src/vp/VP.cpp

3
.gitignore

@ -12,7 +12,8 @@
/bin/data/images /bin/data/images
/bin/data/recordings /bin/data/recordings
/bin/data/models /bin/data/models
/bin/data/dataset /bin/data/dataset1
/bin/data/main_dataset
/bin/libs/ /bin/libs/
######### #########

BIN
bin/data/debug_binaryMat.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

90675
bin/data/json/sv_embeddings.json

File diff suppressed because it is too large

BIN
bin/data/new_tree.bin

Binary file not shown.

BIN
bin/image-to-mesh

Binary file not shown.

160
src/Bullet.cpp

@ -26,8 +26,6 @@ void Bullet::setup(vector<Node>& _nodes){
} }
shader.load("shaders/vertex_snap"); shader.load("shaders/vertex_snap");
std::cout << workerThreads.size() << std::endl;
} }
void Bullet::update(bool& is_controller_active, Node& chosen_node) { void Bullet::update(bool& is_controller_active, Node& chosen_node) {
@ -35,97 +33,57 @@ void Bullet::update(bool& is_controller_active, Node& chosen_node) {
cameraBounds = getCameraBounds(camera); cameraBounds = getCameraBounds(camera);
world.update(); world.update();
// static bool was_controller_active = false; updateRepulsionNode();
// static float transition_timer = 0.0f; cameraBounds = getCameraBounds(camera);
// static glm::vec3 start_pos; world.update();
float d_time = ofGetLastFrameTime();
// glm::vec3 current_pos = camera.getPosition(); glm::vec3 target_pos = chosen_node.collider->getPosition();
// float deltaTime = ofGetLastFrameTime(); glm::vec3 current_pos = camera.getPosition();
glm::vec3 dir = current_pos - target_pos;
// // Detect transition from controller to inactive float dist = glm::length(dir);
// if (is_controller_active != was_controller_active) { glm::vec3 norm_dir = glm::normalize(dir);
// if (!is_controller_active) {
// // Starting transition to new node if (is_controller_active) {
// transition_timer = 0.0f; if (glm::length(camera_velocity) > 0.0f) {
// start_pos = current_pos; glm::vec3 decel_dir = -glm::normalize(camera_velocity);
// } camera_velocity += decel_dir * DECELERATION * d_time;
// } if (glm::length(camera_velocity) < 0.01f) {
camera_velocity = glm::vec3(0.0f);
// if (!is_controller_active && &chosen_node != current_target_node) { }
// current_target_node = &chosen_node; }
// } } else {
float distance_factor = glm::min(dist / 50.0f, 1.0f);
float current_acceleration = ACCELERATION * distance_factor;
// // Update camera physics camera_velocity += -norm_dir * current_acceleration * d_time;
// if (is_controller_active) {
// // Decelerate over 2 seconds
// float deceleration_rate = 0.5f; // 1/2 = 2 seconds
// camera_velocity = camera_velocity * (1.0f - deceleration_rate * deltaTime);
// if (glm::length(camera_velocity) < 0.01f) { if (dist < 5.0f) {
// camera_velocity = glm::vec3(0.0f); float decel_factor = dist / 5.0f;
// } camera_velocity *= (1.0f - (1.0f - decel_factor) * d_time * 10.0f);
}
// // Keep base zoom when controller is active float mag = glm::length(camera_velocity);
// current_zoom = current_zoom + (0.03f - current_zoom) * deltaTime * 5.0f; if (mag > MAX_VELOCITY) {
// } else { camera_velocity = glm::normalize(camera_velocity) * MAX_VELOCITY;
// glm::vec3 target_position = current_target_node->collider->getPosition(); }
// // Transition period (zooming out and in)
// if (transition_timer < 10.0f) { // 2 second transition
// transition_timer += deltaTime;
// float progress = transition_timer / 2.0f;
// // Zoom curve (out and in)
// float zoomProgress;
// if (progress < 0.5f) {
// // Zoom out during first half
// zoomProgress = progress * 2.0f;
// float targetZoom = glm::mix(0.03f, 0.6f, zoomProgress);
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
// } else {
// // Zoom in during second half
// zoomProgress = (1.0f - progress) * 2.0f;
// float targetZoom = glm::mix(0.03f, 0.6f, zoomProgress);
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
// }
// // Move towards target during transition // Smoothed zoom based on velocity
// glm::vec3 ideal_pos = glm::mix(start_pos, target_position, progress); float vel_magnitude = glm::length(camera_velocity);
// camera_velocity = (ideal_pos - current_pos) / deltaTime; static float current_zoom = 0.02f; // Store current zoom
// } else { float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true);
// // After transition, follow node with spring physics
// float k = 2.0f;
// float damping = 3.0f;
// glm::vec3 displacement = target_position - current_pos;
// glm::vec3 spring_force = k * displacement;
// camera_velocity = camera_velocity + spring_force * deltaTime;
// camera_velocity = camera_velocity * (1.0f - damping * deltaTime);
// // Optional: Velocity-based zoom after transition
// float speed = glm::length(camera_velocity);
// float maxSpeed = 25.0f;
// float speedFactor = glm::min(speed / maxSpeed, 1.0f);
// float targetZoom = glm::mix(0.03f, 0.15f, speedFactor); // smaller zoom range for following
// current_zoom = current_zoom + (targetZoom - current_zoom) * deltaTime * 5.0f;
// }
// // Clamp velocity to maximum speed // Smooth lerp to target zoom
// float maxSpeed = 25.0f; current_zoom = current_zoom + (target_zoom - current_zoom) * 0.1f;
// float currentSpeed = glm::length(camera_velocity); camera.setScale(current_zoom);
// if (currentSpeed > maxSpeed) { }
// camera_velocity = (camera_velocity / currentSpeed) * maxSpeed;
// }
// }
// camera.setScale(current_zoom); camera.setPosition(current_pos + camera_velocity * d_time);
// // Update position using velocity if (glm::length(current_pos - target_pos) < 0.01f) {
// glm::vec3 new_position = current_pos + camera_velocity * deltaTime; camera.setPosition(target_pos);
// camera.setPosition(new_position); camera_velocity = glm::vec3(0.0f);
}
// was_controller_active = is_controller_active;
} }
void Bullet::draw(){ void Bullet::draw(){
@ -194,7 +152,7 @@ void Bullet::draw(){
ss << "Camera Position: " << camera.getPosition() << std::endl; ss << "Camera Position: " << camera.getPosition() << std::endl;
ss << "Camera Scale: " << camera.getScale() << std::endl; ss << "Camera Scale: " << camera.getScale() << std::endl;
ss << "Camera Bounds: " << cameraBounds.z << std::endl; ss << "Camera Bounds: " << cameraBounds.z << std::endl;
ofSetColor(255, 255, 255); ofSetColor(ofColor::blue);
ofDrawBitmapString(ss.str().c_str(), 20, 20); ofDrawBitmapString(ss.str().c_str(), 20, 20);
now = false; now = false;
} }
@ -242,36 +200,6 @@ void Bullet::workerThreadFunction(int threadId) {
} }
void Bullet::updateShapeBatch(size_t start, size_t end) { void Bullet::updateShapeBatch(size_t start, size_t end) {
// for (size_t i = start; i < end; ++i) {
// std::lock_guard<std::mutex> lock(shapeMutex);
// glm::vec3 pos = nodes[i].collider->getPosition();
// glm::vec3 direction = glm::vec3(0, 0, -5) - pos;
// float dist_sq = glm::length(direction);
// glm::vec3 norm_dir = glm::normalize(direction);
// nodes[i].collider->applyCentralForce(1.0 * norm_dir);
// if(now){
// std::lock_guard<std::mutex> lock(shapeMutex);
// nodes[i].collider->applyCentralForce(glm::vec3(ofRandom(-1, 1), ofRandom(-1, 1), ofRandom(-1, 1)));
// }
// if (dist_sq > FORCE_RADIUS_SQ){
// glm::vec3 norm_dir = glm::normalize(direction);
// std::lock_guard<std::mutex> lock(shapeMutex);
// nodes[i].collider->applyCentralForce(0.001 * direction);
// }
// btVector3 vel = nodes[i].collider->getRigidBody()->getLinearVelocity();
// float vel_mag = vel.length();
// if (vel_mag > 1.0f) { // Cap at magnitude 1
// vel.normalize(); // Normalize the velocity
// vel *= 1.0f; // Scale to cap
// nodes[i].collider->getRigidBody()->setLinearVelocity(vel); // Set the capped velocity
// }
//}
for (size_t i = start; i < end; ++i) { for (size_t i = start; i < end; ++i) {
std::lock_guard<std::mutex> lock(shapeMutex); std::lock_guard<std::mutex> lock(shapeMutex);

14
src/Bullet.h

@ -18,6 +18,12 @@ struct Node {
int error; int error;
}; };
struct CameraPosition {
glm::vec3 position;
glm::quat rotation;
float time;
};
class Bullet{ class Bullet{
public: public:
void setup(vector<Node>& _nodes); void setup(vector<Node>& _nodes);
@ -60,6 +66,12 @@ class Bullet{
bool was_camera_active = false; bool was_camera_active = false;
float current_zoom = 0.03f; float current_zoom = 0.03f;
glm::vec3 transition_start_pos; glm::vec3 transition_start_pos;
glm::vec3 camera_velocity = glm::vec3(0.0f);
const float ACCELERATION = 100.0f; // Adjust this value
const float DECELERATION = 20.0f; // Adjust this value
const float MAX_VELOCITY = 50.0f; // Your velocity cap
ofLight light; ofLight light;
ofTexture tex; ofTexture tex;
@ -143,6 +155,4 @@ class Bullet{
bool now = true; bool now = true;
bool new_chosen_node; bool new_chosen_node;
Node* current_target_node = nullptr; Node* current_target_node = nullptr;
glm::vec3 camera_velocity = glm::vec3(0.0f);
}; };

2
src/network/Server.cpp

@ -146,7 +146,7 @@ void Server::checkActivity(){
vp_queries.push_back(embedding.to_vector()); vp_queries.push_back(embedding.to_vector());
vector<int> ids = tree.query(vp_queries, 1); vector<int> ids = tree.query(vp_queries, 1);
chosen_node = &nodes[ids[0]]; chosen_node = &nodes[ids[0]];
ofLogNotice() << chosen_node->tsne_position; //Notice() << chosen_node->tsne_position;
} else { } else {
// Calculate the time since the last change // Calculate the time since the last change

51
src/ofApp.cpp

@ -4,10 +4,10 @@
void ofApp::setup(){ void ofApp::setup(){
/* allocated fbo's */ /* allocated fbo's */
map_fbo.allocate(ofGetWindowWidth() / 3, map_h, GL_RGB); map_fbo.allocate(ofGetWindowWidth() / 2, map_h, GL_RGB);
map_fbo_alpha.allocate(map_fbo.getWidth(), map_h, GL_RGBA); map_fbo_alpha.allocate(map_fbo.getWidth(), map_h, GL_RGBA);
map_fbo_post.allocate(map_fbo.getWidth(), map_h, GL_RGBA); map_fbo_post.allocate(map_fbo.getWidth(), map_h, GL_RGBA);
portrait_fbo.allocate((ofGetWindowWidth() / 3) * 2, map_h, GL_RGBA); // this shoould be full with 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.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_pre_fbo_alpha.allocate((ofGetWindowWidth() / 3) * 1, map_h, GL_RGBA);
comp_fbo.allocate(ofGetWindowWidth(), map_h, GL_RGBA); comp_fbo.allocate(ofGetWindowWidth(), map_h, GL_RGBA);
@ -72,19 +72,30 @@ void ofApp::setup(){
depth_portrait.setup(&model_image_portrait, &model_portrait_out_fbo, &depth_onnx_portrait); depth_portrait.setup(&model_image_portrait, &model_portrait_out_fbo, &depth_onnx_portrait);
/* camera settings for portrait */ /* camera settings for portrait */
glm::quat rot(0.9155, 0.3170, 0.02, -0.035); CameraPosition cp;
cp.position = glm::vec3(116.388, -441.054, 967.724);
cp.rotation = glm::quat(0.9155, 0.3170, 0.02, -0.035);
cam_positions.push_back(cp);
cp.position = glm::vec3(7.987, -195.329, 813.56);
cp.rotation = glm::quat(0.993, 0.117, 0.005, -0.00057);
cam_positions.push_back(cp);
cp.position = glm::vec3(160.81, -87.86, 731.575);
cp.rotation = glm::quat(0.980, 0.027, 0.1934, -0.0053);
cam_positions.push_back(cp);
/* settings */ /* settings */
// portrait_camera.enableOrtho(); // portrait_camera.enableOrtho();
// portrait_camera.setNearClip(-10000); // portrait_camera.setNearClip(-10000);
// portrait_camera.setFarClip(10000); // portrait_camera.setFarClip(10000);
portrait_camera.setPosition(116.388, -441.054, 967.724); portrait_camera.setPosition(cam_positions[0].position);
portrait_camera.setOrientation(rot); portrait_camera.setOrientation(cam_positions[0].rotation);
portrait_camera.setScale(0.5); portrait_camera.setScale(0.5);
// portrait_camera.removeAllInteractions(); // portrait_camera.removeAllInteractions();
// portrait_camera.disableMouseInput(); // portrait_camera.disableMouseInput();
createNodes("data/json/embeddings.json"); createNodes("data/json/sv_embeddings.json");
buildMeshes(); buildMeshes();
@ -144,7 +155,8 @@ void ofApp::update(){
//mapper.update(); //mapper.update();
bullet.update(server->is_active, server->getChosenNode()); bullet.update(server->is_active, server->getChosenNode());
std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< " : " <<portrait_camera.getScale() << std::endl;
std::cout << portrait_camera.getPosition() << " : " <<portrait_camera.getOrientationQuat()<< std::endl;
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -197,7 +209,7 @@ void ofApp::draw(){
ofBackgroundGradient(ofColor::darkGrey, ofColor::whiteSmoke, OF_GRADIENT_LINEAR); ofBackgroundGradient(ofColor::darkGrey, ofColor::whiteSmoke, OF_GRADIENT_LINEAR);
//ofClear(0); //ofClear(0);
shaders.begin(); shaders.begin();
portrait_fbo.draw(ofGetWindowWidth() / 3, 0); portrait_fbo.draw(ofGetWindowWidth() / 2, 0);
shaders.setUniformTexture("tex0", t, 0); shaders.setUniformTexture("tex0", t, 0);
shaders.setUniformTexture("tex1", bayer, 1); shaders.setUniformTexture("tex1", bayer, 1);
shaders.setUniform2f("resolution", map_w, map_h); shaders.setUniform2f("resolution", map_w, map_h);
@ -243,7 +255,7 @@ void ofApp::drawPortrait(){
// Move to center of FBO // Move to center of FBO
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight() * 0.6); // 0.8 ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight() * 0.6); // 0.8
// Apply scale // Apply scale
ofScale(p_scale); ofScale(1);
// Move back by half the scaled image dimensions // Move back by half the scaled image dimensions
ofTranslate(-scaledWidth/2, -scaledHeight/2); ofTranslate(-scaledWidth/2, -scaledHeight/2);
// Draw at 0,0 since we've already translated // Draw at 0,0 since we've already translated
@ -396,26 +408,29 @@ void ofApp::createNodes(std::string json_path){
} }
/* setup nodes */ /* setup nodes */
for(const auto& j : json){ bool addNode = true; // Toggle flag to track every second node
if(j.contains("vector") && j["vector"].is_array()){ for(const auto& j : json) {
if(j.contains("vector") && j["vector"].is_array() && j["error"] == 0) {
if(addNode) { // Only process when flag is true
Node n; Node n;
n.img.load(j["image"]); n.img.load(j["image"]);
n.tex = n.img.getTexture(); n.tex = n.img.getTexture();
n.error = j["lost"]; n.error = j["error"];
std::vector<float> t_embedding; std::vector<float> t_embedding;
int count = 0; int count = 0;
for (const auto& value: j["vector"]){ for (const auto& value: j["vector"]) {
if(value.is_number() && count < 4){ if(value.is_number()) {
t_embedding.push_back(value.get<float>()); t_embedding.push_back(value.get<float>());
count++; count++;
} else { } else {
ofLogError() << "Vector value is not a number"; ofLogError() << "Vector value is not a number";
} }
} }
n.raw_embedding = t_embedding; n.raw_embedding = t_embedding;
nodes.push_back(n); nodes.push_back(n);
} }
addNode = !addNode; // Toggle the flag after each valid node
}
} }
ofLogNotice() << "node count: " << nodes.size(); ofLogNotice() << "node count: " << nodes.size();
@ -534,6 +549,12 @@ void ofApp::keyPressed(int key) {
plane_size -=5; plane_size -=5;
ofLog() << "Plane Size: " << plane_size; ofLog() << "Plane Size: " << plane_size;
break; 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);
} }
//mapper.keyPressed(key); //mapper.keyPressed(key);
} }

3
src/ofApp.h

@ -117,4 +117,7 @@ class ofApp : public ofBaseApp{
int map_h = 960; int map_h = 960;
int map_w = 1920; int map_w = 1920;
/* camera positions */
vector<CameraPosition> cam_positions;
float cam_pos_idx = 0;
}; };

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) { for (const auto& q : query_double) {
auto [distances, indices] = t->getNearestNeighbors(q, k); auto [distances, indices] = t->getNearestNeighbors(q, k);
std::cout << "Query: "; //std::cout << "Query: ";
for (double d : q) std::cout << d << " "; //for (double d : q) std::cout << d << " ";
std::cout << "\nNearest neighbors:\n"; //std::cout << "\nNearest neighbors:\n";
for (int i = 0; i < k; ++i) { for (int i = 0; i < k; ++i) {
indexes.push_back(indices[i]); indexes.push_back(indices[i]);

Loading…
Cancel
Save