Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ofApp.h"
- //--------------------------------------------------------------
- void ofApp::setup() {
- ofDisableArbTex();
- ofImage first, second;
- kinectsFbo.allocate(160 * 9, 120);
- //test fotky
- first.loadImage("1.png");
- second.loadImage("2.png");
- thressholdBrithness = 100;
- for (int i = 0; i < numberofmutex; i++) {
- textures.push_back(ofTexture());
- textures[i].allocate(640, 480, GL_RGB);
- setupMutexs(i);
- if (i % 2 == 0)
- textures[i] = first.getTexture();
- else
- textures[i] = second.getTexture();
- textures[i].enableMipmap();
- }
- nocolor = false;
- this->texture.enableMipmap();
- this->warpController.loadSettings("settings.json");
- if (this->warpController.getWarps().empty())
- {
- shared_ptr<ofxWarpBase> warp;
- for (int i = 0; i < numberofmutex; i++) {
- warp = this->warpController.buildWarp<ofxWarpBilinear>();
- warp->setSize(640, 240);
- }
- }
- this->srcAreas.resize(this->warpController.getNumWarps());
- this->areaMode = -1;
- this->keyPressed('p');
- }
- void ofApp::setupMutexs(int index){
- mapFileHandle[index] = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, szNames[index].c_str());
- if (mapFileHandle[index] == NULL) {
- printf("Map File Failed to open\n");
- return;
- }
- texture.allocate(640, 480, GL_RGB);
- mutex[index] = OpenMutexW(SYNCHRONIZE, false, mutexNames[index].c_str());
- if (mutex[index] == NULL) {
- printf("No mutex found \n");
- }
- name.c_str();
- }
- void ofApp::updateMutexs(int index){
- DWORD waitResult = WaitForSingleObject(mutex[index], 1000 / 60);
- if (waitResult == WAIT_OBJECT_0) {
- printf("Obtaining data \n");
- data = MapViewOfFile(mapFileHandle[index], FILE_MAP_ALL_ACCESS, 0, 0, size_of_frame);
- if (data != nullptr) {
- printf("Uploading Texture \n");
- ofPixels pix;
- pix.setFromExternalPixels((uint8_t*)data, 640, 480, ofPixelFormat::OF_PIXELS_RGB);
- textures[index].allocate(pix);
- }
- UnmapViewOfFile(mapFileHandle[index]);
- if (!ReleaseMutex(mutex[index])) {
- printf("Failed to release mutex \n");
- }
- }
- else {
- printf("x");
- }
- }
- //--------------------------------------------------------------
- void ofApp::update() {
- for (int i = 0; i < numberofmutex; i++) {
- updateMutexs(i);
- ofPixels pix;
- textures[i].readToPixels(pix);
- for (int i = 0; i<pix.size(); i++) {
- unsigned char c = pix[i];
- (pix[i] > thressholdBrithness) ? (pix[i] = pix[i]) : (pix[i] = 0);
- }
- textures[i].loadData(pix);
- }
- }
- //--------------------------------------------------------------
- void ofApp::draw() {
- //ofBackground(0);
- for (int i = 0; i < numberofmutex; i++) {
- if (textures[i].isAllocated()) {
- // textures[i].draw(640*i, 0);
- }
- }
- //textures[0].draw(0,0);
- //textures[0].draw(640, 0, 160, 120);
- //ofNoFill();
- kinectsFbo.begin();
- ofBackground(0);
- for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
- {
- if (this->textures[0].isAllocated()) {
- auto warp = this->warpController.getWarp(i);
- if (this->useBeginEnd)
- {
- warp->begin();
- auto bounds = warp->getBounds();
- this->textures[i].draw(i * 640, 0);
- warp->end();
- }
- else
- {
- warp->draw(textures[i], this->srcAreas[i]);
- }
- }
- }
- /*if (nocolor) {
- ofPopStyle();
- ofSetColor(0);
- ofRect(0, 0, ofGetWidth(), 100);
- ofRect(260, 0, ofGetWidth(), 100);
- ofPushStyle();
- }*/
- kinectsFbo.end();
- kinectsFbo.draw(0,0);
- ofDrawBitmapString(ofToString(thressholdBrithness, 0) + "Thresshold", 20, 200);
- ofDrawBitmapString(ofToString(ofGetFrameRate(), 0) + "FPS", 20, 240);
- }
- //--------------------------------------------------------------
- void ofApp::keyPressed(int key) {
- if (key == '+') {
- thressholdBrithness = thressholdBrithness++;
- (thressholdBrithness > 255) ? (thressholdBrithness = 255) : (thressholdBrithness);
- }
- if (key == '-') {
- thressholdBrithness = thressholdBrithness--;
- (thressholdBrithness < 0) ? (thressholdBrithness = 0) : (thressholdBrithness);
- }
- if (key == 'a') {
- nocolor = !nocolor;
- }
- if (key == 's') {
- this->warpController.saveSettings("settings.json");
- }
- if (key == 'o')
- {
- ofToggleFullscreen();
- }
- if (key == 'p')
- {
- this->areaMode = (this->areaMode + 1) % 3;
- if (this->areaMode == 0)
- {
- auto area = ofRectangle(0, 0, 640, 480);
- for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
- {
- this->srcAreas[i] = area;
- }
- this->areaName = "full";
- }
- }
- }
- //--------------------------------------------------------------
- void ofApp::keyReleased(int key) {
- }
- //--------------------------------------------------------------
- void ofApp::mouseMoved(int x, int y) {
- }
- //--------------------------------------------------------------
- void ofApp::mouseDragged(int x, int y, int button) {
- }
- //--------------------------------------------------------------
- void ofApp::mousePressed(int x, int y, int button) {
- }
- //--------------------------------------------------------------
- void ofApp::mouseReleased(int x, int y, int button) {
- }
- //--------------------------------------------------------------
- void ofApp::mouseEntered(int x, int y) {
- }
- //--------------------------------------------------------------
- void ofApp::mouseExited(int x, int y) {
- }
- //--------------------------------------------------------------
- void ofApp::windowResized(int w, int h) {
- }
- //--------------------------------------------------------------
- void ofApp::gotMessage(ofMessage msg) {
- }
- //--------------------------------------------------------------
- void ofApp::dragEvent(ofDragInfo dragInfo) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement