Advertisement
Guest User

openni android patch

a guest
Feb 2nd, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.23 KB | None | 0 0
  1. diff --git a/Include/OniCAPI.h b/Include/OniCAPI.h
  2. index aea426d..fceaa6f 100644
  3. --- a/Include/OniCAPI.h
  4. +++ b/Include/OniCAPI.h
  5. @@ -30,6 +30,7 @@
  6.  
  7. /** Initialize OpenNI2. Use ONI_API_VERSION as the version. */
  8. ONI_C_API OniStatus oniInitialize(int apiVersion);
  9. +ONI_C_API void oniSetLibraryPath(char const *p);
  10. /** Shutdown OpenNI2 */
  11. ONI_C_API void oniShutdown();
  12.  
  13. diff --git a/Include/OpenNI.h b/Include/OpenNI.h
  14. index 52324b4..53e210d 100644
  15. --- a/Include/OpenNI.h
  16. +++ b/Include/OpenNI.h
  17. @@ -2099,6 +2099,12 @@ public:
  18. return (Status)oniInitialize(ONI_API_VERSION); // provide version of API, to make sure proper struct sizes are used
  19. }
  20.  
  21. + static void setLibraryPath(char const *p)
  22. + {
  23. + oniSetLibraryPath(p);
  24. + }
  25. +
  26. +
  27. /**
  28. Stop using the library. Unload all drivers, close all streams and devices.
  29. Once @ref shutdown was called, no other calls to OpenNI is allowed.
  30. diff --git a/Samples/AndroidRead/Android.mk b/Samples/AndroidRead/Android.mk
  31. new file mode 100644
  32. index 0000000..08f38c4
  33. --- /dev/null
  34. +++ b/Samples/AndroidRead/Android.mk
  35. @@ -0,0 +1,48 @@
  36. +# OpenNI 2.x Android makefile.
  37. +# Copyright (C) 2012 PrimeSense Ltd.
  38. +#
  39. +# Licensed under the Apache License, Version 2.0 (the "License");
  40. +# you may not use this file except in compliance with the License.
  41. +# You may obtain a copy of the License at
  42. +#
  43. +# http://www.apache.org/licenses/LICENSE-2.0
  44. +#
  45. +# Unless required by applicable law or agreed to in writing, software
  46. +# distributed under the License is distributed on an "AS IS" BASIS,
  47. +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  48. +# See the License for the specific language governing permissions and
  49. +# limitations under the License.
  50. +
  51. +LOCAL_PATH := $(call my-dir)
  52. +
  53. +include $(CLEAR_VARS)
  54. +
  55. +# Sources
  56. +MY_SRC_FILES := \
  57. + $(LOCAL_PATH)/*.cpp
  58. +
  59. +MY_SRC_FILE_EXPANDED := $(wildcard $(MY_SRC_FILES))
  60. +LOCAL_SRC_FILES := $(MY_SRC_FILE_EXPANDED:$(LOCAL_PATH)/%=%)
  61. +
  62. +# C/CPP Flags
  63. +LOCAL_CFLAGS += $(OPENNI2_CFLAGS) -DANDROID_MODULE
  64. +
  65. +# Includes
  66. +LOCAL_C_INCLUDES := \
  67. + $(LOCAL_PATH)/../../Include \
  68. + $(LOCAL_PATH)/../Common
  69. +LOCAL_LDFLAGS := -llog
  70. +
  71. +LOCAL_STATIC_LIBRARIES += libstlport
  72. +
  73. +LOCAL_C_INCLUDES += external/stlport/stlport
  74. +LOCAL_C_INCLUDES += bionic
  75. +
  76. +# Dependencies
  77. +LOCAL_SHARED_LIBRARIES := libOpenNI2
  78. +
  79. +# Output
  80. +LOCAL_MODULE := AndroidRead
  81. +
  82. +#include $(BUILD_EXECUTABLE)
  83. +include $(BUILD_SHARED_LIBRARY)
  84. diff --git a/Samples/AndroidRead/Makefile b/Samples/AndroidRead/Makefile
  85. new file mode 100644
  86. index 0000000..9904e93
  87. --- /dev/null
  88. +++ b/Samples/AndroidRead/Makefile
  89. @@ -0,0 +1,17 @@
  90. +include ../../ThirdParty/PSCommon/BuildSystem/CommonDefs.mak
  91. +
  92. +BIN_DIR = ../../Bin
  93. +
  94. +INC_DIRS = \
  95. + ../../Include \
  96. + ../Common
  97. +
  98. +SRC_FILES = *.cpp
  99. +
  100. +USED_LIBS += OpenNI2
  101. +
  102. +EXE_NAME = SimpleRead
  103. +
  104. +CFLAGS += -Wall
  105. +
  106. +include ../../ThirdParty/PSCommon/BuildSystem/CommonCppMakefile
  107. diff --git a/Samples/AndroidRead/com_zero997_structurescanner_StructureScanner.h b/Samples/AndroidRead/com_zero997_structurescanner_StructureScanner.h
  108. new file mode 100644
  109. index 0000000..59854b3
  110. --- /dev/null
  111. +++ b/Samples/AndroidRead/com_zero997_structurescanner_StructureScanner.h
  112. @@ -0,0 +1,45 @@
  113. +/* DO NOT EDIT THIS FILE - it is machine generated */
  114. +#include <jni.h>
  115. +/* Header for class com_zero997_structurescanner_StructureScanner */
  116. +
  117. +#ifndef _Included_com_zero997_structurescanner_StructureScanner
  118. +#define _Included_com_zero997_structurescanner_StructureScanner
  119. +#ifdef __cplusplus
  120. +extern "C" {
  121. +#endif
  122. +/*
  123. + * Class: com_zero997_structurescanner_StructureScanner
  124. + * Method: scan
  125. + * Signature: ()[I
  126. + */
  127. +JNIEXPORT jintArray JNICALL Java_com_zero997_structurescanner_StructureScanner_scan
  128. + (JNIEnv *, jobject);
  129. +
  130. +/*
  131. + * Class: com_zero997_structurescanner_StructureScanner
  132. + * Method: open
  133. + * Signature: ()I
  134. + */
  135. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_open
  136. + (JNIEnv *, jobject);
  137. +
  138. +/*
  139. + * Class: com_zero997_structurescanner_StructureScanner
  140. + * Method: setLibraryDir
  141. + * Signature: (Ljava/lang/String;)I
  142. + */
  143. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_setLibraryDir
  144. + (JNIEnv *, jobject, jstring);
  145. +
  146. +/*
  147. + * Class: com_zero997_structurescanner_StructureScanner
  148. + * Method: close
  149. + * Signature: ()I
  150. + */
  151. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_close
  152. + (JNIEnv *, jobject);
  153. +
  154. +#ifdef __cplusplus
  155. +}
  156. +#endif
  157. +#endif
  158. diff --git a/Samples/AndroidRead/java/com/zero997/structurescanner/StructureScanner.java b/Samples/AndroidRead/java/com/zero997/structurescanner/StructureScanner.java
  159. new file mode 100644
  160. index 0000000..c4164cf
  161. --- /dev/null
  162. +++ b/Samples/AndroidRead/java/com/zero997/structurescanner/StructureScanner.java
  163. @@ -0,0 +1,170 @@
  164. +package com.zero997.structurescanner;
  165. +
  166. +import android.app.PendingIntent;
  167. +import android.content.BroadcastReceiver;
  168. +import android.content.Context;
  169. +import android.content.Intent;
  170. +import android.content.IntentFilter;
  171. +import android.hardware.usb.UsbDevice;
  172. +import android.hardware.usb.UsbDeviceConnection;
  173. +import android.hardware.usb.UsbManager;
  174. +import android.util.Log;
  175. +
  176. +import java.io.DataOutputStream;
  177. +import java.io.IOException;
  178. +import java.util.HashMap;
  179. +import java.util.Iterator;
  180. +
  181. +/**
  182. + * Created by developer on 16.01.15.
  183. + */
  184. +public class StructureScanner {
  185. +
  186. + Context parent = null;
  187. + private boolean active = false;
  188. +
  189. + static {
  190. + System.loadLibrary("usb");
  191. + System.loadLibrary("OniFile");
  192. + System.loadLibrary("PS1080");
  193. + System.loadLibrary("PSLink");
  194. + System.loadLibrary("OpenNI2");
  195. + System.loadLibrary("AndroidRead");
  196. + }
  197. +
  198. + public StructureScanner(Context ctx)
  199. + {
  200. + parent = ctx;
  201. + setLibraryDir(ctx.getApplicationInfo().nativeLibraryDir);
  202. +
  203. +/* try {
  204. + Process su = Runtime.getRuntime().exec("su");
  205. + DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
  206. +
  207. + outputStream.writeBytes("chmod -R 777 /dev/bus/usb/*\n");
  208. + outputStream.flush();
  209. +
  210. + outputStream.writeBytes("exit\n");
  211. + outputStream.flush();
  212. + su.waitFor();
  213. +
  214. + } catch (IOException e)
  215. + {
  216. + Log.e("StructureSensor", "Could not set permissions");
  217. + }
  218. + catch (InterruptedException e)
  219. + {
  220. + Log.e("StructureSensor", "Timeout waiting for superuser");
  221. +
  222. +
  223. + }
  224. +*/
  225. + }
  226. +
  227. + public int[] safe_scan(){
  228. + if (active)
  229. + return scan();
  230. +
  231. + return new int[0];
  232. + }
  233. +
  234. + public void safe_open(){
  235. + if (active)
  236. + open();
  237. + }
  238. +
  239. + public void safe_close(){
  240. + if (active)
  241. + close();
  242. + }
  243. +
  244. +
  245. + private native int[] scan();
  246. +
  247. + private native int open();
  248. +
  249. + private native int setLibraryDir(String libraryDir);
  250. +
  251. + private native int close();
  252. +
  253. + private UsbDeviceConnection conn = null;
  254. + UsbManager manager = null;
  255. +
  256. + private static final String ACTION_USB_PERMISSION =
  257. + "com.android.example.USB_PERMISSION";
  258. + private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
  259. +
  260. + public void onReceive(Context context, Intent intent) {
  261. + String action = intent.getAction();
  262. + if (ACTION_USB_PERMISSION.equals(action)) {
  263. + synchronized (this) {
  264. + UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
  265. +
  266. + if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
  267. + if(device != null){
  268. + Log.v("StructureScanner","Permission granted");
  269. + conn = manager.openDevice(device);
  270. + active = true;
  271. + //call method to set up device communication
  272. + }
  273. + }
  274. + else {
  275. + Log.d("StructureScanner", "permission denied for device :" + device);
  276. + }
  277. + }
  278. + }
  279. + }
  280. + };
  281. +
  282. + public boolean isActive()
  283. + {
  284. + return active;
  285. + }
  286. +
  287. + public boolean activate()
  288. + {
  289. + manager = (UsbManager) parent.getSystemService(Context.USB_SERVICE);
  290. + HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
  291. + Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
  292. + String alldevices = "";
  293. + UsbDevice device = null;
  294. +
  295. + boolean found = false;
  296. + while(deviceIterator.hasNext()){
  297. + device = deviceIterator.next();
  298. + alldevices = alldevices + " " + device.getDeviceName();
  299. + Log.v("StructureSensor", String.format("%s Vendor: %d Product: %d Class: %d Subclass :%d Protocol: %d", device.getDeviceName(), device.getVendorId(), device.getProductId(), device.getDeviceClass(), device.getDeviceSubclass(), device.getDeviceProtocol()));
  300. + if (device.getVendorId() == 7463 && device.getProductId() == 1536)
  301. + {
  302. + found = true;
  303. + break;
  304. + }
  305. + }
  306. + if (found)
  307. + {
  308. + PendingIntent mPermissionIntent = PendingIntent.getBroadcast(parent, 0, new Intent(ACTION_USB_PERMISSION), 0);
  309. + IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
  310. + parent.registerReceiver(mUsbReceiver, filter);
  311. + manager.requestPermission(device, mPermissionIntent);
  312. + }
  313. +
  314. + return found;
  315. + }
  316. +
  317. +
  318. +
  319. + public void deactivate()
  320. + {
  321. + safe_close();
  322. + if (manager != null && conn != null)
  323. + conn.close();
  324. +
  325. + if (mUsbReceiver != null && active)
  326. + parent.unregisterReceiver(mUsbReceiver);
  327. + active = false;
  328. + }
  329. +
  330. +
  331. +
  332. +}
  333. +
  334. diff --git a/Samples/AndroidRead/main.cpp b/Samples/AndroidRead/main.cpp
  335. new file mode 100644
  336. index 0000000..9dd9250
  337. --- /dev/null
  338. +++ b/Samples/AndroidRead/main.cpp
  339. @@ -0,0 +1,318 @@
  340. +/*****************************************************************************
  341. +* *
  342. +* OpenNI 2.x Alpha *
  343. +* Copyright (C) 2012 PrimeSense Ltd. *
  344. +* *
  345. +* This file is part of OpenNI. *
  346. +* *
  347. +* Licensed under the Apache License, Version 2.0 (the "License"); *
  348. +* you may not use this file except in compliance with the License. *
  349. +* You may obtain a copy of the License at *
  350. +* *
  351. +* http://www.apache.org/licenses/LICENSE-2.0 *
  352. +* *
  353. +* Unless required by applicable law or agreed to in writing, software *
  354. +* distributed under the License is distributed on an "AS IS" BASIS, *
  355. +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  356. +* See the License for the specific language governing permissions and *
  357. +* limitations under the License. *
  358. +* *
  359. +*****************************************************************************/
  360. +#include <stdio.h>
  361. +#include <OpenNI.h>
  362. +
  363. +#include "OniSampleUtilities.h"
  364. +
  365. +
  366. +#define SAMPLE_READ_WAIT_TIMEOUT 2000 //2000ms
  367. +
  368. +using namespace openni;
  369. +
  370. +#ifdef ANDROID_MODULE
  371. +#include <jni.h>
  372. +#include <android/log.h>
  373. +#include "com_zero997_structurescanner_StructureScanner.h"
  374. +
  375. +
  376. +
  377. +//globals
  378. +Device device;
  379. +VideoStream depth;
  380. +int structure_state = 0;
  381. +
  382. +
  383. +
  384. +
  385. +int structure_open()
  386. +{
  387. + if (structure_state != 0)
  388. + {
  389. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Can not open sensor: Wrong state");
  390. + return -1;
  391. + }
  392. +
  393. + Status rc = OpenNI::initialize();
  394. + if (rc != STATUS_OK)
  395. + {
  396. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Initialize failed: ");
  397. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor",OpenNI::getExtendedError());
  398. + return 1;
  399. + }
  400. +
  401. + rc = device.open(ANY_DEVICE);
  402. + if (rc != STATUS_OK)
  403. + {
  404. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","Couldn't open device:");
  405. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", OpenNI::getExtendedError());
  406. + return 2;
  407. + }
  408. +
  409. + if (device.getSensorInfo(SENSOR_DEPTH) != NULL)
  410. + {
  411. + rc = depth.create(device, SENSOR_DEPTH);
  412. + if (rc != STATUS_OK)
  413. + {
  414. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","Couldn't create depth stream:");
  415. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", OpenNI::getExtendedError());
  416. + return 3;
  417. + }
  418. + }
  419. +
  420. + const SensorInfo *sinfo = device.getSensorInfo(SENSOR_DEPTH);
  421. + const Array< VideoMode> &depths = sinfo->getSupportedVideoModes();
  422. +
  423. + int selectedMode = 0;
  424. + for (int idx = 0; idx < depths.getSize(); idx ++)
  425. + {
  426. + int resX = depths[idx].getResolutionX();
  427. + int resY = depths[idx].getResolutionY();
  428. + int fps = depths[idx].getFps();
  429. + //std::cout<< resX<<"x"<<resY<<"@"<<fps<<std::endl;
  430. + if (resX == 640 && resY == 480)
  431. + {
  432. + selectedMode = idx;
  433. + }
  434. +
  435. + }
  436. +
  437. + printf ("Selected mode: %d",selectedMode);
  438. + rc = depth.setVideoMode(depths[selectedMode]);
  439. +
  440. + if (STATUS_OK != rc)
  441. + {
  442. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "error: depth fromat not supprted...");
  443. + }
  444. +
  445. + structure_state = 1;
  446. + return 0;
  447. +}
  448. +
  449. +
  450. +unsigned int structure_scan (jint **data)
  451. +{
  452. + unsigned int frameSize = 0;
  453. + if (structure_state != 1)
  454. + {
  455. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Can not scan: Sensor not opened");
  456. + return 0;
  457. + }
  458. +
  459. +
  460. + *data = NULL;
  461. +
  462. + Status rc = depth.start();
  463. + if (rc != STATUS_OK)
  464. + {
  465. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","Couldn't start the depth stream");
  466. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", OpenNI::getExtendedError());
  467. + return 0;
  468. + }
  469. +
  470. + VideoFrameRef frame;
  471. +
  472. + int depthValue = -1;
  473. + bool frameFinished = false;
  474. + int timeout = 10;
  475. + while (!frameFinished && timeout > 0)
  476. + {
  477. + int changedStreamDummy;
  478. + VideoStream* pStream = &depth;
  479. + rc = OpenNI::waitForAnyStream(&pStream, 1, &changedStreamDummy, SAMPLE_READ_WAIT_TIMEOUT);
  480. + if (rc != STATUS_OK)
  481. + {
  482. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","Wait failed!:");
  483. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor",OpenNI::getExtendedError());
  484. + continue;
  485. + }
  486. +
  487. + rc = depth.readFrame(&frame);
  488. + if (rc != STATUS_OK)
  489. + {
  490. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Read failed!");
  491. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor",OpenNI::getExtendedError());
  492. + continue;
  493. + }
  494. +
  495. + if (frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_1_MM && frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_100_UM)
  496. + {
  497. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","Unexpected frame format");
  498. + continue;
  499. + }
  500. +
  501. + DepthPixel* pDepth = (DepthPixel*)frame.getData();
  502. + if (pDepth)
  503. + {
  504. + int w = frame.getWidth();
  505. + int h = frame.getHeight();
  506. + int stride = frame.getStrideInBytes()/sizeof(DepthPixel);
  507. +
  508. + frameSize = frame.getHeight()*frame.getWidth();
  509. + __android_log_print(ANDROID_LOG_ERROR, "StructureSensor","Valid depth data received %d",frameSize);
  510. + __android_log_print(ANDROID_LOG_ERROR, "StructureSensor","Stride %d",stride);
  511. +
  512. + *data = (jint *)malloc(frameSize*sizeof(jint));
  513. +
  514. + for (int y = 0; y<h; y++)
  515. + for (int x = 0; x<w; x++)
  516. + {
  517. + (*data)[y*w+x] = pDepth[y*stride+x];
  518. + }
  519. + }
  520. + else
  521. + {
  522. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor","No depth data received");
  523. + }
  524. +
  525. + frameFinished = true;
  526. +
  527. + timeout --;
  528. + }
  529. +
  530. + depth.stop();
  531. + return frameSize;
  532. +}
  533. +
  534. +int structure_close()
  535. +{
  536. +
  537. + if (structure_state != 1)
  538. + {
  539. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Can not close sensor: Not opened");
  540. + return -1;
  541. + }
  542. +
  543. + depth.destroy();
  544. + device.close();
  545. + OpenNI::shutdown();
  546. +
  547. + structure_state = 0;
  548. + return 0;
  549. +}
  550. +
  551. +
  552. +
  553. +
  554. +
  555. +
  556. +extern "C" {
  557. +
  558. +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
  559. +{
  560. +
  561. + __android_log_write(ANDROID_LOG_INFO, "StructureSensor", "Loading Native StructureSensor API");
  562. +
  563. + #warning "*** BIG FAT SECURITY WARNING ! ! ! Read sourcecode for more information"
  564. +
  565. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "*** BIG FAT SECURITY WARNING ! ! !");
  566. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "***");
  567. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "*** THIS COMPLETELY UNDERMINES THE SECURITY RESTRICTIONS IMPOSED BY");
  568. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "*** ANDROID FOR ACCESING USB DEVICES. YOU CAN ONLY USE THIS IS YOU");
  569. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "*** HAVE ROOTED YOUR DEVICE AND IF YOU ABSOLUTELY KNOW WHAT SECURITY");
  570. + __android_log_write(ANDROID_LOG_WARN,"StructureSensor", "*** IMPLICATIONS THIS HAS");
  571. +
  572. +/* int r = system("su -c \"chmod -R 777 /proc/bus/usb/\"");
  573. + if(r!=0) {
  574. + __android_log_write(ANDROID_LOG_ERROR,"StructureSensor", "Can't grant permissions to USB");
  575. + }
  576. +*/
  577. + return JNI_VERSION_1_4;
  578. +}
  579. +
  580. +
  581. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_open
  582. + (JNIEnv *env, jobject obj)
  583. +{
  584. +
  585. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "StructureSensor.open()");
  586. +
  587. + int ret = 0;
  588. +
  589. + ret = structure_open();
  590. +
  591. + return ret;
  592. +}
  593. +
  594. +
  595. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_setLibraryDir
  596. + (JNIEnv *env, jobject obj, jstring libdir)
  597. +{
  598. +
  599. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "StructureSensor.setLibraryPath()");
  600. +
  601. + int ret = 0;
  602. + const char *libraryPath = env->GetStringUTFChars(libdir, 0);
  603. +
  604. + OpenNI::setLibraryPath(libraryPath);
  605. +
  606. + env->ReleaseStringUTFChars(libdir, libraryPath);
  607. +
  608. + return ret;
  609. +}
  610. +
  611. +
  612. +
  613. +
  614. +JNIEXPORT jintArray JNICALL Java_com_zero997_structurescanner_StructureScanner_scan
  615. + (JNIEnv *env, jobject obj)
  616. +{
  617. + jint *data=NULL;
  618. + int size=0;
  619. + int idx = 0;
  620. +
  621. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "StructureSensor.scan()");
  622. +
  623. + size = structure_scan(&data);
  624. +
  625. + jintArray intJavaArray = env->NewIntArray(size);
  626. +
  627. + if (size > 0 && data && intJavaArray)
  628. + {
  629. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "Copy result");
  630. +
  631. + env->SetIntArrayRegion(intJavaArray, 0, size, data);
  632. + }
  633. + if (data)
  634. + {
  635. + free(data);
  636. + }
  637. +
  638. + return intJavaArray;
  639. +}
  640. +
  641. +
  642. +JNIEXPORT jint JNICALL Java_com_zero997_structurescanner_StructureScanner_close
  643. + (JNIEnv *env, jobject obj)
  644. +{
  645. +
  646. + __android_log_write(ANDROID_LOG_ERROR, "StructureSensor", "StructureSensor.close()");
  647. +
  648. + return structure_close();
  649. +}
  650. +
  651. +
  652. +}
  653. +
  654. +
  655. +
  656. +#endif
  657. +
  658. diff --git a/Source/Core/OniContext.cpp b/Source/Core/OniContext.cpp
  659. index 153c7c6..a47e765 100644
  660. --- a/Source/Core/OniContext.cpp
  661. +++ b/Source/Core/OniContext.cpp
  662. @@ -236,7 +236,15 @@ XnStatus Context::loadLibraries(const char* directoryName)
  663. XnChar workingDir[XN_FILE_MAX_PATH];
  664. xnOSGetCurrentDir(workingDir, XN_FILE_MAX_PATH);
  665. // Change directory
  666. - xnOSSetCurrentDir(directoryName);
  667. +
  668. + if (m_overrideLibraryDirectory[0] != 0)
  669. + {
  670. + xnOSSetCurrentDir(m_overrideLibraryDirectory);
  671. + }
  672. + else
  673. + {
  674. + xnOSSetCurrentDir(directoryName);
  675. + }
  676.  
  677. for (int i = 0; i < nFileCount; ++i)
  678. {
  679. diff --git a/Source/Core/OniContext.h b/Source/Core/OniContext.h
  680. index d9ee2af..c1ad5e4 100644
  681. --- a/Source/Core/OniContext.h
  682. +++ b/Source/Core/OniContext.h
  683. @@ -58,6 +58,8 @@ public:
  684. Context();
  685. ~Context();
  686.  
  687. + char m_overrideLibraryDirectory[XN_FILE_MAX_PATH];
  688. +
  689. OniStatus initialize();
  690. void shutdown();
  691.  
  692. diff --git a/Source/Core/OpenNI.cpp b/Source/Core/OpenNI.cpp
  693. index 8c4e608..f9b0c76 100644
  694. --- a/Source/Core/OpenNI.cpp
  695. +++ b/Source/Core/OpenNI.cpp
  696. @@ -26,6 +26,12 @@
  697.  
  698. oni::implementation::Context g_Context;
  699.  
  700. +ONI_C_API void oniSetLibraryPath(char const *p)
  701. +{
  702. + strncpy(g_Context.m_overrideLibraryDirectory, p, XN_FILE_MAX_PATH-1);
  703. +}
  704. +
  705. +
  706. ONI_C_API OniStatus oniInitialize(int /*apiVersion*/)
  707. {
  708. g_Context.clearErrorLogger();
  709. @@ -514,4 +520,4 @@ ONI_C_API OniStatus oniCoordinateConverterDepthToColor(OniStreamHandle depthStre
  710. return depthStream->pStream->convertDepthToColorCoordinates(colorStream->pStream, depthX, depthY, depthZ, pColorX, pColorY);
  711. }
  712.  
  713. -XN_API_EXPORT_INIT()
  714. \ No newline at end of file
  715. +XN_API_EXPORT_INIT()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement