Guest User

Untitled

a guest
Nov 5th, 2014
150
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <jni.h>
  2. #include <android/log.h>
  3.  
  4.  
  5. #include "cvsba/sba.h"
  6.  
  7. #include "BA/projHybrid.h"
  8. #include "BA/jacprojHybrid.h"
  9.  
  10. #define  LOG_TAG    "BundleAdjustmentJNI"
  11. #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
  12. #define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
  13. #define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
  14. #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
  15.  
  16.  
  17.  
  18. extern "C" {
  19.     JNIEXPORT jdoubleArray JNICALL Java_hu_u_1szeged_inf_nativelib_BundleAdjustmentJNI_hybridBA(JNIEnv* env, jobject obj,
  20. jdoubleArray p0, jdoubleArray affineAndPoints2d, jint ncams, jintArray visib_mask, jdoubleArray intrinsics,
  21. jint pts_count, jint pts3d_count    );
  22. };
  23.  
  24. static void proj_motstr(int j, int i, double *aj, double *bi, double *xij, void *adata)
  25. {
  26. //   double* ncams = (double*)(&adata)[0];
  27. //   double **affineAndPts2D = (double **)(&adata)[1];
  28. //   double **intrinsics = (double **)(&adata)[2];
  29.     int *ncams=((int **)&adata)[0];
  30.     double *affineAndPts2D = ((double **)((&adata + sizeof(int *))))[0];
  31.     double *intrinsics = ((double **)((&adata + sizeof(int *))))[1];
  32.  
  33.     LOGD("4.4 %d", *ncams);
  34.     LOGD("4.5 %f", intrinsics[2]);
  35.     LOGD("4.6 %f", affineAndPts2D[4]);
  36.  
  37.    projHybrid(j, i, aj, bi, (double)(*ncams), affineAndPts2D, intrinsics, xij);
  38. }
  39.  
  40. static void projac_motstr(int j, int i, double *aj, double *bi, double *Aij, double *Bij, void *adata)
  41. {
  42.  
  43. //   double* ncams = (double*)(&adata)[0];
  44. //   double **affineAndPts2D = (double **)(&adata)[1];
  45.  //  double **intrinsics = (double **)(&adata)[2];
  46.     int *ncams=((int **)&adata)[0];
  47.     double *affineAndPts2D = ((double **)((&adata + sizeof(int *))))[0];
  48.     double *intrinsics = ((double **)((&adata + sizeof(int *))))[1];
  49.  
  50.  
  51.  
  52.    jacprojHybrid(j, i, aj, bi, (double)(*ncams), affineAndPts2D, intrinsics, Aij, Bij);
  53. }
  54.  
  55.  
  56. JNIEXPORT jdoubleArray JNICALL Java_hu_u_1szeged_inf_nativelib_BundleAdjustmentJNI_hybridBA(JNIEnv* env, jobject obj,
  57. jdoubleArray p0, jdoubleArray affineAndPoints2d, jint ncams, jintArray visib_mask, jdoubleArray intrinsics ,
  58.  jint pts_count, jint pts3d_count) {
  59.  
  60.  
  61.     double *P0 = env->GetDoubleArrayElements(p0, 0);
  62.     env->ReleaseDoubleArrayElements(p0, P0, 0);
  63.  
  64.     double *AffineAndPoints2d = env->GetDoubleArrayElements(affineAndPoints2d, 0);
  65.     env->ReleaseDoubleArrayElements(affineAndPoints2d, AffineAndPoints2d, 0);
  66.  
  67.     double *Intrinsics = env->GetDoubleArrayElements(intrinsics, 0);
  68.     env->ReleaseDoubleArrayElements(intrinsics, Intrinsics, 0);
  69.  
  70.     int * ivmask = env->GetIntArrayElements(visib_mask, 0);
  71.     env->ReleaseIntArrayElements(visib_mask, ivmask, 0);
  72.  
  73.     /*for(int i=0;i<ncams*pts3d_count;i++){
  74.         LOGD("ivmask[%d]: %d", i,ivmask[i]);
  75.     }*/
  76.  
  77.     char vmask[ncams*pts3d_count];
  78.  
  79.     //LOGD("vmask: %p", vmask);
  80.     for(int i=0;i<ncams*pts3d_count;i++){
  81.         if(ivmask[i]==0){
  82.             vmask[i]=0;
  83.         }else{
  84.             vmask[i]=1;
  85.         }
  86.  
  87.         //LOGD("vmask[%d]: %d", i,vmask[i]);
  88.     }
  89.  
  90.     int cnp = 6;
  91.     int p2dnp = 6;
  92.     int p3Dnp=5;
  93.    
  94.      LOGD("3.4 %d", ncams);
  95.      LOGD("3.5 %f", Intrinsics[2]);
  96.      LOGD("3.6 %f", AffineAndPoints2d[4]);
  97.  
  98.     void* adata[3];
  99.     adata[0]=&ncams;
  100.     adata[1]=AffineAndPoints2d;
  101.     adata[2]=Intrinsics;
  102.  
  103.  
  104.     double opts[SBA_OPTSSZ]={SBA_INIT_MU, SBA_STOP_THRESH, SBA_STOP_THRESH, SBA_STOP_THRESH, 0.0};
  105.     //sba(npts, 0, ncams, 1, dmask, p0, cnp, p3Dnp, affineAndPts2D, p2Dnp, 'projHybrid', 'jacprojHybrid',
  106.     //   100, 1, opts, 'motstr', ncams, affineAndPts2D, intrinsics)
  107.     sba_motstr_levmar(pts3d_count, 0, ncams, 0, vmask, P0, cnp, p3Dnp, AffineAndPoints2d , NULL, p2dnp, proj_motstr, projac_motstr, adata, 100, 1,opts,NULL);
  108.     int l=ncams*cnp+pts3d_count*p3Dnp;
  109.     jdoubleArray jResults = env->NewDoubleArray(l);
  110.     env->SetDoubleArrayRegion(jResults, 0, l, &P0[0]);
  111.     return jResults;
  112.    
  113. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×