void raytrace_1_4(int im, inputPars *par, struct grid *g, molData *m, image *img){ /* This is an alternative raytracing algorithm which was implemented by C Brinch in version 1.4 (the original parallelized version) of LIME. I've adapted it slightly so it makes use of the function traceray(), which was modified from the function tracerays() in v1.4. This algorithm is not currently used, but may be useful as an option; that's why I have kept it. */ int *counta, *countb,nlinetot; int ichan,i,px,iline,tmptrans,count; double size,xp,yp,minfreq,absDeltaFreq; double cutoff; gsl_rng *ran = gsl_rng_alloc(gsl_rng_ranlxs2); /* Random number generator */ #ifdef TEST gsl_rng_set(ran,178490); #else gsl_rng_set(ran,time(0)); #endif rayData *rays; int sg,n; double cx,cy; double x1,x2,x3,y1,y2,y3,z1,z2,z3,xt[3],yt[3],di,p,d1,d2,d3,temp1; int zt[3]; int c; char flags[255]; boolT ismalloc = False; facetT *facet, *neighbor, **neighborp;; vertexT *vertex,**vertexp; coordT *pt_array; int id; coordT point[3]; boolT isoutside; realT bestdist; size=img[im].distance*img[im].imgres; /* Determine whether there are blended lines or not */ lineCount(par->nSpecies, m, &counta, &countb, &nlinetot); if(img[im].doline==0) nlinetot=1; /* Fix the image parameters */ if(img[im].freq < 0) img[im].freq=m[0].freq[img[im].trans]; if(img[im].nchan == 0 && img[im].bandwidth>0){ img[im].nchan=(int) (img[im].bandwidth/(img[im].velres/CLIGHT*img[im].freq)); } else if (img[im].velres<0 && img[im].bandwidth>0){ img[im].velres = img[im].bandwidth*CLIGHT/img[im].freq/img[im].nchan; } else img[im].bandwidth = img[im].nchan*img[im].velres/CLIGHT * img[im].freq; if(img[im].trans<0){ iline=0; minfreq=fabs(img[im].freq-m[0].freq[iline]); tmptrans=iline; for(iline=1;iline<m[0].nline;iline++){ absDeltaFreq=fabs(img[im].freq-m[0].freq[iline]); if(absDeltaFreq<minfreq){ minfreq=absDeltaFreq; tmptrans=iline; } } } else tmptrans=img[im].trans; /* Allocate dynamical arrays */ rays = malloc(sizeof(rayData) * (par->pIntensity)); for(i=0;i<par->pIntensity;i++){ rays[i].x=g[i].x[0]; rays[i].y=g[i].x[1]; rays[i].tau=malloc(sizeof(double) * img[im].nchan); rays[i].intensity=malloc(sizeof(double) * img[im].nchan); for(ichan=0;ichan<img[im].nchan;ichan++) { rays[i].tau[ichan]=0.0; rays[i].intensity[ichan]=0.0; } } /* Smooth out the distribution of rays */ for(sg=0;sg<20;sg++){ pt_array=malloc(2*sizeof(coordT)*par->pIntensity); for(i=0;i<par->pIntensity;i++) { pt_array[i*2+0]=rays[i].x; pt_array[i*2+1]=rays[i].y; } sprintf(flags,"qhull v s Qbb T0"); if (!qh_new_qhull(2, par->pIntensity, pt_array, ismalloc, flags, NULL, NULL)) { qh_setvoronoi_all(); FORALLvertices { i=qh_pointid(vertex->point); cx=0.; cy=0.; n=0; FOREACHneighbor_(vertex) { if (!neighbor->upperdelaunay) n++; } if(n>0){ } else { if(!silent) bail_out("Qhull error"); exit(0); } FOREACHneighbor_(vertex) { if (!neighbor->upperdelaunay) { cx+=neighbor->center[0]; cy+=neighbor->center[1]; } } rays[i].x = rays[i].x - (rays[i].x-cx/ (double) n)*0.1; rays[i].y = rays[i].y - (rays[i].y-cy/ (double) n)*0.1; } } else {
JNIEXPORT jboolean JNICALL Java_qhull_QHull_voronoi_1 (JNIEnv *env, jclass jc, jobject jresult, jobjectArray points) { jclass vresultsCls=(*env)->GetObjectClass(env,jresult); jint np=(*env)->GetArrayLength(env,points); //Convert points to pt_array, suitable for input double pt_array[np*3]; int dim=3; for(int i=0;i<np;i++) { jobject pv=(*env)->GetObjectArrayElement(env,points,i); jclass vecclass=(*env)->GetObjectClass(env,pv); jfieldID fieldX=(*env)->GetFieldID(env, vecclass, "x", "D"); jfieldID fieldY=(*env)->GetFieldID(env, vecclass, "y", "D"); jfieldID fieldZ=(*env)->GetFieldID(env, vecclass, "z", "D"); pt_array[i*3+0]=(*env)->GetDoubleField(env,pv,fieldX); pt_array[i*3+1]=(*env)->GetDoubleField(env,pv,fieldY); pt_array[i*3+2]=(*env)->GetDoubleField(env,pv,fieldZ); } char options[]=""; char flags[250]; sprintf (flags, "qhull v Fv T0 %s", options); //////////////////////////////// int ismalloc = false; FILE *outfile = stdout; // FILE *errfile = stderr; FILE *errfile = 0; if(!qh_new_qhull (dim, np, pt_array, ismalloc, flags, outfile, errfile)) { facetT *facet; vertexT *vertex; int n = 1, k = 0, m = 0, fidx = 0, j = 0;//, r = 0; int ni[np]; for (int i = 0; i < np; i++) ni[i] = 0; qh_setvoronoi_all (); return JNI_FALSE; /////// int infinity_seen = false; facetT *neighbor, **neighborp; coordT *voronoi_vertex; FORALLfacets { facet->seen = false; } FORALLvertices { if (qh hull_dim == 3) qh_order_vertexneighbors (vertex); infinity_seen = false; FOREACHneighbor_ (vertex) { if (! neighbor->upperdelaunay) { if (! neighbor->seen) { n++; neighbor->seen = true; } ni[k]++; } else if (! infinity_seen) { infinity_seen = true; ni[k]++; } } k++; } double v[n][dim]; // Matrix v (n, dim); for (int d = 0; d < dim; d++) v[0][d] = 99999999; //infinity int AtInf[np]; //need to malloc for (int i = 0; i < np; i++) AtInf[i] = 0; jobject *faceArray=NULL; int faceArraySize=0; // octave_value_list F; k = 0; int newi = 0; FORALLfacets { facet->seen = false; } FORALLvertices { if (qh hull_dim == 3) qh_order_vertexneighbors(vertex); infinity_seen = false; jintArray facet_list=(*env)->NewIntArray(env, ni[k++]); m = 0; FOREACHneighbor_(vertex) { if (neighbor->upperdelaunay) { if (! infinity_seen) { infinity_seen = true; jint one=1; (*env)->SetIntArrayRegion(env, facet_list, m++, 1, (jint *)(&one)); // m++; // facet_list(m++) = 1; AtInf[j] = true; } } else { if(!neighbor->seen) { voronoi_vertex = neighbor->center; fidx = neighbor->id; newi++; for (int d = 0; d < dim; d++) { v[newi][d] = *(voronoi_vertex++); } neighbor->seen = true; neighbor->visitid = newi; } jint pos=neighbor->visitid + 1; (*env)->SetIntArrayRegion(env, facet_list, m++, 1, (jint *)(&pos)); // facet_list(m++) = neighbor->visitid + 1; } } faceArraySize++; faceArray=realloc(faceArray,sizeof(jobject*)*faceArraySize); faceArray[faceArraySize-1]=facet_list; // F(r++) = facet_list; j++; } // *outv=v; // *outC=C; // *outAtInf=AtInf; //Convert C faces *[I to [[I jclass intArrCls = (*env)->FindClass(env,"[I") ; jobjectArray faceJavaArray=(*env)->NewObjectArray(env, faceArraySize, intArrCls, NULL); for(int i=0;i<faceArraySize;i++) (*env)->SetObjectArrayElement(env, faceJavaArray, faceArraySize, faceArray[i]); free(faceArray); //Convert *vertex to [Vector3d //TODO // jobject pv=(*env)->GetObjectArrayElement(env,points,i); // pt_array[i*3+0]=(*env)->GetDoubleField(env,pv,fieldX); //Set result field faces jfieldID fieldFaces=(*env)->GetFieldID(env, vresultsCls, "faces", "[[I"); (*env)->SetObjectField(env, jresult, fieldFaces, faceJavaArray); //Set result field vector jfieldID fieldVectors=(*env)->GetFieldID(env, vresultsCls, "vectors", "[javax/vecmath/Vector3d"); // free long memory qh_freeqhull (! qh_ALL); // free short memory and memory allocator int curlong, totlong; qh_memfreeshort (&curlong, &totlong); if (curlong || totlong) printf ("voronoi: did not free %d bytes of long memory (%d pieces)", totlong, curlong); return JNI_TRUE; }