2#define LOG_TAG "org.visp.utils.Converters"
5jlongArray vector_vpColVector_to_List(JNIEnv *env,
const std::vector<vpColVector> &V)
7 jlongArray result = env->NewLongArray(V.size());
8 jlong *body = env->GetLongArrayElements(result, 0);
10 for (
size_t i = 0; i < V.size(); i++) {
14 env->ReleaseLongArrayElements(result, body, 0);
18jlongArray vector_vpHomogeneousMatrix_to_List(JNIEnv *env,
const std::vector<vpHomogeneousMatrix> &V)
20 jlongArray result = env->NewLongArray(V.size());
21 jlong *body = env->GetLongArrayElements(result, 0);
23 for (
size_t i = 0; i < V.size(); i++) {
27 env->ReleaseLongArrayElements(result, body, 0);
31std::vector<vpHomogeneousMatrix> List_to_vector_vpHomogeneousMatrix(JNIEnv *env, jlongArray arr)
33 jlong *body = env->GetLongArrayElements(arr, 0);
34 int len = env->GetArrayLength(arr);
36 std::vector<vpHomogeneousMatrix> V(len);
37 for (
int i = 0; i < len; i++) {
42 env->ReleaseLongArrayElements(arr, body, 0);
46std::vector<vpCameraParameters> List_to_vector_vpCameraParameters(JNIEnv *env, jlongArray arr)
48 jlong *body = env->GetLongArrayElements(arr, 0);
49 int len = env->GetArrayLength(arr);
51 std::vector<vpCameraParameters> V(len);
52 for (
int i = 0; i < len; i++) {
57 env->ReleaseLongArrayElements(arr, body, 0);
61std::vector<int> List_to_vector_int(JNIEnv *env, jintArray arr)
63 jint *body = env->GetIntArrayElements(arr, 0);
64 int len = env->GetArrayLength(arr);
66 std::vector<int> V(len);
67 for (
int i = 0; i < len; i++) {
71 env->ReleaseIntArrayElements(arr, body, 0);
75std::vector<float> List_to_vector_float(JNIEnv *env, jfloatArray arr)
77 jfloat *body = env->GetFloatArrayElements(arr, 0);
78 int len = env->GetArrayLength(arr);
80 std::vector<float> V(len);
81 for (
int i = 0; i < len; i++) {
85 env->ReleaseFloatArrayElements(arr, body, 0);
89std::vector<double> List_to_vector_double(JNIEnv *env, jdoubleArray arr)
91 jdouble *body = env->GetDoubleArrayElements(arr, 0);
92 int len = env->GetArrayLength(arr);
94 std::vector<double> V(len);
95 for (
int i = 0; i < len; i++) {
99 env->ReleaseDoubleArrayElements(arr, body, 0);
103jobjectArray vector_vector_vpImagePoint_to_List(JNIEnv *env,
const std::vector<std::vector<vpImagePoint> > &V)
109 size_t outerSize = V.size();
110 jobjectArray outerArray = env->NewObjectArray(outerSize, env->FindClass(
"java/lang/Object"), NULL);
112 for (
int i = 0; i < env->GetArrayLength(outerArray); i++) {
113 size_t innerSize = V[i].size();
114 jlongArray longArray = env->NewLongArray(innerSize);
115 jlong *longArrayElements = env->GetLongArrayElements(longArray, 0);
117 for (
int j = 0; j < env->GetArrayLength(longArray); j++) {
118 longArrayElements[j] = (jlong)
new vpImagePoint(V[i][j]);
121 env->ReleaseLongArrayElements(longArray, longArrayElements, 0);
122 env->SetObjectArrayElement(outerArray, i, longArray);
128jobjectArray vector_vector_double_to_List(JNIEnv *env,
const std::vector<std::vector<double> > &V)
134 size_t outerSize = V.size();
135 jobjectArray outerArray = env->NewObjectArray(outerSize, env->FindClass(
"java/lang/Object"), NULL);
137 for (
int i = 0; i < env->GetArrayLength(outerArray); i++) {
138 size_t innerSize = V[i].size();
139 jdoubleArray doubleArray = env->NewDoubleArray(innerSize);
140 jdouble *doubleArrayElements = env->GetDoubleArrayElements(doubleArray, 0);
142 for (
int j = 0; j < env->GetArrayLength(doubleArray); j++) {
143 doubleArrayElements[j] = (jdouble)V[i][j];
146 env->ReleaseDoubleArrayElements(doubleArray, doubleArrayElements, 0);
147 env->SetObjectArrayElement(outerArray, i, doubleArray);
153std::string convertTo(JNIEnv *env, jstring jstr)
155 const char *rawString = env->GetStringUTFChars(jstr, 0);
156 std::string cppString(rawString ? rawString :
"");
157 env->ReleaseStringUTFChars(jstr, rawString);
162jstring convertTo(JNIEnv *env,
const std::string &str) {
return env->NewStringUTF(str.c_str()); }
165map_string_vector_vector_double_to_array_native(JNIEnv *env,
166 const std::map<std::string, std::vector<std::vector<double> > > &map)
172 size_t mapSize = map.size();
173 jobjectArray mapArray = env->NewObjectArray(mapSize, env->FindClass(
"java/lang/Object"), NULL);
176 for (std::map<std::string, std::vector<std::vector<double> > >::const_iterator it = map.begin(); it != map.end();
178 size_t outerSize = it->second.size();
179 jobjectArray outerArray = env->NewObjectArray(outerSize, env->FindClass(
"java/lang/Object"), NULL);
181 for (
int i = 0; i < env->GetArrayLength(outerArray); i++) {
182 size_t innerSize = it->second[i].size();
183 jdoubleArray doubleArray = env->NewDoubleArray(innerSize);
184 jdouble *doubleArrayElements = env->GetDoubleArrayElements(doubleArray, 0);
186 for (
int j = 0; j < env->GetArrayLength(doubleArray); j++) {
187 doubleArrayElements[j] = (jdouble)it->second[i][j];
190 env->ReleaseDoubleArrayElements(doubleArray, doubleArrayElements, 0);
191 env->SetObjectArrayElement(outerArray, i, doubleArray);
194 env->SetObjectArrayElement(mapArray, idx, outerArray);
200jobjectArray vector_string_to_array_native(JNIEnv *env,
const std::vector<std::string> &V)
206 size_t vecSize = V.size();
207 jobjectArray vec = env->NewObjectArray(vecSize, env->FindClass(
"java/lang/String"), env->NewStringUTF(
""));
208 for (
size_t i = 0; i < V.size(); i++) {
209 env->SetObjectArrayElement(vec, i, env->NewStringUTF(V[i].c_str()));
215std::vector<std::string> array_string_to_vector(JNIEnv *env, jobjectArray arr)
217 int size = env->GetArrayLength(arr);
219 std::vector<std::string> vec(size);
220 for (
int i = 0; i < size; i++) {
221 vec[i] = convertTo(env, (jstring)env->GetObjectArrayElement(arr, i));
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...