Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup() {
  5. ofDisableArbTex();
  6. ofImage first, second;
  7. kinectsFbo.allocate(160 * 9, 120);
  8. //test fotky
  9. first.loadImage("1.png");
  10. second.loadImage("2.png");
  11. thressholdBrithness = 100;
  12. for (int i = 0; i < numberofmutex; i++) {
  13. textures.push_back(ofTexture());
  14. textures[i].allocate(640, 480, GL_RGB);
  15.  
  16. setupMutexs(i);
  17. if (i % 2 == 0)
  18. textures[i] = first.getTexture();
  19.  
  20. else
  21. textures[i] = second.getTexture();
  22. textures[i].enableMipmap();
  23. }
  24.  
  25. nocolor = false;
  26. this->texture.enableMipmap();
  27.  
  28. this->warpController.loadSettings("settings.json");
  29. if (this->warpController.getWarps().empty())
  30. {
  31. shared_ptr<ofxWarpBase> warp;
  32. for (int i = 0; i < numberofmutex; i++) {
  33. warp = this->warpController.buildWarp<ofxWarpBilinear>();
  34. warp->setSize(640, 240);
  35. }
  36.  
  37. }
  38.  
  39. this->srcAreas.resize(this->warpController.getNumWarps());
  40. this->areaMode = -1;
  41.  
  42. this->keyPressed('p');
  43.  
  44. }
  45. void ofApp::setupMutexs(int index){
  46. mapFileHandle[index] = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, szNames[index].c_str());
  47. if (mapFileHandle[index] == NULL) {
  48. printf("Map File Failed to open\n");
  49. return;
  50. }
  51. texture.allocate(640, 480, GL_RGB);
  52. mutex[index] = OpenMutexW(SYNCHRONIZE, false, mutexNames[index].c_str());
  53. if (mutex[index] == NULL) {
  54. printf("No mutex found \n");
  55. }
  56. name.c_str();
  57.  
  58. }
  59. void ofApp::updateMutexs(int index){
  60. DWORD waitResult = WaitForSingleObject(mutex[index], 1000 / 60);
  61. if (waitResult == WAIT_OBJECT_0) {
  62. printf("Obtaining data \n");
  63. data = MapViewOfFile(mapFileHandle[index], FILE_MAP_ALL_ACCESS, 0, 0, size_of_frame);
  64. if (data != nullptr) {
  65. printf("Uploading Texture \n");
  66. ofPixels pix;
  67. pix.setFromExternalPixels((uint8_t*)data, 640, 480, ofPixelFormat::OF_PIXELS_RGB);
  68. textures[index].allocate(pix);
  69. }
  70. UnmapViewOfFile(mapFileHandle[index]);
  71. if (!ReleaseMutex(mutex[index])) {
  72. printf("Failed to release mutex \n");
  73. }
  74. }
  75. else {
  76. printf("x");
  77. }
  78. }
  79. //--------------------------------------------------------------
  80. void ofApp::update() {
  81. for (int i = 0; i < numberofmutex; i++) {
  82. updateMutexs(i);
  83.  
  84.  
  85. ofPixels pix;
  86. textures[i].readToPixels(pix);
  87.  
  88. for (int i = 0; i<pix.size(); i++) {
  89. unsigned char c = pix[i];
  90. (pix[i] > thressholdBrithness) ? (pix[i] = pix[i]) : (pix[i] = 0);
  91. }
  92.  
  93. textures[i].loadData(pix);
  94.  
  95. }
  96.  
  97.  
  98.  
  99. }
  100.  
  101. //--------------------------------------------------------------
  102. void ofApp::draw() {
  103. //ofBackground(0);
  104. for (int i = 0; i < numberofmutex; i++) {
  105. if (textures[i].isAllocated()) {
  106. // textures[i].draw(640*i, 0);
  107. }
  108. }
  109.  
  110. //textures[0].draw(0,0);
  111. //textures[0].draw(640, 0, 160, 120);
  112. //ofNoFill();
  113. kinectsFbo.begin();
  114. ofBackground(0);
  115. for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
  116. {
  117. if (this->textures[0].isAllocated()) {
  118. auto warp = this->warpController.getWarp(i);
  119. if (this->useBeginEnd)
  120. {
  121. warp->begin();
  122. auto bounds = warp->getBounds();
  123. this->textures[i].draw(i * 640, 0);
  124. warp->end();
  125. }
  126. else
  127. {
  128. warp->draw(textures[i], this->srcAreas[i]);
  129. }
  130. }
  131. }
  132. /*if (nocolor) {
  133. ofPopStyle();
  134. ofSetColor(0);
  135. ofRect(0, 0, ofGetWidth(), 100);
  136. ofRect(260, 0, ofGetWidth(), 100);
  137. ofPushStyle();
  138. }*/
  139. kinectsFbo.end();
  140. kinectsFbo.draw(0,0);
  141. ofDrawBitmapString(ofToString(thressholdBrithness, 0) + "Thresshold", 20, 200);
  142. ofDrawBitmapString(ofToString(ofGetFrameRate(), 0) + "FPS", 20, 240);
  143. }
  144.  
  145. //--------------------------------------------------------------
  146. void ofApp::keyPressed(int key) {
  147.  
  148.  
  149.  
  150. if (key == '+') {
  151. thressholdBrithness = thressholdBrithness++;
  152. (thressholdBrithness > 255) ? (thressholdBrithness = 255) : (thressholdBrithness);
  153. }
  154. if (key == '-') {
  155. thressholdBrithness = thressholdBrithness--;
  156. (thressholdBrithness < 0) ? (thressholdBrithness = 0) : (thressholdBrithness);
  157. }
  158. if (key == 'a') {
  159. nocolor = !nocolor;
  160. }
  161.  
  162.  
  163. if (key == 's') {
  164.  
  165. this->warpController.saveSettings("settings.json");
  166. }
  167. if (key == 'o')
  168. {
  169. ofToggleFullscreen();
  170. }
  171. if (key == 'p')
  172. {
  173. this->areaMode = (this->areaMode + 1) % 3;
  174. if (this->areaMode == 0)
  175. {
  176. auto area = ofRectangle(0, 0, 640, 480);
  177. for (auto i = 0; i < this->warpController.getNumWarps(); ++i)
  178. {
  179. this->srcAreas[i] = area;
  180. }
  181.  
  182. this->areaName = "full";
  183. }
  184.  
  185. }
  186. }
  187.  
  188. //--------------------------------------------------------------
  189. void ofApp::keyReleased(int key) {
  190.  
  191. }
  192.  
  193. //--------------------------------------------------------------
  194. void ofApp::mouseMoved(int x, int y) {
  195.  
  196. }
  197.  
  198. //--------------------------------------------------------------
  199. void ofApp::mouseDragged(int x, int y, int button) {
  200.  
  201. }
  202.  
  203. //--------------------------------------------------------------
  204. void ofApp::mousePressed(int x, int y, int button) {
  205.  
  206. }
  207.  
  208. //--------------------------------------------------------------
  209. void ofApp::mouseReleased(int x, int y, int button) {
  210.  
  211. }
  212.  
  213. //--------------------------------------------------------------
  214. void ofApp::mouseEntered(int x, int y) {
  215.  
  216. }
  217.  
  218. //--------------------------------------------------------------
  219. void ofApp::mouseExited(int x, int y) {
  220.  
  221. }
  222.  
  223. //--------------------------------------------------------------
  224. void ofApp::windowResized(int w, int h) {
  225.  
  226. }
  227.  
  228. //--------------------------------------------------------------
  229. void ofApp::gotMessage(ofMessage msg) {
  230.  
  231. }
  232.  
  233. //--------------------------------------------------------------
  234. void ofApp::dragEvent(ofDragInfo dragInfo) {
  235.  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement