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. 176
      src/Bullet.cpp
  7. 14
      src/Bullet.h
  8. 2
      src/network/Server.cpp
  9. 73
      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/recordings
/bin/data/models
/bin/data/dataset
/bin/data/dataset1
/bin/data/main_dataset
/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.

176
src/Bullet.cpp

@ -26,8 +26,6 @@ void Bullet::setup(vector<Node>& _nodes){
}
shader.load("shaders/vertex_snap");
std::cout << workerThreads.size() << std::endl;
}
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);
world.update();
// static bool was_controller_active = false;
// static float transition_timer = 0.0f;
// static glm::vec3 start_pos;
// glm::vec3 current_pos = camera.getPosition();
// float deltaTime = ofGetLastFrameTime();
// // Detect transition from controller to inactive
// if (is_controller_active != was_controller_active) {
// if (!is_controller_active) {
// // Starting transition to new node
// transition_timer = 0.0f;
// start_pos = current_pos;
// }
// }
// if (!is_controller_active && &chosen_node != current_target_node) {
// current_target_node = &chosen_node;
// }
// // Update camera physics
// 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) {
// camera_velocity = glm::vec3(0.0f);
// }
// // Keep base zoom when controller is active
// current_zoom = current_zoom + (0.03f - current_zoom) * deltaTime * 5.0f;
// } else {
// 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
// glm::vec3 ideal_pos = glm::mix(start_pos, target_position, progress);
// camera_velocity = (ideal_pos - current_pos) / deltaTime;
// } else {
// // 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
// float maxSpeed = 25.0f;
// float currentSpeed = glm::length(camera_velocity);
// if (currentSpeed > maxSpeed) {
// camera_velocity = (camera_velocity / currentSpeed) * maxSpeed;
// }
// }
// camera.setScale(current_zoom);
// // Update position using velocity
// glm::vec3 new_position = current_pos + camera_velocity * deltaTime;
// camera.setPosition(new_position);
// was_controller_active = is_controller_active;
updateRepulsionNode();
cameraBounds = getCameraBounds(camera);
world.update();
float d_time = ofGetLastFrameTime();
glm::vec3 target_pos = chosen_node.collider->getPosition();
glm::vec3 current_pos = camera.getPosition();
glm::vec3 dir = current_pos - target_pos;
float dist = glm::length(dir);
glm::vec3 norm_dir = glm::normalize(dir);
if (is_controller_active) {
if (glm::length(camera_velocity) > 0.0f) {
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);
}
}
} else {
float distance_factor = glm::min(dist / 50.0f, 1.0f);
float current_acceleration = ACCELERATION * distance_factor;
camera_velocity += -norm_dir * current_acceleration * d_time;
if (dist < 5.0f) {
float decel_factor = dist / 5.0f;
camera_velocity *= (1.0f - (1.0f - decel_factor) * d_time * 10.0f);
}
float mag = glm::length(camera_velocity);
if (mag > MAX_VELOCITY) {
camera_velocity = glm::normalize(camera_velocity) * MAX_VELOCITY;
}
// Smoothed zoom based on velocity
float vel_magnitude = glm::length(camera_velocity);
static float current_zoom = 0.02f; // Store current zoom
float target_zoom = ofMap(vel_magnitude, 0, MAX_VELOCITY, 0.02, 0.3, true);
// Smooth lerp to target zoom
current_zoom = current_zoom + (target_zoom - current_zoom) * 0.1f;
camera.setScale(current_zoom);
}
camera.setPosition(current_pos + camera_velocity * d_time);
if (glm::length(current_pos - target_pos) < 0.01f) {
camera.setPosition(target_pos);
camera_velocity = glm::vec3(0.0f);
}
}
void Bullet::draw(){
@ -194,7 +152,7 @@ void Bullet::draw(){
ss << "Camera Position: " << camera.getPosition() << std::endl;
ss << "Camera Scale: " << camera.getScale() << std::endl;
ss << "Camera Bounds: " << cameraBounds.z << std::endl;
ofSetColor(255, 255, 255);
ofSetColor(ofColor::blue);
ofDrawBitmapString(ss.str().c_str(), 20, 20);
now = false;
}
@ -242,36 +200,6 @@ void Bullet::workerThreadFunction(int threadId) {
}
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) {
std::lock_guard<std::mutex> lock(shapeMutex);

14
src/Bullet.h

@ -18,6 +18,12 @@ struct Node {
int error;
};
struct CameraPosition {
glm::vec3 position;
glm::quat rotation;
float time;
};
class Bullet{
public:
void setup(vector<Node>& _nodes);
@ -60,6 +66,12 @@ class Bullet{
bool was_camera_active = false;
float current_zoom = 0.03f;
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;
ofTexture tex;
@ -143,6 +155,4 @@ class Bullet{
bool now = true;
bool new_chosen_node;
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());
vector<int> ids = tree.query(vp_queries, 1);
chosen_node = &nodes[ids[0]];
ofLogNotice() << chosen_node->tsne_position;
//Notice() << chosen_node->tsne_position;
} else {
// Calculate the time since the last change

73
src/ofApp.cpp

@ -4,10 +4,10 @@
void ofApp::setup(){
/* 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_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_alpha.allocate((ofGetWindowWidth() / 3) * 1, 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);
/* 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 */
// portrait_camera.enableOrtho();
// portrait_camera.setNearClip(-10000);
// portrait_camera.setFarClip(10000);
portrait_camera.setPosition(116.388, -441.054, 967.724);
portrait_camera.setOrientation(rot);
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();
createNodes("data/json/embeddings.json");
createNodes("data/json/sv_embeddings.json");
buildMeshes();
@ -144,7 +155,8 @@ void ofApp::update(){
//mapper.update();
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);
//ofClear(0);
shaders.begin();
portrait_fbo.draw(ofGetWindowWidth() / 3, 0);
portrait_fbo.draw(ofGetWindowWidth() / 2, 0);
shaders.setUniformTexture("tex0", t, 0);
shaders.setUniformTexture("tex1", bayer, 1);
shaders.setUniform2f("resolution", map_w, map_h);
@ -243,7 +255,7 @@ void ofApp::drawPortrait(){
// Move to center of FBO
ofTranslate(portrait_pre_fbo.getWidth()/2, portrait_pre_fbo.getHeight() * 0.6); // 0.8
// Apply scale
ofScale(p_scale);
ofScale(1);
// Move back by half the scaled image dimensions
ofTranslate(-scaledWidth/2, -scaledHeight/2);
// Draw at 0,0 since we've already translated
@ -396,25 +408,28 @@ void ofApp::createNodes(std::string json_path){
}
/* setup nodes */
for(const auto& j : json){
if(j.contains("vector") && j["vector"].is_array()){
Node n;
n.img.load(j["image"]);
n.tex = n.img.getTexture();
n.error = j["lost"];
std::vector<float> t_embedding;
int count = 0;
for (const auto& value: j["vector"]){
if(value.is_number() && count < 4){
t_embedding.push_back(value.get<float>());
count++;
} else {
ofLogError() << "Vector value is not a number";
bool addNode = true; // Toggle flag to track every second node
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;
n.img.load(j["image"]);
n.tex = n.img.getTexture();
n.error = j["error"];
std::vector<float> t_embedding;
int count = 0;
for (const auto& value: j["vector"]) {
if(value.is_number()) {
t_embedding.push_back(value.get<float>());
count++;
} else {
ofLogError() << "Vector value is not a number";
}
}
n.raw_embedding = t_embedding;
nodes.push_back(n);
}
n.raw_embedding = t_embedding;
nodes.push_back(n);
addNode = !addNode; // Toggle the flag after each valid node
}
}
ofLogNotice() << "node count: " << nodes.size();
@ -534,6 +549,12 @@ void ofApp::keyPressed(int key) {
plane_size -=5;
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);
}
//mapper.keyPressed(key);
}

3
src/ofApp.h

@ -117,4 +117,7 @@ class ofApp : public ofBaseApp{
int map_h = 960;
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) {
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 << " ";
//std::cout << "\nNearest neighbors:\n";
for (int i = 0; i < k; ++i) {
indexes.push_back(indices[i]);

Loading…
Cancel
Save