Browse Source

Change src code style using ofStyler

master
Krisjanis Rijnieks 10 years ago
parent
commit
95b366ada5
  1. 36
      src/Application/Application.cpp
  2. 12
      src/Application/Application.h
  3. 8
      src/Application/ApplicationBaseState.cpp
  4. 16
      src/Application/ApplicationBaseState.h
  5. 17
      src/Application/PresentationState.cpp
  6. 10
      src/Application/PresentationState.h
  7. 21
      src/Application/ProjectionMappingState.cpp
  8. 10
      src/Application/ProjectionMappingState.h
  9. 17
      src/Application/SourceSelectionState.cpp
  10. 10
      src/Application/SourceSelectionState.h
  11. 17
      src/Application/TextureMappingState.cpp
  12. 10
      src/Application/TextureMappingState.h
  13. 38
      src/Commands/AddSurfaceCmd.cpp
  14. 11
      src/Commands/AddSurfaceCmd.h
  15. 36
      src/Commands/BaseCmd.h
  16. 22
      src/Commands/CmdManager.cpp
  17. 14
      src/Commands/CmdManager.h
  18. 18
      src/Commands/MvAllTexCoordsCmd.cpp
  19. 13
      src/Commands/MvAllTexCoordsCmd.h
  20. 19
      src/Commands/MvSurfaceCmd.cpp
  21. 16
      src/Commands/MvSurfaceCmd.h
  22. 19
      src/Commands/MvSurfaceVertCmd.cpp
  23. 14
      src/Commands/MvSurfaceVertCmd.h
  24. 18
      src/Commands/MvTexCoordCmd.cpp
  25. 11
      src/Commands/MvTexCoordCmd.h
  26. 20
      src/Commands/RmSurfaceCmd.cpp
  27. 11
      src/Commands/RmSurfaceCmd.h
  28. 19
      src/Commands/SelSurfaceCmd.cpp
  29. 14
      src/Commands/SelSurfaceCmd.h
  30. 20
      src/Commands/SetApplicationStateCmd.cpp
  31. 16
      src/Commands/SetApplicationStateCmd.h
  32. 38
      src/Commands/SetSourceCmd.cpp
  33. 15
      src/Commands/SetSourceCmd.h
  34. 27
      src/MediaServer/DirectoryWatcher.cpp
  35. 76
      src/MediaServer/DirectoryWatcher.h
  36. 236
      src/MediaServer/MediaServer.cpp
  37. 69
      src/MediaServer/MediaServer.h
  38. 50
      src/Sources/BaseSource.cpp
  39. 30
      src/Sources/BaseSource.h
  40. 72
      src/Sources/FboSource.cpp
  41. 18
      src/Sources/FboSource.h
  42. 23
      src/Sources/ImageSource.cpp
  43. 20
      src/Sources/ImageSource.h
  44. 44
      src/Sources/SourceType.h
  45. 43
      src/Sources/VideoSource.cpp
  46. 23
      src/Sources/VideoSource.h
  47. 72
      src/Surfaces/BaseSurface.cpp
  48. 46
      src/Surfaces/BaseSurface.h
  49. 68
      src/Surfaces/QuadSurface.cpp
  50. 13
      src/Surfaces/QuadSurface.h
  51. 179
      src/Surfaces/SurfaceManager.cpp
  52. 34
      src/Surfaces/SurfaceManager.h
  53. 175
      src/Surfaces/SurfaceManagerGui.cpp
  54. 28
      src/Surfaces/SurfaceManagerGui.h
  55. 14
      src/Surfaces/SurfaceType.h
  56. 62
      src/Surfaces/TriangleSurface.cpp
  57. 12
      src/Surfaces/TriangleSurface.h
  58. 59
      src/UserInterface/BaseJoint.cpp
  59. 17
      src/UserInterface/BaseJoint.h
  60. 44
      src/UserInterface/CircleJoint.cpp
  61. 7
      src/UserInterface/CircleJoint.h
  62. 10
      src/UserInterface/EditorType.h
  63. 10
      src/UserInterface/GuiMode.h
  64. 217
      src/UserInterface/ProjectionEditor.cpp
  65. 34
      src/UserInterface/ProjectionEditor.h
  66. 122
      src/UserInterface/RadioList.cpp
  67. 26
      src/UserInterface/RadioList.h
  68. 233
      src/UserInterface/SourcesEditor.cpp
  69. 48
      src/UserInterface/SourcesEditor.h
  70. 134
      src/UserInterface/TextureEditor.cpp
  71. 24
      src/UserInterface/TextureEditor.h
  72. 36
      src/ofxPiMapper.cpp
  73. 20
      src/ofxPiMapper.h

36
src/Application/Application.cpp

@ -2,39 +2,39 @@
#include "PresentationState.h" #include "PresentationState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
Application::Application(ofxPiMapper * opm) { Application::Application(ofxPiMapper * opm){
_ofxPiMapper = opm; _ofxPiMapper = opm;
setState(PresentationState::instance()); setState(PresentationState::instance());
ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed); ofAddListener(ofEvents().keyPressed, this, &Application::onKeyPressed);
} }
Application::~Application() { Application::~Application(){
_ofxPiMapper = 0; _ofxPiMapper = 0;
setState(0); setState(0);
ofRemoveListener(ofEvents().keyPressed, this, &Application::onKeyPressed); ofRemoveListener(ofEvents().keyPressed, this, &Application::onKeyPressed);
} }
ApplicationBaseState * Application::getState() { ApplicationBaseState * Application::getState(){
return _state; return _state;
} }
ofxPiMapper * Application::getOfxPiMapper() { ofxPiMapper * Application::getOfxPiMapper(){
return _ofxPiMapper; return _ofxPiMapper;
} }
void Application::draw(){ void Application::draw(){
_state->draw(this); _state->draw(this);
} }
// Here we handle application state changes only // Here we handle application state changes only
void Application::onKeyPressed(ofKeyEventArgs & args) { void Application::onKeyPressed(ofKeyEventArgs & args){
// For now we set the state of the new system and also the old // For now we set the state of the new system and also the old
// before it is completely ported to the state system. // before it is completely ported to the state system.
switch (args.key) { switch(args.key){
case '1': case '1':
_ofxPiMapper->getCmdManager().exec( _ofxPiMapper->getCmdManager().exec(
new ofx::piMapper::SetApplicationStateCmd( new ofx::piMapper::SetApplicationStateCmd(
@ -85,11 +85,11 @@ namespace ofx {
_state->onKeyPressed(this, args); _state->onKeyPressed(this, args);
break; break;
} }
} }
void Application::setState(ApplicationBaseState * st){ void Application::setState(ApplicationBaseState * st){
_state = st; _state = st;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

12
src/Application/Application.h

@ -19,11 +19,12 @@
class ofxPiMapper; class ofxPiMapper;
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ApplicationBaseState; class ApplicationBaseState;
class Application {
class Application {
public: public:
Application(ofxPiMapper * opm); Application(ofxPiMapper * opm);
~Application(); ~Application();
@ -43,7 +44,8 @@ namespace ofx {
ApplicationBaseState * _state; ApplicationBaseState * _state;
ofxPiMapper * _ofxPiMapper; ofxPiMapper * _ofxPiMapper;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

8
src/Application/ApplicationBaseState.cpp

@ -2,11 +2,11 @@
#include "PresentationState.h" #include "PresentationState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
void ApplicationBaseState::setState(Application * app, ApplicationBaseState * st) { void ApplicationBaseState::setState(Application * app, ApplicationBaseState * st){
app->setState(st); app->setState(st);
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

16
src/Application/ApplicationBaseState.h

@ -4,18 +4,20 @@
#include "ofLog.h" #include "ofLog.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class Application; class Application;
class ApplicationBaseState {
class ApplicationBaseState {
public: public:
virtual void draw(Application * app){}; virtual void draw(Application * app){}
virtual void setState(Application * app, ApplicationBaseState * st); virtual void setState(Application * app, ApplicationBaseState * st);
// Event handler virtual methods // Event handler virtual methods
virtual void onKeyPressed(Application * app, ofKeyEventArgs & args){}; virtual void onKeyPressed(Application * app, ofKeyEventArgs & args){}
};
};
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

17
src/Application/PresentationState.cpp

@ -1,17 +1,18 @@
#include "PresentationState.h" #include "PresentationState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
PresentationState * PresentationState::_instance = 0; PresentationState * PresentationState::_instance = 0;
PresentationState * PresentationState::instance() { PresentationState * PresentationState::instance(){
if (_instance == 0) { if(_instance == 0){
_instance = new ofx::piMapper::PresentationState(); _instance = new ofx::piMapper::PresentationState();
} }
return _instance; return _instance;
}
void PresentationState::draw(Application * app) {}
}
} }
void PresentationState::draw(Application * app){}
} // namespace piMapper
} // namespace ofx

10
src/Application/PresentationState.h

@ -6,16 +6,18 @@
#include "ofGraphics.h" #include "ofGraphics.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class PresentationState : public ApplicationBaseState {
class PresentationState : public ApplicationBaseState {
public: public:
static PresentationState * instance(); static PresentationState * instance();
void draw(Application * app); void draw(Application * app);
private: private:
static PresentationState * _instance; static PresentationState * _instance;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

21
src/Application/ProjectionMappingState.cpp

@ -1,21 +1,21 @@
#include "ProjectionMappingState.h" #include "ProjectionMappingState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
ProjectionMappingState * ProjectionMappingState::_instance = 0; ProjectionMappingState * ProjectionMappingState::_instance = 0;
ProjectionMappingState * ProjectionMappingState::instance() { ProjectionMappingState * ProjectionMappingState::instance(){
if (_instance == 0) { if(_instance == 0){
_instance = new ofx::piMapper::ProjectionMappingState(); _instance = new ofx::piMapper::ProjectionMappingState();
} }
return _instance; return _instance;
} }
void ProjectionMappingState::draw(Application * app) {} void ProjectionMappingState::draw(Application * app){}
void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args) { void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){
switch (args.key) { switch(args.key){
case 't': case 't':
app->getOfxPiMapper()->getCmdManager().exec( app->getOfxPiMapper()->getCmdManager().exec(
@ -41,6 +41,7 @@ namespace ofx {
default: default:
break; break;
} }
}
}
} }
} // namespace piMapper
} // namespace ofx

10
src/Application/ProjectionMappingState.h

@ -8,9 +8,10 @@
#include "SurfaceType.h" #include "SurfaceType.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ProjectionMappingState : public ApplicationBaseState {
class ProjectionMappingState : public ApplicationBaseState {
public: public:
static ProjectionMappingState * instance(); static ProjectionMappingState * instance();
void draw(Application * app); void draw(Application * app);
@ -18,7 +19,8 @@ namespace ofx {
private: private:
static ProjectionMappingState * _instance; static ProjectionMappingState * _instance;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

17
src/Application/SourceSelectionState.cpp

@ -1,17 +1,18 @@
#include "SourceSelectionState.h" #include "SourceSelectionState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SourceSelectionState * SourceSelectionState::_instance = 0; SourceSelectionState * SourceSelectionState::_instance = 0;
SourceSelectionState * SourceSelectionState::instance() { SourceSelectionState * SourceSelectionState::instance(){
if (_instance == 0) { if(_instance == 0){
_instance = new ofx::piMapper::SourceSelectionState(); _instance = new ofx::piMapper::SourceSelectionState();
} }
return _instance; return _instance;
}
void SourceSelectionState::draw(Application * app) {}
}
} }
void SourceSelectionState::draw(Application * app){}
} // namespace piMapper
} // namespace ofx

10
src/Application/SourceSelectionState.h

@ -6,16 +6,18 @@
#include "ofGraphics.h" #include "ofGraphics.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourceSelectionState : public ApplicationBaseState {
class SourceSelectionState : public ApplicationBaseState {
public: public:
static SourceSelectionState * instance(); static SourceSelectionState * instance();
void draw(Application * app); void draw(Application * app);
private: private:
static SourceSelectionState * _instance; static SourceSelectionState * _instance;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

17
src/Application/TextureMappingState.cpp

@ -1,17 +1,18 @@
#include "TextureMappingState.h" #include "TextureMappingState.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TextureMappingState * TextureMappingState::_instance = 0; TextureMappingState * TextureMappingState::_instance = 0;
TextureMappingState * TextureMappingState::instance() { TextureMappingState * TextureMappingState::instance(){
if (_instance == 0) { if(_instance == 0){
_instance = new ofx::piMapper::TextureMappingState(); _instance = new ofx::piMapper::TextureMappingState();
} }
return _instance; return _instance;
}
void TextureMappingState::draw(Application * app) {}
}
} }
void TextureMappingState::draw(Application * app){}
} // namespace piMapper
} // namespace ofx

10
src/Application/TextureMappingState.h

@ -6,16 +6,18 @@
#include "ofGraphics.h" #include "ofGraphics.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TextureMappingState : public ApplicationBaseState {
class TextureMappingState : public ApplicationBaseState {
public: public:
static TextureMappingState * instance(); static TextureMappingState * instance();
void draw(Application * app); void draw(Application * app);
private: private:
static TextureMappingState * _instance; static TextureMappingState * _instance;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

38
src/Commands/AddSurfaceCmd.cpp

@ -1,61 +1,61 @@
#include "AddSurfaceCmd.h" #include "AddSurfaceCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
AddSurfaceCmd::AddSurfaceCmd(ofxPiMapper * app, int surfaceType){ AddSurfaceCmd::AddSurfaceCmd(ofxPiMapper * app, int surfaceType){
_app = app; _app = app;
_surfaceType = surfaceType; _surfaceType = surfaceType;
} }
void AddSurfaceCmd::exec(){ void AddSurfaceCmd::exec(){
if (_surfaceType == SurfaceType::TRIANGLE_SURFACE) { if(_surfaceType == SurfaceType::TRIANGLE_SURFACE){
addTriangleSurface(); addTriangleSurface();
} else if (_surfaceType == SurfaceType::QUAD_SURFACE) { }else if(_surfaceType == SurfaceType::QUAD_SURFACE){
addQuadSurface(); addQuadSurface();
} }
} }
void AddSurfaceCmd::undo(){ void AddSurfaceCmd::undo(){
ofLogNotice("AddSurfaceCmd", "undo"); ofLogNotice("AddSurfaceCmd", "undo");
_app->getSurfaceManager().removeSurface(); _app->getSurfaceManager().removeSurface();
} }
void AddSurfaceCmd::addTriangleSurface() { void AddSurfaceCmd::addTriangleSurface(){
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices; vector <ofVec2f> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f)); texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f)); texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f)); texCoords.push_back(ofVec2f(0.0f, 1.0f));
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); _app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords);
} }
void AddSurfaceCmd::addQuadSurface() { void AddSurfaceCmd::addQuadSurface(){
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices; vector <ofVec2f> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin)); vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); _app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords);
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

11
src/Commands/AddSurfaceCmd.h

@ -7,10 +7,10 @@
class ofxPiMapper; class ofxPiMapper;
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class AddSurfaceCmd : public BaseUndoCmd{ class AddSurfaceCmd : public BaseUndoCmd {
public: public:
AddSurfaceCmd(ofxPiMapper * app, int surfaceType); AddSurfaceCmd(ofxPiMapper * app, int surfaceType);
@ -24,8 +24,9 @@ namespace ofx{
// TODO: Should use some kind of factory class here // TODO: Should use some kind of factory class here
void addTriangleSurface(); void addTriangleSurface();
void addQuadSurface(); void addQuadSurface();
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

36
src/Commands/BaseCmd.h

@ -9,33 +9,41 @@
#pragma once #pragma once
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
// Base class for all commands
class BaseCmd {
// Base class for all commands
class BaseCmd{
public: public:
virtual ~BaseCmd(){}; virtual ~BaseCmd(){}
virtual void exec() = 0; virtual void exec() = 0;
// By default a command is not undo // By default a command is not undo
virtual bool isUndoable(){return false;} virtual bool isUndoable(){
return false;
}
protected: protected:
// In order to avoid using this class directly, // In order to avoid using this class directly,
// we make the constructor protected. // we make the constructor protected.
BaseCmd(){}; BaseCmd(){}
};
};
// Base class for all undoable commands
class BaseUndoCmd : public BaseCmd {
// Base class for all undoable commands
class BaseUndoCmd : public BaseCmd{
public: public:
virtual void undo() = 0; virtual void undo() = 0;
virtual bool isUndoable(){return true;} virtual bool isUndoable(){
return true;
}
protected: protected:
BaseUndoCmd(){}; BaseUndoCmd(){}
};
};
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

22
src/Commands/CmdManager.cpp

@ -1,28 +1,28 @@
#include "CmdManager.h" #include "CmdManager.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
void CmdManager::exec(BaseCmd * cmd){ void CmdManager::exec(BaseCmd * cmd){
cmd->exec(); cmd->exec();
if (cmd->isUndoable()){ if(cmd->isUndoable()){
cmdStack.push_back(static_cast<BaseUndoCmd *>(cmd)); cmdStack.push_back(static_cast <BaseUndoCmd *>(cmd));
}
} }
}
void CmdManager::undo(){ void CmdManager::undo(){
ofLogNotice("CmdManager", "undo"); ofLogNotice("CmdManager", "undo");
if (cmdStack.size() > 0){ if(cmdStack.size() > 0){
BaseUndoCmd * cmd = cmdStack.back(); BaseUndoCmd * cmd = cmdStack.back();
cmd->undo(); cmd->undo();
// Delete last command now, change this when implementing redo. // Delete last command now, change this when implementing redo.
delete cmdStack.back(); delete cmdStack.back();
cmdStack.pop_back(); cmdStack.pop_back();
} else { }else{
ofLogNotice("CmdManager", "Nothing to undo"); ofLogNotice("CmdManager", "Nothing to undo");
} }
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

14
src/Commands/CmdManager.h

@ -4,17 +4,19 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "ofLog.h" #include "ofLog.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class CmdManager {
class CmdManager{
public: public:
void exec(BaseCmd * cmd); void exec(BaseCmd * cmd);
void undo(); void undo();
private: private:
std::vector<BaseUndoCmd *> cmdStack; std::vector <BaseUndoCmd *> cmdStack;
};
};
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

18
src/Commands/MvAllTexCoordsCmd.cpp

@ -1,27 +1,27 @@
#include "MvAllTexCoordsCmd.h" #include "MvAllTexCoordsCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
MvAllTexCoordsCmd::MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor){ MvAllTexCoordsCmd::MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor){
_surface = surface; _surface = surface;
_texEditor = texEditor; _texEditor = texEditor;
} }
void MvAllTexCoordsCmd::exec(){ void MvAllTexCoordsCmd::exec(){
ofLogNotice("MvAllTexCoordsCmd", "exec"); ofLogNotice("MvAllTexCoordsCmd", "exec");
_texCoords = _surface->getTexCoords(); _texCoords = _surface->getTexCoords();
} }
void MvAllTexCoordsCmd::undo(){ void MvAllTexCoordsCmd::undo(){
ofLogNotice("MvAllTexCoordsCmd", "undo"); ofLogNotice("MvAllTexCoordsCmd", "undo");
ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0]; ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0];
dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x; dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x;
dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y; dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y;
_texEditor->moveTexCoords(dist); _texEditor->moveTexCoords(dist);
_surface = 0; _surface = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

13
src/Commands/MvAllTexCoordsCmd.h

@ -8,10 +8,10 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "TextureEditor.h" #include "TextureEditor.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class MvAllTexCoordsCmd : public BaseUndoCmd{ class MvAllTexCoordsCmd : public BaseUndoCmd {
public: public:
MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor); MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor);
@ -19,11 +19,12 @@ namespace ofx{
void undo(); void undo();
private: private:
vector<ofVec2f> _texCoords; vector <ofVec2f> _texCoords;
BaseSurface * _surface; BaseSurface * _surface;
TextureEditor * _texEditor; TextureEditor * _texEditor;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

19
src/Commands/MvSurfaceCmd.cpp

@ -1,30 +1,29 @@
#include "MvSurfaceCmd.h" #include "MvSurfaceCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
MvSurfaceCmd::MvSurfaceCmd( MvSurfaceCmd::MvSurfaceCmd(BaseSurface * surface,
BaseSurface * surface,
ProjectionEditor * projectionEditor){ ProjectionEditor * projectionEditor){
_surface = surface; _surface = surface;
_projectionEditor = projectionEditor; _projectionEditor = projectionEditor;
} }
void MvSurfaceCmd::exec(){ void MvSurfaceCmd::exec(){
ofLogNotice("MvSurfaceCmd", "exec"); ofLogNotice("MvSurfaceCmd", "exec");
_previousVertices = _surface->getVertices(); _previousVertices = _surface->getVertices();
_surface->setMoved(false); _surface->setMoved(false);
} }
void MvSurfaceCmd::undo(){ void MvSurfaceCmd::undo(){
ofLogNotice("MvSurfaceCmd", "undo"); ofLogNotice("MvSurfaceCmd", "undo");
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]); _surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]);
_projectionEditor->updateJoints(); _projectionEditor->updateJoints();
_previousVertices.clear(); _previousVertices.clear();
_surface = 0; _surface = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

16
src/Commands/MvSurfaceCmd.h

@ -8,14 +8,13 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "ProjectionEditor.h" #include "ProjectionEditor.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class MvSurfaceCmd : public BaseUndoCmd{ class MvSurfaceCmd : public BaseUndoCmd {
public: public:
MvSurfaceCmd( MvSurfaceCmd(BaseSurface * surface,
BaseSurface * surface,
ProjectionEditor * projectionEditor); ProjectionEditor * projectionEditor);
void exec(); void exec();
void undo(); void undo();
@ -23,9 +22,10 @@ namespace ofx{
private: private:
BaseSurface * _surface; BaseSurface * _surface;
ProjectionEditor * _projectionEditor; ProjectionEditor * _projectionEditor;
vector<ofVec3f> _previousVertices; vector <ofVec3f> _previousVertices;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

19
src/Commands/MvSurfaceVertCmd.cpp

@ -1,31 +1,30 @@
#include "MvSurfaceVertCmd.h" #include "MvSurfaceVertCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
MvSurfaceVertCmd::MvSurfaceVertCmd( MvSurfaceVertCmd::MvSurfaceVertCmd(int vertIndex,
int vertIndex,
BaseSurface * surface, BaseSurface * surface,
ProjectionEditor * projectionEditor){ ProjectionEditor * projectionEditor){
_vertIndex = vertIndex; _vertIndex = vertIndex;
_surface = surface; _surface = surface;
_projectionEditor = projectionEditor; _projectionEditor = projectionEditor;
} }
void MvSurfaceVertCmd::exec(){ void MvSurfaceVertCmd::exec(){
ofLogNotice("MvSurfaceVertCommand", "exec"); ofLogNotice("MvSurfaceVertCommand", "exec");
_prevVertPos = _surface->getVertices()[_vertIndex]; _prevVertPos = _surface->getVertices()[_vertIndex];
} }
void MvSurfaceVertCmd::undo(){ void MvSurfaceVertCmd::undo(){
ofLogNotice("MvSurfaceVertCommand", "undo"); ofLogNotice("MvSurfaceVertCommand", "undo");
_surface->setVertex(_vertIndex, _prevVertPos); _surface->setVertex(_vertIndex, _prevVertPos);
_projectionEditor->updateJoints(); _projectionEditor->updateJoints();
_projectionEditor = 0; _projectionEditor = 0;
_surface = 0; _surface = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

14
src/Commands/MvSurfaceVertCmd.h

@ -9,14 +9,13 @@
#include "ProjectionEditor.h" #include "ProjectionEditor.h"
#include "BaseJoint.h" #include "BaseJoint.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class MvSurfaceVertCmd : public BaseUndoCmd{ class MvSurfaceVertCmd : public BaseUndoCmd {
public: public:
MvSurfaceVertCmd( MvSurfaceVertCmd(int vertIndex,
int vertIndex,
BaseSurface * surface, BaseSurface * surface,
ProjectionEditor * projectionEditor); ProjectionEditor * projectionEditor);
void exec(); void exec();
@ -27,8 +26,9 @@ namespace ofx{
ofVec2f _prevVertPos; ofVec2f _prevVertPos;
BaseSurface * _surface; BaseSurface * _surface;
ProjectionEditor * _projectionEditor; ProjectionEditor * _projectionEditor;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

18
src/Commands/MvTexCoordCmd.cpp

@ -1,26 +1,26 @@
#include "MvTexCoordCmd.h" #include "MvTexCoordCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
MvTexCoordCmd::MvTexCoordCmd(int jointIndex, TextureEditor * texEditor){ MvTexCoordCmd::MvTexCoordCmd(int jointIndex, TextureEditor * texEditor){
_jointIndex = jointIndex; _jointIndex = jointIndex;
_texEditor = texEditor; _texEditor = texEditor;
} }
void MvTexCoordCmd::exec(){ void MvTexCoordCmd::exec(){
ofLogNotice("MvTexCoordCmd", "exec"); ofLogNotice("MvTexCoordCmd", "exec");
_jointPosition = _texEditor->getJoints()[_jointIndex]->position; _jointPosition = _texEditor->getJoints()[_jointIndex]->position;
} }
void MvTexCoordCmd::undo(){ void MvTexCoordCmd::undo(){
ofLogNotice("MvTexCoordCmd", "undo"); ofLogNotice("MvTexCoordCmd", "undo");
_texEditor->unselectAllJoints(); _texEditor->unselectAllJoints();
_texEditor->getJoints()[_jointIndex]->select(); _texEditor->getJoints()[_jointIndex]->select();
_texEditor->getJoints()[_jointIndex]->position = _jointPosition; _texEditor->getJoints()[_jointIndex]->position = _jointPosition;
_texEditor = 0; _texEditor = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

11
src/Commands/MvTexCoordCmd.h

@ -8,10 +8,10 @@
#include "CircleJoint.h" #include "CircleJoint.h"
#include "TextureEditor.h" #include "TextureEditor.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class MvTexCoordCmd : public BaseUndoCmd{ class MvTexCoordCmd : public BaseUndoCmd {
public: public:
MvTexCoordCmd(int jointIndex, TextureEditor * texEditor); MvTexCoordCmd(int jointIndex, TextureEditor * texEditor);
@ -22,8 +22,9 @@ namespace ofx{
ofVec2f _jointPosition; ofVec2f _jointPosition;
int _jointIndex; int _jointIndex;
TextureEditor * _texEditor; TextureEditor * _texEditor;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

20
src/Commands/RmSurfaceCmd.cpp

@ -1,30 +1,30 @@
#include "RmSurfaceCmd.h" #include "RmSurfaceCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
RmSurfaceCmd::RmSurfaceCmd(ofxPiMapper * app){ RmSurfaceCmd::RmSurfaceCmd(ofxPiMapper * app){
_app = app; _app = app;
_surface = 0; _surface = 0;
} }
void RmSurfaceCmd::exec(){ void RmSurfaceCmd::exec(){
// Store the surface, this implies that the surfaceManager's // Store the surface, this implies that the surfaceManager's
// removeSelectedSurface does not destroy the surface. // removeSelectedSurface does not destroy the surface.
_surface = _app->surfaceManager.getSelectedSurface(); _surface = _app->surfaceManager.getSelectedSurface();
_app->surfaceManager.removeSelectedSurface(); _app->surfaceManager.removeSelectedSurface();
} }
void RmSurfaceCmd::undo(){ void RmSurfaceCmd::undo(){
ofLogNotice("RmSurfaceCmd", "undo"); ofLogNotice("RmSurfaceCmd", "undo");
if (_surface == 0) { if(_surface == 0){
ofLogError("RmSurfaceCmd", "No surface stored"); ofLogError("RmSurfaceCmd", "No surface stored");
} }
_app->surfaceManager.addSurface(_surface); _app->surfaceManager.addSurface(_surface);
_app->surfaceManager.selectSurface(_surface); _app->surfaceManager.selectSurface(_surface);
_surface = 0; _surface = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

11
src/Commands/RmSurfaceCmd.h

@ -10,10 +10,10 @@
class ofxPiMapper; class ofxPiMapper;
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class RmSurfaceCmd : public BaseUndoCmd{ class RmSurfaceCmd : public BaseUndoCmd {
public: public:
RmSurfaceCmd(ofxPiMapper * app); RmSurfaceCmd(ofxPiMapper * app);
@ -23,8 +23,9 @@ namespace ofx{
private: private:
ofxPiMapper * _app; ofxPiMapper * _app;
BaseSurface * _surface; BaseSurface * _surface;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

19
src/Commands/SelSurfaceCmd.cpp

@ -1,34 +1,33 @@
#include "SelSurfaceCmd.h" #include "SelSurfaceCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
SelSurfaceCmd::SelSurfaceCmd( SelSurfaceCmd::SelSurfaceCmd(SurfaceManager * surfaceManager,
SurfaceManager * surfaceManager,
BaseSurface * surfaceToSelect, BaseSurface * surfaceToSelect,
ProjectionEditor * projectionEditor){ ProjectionEditor * projectionEditor){
_surfaceManager = surfaceManager; _surfaceManager = surfaceManager;
_surfaceToSelect = surfaceToSelect; _surfaceToSelect = surfaceToSelect;
_projectionEditor = projectionEditor; _projectionEditor = projectionEditor;
} }
void SelSurfaceCmd::exec(){ void SelSurfaceCmd::exec(){
_prevSelectedSurface = _surfaceManager->getSelectedSurface(); _prevSelectedSurface = _surfaceManager->getSelectedSurface();
_projectionEditor->clearJoints(); _projectionEditor->clearJoints();
_surfaceManager->selectSurface(_surfaceToSelect); _surfaceManager->selectSurface(_surfaceToSelect);
_projectionEditor->createJoints(); _projectionEditor->createJoints();
} }
void SelSurfaceCmd::undo(){ void SelSurfaceCmd::undo(){
ofLogNotice("SelSurfaceCmd", "undo"); ofLogNotice("SelSurfaceCmd", "undo");
_projectionEditor->clearJoints(); _projectionEditor->clearJoints();
_surfaceManager->selectSurface(_prevSelectedSurface); _surfaceManager->selectSurface(_prevSelectedSurface);
_projectionEditor->createJoints(); _projectionEditor->createJoints();
_surfaceToSelect = 0; _surfaceToSelect = 0;
_prevSelectedSurface = 0; _prevSelectedSurface = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

14
src/Commands/SelSurfaceCmd.h

@ -9,14 +9,13 @@
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "ProjectionEditor.h" #include "ProjectionEditor.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class SelSurfaceCmd : public BaseUndoCmd{ class SelSurfaceCmd : public BaseUndoCmd {
public: public:
SelSurfaceCmd( SelSurfaceCmd(SurfaceManager * surfaceManager,
SurfaceManager * surfaceManager,
BaseSurface * surfaceToSelect, BaseSurface * surfaceToSelect,
ProjectionEditor * projectionEditor); ProjectionEditor * projectionEditor);
void exec(); void exec();
@ -27,8 +26,9 @@ namespace ofx{
SurfaceManager * _surfaceManager; SurfaceManager * _surfaceManager;
BaseSurface * _prevSelectedSurface; BaseSurface * _prevSelectedSurface;
ProjectionEditor * _projectionEditor; ProjectionEditor * _projectionEditor;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

20
src/Commands/SetApplicationStateCmd.cpp

@ -1,14 +1,12 @@
#include "SetApplicationStateCmd.h" #include "SetApplicationStateCmd.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SetApplicationStateCmd::SetApplicationStateCmd( SetApplicationStateCmd::SetApplicationStateCmd(Application * app,
Application * app,
ApplicationBaseState * st, ApplicationBaseState * st,
SurfaceManagerGui * gui, SurfaceManagerGui * gui,
int mode) { int mode){
_application = app; _application = app;
_prevApplicationState = 0; _prevApplicationState = 0;
@ -18,25 +16,25 @@ namespace ofx {
_gui = gui; _gui = gui;
_prevGuiMode = -1; _prevGuiMode = -1;
_mode = mode; _mode = mode;
} }
void SetApplicationStateCmd::exec() { void SetApplicationStateCmd::exec(){
_prevApplicationState = _application->getState(); _prevApplicationState = _application->getState();
_application->setState(_applicationState); _application->setState(_applicationState);
// TODO: To be removed. // TODO: To be removed.
_prevGuiMode = _gui->getMode(); _prevGuiMode = _gui->getMode();
_gui->setMode(_mode); _gui->setMode(_mode);
} }
void SetApplicationStateCmd::undo() { void SetApplicationStateCmd::undo(){
ofLogNotice("SetApplicationStateCmd", "undo"); ofLogNotice("SetApplicationStateCmd", "undo");
_application->setState(_prevApplicationState); _application->setState(_prevApplicationState);
// TODO: To be removed. // TODO: To be removed.
_gui->setMode(_prevGuiMode); _gui->setMode(_prevGuiMode);
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

16
src/Commands/SetApplicationStateCmd.h

@ -4,16 +4,15 @@
#include "Application.h" #include "Application.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class Application; class Application;
class ApplicationBaseState; class ApplicationBaseState;
class SetApplicationStateCmd : public BaseUndoCmd { class SetApplicationStateCmd : public BaseUndoCmd {
public: public:
SetApplicationStateCmd( SetApplicationStateCmd(Application * app,
Application * app,
ApplicationBaseState * st, ApplicationBaseState * st,
SurfaceManagerGui * gui, SurfaceManagerGui * gui,
int mode); int mode);
@ -30,8 +29,9 @@ namespace ofx {
SurfaceManagerGui * _gui; SurfaceManagerGui * _gui;
int _prevGuiMode; int _prevGuiMode;
int _mode; int _mode;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

38
src/Commands/SetSourceCmd.cpp

@ -1,9 +1,9 @@
#include "SetSourceCmd.h" #include "SetSourceCmd.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
SetSourceCmd::SetSourceCmd(int sourceType, SetSourceCmd::SetSourceCmd(int sourceType,
string sourceId, string sourceId,
BaseSurface * surface, BaseSurface * surface,
SourcesEditor * sourcesEditor){ SourcesEditor * sourcesEditor){
@ -12,46 +12,46 @@ namespace ofx{
_sourceId = sourceId; _sourceId = sourceId;
_surface = surface; _surface = surface;
_sourcesEditor = sourcesEditor; _sourcesEditor = sourcesEditor;
} }
void SetSourceCmd::exec(){ void SetSourceCmd::exec(){
ofLogNotice("SetSourceCmd", "exec"); ofLogNotice("SetSourceCmd", "exec");
_oldSourceType = _surface->getSource()->getType(); _oldSourceType = _surface->getSource()->getType();
if (_surface->getSource()->isLoadable()) { if(_surface->getSource()->isLoadable()){
_oldSourceId = _surface->getSource()->getPath(); _oldSourceId = _surface->getSource()->getPath();
} else { }else{
_oldSourceId = _surface->getSource()->getName(); _oldSourceId = _surface->getSource()->getName();
} }
if (_sourceType == SourceType::SOURCE_TYPE_IMAGE) { if(_sourceType == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_sourceId); _sourcesEditor->setImageSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_VIDEO) { }else if(_sourceType == SourceType::SOURCE_TYPE_VIDEO){
_sourcesEditor->setVideoSource(_sourceId); _sourcesEditor->setVideoSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_FBO) { }else if(_sourceType == SourceType::SOURCE_TYPE_FBO){
_sourcesEditor->setFboSource(_sourceId); _sourcesEditor->setFboSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_NONE) { }else if(_sourceType == SourceType::SOURCE_TYPE_NONE){
_sourcesEditor->clearSource(); _sourcesEditor->clearSource();
} }
} }
void SetSourceCmd::undo(){ void SetSourceCmd::undo(){
ofLogNotice("SetSourceCmd", "undo"); ofLogNotice("SetSourceCmd", "undo");
if (_oldSourceType == SourceType::SOURCE_TYPE_IMAGE) { if(_oldSourceType == SourceType::SOURCE_TYPE_IMAGE){
_sourcesEditor->setImageSource(_oldSourceId); _sourcesEditor->setImageSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_VIDEO) { }else if(_oldSourceType == SourceType::SOURCE_TYPE_VIDEO){
_sourcesEditor->setVideoSource(_oldSourceId); _sourcesEditor->setVideoSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_FBO) { }else if(_oldSourceType == SourceType::SOURCE_TYPE_FBO){
_sourcesEditor->setFboSource(_oldSourceId); _sourcesEditor->setFboSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_NONE) { }else if(_oldSourceType == SourceType::SOURCE_TYPE_NONE){
_sourcesEditor->clearSource(); _sourcesEditor->clearSource();
} }
_surface = 0; _surface = 0;
_sourcesEditor = 0; _sourcesEditor = 0;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

15
src/Commands/SetSourceCmd.h

@ -8,14 +8,12 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SourcesEditor.h" #include "SourcesEditor.h"
namespace ofx {
namespace piMapper {
class SourcesEditor;
namespace ofx{ class SetSourceCmd : public BaseUndoCmd {
namespace piMapper{
class SourcesEditor;
class SetSourceCmd : public BaseUndoCmd{
public: public:
SetSourceCmd(int sourceType, SetSourceCmd(int sourceType,
@ -33,8 +31,9 @@ namespace ofx{
int _oldSourceType; int _oldSourceType;
string _oldSourceId; string _oldSourceId;
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

27
src/MediaServer/DirectoryWatcher.cpp

@ -9,15 +9,16 @@
#include "DirectoryWatcher.h" #include "DirectoryWatcher.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
DirectoryWatcher::DirectoryWatcher(std::string path, int watcherMediaType) {
DirectoryWatcher::DirectoryWatcher(std::string path, int watcherMediaType){
mediaType = watcherMediaType; mediaType = watcherMediaType;
// Decide what filter we need depending on media type // Decide what filter we need depending on media type
if (mediaType == SourceType::SOURCE_TYPE_VIDEO) { if(mediaType == SourceType::SOURCE_TYPE_VIDEO){
filter = new VideoPathFilter(); filter = new VideoPathFilter();
} else if (mediaType == SourceType::SOURCE_TYPE_IMAGE) { }else if(mediaType == SourceType::SOURCE_TYPE_IMAGE){
filter = new ImagePathFilter(); filter = new ImagePathFilter();
} else { }else{
ofLogFatalError("DirectoryWatcher::DirectoryWatcher", "Unkonwn media type"); ofLogFatalError("DirectoryWatcher::DirectoryWatcher", "Unkonwn media type");
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
@ -27,20 +28,20 @@ namespace ofx {
dirWatcher.addPath(path); dirWatcher.addPath(path);
// Initial directory listing. Fill the file paths vector. // Initial directory listing. Fill the file paths vector.
IO::DirectoryUtils::list(path, filePaths, true, filter); IO::DirectoryUtils::list(path, filePaths, true, filter);
} }
DirectoryWatcher::~DirectoryWatcher() { DirectoryWatcher::~DirectoryWatcher(){
delete filter; delete filter;
filter = NULL; filter = NULL;
} }
std::vector<std::string>& DirectoryWatcher::getFilePaths() { std::vector <std::string> & DirectoryWatcher::getFilePaths(){
return filePaths; return filePaths;
} }
int DirectoryWatcher::getMediaType() { int DirectoryWatcher::getMediaType(){
return mediaType; return mediaType;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

76
src/MediaServer/DirectoryWatcher.h

@ -15,22 +15,22 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class BasePathFilter : public ofx::IO::AbstractPathFilter { class BasePathFilter : public ofx::IO::AbstractPathFilter {
public: public:
BasePathFilter() {}; BasePathFilter(){}
virtual ~BasePathFilter() {}; virtual ~BasePathFilter(){}
virtual bool accept(const Poco::Path& path) const {}; virtual bool accept(const Poco::Path & path) const {}
}; };
class VideoPathFilter : public BasePathFilter { class VideoPathFilter : public BasePathFilter {
public: public:
VideoPathFilter() {}; VideoPathFilter(){}
virtual ~VideoPathFilter() {}; virtual ~VideoPathFilter(){}
bool accept(const Poco::Path& path) const { bool accept(const Poco::Path & path) const {
return !Poco::File(path).isHidden() && return !Poco::File(path).isHidden() &&
(ofIsStringInString(path.toString(), ".mp4") || (ofIsStringInString(path.toString(), ".mp4") ||
ofIsStringInString(path.toString(), ".h264")|| ofIsStringInString(path.toString(), ".h264") ||
ofIsStringInString(path.toString(), ".mov") || ofIsStringInString(path.toString(), ".mov") ||
ofIsStringInString(path.toString(), ".avi") || ofIsStringInString(path.toString(), ".avi") ||
ofIsStringInString(path.toString(), ".mpeg")); ofIsStringInString(path.toString(), ".mpeg"));
@ -39,10 +39,10 @@ class VideoPathFilter : public BasePathFilter {
class ImagePathFilter : public BasePathFilter { class ImagePathFilter : public BasePathFilter {
public: public:
ImagePathFilter() {}; ImagePathFilter(){}
virtual ~ImagePathFilter() {}; virtual ~ImagePathFilter(){}
bool accept(const Poco::Path& path) const { bool accept(const Poco::Path & path) const {
return !Poco::File(path).isHidden() && return !Poco::File(path).isHidden() &&
(ofIsStringInString(path.toString(), ".png") || (ofIsStringInString(path.toString(), ".png") ||
ofIsStringInString(path.toString(), ".jpg") || ofIsStringInString(path.toString(), ".jpg") ||
@ -56,27 +56,25 @@ class DirectoryWatcher {
~DirectoryWatcher(); ~DirectoryWatcher();
// TODO make useful stuff with onDirectoryWatcher* // TODO make useful stuff with onDirectoryWatcher*
void onDirectoryWatcherItemAdded( void onDirectoryWatcherItemAdded(const ofx::IO::DirectoryWatcherManager::DirectoryEvent & evt){
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path(); string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path); Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) { if(!filter->accept(pocoPath)){
return; return;
} }
filePaths.push_back(path); filePaths.push_back(path);
ofNotifyEvent(onItemAdded, path, this); ofNotifyEvent(onItemAdded, path, this);
} }
void onDirectoryWatcherItemRemoved( void onDirectoryWatcherItemRemoved(const ofx::IO::DirectoryWatcherManager::DirectoryEvent & evt){
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path(); string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path); Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) { if(!filter->accept(pocoPath)){
return; return;
} }
// Remove path from vector // Remove path from vector
for (int i = 0; i < filePaths.size(); i++) { for(int i = 0; i < filePaths.size(); i++){
if (path == filePaths[i]) { if(path == filePaths[i]){
filePaths.erase(filePaths.begin() + i); filePaths.erase(filePaths.begin() + i);
break; break;
} }
@ -84,21 +82,19 @@ class DirectoryWatcher {
ofNotifyEvent(onItemRemoved, path, this); ofNotifyEvent(onItemRemoved, path, this);
} }
void onDirectoryWatcherItemModified( void onDirectoryWatcherItemModified(const ofx::IO::DirectoryWatcherManager::DirectoryEvent & evt){
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path(); string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path); Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) { if(!filter->accept(pocoPath)){
return; return;
} }
ofNotifyEvent(onItemModified, path, this); ofNotifyEvent(onItemModified, path, this);
} }
void onDirectoryWatcherItemMovedFrom( void onDirectoryWatcherItemMovedFrom(const ofx::IO::DirectoryWatcherManager::DirectoryEvent & evt){
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path(); string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path); Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) { if(!filter->accept(pocoPath)){
return; return;
} }
ofLogNotice("ofApp::onDirectoryWatcherItemMovedFrom") ofLogNotice("ofApp::onDirectoryWatcherItemMovedFrom")
@ -106,11 +102,10 @@ class DirectoryWatcher {
ofNotifyEvent(onItemMovedFrom, path, this); ofNotifyEvent(onItemMovedFrom, path, this);
} }
void onDirectoryWatcherItemMovedTo( void onDirectoryWatcherItemMovedTo(const ofx::IO::DirectoryWatcherManager::DirectoryEvent & evt){
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path(); string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path); Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) { if(!filter->accept(pocoPath)){
return; return;
} }
ofLogNotice("ofApp::onDirectoryWatcherItemMovedTo") ofLogNotice("ofApp::onDirectoryWatcherItemMovedTo")
@ -118,27 +113,28 @@ class DirectoryWatcher {
ofNotifyEvent(onItemMovedTo, path, this); ofNotifyEvent(onItemMovedTo, path, this);
} }
void onDirectoryWatcherError(const Poco::Exception& exc) { void onDirectoryWatcherError(const Poco::Exception & exc){
ofLogError("ofApp::onDirectoryWatcherError") ofLogError("ofApp::onDirectoryWatcherError")
<< "Error: " << exc.displayText(); << "Error: " << exc.displayText();
} }
// Getters // Getters
std::vector<std::string>& getFilePaths(); std::vector <std::string> & getFilePaths();
int getMediaType(); int getMediaType();
// Custom events // Custom events
ofEvent<string> onItemAdded; ofEvent <string> onItemAdded;
ofEvent<string> onItemRemoved; ofEvent <string> onItemRemoved;
ofEvent<string> onItemModified; ofEvent <string> onItemModified;
ofEvent<string> onItemMovedFrom; ofEvent <string> onItemMovedFrom;
ofEvent<string> onItemMovedTo; ofEvent <string> onItemMovedTo;
private: private:
ofx::IO::DirectoryWatcherManager dirWatcher; ofx::IO::DirectoryWatcherManager dirWatcher;
BasePathFilter* filter; BasePathFilter * filter;
std::vector<std::string> filePaths; std::vector <std::string> filePaths;
int mediaType; int mediaType;
}; };
}
} } // namespace piMapper
} // namespace ofx

236
src/MediaServer/MediaServer.cpp

@ -11,87 +11,93 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
MediaServer::MediaServer(): MediaServer::MediaServer() :
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), SourceType::SOURCE_TYPE_VIDEO), videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), SourceType::SOURCE_TYPE_VIDEO),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), SourceType::SOURCE_TYPE_IMAGE) { imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), SourceType::SOURCE_TYPE_IMAGE){
addWatcherListeners(); addWatcherListeners();
} }
MediaServer::~MediaServer() { MediaServer::~MediaServer(){
removeWatcherListeners(); removeWatcherListeners();
}; }
int MediaServer::getNumImages() { return imageWatcher.getFilePaths().size(); } int MediaServer::getNumImages(){
int MediaServer::getNumVideos() { return videoWatcher.getFilePaths().size(); } return imageWatcher.getFilePaths().size();
int MediaServer::getNumFboSources() { return fboSources.size(); } }
int MediaServer::getNumVideos(){
return videoWatcher.getFilePaths().size();
}
int MediaServer::getNumFboSources(){
return fboSources.size();
}
std::vector<std::string>& MediaServer::getImagePaths() { std::vector <std::string> & MediaServer::getImagePaths(){
return imageWatcher.getFilePaths(); return imageWatcher.getFilePaths();
} }
std::vector<std::string> MediaServer::getImageNames() { std::vector <std::string> MediaServer::getImageNames(){
std::vector<std::string> imageNames; std::vector <std::string> imageNames;
for (int i = 0; i < getNumImages(); i++) { for(int i = 0; i < getNumImages(); i++){
// Split image path // Split image path
std::vector<std::string> pathParts = ofSplitString(getImagePaths()[i], "/"); std::vector <std::string> pathParts = ofSplitString(getImagePaths()[i], "/");
// And get only the last piece // And get only the last piece
std::string name = pathParts[pathParts.size()-1]; std::string name = pathParts[pathParts.size() - 1];
imageNames.push_back(name); imageNames.push_back(name);
} }
return imageNames; return imageNames;
} }
std::vector<std::string> MediaServer::getFboSourceNames() { std::vector <std::string> MediaServer::getFboSourceNames(){
std::vector<std::string> fboSourceNames; std::vector <std::string> fboSourceNames;
for (int i = 0; i < fboSources.size(); i++) { for(int i = 0; i < fboSources.size(); i++){
fboSourceNames.push_back(fboSources[i]->getName()); fboSourceNames.push_back(fboSources[i]->getName());
} }
return fboSourceNames; return fboSourceNames;
} }
std::vector<std::string>& MediaServer::getVideoPaths() { std::vector <std::string> & MediaServer::getVideoPaths(){
return videoWatcher.getFilePaths(); return videoWatcher.getFilePaths();
} }
std::vector<std::string> MediaServer::getVideoNames() { std::vector <std::string> MediaServer::getVideoNames(){
std::vector<std::string> videoNames; std::vector <std::string> videoNames;
for (int i = 0; i < getNumVideos(); i++) { for(int i = 0; i < getNumVideos(); i++){
// Split video path // Split video path
std::vector<std::string> pathParts = ofSplitString(getVideoPaths()[i], "/"); std::vector <std::string> pathParts = ofSplitString(getVideoPaths()[i], "/");
// And get only the last piece // And get only the last piece
std::string name = pathParts[pathParts.size()-1]; std::string name = pathParts[pathParts.size() - 1];
videoNames.push_back(name); videoNames.push_back(name);
} }
return videoNames; return videoNames;
} }
BaseSource* MediaServer::loadMedia(string &path, int mediaType) { BaseSource * MediaServer::loadMedia(string & path, int mediaType){
// Chose load method depending on type // Chose load method depending on type
if (mediaType == SourceType::SOURCE_TYPE_IMAGE) { if(mediaType == SourceType::SOURCE_TYPE_IMAGE){
return loadImage(path); return loadImage(path);
} else if (mediaType == SourceType::SOURCE_TYPE_VIDEO) { }else if(mediaType == SourceType::SOURCE_TYPE_VIDEO){
return loadVideo(path); return loadVideo(path);
} else if (mediaType == SourceType::SOURCE_TYPE_FBO) { }else if(mediaType == SourceType::SOURCE_TYPE_FBO){
return loadFboSource(path); return loadFboSource(path);
} else { }else{
std::stringstream ss; std::stringstream ss;
ss << "Can not load media of unknown type: " << mediaType; ss << "Can not load media of unknown type: " << mediaType;
ofLogFatalError("MediaServer") << ss.str(); ofLogFatalError("MediaServer") << ss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
return NULL; return NULL;
} }
BaseSource* MediaServer::loadImage(string& path) { BaseSource * MediaServer::loadImage(string & path){
ImageSource* imageSource = NULL; ImageSource * imageSource = NULL;
// Check if this image is already loaded // Check if this image is already loaded
bool isImageLoaded = false; bool isImageLoaded = false;
if (loadedSources.count(path)) { if(loadedSources.count(path)){
imageSource = static_cast<ImageSource*>(loadedSources[path]); imageSource = static_cast <ImageSource *>(loadedSources[path]);
isImageLoaded = true; isImageLoaded = true;
} }
// If image is loaded // If image is loaded
if (isImageLoaded) { if(isImageLoaded){
// Increase reference count of this source // Increase reference count of this source
//referenceCount[path]++; //referenceCount[path]++;
imageSource->referenceCount++; imageSource->referenceCount++;
@ -117,15 +123,15 @@ namespace piMapper {
// Notify objects registered to onImageLoaded event // Notify objects registered to onImageLoaded event
ofNotifyEvent(onImageLoaded, path, this); ofNotifyEvent(onImageLoaded, path, this);
return imageSource; return imageSource;
} }
void MediaServer::unloadImage(string& path) { void MediaServer::unloadImage(string & path){
ImageSource* source = static_cast<ImageSource*>(getSourceByPath(path)); ImageSource * source = static_cast <ImageSource *>(getSourceByPath(path));
ofLogNotice("MediaServer") << "Unload image, current reference count: " << source->referenceCount; ofLogNotice("MediaServer") << "Unload image, current reference count: " << source->referenceCount;
source->referenceCount--; source->referenceCount--;
// Unload only if reference count is less or equal to 0 // Unload only if reference count is less or equal to 0
ofLogNotice("MediaServer") << "New reference count: " << source->referenceCount; ofLogNotice("MediaServer") << "New reference count: " << source->referenceCount;
if (source->referenceCount > 0) { if(source->referenceCount > 0){
ofLogNotice("MediaServer") << "Not unloading image as it is being referenced elsewhere"; ofLogNotice("MediaServer") << "Not unloading image as it is being referenced elsewhere";
return; return;
} }
@ -134,10 +140,10 @@ namespace piMapper {
ss << "Removing image " << path; ss << "Removing image " << path;
ofLogNotice("MediaServer") << ss.str(); ofLogNotice("MediaServer") << ss.str();
// Destroy image source // Destroy image source
if (loadedSources.count(path)) { if(loadedSources.count(path)){
ofLogNotice("MediaServer") << "Source count BEFORE image removal: " << loadedSources.size() << endl; ofLogNotice("MediaServer") << "Source count BEFORE image removal: " << loadedSources.size() << endl;
loadedSources[path]->clear(); loadedSources[path]->clear();
std::map<std::string, BaseSource*>::iterator it = loadedSources.find(path); std::map <std::string, BaseSource *>::iterator it = loadedSources.find(path);
delete it->second; delete it->second;
loadedSources.erase(it); loadedSources.erase(it);
ofLogNotice("MediaServer") << "Source count AFTER image removal: " << loadedSources.size() << endl; ofLogNotice("MediaServer") << "Source count AFTER image removal: " << loadedSources.size() << endl;
@ -149,18 +155,18 @@ namespace piMapper {
failss << "Failed to remove image source: " << path; failss << "Failed to remove image source: " << path;
ofLogFatalError("MediaServer") << failss.str(); ofLogFatalError("MediaServer") << failss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
BaseSource* MediaServer::loadVideo(string& path) { BaseSource * MediaServer::loadVideo(string & path){
VideoSource* videoSource = NULL; VideoSource * videoSource = NULL;
// Check if this video is already loaded // Check if this video is already loaded
bool isVideoLoaded = false; bool isVideoLoaded = false;
if (loadedSources.count(path)) { if(loadedSources.count(path)){
videoSource = static_cast<VideoSource*>(loadedSources[path]); videoSource = static_cast <VideoSource *>(loadedSources[path]);
isVideoLoaded = true; isVideoLoaded = true;
} }
// If is loaded // If is loaded
if (isVideoLoaded) { if(isVideoLoaded){
// Increase reference count of this source // Increase reference count of this source
videoSource->referenceCount++; videoSource->referenceCount++;
std::stringstream refss; std::stringstream refss;
@ -184,25 +190,25 @@ namespace piMapper {
ofLogNotice("MediaServer") << refss.str(); ofLogNotice("MediaServer") << refss.str();
ofNotifyEvent(onVideoLoaded, path, this); ofNotifyEvent(onVideoLoaded, path, this);
return videoSource; return videoSource;
} }
void MediaServer::unloadVideo(string& path) { void MediaServer::unloadVideo(string & path){
VideoSource* videoSource = static_cast<VideoSource*>(getSourceByPath(path)); VideoSource * videoSource = static_cast <VideoSource *>(getSourceByPath(path));
// Decrease reference count of the video // Decrease reference count of the video
//referenceCount[path]--; //referenceCount[path]--;
videoSource->referenceCount--; videoSource->referenceCount--;
// Unload only if reference count is less or equal to 0 // Unload only if reference count is less or equal to 0
if (videoSource->referenceCount > 0) { if(videoSource->referenceCount > 0){
ofLogNotice("MediaServer") << "Not unloading video as it is being referenced elsewhere"; ofLogNotice("MediaServer") << "Not unloading video as it is being referenced elsewhere";
return; return;
} }
// Reference count 0 or less, let's unload the video // Reference count 0 or less, let's unload the video
ofLogNotice("MediaServer") << "Removing video " << path; ofLogNotice("MediaServer") << "Removing video " << path;
// Distroy video source // Distroy video source
if (loadedSources.count(path)) { if(loadedSources.count(path)){
ofLogNotice("MediaServer") << "Source count before video removal: " << loadedSources.size() << endl; ofLogNotice("MediaServer") << "Source count before video removal: " << loadedSources.size() << endl;
videoSource->clear(); videoSource->clear();
std::map<std::string, BaseSource*>::iterator it = loadedSources.find(path); std::map <std::string, BaseSource *>::iterator it = loadedSources.find(path);
delete it->second; delete it->second;
loadedSources.erase(it); loadedSources.erase(it);
ofLogNotice("MediaServer") << "Source count after video removal: " << loadedSources.size() << endl; ofLogNotice("MediaServer") << "Source count after video removal: " << loadedSources.size() << endl;
@ -214,42 +220,42 @@ namespace piMapper {
failss << "Failed to remove video source: " << path; failss << "Failed to remove video source: " << path;
ofLogFatalError("MediaServer") << failss.str(); ofLogFatalError("MediaServer") << failss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
void MediaServer::unloadMedia(string &path) { void MediaServer::unloadMedia(string & path){
if (loadedSources.count(path)) { if(loadedSources.count(path)){
BaseSource* mediaSource = getSourceByPath(path); BaseSource * mediaSource = getSourceByPath(path);
if (mediaSource->getType() == SourceType::SOURCE_TYPE_IMAGE) { if(mediaSource->getType() == SourceType::SOURCE_TYPE_IMAGE){
unloadImage(path); unloadImage(path);
} else if (mediaSource->getType() == SourceType::SOURCE_TYPE_VIDEO) { }else if(mediaSource->getType() == SourceType::SOURCE_TYPE_VIDEO){
unloadVideo(path); unloadVideo(path);
} else if (mediaSource->getType() == SourceType::SOURCE_TYPE_FBO) { }else if(mediaSource->getType() == SourceType::SOURCE_TYPE_FBO){
unloadFboSource(path); unloadFboSource(path);
} else { }else{
// Oh my god, what to do!? Relax and exit. // Oh my god, what to do!? Relax and exit.
ofLogFatalError("MediaServer") << "Attempt to unload media of unknown type"; ofLogFatalError("MediaServer") << "Attempt to unload media of unknown type";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} else { }else{
ofLogNotice("MediaServer") << "Nothing to unload"; ofLogNotice("MediaServer") << "Nothing to unload";
} }
} }
// Clear all loaded media // Clear all loaded media
void MediaServer::clear() { void MediaServer::clear(){
typedef std::map<std::string, BaseSource*>::iterator it_type; typedef std::map <std::string, BaseSource *>::iterator it_type;
for (it_type i = loadedSources.begin(); i != loadedSources.end(); i++) { for(it_type i = loadedSources.begin(); i != loadedSources.end(); i++){
// Do not delete FBO source pointers as they are (and should be) initialized elsewhere // Do not delete FBO source pointers as they are (and should be) initialized elsewhere
if (i->second->getType() != SourceType::SOURCE_TYPE_FBO) { if(i->second->getType() != SourceType::SOURCE_TYPE_FBO){
delete i->second; delete i->second;
} }
} }
loadedSources.clear(); loadedSources.clear();
} }
// TODO: getLoadedSourceByPath // TODO: getLoadedSourceByPath
BaseSource* MediaServer::getSourceByPath(std::string& mediaPath) { BaseSource * MediaServer::getSourceByPath(std::string & mediaPath){
if (loadedSources.count(mediaPath)) { if(loadedSources.count(mediaPath)){
return loadedSources[mediaPath]; return loadedSources[mediaPath];
} }
// Source not found, exit with error // Source not found, exit with error
@ -257,59 +263,59 @@ namespace piMapper {
ss << "Could not find source by path: " << mediaPath; ss << "Could not find source by path: " << mediaPath;
ofLogFatalError("MediaServer") << ss.str(); ofLogFatalError("MediaServer") << ss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
std::string MediaServer::getDefaultImageDir() { std::string MediaServer::getDefaultImageDir(){
return DEFAULT_IMAGES_DIR; return DEFAULT_IMAGES_DIR;
} }
std::string MediaServer::getDefaultVideoDir() { std::string MediaServer::getDefaultVideoDir(){
return DEFAULT_VIDEOS_DIR; return DEFAULT_VIDEOS_DIR;
} }
std::string MediaServer::getDefaultMediaDir(int sourceType) { std::string MediaServer::getDefaultMediaDir(int sourceType){
if (sourceType == SourceType::SOURCE_TYPE_IMAGE) { if(sourceType == SourceType::SOURCE_TYPE_IMAGE){
return getDefaultImageDir(); return getDefaultImageDir();
} else if (sourceType == SourceType::SOURCE_TYPE_VIDEO) { }else if(sourceType == SourceType::SOURCE_TYPE_VIDEO){
return getDefaultVideoDir(); return getDefaultVideoDir();
} else { }else{
std::stringstream ss; std::stringstream ss;
ss << "Could not get default media dir. Unknown source type: " << sourceType; ss << "Could not get default media dir. Unknown source type: " << sourceType;
ofLogFatalError("MediaServer") << ss.str(); ofLogFatalError("MediaServer") << ss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} }
void MediaServer::addFboSource(ofx::piMapper::FboSource &fboSource) { void MediaServer::addFboSource(ofx::piMapper::FboSource & fboSource){
ofLogNotice("MediaServer") << "Attempting to add FBO source with name " << fboSource.getName(); ofLogNotice("MediaServer") << "Attempting to add FBO source with name " << fboSource.getName();
// FBO source has to be with unique name // FBO source has to be with unique name
for (int i = 0; i < fboSources.size(); i++) { for(int i = 0; i < fboSources.size(); i++){
if (fboSources[i]->getName() == fboSource.getName()) { if(fboSources[i]->getName() == fboSource.getName()){
ofLogWarning("MediaServer") << "Attempt to add FBO source with duplicate name"; ofLogWarning("MediaServer") << "Attempt to add FBO source with duplicate name";
ofExit(EXIT_FAILURE); // Here we definitely need to fail to avoid confusion ofExit(EXIT_FAILURE); // Here we definitely need to fail to avoid confusion
} }
} }
ofLogNotice("MediaServer") << "Source new, adding"; ofLogNotice("MediaServer") << "Source new, adding";
fboSources.push_back(&fboSource); fboSources.push_back(&fboSource);
} // addFboSource } // addFboSource
BaseSource* MediaServer::loadFboSource(std::string &fboSourceName) { BaseSource * MediaServer::loadFboSource(std::string & fboSourceName){
ofLogNotice("MediaServer") << "Attempting to load FBO source with name " << fboSourceName; ofLogNotice("MediaServer") << "Attempting to load FBO source with name " << fboSourceName;
// Search for FBO source name in our storage // Search for FBO source name in our storage
FboSource* source = NULL; FboSource * source = NULL;
for (int i = 0; i < fboSources.size(); i++) { for(int i = 0; i < fboSources.size(); i++){
if (fboSources[i]->getName() == fboSourceName) { if(fboSources[i]->getName() == fboSourceName){
source = fboSources[i]; source = fboSources[i];
break; break;
} }
} }
// Panic if not in storage // Panic if not in storage
if (source == NULL) { if(source == NULL){
ofLogError("MediaServer") << "Attempt to load non existing FBO source: " << fboSourceName; ofLogError("MediaServer") << "Attempt to load non existing FBO source: " << fboSourceName;
ofExit(EXIT_FAILURE); ofExit(EXIT_FAILURE);
} }
// Check if it is loaded/activated // Check if it is loaded/activated
if (loadedSources.count(fboSourceName)) { if(loadedSources.count(fboSourceName)){
// Is loaded, increase reference count and return existing // Is loaded, increase reference count and return existing
loadedSources[fboSourceName]->referenceCount++; loadedSources[fboSourceName]->referenceCount++;
ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount; ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount;
@ -323,60 +329,60 @@ namespace piMapper {
ofLogNotice("MediaServer") << "Current " << fboSourceName << " reference count: " << source->referenceCount; ofLogNotice("MediaServer") << "Current " << fboSourceName << " reference count: " << source->referenceCount;
loadedSources[fboSourceName] = source; loadedSources[fboSourceName] = source;
return loadedSources[fboSourceName]; return loadedSources[fboSourceName];
} // loadFboSource } // loadFboSource
void MediaServer::unloadFboSource(std::string &fboSourceName) { void MediaServer::unloadFboSource(std::string & fboSourceName){
ofLogNotice("MediaServer") << "Attempt to unload FBO source " << fboSourceName; ofLogNotice("MediaServer") << "Attempt to unload FBO source " << fboSourceName;
// Check if loaded at all // Check if loaded at all
if (!loadedSources.count(fboSourceName)) { if(!loadedSources.count(fboSourceName)){
ofLogWarning("MediaServer") << "FBO source not loaded"; ofLogWarning("MediaServer") << "FBO source not loaded";
return; return;
} }
// TODO: remove static cast, make the sources handle reference counting, // TODO: remove static cast, make the sources handle reference counting,
// enabling and disabling by themselves // enabling and disabling by themselves
FboSource* source = static_cast<FboSource*>(loadedSources[fboSourceName]); FboSource * source = static_cast <FboSource *>(loadedSources[fboSourceName]);
// else decrease reference count // else decrease reference count
source->referenceCount--; source->referenceCount--;
ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount; ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount;
// If no references left, disable // If no references left, disable
if (source->referenceCount <= 0) { if(source->referenceCount <= 0){
ofLogNotice("MediaServer") << fboSourceName << " reference count <= 0, removing from loaded sources"; ofLogNotice("MediaServer") << fboSourceName << " reference count <= 0, removing from loaded sources";
source->referenceCount = 0; source->referenceCount = 0;
source->removeAppListeners(); source->removeAppListeners();
std::map<std::string, BaseSource*>::iterator it = loadedSources.find(fboSourceName); std::map <std::string, BaseSource *>::iterator it = loadedSources.find(fboSourceName);
loadedSources.erase(it); loadedSources.erase(it);
ofLogNotice("MediaServer") << "Source count after FBO source removal: " << loadedSources.size() << endl; ofLogNotice("MediaServer") << "Source count after FBO source removal: " << loadedSources.size() << endl;
ofNotifyEvent(onFboSourceUnloaded, fboSourceName, this); ofNotifyEvent(onFboSourceUnloaded, fboSourceName, this);
} }
} // unloadFboSource } // unloadFboSource
void MediaServer::handleImageAdded(string& path) { void MediaServer::handleImageAdded(string & path){
ofNotifyEvent(onImageAdded, path, this); ofNotifyEvent(onImageAdded, path, this);
} }
void MediaServer::handleImageRemoved(string& path) { void MediaServer::handleImageRemoved(string & path){
ofNotifyEvent(onImageRemoved, path, this); ofNotifyEvent(onImageRemoved, path, this);
} }
void MediaServer::handleVideoAdded(string& path) { void MediaServer::handleVideoAdded(string & path){
ofNotifyEvent(onVideoAdded, path, this); ofNotifyEvent(onVideoAdded, path, this);
} }
void MediaServer::handleVideoRemoved(string& path) { void MediaServer::handleVideoRemoved(string & path){
ofNotifyEvent(onVideoRemoved, path, this); ofNotifyEvent(onVideoRemoved, path, this);
} }
void MediaServer::addWatcherListeners() { void MediaServer::addWatcherListeners(){
ofAddListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded); ofAddListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded);
ofAddListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved); ofAddListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved);
ofAddListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded); ofAddListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded);
ofAddListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved); ofAddListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved);
} }
void MediaServer::removeWatcherListeners() { void MediaServer::removeWatcherListeners(){
ofRemoveListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded); ofRemoveListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded);
ofRemoveListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved); ofRemoveListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved);
ofRemoveListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded); ofRemoveListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded);
ofRemoveListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved); ofRemoveListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved);
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

69
src/MediaServer/MediaServer.h

@ -37,52 +37,52 @@ class MediaServer {
int getNumVideos(); int getNumVideos();
int getNumImages(); int getNumImages();
int getNumFboSources(); // new int getNumFboSources(); // new
std::vector<std::string>& getVideoPaths(); std::vector <std::string> & getVideoPaths();
std::vector<std::string> getVideoNames(); std::vector <std::string> getVideoNames();
std::vector<std::string>& getImagePaths(); std::vector <std::string> & getImagePaths();
std::vector<std::string> getImageNames(); std::vector <std::string> getImageNames();
std::vector<std::string> getFboSourceNames(); // new std::vector <std::string> getFboSourceNames(); // new
BaseSource* loadMedia(string& path, int mediaType); BaseSource * loadMedia(string & path, int mediaType);
BaseSource* loadImage(string& path); BaseSource * loadImage(string & path);
void unloadImage(string& path); void unloadImage(string & path);
BaseSource* loadVideo(string& path); BaseSource * loadVideo(string & path);
void unloadVideo(string& path); void unloadVideo(string & path);
void unloadMedia(string& path); void unloadMedia(string & path);
void clear(); // Force all loaded source unload void clear(); // Force all loaded source unload
BaseSource* getSourceByPath(std::string& mediaPath); BaseSource * getSourceByPath(std::string & mediaPath);
std::string getDefaultImageDir(); std::string getDefaultImageDir();
std::string getDefaultVideoDir(); std::string getDefaultVideoDir();
std::string getDefaultMediaDir(int sourceType); std::string getDefaultMediaDir(int sourceType);
// Do things with FBO sources // Do things with FBO sources
void addFboSource(FboSource& fboSource); // could be called also as register FBO source void addFboSource(FboSource & fboSource); // could be called also as register FBO source
BaseSource* loadFboSource(std::string& fboSourceName); BaseSource * loadFboSource(std::string & fboSourceName);
void unloadFboSource(std::string& fboSourceName); void unloadFboSource(std::string & fboSourceName);
// Custom events, add/remove // Custom events, add/remove
ofEvent<std::string> onImageAdded; ofEvent <std::string> onImageAdded;
ofEvent<std::string> onImageRemoved; ofEvent <std::string> onImageRemoved;
ofEvent<std::string> onVideoAdded; ofEvent <std::string> onVideoAdded;
ofEvent<std::string> onVideoRemoved; ofEvent <std::string> onVideoRemoved;
ofEvent<std::string> onFboSourceAdded; ofEvent <std::string> onFboSourceAdded;
ofEvent<std::string> onFboSourceRemoved; ofEvent <std::string> onFboSourceRemoved;
// load/unload // load/unload
ofEvent<std::string> onImageLoaded; ofEvent <std::string> onImageLoaded;
ofEvent<std::string> onImageUnloaded; ofEvent <std::string> onImageUnloaded;
ofEvent<std::string> onVideoLoaded; ofEvent <std::string> onVideoLoaded;
ofEvent<std::string> onVideoUnloaded; ofEvent <std::string> onVideoUnloaded;
ofEvent<std::string> onFboSourceLoaded; ofEvent <std::string> onFboSourceLoaded;
ofEvent<std::string> onFboSourceUnloaded; ofEvent <std::string> onFboSourceUnloaded;
private: private:
// Directory Watchers // Directory Watchers
ofx::piMapper::DirectoryWatcher videoWatcher; ofx::piMapper::DirectoryWatcher videoWatcher;
ofx::piMapper::DirectoryWatcher imageWatcher; ofx::piMapper::DirectoryWatcher imageWatcher;
std::map<std::string, BaseSource*> loadedSources; std::map <std::string, BaseSource *> loadedSources;
// imageWatcher event listeners // imageWatcher event listeners
void handleImageAdded(string& path); void handleImageAdded(string & path);
void handleImageRemoved(string& path); void handleImageRemoved(string & path);
// TODO rest of listeners // TODO rest of listeners
/* /*
void onImageModified(); void onImageModified();
@ -91,8 +91,8 @@ class MediaServer {
*/ */
// videoWatcher event listeners // videoWatcher event listeners
void handleVideoAdded(string& path); void handleVideoAdded(string & path);
void handleVideoRemoved(string& path); void handleVideoRemoved(string & path);
// TODO rest of listeners // TODO rest of listeners
/* /*
void onVideoModified(); void onVideoModified();
@ -108,7 +108,8 @@ class MediaServer {
void removeWatcherListeners(); void removeWatcherListeners();
// FBO source storage before they go to loadedSources // FBO source storage before they go to loadedSources
std::vector<FboSource*> fboSources; // FBO source storage std::vector <FboSource *> fboSources; // FBO source storage
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

50
src/Sources/BaseSource.cpp

@ -1,44 +1,45 @@
#include "BaseSource.h" #include "BaseSource.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
BaseSource::BaseSource() {
BaseSource::BaseSource(){
//cout << "BaseSource" << endl; //cout << "BaseSource" << endl;
init(); init();
} }
BaseSource::BaseSource(ofTexture* newTexture) { BaseSource::BaseSource(ofTexture * newTexture){
init(); init();
texture = newTexture; texture = newTexture;
} }
BaseSource::~BaseSource() {} BaseSource::~BaseSource(){}
ofTexture* BaseSource::getTexture() { ofTexture * BaseSource::getTexture(){
return texture; return texture;
} }
std::string& BaseSource::getName() { std::string & BaseSource::getName(){
return name; return name;
} }
bool BaseSource::isLoadable() { bool BaseSource::isLoadable(){
return loadable; return loadable;
} }
bool BaseSource::isLoaded() { bool BaseSource::isLoaded(){
return loaded; return loaded;
} }
int BaseSource::getType() { int BaseSource::getType(){
return type; return type;
} }
std::string& BaseSource::getPath() { std::string & BaseSource::getPath(){
return path; return path;
} }
void BaseSource::init() { void BaseSource::init(){
texture = NULL; texture = NULL;
name = ""; name = "";
path = ""; path = "";
@ -46,14 +47,15 @@ namespace ofx {
loaded = false; loaded = false;
type = SourceType::SOURCE_TYPE_NONE; type = SourceType::SOURCE_TYPE_NONE;
referenceCount = 1; // We have one instance on init referenceCount = 1; // We have one instance on init
} }
void BaseSource::setNameFromPath(std::string& fullPath) { void BaseSource::setNameFromPath(std::string & fullPath){
std::vector<string> pathParts; std::vector <string> pathParts;
//cout << "fullPath: " << fullPath << endl; //cout << "fullPath: " << fullPath << endl;
pathParts = ofSplitString(fullPath, "/"); // Maybe on win "/" is "\", have to test pathParts = ofSplitString(fullPath, "/"); // Maybe on win "/" is "\", have to test
//cout << "lastPathPart: " << pathParts[pathParts.size() - 1] << endl; //cout << "lastPathPart: " << pathParts[pathParts.size() - 1] << endl;
name = pathParts[pathParts.size() - 1]; name = pathParts[pathParts.size() - 1];
}
}
} }
} // namespace piMapper
} // namespace ofx

30
src/Sources/BaseSource.h

@ -4,20 +4,22 @@
#include "SourceType.h" #include "SourceType.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
// Use this for adding generative sources to your surfaces
class BaseSource { // Use this for adding generative sources to your surfaces
class BaseSource {
public: public:
BaseSource(); BaseSource();
BaseSource(ofTexture* newTexture); // Only one clean way of passing the texture BaseSource(ofTexture * newTexture); // Only one clean way of passing the texture
~BaseSource(); ~BaseSource();
ofTexture* getTexture(); ofTexture * getTexture();
std::string& getName(); std::string & getName();
bool isLoadable(); // Maybe the loading features shoud go to a derrived class bool isLoadable(); // Maybe the loading features shoud go to a derrived class
bool isLoaded(); // as BaseSourceLoadable bool isLoaded(); // as BaseSourceLoadable
int getType(); int getType();
std::string& getPath(); std::string & getPath();
virtual void clear() {}; virtual void clear(){}
// TODO: add virtual increaseReferenceCount and decreaseReferenceCount methods // TODO: add virtual increaseReferenceCount and decreaseReferenceCount methods
// and make the variable protected // and make the variable protected
@ -27,13 +29,15 @@ namespace ofx {
void init(); void init();
protected: protected:
void setNameFromPath(std::string& fullPath); void setNameFromPath(std::string & fullPath);
ofTexture* texture; ofTexture * texture;
std::string name; std::string name;
std::string path; // This is set only if loadable is true std::string path; // This is set only if loadable is true
bool loadable; // If the source can be loaded from disk like image and video bool loadable; // If the source can be loaded from disk like image and video
bool loaded; // Is the source loaded? bool loaded; // Is the source loaded?
int type; int type;
};
} };
}
} // namespace piMapper
} // namespace ofx

72
src/Sources/FboSource.cpp

@ -1,23 +1,23 @@
#include "FboSource.h" #include "FboSource.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
FboSource::FboSource() : fbo(NULL) { FboSource::FboSource() : fbo(NULL){
name = PIMAPPER_FBO_SOURCE_DEF_NAME; name = PIMAPPER_FBO_SOURCE_DEF_NAME;
loadable = false; loadable = false;
loaded = false; loaded = false;
type = SourceType::SOURCE_TYPE_FBO; type = SourceType::SOURCE_TYPE_FBO;
ofAddListener(ofEvents().setup, this, ofAddListener(ofEvents().setup, this,
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP);
} }
FboSource::~FboSource() { FboSource::~FboSource(){
removeAppListeners(); removeAppListeners();
clear(); clear();
} }
void FboSource::addAppListeners() { void FboSource::addAppListeners(){
ofLogNotice("FboSource") << "Adding app listeners"; ofLogNotice("FboSource") << "Adding app listeners";
ofAddListener(ofEvents().update, this, ofAddListener(ofEvents().update, this,
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP);
@ -25,9 +25,9 @@ namespace ofx {
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP);
ofAddListener(ofEvents().exit, this, ofAddListener(ofEvents().exit, this,
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP);
} }
void FboSource::removeAppListeners() { void FboSource::removeAppListeners(){
ofLogNotice("FboSource") << "Removing app listeners"; ofLogNotice("FboSource") << "Removing app listeners";
ofRemoveListener(ofEvents().update, this, ofRemoveListener(ofEvents().update, this,
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP);
@ -35,46 +35,46 @@ namespace ofx {
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP);
ofRemoveListener(ofEvents().exit, this, ofRemoveListener(ofEvents().exit, this,
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP);
} }
void FboSource::onAppSetup(ofEventArgs &args) { void FboSource::onAppSetup(ofEventArgs & args){
ofRemoveListener(ofEvents().setup, this, ofRemoveListener(ofEvents().setup, this,
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP);
setup(); setup();
// Check if FBO was allocated in user defined setup // Check if FBO was allocated in user defined setup
// If not, show warning and alocate to avoid panic // If not, show warning and alocate to avoid panic
if (!fbo->isAllocated()) { if(!fbo->isAllocated()){
ofLogWarning("FboSource::onAppSetup") << ofLogWarning("FboSource::onAppSetup")
"FBO not allocated, allocating with default values"; << "FBO not allocated, allocating with default values";
allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH,
PIMAPPER_FBO_SOURCE_DEF_HEIGHT); PIMAPPER_FBO_SOURCE_DEF_HEIGHT);
} }
} }
void FboSource::onAppUpdate(ofEventArgs &args) { void FboSource::onAppUpdate(ofEventArgs & args){
if (fbo == NULL || !fbo->isAllocated()) { if(fbo == NULL || !fbo->isAllocated()){
ofLogWarning("FboSource") << "FBO not allocated"; ofLogWarning("FboSource") << "FBO not allocated";
return; return;
} }
update(); update();
} }
void FboSource::onAppDraw(ofEventArgs &args) { void FboSource::onAppDraw(ofEventArgs & args){
if (fbo == NULL || !fbo->isAllocated()) { if(fbo == NULL || !fbo->isAllocated()){
ofLogWarning("FboSource") << "FBO not allocated"; ofLogWarning("FboSource") << "FBO not allocated";
return; return;
} }
fbo->begin(); fbo->begin();
draw(); draw();
fbo->end(); fbo->end();
} }
void FboSource::onAppExit(ofEventArgs &args) { void FboSource::onAppExit(ofEventArgs & args){
exit(); exit();
} }
void FboSource::allocate(int width, int height) { void FboSource::allocate(int width, int height){
clear(); clear();
fbo = new ofFbo(); fbo = new ofFbo();
fbo->allocate(width, height); fbo->allocate(width, height);
@ -85,31 +85,31 @@ namespace ofx {
fbo->end(); fbo->end();
texture = &(fbo->getTextureReference()); texture = &(fbo->getTextureReference());
} }
void FboSource::clear() { void FboSource::clear(){
texture = NULL; texture = NULL;
if (fbo != NULL) { if(fbo != NULL){
delete fbo; delete fbo;
fbo = NULL; fbo = NULL;
} }
} }
int FboSource::getWidth() { int FboSource::getWidth(){
if (fbo->isAllocated()) { if(fbo->isAllocated()){
return fbo->getWidth(); return fbo->getWidth();
} else { }else{
return 0; return 0;
} }
} }
int FboSource::getHeight() { int FboSource::getHeight(){
if (fbo->isAllocated()) { if(fbo->isAllocated()){
return fbo->getHeight(); return fbo->getHeight();
} else { }else{
return 0; return 0;
} }
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

18
src/Sources/FboSource.h

@ -8,18 +8,19 @@
#define PIMAPPER_FBO_SOURCE_DEF_HEIGHT 500 #define PIMAPPER_FBO_SOURCE_DEF_HEIGHT 500
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class FboSource : public BaseSource {
class FboSource : public BaseSource {
public: public:
FboSource(); FboSource();
~FboSource(); ~FboSource();
// Override these in your custom FBO source // Override these in your custom FBO source
virtual void setup() {}; virtual void setup(){}
virtual void update() {}; virtual void update(){}
virtual void draw() {}; virtual void draw(){}
virtual void exit() {}; virtual void exit(){}
// The only method from BaseSource to be overriden // The only method from BaseSource to be overriden
void clear(); void clear();
@ -39,7 +40,8 @@ namespace ofx {
// Some handy getters // Some handy getters
int getWidth(); int getWidth();
int getHeight(); int getHeight();
};
} // namespace piMapper };
} // namespace piMapper
} // namespace ofx } // namespace ofx

23
src/Sources/ImageSource.cpp

@ -1,31 +1,32 @@
#include "ImageSource.h" #include "ImageSource.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
ImageSource::ImageSource() {
ImageSource::ImageSource(){
//cout << "ImageSource" << endl; //cout << "ImageSource" << endl;
loadable = true; loadable = true;
loaded = false; loaded = false;
type = SourceType::SOURCE_TYPE_IMAGE; type = SourceType::SOURCE_TYPE_IMAGE;
} }
ImageSource::~ImageSource() {} ImageSource::~ImageSource(){}
void ImageSource::loadImage(std::string& filePath) { void ImageSource::loadImage(std::string & filePath){
path = filePath; path = filePath;
//cout << "loading image: " << filePath << endl; //cout << "loading image: " << filePath << endl;
setNameFromPath(filePath); setNameFromPath(filePath);
//cout << "path: " << path << endl; //cout << "path: " << path << endl;
image = new ofImage(); image = new ofImage();
if (!image->loadImage(filePath)) { if(!image->loadImage(filePath)){
ofLogWarning("ImageSource") << "Could not load image"; ofLogWarning("ImageSource") << "Could not load image";
//std::exit(EXIT_FAILURE); //std::exit(EXIT_FAILURE);
} }
texture = &image->getTextureReference(); texture = &image->getTextureReference();
loaded = true; loaded = true;
} }
void ImageSource::clear() { void ImageSource::clear(){
texture = NULL; texture = NULL;
image->clear(); image->clear();
delete image; delete image;
@ -33,7 +34,7 @@ namespace ofx {
//path = ""; //path = "";
//name = ""; //name = "";
loaded = false; loaded = false;
}
}
} }
} // namespace piMapper
} // namespace ofx

20
src/Sources/ImageSource.h

@ -3,16 +3,20 @@
#include "BaseSource.h" #include "BaseSource.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ImageSource : public BaseSource {
class ImageSource : public BaseSource {
public: public:
ImageSource(); ImageSource();
~ImageSource(); ~ImageSource();
std::string& getPath(); std::string & getPath();
void loadImage(std::string& filePath); void loadImage(std::string & filePath);
void clear(); void clear();
private: private:
ofImage* image; ofImage * image;
};
} };
}
} // namespace piMapper
} // namespace ofx

44
src/Sources/SourceType.h

@ -8,44 +8,50 @@
#define SOURCE_TYPE_NAME_FBO "fbo" #define SOURCE_TYPE_NAME_FBO "fbo"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourceType {
class SourceType {
public: public:
enum { SOURCE_TYPE_NONE, SOURCE_TYPE_IMAGE, SOURCE_TYPE_VIDEO, SOURCE_TYPE_FBO }; enum {
SOURCE_TYPE_NONE, SOURCE_TYPE_IMAGE, SOURCE_TYPE_VIDEO, SOURCE_TYPE_FBO
};
static std::string GetSourceTypeName(int sourceTypeEnum) { static std::string GetSourceTypeName(int sourceTypeEnum){
if (sourceTypeEnum == SOURCE_TYPE_IMAGE) { if(sourceTypeEnum == SOURCE_TYPE_IMAGE){
return SOURCE_TYPE_NAME_IMAGE; return SOURCE_TYPE_NAME_IMAGE;
} else if (sourceTypeEnum == SOURCE_TYPE_VIDEO) { }else if(sourceTypeEnum == SOURCE_TYPE_VIDEO){
return SOURCE_TYPE_NAME_VIDEO; return SOURCE_TYPE_NAME_VIDEO;
} else if (sourceTypeEnum == SOURCE_TYPE_NONE) { }else if(sourceTypeEnum == SOURCE_TYPE_NONE){
return SOURCE_TYPE_NAME_NONE; return SOURCE_TYPE_NAME_NONE;
} else if (sourceTypeEnum == SOURCE_TYPE_FBO) { }else if(sourceTypeEnum == SOURCE_TYPE_FBO){
return SOURCE_TYPE_NAME_FBO; return SOURCE_TYPE_NAME_FBO;
} else { }else{
std::stringstream ss; std::stringstream ss;
ss << "Invalid source type: " << sourceTypeEnum; ss << "Invalid source type: " << sourceTypeEnum;
ofLogFatalError("SourceType") << ss.str(); ofLogFatalError("SourceType") << ss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
}; }
static int GetSourceTypeEnum(std::string sourceTypeName) { static int GetSourceTypeEnum(std::string sourceTypeName){
if (sourceTypeName == SOURCE_TYPE_NAME_IMAGE) { if(sourceTypeName == SOURCE_TYPE_NAME_IMAGE){
return SOURCE_TYPE_IMAGE; return SOURCE_TYPE_IMAGE;
} else if (sourceTypeName == SOURCE_TYPE_NAME_VIDEO) { }else if(sourceTypeName == SOURCE_TYPE_NAME_VIDEO){
return SOURCE_TYPE_VIDEO; return SOURCE_TYPE_VIDEO;
} else if (sourceTypeName == SOURCE_TYPE_NAME_NONE) { }else if(sourceTypeName == SOURCE_TYPE_NAME_NONE){
return SOURCE_TYPE_NONE; return SOURCE_TYPE_NONE;
} else if (sourceTypeName == SOURCE_TYPE_NAME_FBO) { }else if(sourceTypeName == SOURCE_TYPE_NAME_FBO){
return SOURCE_TYPE_FBO; return SOURCE_TYPE_FBO;
} else { }else{
std::stringstream ss; std::stringstream ss;
ss << "Invalid source type name: " << sourceTypeName; ss << "Invalid source type name: " << sourceTypeName;
ofLogFatalError("SourceType") << ss.str(); ofLogFatalError("SourceType") << ss.str();
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} }
};
} };
}
} // namespace piMapper
} // namespace ofx

43
src/Sources/VideoSource.cpp

@ -1,27 +1,27 @@
#include "VideoSource.h" #include "VideoSource.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
bool VideoSource::enableAudio = false; bool VideoSource::enableAudio = false;
VideoSource::VideoSource() { VideoSource::VideoSource(){
loadable = true; loadable = true;
loaded = false; loaded = false;
type = SourceType::SOURCE_TYPE_VIDEO; type = SourceType::SOURCE_TYPE_VIDEO;
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
omxPlayer = NULL; omxPlayer = NULL;
#else #else
videoPlayer = NULL; videoPlayer = NULL;
#endif #endif
} }
VideoSource::~VideoSource() {} VideoSource::~VideoSource(){}
void VideoSource::loadVideo(std::string & filePath) { void VideoSource::loadVideo(std::string & filePath){
path = filePath; path = filePath;
setNameFromPath(filePath); setNameFromPath(filePath);
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
ofxOMXPlayerSettings settings; ofxOMXPlayerSettings settings;
settings.videoPath = filePath; settings.videoPath = filePath;
settings.useHDMIForAudio = true; settings.useHDMIForAudio = true;
@ -31,7 +31,7 @@ namespace ofx {
omxPlayer = new ofxOMXPlayer(); omxPlayer = new ofxOMXPlayer();
omxPlayer->setup(settings); omxPlayer->setup(settings);
texture = &(omxPlayer->getTextureReference()); texture = &(omxPlayer->getTextureReference());
#else #else
videoPlayer = new ofVideoPlayer(); videoPlayer = new ofVideoPlayer();
videoPlayer->load(filePath); videoPlayer->load(filePath);
videoPlayer->setLoopState(OF_LOOP_NORMAL); videoPlayer->setLoopState(OF_LOOP_NORMAL);
@ -39,32 +39,33 @@ namespace ofx {
videoPlayer->play(); videoPlayer->play();
texture = &(videoPlayer->getTexture()); texture = &(videoPlayer->getTexture());
ofAddListener(ofEvents().update, this, &VideoSource::update); ofAddListener(ofEvents().update, this, &VideoSource::update);
#endif #endif
loaded = true; loaded = true;
} }
void VideoSource::clear() { void VideoSource::clear(){
texture = NULL; texture = NULL;
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
omxPlayer->close(); omxPlayer->close();
delete omxPlayer; delete omxPlayer;
omxPlayer = NULL; omxPlayer = NULL;
#else #else
ofRemoveListener(ofEvents().update, this, &VideoSource::update); ofRemoveListener(ofEvents().update, this, &VideoSource::update);
videoPlayer->stop(); videoPlayer->stop();
videoPlayer->close(); videoPlayer->close();
delete videoPlayer; delete videoPlayer;
videoPlayer = NULL; videoPlayer = NULL;
#endif #endif
loaded = false; loaded = false;
} }
#ifndef TARGET_RASPBERRY_PI #ifndef TARGET_RASPBERRY_PI
void VideoSource::update(ofEventArgs & args) { void VideoSource::update(ofEventArgs & args){
if (videoPlayer != NULL) { if(videoPlayer != NULL){
videoPlayer->update(); videoPlayer->update();
} }
} }
#endif #endif
} // namespace piMapper
} // namespace piMapper
} // namespace ofx } // namespace ofx

23
src/Sources/VideoSource.h

@ -8,8 +8,10 @@
#endif #endif
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class VideoSource : public BaseSource {
class VideoSource : public BaseSource {
public: public:
// TODO: Create enableAudio() and disableAudio() methods // TODO: Create enableAudio() and disableAudio() methods
@ -23,20 +25,21 @@ namespace ofx {
void loadVideo(std::string & path); void loadVideo(std::string & path);
void clear(); void clear();
#ifndef TARGET_RASPBERRY_PI #ifndef TARGET_RASPBERRY_PI
void update(ofEventArgs & args); void update(ofEventArgs & args);
#endif #endif
private: private:
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
ofxOMXPlayer * omxPlayer; // Naming different for less confusion ofxOMXPlayer * omxPlayer; // Naming different for less confusion
#else #else
// Go with ofVideoPlayer or // Go with ofVideoPlayer or
// TODO: High Performance Video player on newer Macs // TODO: High Performance Video player on newer Macs
ofVideoPlayer * videoPlayer; ofVideoPlayer * videoPlayer;
#endif #endif
};
}; } // namespace piMapper
} } // namespace ofx
}

72
src/Surfaces/BaseSurface.cpp

@ -1,43 +1,44 @@
#include "BaseSurface.h" #include "BaseSurface.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
BaseSurface::BaseSurface() { BaseSurface::BaseSurface(){
_moved = false; _moved = false;
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
createDefaultTexture(); createDefaultTexture();
} }
BaseSurface::~BaseSurface() { BaseSurface::~BaseSurface(){
delete defaultSource; delete defaultSource;
defaultSource = NULL; defaultSource = NULL;
defaultTexture.clear(); defaultTexture.clear();
} }
void BaseSurface::createDefaultTexture() { void BaseSurface::createDefaultTexture(){
ofPixels pixels; ofPixels pixels;
pixels.allocate(500, 500, 1); pixels.allocate(500, 500, 1);
for (int i = 0; i < pixels.size(); i++) { for(int i = 0; i < pixels.size(); i++){
pixels[i] = 255; pixels[i] = 255;
} }
int squareSize = 10; // size of each test pattern square int squareSize = 10; // size of each test pattern square
bool sy = false; bool sy = false;
for (int y = 0; y < pixels.getWidth(); y += squareSize) { for(int y = 0; y < pixels.getWidth(); y += squareSize){
bool sx = false; bool sx = false;
for (int x = 0; x < pixels.getHeight(); x += squareSize) { for(int x = 0; x < pixels.getHeight(); x += squareSize){
for (int yi = 0; yi < squareSize; yi++) { for(int yi = 0; yi < squareSize; yi++){
for (int xi = 0; xi < squareSize; xi++) { for(int xi = 0; xi < squareSize; xi++){
if (sx && sy) if(sx && sy){
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; pixels[(y + yi) * pixels.getWidth() + x + xi] = 255;
else if (sx && !sy) }else if(sx && !sy){
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; pixels[(y + yi) * pixels.getWidth() + x + xi] = 0;
else if (!sx && sy) }else if(!sx && sy){
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; pixels[(y + yi) * pixels.getWidth() + x + xi] = 0;
else }else{
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; pixels[(y + yi) * pixels.getWidth() + x + xi] = 255;
} }
} }
}
sx = !sx; sx = !sx;
} }
sy = !sy; sy = !sy;
@ -48,10 +49,10 @@ namespace ofx {
// Create new source to be the default // Create new source to be the default
defaultSource = new BaseSource(&defaultTexture); defaultSource = new BaseSource(&defaultTexture);
source = defaultSource; source = defaultSource;
} }
void BaseSurface::drawTexture(ofVec2f position) { void BaseSurface::drawTexture(ofVec2f position){
if (source->getTexture() == NULL) { if(source->getTexture() == NULL){
ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; ofLogWarning("BaseSurface") << "Source texture empty. Not drawing.";
return; return;
} }
@ -59,8 +60,8 @@ namespace ofx {
ofMesh texMesh; ofMesh texMesh;
texMesh.addVertex(position); texMesh.addVertex(position);
texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f)); texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f));
texMesh.addVertex(position + texMesh.addVertex(position
ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); + ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()));
texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight())); texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight()));
texMesh.addTriangle(0, 2, 3); texMesh.addTriangle(0, 2, 3);
texMesh.addTriangle(0, 1, 2); texMesh.addTriangle(0, 1, 2);
@ -71,24 +72,29 @@ namespace ofx {
source->getTexture()->bind(); source->getTexture()->bind();
texMesh.draw(); texMesh.draw();
source->getTexture()->unbind(); source->getTexture()->unbind();
} }
//void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; } //void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; }
void BaseSurface::setSource(BaseSource* newSource) { void BaseSurface::setSource(BaseSource * newSource){
source = newSource; source = newSource;
} }
//ofTexture* BaseSurface::getTexture() { return texture; } //ofTexture* BaseSurface::getTexture() { return texture; }
BaseSource* BaseSurface::getSource() { BaseSource * BaseSurface::getSource(){
return source; return source;
} }
//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; } //ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
BaseSource* BaseSurface::getDefaultSource() { BaseSource * BaseSurface::getDefaultSource(){
return defaultSource; return defaultSource;
} }
void BaseSurface::setMoved(bool moved){ _moved = moved; } void BaseSurface::setMoved(bool moved){
bool BaseSurface::getMoved(){ return _moved; } _moved = moved;
}
} }
bool BaseSurface::getMoved(){
return _moved;
}
} // namespace piMapper
} // namespace ofx

46
src/Surfaces/BaseSurface.h

@ -7,27 +7,29 @@
using namespace std; using namespace std;
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class BaseSurface {
class BaseSurface {
public: public:
BaseSurface(); BaseSurface();
~BaseSurface(); ~BaseSurface();
virtual void setup() {}; virtual void setup(){}
virtual void draw() {}; virtual void draw(){}
virtual void setVertex(int index, ofVec2f p) {}; virtual void setVertex(int index, ofVec2f p){}
virtual void setTexCoord(int index, ofVec2f t) {}; virtual void setTexCoord(int index, ofVec2f t){}
virtual void moveBy(ofVec2f v) {}; virtual void moveBy(ofVec2f v){}
virtual int getType() {}; virtual int getType(){}
virtual bool hitTest(ofVec2f p) {}; virtual bool hitTest(ofVec2f p){}
virtual ofPolyline getHitArea() {}; virtual ofPolyline getHitArea(){}
virtual ofPolyline getTextureHitArea() {}; virtual ofPolyline getTextureHitArea(){}
virtual vector<ofVec3f>& getVertices() {}; virtual vector <ofVec3f> & getVertices(){}
virtual vector<ofVec2f>& getTexCoords() {}; virtual vector <ofVec2f> & getTexCoords(){}
void drawTexture(ofVec2f position); void drawTexture(ofVec2f position);
void setSource(BaseSource* newSource); void setSource(BaseSource * newSource);
BaseSource* getSource(); BaseSource * getSource();
BaseSource* getDefaultSource(); BaseSource * getDefaultSource();
void setMoved(bool moved); void setMoved(bool moved);
bool getMoved(); bool getMoved();
@ -35,10 +37,12 @@ namespace ofx {
protected: protected:
ofMesh mesh; ofMesh mesh;
ofTexture defaultTexture; ofTexture defaultTexture;
BaseSource* source; BaseSource * source;
BaseSource* defaultSource; BaseSource * defaultSource;
void createDefaultTexture(); void createDefaultTexture();
bool _moved; bool _moved;
};
} };
}
} // namespace piMapper
} // namespace ofx

68
src/Surfaces/QuadSurface.cpp

@ -2,13 +2,16 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
QuadSurface::QuadSurface() {
QuadSurface::QuadSurface(){
setup(); setup();
} }
QuadSurface::~QuadSurface() { cout << "QuadSurface destructor." << endl; } QuadSurface::~QuadSurface(){
cout << "QuadSurface destructor." << endl;
}
void QuadSurface::setup() { void QuadSurface::setup(){
// Create 4 points for the 2 triangles // Create 4 points for the 2 triangles
ofVec2f p1 = ofVec2f(0, 0); ofVec2f p1 = ofVec2f(0, 0);
ofVec2f p2 = ofVec2f(0, ofGetHeight()); ofVec2f p2 = ofVec2f(0, ofGetHeight());
@ -26,7 +29,7 @@ void QuadSurface::setup() {
void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4,
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4,
BaseSource* newSource) { BaseSource * newSource){
// Assign texture // Assign texture
source = newSource; source = newSource;
@ -66,8 +69,8 @@ void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4,
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::draw() { void QuadSurface::draw(){
if (source->getTexture() == NULL) { if(source->getTexture() == NULL){
ofLogWarning("QuadSurface") << "Source texture empty. Not drawing."; ofLogWarning("QuadSurface") << "Source texture empty. Not drawing.";
return; return;
} }
@ -90,8 +93,8 @@ void QuadSurface::draw() {
source->getTexture()->unbind(); source->getTexture()->unbind();
} }
void QuadSurface::setVertex(int index, ofVec2f p) { void QuadSurface::setVertex(int index, ofVec2f p){
if (index > 3) { if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
return; return;
} }
@ -100,8 +103,8 @@ void QuadSurface::setVertex(int index, ofVec2f p) {
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::setTexCoord(int index, ofVec2f t) { void QuadSurface::setTexCoord(int index, ofVec2f t){
if (index > 3) { if(index > 3){
ofLog() << "Texture coordinate with this index does not exist: " << index ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl; << endl;
return; return;
@ -111,30 +114,32 @@ void QuadSurface::setTexCoord(int index, ofVec2f t) {
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::moveBy(ofVec2f v) { void QuadSurface::moveBy(ofVec2f v){
vector<ofVec3f>& vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for (int i = 0; i < vertices.size(); i++) { for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v;
} }
calculate4dTextureCoords(); calculate4dTextureCoords();
setMoved(true); setMoved(true);
} }
int QuadSurface::getType() { return SurfaceType::QUAD_SURFACE; } int QuadSurface::getType(){
return SurfaceType::QUAD_SURFACE;
}
bool QuadSurface::hitTest(ofVec2f p) { bool QuadSurface::hitTest(ofVec2f p){
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
if (line.inside(p.x, p.y)) { if(line.inside(p.x, p.y)){
return true; return true;
} else { }else{
return false; return false;
} }
} }
ofVec2f QuadSurface::getVertex(int index) { ofVec2f QuadSurface::getVertex(int index){
if (index > 3) { if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
throw std::runtime_error("Vertex index out of bounds."); throw std::runtime_error("Vertex index out of bounds.");
} }
@ -143,15 +148,15 @@ ofVec2f QuadSurface::getVertex(int index) {
return ofVec2f(vert.x, vert.y); return ofVec2f(vert.x, vert.y);
} }
ofVec2f QuadSurface::getTexCoord(int index) { ofVec2f QuadSurface::getTexCoord(int index){
if (index > 3) { if(index > 3){
throw std::runtime_error("Texture coordinate index out of bounds."); throw std::runtime_error("Texture coordinate index out of bounds.");
} }
return mesh.getTexCoord(index); return mesh.getTexCoord(index);
} }
ofPolyline QuadSurface::getHitArea() { ofPolyline QuadSurface::getHitArea(){
ofPolyline line; ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y));
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y));
@ -162,11 +167,11 @@ ofPolyline QuadSurface::getHitArea() {
return line; return line;
} }
ofPolyline QuadSurface::getTextureHitArea() { ofPolyline QuadSurface::getTextureHitArea(){
ofPolyline line; ofPolyline line;
vector<ofVec2f>& texCoords = mesh.getTexCoords(); vector <ofVec2f> & texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for(int i = 0; i < texCoords.size(); i++){
line.addVertex(ofPoint(texCoords[i] * textureSize)); line.addVertex(ofPoint(texCoords[i] * textureSize));
} }
line.close(); line.close();
@ -174,14 +179,16 @@ ofPolyline QuadSurface::getTextureHitArea() {
return line; return line;
} }
vector<ofVec3f>& QuadSurface::getVertices() { vector <ofVec3f> & QuadSurface::getVertices(){
// return only joint vertices // return only joint vertices
return mesh.getVertices(); return mesh.getVertices();
} }
vector<ofVec2f>& QuadSurface::getTexCoords() { return mesh.getTexCoords(); } vector <ofVec2f> & QuadSurface::getTexCoords(){
return mesh.getTexCoords();
}
void QuadSurface::calculate4dTextureCoords() { void QuadSurface::calculate4dTextureCoords(){
// Perspective Warping with OpenGL Fixed Pipeline and q coordinates // Perspective Warping with OpenGL Fixed Pipeline and q coordinates
// see: // see:
// http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/ // http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/
@ -250,5 +257,6 @@ void QuadSurface::calculate4dTextureCoords() {
quadTexCoordinates[13] = t3.y * q3; quadTexCoordinates[13] = t3.y * q3;
quadTexCoordinates[15] = q3; quadTexCoordinates[15] = q3;
} }
}
} } // namespace piMapper
} // namespace ofx

13
src/Surfaces/QuadSurface.h

@ -6,6 +6,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class QuadSurface : public BaseSurface { class QuadSurface : public BaseSurface {
public: public:
QuadSurface(); QuadSurface();
@ -14,7 +15,7 @@ class QuadSurface : public BaseSurface {
void setup(); void setup();
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, ofVec2f t1, void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, ofVec2f t1,
ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource* newSource); ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource * newSource);
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, ofVec2f p);
@ -27,14 +28,16 @@ class QuadSurface : public BaseSurface {
ofVec2f getTexCoord(int index); ofVec2f getTexCoord(int index);
ofPolyline getHitArea(); ofPolyline getHitArea();
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
vector<ofVec3f>& getVertices(); vector <ofVec3f> & getVertices();
vector<ofVec2f>& getTexCoords(); vector <ofVec2f> & getTexCoords();
private: private:
void calculate4dTextureCoords(); void calculate4dTextureCoords();
GLfloat quadVertices[12]; GLfloat quadVertices[12];
GLubyte quadIndices[6]; GLubyte quadIndices[6];
GLfloat quadTexCoordinates[16]; GLfloat quadTexCoordinates[16];
}; };
}
} } // namespace piMapper
} // namespace ofx

179
src/Surfaces/SurfaceManager.cpp

@ -2,89 +2,92 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SurfaceManager::SurfaceManager() :
SurfaceManager::SurfaceManager() :
mediaServer(NULL), mediaServer(NULL),
selectedSurface(NULL) {} selectedSurface(NULL){}
SurfaceManager::~SurfaceManager() { clear(); } SurfaceManager::~SurfaceManager(){
clear();
}
void SurfaceManager::draw() { void SurfaceManager::draw(){
for (int i = 0; i < surfaces.size(); i++) { for(int i = 0; i < surfaces.size(); i++){
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
surfaces[i]->draw(); surfaces[i]->draw();
} }
} }
void SurfaceManager::addSurface(int surfaceType) { void SurfaceManager::addSurface(int surfaceType){
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if(surfaceType == SurfaceType::TRIANGLE_SURFACE){
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
} else if (surfaceType == SurfaceType::QUAD_SURFACE) { }else if(surfaceType == SurfaceType::QUAD_SURFACE){
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
} else { }else{
ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type"; ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} }
void SurfaceManager::addSurface(int surfaceType, BaseSource* newSource) { void SurfaceManager::addSurface(int surfaceType, BaseSource * newSource){
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if(surfaceType == SurfaceType::TRIANGLE_SURFACE){
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
surfaces.back()->setSource(newSource); surfaces.back()->setSource(newSource);
} else if (surfaceType == SurfaceType::QUAD_SURFACE) { }else if(surfaceType == SurfaceType::QUAD_SURFACE){
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
surfaces.back()->setSource(newSource); surfaces.back()->setSource(newSource);
} else { }else{
ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type"; ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} }
void SurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, void SurfaceManager::addSurface(int surfaceType, vector <ofVec2f> vertices,
vector<ofVec2f> texCoords) { vector <ofVec2f> texCoords){
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if(surfaceType == SurfaceType::TRIANGLE_SURFACE){
if (vertices.size() < 3) { if(vertices.size() < 3){
throw std::runtime_error( throw std::runtime_error(
"There must be 3 vertices for a triangle surface."); "There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) { }else if(texCoords.size() < 3){
throw std::runtime_error( throw std::runtime_error(
"There must be 3 texture coordinates for a triangle surface."); "There must be 3 texture coordinates for a triangle surface.");
} }
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
for (int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++){
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} else if (surfaceType == SurfaceType::QUAD_SURFACE) { }else if(surfaceType == SurfaceType::QUAD_SURFACE){
if (vertices.size() < 4) { if(vertices.size() < 4){
throw std::runtime_error("There must be 4 vertices for a quad surface."); throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) { }else if(texCoords.size() < 4){
throw std::runtime_error( throw std::runtime_error(
"There must be 4 texture coordinates for a quad surface."); "There must be 4 texture coordinates for a quad surface.");
} }
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
for (int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++){
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} else { }else{
ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type"; ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
} }
void SurfaceManager::addSurface(int surfaceType, BaseSource* newSource, void SurfaceManager::addSurface(int surfaceType, BaseSource * newSource,
vector<ofVec2f> vertices, vector <ofVec2f> vertices,
vector<ofVec2f> texCoords) { vector <ofVec2f> texCoords){
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if(surfaceType == SurfaceType::TRIANGLE_SURFACE){
if (vertices.size() < 3) { if(vertices.size() < 3){
throw std::runtime_error( throw std::runtime_error(
"There must be 3 vertices for a triangle surface."); "There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) { }else if(texCoords.size() < 3){
throw std::runtime_error( throw std::runtime_error(
"Thre must be 3 texture coordinates for a triangle surface."); "Thre must be 3 texture coordinates for a triangle surface.");
} }
@ -92,15 +95,15 @@ void SurfaceManager::addSurface(int surfaceType, BaseSource* newSource,
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
surfaces.back()->setSource(newSource); surfaces.back()->setSource(newSource);
for (int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++){
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} else if (surfaceType == SurfaceType::QUAD_SURFACE) { }else if(surfaceType == SurfaceType::QUAD_SURFACE){
if (vertices.size() < 4) { if(vertices.size() < 4){
throw std::runtime_error("There must be 4 vertices for a quad surface."); throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) { }else if(texCoords.size() < 4){
throw std::runtime_error( throw std::runtime_error(
"Thre must be 4 texture coordinates for a quad surface."); "Thre must be 4 texture coordinates for a quad surface.");
} }
@ -108,11 +111,11 @@ void SurfaceManager::addSurface(int surfaceType, BaseSource* newSource,
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
surfaces.back()->setSource(newSource); surfaces.back()->setSource(newSource);
for (int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++){
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} else { }else{
ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type"; ofLogFatalError("SurfaceManager") << "Attempt to add non-existing surface type";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
@ -124,11 +127,11 @@ void SurfaceManager::addSurface(BaseSurface * surface){
} }
void SurfaceManager::removeSelectedSurface(){ void SurfaceManager::removeSelectedSurface(){
if (selectedSurface == NULL){ if(selectedSurface == NULL){
return; return;
} }
for (int i = 0; i < surfaces.size(); i++){ for(int i = 0; i < surfaces.size(); i++){
if (surfaces[i] == selectedSurface){ if(surfaces[i] == selectedSurface){
// Do not delete pointer as we are storing the // Do not delete pointer as we are storing the
// surface in the RemoveSurfaceCommand. // surface in the RemoveSurfaceCommand.
//delete surfaces[i]; //delete surfaces[i];
@ -139,25 +142,25 @@ void SurfaceManager::removeSelectedSurface(){
} }
} }
void SurfaceManager::removeSurface() { void SurfaceManager::removeSurface(){
if (!surfaces.size()) { if(!surfaces.size()){
return; return;
} }
delete surfaces.back(); delete surfaces.back();
surfaces.pop_back(); surfaces.pop_back();
} }
void SurfaceManager::clear() { void SurfaceManager::clear(){
// delete all extra allocations from the heap // delete all extra allocations from the heap
while (surfaces.size()) { while(surfaces.size()){
delete surfaces.back(); delete surfaces.back();
surfaces.pop_back(); surfaces.pop_back();
} }
} }
void SurfaceManager::saveXmlSettings(string fileName) { void SurfaceManager::saveXmlSettings(string fileName){
// Exit if mediaServer not set // Exit if mediaServer not set
if (mediaServer == NULL) { if(mediaServer == NULL){
ofLogFatalError("SurfaceManager") << "Media server not set"; ofLogFatalError("SurfaceManager") << "Media server not set";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
@ -166,18 +169,18 @@ void SurfaceManager::saveXmlSettings(string fileName) {
// Save surfaces // Save surfaces
xmlSettings.addTag("surfaces"); xmlSettings.addTag("surfaces");
xmlSettings.pushTag("surfaces"); xmlSettings.pushTag("surfaces");
for (int i = 0; i < surfaces.size(); i++) { for(int i = 0; i < surfaces.size(); i++){
xmlSettings.addTag("surface"); xmlSettings.addTag("surface");
xmlSettings.pushTag("surface", i); xmlSettings.pushTag("surface", i);
BaseSurface* surface = surfaces[i]; BaseSurface * surface = surfaces[i];
xmlSettings.addTag("vertices"); xmlSettings.addTag("vertices");
xmlSettings.pushTag("vertices"); xmlSettings.pushTag("vertices");
vector<ofVec3f>* vertices = &surface->getVertices(); vector <ofVec3f> * vertices = &surface->getVertices();
for (int j = 0; j < vertices->size(); j++) { for(int j = 0; j < vertices->size(); j++){
xmlSettings.addTag("vertex"); xmlSettings.addTag("vertex");
xmlSettings.pushTag("vertex", j); xmlSettings.pushTag("vertex", j);
ofVec3f* vertex = &(*vertices)[j]; ofVec3f * vertex = &(*vertices)[j];
xmlSettings.addValue("x", vertex->x); xmlSettings.addValue("x", vertex->x);
xmlSettings.addValue("y", vertex->y); xmlSettings.addValue("y", vertex->y);
@ -189,11 +192,11 @@ void SurfaceManager::saveXmlSettings(string fileName) {
xmlSettings.addTag("texCoords"); xmlSettings.addTag("texCoords");
xmlSettings.pushTag("texCoords"); xmlSettings.pushTag("texCoords");
vector<ofVec2f>* texCoords = &surface->getTexCoords(); vector <ofVec2f> * texCoords = &surface->getTexCoords();
for (int j = 0; j < texCoords->size(); j++) { for(int j = 0; j < texCoords->size(); j++){
xmlSettings.addTag("texCoord"); xmlSettings.addTag("texCoord");
xmlSettings.pushTag("texCoord", j); xmlSettings.pushTag("texCoord", j);
ofVec2f* texCoord = &(*texCoords)[j]; ofVec2f * texCoord = &(*texCoords)[j];
xmlSettings.addValue("x", texCoord->x); xmlSettings.addValue("x", texCoord->x);
xmlSettings.addValue("y", texCoord->y); xmlSettings.addValue("y", texCoord->y);
xmlSettings.popTag(); // texCoord xmlSettings.popTag(); // texCoord
@ -212,17 +215,17 @@ void SurfaceManager::saveXmlSettings(string fileName) {
xmlSettings.save(fileName); xmlSettings.save(fileName);
} }
void SurfaceManager::loadXmlSettings(string fileName) { void SurfaceManager::loadXmlSettings(string fileName){
// Exit if there is no media server // Exit if there is no media server
if (mediaServer == NULL) { if(mediaServer == NULL){
ofLogFatalError("SurfaceManager") << "Media server not set"; ofLogFatalError("SurfaceManager") << "Media server not set";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }
if (!xmlSettings.loadFile(fileName)) { if(!xmlSettings.loadFile(fileName)){
ofLogWarning("SurfaceManager") << "Could not load XML settings"; ofLogWarning("SurfaceManager") << "Could not load XML settings";
return; return;
} }
if (!xmlSettings.tagExists("surfaces")) { if(!xmlSettings.tagExists("surfaces")){
ofLogWarning("SurfaceManager") << "XML settings is empty or has wrong markup"; ofLogWarning("SurfaceManager") << "XML settings is empty or has wrong markup";
return; return;
} }
@ -230,20 +233,20 @@ void SurfaceManager::loadXmlSettings(string fileName) {
xmlSettings.pushTag("surfaces"); xmlSettings.pushTag("surfaces");
int numSurfaces = xmlSettings.getNumTags("surface"); int numSurfaces = xmlSettings.getNumTags("surface");
for (int i = 0; i < numSurfaces; i++) { for(int i = 0; i < numSurfaces; i++){
xmlSettings.pushTag("surface", i); xmlSettings.pushTag("surface", i);
// attempt to load surface source // attempt to load surface source
xmlSettings.pushTag("source"); xmlSettings.pushTag("source");
string sourceType = xmlSettings.getValue("source-type", ""); string sourceType = xmlSettings.getValue("source-type", "");
string sourceName = xmlSettings.getValue("source-name", ""); string sourceName = xmlSettings.getValue("source-name", "");
BaseSource* source = NULL; BaseSource * source = NULL;
if (sourceName != "" && sourceName != "none" && sourceType != "") { if(sourceName != "" && sourceName != "none" && sourceType != ""){
// Load source depending on type // Load source depending on type
int typeEnum = SourceType::GetSourceTypeEnum(sourceType); int typeEnum = SourceType::GetSourceTypeEnum(sourceType);
if (typeEnum == SourceType::SOURCE_TYPE_FBO) { if(typeEnum == SourceType::SOURCE_TYPE_FBO){
// Load FBO source using sourceName // Load FBO source using sourceName
source = mediaServer->loadMedia(sourceName, typeEnum); source = mediaServer->loadMedia(sourceName, typeEnum);
} else { }else{
// Construct full path // Construct full path
string dir = mediaServer->getDefaultMediaDir(typeEnum); string dir = mediaServer->getDefaultMediaDir(typeEnum);
std::stringstream pathss; std::stringstream pathss;
@ -255,10 +258,10 @@ void SurfaceManager::loadXmlSettings(string fileName) {
} }
xmlSettings.popTag(); // source xmlSettings.popTag(); // source
xmlSettings.pushTag("vertices"); xmlSettings.pushTag("vertices");
vector<ofVec2f> vertices; vector <ofVec2f> vertices;
int vertexCount = xmlSettings.getNumTags("vertex"); int vertexCount = xmlSettings.getNumTags("vertex");
// it's a triangle ? // it's a triangle ?
if (vertexCount == 3) { if(vertexCount == 3){
//ofLog(OF_LOG_NOTICE, "create Triangle"); //ofLog(OF_LOG_NOTICE, "create Triangle");
xmlSettings.pushTag("vertex", 0); xmlSettings.pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f), vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
@ -279,7 +282,7 @@ void SurfaceManager::loadXmlSettings(string fileName) {
xmlSettings.pushTag("texCoords"); xmlSettings.pushTag("texCoords");
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
xmlSettings.pushTag("texCoord", 0); xmlSettings.pushTag("texCoord", 0);
texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f), texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
@ -300,17 +303,16 @@ void SurfaceManager::loadXmlSettings(string fileName) {
// now we have variables sourceName and sourceTexture // now we have variables sourceName and sourceTexture
// by checking those we can use one or another addSurface method // by checking those we can use one or another addSurface method
if (sourceName != "none" && source != NULL) { if(sourceName != "none" && source != NULL){
addSurface(SurfaceType::TRIANGLE_SURFACE, source, vertices, addSurface(SurfaceType::TRIANGLE_SURFACE, source, vertices,
texCoords); texCoords);
} else { }else{
addSurface(SurfaceType::TRIANGLE_SURFACE, vertices, texCoords); addSurface(SurfaceType::TRIANGLE_SURFACE, vertices, texCoords);
} }
} }
// it's a quad ? // it's a quad ?
else if (vertexCount == 4) else if(vertexCount == 4){
// if (surface-type == QUAD_SURFACE) // if (surface-type == QUAD_SURFACE)
{
xmlSettings.pushTag("vertex", 0); xmlSettings.pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f), vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 0.0f))); xmlSettings.getValue("y", 0.0f)));
@ -335,7 +337,7 @@ void SurfaceManager::loadXmlSettings(string fileName) {
xmlSettings.pushTag("texCoords"); xmlSettings.pushTag("texCoords");
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
xmlSettings.pushTag("texCoord", 0); xmlSettings.pushTag("texCoord", 0);
texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f), texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
@ -361,10 +363,10 @@ void SurfaceManager::loadXmlSettings(string fileName) {
// now we have variables sourceName and sourceTexture // now we have variables sourceName and sourceTexture
// by checking those we can use one or another addSurface method // by checking those we can use one or another addSurface method
if (sourceName != "none" && source != NULL) { if(sourceName != "none" && source != NULL){
addSurface(SurfaceType::QUAD_SURFACE, source, vertices, addSurface(SurfaceType::QUAD_SURFACE, source, vertices,
texCoords); texCoords);
} else { }else{
addSurface(SurfaceType::QUAD_SURFACE, vertices, texCoords); addSurface(SurfaceType::QUAD_SURFACE, vertices, texCoords);
} }
} }
@ -375,12 +377,12 @@ void SurfaceManager::loadXmlSettings(string fileName) {
xmlSettings.popTag(); // surfaces xmlSettings.popTag(); // surfaces
} }
void SurfaceManager::setMediaServer(MediaServer* newMediaServer) { void SurfaceManager::setMediaServer(MediaServer * newMediaServer){
mediaServer = newMediaServer; mediaServer = newMediaServer;
} }
BaseSurface * SurfaceManager::selectSurface(int index) { BaseSurface * SurfaceManager::selectSurface(int index){
if (index >= surfaces.size()) { if(index >= surfaces.size()){
throw std::runtime_error("Surface index out of bounds."); throw std::runtime_error("Surface index out of bounds.");
} }
selectedSurface = surfaces[index]; selectedSurface = surfaces[index];
@ -388,11 +390,11 @@ void SurfaceManager::loadXmlSettings(string fileName) {
// notify that a new surface has been selected // notify that a new surface has been selected
ofSendMessage("surfaceSelected"); ofSendMessage("surfaceSelected");
return selectedSurface; return selectedSurface;
} }
BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){ BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){
for (int i = 0; i < surfaces.size(); i++) { for(int i = 0; i < surfaces.size(); i++){
if (surfaces[i] == surface){ if(surfaces[i] == surface){
selectedSurface = surface; selectedSurface = surface;
ofSendMessage("surfaceSelected"); ofSendMessage("surfaceSelected");
return selectedSurface; return selectedSurface;
@ -400,18 +402,18 @@ void SurfaceManager::loadXmlSettings(string fileName) {
} }
deselectSurface(); deselectSurface();
return 0; return 0;
} }
BaseSurface* SurfaceManager::getSelectedSurface() { BaseSurface * SurfaceManager::getSelectedSurface(){
return selectedSurface; return selectedSurface;
} }
void SurfaceManager::deselectSurface() { void SurfaceManager::deselectSurface(){
selectedSurface = NULL; selectedSurface = NULL;
} }
BaseSurface* SurfaceManager::getSurface(int index) { BaseSurface * SurfaceManager::getSurface(int index){
if (index >= surfaces.size()) { if(index >= surfaces.size()){
throw std::runtime_error("Surface index out of bounds."); throw std::runtime_error("Surface index out of bounds.");
return NULL; return NULL;
} }
@ -419,6 +421,9 @@ BaseSurface* SurfaceManager::getSurface(int index) {
return surfaces[index]; return surfaces[index];
} }
int SurfaceManager::size() { return surfaces.size(); } int SurfaceManager::size(){
} return surfaces.size();
} }
} // namespace piMapper
} // namespace ofx

34
src/Surfaces/SurfaceManager.h

@ -15,7 +15,9 @@ using namespace std;
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SurfaceManager { class SurfaceManager {
public: public:
SurfaceManager(); SurfaceManager();
~SurfaceManager(); ~SurfaceManager();
@ -24,11 +26,11 @@ class SurfaceManager {
// TODO: These should be renamed to createSurface // TODO: These should be renamed to createSurface
void addSurface(int surfaceType); void addSurface(int surfaceType);
void addSurface(int surfaceType, BaseSource* newSource); void addSurface(int surfaceType, BaseSource * newSource);
void addSurface(int surfaceType, vector<ofVec2f> vertices, void addSurface(int surfaceType, vector <ofVec2f> vertices,
vector<ofVec2f> texCoords); vector <ofVec2f> texCoords);
void addSurface(int surfaceType, BaseSource* newSource, void addSurface(int surfaceType, BaseSource * newSource,
vector<ofVec2f> vertices, vector<ofVec2f> texCoords); vector <ofVec2f> vertices, vector <ofVec2f> texCoords);
// Except this, as it adds existing surface // Except this, as it adds existing surface
void addSurface(BaseSurface * surface); void addSurface(BaseSurface * surface);
@ -39,20 +41,22 @@ class SurfaceManager {
void clear(); void clear();
void saveXmlSettings(string fileName); void saveXmlSettings(string fileName);
void loadXmlSettings(string fileName); void loadXmlSettings(string fileName);
void setMediaServer(MediaServer* newMediaServer); void setMediaServer(MediaServer * newMediaServer);
BaseSurface* getSurface(int index); BaseSurface * getSurface(int index);
int size(); int size();
BaseSurface* selectSurface(int index); BaseSurface * selectSurface(int index);
BaseSurface* selectSurface(BaseSurface * surface); BaseSurface * selectSurface(BaseSurface * surface);
BaseSurface* getSelectedSurface(); BaseSurface * getSelectedSurface();
void deselectSurface(); void deselectSurface();
private: private:
std::vector<BaseSurface*> surfaces; std::vector <BaseSurface *> surfaces;
BaseSurface* selectedSurface; BaseSurface * selectedSurface;
ofxXmlSettings xmlSettings; ofxXmlSettings xmlSettings;
MediaServer* mediaServer; MediaServer * mediaServer;
}; };
}
} } // namespace piMapper
} // namespace ofx

175
src/Surfaces/SurfaceManagerGui.cpp

@ -1,48 +1,51 @@
#include "SurfaceManagerGui.h" #include "SurfaceManagerGui.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SurfaceManagerGui::SurfaceManagerGui() {
SurfaceManagerGui::SurfaceManagerGui(){
surfaceManager = NULL; surfaceManager = NULL;
guiMode = GuiMode::NONE; guiMode = GuiMode::NONE;
bDrag = false; bDrag = false;
registerMouseEvents(); registerMouseEvents();
ofHideCursor(); ofHideCursor();
_cmdManager = 0; _cmdManager = 0;
} }
SurfaceManagerGui::~SurfaceManagerGui() { SurfaceManagerGui::~SurfaceManagerGui(){
unregisterMouseEvents(); unregisterMouseEvents();
surfaceManager = NULL; surfaceManager = NULL;
_cmdManager = 0; _cmdManager = 0;
} }
void SurfaceManagerGui::registerMouseEvents() { void SurfaceManagerGui::registerMouseEvents(){
ofAddListener(ofEvents().mousePressed, this, ofAddListener(ofEvents().mousePressed, this,
&SurfaceManagerGui::mousePressed); &SurfaceManagerGui::mousePressed);
ofAddListener(ofEvents().mouseReleased, this, ofAddListener(ofEvents().mouseReleased, this,
&SurfaceManagerGui::mouseReleased); &SurfaceManagerGui::mouseReleased);
ofAddListener(ofEvents().mouseDragged, this, ofAddListener(ofEvents().mouseDragged, this,
&SurfaceManagerGui::mouseDragged); &SurfaceManagerGui::mouseDragged);
} }
void SurfaceManagerGui::unregisterMouseEvents() { void SurfaceManagerGui::unregisterMouseEvents(){
ofRemoveListener(ofEvents().mousePressed, this, ofRemoveListener(ofEvents().mousePressed, this,
&SurfaceManagerGui::mousePressed); &SurfaceManagerGui::mousePressed);
ofRemoveListener(ofEvents().mouseReleased, this, ofRemoveListener(ofEvents().mouseReleased, this,
&SurfaceManagerGui::mouseReleased); &SurfaceManagerGui::mouseReleased);
ofRemoveListener(ofEvents().mouseDragged, this, ofRemoveListener(ofEvents().mouseDragged, this,
&SurfaceManagerGui::mouseDragged); &SurfaceManagerGui::mouseDragged);
} }
void SurfaceManagerGui::draw() { void SurfaceManagerGui::draw(){
if (surfaceManager == NULL) return; if(surfaceManager == NULL){
return;
}
if (guiMode == GuiMode::NONE) { if(guiMode == GuiMode::NONE){
surfaceManager->draw(); surfaceManager->draw();
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { }else if(guiMode == GuiMode::TEXTURE_MAPPING){
// draw the texture of the selected surface // draw the texture of the selected surface
if (surfaceManager->getSelectedSurface() != NULL) { if(surfaceManager->getSelectedSurface() != NULL){
// Reset default color to white first // Reset default color to white first
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0));
@ -63,7 +66,7 @@ namespace ofx {
// draw texture editing GUI on top // draw texture editing GUI on top
textureEditor.draw(); textureEditor.draw();
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { }else if(guiMode == GuiMode::PROJECTION_MAPPING){
// draw projection surfaces first // draw projection surfaces first
surfaceManager->draw(); surfaceManager->draw();
@ -73,7 +76,7 @@ namespace ofx {
// draw projection mapping editing gui // draw projection mapping editing gui
projectionEditor.draw(); projectionEditor.draw();
} else if (guiMode == GuiMode::SOURCE_SELECTION) { }else if(guiMode == GuiMode::SOURCE_SELECTION){
// draw projection surfaces first // draw projection surfaces first
surfaceManager->draw(); surfaceManager->draw();
@ -82,16 +85,16 @@ namespace ofx {
sourcesEditor.draw(); sourcesEditor.draw();
} }
} }
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){
if (guiMode == GuiMode::NONE) { if(guiMode == GuiMode::NONE){
return; return;
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { }else if(guiMode == GuiMode::TEXTURE_MAPPING){
bool bSurfaceSelected = false; bool bSurfaceSelected = false;
CircleJoint* hitJoint = CircleJoint * hitJoint =
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); textureEditor.hitTestJoints(ofVec2f(args.x, args.y));
if (hitJoint != NULL) { if(hitJoint != NULL){
textureEditor.unselectAllJoints(); textureEditor.unselectAllJoints();
hitJoint->select(); hitJoint->select();
@ -99,25 +102,25 @@ namespace ofx {
bSurfaceSelected = true; bSurfaceSelected = true;
int jointIndex = -1; int jointIndex = -1;
for (int i = 0; i < textureEditor.getJoints().size(); i++) { for(int i = 0; i < textureEditor.getJoints().size(); i++){
if (textureEditor.getJoints()[i] == hitJoint) { if(textureEditor.getJoints()[i] == hitJoint){
jointIndex = i; jointIndex = i;
break; break;
} }
} }
if (jointIndex != -1) { if(jointIndex != -1){
_cmdManager->exec(new MvTexCoordCmd(jointIndex, &textureEditor)); _cmdManager->exec(new MvTexCoordCmd(jointIndex, &textureEditor));
} }
} else { }else{
textureEditor.unselectAllJoints(); textureEditor.unselectAllJoints();
} }
if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { if(surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected){
// hittest texture area to see if we are hitting the texture surface // hittest texture area to see if we are hitting the texture surface
if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside( if(surfaceManager->getSelectedSurface()->getTextureHitArea().inside(
args.x, args.y)) { args.x, args.y)){
// TODO: move these to a separate routine // TODO: move these to a separate routine
clickPosition = ofVec2f(args.x, args.y); clickPosition = ofVec2f(args.x, args.y);
@ -130,18 +133,18 @@ namespace ofx {
} }
} }
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { }else if(guiMode == GuiMode::PROJECTION_MAPPING){
bool bSurfaceSelected = false; bool bSurfaceSelected = false;
CircleJoint* hitJoint = CircleJoint * hitJoint =
projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); projectionEditor.hitTestJoints(ofVec2f(args.x, args.y));
if (hitJoint != NULL) { if(hitJoint != NULL){
projectionEditor.unselectAllJoints(); projectionEditor.unselectAllJoints();
hitJoint->select(); hitJoint->select();
hitJoint->startDrag(); hitJoint->startDrag();
int jointVertIndex = 0; int jointVertIndex = 0;
for (int i = 0; i < projectionEditor.getJoints()->size(); i++) { for(int i = 0; i < projectionEditor.getJoints()->size(); i++){
if ((*projectionEditor.getJoints())[i] == hitJoint) { if((*projectionEditor.getJoints())[i] == hitJoint){
jointVertIndex = i; jointVertIndex = i;
break; break;
} }
@ -154,13 +157,13 @@ namespace ofx {
} }
// attempt to select surface, loop from end to beginning // attempt to select surface, loop from end to beginning
if (!bSurfaceSelected) { if(!bSurfaceSelected){
for (int i = surfaceManager->size() - 1; i >= 0; i--) { for(int i = surfaceManager->size() - 1; i >= 0; i--){
if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) { if(surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))){
// Do not repeat this command if attempting to select an // Do not repeat this command if attempting to select an
// already selected surface. // already selected surface.
if (surfaceManager->getSelectedSurface() != surfaceManager->getSurface(i)){ if(surfaceManager->getSelectedSurface() != surfaceManager->getSurface(i)){
_cmdManager->exec(new SelSurfaceCmd( _cmdManager->exec(new SelSurfaceCmd(
surfaceManager, surfaceManager,
surfaceManager->getSurface(i), surfaceManager->getSurface(i),
@ -173,7 +176,7 @@ namespace ofx {
} }
} }
if (bSurfaceSelected && hitJoint == NULL) { if(bSurfaceSelected && hitJoint == NULL){
// if not hitting the joints, start drag only if // if not hitting the joints, start drag only if
// we have a selected surface // we have a selected surface
@ -186,126 +189,134 @@ namespace ofx {
&projectionEditor)); &projectionEditor));
} }
if (!bSurfaceSelected) { if(!bSurfaceSelected){
// unselect if no surface selected // unselect if no surface selected
projectionEditor.clearJoints(); projectionEditor.clearJoints();
surfaceManager->deselectSurface(); surfaceManager->deselectSurface();
} }
} else if (guiMode == GuiMode::SOURCE_SELECTION) { }else if(guiMode == GuiMode::SOURCE_SELECTION){}
} }
}
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { void SurfaceManagerGui::mouseReleased(ofMouseEventArgs & args){
stopDrag(); stopDrag();
projectionEditor.stopDragJoints(); projectionEditor.stopDragJoints();
textureEditor.stopDragJoints(); textureEditor.stopDragJoints();
// Check if surface has moved // Check if surface has moved
if (surfaceManager->getSelectedSurface()){ if(surfaceManager->getSelectedSurface()){
if (!surfaceManager->getSelectedSurface()->getMoved()) { if(!surfaceManager->getSelectedSurface()->getMoved()){
_cmdManager->undo(); _cmdManager->undo();
} }
} }
} }
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { void SurfaceManagerGui::mouseDragged(ofMouseEventArgs & args){
if (bDrag) { if(bDrag){
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
ofVec2f distance = mousePosition - clickPosition; ofVec2f distance = mousePosition - clickPosition;
if (guiMode == GuiMode::PROJECTION_MAPPING) { if(guiMode == GuiMode::PROJECTION_MAPPING){
// add this distance to all vertices in surface // add this distance to all vertices in surface
projectionEditor.moveSelectedSurface(distance); projectionEditor.moveSelectedSurface(distance);
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { }else if(guiMode == GuiMode::TEXTURE_MAPPING){
textureEditor.moveTexCoords(distance); textureEditor.moveTexCoords(distance);
} }
clickPosition = mousePosition; clickPosition = mousePosition;
} }
} }
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { void SurfaceManagerGui::setSurfaceManager(SurfaceManager * newSurfaceManager){
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
projectionEditor.setSurfaceManager(surfaceManager); projectionEditor.setSurfaceManager(surfaceManager);
sourcesEditor.setSurfaceManager(surfaceManager); sourcesEditor.setSurfaceManager(surfaceManager);
} }
// Set external media server so we can access it from wherever we need // Set external media server so we can access it from wherever we need
void SurfaceManagerGui::setMediaServer(MediaServer* newMediaServer) { void SurfaceManagerGui::setMediaServer(MediaServer * newMediaServer){
mediaServer = newMediaServer; mediaServer = newMediaServer;
// Set the media server of the sources editor here // Set the media server of the sources editor here
sourcesEditor.setMediaServer(mediaServer); sourcesEditor.setMediaServer(mediaServer);
} }
void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){ void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){
_cmdManager = cmdManager; _cmdManager = cmdManager;
sourcesEditor.setCmdManager(_cmdManager); sourcesEditor.setCmdManager(_cmdManager);
} }
void SurfaceManagerGui::setMode(int newGuiMode) { void SurfaceManagerGui::setMode(int newGuiMode){
if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && if(newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING &&
newGuiMode != GuiMode::PROJECTION_MAPPING && newGuiMode != GuiMode::PROJECTION_MAPPING &&
newGuiMode != GuiMode::SOURCE_SELECTION) { newGuiMode != GuiMode::SOURCE_SELECTION){
throw std::runtime_error("Trying to set invalid mode."); throw std::runtime_error("Trying to set invalid mode.");
} }
if (newGuiMode == GuiMode::NONE) { if(newGuiMode == GuiMode::NONE){
ofHideCursor(); ofHideCursor();
} else { }else{
ofShowCursor(); ofShowCursor();
} }
guiMode = newGuiMode; guiMode = newGuiMode;
if (guiMode == GuiMode::SOURCE_SELECTION) { if(guiMode == GuiMode::SOURCE_SELECTION){
sourcesEditor.enable(); sourcesEditor.enable();
//string sourceName = surfaceManager->getSelectedSurfaceSourceName(); //string sourceName = surfaceManager->getSelectedSurfaceSourceName();
//sourcesEditor.selectImageSourceRadioButton(sourceName); //sourcesEditor.selectImageSourceRadioButton(sourceName);
} else { }else{
sourcesEditor.disable(); sourcesEditor.disable();
} }
if (guiMode == GuiMode::TEXTURE_MAPPING) { if(guiMode == GuiMode::TEXTURE_MAPPING){
textureEditor.enable(); textureEditor.enable();
// refresh texture editor surface reference // refresh texture editor surface reference
textureEditor.setSurface(surfaceManager->getSelectedSurface()); textureEditor.setSurface(surfaceManager->getSelectedSurface());
} else { }else{
textureEditor.disable(); textureEditor.disable();
} }
if (guiMode == GuiMode::PROJECTION_MAPPING) { if(guiMode == GuiMode::PROJECTION_MAPPING){
projectionEditor.enable(); projectionEditor.enable();
} else { }else{
projectionEditor.disable(); projectionEditor.disable();
} }
} }
int SurfaceManagerGui::getMode(){ int SurfaceManagerGui::getMode(){
return guiMode; return guiMode;
} }
void SurfaceManagerGui::drawSelectedSurfaceHighlight() { void SurfaceManagerGui::drawSelectedSurfaceHighlight(){
if (surfaceManager->getSelectedSurface() == NULL) return; if(surfaceManager->getSelectedSurface() == NULL){
return;
}
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea();
ofPushStyle(); ofPushStyle();
ofSetLineWidth(1); ofSetLineWidth(1);
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
line.draw(); line.draw();
ofPopStyle(); ofPopStyle();
} }
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() { void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight(){
if (surfaceManager->getSelectedSurface() == NULL) return; if(surfaceManager->getSelectedSurface() == NULL){
return;
}
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea();
ofPushStyle(); ofPushStyle();
ofSetLineWidth(1); ofSetLineWidth(1);
ofSetColor(255, 255, 0, 255); ofSetColor(255, 255, 0, 255);
line.draw(); line.draw();
ofPopStyle(); ofPopStyle();
} }
void SurfaceManagerGui::startDrag() { bDrag = true; } void SurfaceManagerGui::startDrag(){
bDrag = true;
}
void SurfaceManagerGui::stopDrag() { bDrag = false; } void SurfaceManagerGui::stopDrag(){
} bDrag = false;
} }
} // namespace piMapper
} // namespace ofx

28
src/Surfaces/SurfaceManagerGui.h

@ -18,8 +18,10 @@
#include "MvTexCoordCmd.h" #include "MvTexCoordCmd.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SurfaceManagerGui {
class SurfaceManagerGui {
public: public:
SurfaceManagerGui(); SurfaceManagerGui();
~SurfaceManagerGui(); ~SurfaceManagerGui();
@ -28,12 +30,12 @@ namespace ofx {
void unregisterMouseEvents(); void unregisterMouseEvents();
void draw(); void draw();
void mousePressed(ofMouseEventArgs& args); void mousePressed(ofMouseEventArgs & args);
void mouseReleased(ofMouseEventArgs& args); void mouseReleased(ofMouseEventArgs & args);
void mouseDragged(ofMouseEventArgs& args); void mouseDragged(ofMouseEventArgs & args);
void setSurfaceManager(SurfaceManager* newSurfaceManager); void setSurfaceManager(SurfaceManager * newSurfaceManager);
void setMediaServer(MediaServer* newMediaServer); void setMediaServer(MediaServer * newMediaServer);
void setCmdManager(CmdManager * cmdManager); void setCmdManager(CmdManager * cmdManager);
void setMode(int newGuiMode); void setMode(int newGuiMode);
@ -44,8 +46,8 @@ namespace ofx {
void stopDrag(); void stopDrag();
private: private:
SurfaceManager* surfaceManager; SurfaceManager * surfaceManager;
MediaServer* mediaServer; MediaServer * mediaServer;
TextureEditor textureEditor; TextureEditor textureEditor;
ProjectionEditor projectionEditor; ProjectionEditor projectionEditor;
SourcesEditor sourcesEditor; SourcesEditor sourcesEditor;
@ -53,6 +55,8 @@ namespace ofx {
bool bDrag; bool bDrag;
ofVec2f clickPosition; ofVec2f clickPosition;
CmdManager * _cmdManager; CmdManager * _cmdManager;
};
} };
}
} // namespace piMapper
} // namespace ofx

14
src/Surfaces/SurfaceType.h

@ -1,9 +1,13 @@
#pragma once #pragma once
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct SurfaceType {
enum { TRIANGLE_SURFACE, QUAD_SURFACE }; struct SurfaceType {
enum {
TRIANGLE_SURFACE, QUAD_SURFACE
}; };
} };
}
} // namespace piMapper
} // namespace ofx

62
src/Surfaces/TriangleSurface.cpp

@ -2,13 +2,14 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TriangleSurface::TriangleSurface() {
TriangleSurface::TriangleSurface(){
setup(); setup();
} }
TriangleSurface::~TriangleSurface() {} TriangleSurface::~TriangleSurface(){}
void TriangleSurface::setup() { void TriangleSurface::setup(){
// Create 3 points for the triangle // Create 3 points for the triangle
ofVec2f p1 = ofVec2f(ofGetWidth() / 2.0f, 0); ofVec2f p1 = ofVec2f(ofGetWidth() / 2.0f, 0);
ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight()));
@ -23,7 +24,7 @@ void TriangleSurface::setup() {
} }
void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1,
ofVec2f t2, ofVec2f t3, BaseSource* newSource) { ofVec2f t2, ofVec2f t3, BaseSource * newSource){
// Assign texture // Assign texture
source = newSource; source = newSource;
@ -41,8 +42,8 @@ void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1,
mesh.addTexCoord(t3); mesh.addTexCoord(t3);
} }
void TriangleSurface::draw() { void TriangleSurface::draw(){
if (source->getTexture() == NULL) { if(source->getTexture() == NULL){
ofLogWarning("TriangleSurface") << "Source texture is empty. Not drawing."; ofLogWarning("TriangleSurface") << "Source texture is empty. Not drawing.";
return; return;
} }
@ -52,8 +53,8 @@ void TriangleSurface::draw() {
source->getTexture()->unbind(); source->getTexture()->unbind();
} }
void TriangleSurface::setVertex(int index, ofVec2f p) { void TriangleSurface::setVertex(int index, ofVec2f p){
if (index > 2) { if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
return; return;
} }
@ -61,8 +62,8 @@ void TriangleSurface::setVertex(int index, ofVec2f p) {
mesh.setVertex(index, p); mesh.setVertex(index, p);
} }
void TriangleSurface::setTexCoord(int index, ofVec2f t) { void TriangleSurface::setTexCoord(int index, ofVec2f t){
if (index > 2) { if(index > 2){
ofLog() << "Texture coordinate with this index does not exist: " << index ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl; << endl;
return; return;
@ -71,29 +72,31 @@ void TriangleSurface::setTexCoord(int index, ofVec2f t) {
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t);
} }
void TriangleSurface::moveBy(ofVec2f v) { void TriangleSurface::moveBy(ofVec2f v){
vector<ofVec3f>& vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for (int i = 0; i < vertices.size(); i++) { for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v;
} }
setMoved(true); setMoved(true);
} }
int TriangleSurface::getType() { return SurfaceType::TRIANGLE_SURFACE; } int TriangleSurface::getType(){
return SurfaceType::TRIANGLE_SURFACE;
}
bool TriangleSurface::hitTest(ofVec2f p) { bool TriangleSurface::hitTest(ofVec2f p){
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
if (line.inside(p.x, p.y)) { if(line.inside(p.x, p.y)){
return true; return true;
} else { }else{
return false; return false;
} }
} }
ofVec2f TriangleSurface::getVertex(int index) { ofVec2f TriangleSurface::getVertex(int index){
if (index > 2) { if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
throw std::runtime_error("Vertex index out of bounds."); throw std::runtime_error("Vertex index out of bounds.");
} }
@ -102,15 +105,15 @@ ofVec2f TriangleSurface::getVertex(int index) {
return ofVec2f(vert.x, vert.y); return ofVec2f(vert.x, vert.y);
} }
ofVec2f TriangleSurface::getTexCoord(int index) { ofVec2f TriangleSurface::getTexCoord(int index){
if (index > 2) { if(index > 2){
throw std::runtime_error("Texture coordinate index out of bounds."); throw std::runtime_error("Texture coordinate index out of bounds.");
} }
return mesh.getTexCoord(index); return mesh.getTexCoord(index);
} }
ofPolyline TriangleSurface::getHitArea() { ofPolyline TriangleSurface::getHitArea(){
ofPolyline line; ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y));
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y));
@ -120,11 +123,11 @@ ofPolyline TriangleSurface::getHitArea() {
return line; return line;
} }
ofPolyline TriangleSurface::getTextureHitArea() { ofPolyline TriangleSurface::getTextureHitArea(){
ofPolyline line; ofPolyline line;
vector<ofVec2f>& texCoords = mesh.getTexCoords(); vector <ofVec2f> & texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for(int i = 0; i < texCoords.size(); i++){
line.addVertex(ofPoint(texCoords[i] * textureSize)); line.addVertex(ofPoint(texCoords[i] * textureSize));
} }
line.close(); line.close();
@ -132,11 +135,14 @@ ofPolyline TriangleSurface::getTextureHitArea() {
return line; return line;
} }
vector<ofVec3f>& TriangleSurface::getVertices() { vector <ofVec3f> & TriangleSurface::getVertices(){
// return only joint vertices // return only joint vertices
return mesh.getVertices(); return mesh.getVertices();
} }
vector<ofVec2f>& TriangleSurface::getTexCoords() { return mesh.getTexCoords(); } vector <ofVec2f> & TriangleSurface::getTexCoords(){
} return mesh.getTexCoords();
} }
} // namespace piMapper
} // namespace ofx

12
src/Surfaces/TriangleSurface.h

@ -6,6 +6,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TriangleSurface : public BaseSurface { class TriangleSurface : public BaseSurface {
public: public:
TriangleSurface(); TriangleSurface();
@ -13,7 +14,7 @@ class TriangleSurface : public BaseSurface {
void setup(); void setup();
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2,
ofVec2f t3, BaseSource* newSource); ofVec2f t3, BaseSource * newSource);
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, ofVec2f p);
void setTexCoord(int index, ofVec2f t); void setTexCoord(int index, ofVec2f t);
@ -25,8 +26,9 @@ class TriangleSurface : public BaseSurface {
ofVec2f getTexCoord(int index); ofVec2f getTexCoord(int index);
ofPolyline getHitArea(); ofPolyline getHitArea();
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
vector<ofVec3f>& getVertices(); vector <ofVec3f> & getVertices();
vector<ofVec2f>& getTexCoords(); vector <ofVec2f> & getTexCoords();
}; };
}
} } // namespace piMapper
} // namespace ofx

59
src/UserInterface/BaseJoint.cpp

@ -3,63 +3,81 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
BaseJoint::BaseJoint() { BaseJoint::BaseJoint(){
setDefaultColors(); setDefaultColors();
setDefaultProperties(); setDefaultProperties();
registerMouseEvents(); registerMouseEvents();
} }
BaseJoint::~BaseJoint() { unregisterMouseEvents(); } BaseJoint::~BaseJoint(){
unregisterMouseEvents();
}
void BaseJoint::registerMouseEvents() { void BaseJoint::registerMouseEvents(){
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::unregisterMouseEvents() { void BaseJoint::unregisterMouseEvents(){
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::mousePressed(ofMouseEventArgs& args) { void BaseJoint::mousePressed(ofMouseEventArgs & args){
if (hitTest(ofVec2f(args.x, args.y))) { if(hitTest(ofVec2f(args.x, args.y))){
// selected = true; // selected = true;
clickDistance = position - ofVec2f(args.x, args.y); clickDistance = position - ofVec2f(args.x, args.y);
// startDrag(); // startDrag();
} }
} }
void BaseJoint::mouseReleased(int x, int y, int button) { stopDrag(); } void BaseJoint::mouseReleased(int x, int y, int button){
stopDrag();
}
void BaseJoint::mouseDragged(ofMouseEventArgs& args) { void BaseJoint::mouseDragged(ofMouseEventArgs & args){
if (!bDrag) return; if(!bDrag){
return;
}
position = ofVec2f(args.x, args.y) + clickDistance; position = ofVec2f(args.x, args.y) + clickDistance;
} }
void BaseJoint::startDrag() { bDrag = true; } void BaseJoint::startDrag(){
bDrag = true;
}
void BaseJoint::stopDrag() { bDrag = false; } void BaseJoint::stopDrag(){
bDrag = false;
}
void BaseJoint::select() { selected = true; } void BaseJoint::select(){
selected = true;
}
void BaseJoint::unselect() { selected = false; } void BaseJoint::unselect(){
selected = false;
}
void BaseJoint::setClickDistance(ofVec2f newClickDistance) { void BaseJoint::setClickDistance(ofVec2f newClickDistance){
clickDistance = newClickDistance; clickDistance = newClickDistance;
} }
bool BaseJoint::isDragged() { return bDrag; } bool BaseJoint::isDragged(){
return bDrag;
}
bool BaseJoint::isSelected() { return selected; } bool BaseJoint::isSelected(){
return selected;
}
void BaseJoint::setDefaultColors() { void BaseJoint::setDefaultColors(){
fillColor = ofColor(0, 255, 255, 0); fillColor = ofColor(0, 255, 255, 0);
strokeColor = ofColor(255, 255, 255); strokeColor = ofColor(255, 255, 255);
fillColorSelected = ofColor(255, 255, 0, 0); fillColorSelected = ofColor(255, 255, 0, 0);
strokeColorSelected = ofColor(255, 0, 0); strokeColorSelected = ofColor(255, 0, 0);
} }
void BaseJoint::setDefaultProperties() { void BaseJoint::setDefaultProperties(){
enabled = true; enabled = true;
visible = true; visible = true;
position = ofVec2f(20.0f, 20.0f); position = ofVec2f(20.0f, 20.0f);
@ -68,5 +86,6 @@ void BaseJoint::setDefaultProperties() {
selected = false; selected = false;
strokeWidth = 1.5f; strokeWidth = 1.5f;
} }
}
} } // namespace piMapper
} // namespace ofx

17
src/UserInterface/BaseJoint.h

@ -6,6 +6,7 @@ namespace ofx {
namespace piMapper { namespace piMapper {
class BaseJoint { class BaseJoint {
public: public:
BaseJoint(); BaseJoint();
~BaseJoint(); ~BaseJoint();
@ -18,9 +19,9 @@ class BaseJoint {
bool visible; bool visible;
bool selected; bool selected;
void mousePressed(ofMouseEventArgs& args); void mousePressed(ofMouseEventArgs & args);
void mouseReleased(int x, int y, int button); void mouseReleased(int x, int y, int button);
void mouseDragged(ofMouseEventArgs& args); void mouseDragged(ofMouseEventArgs & args);
void startDrag(); void startDrag();
void stopDrag(); void stopDrag();
void select(); void select();
@ -29,9 +30,9 @@ class BaseJoint {
bool isDragged(); bool isDragged();
bool isSelected(); bool isSelected();
virtual void update() {}; virtual void update(){}
virtual void draw() {}; virtual void draw(){}
virtual bool hitTest(ofVec2f position) {}; virtual bool hitTest(ofVec2f position){}
protected: protected:
ofColor fillColor; ofColor fillColor;
@ -46,6 +47,8 @@ class BaseJoint {
private: private:
void setDefaultColors(); void setDefaultColors();
void setDefaultProperties(); void setDefaultProperties();
}; };
}
} } // namespace piMapper
} // namespace ofx

44
src/UserInterface/CircleJoint.cpp

@ -3,31 +3,39 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
CircleJoint::CircleJoint() { setDefaultProperties(); } CircleJoint::CircleJoint(){
setDefaultProperties();
}
void CircleJoint::update() { void CircleJoint::update(){
if (!enabled) return; if(!enabled){
return;
}
} }
void CircleJoint::draw() { void CircleJoint::draw(){
if (!visible) return; if(!visible){
if (!enabled) return; return;
}
if(!enabled){
return;
}
ofPushStyle(); ofPushStyle();
ofFill(); ofFill();
if (selected) { if(selected){
ofSetColor(fillColorSelected); ofSetColor(fillColorSelected);
} else { }else{
ofSetColor(fillColor); ofSetColor(fillColor);
} }
ofCircle(position.x, position.y, radius); ofCircle(position.x, position.y, radius);
ofNoFill(); ofNoFill();
if (selected) { if(selected){
ofSetColor(strokeColorSelected); ofSetColor(strokeColorSelected);
} else { }else{
ofSetColor(strokeColor); ofSetColor(strokeColor);
} }
@ -36,14 +44,18 @@ void CircleJoint::draw() {
ofPopStyle(); ofPopStyle();
} }
void CircleJoint::setDefaultProperties() { radius = 10.0f; } void CircleJoint::setDefaultProperties(){
radius = 10.0f;
}
bool CircleJoint::hitTest(ofVec2f pos) { bool CircleJoint::hitTest(ofVec2f pos){
float distance = position.distance(pos); float distance = position.distance(pos);
if (distance < radius) if(distance < radius){
return true; return true;
else }else{
return false; return false;
}
} }
}
} } // namespace piMapper
} // namespace ofx

7
src/UserInterface/CircleJoint.h

@ -6,6 +6,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class CircleJoint : public BaseJoint { class CircleJoint : public BaseJoint {
public: public:
CircleJoint(); CircleJoint();
@ -17,6 +18,8 @@ class CircleJoint : public BaseJoint {
float radius; float radius;
void setDefaultProperties(); void setDefaultProperties();
}; };
}
} } // namespace piMapper
} // namespace ofx

10
src/UserInterface/EditorType.h

@ -2,8 +2,12 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct EditorType { struct EditorType {
enum { TEXTURE, PROJECTION }; enum {
TEXTURE, PROJECTION
};
}; };
}
} } // namespace piMapper
} // namespace ofx

10
src/UserInterface/GuiMode.h

@ -2,8 +2,12 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct GuiMode { struct GuiMode {
enum { NONE, TEXTURE_MAPPING, PROJECTION_MAPPING, SOURCE_SELECTION }; enum {
NONE, TEXTURE_MAPPING, PROJECTION_MAPPING, SOURCE_SELECTION
};
}; };
}
} } // namespace piMapper
} // namespace ofx

217
src/UserInterface/ProjectionEditor.cpp

@ -1,71 +1,72 @@
#include "ProjectionEditor.h" #include "ProjectionEditor.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
ProjectionEditor::ProjectionEditor() {
ProjectionEditor::ProjectionEditor(){
surfaceManager = NULL; surfaceManager = NULL;
bShiftKeyDown = false; bShiftKeyDown = false;
fSnapDistance = 10.0f; fSnapDistance = 10.0f;
enable(); enable();
} }
ProjectionEditor::~ProjectionEditor() { ProjectionEditor::~ProjectionEditor(){
clearJoints(); clearJoints();
surfaceManager = NULL; surfaceManager = NULL;
disable(); disable();
} }
void ProjectionEditor::registerAppEvents() { void ProjectionEditor::registerAppEvents(){
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); ofAddListener(ofEvents().update, this, &ProjectionEditor::update);
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage);
} }
void ProjectionEditor::unregisterAppEvents() { void ProjectionEditor::unregisterAppEvents(){
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update);
ofRemoveListener(ofEvents().messageEvent, this, ofRemoveListener(ofEvents().messageEvent, this,
&ProjectionEditor::gotMessage); &ProjectionEditor::gotMessage);
} }
void ProjectionEditor::registerMouseEvents() { void ProjectionEditor::registerMouseEvents(){
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged);
} }
void ProjectionEditor::unregisterMouseEvents() { void ProjectionEditor::unregisterMouseEvents(){
ofRemoveListener(ofEvents().mouseDragged, this, ofRemoveListener(ofEvents().mouseDragged, this,
&ProjectionEditor::mouseDragged); &ProjectionEditor::mouseDragged);
} }
void ProjectionEditor::registerKeyEvents() { void ProjectionEditor::registerKeyEvents(){
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed);
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased);
} }
void ProjectionEditor::unregisterKeyEvents() { void ProjectionEditor::unregisterKeyEvents(){
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed);
ofRemoveListener(ofEvents().keyReleased, this, ofRemoveListener(ofEvents().keyReleased, this,
&ProjectionEditor::keyReleased); &ProjectionEditor::keyReleased);
} }
void ProjectionEditor::enable() { void ProjectionEditor::enable(){
registerAppEvents(); registerAppEvents();
registerMouseEvents(); registerMouseEvents();
registerKeyEvents(); registerKeyEvents();
} }
void ProjectionEditor::disable() { void ProjectionEditor::disable(){
unregisterAppEvents(); unregisterAppEvents();
unregisterMouseEvents(); unregisterMouseEvents();
unregisterKeyEvents(); unregisterKeyEvents();
} }
void ProjectionEditor::update(ofEventArgs& args) { void ProjectionEditor::update(ofEventArgs & args){
// update surface if one of the joints is being dragged // update surface if one of the joints is being dragged
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->isDragged() || joints[i]->isSelected()) { if(joints[i]->isDragged() || joints[i]->isSelected()){
if (surfaceManager->getSelectedSurface() != NULL) { if(surfaceManager->getSelectedSurface() != NULL){
// update vertex to new location // update vertex to new location
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position);
} else { }else{
// clear joints if there is no surface selected // clear joints if there is no surface selected
// as the remove selected surface in the surface manager // as the remove selected surface in the surface manager
// is not supposed to access joints here // is not supposed to access joints here
@ -74,38 +75,44 @@ namespace ofx {
break; break;
} }
} }
} }
void ProjectionEditor::draw() { void ProjectionEditor::draw(){
if (surfaceManager == NULL) return; if(surfaceManager == NULL){
if (surfaceManager->getSelectedSurface() == NULL) return; return;
if (joints.size() <= 0) createJoints(); }
drawJoints(); if(surfaceManager->getSelectedSurface() == NULL){
return;
}
if(joints.size() <= 0){
createJoints();
} }
drawJoints();
}
void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { void ProjectionEditor::mouseDragged(ofMouseEventArgs & args){
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
// Collect all vertices of the projection surfaces // Collect all vertices of the projection surfaces
vector<ofVec3f*> allVertices; vector <ofVec3f *> allVertices;
for (int i = 0; i < surfaceManager->size(); i++) { for(int i = 0; i < surfaceManager->size(); i++){
BaseSurface* surface = surfaceManager->getSurface(i); BaseSurface * surface = surfaceManager->getSurface(i);
if (surface == surfaceManager->getSelectedSurface()) { if(surface == surfaceManager->getSelectedSurface()){
continue; // Don't add vertices of selected surface continue; // Don't add vertices of selected surface
} }
for (int j = 0; j < surface->getVertices().size(); j++) { for(int j = 0; j < surface->getVertices().size(); j++){
allVertices.push_back(&surface->getVertices()[j]); allVertices.push_back(&surface->getVertices()[j]);
} }
} }
// Snap currently dragged joint to nearest vertex // Snap currently dragged joint to nearest vertex
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->isDragged()) { if(joints[i]->isDragged()){
// Snap it! // Snap it!
for (int j = 0; j < allVertices.size(); j++) { for(int j = 0; j < allVertices.size(); j++){
float distance = mousePosition.distance(*allVertices[j]); float distance = mousePosition.distance(*allVertices[j]);
// cout << "distance: " << distance << endl; // cout << "distance: " << distance << endl;
if (distance < fSnapDistance) { if(distance < fSnapDistance){
joints[i]->position = *allVertices[j]; joints[i]->position = *allVertices[j];
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y);
joints[i]->setClickDistance(clickDistance); joints[i]->setClickDistance(clickDistance);
@ -114,102 +121,113 @@ namespace ofx {
} }
} }
} }
} }
void ProjectionEditor::keyPressed(ofKeyEventArgs& args) { void ProjectionEditor::keyPressed(ofKeyEventArgs & args){
int key = args.key; int key = args.key;
float moveStep; float moveStep;
if (bShiftKeyDown) if(bShiftKeyDown){
moveStep = 10.0f; moveStep = 10.0f;
else }else{
moveStep = 0.5f; moveStep = 0.5f;
}
switch (key) { switch(key){
case OF_KEY_LEFT: case OF_KEY_LEFT:
moveSelection(ofVec2f(-moveStep, 0.0f)); moveSelection(ofVec2f(-moveStep, 0.0f));
break; break;
case OF_KEY_RIGHT: case OF_KEY_RIGHT:
moveSelection(ofVec2f(moveStep, 0.0f)); moveSelection(ofVec2f(moveStep, 0.0f));
break; break;
case OF_KEY_UP: case OF_KEY_UP:
moveSelection(ofVec2f(0.0f, -moveStep)); moveSelection(ofVec2f(0.0f, -moveStep));
break; break;
case OF_KEY_DOWN: case OF_KEY_DOWN:
moveSelection(ofVec2f(0.0f, moveStep)); moveSelection(ofVec2f(0.0f, moveStep));
break; break;
case OF_KEY_SHIFT: case OF_KEY_SHIFT:
bShiftKeyDown = true; bShiftKeyDown = true;
break; break;
} }
} }
void ProjectionEditor::keyReleased(ofKeyEventArgs& args) { void ProjectionEditor::keyReleased(ofKeyEventArgs & args){
int key = args.key; int key = args.key;
switch (key) { switch(key){
case OF_KEY_SHIFT: case OF_KEY_SHIFT:
bShiftKeyDown = false; bShiftKeyDown = false;
break; break;
} }
} }
void ProjectionEditor::gotMessage(ofMessage& msg) { void ProjectionEditor::gotMessage(ofMessage & msg){
if (msg.message == "surfaceSelected") { if(msg.message == "surfaceSelected"){
// refresh gui // refresh gui
clearJoints(); clearJoints();
createJoints(); createJoints();
} }
} }
void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { void ProjectionEditor::setSurfaceManager(SurfaceManager * newSurfaceManager){
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
} }
void ProjectionEditor::clearJoints() { void ProjectionEditor::clearJoints(){
while (joints.size()) { while(joints.size()){
delete joints.back(); delete joints.back();
joints.pop_back(); joints.pop_back();
} }
} }
void ProjectionEditor::createJoints() { void ProjectionEditor::createJoints(){
if (surfaceManager == NULL) return; if(surfaceManager == NULL){
return;
}
clearJoints(); clearJoints();
if (surfaceManager->getSelectedSurface() == NULL) { if(surfaceManager->getSelectedSurface() == NULL){
ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected."); ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected.");
return; return;
} }
vector<ofVec3f>& vertices = vector <ofVec3f> & vertices =
surfaceManager->getSelectedSurface()->getVertices(); surfaceManager->getSelectedSurface()->getVertices();
for (int i = 0; i < vertices.size(); i++) { for(int i = 0; i < vertices.size(); i++){
joints.push_back(new CircleJoint()); joints.push_back(new CircleJoint());
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y);
} }
} }
void ProjectionEditor::updateJoints() { void ProjectionEditor::updateJoints(){
if (surfaceManager->getSelectedSurface()) { if(surfaceManager->getSelectedSurface()){
vector<ofVec3f>& vertices = vector <ofVec3f> & vertices =
surfaceManager->getSelectedSurface()->getVertices(); surfaceManager->getSelectedSurface()->getVertices();
for (int i = 0; i < vertices.size(); i++) { for(int i = 0; i < vertices.size(); i++){
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y);
} }
} }
} }
void ProjectionEditor::unselectAllJoints() { void ProjectionEditor::unselectAllJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->unselect(); joints[i]->unselect();
} }
} }
void ProjectionEditor::moveSelectedSurface(ofVec2f by) { void ProjectionEditor::moveSelectedSurface(ofVec2f by){
if (surfaceManager == NULL) return; if(surfaceManager == NULL){
if (surfaceManager->getSelectedSurface() == NULL) return; return;
}
if(surfaceManager->getSelectedSurface() == NULL){
return;
}
surfaceManager->getSelectedSurface()->moveBy(by); surfaceManager->getSelectedSurface()->moveBy(by);
/*vector<ofVec3f>& vertices = /*vector<ofVec3f>& vertices =
surfaceManager->getSelectedSurface()->getVertices(); surfaceManager->getSelectedSurface()->getVertices();
@ -217,54 +235,55 @@ namespace ofx {
vertices[i] += by; vertices[i] += by;
}*/ }*/
updateJoints(); updateJoints();
} }
void ProjectionEditor::stopDragJoints() { void ProjectionEditor::stopDragJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->stopDrag(); joints[i]->stopDrag();
} }
} }
void ProjectionEditor::moveSelection(ofVec2f by) { void ProjectionEditor::moveSelection(ofVec2f by){
// check if joints selected // check if joints selected
bool bJointSelected = false; bool bJointSelected = false;
BaseJoint* selectedJoint; BaseJoint * selectedJoint;
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->isSelected()) { if(joints[i]->isSelected()){
bJointSelected = true; bJointSelected = true;
selectedJoint = joints[i]; selectedJoint = joints[i];
break; break;
} }
} }
if (bJointSelected) { if(bJointSelected){
selectedJoint->position += by; selectedJoint->position += by;
} else { }else{
moveSelectedSurface(by); moveSelectedSurface(by);
} }
} }
void ProjectionEditor::setSnapDistance(float newSnapDistance) { void ProjectionEditor::setSnapDistance(float newSnapDistance){
fSnapDistance = newSnapDistance; fSnapDistance = newSnapDistance;
} }
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) { CircleJoint * ProjectionEditor::hitTestJoints(ofVec2f pos){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->hitTest(pos)) { if(joints[i]->hitTest(pos)){
return joints[i]; return joints[i];
} }
} }
return NULL; return NULL;
} }
vector<CircleJoint *> * ProjectionEditor::getJoints(){ vector <CircleJoint *> * ProjectionEditor::getJoints(){
return &joints; return &joints;
} }
void ProjectionEditor::drawJoints() { void ProjectionEditor::drawJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->draw(); joints[i]->draw();
} }
}
}
} }
} // namespace piMapper
} // namespace ofx

34
src/UserInterface/ProjectionEditor.h

@ -4,8 +4,10 @@
#include "CircleJoint.h" #include "CircleJoint.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ProjectionEditor {
class ProjectionEditor {
public: public:
ProjectionEditor(); ProjectionEditor();
~ProjectionEditor(); ~ProjectionEditor();
@ -20,13 +22,13 @@ namespace ofx {
void enable(); void enable();
void disable(); void disable();
void update(ofEventArgs& args); void update(ofEventArgs & args);
void draw(); void draw();
void mouseDragged(ofMouseEventArgs& args); void mouseDragged(ofMouseEventArgs & args);
void keyPressed(ofKeyEventArgs& args); void keyPressed(ofKeyEventArgs & args);
void keyReleased(ofKeyEventArgs& args); void keyReleased(ofKeyEventArgs & args);
void gotMessage(ofMessage& msg); void gotMessage(ofMessage & msg);
void setSurfaceManager(SurfaceManager* newSurfaceManager); void setSurfaceManager(SurfaceManager * newSurfaceManager);
void clearJoints(); void clearJoints();
void createJoints(); void createJoints();
void updateJoints(); void updateJoints();
@ -36,16 +38,18 @@ namespace ofx {
void updateVertices(); void updateVertices();
void moveSelection(ofVec2f by); void moveSelection(ofVec2f by);
void setSnapDistance(float newSnapDistance); void setSnapDistance(float newSnapDistance);
CircleJoint* hitTestJoints(ofVec2f pos); CircleJoint * hitTestJoints(ofVec2f pos);
vector<CircleJoint *> * getJoints(); vector <CircleJoint *> * getJoints();
private: private:
SurfaceManager* surfaceManager; SurfaceManager * surfaceManager;
vector<CircleJoint*> joints; vector <CircleJoint *> joints;
bool bShiftKeyDown; bool bShiftKeyDown;
float fSnapDistance; float fSnapDistance;
void drawJoints(); void drawJoints();
};
} };
}
} // namespace piMapper
} // namespace ofx

122
src/UserInterface/RadioList.cpp

@ -1,27 +1,28 @@
#include "RadioList.h" #include "RadioList.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
RadioList::RadioList(){
RadioList::RadioList(){
storedTitle = ""; storedTitle = "";
storedSelectedItem = 0; storedSelectedItem = 0;
} }
RadioList::RadioList(vector<string> & labels, vector<string> & values){ RadioList::RadioList(vector <string> & labels, vector <string> & values){
RadioList(); RadioList();
setup(labels, values); setup(labels, values);
} }
RadioList::RadioList(string title, vector<string> & labels, vector<string> & values){ RadioList::RadioList(string title, vector <string> & labels, vector <string> & values){
RadioList(); RadioList();
setup(title, labels, values); setup(title, labels, values);
} }
RadioList::~RadioList(){ RadioList::~RadioList(){
clear(); clear();
} }
void RadioList::setup(vector<string> & labels, vector<string> & values){ void RadioList::setup(vector <string> & labels, vector <string> & values){
// Copy incomming labels for later use // Copy incomming labels for later use
storedLabels = labels; storedLabels = labels;
@ -35,45 +36,45 @@ namespace ofx{
toggle->setName(labels[i]); toggle->setName(labels[i]);
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
guiGroup.add(toggle); guiGroup.add(toggle);
#if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0) #if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0)
toggle->registerMouseEvents(); toggle->registerMouseEvents();
#endif #endif
}
} }
}
void RadioList::setup(string title, vector<string> & labels, vector<string> & values){ void RadioList::setup(string title, vector <string> & labels, vector <string> & values){
// Store title for later use // Store title for later use
storedTitle = title; storedTitle = title;
guiGroup.setName(title); guiGroup.setName(title);
setup(labels, values); setup(labels, values);
} }
void RadioList::draw(){ void RadioList::draw(){
guiGroup.draw(); guiGroup.draw();
} }
void RadioList::setTitle(string title){ void RadioList::setTitle(string title){
storedTitle = title; storedTitle = title;
guiGroup.setName(title); guiGroup.setName(title);
} }
void RadioList::setPosition(ofPoint p){ void RadioList::setPosition(ofPoint p){
guiGroup.setPosition(p); guiGroup.setPosition(p);
} }
void RadioList::setPosition(float x, float y){ void RadioList::setPosition(float x, float y){
guiGroup.setPosition(x, y); guiGroup.setPosition(x, y);
} }
void RadioList::selectItem(int index){ void RadioList::selectItem(int index){
if(index >= guiGroup.getNumControls()){ if(index >= guiGroup.getNumControls()){
return; return;
} }
unselectAll(); unselectAll();
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(index));
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = true; // Select the specific radio button *toggle = true; // Select the specific radio button
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
@ -82,9 +83,9 @@ namespace ofx{
string value = storedValues[index]; string value = storedValues[index];
ofNotifyEvent(onRadioSelected, value, this); ofNotifyEvent(onRadioSelected, value, this);
storedSelectedItem = index; storedSelectedItem = index;
} }
bool RadioList::selectItemByValue(std::string itemValue){ bool RadioList::selectItemByValue(std::string itemValue){
if(itemValue == ""){ if(itemValue == ""){
ofLogNotice("RadioList") << "Item value empty"; ofLogNotice("RadioList") << "Item value empty";
return false; return false;
@ -98,7 +99,7 @@ namespace ofx{
} }
} }
if(itemIndex >= 0){ if(itemIndex >= 0){
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(itemIndex)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(itemIndex));
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = true; // Select the specific radio button *toggle = true; // Select the specific radio button
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
@ -106,9 +107,9 @@ namespace ofx{
} }
ofLogNotice("RadioList") << "Item with value " << itemValue << " not found"; ofLogNotice("RadioList") << "Item with value " << itemValue << " not found";
return false; return false;
} }
void RadioList::enable(){ void RadioList::enable(){
if(guiGroup.getNumControls() > 0){ if(guiGroup.getNumControls() > 0){
clear(); clear();
} }
@ -117,83 +118,84 @@ namespace ofx{
setup(storedTitle, storedLabels, storedValues); setup(storedTitle, storedLabels, storedValues);
// Select the stored selected item without throwing an event // Select the stored selected item without throwing an event
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(storedSelectedItem)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(storedSelectedItem));
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = true; *toggle = true;
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
cout << "num items after enable: " << guiGroup.getNumControls() << endl; cout << "num items after enable: " << guiGroup.getNumControls() << endl;
} }
void RadioList::disable(){ void RadioList::disable(){
// Just remove everything // Just remove everything
clear(); clear();
} }
void RadioList::clear(){ void RadioList::clear(){
int i; int i;
for(i = 0; i < guiGroup.getNumControls(); i++){ for(i = 0; i < guiGroup.getNumControls(); i++){
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i));
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
delete toggle; delete toggle;
} }
guiGroup.clear(); guiGroup.clear();
} }
void RadioList::unselectAll(){ void RadioList::unselectAll(){
int i; int i;
for(i = 0; i < guiGroup.getNumControls(); i++){ for(i = 0; i < guiGroup.getNumControls(); i++){
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i));
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); ofParameter <bool> * paramPtr = static_cast <ofParameter <bool> *>(&toggle->getParameter());
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = false; *toggle = false;
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
} }
} }
ofPoint RadioList::getPosition(){ ofPoint RadioList::getPosition(){
return guiGroup.getPosition(); return guiGroup.getPosition();
} }
float RadioList::getWidth(){ float RadioList::getWidth(){
return guiGroup.getWidth(); return guiGroup.getWidth();
} }
float RadioList::getHeight(){ float RadioList::getHeight(){
return guiGroup.getHeight(); return guiGroup.getHeight();
} }
string RadioList::getTitle(){ string RadioList::getTitle(){
return guiGroup.getName(); return guiGroup.getName();
} }
string RadioList::getItemName(int index){ string RadioList::getItemName(int index){
if(index >= guiGroup.getNumControls()){ if(index >= guiGroup.getNumControls()){
return ""; return "";
} }
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(index));
return toggle->getName(); return toggle->getName();
} }
int RadioList::size(){ int RadioList::size(){
return storedValues.size(); return storedValues.size();
} }
void RadioList::onToggleClicked(bool & toggleValue){ void RadioList::onToggleClicked(bool & toggleValue){
unselectAll(); unselectAll();
// Search for the actual toggle triggering the event // Search for the actual toggle triggering the event
int i; int i;
for(i = 0; i < guiGroup.getNumControls(); i++){ for(i = 0; i < guiGroup.getNumControls(); i++){
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i));
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); ofParameter <bool> * paramPtr = static_cast <ofParameter <bool> *>(&toggle->getParameter());
if(&(paramPtr->get()) == &toggleValue){ if(&(paramPtr->get()) == &toggleValue){
selectItem(i); selectItem(i);
break; break;
} }
} }
} }
} // namespace piMapper
} // namespace piMapper
} // namespace ofx } // namespace ofx

26
src/UserInterface/RadioList.h

@ -5,17 +5,18 @@
#include "ofxToggle.h" #include "ofxToggle.h"
#include "ofxLabel.h" #include "ofxLabel.h"
namespace ofx{ namespace ofx {
namespace piMapper{ namespace piMapper {
class RadioList{
class RadioList {
public: public:
RadioList(); RadioList();
RadioList(vector<string> & labels, vector<string> & values); RadioList(vector <string> & labels, vector <string> & values);
RadioList(string title, vector<string> & labels, vector<string> & values); RadioList(string title, vector <string> & labels, vector <string> & values);
~RadioList(); ~RadioList();
void setup(vector<string> & labels, vector<string> & values); void setup(vector <string> & labels, vector <string> & values);
void setup(string title, vector<string> & labels, vector<string> & values); void setup(string title, vector <string> & labels, vector <string> & values);
void draw(); void draw();
void setTitle(string title); void setTitle(string title);
void setPosition(ofPoint p); void setPosition(ofPoint p);
@ -38,17 +39,18 @@ namespace ofx{
// Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr, // Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr,
// &listenerClass::listenerMethod) // &listenerClass::listenerMethod)
// to listen to this. Listner method void listenerMethod(string & radioName) // to listen to this. Listner method void listenerMethod(string & radioName)
ofEvent<string> onRadioSelected; ofEvent <string> onRadioSelected;
private: private:
vector<string> storedLabels; vector <string> storedLabels;
vector<string> storedValues; vector <string> storedValues;
string storedTitle; string storedTitle;
ofxGuiGroup guiGroup; ofxGuiGroup guiGroup;
int storedSelectedItem; int storedSelectedItem;
void onToggleClicked(bool & toggleValue); void onToggleClicked(bool & toggleValue);
}; };
} // namespace piMapper
} // namespace piMapper
} // namespace ofx } // namespace ofx

233
src/UserInterface/SourcesEditor.cpp

@ -2,47 +2,48 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SourcesEditor::SourcesEditor() {
SourcesEditor::SourcesEditor(){
init(); init();
// Create new MediaServer instance, // Create new MediaServer instance,
// we will need to clear this in the deconstr // we will need to clear this in the deconstr
mediaServer = new MediaServer(); mediaServer = new MediaServer();
isMediaServerExternal = false; isMediaServerExternal = false;
addMediaServerListeners(); addMediaServerListeners();
} }
void SourcesEditor::init() { void SourcesEditor::init(){
mediaServer = NULL; // Pointers to NULL pointer so we can check later mediaServer = NULL; // Pointers to NULL pointer so we can check later
isMediaServerExternal = false; isMediaServerExternal = false;
registerAppEvents(); registerAppEvents();
} }
SourcesEditor::SourcesEditor(MediaServer* externalMediaServer) { SourcesEditor::SourcesEditor(MediaServer * externalMediaServer){
init(); init();
// Assign external MediaServer instance pointer // Assign external MediaServer instance pointer
mediaServer = externalMediaServer; mediaServer = externalMediaServer;
isMediaServerExternal = true; isMediaServerExternal = true;
addMediaServerListeners(); addMediaServerListeners();
} }
SourcesEditor::~SourcesEditor() { SourcesEditor::~SourcesEditor(){
unregisterAppEvents(); unregisterAppEvents();
delete imageSelector; delete imageSelector;
delete videoSelector; delete videoSelector;
delete fboSelector; delete fboSelector;
removeMediaServerListeners(); removeMediaServerListeners();
clearMediaServer(); clearMediaServer();
} }
void SourcesEditor::registerAppEvents() { void SourcesEditor::registerAppEvents(){
ofAddListener(ofEvents().setup, this, &SourcesEditor::setup); ofAddListener(ofEvents().setup, this, &SourcesEditor::setup);
} }
void SourcesEditor::unregisterAppEvents() { void SourcesEditor::unregisterAppEvents(){
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup);
} }
void SourcesEditor::setup(ofEventArgs& args) { void SourcesEditor::setup(ofEventArgs & args){
imageSelector = new RadioList(); imageSelector = new RadioList();
videoSelector = new RadioList(); videoSelector = new RadioList();
fboSelector = new RadioList(); fboSelector = new RadioList();
@ -53,19 +54,19 @@ namespace piMapper {
int numFbos = mediaServer->getNumFboSources(); int numFbos = mediaServer->getNumFboSources();
// Depending on media count, decide what to load and initialize // Depending on media count, decide what to load and initialize
if (numImages) { if(numImages){
// Get image names from media server // Get image names from media server
vector<string> imageNames = mediaServer->getImageNames(); vector <string> imageNames = mediaServer->getImageNames();
imageSelector->setup("Images", imageNames, mediaServer->getImagePaths()); imageSelector->setup("Images", imageNames, mediaServer->getImagePaths());
ofAddListener(imageSelector->onRadioSelected, this, &SourcesEditor::handleImageSelected); ofAddListener(imageSelector->onRadioSelected, this, &SourcesEditor::handleImageSelected);
} }
if (numVideos) { if(numVideos){
vector<string> videoNames = mediaServer->getVideoNames(); vector <string> videoNames = mediaServer->getVideoNames();
videoSelector->setup("Videos", videoNames, mediaServer->getVideoPaths()); videoSelector->setup("Videos", videoNames, mediaServer->getVideoPaths());
ofAddListener(videoSelector->onRadioSelected, this, &SourcesEditor::handleVideoSelected); ofAddListener(videoSelector->onRadioSelected, this, &SourcesEditor::handleVideoSelected);
} }
if (numFbos) { if(numFbos){
std::vector<std::string> fboNames = mediaServer->getFboSourceNames(); std::vector <std::string> fboNames = mediaServer->getFboSourceNames();
fboSelector->setup("FBOs", fboNames, fboNames); fboSelector->setup("FBOs", fboNames, fboNames);
ofAddListener(fboSelector->onRadioSelected, this, &SourcesEditor::handleFboSelected); ofAddListener(fboSelector->onRadioSelected, this, &SourcesEditor::handleFboSelected);
} }
@ -73,87 +74,87 @@ namespace piMapper {
// Align menus // Align menus
int menuPosX = 20; int menuPosX = 20;
int distX = 230; int distX = 230;
if (numImages) { if(numImages){
imageSelector->setPosition(menuPosX, 20); imageSelector->setPosition(menuPosX, 20);
menuPosX += distX; menuPosX += distX;
} }
if (numVideos) { if(numVideos){
videoSelector->setPosition(menuPosX, 20); videoSelector->setPosition(menuPosX, 20);
menuPosX += distX; menuPosX += distX;
} }
if (numFbos) { if(numFbos){
fboSelector->setPosition(menuPosX, 20); fboSelector->setPosition(menuPosX, 20);
} }
} }
void SourcesEditor::draw() { void SourcesEditor::draw(){
// Don't draw if there is no source selected // Don't draw if there is no source selected
if (surfaceManager->getSelectedSurface() == NULL) { if(surfaceManager->getSelectedSurface() == NULL){
//ofLogNotice("SourcesEditor") << "No surface selected"; //ofLogNotice("SourcesEditor") << "No surface selected";
return; return;
} }
if (imageSelector->size()) { if(imageSelector->size()){
imageSelector->draw(); imageSelector->draw();
} }
if (videoSelector->size()) { if(videoSelector->size()){
videoSelector->draw(); videoSelector->draw();
} }
if (fboSelector->size()) { if(fboSelector->size()){
fboSelector->draw(); fboSelector->draw();
} }
} }
void SourcesEditor::disable() { void SourcesEditor::disable(){
if (imageSelector->size()) { if(imageSelector->size()){
imageSelector->disable(); imageSelector->disable();
} }
if (videoSelector->size()) { if(videoSelector->size()){
videoSelector->disable(); videoSelector->disable();
} }
if (fboSelector->size()) { if(fboSelector->size()){
fboSelector->disable(); fboSelector->disable();
} }
} }
void SourcesEditor::enable() { void SourcesEditor::enable(){
// Don't enable if there is no surface selected // Don't enable if there is no surface selected
if (surfaceManager->getSelectedSurface() == NULL) { if(surfaceManager->getSelectedSurface() == NULL){
ofLogNotice("SourcesEditor") << "No surface selected. Not enabling and not showing source list."; ofLogNotice("SourcesEditor") << "No surface selected. Not enabling and not showing source list.";
return; return;
} }
if (imageSelector->size()) { if(imageSelector->size()){
imageSelector->enable(); imageSelector->enable();
} }
if (videoSelector->size()) { if(videoSelector->size()){
videoSelector->enable(); videoSelector->enable();
} }
if (fboSelector->size()) { if(fboSelector->size()){
fboSelector->enable(); fboSelector->enable();
} }
BaseSource* source = surfaceManager->getSelectedSurface()->getSource(); BaseSource * source = surfaceManager->getSelectedSurface()->getSource();
// TODO: getPath should be replaced with something like getId() as now we // TODO: getPath should be replaced with something like getId() as now we
// use paths for loadable sources and names for FBOs // use paths for loadable sources and names for FBOs
if (source->getType() == SourceType::SOURCE_TYPE_FBO) { if(source->getType() == SourceType::SOURCE_TYPE_FBO){
selectSourceRadioButton(source->getName()); selectSourceRadioButton(source->getName());
} else { }else{
selectSourceRadioButton(source->getPath()); selectSourceRadioButton(source->getPath());
} }
} }
void SourcesEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { void SourcesEditor::setSurfaceManager(SurfaceManager * newSurfaceManager){
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
} }
void SourcesEditor::setCmdManager(CmdManager * cmdManager){ void SourcesEditor::setCmdManager(CmdManager * cmdManager){
_cmdManager = cmdManager; _cmdManager = cmdManager;
} }
void SourcesEditor::setMediaServer(MediaServer* newMediaServer) { void SourcesEditor::setMediaServer(MediaServer * newMediaServer){
// If the new media server is not valid // If the new media server is not valid
if (newMediaServer == NULL) { if(newMediaServer == NULL){
// Log an error and return from the routine // Log an error and return from the routine
ofLogFatalError("SourcesEditor") << "New media server is NULL"; ofLogFatalError("SourcesEditor") << "New media server is NULL";
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
@ -164,46 +165,46 @@ namespace piMapper {
//cout << "new ms addr: " << newMediaServer << endl; //cout << "new ms addr: " << newMediaServer << endl;
mediaServer = newMediaServer; mediaServer = newMediaServer;
isMediaServerExternal = true; isMediaServerExternal = true;
} }
void SourcesEditor::selectSourceRadioButton(std::string& sourcePath) { void SourcesEditor::selectSourceRadioButton(std::string & sourcePath){
if (sourcePath == "") { if(sourcePath == ""){
ofLogNotice("SourcesEditor") << "Path is empty"; ofLogNotice("SourcesEditor") << "Path is empty";
if (imageSelector->size()) { if(imageSelector->size()){
imageSelector->unselectAll(); imageSelector->unselectAll();
} }
if (videoSelector->size()) { if(videoSelector->size()){
videoSelector->unselectAll(); videoSelector->unselectAll();
} }
if (fboSelector->size()) { if(fboSelector->size()){
fboSelector->unselectAll(); fboSelector->unselectAll();
} }
return; return;
} else { }else{
// Check image selector first // Check image selector first
bool imageRadioSelected = false; bool imageRadioSelected = false;
bool videoRadioSelected = false; bool videoRadioSelected = false;
bool fboRadioSelected = false; bool fboRadioSelected = false;
if (imageSelector->size()) { if(imageSelector->size()){
imageRadioSelected = imageSelector->selectItemByValue(sourcePath); imageRadioSelected = imageSelector->selectItemByValue(sourcePath);
} }
if (videoSelector->size()) { if(videoSelector->size()){
videoRadioSelected = videoSelector->selectItemByValue(sourcePath); videoRadioSelected = videoSelector->selectItemByValue(sourcePath);
} }
if (fboSelector->size()) { if(fboSelector->size()){
fboRadioSelected = fboSelector->selectItemByValue(sourcePath); fboRadioSelected = fboSelector->selectItemByValue(sourcePath);
} }
if (imageRadioSelected || videoRadioSelected || fboRadioSelected) { if(imageRadioSelected || videoRadioSelected || fboRadioSelected){
return; return;
} }
// Log warning if we are still here // Log warning if we are still here
ofLogWarning("SourcesEditor") << "Could not find option in any of the source lists"; ofLogWarning("SourcesEditor") << "Could not find option in any of the source lists";
} }
} }
void SourcesEditor::addMediaServerListeners() { void SourcesEditor::addMediaServerListeners(){
// Check if the media server is valid // Check if the media server is valid
if (mediaServer == NULL) { if(mediaServer == NULL){
ofLogError("SourcesEditor::addMediaServerListeners", "Media server not set"); ofLogError("SourcesEditor::addMediaServerListeners", "Media server not set");
return; return;
} }
@ -220,11 +221,11 @@ namespace piMapper {
ofAddListener(mediaServer->onFboSourceLoaded, this, &SourcesEditor::handleFboSourceLoaded); ofAddListener(mediaServer->onFboSourceLoaded, this, &SourcesEditor::handleFboSourceLoaded);
ofAddListener(mediaServer->onFboSourceUnloaded, this, &SourcesEditor::handleFboSourceUnloaded); ofAddListener(mediaServer->onFboSourceUnloaded, this, &SourcesEditor::handleFboSourceUnloaded);
} }
void SourcesEditor::removeMediaServerListeners() { void SourcesEditor::removeMediaServerListeners(){
// Check if the media server is valid // Check if the media server is valid
if (mediaServer == NULL) { if(mediaServer == NULL){
ofLogError("SourcesEditor::addMediaServerListeners", "Media server not set"); ofLogError("SourcesEditor::addMediaServerListeners", "Media server not set");
return; return;
} }
@ -239,134 +240,134 @@ namespace piMapper {
ofRemoveListener(mediaServer->onFboSourceRemoved, this, &SourcesEditor::handleFboSourceRemoved); ofRemoveListener(mediaServer->onFboSourceRemoved, this, &SourcesEditor::handleFboSourceRemoved);
ofRemoveListener(mediaServer->onFboSourceLoaded, this, &SourcesEditor::handleFboSourceLoaded); ofRemoveListener(mediaServer->onFboSourceLoaded, this, &SourcesEditor::handleFboSourceLoaded);
ofRemoveListener(mediaServer->onFboSourceUnloaded, this, &SourcesEditor::handleFboSourceUnloaded); ofRemoveListener(mediaServer->onFboSourceUnloaded, this, &SourcesEditor::handleFboSourceUnloaded);
} }
void SourcesEditor::handleImageSelected(string & imagePath){ void SourcesEditor::handleImageSelected(string & imagePath){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_IMAGE, _cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_IMAGE,
imagePath, imagePath,
surfaceManager->getSelectedSurface(), surfaceManager->getSelectedSurface(),
(SourcesEditor *)this)); (SourcesEditor *)this));
} }
void SourcesEditor::setImageSource(string & imagePath){ void SourcesEditor::setImageSource(string & imagePath){
// Unselect selected items // Unselect selected items
videoSelector->unselectAll(); videoSelector->unselectAll();
fboSelector->unselectAll(); fboSelector->unselectAll();
BaseSurface* surface = surfaceManager->getSelectedSurface(); BaseSurface * surface = surfaceManager->getSelectedSurface();
if (surface == NULL) { if(surface == NULL){
ofLogWarning("SourcesEditor") << "No surface selected"; ofLogWarning("SourcesEditor") << "No surface selected";
return; return;
} }
// Unload old media // Unload old media
BaseSource* source = surface->getSource(); BaseSource * source = surface->getSource();
if (source->isLoadable()) { if(source->isLoadable()){
mediaServer->unloadMedia(source->getPath()); mediaServer->unloadMedia(source->getPath());
} else { }else{
mediaServer->unloadMedia(source->getName()); mediaServer->unloadMedia(source->getName());
} }
// Load new image // Load new image
surface->setSource(mediaServer->loadImage(imagePath)); surface->setSource(mediaServer->loadImage(imagePath));
} }
void SourcesEditor::handleVideoSelected(string & videoPath){ void SourcesEditor::handleVideoSelected(string & videoPath){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_VIDEO, _cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_VIDEO,
videoPath, videoPath,
surfaceManager->getSelectedSurface(), surfaceManager->getSelectedSurface(),
(SourcesEditor *)this)); (SourcesEditor *)this));
} }
void SourcesEditor::setVideoSource(string & videoPath){ void SourcesEditor::setVideoSource(string & videoPath){
// Unselect any selected items // Unselect any selected items
fboSelector->unselectAll(); fboSelector->unselectAll();
imageSelector->unselectAll(); imageSelector->unselectAll();
BaseSurface* surface = surfaceManager->getSelectedSurface(); BaseSurface * surface = surfaceManager->getSelectedSurface();
if (surface == NULL) { if(surface == NULL){
ofLogWarning("SourcesEditor") << "No surface selected"; ofLogWarning("SourcesEditor") << "No surface selected";
return; return;
} }
// Unload old media // Unload old media
BaseSource* source = surface->getSource(); BaseSource * source = surface->getSource();
if (source->isLoadable()) { if(source->isLoadable()){
mediaServer->unloadMedia(source->getPath()); mediaServer->unloadMedia(source->getPath());
} else { }else{
mediaServer->unloadMedia(source->getName()); mediaServer->unloadMedia(source->getName());
} }
// Load new video // Load new video
surface->setSource(mediaServer->loadVideo(videoPath)); surface->setSource(mediaServer->loadVideo(videoPath));
} }
void SourcesEditor::handleFboSelected(string & fboName){ void SourcesEditor::handleFboSelected(string & fboName){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_FBO, _cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_FBO,
fboName, fboName,
surfaceManager->getSelectedSurface(), surfaceManager->getSelectedSurface(),
(SourcesEditor *)this)); (SourcesEditor *)this));
} }
void SourcesEditor::setFboSource(string & fboName) { void SourcesEditor::setFboSource(string & fboName){
videoSelector->unselectAll(); videoSelector->unselectAll();
imageSelector->unselectAll(); imageSelector->unselectAll();
// Get selected surface // Get selected surface
BaseSurface* surface = surfaceManager->getSelectedSurface(); BaseSurface * surface = surfaceManager->getSelectedSurface();
if (surface == NULL) { if(surface == NULL){
ofLogWarning("SourcesEditor") << "No surface selected"; ofLogWarning("SourcesEditor") << "No surface selected";
return; return;
} }
// Unload old media // Unload old media
BaseSource* source = surface->getSource(); BaseSource * source = surface->getSource();
if (source->isLoadable()) { if(source->isLoadable()){
mediaServer->unloadMedia(source->getPath()); mediaServer->unloadMedia(source->getPath());
} else { }else{
mediaServer->unloadMedia(source->getName()); mediaServer->unloadMedia(source->getName());
} }
// Load new FBO // Load new FBO
surface->setSource(mediaServer->loadFboSource(fboName)); surface->setSource(mediaServer->loadFboSource(fboName));
} }
void SourcesEditor::clearSource(){ void SourcesEditor::clearSource(){
BaseSurface* surface = surfaceManager->getSelectedSurface(); BaseSurface * surface = surfaceManager->getSelectedSurface();
// Unload old media // Unload old media
BaseSource* source = surface->getSource(); BaseSource * source = surface->getSource();
if (source->isLoadable()) { if(source->isLoadable()){
mediaServer->unloadMedia(source->getPath()); mediaServer->unloadMedia(source->getPath());
} else { }else{
mediaServer->unloadMedia(source->getName()); mediaServer->unloadMedia(source->getName());
} }
// Reset default source // Reset default source
surface->setSource(surface->getDefaultSource()); surface->setSource(surface->getDefaultSource());
} }
void SourcesEditor::clearMediaServer() { void SourcesEditor::clearMediaServer(){
// If mediaServer is local, clear it // If mediaServer is local, clear it
if (!isMediaServerExternal) { if(!isMediaServerExternal){
// Clear all loaded sources // Clear all loaded sources
mediaServer->clear(); mediaServer->clear();
// Destroy the pointer and set it to NULL pointer // Destroy the pointer and set it to NULL pointer
delete mediaServer; delete mediaServer;
mediaServer = NULL; mediaServer = NULL;
} }
}
void SourcesEditor::handleImageAdded(std::string& path) {}
void SourcesEditor::handleImageRemoved(std::string& path) {}
void SourcesEditor::handleVideoAdded(std::string& path) {}
void SourcesEditor::handleVideoRemoved(std::string& path) {}
void SourcesEditor::handleImageLoaded(std::string& path) {}
void SourcesEditor::handleImageUnloaded(std::string& path) {}
void SourcesEditor::handleFboSourceAdded(std::string& name) {}
void SourcesEditor::handleFboSourceRemoved(std::string& name) {}
void SourcesEditor::handleFboSourceLoaded(std::string& name) {}
void SourcesEditor::handleFboSourceUnloaded(std::string& name) {}
}
} }
void SourcesEditor::handleImageAdded(std::string & path){}
void SourcesEditor::handleImageRemoved(std::string & path){}
void SourcesEditor::handleVideoAdded(std::string & path){}
void SourcesEditor::handleVideoRemoved(std::string & path){}
void SourcesEditor::handleImageLoaded(std::string & path){}
void SourcesEditor::handleImageUnloaded(std::string & path){}
void SourcesEditor::handleFboSourceAdded(std::string & name){}
void SourcesEditor::handleFboSourceRemoved(std::string & name){}
void SourcesEditor::handleFboSourceLoaded(std::string & name){}
void SourcesEditor::handleFboSourceUnloaded(std::string & name){}
} // namespace piMapper
} // namespace ofx

48
src/UserInterface/SourcesEditor.h

@ -10,6 +10,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourcesEditor { class SourcesEditor {
public: public:
// Default contructor that initializes media server locally, // Default contructor that initializes media server locally,
@ -17,27 +18,27 @@ class SourcesEditor {
SourcesEditor(); SourcesEditor();
// Alternative constructor that allows to assign external media server // Alternative constructor that allows to assign external media server
SourcesEditor(MediaServer* externalMediaServer); SourcesEditor(MediaServer * externalMediaServer);
~SourcesEditor(); ~SourcesEditor();
void registerAppEvents(); void registerAppEvents();
void unregisterAppEvents(); void unregisterAppEvents();
void setup(ofEventArgs& args); void setup(ofEventArgs & args);
void draw(); void draw();
void loadImage(string name, string path); void loadImage(string name, string path);
void disable(); void disable();
void enable(); void enable();
void setSurfaceManager(SurfaceManager* newSurfaceManager); void setSurfaceManager(SurfaceManager * newSurfaceManager);
void setCmdManager(CmdManager * cmdManager); void setCmdManager(CmdManager * cmdManager);
// Sets external MediaServer // Sets external MediaServer
void setMediaServer(MediaServer* newMediaServer); void setMediaServer(MediaServer * newMediaServer);
//void selectImageSourceRadioButton(string name); //void selectImageSourceRadioButton(string name);
void selectSourceRadioButton(std::string& sourcePath); void selectSourceRadioButton(std::string & sourcePath);
int getLoadedTexCount(); int getLoadedTexCount();
ofTexture* getTexture(int index); ofTexture * getTexture(int index);
void setImageSource(string & imagePath); void setImageSource(string & imagePath);
void setVideoSource(string & videoPath); void setVideoSource(string & videoPath);
@ -45,11 +46,11 @@ class SourcesEditor {
void clearSource(); void clearSource();
private: private:
MediaServer* mediaServer; MediaServer * mediaServer;
SurfaceManager* surfaceManager; SurfaceManager * surfaceManager;
RadioList* imageSelector; RadioList * imageSelector;
RadioList* videoSelector; RadioList * videoSelector;
RadioList* fboSelector; RadioList * fboSelector;
CmdManager * _cmdManager; CmdManager * _cmdManager;
// Is the media server pointer local or from somewhere else? // Is the media server pointer local or from somewhere else?
@ -73,17 +74,18 @@ class SourcesEditor {
void clearMediaServer(); void clearMediaServer();
// MediaServer event handlers // MediaServer event handlers
void handleImageAdded(std::string& path); void handleImageAdded(std::string & path);
void handleImageRemoved(std::string& path); void handleImageRemoved(std::string & path);
void handleVideoAdded(std::string& path); void handleVideoAdded(std::string & path);
void handleVideoRemoved(std::string& path); void handleVideoRemoved(std::string & path);
void handleImageLoaded(std::string& path); void handleImageLoaded(std::string & path);
void handleImageUnloaded(std::string& path); void handleImageUnloaded(std::string & path);
void handleFboSourceAdded(std::string& name); void handleFboSourceAdded(std::string & name);
void handleFboSourceRemoved(std::string& name); void handleFboSourceRemoved(std::string & name);
void handleFboSourceLoaded(std::string& name); void handleFboSourceLoaded(std::string & name);
void handleFboSourceUnloaded(std::string& name); void handleFboSourceUnloaded(std::string & name);
}; };
}
} } // namespace piMapper
} // namespace ofx

134
src/UserInterface/TextureEditor.cpp

@ -2,47 +2,50 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TextureEditor::TextureEditor() {
TextureEditor::TextureEditor(){
clear(); clear();
enable(); enable();
} }
TextureEditor::~TextureEditor() { TextureEditor::~TextureEditor(){
clear(); clear();
disable(); disable();
} }
void TextureEditor::registerAppEvents() { void TextureEditor::registerAppEvents(){
ofAddListener(ofEvents().update, this, &TextureEditor::update); ofAddListener(ofEvents().update, this, &TextureEditor::update);
} }
void TextureEditor::unregisterAppEvents() { void TextureEditor::unregisterAppEvents(){
ofRemoveListener(ofEvents().update, this, &TextureEditor::update); ofRemoveListener(ofEvents().update, this, &TextureEditor::update);
} }
void TextureEditor::registerKeyEvents() { void TextureEditor::registerKeyEvents(){
ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed);
ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased);
} }
void TextureEditor::unregisterKeyEvents() { void TextureEditor::unregisterKeyEvents(){
ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed);
ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased);
} }
void TextureEditor::enable() { void TextureEditor::enable(){
registerAppEvents(); registerAppEvents();
registerKeyEvents(); registerKeyEvents();
bShiftKeyDown = false; bShiftKeyDown = false;
} }
void TextureEditor::disable() { void TextureEditor::disable(){
unregisterAppEvents(); unregisterAppEvents();
unregisterKeyEvents(); unregisterKeyEvents();
} }
void TextureEditor::update(ofEventArgs& args) { void TextureEditor::update(ofEventArgs & args){
if (surface == NULL) return; if(surface == NULL){
return;
}
// update surface if one of the joints is being dragged // update surface if one of the joints is being dragged
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(),
@ -51,8 +54,8 @@ void TextureEditor::update(ofEventArgs& args) {
// Get selected joint index // Get selected joint index
int selectedJointIndex = 0; int selectedJointIndex = 0;
bool bJointSelected = false; bool bJointSelected = false;
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->isDragged() || joints[i]->isSelected()) { if(joints[i]->isDragged() || joints[i]->isSelected()){
selectedJointIndex = i; selectedJointIndex = i;
bJointSelected = true; bJointSelected = true;
break; break;
@ -60,162 +63,175 @@ void TextureEditor::update(ofEventArgs& args) {
} // for } // for
// Constrain quad texture selection // Constrain quad texture selection
if (joints.size() == 4) { if(joints.size() == 4){
if (bJointSelected) { if(bJointSelected){
constrainJointsToQuad(selectedJointIndex); constrainJointsToQuad(selectedJointIndex);
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
surface->setTexCoord(i, joints[i]->position / textureSize); surface->setTexCoord(i, joints[i]->position / textureSize);
} }
} // if } // if
} else { }else{
if (bJointSelected) { if(bJointSelected){
surface->setTexCoord(selectedJointIndex, joints[selectedJointIndex]->position / textureSize); surface->setTexCoord(selectedJointIndex, joints[selectedJointIndex]->position / textureSize);
} }
} // else } // else
} }
void TextureEditor::keyPressed(ofKeyEventArgs& args) { void TextureEditor::keyPressed(ofKeyEventArgs & args){
int key = args.key; int key = args.key;
float moveStep; float moveStep;
if (bShiftKeyDown) if(bShiftKeyDown){
moveStep = 10.0f; moveStep = 10.0f;
else }else{
moveStep = 0.5f; moveStep = 0.5f;
}
switch (key) { switch(key){
case OF_KEY_LEFT: case OF_KEY_LEFT:
moveSelection(ofVec2f(-moveStep, 0.0f)); moveSelection(ofVec2f(-moveStep, 0.0f));
break; break;
case OF_KEY_RIGHT: case OF_KEY_RIGHT:
moveSelection(ofVec2f(moveStep, 0.0f)); moveSelection(ofVec2f(moveStep, 0.0f));
break; break;
case OF_KEY_UP: case OF_KEY_UP:
moveSelection(ofVec2f(0.0f, -moveStep)); moveSelection(ofVec2f(0.0f, -moveStep));
break; break;
case OF_KEY_DOWN: case OF_KEY_DOWN:
moveSelection(ofVec2f(0.0f, moveStep)); moveSelection(ofVec2f(0.0f, moveStep));
break; break;
case OF_KEY_SHIFT: case OF_KEY_SHIFT:
bShiftKeyDown = true; bShiftKeyDown = true;
break; break;
} }
} }
void TextureEditor::keyReleased(ofKeyEventArgs& args) { void TextureEditor::keyReleased(ofKeyEventArgs & args){
int key = args.key; int key = args.key;
switch (key) { switch(key){
case OF_KEY_SHIFT: case OF_KEY_SHIFT:
bShiftKeyDown = false; bShiftKeyDown = false;
break; break;
} }
} }
void TextureEditor::draw() { void TextureEditor::draw(){
if (surface == NULL) return; if(surface == NULL){
return;
}
// Reset default color to white // Reset default color to white
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
drawJoints(); drawJoints();
} }
void TextureEditor::drawJoints() { void TextureEditor::drawJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->draw(); joints[i]->draw();
} }
} }
void TextureEditor::setSurface(BaseSurface* newSurface) { void TextureEditor::setSurface(BaseSurface * newSurface){
surface = newSurface; surface = newSurface;
createJoints(); createJoints();
} }
void TextureEditor::clear() { void TextureEditor::clear(){
surface = NULL; surface = NULL;
clearJoints(); clearJoints();
} }
void TextureEditor::createJoints() { void TextureEditor::createJoints(){
if (surface == NULL) return; if(surface == NULL){
return;
}
clearJoints(); clearJoints();
vector<ofVec2f>& texCoords = surface->getTexCoords(); vector <ofVec2f> & texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for(int i = 0; i < texCoords.size(); i++){
joints.push_back(new CircleJoint()); joints.push_back(new CircleJoint());
joints.back()->position = texCoords[i] * textureSize; joints.back()->position = texCoords[i] * textureSize;
} }
} }
void TextureEditor::clearJoints() { void TextureEditor::clearJoints(){
while (joints.size()) { while(joints.size()){
delete joints.back(); delete joints.back();
joints.pop_back(); joints.pop_back();
} }
} }
void TextureEditor::unselectAllJoints() { void TextureEditor::unselectAllJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->unselect(); joints[i]->unselect();
} }
} }
void TextureEditor::moveTexCoords(ofVec2f by) { void TextureEditor::moveTexCoords(ofVec2f by){
if (surface == NULL) return; if(surface == NULL){
vector<ofVec2f>& texCoords = surface->getTexCoords(); return;
}
vector <ofVec2f> & texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for(int i = 0; i < texCoords.size(); i++){
joints[i]->position += by; joints[i]->position += by;
surface->setTexCoord(i, joints[i]->position / textureSize); surface->setTexCoord(i, joints[i]->position / textureSize);
} }
} }
void TextureEditor::stopDragJoints() { void TextureEditor::stopDragJoints(){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
joints[i]->stopDrag(); joints[i]->stopDrag();
} }
} }
void TextureEditor::moveSelection(ofVec2f by) { void TextureEditor::moveSelection(ofVec2f by){
// check if joints selected // check if joints selected
bool bJointSelected = false; bool bJointSelected = false;
BaseJoint* selectedJoint; BaseJoint * selectedJoint;
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->isSelected()) { if(joints[i]->isSelected()){
bJointSelected = true; bJointSelected = true;
selectedJoint = joints[i]; selectedJoint = joints[i];
break; break;
} }
} }
if (bJointSelected) { if(bJointSelected){
selectedJoint->position += by; selectedJoint->position += by;
} else { }else{
moveTexCoords(by); moveTexCoords(by);
} }
} }
void TextureEditor::constrainJointsToQuad(int selectedJointIndex) void TextureEditor::constrainJointsToQuad(int selectedJointIndex){
{ switch(selectedJointIndex){
switch (selectedJointIndex) {
case 0: case 0:
joints[1]->position = ofVec2f(joints[1]->position.x, joints[0]->position.y); joints[1]->position = ofVec2f(joints[1]->position.x, joints[0]->position.y);
joints[2]->position = ofVec2f(joints[1]->position.x, joints[3]->position.y); joints[2]->position = ofVec2f(joints[1]->position.x, joints[3]->position.y);
joints[3]->position = ofVec2f(joints[0]->position.x, joints[3]->position.y); joints[3]->position = ofVec2f(joints[0]->position.x, joints[3]->position.y);
break; break;
case 1: case 1:
joints[0]->position = ofVec2f(joints[0]->position.x, joints[1]->position.y); joints[0]->position = ofVec2f(joints[0]->position.x, joints[1]->position.y);
joints[2]->position = ofVec2f(joints[1]->position.x, joints[2]->position.y); joints[2]->position = ofVec2f(joints[1]->position.x, joints[2]->position.y);
joints[3]->position = ofVec2f(joints[0]->position.x, joints[2]->position.y); joints[3]->position = ofVec2f(joints[0]->position.x, joints[2]->position.y);
break; break;
case 2: case 2:
joints[1]->position = ofVec2f(joints[2]->position.x, joints[1]->position.y); joints[1]->position = ofVec2f(joints[2]->position.x, joints[1]->position.y);
joints[3]->position = ofVec2f(joints[3]->position.x, joints[2]->position.y); joints[3]->position = ofVec2f(joints[3]->position.x, joints[2]->position.y);
joints[0]->position = ofVec2f(joints[3]->position.x, joints[1]->position.y); joints[0]->position = ofVec2f(joints[3]->position.x, joints[1]->position.y);
break; break;
case 3: case 3:
joints[0]->position = ofVec2f(joints[3]->position.x, joints[0]->position.y); joints[0]->position = ofVec2f(joints[3]->position.x, joints[0]->position.y);
joints[2]->position = ofVec2f(joints[2]->position.x, joints[3]->position.y); joints[2]->position = ofVec2f(joints[2]->position.x, joints[3]->position.y);
@ -224,18 +240,18 @@ void TextureEditor::constrainJointsToQuad(int selectedJointIndex)
} // switch } // switch
} }
CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos) { CircleJoint * TextureEditor::hitTestJoints(ofVec2f pos){
for (int i = 0; i < joints.size(); i++) { for(int i = 0; i < joints.size(); i++){
if (joints[i]->hitTest(pos)) { if(joints[i]->hitTest(pos)){
return joints[i]; return joints[i];
} }
} }
return NULL; return NULL;
} }
vector<CircleJoint*> & TextureEditor::getJoints(){ vector <CircleJoint *> & TextureEditor::getJoints(){
return joints; return joints;
}
}
} }
} // namespace piMapper
} // namespace ofx

24
src/UserInterface/TextureEditor.h

@ -7,7 +7,9 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TextureEditor { class TextureEditor {
public: public:
TextureEditor(); TextureEditor();
~TextureEditor(); ~TextureEditor();
@ -19,12 +21,12 @@ class TextureEditor {
void enable(); void enable();
void disable(); void disable();
void update(ofEventArgs& args); void update(ofEventArgs & args);
void keyPressed(ofKeyEventArgs& args); void keyPressed(ofKeyEventArgs & args);
void keyReleased(ofKeyEventArgs& args); void keyReleased(ofKeyEventArgs & args);
void draw(); void draw();
void drawJoints(); void drawJoints();
void setSurface(BaseSurface* newSurface); void setSurface(BaseSurface * newSurface);
void clear(); void clear();
void createJoints(); void createJoints();
void clearJoints(); void clearJoints();
@ -33,13 +35,15 @@ class TextureEditor {
void stopDragJoints(); void stopDragJoints();
void moveSelection(ofVec2f by); void moveSelection(ofVec2f by);
void constrainJointsToQuad(int selectedJointIndex); void constrainJointsToQuad(int selectedJointIndex);
CircleJoint* hitTestJoints(ofVec2f pos); CircleJoint * hitTestJoints(ofVec2f pos);
vector<CircleJoint*> & getJoints(); vector <CircleJoint *> & getJoints();
private: private:
BaseSurface* surface; BaseSurface * surface;
vector<CircleJoint*> joints; vector <CircleJoint *> joints;
bool bShiftKeyDown; bool bShiftKeyDown;
}; };
}
} } // namespace piMapper
} // namespace ofx

36
src/ofxPiMapper.cpp

@ -1,21 +1,21 @@
#include "ofxPiMapper.h" #include "ofxPiMapper.h"
ofxPiMapper::ofxPiMapper() { ofxPiMapper::ofxPiMapper(){
bShowInfo = false; bShowInfo = false;
isSetUp = false; isSetUp = false;
} }
void ofxPiMapper::setup() { void ofxPiMapper::setup(){
ofLogNotice("ofxPiMapper") << "Setting up..."; ofLogNotice("ofxPiMapper") << "Setting up...";
surfaceManager.setMediaServer(&mediaServer); surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer); gui.setMediaServer(&mediaServer);
gui.setCmdManager(&cmdManager); gui.setCmdManager(&cmdManager);
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){ if(ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE; ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
} else { }else{
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE; ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE); surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
} }
@ -26,14 +26,14 @@ void ofxPiMapper::setup() {
_application = new ofx::piMapper::Application(this); _application = new ofx::piMapper::Application(this);
} }
void ofxPiMapper::draw() { void ofxPiMapper::draw(){
if (!isSetUp) { if(!isSetUp){
return; return;
} }
gui.draw(); gui.draw();
if (bShowInfo){ if(bShowInfo){
stringstream ss; stringstream ss;
ss << "There are 4 modes:\n\n"; ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n"; ss << " 1. Presentation mode\n";
@ -55,20 +55,20 @@ void ofxPiMapper::draw() {
_application->draw(); _application->draw();
} // draw } // draw
void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource) { void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource){
mediaServer.addFboSource(fboSource); mediaServer.addFboSource(fboSource);
} }
void ofxPiMapper::addTriangleSurface() { void ofxPiMapper::addTriangleSurface(){
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices; vector <ofVec2f> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f)); texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f)); texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f)); texCoords.push_back(ofVec2f(0.0f, 1.0f));
@ -78,17 +78,17 @@ void ofxPiMapper::addTriangleSurface() {
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addTriangleSurface } // addTriangleSurface
void ofxPiMapper::addQuadSurface() { void ofxPiMapper::addQuadSurface(){
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices; vector <ofVec2f> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin)); vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords; vector <ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
@ -100,18 +100,18 @@ void ofxPiMapper::addQuadSurface() {
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addQuadSurface } // addQuadSurface
ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager() { ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager(){
return cmdManager; return cmdManager;
} }
ofx::piMapper::SurfaceManagerGui & ofxPiMapper::getGui() { ofx::piMapper::SurfaceManagerGui & ofxPiMapper::getGui(){
return gui; return gui;
} }
ofx::piMapper::MediaServer & ofxPiMapper::getMediaServer() { ofx::piMapper::MediaServer & ofxPiMapper::getMediaServer(){
return mediaServer; return mediaServer;
} }
ofx::piMapper::SurfaceManager & ofxPiMapper::getSurfaceManager() { ofx::piMapper::SurfaceManager & ofxPiMapper::getSurfaceManager(){
return surfaceManager; return surfaceManager;
} }

20
src/ofxPiMapper.h

@ -14,12 +14,13 @@
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml" #define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class Application; class Application;
} }
} }
class ofxPiMapper { class ofxPiMapper {
public: public:
ofxPiMapper(); ofxPiMapper();
@ -28,9 +29,15 @@ class ofxPiMapper {
void registerFboSource(ofx::piMapper::FboSource & fboSource); void registerFboSource(ofx::piMapper::FboSource & fboSource);
void addTriangleSurface(); void addTriangleSurface();
void addQuadSurface(); void addQuadSurface();
void showInfo() { bShowInfo = true; }; void showInfo(){
void hideInfo() { bShowInfo = false; }; bShowInfo = true;
void toggleInfo() { bShowInfo = !bShowInfo; } }
void hideInfo(){
bShowInfo = false;
}
void toggleInfo(){
bShowInfo = !bShowInfo;
}
ofx::piMapper::CmdManager & getCmdManager(); ofx::piMapper::CmdManager & getCmdManager();
ofx::piMapper::SurfaceManagerGui & getGui(); ofx::piMapper::SurfaceManagerGui & getGui();
@ -45,4 +52,5 @@ class ofxPiMapper {
ofx::piMapper::MediaServer mediaServer; ofx::piMapper::MediaServer mediaServer;
ofx::piMapper::SurfaceManagerGui gui; ofx::piMapper::SurfaceManagerGui gui;
ofx::piMapper::Application * _application; ofx::piMapper::Application * _application;
}; };
Loading…
Cancel
Save