Skip to content

Commit

Permalink
two examples now!
Browse files Browse the repository at this point in the history
lots of cleanup. more to do!
  • Loading branch information
ofTheo committed Mar 31, 2010
1 parent f40dbd8 commit 4ee66d0
Show file tree
Hide file tree
Showing 12 changed files with 667 additions and 528 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build/
obj/
*.o
*.app/
.svn/
.DS_*
30 changes: 20 additions & 10 deletions ofxControlPanelDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
E4C242CD10CC650E004149E2 /* libfmodex.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C242CC10CC650E004149E2 /* libfmodex.dylib */; };
E4C2443910CC7693004149E2 /* openFrameworks-Info.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */; };
E4C246DA10CCAE22004149E2 /* freeimage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C246D910CCAE22004149E2 /* freeimage.a */; };
E4E48C961163DB25007DCE2F /* videoMotionExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E48C951163DB25007DCE2F /* videoMotionExample.cpp */; };
E4E48D421163E4F6007DCE2F /* backgroundSubtractionExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E48D411163E4F6007DCE2F /* backgroundSubtractionExample.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -122,7 +124,6 @@
A1A2F136111F5772000703E4 /* testApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = testApp.h; sourceTree = "<group>"; };
A1A2F138111F5772000703E4 /* vectorField.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = vectorField.cpp; path = vectorField/vectorField.cpp; sourceTree = "<group>"; };
A1A2F139111F5772000703E4 /* vectorField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vectorField.h; path = vectorField/vectorField.h; sourceTree = "<group>"; };
A1A2F13B111F5772000703E4 /* computerVision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = computerVision.h; path = vision/computerVision.h; sourceTree = "<group>"; };
A1A2F151111F57F9000703E4 /* Instructions.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Instructions.txt; sourceTree = "<group>"; };
A1A2F152111F57F9000703E4 /* install.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = install.xml; sourceTree = "<group>"; };
A1A2F154111F57F9000703E4 /* ofxDirList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxDirList.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -182,7 +183,7 @@
A1A2F1E8111F57F9000703E4 /* tinyxmlparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxmlparser.cpp; sourceTree = "<group>"; };
A1A2F1EA111F57F9000703E4 /* ofxXmlSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxXmlSettings.cpp; sourceTree = "<group>"; };
A1A2F1EB111F57F9000703E4 /* ofxXmlSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxXmlSettings.h; sourceTree = "<group>"; };
A1A2F1F9111F57F9000703E4 /* emptyExampleDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = emptyExampleDebug.app; sourceTree = BUILT_PRODUCTS_DIR; };
A1A2F1F9111F57F9000703E4 /* ofxControlPanelDemoDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ofxControlPanelDemoDebug.app; sourceTree = BUILT_PRODUCTS_DIR; };
E45BE0390E8CC647009D7055 /* FreeImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FreeImage.h; path = ../../../libs/freeimage/include/FreeImage.h; sourceTree = SOURCE_ROOT; };
E45BE03F0E8CC650009D7055 /* fmod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = fmod.h; path = ../../../libs/fmodex/include/fmod.h; sourceTree = SOURCE_ROOT; };
E45BE0400E8CC650009D7055 /* fmod.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fmod.hpp; path = ../../../libs/fmodex/include/fmod.hpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -265,6 +266,10 @@
E4C2429310CC5C38004149E2 /* freetype.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = freetype.a; path = ../../../libs/freetype/lib/osx/freetype.a; sourceTree = SOURCE_ROOT; };
E4C242CC10CC650E004149E2 /* libfmodex.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libfmodex.dylib; path = ../../../libs/fmodex/lib/osx/libfmodex.dylib; sourceTree = SOURCE_ROOT; };
E4C246D910CCAE22004149E2 /* freeimage.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = freeimage.a; path = ../../../libs/FreeImage/lib/osx/freeimage.a; sourceTree = SOURCE_ROOT; };
E4E48C951163DB25007DCE2F /* videoMotionExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = videoMotionExample.cpp; sourceTree = "<group>"; };
E4E48D401163E4F6007DCE2F /* backgroundSubtractionExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = backgroundSubtractionExample.h; sourceTree = "<group>"; };
E4E48D411163E4F6007DCE2F /* backgroundSubtractionExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = backgroundSubtractionExample.cpp; sourceTree = "<group>"; };
E4E48DAA1163EDA9007DCE2F /* videoMotionExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = videoMotionExample.h; path = src/videoMotionExample.h; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -730,7 +735,7 @@
E4B69E1C0A3A1BDC003C02F2 /* src */,
E4C2422310CC54B6004149E2 /* openFrameworks */,
E45BE0360E8CC5DE009D7055 /* libs */,
A1A2F1F9111F57F9000703E4 /* emptyExampleDebug.app */,
A1A2F1F9111F57F9000703E4 /* ofxControlPanelDemoDebug.app */,
);
sourceTree = "<group>";
};
Expand All @@ -741,7 +746,10 @@
A1A2F134111F5772000703E4 /* ofAddons.h */,
A1A2F138111F5772000703E4 /* vectorField.cpp */,
A1A2F139111F5772000703E4 /* vectorField.h */,
A1A2F13B111F5772000703E4 /* computerVision.h */,
E4E48D411163E4F6007DCE2F /* backgroundSubtractionExample.cpp */,
E4E48D401163E4F6007DCE2F /* backgroundSubtractionExample.h */,
E4E48C951163DB25007DCE2F /* videoMotionExample.cpp */,
E4E48DAA1163EDA9007DCE2F /* videoMotionExample.h */,
A1A2F135111F5772000703E4 /* testApp.cpp */,
A1A2F136111F5772000703E4 /* testApp.h */,
A1A2F133111F5772000703E4 /* main.cpp */,
Expand Down Expand Up @@ -835,9 +843,9 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
E4B69B5A0A3A1756003C02F2 /* emptyExample */ = {
E4B69B5A0A3A1756003C02F2 /* ofxControlPanelDemo */ = {
isa = PBXNativeTarget;
buildConfigurationList = E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "emptyExample" */;
buildConfigurationList = E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "ofxControlPanelDemo" */;
buildPhases = (
E4B69B580A3A1756003C02F2 /* Sources */,
E4B69B590A3A1756003C02F2 /* Frameworks */,
Expand All @@ -850,9 +858,9 @@
dependencies = (
E4C2422810CC54DA004149E2 /* PBXTargetDependency */,
);
name = emptyExample;
name = ofxControlPanelDemo;
productName = myOFApp;
productReference = A1A2F1F9111F57F9000703E4 /* emptyExampleDebug.app */;
productReference = A1A2F1F9111F57F9000703E4 /* ofxControlPanelDemoDebug.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -874,7 +882,7 @@
);
projectRoot = "";
targets = (
E4B69B5A0A3A1756003C02F2 /* emptyExample */,
E4B69B5A0A3A1756003C02F2 /* ofxControlPanelDemo */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -949,6 +957,8 @@
E48D9D191159484E00A7B771 /* guiTypeVideo.cpp in Sources */,
E4A056F11163AE860087BEF7 /* guiCallbackValue.cpp in Sources */,
E4A056F41163B2000087BEF7 /* guiCallback.cpp in Sources */,
E4E48C961163DB25007DCE2F /* videoMotionExample.cpp in Sources */,
E4E48D421163E4F6007DCE2F /* backgroundSubtractionExample.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1246,7 +1256,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "emptyExample" */ = {
E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "ofxControlPanelDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E4B69B600A3A1757003C02F2 /* Debug */,
Expand Down
79 changes: 79 additions & 0 deletions src/backgroundSubtractionExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* backgroundSubtractionExample.cpp
* ofxControlPanelDemo
*
* Created by theo on 31/03/2010.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/

#include "backgroundSubtractionExample.h"

#include "backgroundSubtractionExample.h"

//------------
void backgroundSubtractionExample::setup(int width, int height){

color.allocate(width, height);
gray.allocate(width, height);
thresh.allocate(width, height);
background.allocate(width, height);

threshAmnt = 29;
numFrames = 0;
}

//-----------
void backgroundSubtractionExample::update(unsigned char * pixelsIn, int width, int height ){
color.setFromPixels(pixelsIn, width, height);

//convert the color image to grayscale
gray = color;

if( numFrames < 20 ){
background = gray;
}

if( mode == BG_ABS ){
//do absolute diff between the prev frame and current frame
//all pixels that are different will show up as non-black
thresh.absDiff(gray, background);
}else if( mode == BG_GREATER ){
thresh = gray;
thresh -= background;
}else if( mode == BG_LESS ){
thresh = background;
thresh -= gray;
}

//threshold to 0 or 255 value
thresh.threshold(threshAmnt);

numFrames++;
}

//-----------
void backgroundSubtractionExample::draw(float x, float y){
ofSetColor(0xFFFFFF);
gray.draw(x, y);
background.draw(x + gray.width, y);
thresh.draw(x, y + gray.height);
}

//-----------
void backgroundSubtractionExample::setThreshold(int threshVal){
threshAmnt = (int)threshVal;
}

//-----------
void backgroundSubtractionExample::captureBackground(){
background = gray;
}

//-----------
void backgroundSubtractionExample::setDifferenceMode(int modeIn){
mode = (captureMode)modeIn;
}



53 changes: 53 additions & 0 deletions src/backgroundSubtractionExample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* backgroundSubtractionExample.h
* ofxControlPanelDemo
*
* Created by theo on 31/03/2010.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/

#pragma once

#include "ofMain.h"
#include "ofxOpenCv.h"

typedef enum{
BG_ABS,
BG_GREATER,
BG_LESS
}captureMode;

class backgroundSubtractionExample{

public:

//------------
void setup(int width, int height);
void update(unsigned char * pixelsIn, int width, int height );

//-----------
//here we add up all the directions from the
//vector field and average them out to an overall
//direction - this will be quite small so you will want
//to scale it up.

//-----------
void draw(float x, float y);

void setThreshold(int threshVal);
void setDifferenceMode(int modeIn);
void captureBackground();

ofxCvColorImage color;
ofxCvGrayscaleImage gray;

ofxCvGrayscaleImage background;
ofxCvGrayscaleImage thresh;

captureMode mode;

int numFrames;
float threshAmnt;

};
2 changes: 2 additions & 0 deletions src/ofxControlPanel/guiTypeToggle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void guiTypeToggle::setup(string toggleName, bool defaultVal){
//-----------------------------------------------
void guiTypeToggle::updateValue(){
//CB
notify();
}

//-----------------------------------------------.
Expand All @@ -23,6 +24,7 @@ void guiTypeToggle::updateGui(float x, float y, bool firstHit, bool isRelative){
}

//CB
notify();
}
}

Expand Down
111 changes: 111 additions & 0 deletions src/ofxControlPanel/ofxControlPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ void ofxControlPanel::setWhichColumn(int column){
panels[currentPanel]->selectColumn(column);
}

//---------------------------------------------
int ofxControlPanel::getSelectedPanel(){
return selectedPanel;
}

//---------------------------------------------
void ofxControlPanel::setSelectedPanel(int whichPanel){
if( whichPanel >= 0 && whichPanel < panels.size()){
selectedPanel = whichPanel;
}
}

// ############################################################## //
// ##
Expand Down Expand Up @@ -364,6 +375,106 @@ guiTypeTextDropDown * ofxControlPanel::addTextDropDown(string name, string xmlNa
return tmp;
}

// ############################################################## //
// ##
// ## events
// ##
// ############################################################## //

//THIS SHOULD BE CALLED AFTER ALL GUI SETUP CALLS HAVE HAPPENED
//---------------------------------------------
void ofxControlPanel::setupEvents(){
eventsEnabled = true;
for(int i = 0; i < guiObjects.size(); i++){
ofAddListener(guiObjects[i]->guiEvent, this, &ofxControlPanel::eventsIn);
}

//setup an event group for each panel
for(int i = 0; i < panels.size(); i++){

vector <string> xmlNames;

for(int j = 0; j < panels[i]->children.size(); j++){
xmlNames.push_back(panels[i]->children[j]->xmlName);
}

string groupName = "PANEL_EVENT_"+ofToString(i);
createEventGroup(groupName, xmlNames);
printf("creating %s\n", groupName.c_str());
}

bEventsSetup = true;
}

// Create a single common event which fired whenever any of the gui elements represented by xmlNames is changed
//---------------------------------------------
void ofxControlPanel::createEventGroup(string eventGroupName, vector <string> xmlNames){
customEvents.push_back( new guiCustomEvent() );
customEvents.back()->group = eventGroupName;
customEvents.back()->names = xmlNames;
}

//---------------------------------------------
void ofxControlPanel::enableEvents(){
if( !bEventsSetup ){
setupEvents();
}
eventsEnabled = true;
}

//---------------------------------------------
void ofxControlPanel::disableEvents(){
eventsEnabled = false;
}

// Get an event object for just a panel
//---------------------------------------------
ofEvent <guiCallbackData> & ofxControlPanel::getEventsForPanel(int panelNo){
if( panelNo < panels.size() ){
return getEventGroup("PANEL_EVENT_"+ofToString(panelNo));
}else{
return guiEvent;
}
}

//---------------------------------------------
ofEvent <guiCallbackData> & ofxControlPanel::getAllEvents(){
return guiEvent;
}


// Use the name you made for your custom group to get back the event object
//---------------------------------------------
ofEvent <guiCallbackData> & ofxControlPanel::getEventGroup(string eventGroupName){
for(int i = 0; i < customEvents.size(); i++){
if( eventGroupName == customEvents[i]->group ){
return customEvents[i]->guiEvent;
}
}

//if we don't find a match we return the global event
ofLog(OF_LOG_ERROR, "error eventGroup %s does not exist - returning the global event instead", eventGroupName.c_str());
return guiEvent;
}

//This is protected
//---------------------------------------------
void ofxControlPanel::eventsIn(guiCallbackData & data){
if( !eventsEnabled ) return;

//we notify the ofxControlPanel event object - aka the global ALL events callback
ofNotifyEvent(guiEvent, data, this);

//we then check custom event groups
for(int i = 0; i < customEvents.size(); i++){
for(int k = 0; k < customEvents[i]->names.size(); k++){
if( customEvents[i]->names[k] == data.groupName ){
ofNotifyEvent(customEvents[i]->guiEvent, data, this);
}
}
}
}

// ############################################################## //
// ##
// ## get and set values
Expand Down
Loading

0 comments on commit 4ee66d0

Please sign in to comment.