Skip to content

Commit 8bfaf4a

Browse files
committed
optimized load between threads
1 parent 57ea8a8 commit 8bfaf4a

File tree

14 files changed

+233
-212
lines changed

14 files changed

+233
-212
lines changed

src/objects/computer_vision/ChromaKey.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,6 @@ void ChromaKey::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9494
//--------------------------------------------------------------
9595
void ChromaKey::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
9696

97-
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
98-
if(!isInputConnected){
99-
isInputConnected = true;
100-
chromakey = new ofxChromaKeyShader(static_cast<ofTexture *>(_inletParams[0])->getWidth(),static_cast<ofTexture *>(_inletParams[0])->getHeight());
101-
updateChromaVars();
102-
}
103-
104-
if(this->inletsConnected[1] && static_cast<ofTexture *>(_inletParams[1])->isAllocated()){
105-
chromakey->updateChromakeyMask(*static_cast<ofTexture *>(_inletParams[0]),*static_cast<ofTexture *>(_inletParams[1]));
106-
*static_cast<ofTexture *>(_outletParams[0]) = chromakey->fbo_final.getTexture();
107-
}else{
108-
*static_cast<ofTexture *>(_outletParams[0]) = *static_cast<ofTexture *>(_inletParams[0]);
109-
}
110-
}else{
111-
isInputConnected = false;
112-
}
113-
11497
if(!loaded){
11598
loaded = true;
11699
chromaBgColor.set(this->getCustomVar("RED"),this->getCustomVar("GREEN"),this->getCustomVar("BLUE"));
@@ -128,6 +111,25 @@ void ChromaKey::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjec
128111

129112
//--------------------------------------------------------------
130113
void ChromaKey::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
114+
115+
// UPDATE SHADER
116+
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
117+
if(!isInputConnected){
118+
isInputConnected = true;
119+
chromakey = new ofxChromaKeyShader(static_cast<ofTexture *>(_inletParams[0])->getWidth(),static_cast<ofTexture *>(_inletParams[0])->getHeight());
120+
updateChromaVars();
121+
}
122+
123+
if(this->inletsConnected[1] && static_cast<ofTexture *>(_inletParams[1])->isAllocated()){
124+
chromakey->updateChromakeyMask(*static_cast<ofTexture *>(_inletParams[0]),*static_cast<ofTexture *>(_inletParams[1]));
125+
*static_cast<ofTexture *>(_outletParams[0]) = chromakey->fbo_final.getTexture();
126+
}else{
127+
*static_cast<ofTexture *>(_outletParams[0]) = *static_cast<ofTexture *>(_inletParams[0]);
128+
}
129+
}else{
130+
isInputConnected = false;
131+
}
132+
131133
ofSetColor(255);
132134
// draw node texture preview with OF
133135
if(scaledObjW*canvasZoom > 90.0f){

src/objects/computer_vision/HaarTracking.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ void HaarTracking::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9797

9898
//--------------------------------------------------------------
9999
void HaarTracking::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
100+
101+
}
102+
103+
//--------------------------------------------------------------
104+
void HaarTracking::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
100105

101-
// HAAR Tracking
106+
// HAAR Tracking UPDATE
102107
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
103108

104109
if(!isFBOAllocated){
@@ -118,7 +123,7 @@ void HaarTracking::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
118123
static_cast<vector<float> *>(_outletParams[1])->push_back(haarFinder->size());
119124

120125
for(int i = 0; i < haarFinder->size(); i++) {
121-
126+
122127
// blob id
123128
int label = haarFinder->getLabel(i);
124129

@@ -145,11 +150,8 @@ void HaarTracking::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
145150
}else{
146151
isFBOAllocated = false;
147152
}
148-
149-
}
150153

151-
//--------------------------------------------------------------
152-
void HaarTracking::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
154+
// HAAR Tracking DRAW
153155
ofSetColor(255);
154156
if(this->inletsConnected[0] && outputFBO->isAllocated() && static_cast<ofTexture *>(_outletParams[0])->isAllocated()){
155157

src/objects/computer_vision/MotionDetection.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ void MotionDetection::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow
8585
//--------------------------------------------------------------
8686
void MotionDetection::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
8787

88+
if(!loaded){
89+
loaded = true;
90+
threshold = this->getCustomVar("THRESHOLD");
91+
noise = this->getCustomVar("NOISE_COMP");
92+
}
93+
94+
}
95+
96+
//--------------------------------------------------------------
97+
void MotionDetection::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
98+
99+
// MOTION DETECTION UPDATE
88100
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
89101
if(!newConnection){
90102
newConnection = true;
@@ -122,22 +134,10 @@ void MotionDetection::updateObjectContent(map<int,shared_ptr<PatchObject>> &patc
122134
newConnection = false;
123135
}
124136

125-
if(!loaded){
126-
loaded = true;
127-
threshold = this->getCustomVar("THRESHOLD");
128-
noise = this->getCustomVar("NOISE_COMP");
129-
}
130-
131137
frameCounter++;
132138

133139
}
134140

135-
//--------------------------------------------------------------
136-
void MotionDetection::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
137-
ofSetColor(255);
138-
139-
}
140-
141141
//--------------------------------------------------------------
142142
void MotionDetection::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
143143

src/objects/computer_vision/OpticalFlow.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,26 @@ void OpticalFlow::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9999
//--------------------------------------------------------------
100100
void OpticalFlow::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
101101

102+
if(!loaded){
103+
loaded = true;
104+
105+
fbUseGaussian = static_cast<bool>(floor(this->getCustomVar("FB_USE_GAUSSIAN")));
106+
fbPyrScale = this->getCustomVar("FB_PYR_SCALE");
107+
fbLevels = this->getCustomVar("FB_LEVELS");
108+
fbWinSize = this->getCustomVar("FB_WIN_SIZE");
109+
fbIterations = this->getCustomVar("FB_ITERATIONS");
110+
fbPolyN = this->getCustomVar("FB_POLY_N");
111+
fbPolySigma = this->getCustomVar("FB_POLY_SIGMA");
112+
}
113+
114+
}
115+
116+
//--------------------------------------------------------------
117+
void OpticalFlow::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
118+
119+
// OPTICAL FLOW UPDATE
102120
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
103-
121+
104122
if(!isFBOAllocated){
105123
isFBOAllocated = true;
106124
pix = new ofPixels();
@@ -145,22 +163,7 @@ void OpticalFlow::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObj
145163
isFBOAllocated = false;
146164
}
147165

148-
if(!loaded){
149-
loaded = true;
150-
151-
fbUseGaussian = static_cast<bool>(floor(this->getCustomVar("FB_USE_GAUSSIAN")));
152-
fbPyrScale = this->getCustomVar("FB_PYR_SCALE");
153-
fbLevels = this->getCustomVar("FB_LEVELS");
154-
fbWinSize = this->getCustomVar("FB_WIN_SIZE");
155-
fbIterations = this->getCustomVar("FB_ITERATIONS");
156-
fbPolyN = this->getCustomVar("FB_POLY_N");
157-
fbPolySigma = this->getCustomVar("FB_POLY_SIGMA");
158-
}
159-
160-
}
161-
162-
//--------------------------------------------------------------
163-
void OpticalFlow::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
166+
// OPTICAL FLOW DRAW
164167
if(this->inletsConnected[0] && outputFBO->isAllocated() && static_cast<ofTexture *>(_outletParams[0])->isAllocated()){
165168

166169
outputFBO->begin();

src/objects/scripting/PythonScript.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ void PythonScript::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
108108
pathChanged(watcher.nextEvent());
109109
}
110110

111+
if(needToLoadScript){
112+
needToLoadScript = false;
113+
loadScript(filepath);
114+
}
115+
116+
}
117+
118+
//--------------------------------------------------------------
119+
void PythonScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
120+
111121
///////////////////////////////////////////
112122
// PYTHON UPDATE
113123
if(script){
@@ -137,15 +147,6 @@ void PythonScript::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
137147
}
138148
///////////////////////////////////////////
139149

140-
if(needToLoadScript){
141-
needToLoadScript = false;
142-
loadScript(filepath);
143-
}
144-
145-
}
146-
147-
//--------------------------------------------------------------
148-
void PythonScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
149150
ofSetColor(255);
150151
// draw node texture preview with OF
151152
if(scaledObjW*canvasZoom > 90.0f){

src/objects/scripting/ShaderObject.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
198198
pathChanged(watcher.nextEvent());
199199
}
200200

201+
202+
if(!loaded){
203+
loaded = true;
204+
prevW = this->getCustomVar("WIDTH");
205+
prevH = this->getCustomVar("HEIGHT");
206+
this->width = prevW;
207+
this->height = prevH;
208+
}
209+
}
210+
211+
//--------------------------------------------------------------
212+
void ShaderObject::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
213+
201214
///////////////////////////////////////////
202215
// SHADER UPDATE
203216
if(scriptLoaded){
@@ -279,17 +292,6 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
279292
*static_cast<ofTexture *>(_outletParams[0]) = fbo->getTexture();
280293
///////////////////////////////////////////
281294

282-
if(!loaded){
283-
loaded = true;
284-
prevW = this->getCustomVar("WIDTH");
285-
prevH = this->getCustomVar("HEIGHT");
286-
this->width = prevW;
287-
this->height = prevH;
288-
}
289-
}
290-
291-
//--------------------------------------------------------------
292-
void ShaderObject::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
293295
ofSetColor(255);
294296
if(static_cast<ofTexture *>(_outletParams[0])->isAllocated()){
295297
// draw node texture preview with OF

src/objects/video/KinectGrabber.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ void KinectGrabber::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
113113
}
114114
}
115115

116+
if(!loaded){
117+
loaded = true;
118+
if(weHaveKinect){
119+
120+
colorCleanImage.allocate(kinectWidth, kinectHeight);
121+
cleanImage.allocate(kinectWidth, kinectHeight);
122+
grayThreshNear.allocate(kinectWidth, kinectHeight);
123+
grayThreshFar.allocate(kinectWidth, kinectHeight);
124+
125+
loadKinectSettings();
126+
127+
static_cast<ofxKinect *>(_outletParams[2])->setRegistration(true);
128+
static_cast<ofxKinect *>(_outletParams[2])->init(isIR,true,true);
129+
static_cast<ofxKinect *>(_outletParams[2])->open(deviceID);
130+
static_cast<ofxKinect *>(_outletParams[2])->setCameraTiltAngle(0);
131+
132+
}
133+
}
134+
135+
}
136+
137+
//--------------------------------------------------------------
138+
void KinectGrabber::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
139+
116140
// KINECT UPDATE
117141
if(weHaveKinect && static_cast<ofxKinect *>(_outletParams[2])->isInitialized() && static_cast<ofxKinect *>(_outletParams[2])->isConnected()){
118142
static_cast<ofxKinect *>(_outletParams[2])->update();
@@ -141,29 +165,6 @@ void KinectGrabber::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
141165
}
142166
}
143167

144-
if(!loaded){
145-
loaded = true;
146-
if(weHaveKinect){
147-
148-
colorCleanImage.allocate(kinectWidth, kinectHeight);
149-
cleanImage.allocate(kinectWidth, kinectHeight);
150-
grayThreshNear.allocate(kinectWidth, kinectHeight);
151-
grayThreshFar.allocate(kinectWidth, kinectHeight);
152-
153-
loadKinectSettings();
154-
155-
static_cast<ofxKinect *>(_outletParams[2])->setRegistration(true);
156-
static_cast<ofxKinect *>(_outletParams[2])->init(isIR,true,true);
157-
static_cast<ofxKinect *>(_outletParams[2])->open(deviceID);
158-
static_cast<ofxKinect *>(_outletParams[2])->setCameraTiltAngle(0);
159-
160-
}
161-
}
162-
163-
}
164-
165-
//--------------------------------------------------------------
166-
void KinectGrabber::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
167168
// background
168169
if(scaledObjW*canvasZoom > 90.0f){
169170
ofSetColor(34,34,34);

src/objects/video/PixelsToTexture.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ void PixelsToTexture::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow
6767
//--------------------------------------------------------------
6868
void PixelsToTexture::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
6969

70+
}
71+
72+
//--------------------------------------------------------------
73+
void PixelsToTexture::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
74+
7075
if(this->inletsConnected[0]){
7176
if(static_cast<ofPixels *>(_inletParams[0])->getWidth() > 0 && static_cast<ofPixels *>(_inletParams[0])->getHeight() > 0){
7277
static_cast<ofTexture *>(_outletParams[0])->loadData(*static_cast<ofPixels *>(_inletParams[0]));
@@ -75,12 +80,6 @@ void PixelsToTexture::updateObjectContent(map<int,shared_ptr<PatchObject>> &patc
7580

7681
}
7782

78-
//--------------------------------------------------------------
79-
void PixelsToTexture::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
80-
ofSetColor(255);
81-
82-
}
83-
8483
//--------------------------------------------------------------
8584
void PixelsToTexture::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
8685

src/objects/video/TextureToPixels.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ void TextureToPixels::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow
6767
//--------------------------------------------------------------
6868
void TextureToPixels::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
6969

70-
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
71-
static_cast<ofTexture *>(_inletParams[0])->readToPixels(*static_cast<ofPixels *>(_outletParams[0]));
72-
}
73-
7470
}
7571

7672
//--------------------------------------------------------------
7773
void TextureToPixels::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
78-
ofSetColor(255);
79-
74+
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
75+
static_cast<ofTexture *>(_inletParams[0])->readToPixels(*static_cast<ofPixels *>(_outletParams[0]));
76+
}
8077
}
8178

8279
//--------------------------------------------------------------

0 commit comments

Comments
 (0)