cailean
3 months ago
6 changed files with 156 additions and 1 deletions
@ -1,2 +1,10 @@ |
|||
ofxOpenCv |
|||
ofxOpenCv |
|||
ofxOsc |
|||
ofxOsc |
|||
ofxNetwork |
|||
ofxNetwork |
|||
ofxGui |
|||
ofxGui |
|||
ofxTSNE |
|||
ofxTSNE |
@ -0,0 +1,70 @@ |
|||
#include "Map.h" |
|||
|
|||
Map::Map(){ |
|||
|
|||
} |
|||
|
|||
void Map::Setup(){ |
|||
ofDisableArbTex(); |
|||
isDebug = true; |
|||
|
|||
json_embeddings = ofLoadJson(jsonPath); |
|||
if(!json_embeddings.is_array()){ |
|||
ofLogError() << "JSON is not an array"; |
|||
return; |
|||
} else { |
|||
std::cout << "JSON LOADED" << std::endl; |
|||
SetupTSNE(); |
|||
} |
|||
|
|||
mapFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|||
} |
|||
|
|||
void Map::Update(){ |
|||
|
|||
} |
|||
|
|||
void Map::Draw(){ |
|||
|
|||
} |
|||
|
|||
void Map::SetupNodes(){ |
|||
|
|||
} |
|||
|
|||
void Map::SetupTSNE(){ |
|||
for (const auto& entry: json_embeddings) { |
|||
if (entry.contains("vector") && entry["vector"].is_array()) { |
|||
Node n; |
|||
n.foldername = entry["folder"]; |
|||
n.image_path = entry["image"]; |
|||
n.isLost = entry["lost"].get<int>(); |
|||
|
|||
std::vector<float> emb; |
|||
|
|||
for (const auto& value: entry["vector"]){ |
|||
if(value.is_number()){ |
|||
emb.push_back(value.get<float>()); |
|||
} else { |
|||
ofLogError() << "Vector value is not a number"; |
|||
} |
|||
} |
|||
|
|||
n.emotion_vector = emb; |
|||
|
|||
nodes.push_back(n); |
|||
embeddings.push_back(emb); |
|||
} |
|||
} |
|||
|
|||
std::cout << nodes.size() << std::endl; |
|||
std::cout << embeddings.size() << std::endl; |
|||
points = tsne.run(embeddings, dims, perplexity, theta, normalise, runManually); |
|||
|
|||
for (size_t i = 0; i < points.size(); i++){ |
|||
const auto& vec = points[i]; |
|||
auto& n = nodes[i]; |
|||
n.position = glm::vec3(vec[0], vec[1], vec[2]); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,65 @@ |
|||
#ifndef _MAP |
|||
#define _MAP |
|||
|
|||
#include "ofMain.h" |
|||
#include "ofxOsc.h" |
|||
#include "ofxTSNE.h" |
|||
|
|||
struct Node { |
|||
glm::vec2 speed; |
|||
glm::vec2 amplitude; |
|||
glm::vec2 phase; |
|||
ofImage texture; |
|||
glm::vec3 position; |
|||
std::string image_path; |
|||
std::string foldername; |
|||
std::vector<float> emotion_vector; |
|||
int isLost; |
|||
}; |
|||
|
|||
class Map { |
|||
public: |
|||
|
|||
/*
|
|||
Constructor |
|||
*/ |
|||
|
|||
Map(); |
|||
|
|||
|
|||
/*
|
|||
Methods |
|||
*/ |
|||
|
|||
void Setup(); |
|||
void Update(); |
|||
void Draw(); |
|||
void SetupNodes(); |
|||
void SetupTSNE(); |
|||
|
|||
/*
|
|||
Variables |
|||
*/ |
|||
bool isDebug; |
|||
|
|||
ofFbo mapFbo; |
|||
vector<ofPlanePrimitive> geoms; |
|||
vector<Node> nodes; |
|||
|
|||
ofxTSNE tsne; |
|||
vector<vector<double>> points; |
|||
vector<vector<float>> embeddings; |
|||
int dims = 3; |
|||
float perplexity = 20; |
|||
float theta = 0.2; |
|||
bool normalise = true; |
|||
bool runManually = false; |
|||
ofJson json_embeddings; |
|||
std::string jsonPath = "data/json/embeddings.json"; |
|||
|
|||
private: |
|||
|
|||
|
|||
}; |
|||
|
|||
#endif |
Loading…
Reference in new issue