stream_profile.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 <cstring> //for memcpy
6 #include "error.h"
7 #include "../../../include/librealsense2/rs.h"
8 
9 extern "C" JNIEXPORT void JNICALL
11  jlong handle, jobject params) {
12  rs2_stream stream_type = RS2_STREAM_ANY;
14  int index = -1;
15  int uniqueId = -1;
16  int frameRate = -1;
17  rs2_error *e = NULL;
18 
19  rs2_get_stream_profile_data((const rs2_stream_profile *) handle, &stream_type, &format, &index, &uniqueId, &frameRate, &e);
20  handle_error(env, e);
21 
22  jclass clazz = env->GetObjectClass(params);
23 
24  jfieldID typeField = env->GetFieldID(clazz, "type", "I");
25  jfieldID formatField = env->GetFieldID(clazz, "format", "I");
26  jfieldID indexField = env->GetFieldID(clazz, "index", "I");
27  jfieldID uniqueIdField = env->GetFieldID(clazz, "uniqueId", "I");
28  jfieldID frameRateField = env->GetFieldID(clazz, "frameRate", "I");
29 
30  env->SetIntField(params, typeField, stream_type);
31  env->SetIntField(params, formatField, format);
32  env->SetIntField(params, indexField, index);
33  env->SetIntField(params, uniqueIdField, uniqueId);
34  env->SetIntField(params, frameRateField, frameRate);
35 }
36 
37 extern "C" JNIEXPORT void JNICALL
39  jlong handle,
40  jobject params) {
41  int width = -1;
42  int height = -1;
43  rs2_error *e = NULL;
44 
45  rs2_get_video_stream_resolution((const rs2_stream_profile *) handle, &width, &height, &e);
46  handle_error(env, e);
47 
48  jclass clazz = env->GetObjectClass(params);
49 
50  jfieldID widthField = env->GetFieldID(clazz, "width", "I");
51  jfieldID heightField = env->GetFieldID(clazz, "height", "I");
52 
53  env->SetIntField(params, widthField, width);
54  env->SetIntField(params, heightField, height);
55 }
56 
57 extern "C" JNIEXPORT void JNICALL
59  jlong handle) {
61 }
62 
63 extern "C"
64 JNIEXPORT jboolean JNICALL
66  jlong handle,
67  jint extension) {
68  rs2_error *e = NULL;
69  int rv = rs2_stream_profile_is(reinterpret_cast<const rs2_stream_profile *>(handle),
70  static_cast<rs2_extension>(extension), &e);
71  handle_error(env, e);
72  return rv;
73 }
74 
75 extern "C"
76 JNIEXPORT void JNICALL
78  jlong handle, jlong otherHandle,
79  jobject extrinsic) {
80  rs2_error* e = nullptr;
82  rs2_get_extrinsics(reinterpret_cast<const rs2_stream_profile *>(handle),
83  reinterpret_cast<const rs2_stream_profile *>(otherHandle),&extr, &e);
84  handle_error(env, e);
85 
86  if (e != nullptr)
87  {
88  return;
89  }
90 
91  jclass clazz = env->GetObjectClass(extrinsic);
92 
93  //retrieving the array members
94  //mRotation
95  jfieldID rotation_field = env->GetFieldID(clazz, "mRotation", "[F");
96  jfloatArray rotationArray = env->NewFloatArray(9);
97  if (rotationArray != NULL)
98  {
99  env->SetFloatArrayRegion(rotationArray, 0, 9, reinterpret_cast<jfloat*>(&extr.rotation));
100  }
101  env->SetObjectField(extrinsic, rotation_field, rotationArray);
102 
103  //mTranslation
104  jfieldID translation_field = env->GetFieldID(clazz, "mTranslation", "[F");
105  jfloatArray translationArray = env->NewFloatArray(3);
106  if (translationArray != NULL)
107  {
108  env->SetFloatArrayRegion(translationArray, 0, 3, reinterpret_cast<jfloat*>(&extr.translation));
109  }
110  env->SetObjectField(extrinsic, translation_field, translationArray);
111 }
112 
113 extern "C"
114 JNIEXPORT void JNICALL
116  jlong fromHandle, jlong toHandle,
117  jobject extrinsic)
118 {
119  rs2_error* e = nullptr;
121 
122  //fill c++ extrinsic from java extrinsic data
123  jclass clazz = env->GetObjectClass(extrinsic);
124  //fill rotation
125  jfieldID rotation_field = env->GetFieldID(clazz, "mRotation", "[F");
126  jobject rotationObject = env->GetObjectField(extrinsic, rotation_field);
127  jfloatArray* rotationArray = reinterpret_cast<jfloatArray *>(&rotationObject);
128  jfloat * rotation = env->GetFloatArrayElements(*rotationArray, NULL);
129  memcpy(extr.rotation, rotation, 9 * sizeof(float));
130  env->ReleaseFloatArrayElements(*rotationArray, rotation, 0);
131  //fill translation
132  jfieldID translation_field = env->GetFieldID(clazz, "mTranslation", "[F");
133  jobject translationObject = env->GetObjectField(extrinsic, translation_field);
134  jfloatArray* translationArray = reinterpret_cast<jfloatArray *>(&translationObject);
135  jfloat * translation = env->GetFloatArrayElements(*translationArray, NULL);
136  memcpy(extr.translation, translation, 3 * sizeof(float));
137  env->ReleaseFloatArrayElements(*translationArray, translation, 0);
138 
139  //calling the api method
140  rs2_register_extrinsics(reinterpret_cast<const rs2_stream_profile *>(fromHandle),
141  reinterpret_cast<const rs2_stream_profile *>(toHandle), extr, &e);
142  handle_error(env, e);
143 }
144 
145 extern "C"
146 JNIEXPORT void JNICALL
148  jlong handle, jobject intrinsic) {
149  rs2_error* e = nullptr;
151  rs2_get_video_stream_intrinsics(reinterpret_cast<const rs2_stream_profile *>(handle), &intr, &e);
152  handle_error(env, e);
153 
154  if (e != nullptr)
155  {
156  return;
157  }
158 
159  jclass clazz = env->GetObjectClass(intrinsic);
160 
161  //retrieving all the built-in types members
162  jfieldID width_field = env->GetFieldID(clazz, "mWidth", "I");
163  jfieldID height_field = env->GetFieldID(clazz, "mHeight", "I");
164  jfieldID ppx_field = env->GetFieldID(clazz, "mPpx", "F");
165  jfieldID ppy_field = env->GetFieldID(clazz, "mPpy", "F");
166  jfieldID fx_field = env->GetFieldID(clazz, "mFx", "F");
167  jfieldID fy_field = env->GetFieldID(clazz, "mFy", "F");
168  jfieldID model_field = env->GetFieldID(clazz, "mModelValue", "I");
169 
170 
171  env->SetIntField(intrinsic, width_field, intr.width);
172  env->SetIntField(intrinsic, height_field, intr.height);
173  env->SetFloatField(intrinsic, ppx_field, intr.ppx);
174  env->SetFloatField(intrinsic, ppy_field, intr.ppy);
175  env->SetFloatField(intrinsic, fx_field, intr.fx);
176  env->SetFloatField(intrinsic, fy_field, intr.fy);
177  env->SetIntField(intrinsic, model_field, intr.model);
178 
179  //retrieving the array member
180  jfieldID coeff_field = env->GetFieldID(clazz, "mCoeffs", "[F");
181  jfloatArray coeffsArray = env->NewFloatArray(5);
182  if (coeffsArray != NULL)
183  {
184  env->SetFloatArrayRegion(coeffsArray, 0, 5, reinterpret_cast<jfloat*>(&intr.coeffs));
185  }
186  env->SetObjectField(intrinsic, coeff_field, coeffsArray);
187 }
188 
189 extern "C"
190 JNIEXPORT void JNICALL
192  jlong handle, jobject intrinsic) {
193  rs2_error* e = nullptr;
195  rs2_get_motion_intrinsics(reinterpret_cast<const rs2_stream_profile *>(handle), &intr, &e);
196  handle_error(env, e);
197 
198  if (e != nullptr)
199  {
200  return;
201  }
202 
203  jclass clazz = env->GetObjectClass(intrinsic);
204 
205  //retrieving the array members
206  //mData
207  jfieldID data_field = env->GetFieldID(clazz, "mData", "[F");
208  jfloatArray dataArray = env->NewFloatArray(12);
209  if (dataArray != NULL)
210  {
211  env->SetFloatArrayRegion(dataArray, 0, 12, reinterpret_cast<jfloat*>(&intr.data));
212  }
213  env->SetObjectField(intrinsic, data_field, dataArray);
214 
215  //mNoiseVariances
216  jfieldID noise_field = env->GetFieldID(clazz, "mNoiseVariances", "[F");
217  jfloatArray noiseArray = env->NewFloatArray(3);
218  if (noiseArray != NULL)
219  {
220  env->SetFloatArrayRegion(noiseArray, 0, 3, reinterpret_cast<jfloat*>(&intr.noise_variances));
221  }
222  env->SetObjectField(intrinsic, noise_field, noiseArray);
223 
224  //mBiasVariances
225  jfieldID bias_field = env->GetFieldID(clazz, "mBiasVariances", "[F");
226  jfloatArray biasArray = env->NewFloatArray(3);
227  if (biasArray != NULL)
228  {
229  env->SetFloatArrayRegion(biasArray, 0, 3, reinterpret_cast<jfloat*>(&intr.bias_variances));
230  }
231  env->SetObjectField(intrinsic, bias_field, biasArray);
232 }
void rs2_register_extrinsics(const rs2_stream_profile *from, const rs2_stream_profile *to, rs2_extrinsics extrin, rs2_error **error)
Definition: rs.cpp:1125
void rs2_get_video_stream_resolution(const rs2_stream_profile *mode, int *width, int *height, rs2_error **error)
Definition: rs.cpp:466
float translation[3]
Definition: rs_sensor.h:99
void rs2_get_extrinsics(const rs2_stream_profile *from, const rs2_stream_profile *to, rs2_extrinsics *extrin, rs2_error **error)
Definition: rs.cpp:1110
GLuint64 GLenum void * handle
Definition: glext.h:7785
void handle_error(JNIEnv *env, rs2_error *error)
Definition: error.cpp:6
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_MotionStreamProfile_nGetIntrinsic(JNIEnv *env, jclass type, jlong handle, jobject intrinsic)
int rs2_stream_profile_is(const rs2_stream_profile *mode, rs2_extension type, rs2_error **error)
Definition: rs.cpp:1504
float coeffs[5]
Definition: rs_types.h:67
e
Definition: rmse.py:177
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_StreamProfile_nDelete(JNIEnv *env, jclass type, jlong handle)
float rotation[9]
Definition: rs_sensor.h:98
GLuint index
void rs2_get_stream_profile_data(const rs2_stream_profile *mode, rs2_stream *stream, rs2_format *format, int *index, int *unique_id, int *framerate, rs2_error **error)
Definition: rs.cpp:484
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_VideoStreamProfile_nGetIntrinsic(JNIEnv *env, jclass type, jlong handle, jobject intrinsic)
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_StreamProfile_nGetProfile(JNIEnv *env, jclass type, jlong handle, jobject params)
void rs2_delete_stream_profile(rs2_stream_profile *mode)
Definition: rs.cpp:512
GLint GLsizei GLsizei height
GLint GLint GLsizei GLint GLenum format
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_VideoStreamProfile_nGetResolution(JNIEnv *env, jclass type, jlong handle, jobject params)
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_StreamProfile_nGetExtrinsicTo(JNIEnv *env, jclass type, jlong handle, jlong otherHandle, jobject extrinsic)
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
GLenum const GLfloat * params
JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_StreamProfile_nIsProfileExtendableTo(JNIEnv *env, jclass type, jlong handle, jint extension)
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void rs2_get_video_stream_intrinsics(const rs2_stream_profile *mode, rs2_intrinsics *intrinsics, rs2_error **error)
Definition: rs.cpp:374
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
rs2_distortion model
Definition: rs_types.h:66
GLenum type
rs2_extrinsics extr
Definition: test-pose.cpp:258
Video stream intrinsics.
Definition: rs_types.h:58
Motion device intrinsics: scale, bias, and variances.
Definition: rs_types.h:103
#define NULL
Definition: tinycthread.c:47
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_StreamProfile_nRegisterExtrinsic(JNIEnv *env, jclass type, jlong fromHandle, jlong toHandle, jobject extrinsic)
void rs2_get_motion_intrinsics(const rs2_stream_profile *mode, rs2_motion_device_intrinsic *intrinsics, rs2_error **error)
Definition: rs.cpp:455
GLint GLsizei width


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