float ofApp::getAverage(ofxJSONElement vals) { float sum = 0; for (int i = 0; i < vals.size(); i++) { sum += vals[i][1].asFloat(); } return sum / vals.size(); }
ofVec2f ofApp::getMinMax(ofxJSONElement vals) { ofVec2f minMax; float min; float max; for (int i = 0; i < vals.size(); i++) { if (i == 0) { min = vals[i][1].asFloat(); max = vals[i][1].asFloat(); } if (min > vals[i][1].asFloat()) { min = vals[i][1].asFloat(); } if (max < vals[i][1].asFloat()) { max = vals[i][1].asFloat(); } } minMax.set(min,max); return minMax; }
void Spot:: loadBackPoints( ofxJSONElement json,int _number){ // cleanPoints(); number = _number; frameCurrent=0; frameFirstBack=0; frameLastBack=0; int points = json.size(); if(points>= 2) { int pointBottomIndex=0; frameFirstBack= json[pointBottomIndex]["frame"].asInt(); frameCurrent=frameFirstBack; SpotPoint * pointBottom = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); backFollower = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); SpotPoint * pointTop; addBackPoint(frameCurrent,pointBottom); //pointsMap[frameCurrent]=pointBottom; frameCurrent++; for(int pointTopIndex=pointBottomIndex+1; pointTopIndex<points; pointTopIndex++) { pointTop = new SpotPoint( json[pointTopIndex]["x"].asInt(), json[pointTopIndex]["y"].asInt(), json[pointTopIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointTopIndex]["alpha"].asInt() ); while(frameCurrent<=json[pointTopIndex]["frame"].asInt()) { addBackPoint(frameCurrent,pointInterPolateFrom( pointBottom, pointTop, json[pointBottomIndex]["frame"].asInt(), frameCurrent, json[pointTopIndex]["frame"].asInt() )); //cout << "added frame: "+ofToString(frameCurrent)+" points: "+ofToString(pointsMap.size())<< endl; frameCurrent++; } addBackPoint(frameCurrent,pointTop); pointBottom = pointTop; pointBottomIndex = pointTopIndex; } frameLastBack=frameCurrent; smoothOutBacks(frameFirstBack,frameLastBack); cout <<" " << ofToString(frameCurrent)<< " frames "<< endl; } else { cout << "Spot: any point"<< endl; } cout << "[MAP SIZE ONCE LOADED ]: "+ofToString(backPointsMap.size())<< endl; cout << "[FRAMES]: "+ofToString(frameLastBack - frameFirstBack )<< endl; }
void Spot:: loadFrontPoints( ofxJSONElement json,int _number){ // cleanPoints(); number = _number; frameCurrent=0; frameFirstFront=0; frameLastFront=0; int points = json.size(); if(points>= 2) { int pointBottomIndex=0; frameFirstFront= json[pointBottomIndex]["frame"].asInt(); frameCurrent=frameFirstFront; SpotPoint * pointBottom = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); // frontFollower = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); SpotPoint * pointTop; addFrontPoint(frameCurrent,pointBottom); frameCurrent++; for(int pointTopIndex=pointBottomIndex+1; pointTopIndex<points; pointTopIndex++) { pointTop = new SpotPoint( json[pointTopIndex]["x"].asInt(), json[pointTopIndex]["y"].asInt(), json[pointTopIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointTopIndex]["alpha"].asInt() ); while(frameCurrent<=json[pointTopIndex]["frame"].asInt()) { addFrontPoint(frameCurrent,pointInterPolateFrom( pointBottom, pointTop, json[pointBottomIndex]["frame"].asInt(), frameCurrent, json[pointTopIndex]["frame"].asInt() )); //cout << "added frame: "+ofToString(frameCurrent)+" points: "+ofToString(pointsMap.size())<< endl; frameCurrent++; } addFrontPoint(frameCurrent,pointTop); pointBottom = pointTop; pointBottomIndex = pointTopIndex; } frameLastFront=frameCurrent; smoothOutFronts(frameFirstFront,frameLastFront); cout <<" " << ofToString(frameCurrent)<< " frames "<< endl; } else { cout << "Spot: dont have any point"<< endl; } cout << "[frontPointsMap ONCE LOADED ]: "+ofToString(frontPointsMap.size())<< endl; cout << "[FRAMES]: "+ofToString(frameLastFront - frameFirstFront )<< endl; verdana.loadFont("verdana.ttf", 40, true, true); verdana.setLineHeight(34.0f); verdana.setLetterSpacing(1.035); }