android/jni/sensor.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include <jni.h>
5 #include <memory>
6 #include <vector>
7 #include "error.h"
8 
9 #include "../../../include/librealsense2/rs.h"
10 
11 extern "C"
12 JNIEXPORT void JNICALL
14  rs2_delete_sensor(reinterpret_cast<rs2_sensor *>(handle));
15 }
16 
17 extern "C"
18 JNIEXPORT jlongArray JNICALL
20  jlong handle) {
21  rs2_error* e = nullptr;
22  std::shared_ptr<rs2_stream_profile_list> list(
23  rs2_get_stream_profiles(reinterpret_cast<rs2_sensor *>(handle), &e),
25  handle_error(env, e);
26 
27  auto size = rs2_get_stream_profiles_count(list.get(), &e);
28  handle_error(env, e);
29 
30  std::vector<const rs2_stream_profile*> profiles;
31 
32  for (auto i = 0; i < size; i++)
33  {
34  auto sp = rs2_get_stream_profile(list.get(), i, &e);
35  handle_error(env, e);
36  profiles.push_back(sp);
37  }
38 
39  // jlong is 64-bit, but pointer in profiles could be 32-bit, copy element by element
40  jlongArray rv = env->NewLongArray(profiles.size());
41  for (auto i = 0; i < size; i++)
42  {
43  env->SetLongArrayRegion(rv, i, 1, reinterpret_cast<const jlong *>(&profiles[i]));
44  }
45  return rv;
46 }
47 
48 extern "C"
49 JNIEXPORT jboolean JNICALL
51  jlong handle, jint extension) {
52  rs2_error *e = NULL;
53  int rv = rs2_is_sensor_extendable_to(reinterpret_cast<const rs2_sensor *>(handle),
54  static_cast<rs2_extension>(extension), &e);
55  handle_error(env, e);
56  return rv > 0;
57 }
58 
59 
60 extern "C"
61 JNIEXPORT void JNICALL
63  jlong handle, jint min_x,
64  jint min_y, jint max_x,
65  jint max_y) {
66  rs2_error* e = nullptr;
67  rs2_set_region_of_interest(reinterpret_cast<rs2_sensor *>(handle), min_x, min_y, max_x, max_y, &e);
68  handle_error(env, e);
69 }
70 
71 extern "C"
72 JNIEXPORT void JNICALL
74  jlong handle, jobject roi) {
75  int min_x, min_y, max_x, max_y;
76  rs2_error *e = nullptr;
77  rs2_get_region_of_interest(reinterpret_cast<rs2_sensor *>(handle), &min_x, &min_y, &max_x, &max_y, &e);
78  handle_error(env, e);
79 
80  if(e)
81  return;
82 
83  jclass clazz = env->GetObjectClass(roi);
84 
85  jfieldID min_x_field = env->GetFieldID(clazz, "minX", "I");
86  jfieldID min_y_field = env->GetFieldID(clazz, "minY", "I");
87  jfieldID max_x_field = env->GetFieldID(clazz, "maxX", "I");
88  jfieldID max_y_field = env->GetFieldID(clazz, "maxY", "I");
89 
90  env->SetIntField(roi, min_x_field, min_x);
91  env->SetIntField(roi, min_y_field, min_y);
92  env->SetIntField(roi, max_x_field, max_x);
93  env->SetIntField(roi, max_y_field, max_y);
94 }
95 
96 extern "C"
97 JNIEXPORT jfloat JNICALL
99  jlong handle) {
100  rs2_error* e = nullptr;
101  float depthScale = rs2_get_depth_scale(reinterpret_cast<rs2_sensor *>(handle), &e);
102  handle_error(env, e);
103  return depthScale;
104 }
float rs2_get_depth_scale(rs2_sensor *sensor, rs2_error **error)
Definition: rs.cpp:2312
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_RoiSensor_nSetRegionOfInterest(JNIEnv *env, jclass clazz, jlong handle, jint min_x, jint min_y, jint max_x, jint max_y)
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Sensor_nRelease(JNIEnv *env, jclass type, jlong handle)
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_RoiSensor_nGetRegionOfInterest(JNIEnv *env, jclass type, jlong handle, jobject roi)
JNIEXPORT jlongArray JNICALL Java_com_intel_realsense_librealsense_Sensor_nGetStreamProfiles(JNIEnv *env, jclass type, jlong handle)
GLuint64 GLenum void * handle
Definition: glext.h:7785
void rs2_set_region_of_interest(const rs2_sensor *sensor, int min_x, int min_y, int max_x, int max_y, rs2_error **error)
sets the active region of interest to be used by auto-exposure algorithm
Definition: rs.cpp:1224
void handle_error(JNIEnv *env, rs2_error *error)
Definition: error.cpp:6
e
Definition: rmse.py:177
rs2_stream_profile_list * rs2_get_stream_profiles(rs2_sensor *sensor, rs2_error **error)
Definition: rs.cpp:327
JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Sensor_nIsSensorExtendableTo(JNIEnv *env, jclass type, jlong handle, jint extension)
GLsizeiptr size
void rs2_delete_sensor(rs2_sensor *sensor)
Definition: rs.cpp:320
void rs2_get_region_of_interest(const rs2_sensor *sensor, int *min_x, int *min_y, int *max_x, int *max_y, rs2_error **error)
gets the active region of interest to be used by auto-exposure algorithm
Definition: rs.cpp:1238
const rs2_stream_profile * rs2_get_stream_profile(const rs2_stream_profile_list *list, int index, rs2_error **error)
Definition: rs.cpp:351
int rs2_is_sensor_extendable_to(const rs2_sensor *sensor, rs2_extension extension, rs2_error **error)
Definition: rs.cpp:1394
GLenum type
void rs2_delete_stream_profiles_list(rs2_stream_profile_list *list)
Definition: rs.cpp:367
#define NULL
Definition: tinycthread.c:47
JNIEXPORT jfloat JNICALL Java_com_intel_realsense_librealsense_DepthSensor_nGetDepthScale(JNIEnv *env, jclass clazz, jlong handle)
int i
int rs2_get_stream_profiles_count(const rs2_stream_profile_list *list, rs2_error **error)
Definition: rs.cpp:360


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41