Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Commit

Permalink
Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbourgeois committed Jul 31, 2018
1 parent 3223984 commit cb4c39f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
55 changes: 43 additions & 12 deletions Area2OSC/src/AreaPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <locale>


AreaPolygon::AreaPolygon(ofVec2f a_oFirstPoint, vector<Augmenta::Person*> a_vPeople, int a_iIndice, int m_iAntiBounce){
AreaPolygon::AreaPolygon(ofVec2f a_oFirstPoint, vector<Augmenta::Person*> a_vPeople, string a_sName, int m_iAntiBounce){
m_oPointsColor = ofColor(246,128,248,200);
m_oLinesColor = ofColor(237,232,229,200);
m_oCompletedColor = ofColor(255, 166, 70,200);
Expand All @@ -14,15 +14,22 @@ AreaPolygon::AreaPolygon(ofVec2f a_oFirstPoint, vector<Augmenta::Person*> a_vPeo
m_fRadius = 5;
m_bIsFinished = false;
setPeopleInside(a_vPeople, m_iAntiBounce);
m_iOldPeopleInside=m_iPeopleInside;
m_iOldPeopleInside=m_iPeopleInsideCount;
m_bSelected = false;
m_fMoveIncremente = 0.001;
m_vInOsc.push_back("/area/" + ofToString(a_iIndice) + "/personEntered");
m_vOutOsc.push_back("/area/" + ofToString(a_iIndice) + "/personWillLeave");
m_vInOsc.push_back("/area/" + ofToString(a_sName) + "/personEntered");
m_vOutOsc.push_back("/area/" + ofToString(a_sName) + "/personWillLeave");
m_sPolyName = a_sName;

addPoint(a_oFirstPoint);
}

void AreaPolygon::setPolyName(string name) {
m_sPolyName = name;
m_vInOsc[0] = "/area/" + ofToString(name) + "/personEntered";
m_vOutOsc[0] = ("/area/" + ofToString(name) + "/personWillLeave");
}

//--------------------------------------------------------------
string AreaPolygon::getInOscAll(){
string tempString = m_vInOsc[0];
Expand Down Expand Up @@ -135,7 +142,7 @@ void AreaPolygon::drawPeopleInside(int width, int height){
if (m_bIsFinished){
ofDrawBitmapString("[in] " + m_vInOsc[0], ofVec2f(m_oCentroid.x * width, m_oCentroid.y * height - 20));
ofDrawBitmapString("[out] " + m_vOutOsc[0], ofVec2f(m_oCentroid.x * width, m_oCentroid.y * height - 10));
ofDrawBitmapString("people : " + ofToString(m_iPeopleInside), ofVec2f(m_oCentroid.x * width, m_oCentroid.y * height));
ofDrawBitmapString("people : " + ofToString(m_iPeopleInsideCount), ofVec2f(m_oCentroid.x * width, m_oCentroid.y * height));
}
}

Expand Down Expand Up @@ -169,7 +176,7 @@ void AreaPolygon::draw(int width,int height){
ofLine(m_vVectorPoints[0].x * width, m_vVectorPoints[0].y * height, m_vVectorPoints[m_vVectorPoints.size() - 1].x * width, m_vVectorPoints[m_vVectorPoints.size() - 1].y * height);


if (m_iPeopleInside > 0){
if (m_iPeopleInsideCount > 0){
if (m_bSelected){
ofColor tempColor = m_oNotEmptyColor;
tempColor.setBrightness(brightness);
Expand Down Expand Up @@ -220,7 +227,7 @@ void AreaPolygon::setPeopleInside(vector<Augmenta::Person*> people, int a_iBounc
ofPoint centroid;
unsigned long long currentTime = ofGetElapsedTimeMillis();
vector<int> peopleInsideRightNow;
m_iPeopleInside = 0;
m_iPeopleInsideCount = 0;

//Getting id of the persons whose inside
for (int i = 0; i < people.size(); i++){
Expand All @@ -229,6 +236,21 @@ void AreaPolygon::setPeopleInside(vector<Augmenta::Person*> people, int a_iBounc
}
}

////Getting id of the persons whose inside
//for (int i = 0; i < people.size(); i++) {
// if (std::find(peopleInsideRightNow.begin(), peopleInsideRightNow.end(), people[i]) != peopleInsideRightNow.end() && !isPointInPolygon(people[i]->centroid)) { //contains but not in area
// if () {
// peopleInsideRightNow.push_back(people[i]->pid);
// }
// }
// else { //not contains

// }


//}


//Add WaitingToLeave
for (int j = 0; j < m_vIdPeopleInside.size(); j++){
if (std::find(peopleInsideRightNow.begin(), peopleInsideRightNow.end(), m_vIdPeopleInside[j]) == peopleInsideRightNow.end()){
Expand All @@ -249,18 +271,23 @@ void AreaPolygon::setPeopleInside(vector<Augmenta::Person*> people, int a_iBounc
//Update of the people in waiting to leave list
for (int i = 0; i < m_vWaitingToLeave.size(); ++i){
if ((currentTime - m_vWaitingToLeave[i].getLeavingTime()) > a_iBounceIntervalTime){
m_vLastIdWhichLeft = m_vWaitingToLeave[i].getId();
m_vWaitingToLeave.erase(m_vWaitingToLeave.begin() + i);
}
}

//m_iPeopleInside = personns inside right now + people on the waiting to leave list
m_iPeopleInside = m_vWaitingToLeave.size() + peopleInsideRightNow.size();
//m_iPeopleInsideCount = personns inside right now + people on the waiting to leave list
m_iPeopleInsideCount = m_vWaitingToLeave.size() + peopleInsideRightNow.size();

for (int i = 0; i < peopleInsideRightNow.size(); i++) {
if(std::find(m_vIdPeopleInside.begin(), m_vIdPeopleInside.end(), peopleInsideRightNow[i]) == m_vIdPeopleInside.end())
m_vLastIdWhichEntered = peopleInsideRightNow[i];
}
m_vIdPeopleInside.clear();
m_vIdPeopleInside.swap(peopleInsideRightNow);

/*
std::cout << " people inside = " << m_iPeopleInside << std::endl;
std::cout << " people inside = " << m_iPeopleInsideCount << std::endl;
std::cout << "m_vIdPeopleInside size = " << m_vIdPeopleInside.size() << std::endl;
std::cout << "m_vWaitingToLeave size = " << m_vWaitingToLeave.size() << std::endl;
*/
Expand Down Expand Up @@ -313,6 +340,10 @@ bool AreaPolygon::removeLastPoint(){
}
}

void AreaPolygon::moveLastPoint(float x, float y) {
m_vVectorPoints[m_vVectorPoints.size() - 1].x = x;
m_vVectorPoints[m_vVectorPoints.size() - 1].y = y;
}
//--------------------------------------------------------------
void AreaPolygon::moveDown(){
bool isMovePossible = true;
Expand Down Expand Up @@ -402,8 +433,8 @@ void AreaPolygon::move(float a_iX, float a_iY){
void AreaPolygon::update(vector<Augmenta::Person*> a_vPeople, int a_iBounceIntervalTime){

setPeopleInside(a_vPeople, a_iBounceIntervalTime);
m_iPeopleMovement= m_iPeopleInside - m_iOldPeopleInside;
m_iOldPeopleInside = m_iPeopleInside;
m_iPeopleMovement= m_iPeopleInsideCount - m_iOldPeopleInside;
m_iOldPeopleInside = m_iPeopleInsideCount;

}

19 changes: 16 additions & 3 deletions Area2OSC/src/AreaPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ class AreaPolygon {
public:

//Construction
AreaPolygon(ofVec2f a_oFirstPoint, vector<Augmenta::Person*> a_vPeople, int a_iIndice, int m_iAntiBounce);
AreaPolygon(ofVec2f a_oFirstPoint, vector<Augmenta::Person*> a_vPeople, string a_sName, int m_iAntiBounce);

//Inline
inline bool isCompleted(){ return m_bIsFinished; };
inline int getSize(){ return m_vVectorPoints.size(); };
inline ofVec2f getPoint(int a_iIndice){ return m_vVectorPoints[a_iIndice]; };
inline void hasBeenSelected(bool a_bSelected){ m_bSelected = a_bSelected; };
inline int getPeopleMovement(){ return m_iPeopleMovement; };
inline int getPeopleInside(){ return m_iPeopleInside; };
inline int getPeopleInsideCount(){ return m_iPeopleInsideCount; };
inline int getPersonInside(int index) { return m_vIdPeopleInside[index]; };
inline int getLastIdWhichLeft() { return m_vLastIdWhichLeft; };
inline int getLastIdWhichEntered() { return m_vLastIdWhichEntered; };

//Osc
void setPolyName(string name);
inline string getPolyName() {return m_sPolyName; };
inline string getInOscAdress(){ return m_vInOsc[0]; };
inline string getOutOscAdress(){ return m_vOutOsc[0]; };
inline ofxOscMessage getInOscMessage(){ return m_oOscMessageIn; };
Expand All @@ -51,6 +56,9 @@ class AreaPolygon {
void drawPeopleInside(int width, int height);
void drawPeopleMovement(int width, int height);

//move point
void moveLastPoint(float x, float y);

//Move Poly
void moveLeft();
void moveRight();
Expand All @@ -70,11 +78,16 @@ class AreaPolygon {
bool doesStringContainOnlyNumberAndOnePoint(string s);

private:
template <class T>
void contains(vector<T> list, int height);

string m_sPolyName;
vector<ofVec2f> m_vVectorPoints;
bool m_bIsFinished;
int m_iPeopleInside;
int m_iPeopleInsideCount;
int m_iOldPeopleInside;
int m_vLastIdWhichLeft;
int m_vLastIdWhichEntered;
bool m_bSelected;
ofVec2f m_oCentroid;
int m_iPeopleMovement;
Expand Down
2 changes: 2 additions & 0 deletions Area2OSC/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "AreaPolygon.h"
#include "AugmentaScene.h"

#include "ofFileUtils.h"
#include "ofMain.h"
#include "ofxGui.h"
#include "ofxOsc.h"
Expand Down Expand Up @@ -133,6 +134,7 @@ class ofApp : public ofBaseApp {
ofxFloatSlider m_fZoomCoef;

// Gui parameters inside m_SecondGroup
ofxInputField<string> m_sPolyName;
ofxToggle m_oToggleClearAll;
ofxToggle m_oToggleDeleteLastPoly;

Expand Down

0 comments on commit cb4c39f

Please sign in to comment.