|
@ -27,12 +27,19 @@ void Map::Setup(){ |
|
|
SetupNodes(); |
|
|
SetupNodes(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Map::Update(){ |
|
|
void Map::Update(std::string& vp_img, bool& is_active){ |
|
|
time = ofGetElapsedTimef(); |
|
|
time = ofGetElapsedTimef(); |
|
|
for(auto& n : nodes){ |
|
|
for(auto& n : nodes){ |
|
|
glm::vec2 offset = n.amplitude * sin(n.speed * time); |
|
|
glm::vec2 offset = n.amplitude * sin(n.speed * time); |
|
|
n.offset = glm::vec3(offset.x, offset.y, 0); |
|
|
n.offset = glm::vec3(offset.x, offset.y, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
std::cout << cam.getPosition() << std::endl; |
|
|
|
|
|
if(is_active){ |
|
|
|
|
|
has_reached = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!is_active) |
|
|
|
|
|
MoveCamera(vp_img); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Map::Draw(){ |
|
|
void Map::Draw(){ |
|
@ -46,17 +53,18 @@ void Map::Draw(){ |
|
|
ofMatrix4x4 viewMatrix = cam.getModelViewMatrix(); |
|
|
ofMatrix4x4 viewMatrix = cam.getModelViewMatrix(); |
|
|
ofMatrix4x4 mvpMatrix = projectionMatrix * viewMatrix; |
|
|
ofMatrix4x4 mvpMatrix = projectionMatrix * viewMatrix; |
|
|
|
|
|
|
|
|
for (auto& n :nodes){ |
|
|
for (auto& n :sortedNodes){ |
|
|
glm::vec3 node_position = n.position + n.offset; |
|
|
glm::vec3 node_position = n->position + n->offset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isFrustum(node_position, 50)){ |
|
|
if(isFrustum(node_position, 50)){ |
|
|
n.texture.getTexture().bind(); |
|
|
n->texture.getTexture().bind(); |
|
|
ofPushMatrix(); |
|
|
ofPushMatrix(); |
|
|
ofFill(); |
|
|
ofFill(); |
|
|
n.geom.setPosition(node_position); |
|
|
n->geom.setPosition(node_position); |
|
|
n.geom.draw(); |
|
|
n->geom.draw(); |
|
|
ofPopMatrix(); |
|
|
ofPopMatrix(); |
|
|
n.texture.getTexture().unbind(); |
|
|
n->texture.getTexture().unbind(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -80,10 +88,10 @@ void Map::SetupNodes(){ |
|
|
ofPlanePrimitive plane; |
|
|
ofPlanePrimitive plane; |
|
|
|
|
|
|
|
|
img.load("data/" + node.image_path); |
|
|
img.load("data/" + node.image_path); |
|
|
int imageW = img.getWidth(); |
|
|
int imageW = img.getWidth() * 0.1; |
|
|
int imageH = img.getHeight(); |
|
|
int imageH = img.getHeight() * 0.1; |
|
|
int maxWidth = 100; |
|
|
int maxWidth = 1; |
|
|
int maxHeight = 100; |
|
|
int maxHeight = 1; |
|
|
float aspectRatio = (float)imageW / (float)imageH; |
|
|
float aspectRatio = (float)imageW / (float)imageH; |
|
|
|
|
|
|
|
|
// Determine plane dimensions based on aspect ratio and constraints
|
|
|
// Determine plane dimensions based on aspect ratio and constraints
|
|
@ -108,16 +116,16 @@ void Map::SetupNodes(){ |
|
|
planeH = maxWidth / aspectRatio; |
|
|
planeH = maxWidth / aspectRatio; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
plane.set(planeW, planeH); |
|
|
plane.set(imageW, imageH); |
|
|
plane.setPosition(node.position); |
|
|
plane.setPosition(node.position); |
|
|
plane.setResolution(2, 2); |
|
|
plane.setResolution(10, 10); |
|
|
plane.mapTexCoordsFromTexture(img.getTexture()); |
|
|
plane.mapTexCoordsFromTexture(img.getTexture()); |
|
|
img.getTexture().setTextureWrap(GL_REPEAT, GL_REPEAT); |
|
|
img.getTexture().setTextureWrap(GL_REPEAT, GL_REPEAT); |
|
|
plane.setScale(1); |
|
|
plane.setScale(1); |
|
|
|
|
|
|
|
|
node.geom = plane; |
|
|
node.geom = plane; |
|
|
node.texture = img; |
|
|
node.texture = img; |
|
|
node.speed = glm::vec2(ofRandom(0.1, 2), ofRandom(0.1, 2)); |
|
|
node.speed = glm::vec2(ofRandom(0.1, 0.5), ofRandom(0.1, 0.5)); |
|
|
node.amplitude = glm::vec2(ofRandom(1, 5), ofRandom(1, 5)); |
|
|
node.amplitude = glm::vec2(ofRandom(1, 5), ofRandom(1, 5)); |
|
|
node.phase = glm::vec2(ofRandom(0, TWO_PI), ofRandom(0, TWO_PI)); |
|
|
node.phase = glm::vec2(ofRandom(0, TWO_PI), ofRandom(0, TWO_PI)); |
|
|
} |
|
|
} |
|
@ -159,11 +167,16 @@ void Map::SetupTSNE(){ |
|
|
for (size_t i = 0; i < points.size(); i++){ |
|
|
for (size_t i = 0; i < points.size(); i++){ |
|
|
const auto& vec = points[i]; |
|
|
const auto& vec = points[i]; |
|
|
auto& n = nodes[i]; |
|
|
auto& n = nodes[i]; |
|
|
n.position = ( (glm::vec3(vec[0], vec[1], vec[2]) * scale) - (scale / 2) ); |
|
|
n.position = (glm::vec3(vec[0] * scale, vec[1] * scale, vec[2] * scale)); |
|
|
node_hash_map[n.image_path] = &n; |
|
|
node_hash_map[n.image_path] = &n; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
SortNodes(); |
|
|
// Instead of sorting nodes, just create a sorted reference list
|
|
|
|
|
|
for (auto& node : nodes) { |
|
|
|
|
|
sortedNodes.push_back(&node); // Pointers to the original nodes
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SortNodes(); // Sort the references for rendering
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
@ -172,18 +185,72 @@ void Map::SetupTSNE(){ |
|
|
void Map::Setup3D(){ |
|
|
void Map::Setup3D(){ |
|
|
cam.setFov(20); |
|
|
cam.setFov(20); |
|
|
cam.removeAllInteractions(); |
|
|
cam.removeAllInteractions(); |
|
|
cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_XY, OF_MOUSE_BUTTON_LEFT); |
|
|
|
|
|
cam.addInteraction(ofEasyCam::TRANSFORM_TRANSLATE_Z, OF_MOUSE_BUTTON_MIDDLE); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
Query hashmap |
|
|
Query hashmap |
|
|
*/ |
|
|
*/ |
|
|
void Map::SearchMap(){ |
|
|
bool Map::SearchMap(std::string& search_string){ |
|
|
std::string t = "dataset/20230601_webexclusi-irelandsey_cl11536538/segmented_images/000000000_0.png"; |
|
|
std::string t = search_string; |
|
|
if(node_hash_map.find(t) != node_hash_map.end()){ |
|
|
if(node_hash_map.find(t) != node_hash_map.end()){ |
|
|
Node* n = node_hash_map[t]; |
|
|
Node* n = node_hash_map[t]; |
|
|
std::cout << n->foldername << std::endl; |
|
|
std::cout << n->foldername << std::endl; |
|
|
|
|
|
return true; |
|
|
|
|
|
} else { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* search if image is in the hashmap -> if true, move to its position */ |
|
|
|
|
|
void Map::MoveCamera(std::string& vp_img){ |
|
|
|
|
|
if(SearchMap(vp_img)){ |
|
|
|
|
|
Node* n = node_hash_map[vp_img]; |
|
|
|
|
|
glm::vec3 cur_pos(cam.getPosition().x, cam.getPosition().y, cam.getPosition().z); |
|
|
|
|
|
glm::vec3 target_pos((n->position.x), (n->position.y), (n->position.z) + 100); |
|
|
|
|
|
glm::vec3 dir = target_pos - cur_pos; |
|
|
|
|
|
float dist = glm::length(dir); |
|
|
|
|
|
dir = glm::normalize(dir); |
|
|
|
|
|
accel = dir * 0.02f; |
|
|
|
|
|
vel += accel; |
|
|
|
|
|
|
|
|
|
|
|
// Define minimum and maximum velocities based on distance
|
|
|
|
|
|
const float minVelocity = 0.01f; // Minimum velocity when close to the target
|
|
|
|
|
|
const float maxVelocityDistance = 1000.0f; // Distance at which max velocity is applied
|
|
|
|
|
|
const float maxVelocity = 50.0f; // Maximum velocity
|
|
|
|
|
|
|
|
|
|
|
|
// Scale max velocity based on distance
|
|
|
|
|
|
float dynamicMaxVelocity = glm::clamp(dist / maxVelocityDistance * maxVelocity, minVelocity, maxVelocity); |
|
|
|
|
|
|
|
|
|
|
|
// Clamp the velocity to the range [-dynamicMaxVelocity, dynamicMaxVelocity]
|
|
|
|
|
|
float velocityLength = glm::length(vel); |
|
|
|
|
|
if (velocityLength > dynamicMaxVelocity) { |
|
|
|
|
|
vel = glm::normalize(vel) * dynamicMaxVelocity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update position
|
|
|
|
|
|
glm::vec3 newPosition = cur_pos + vel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cam.getPosition() == target_pos){ |
|
|
|
|
|
has_reached = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!has_reached){ |
|
|
|
|
|
cam.setPosition(target_pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::cout << "velocity " << vel << std::endl; |
|
|
|
|
|
std::cout << "target " << target_pos << std::endl; |
|
|
|
|
|
std::cout << "new position " << cam.getPosition() << std::endl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Map::buttonPressed(int key){ |
|
|
|
|
|
if(key==OF_KEY_LEFT){ |
|
|
|
|
|
z_adj -= 1; |
|
|
|
|
|
} else { |
|
|
|
|
|
z_adj += 1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -191,11 +258,9 @@ void Map::SearchMap(){ |
|
|
Sort nodes by z position, for draw calls (lowest -> highest) |
|
|
Sort nodes by z position, for draw calls (lowest -> highest) |
|
|
*/ |
|
|
*/ |
|
|
void Map::SortNodes(){ |
|
|
void Map::SortNodes(){ |
|
|
std::cout << "Sorting Nodes.." << std::endl; |
|
|
std::sort(sortedNodes.begin(), sortedNodes.end(), [](const Node* a, const Node* b){ |
|
|
std::sort(nodes.begin(), nodes.end(), [](const Node& a, const Node&b){ |
|
|
return a->position.z < b->position.z; // Sorting by z-position
|
|
|
return a.position.z < b.position.z; |
|
|
|
|
|
}); |
|
|
}); |
|
|
std::cout << "Finished Sorting!" << std::endl; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Map::isFrustum(const glm::vec3& position, float radius){ |
|
|
bool Map::isFrustum(const glm::vec3& position, float radius){ |
|
|