mgltools-geomutils-1.5.7~rc1~cvs.20130519/0000755000175000017500000000000012146210053017233 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/src/0000755000175000017500000000000012146210052020021 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/0000755000175000017500000000000012146210052020750 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/efit.h0000644000175000017500000000243010020707053022050 0ustar debiandebian/* efit.h */ /* defines */ #define MAXPOINTS 150*1024 #define MATRIXFORMAT "%14.7g %14.7g %14.7g\n%14.7g %14.7g %14.7g\n%14.7g %14.7g %14.7g\n" #define POSITIONFORMAT "%14.7g %14.7g %14.7g\n" #define EFIT_NAME_LENGTH 64 #define INBUFSIZE 256 #define X 0 #define Y 1 #define Z 2 #define EFIT_OK 0 #define EFIT_ERROR -1 typedef float matrix33[3][3]; /* SYSV def */ #define index strchr /* MACROS */ #define RAD_TO_DEG(x) ((x)*(180.0/M_PI)) #define DEG_TO_RAD(x) ((x)*(M_PI/180.0)) /* STRUCTURES */ struct datum { float point[3]; float weight; }; struct ellipsoid { char name[EFIT_NAME_LENGTH]; float position[3]; /* center of mass */ double axis[3]; /* major, minor, middle axis lengths */ float orientation[3][3]; /* orientation matrix */ float inv_orientation[3][3];/* inverse orientation matrix */ float tensor[3][3]; /* inertia or covariance */ }; struct efit_info { int weightflag; int covarflag; int volumeflag; int matrixflag; int nocenterflag; int noscaleflag; int nosortflag; int count; float cov_scale; /* multiplier for covariance std axies */ float ell_scale; /* multiplier for ellipsoid axies */ }; #include "efit_globals.h" /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/efit_aux.c0000644000175000017500000003313410020707053022725 0ustar debiandebian/* * efit_aux.c */ #include #include #include "efit.h" int efit_read_points(eptr,points,fp) struct efit_info *eptr; struct datum *points; FILE *fp; { int i; int count; char buf[INBUFSIZE]; float x,y,z,weight; /* init */ if(!fp) return EFIT_ERROR; i = count = 0; if(debug){ fprintf(stderr,"efit_read_points:\n"); } /* read points */ while(fgets(buf,sizeof(buf),fp) != NULL){ if(sscanf(buf,"%f %f %f %f",&x,&y,&z,&weight) < 3){ fprintf(stderr,"%s: error near line %d input [%s]\n", programname, i+1, buf); return EFIT_ERROR; } if(!eptr->weightflag) weight = 1.0; if(eptr->volumeflag) weight = weight*weight*weight; points[i].point[X] = x; points[i].point[Y] = y; points[i].point[Z]= z; points[i].weight = weight; if(i >= MAXPOINTS){ fprintf(stderr,"%s: too many points (max %d)\n", programname, MAXPOINTS); return EFIT_ERROR; } i++; } count = i; if(debug){ fprintf(stderr,"\tcount %d\n", count); } if(count == 0){ fprintf(stderr,"%s: null input\n",programname); return EFIT_ERROR; } if(count < 2){ fprintf(stderr,"%s: too few points\n",programname); return EFIT_ERROR; } eptr->count = count; return EFIT_OK; } #ifdef EFIT_CANONICAL efit_canonical() { /* orientation ambiguity: ?? omega 0 == omega 180 phi 0 == phi 180 theta 0 = theta 180 restrict range to +/- 90 */ if(ellipsoid.location.phi > 90.0){ ellipsoid.location.phi = 180.0 - ellipsoid.location.phi; } if(ellipsoid.location.phi < -90.0){ ellipsoid.location.phi = 180.0 + ellipsoid.location.phi; } if(ellipsoid.location.theta > 90.0){ ellipsoid.location.theta = 180.0 - ellipsoid.location.theta; } if(ellipsoid.location.theta < -90.0){ ellipsoid.location.theta = 180.0 + ellipsoid.location.theta; } if(ellipsoid.location.omega > 90.0){ ellipsoid.location.omega = 180.0 - ellipsoid.location.omega; } if(ellipsoid.location.omega < -90.0){ ellipsoid.location.omega = 180.0 + ellipsoid.location.omega; } location_matrix(&ellipsoid.location,m2); transtom33(m2,ellipsoid.orientation,&ellipsoid.position); } #endif efit_init(eptr) struct efit_info *eptr; { if(!eptr) return EFIT_ERROR; eptr->cov_scale = 1.75; /* multiplier for covariance std axies */ eptr->ell_scale = 1.0; /* multiplier for ellipsoid axies */ return EFIT_OK; } efit_centroid(count,points,centroid) int count; struct datum *points; float *centroid; { /* return the centroid of a collection of points */ int i; double sumx,sumy,sumz; if(!count) return EFIT_ERROR; sumx=sumy=sumz=0.0; for(i=0;ivalue > b->value) return(-1); if(a->value < b->value) return(1); return(0); } canonical_ellipsoid(eptr,ep) struct efit_info *eptr; struct ellipsoid *ep; { struct pair a[3]; int i,j; float dotvalue; matrix33 orientation; float row[3][3]; float tmppoint[3]; tmppoint[X] = tmppoint[Y] = tmppoint[Z]= 0.0; if(debug > 1)fprintf(stderr,"canonical_ellipsoid\n"); /* prepare to sort axies lengths */ mat_copy(ep->orientation,orientation); for(i=0;i<3;i++){ a[i].index = i; a[i].value = ep->axis[i]; } /* sort */ if(!eptr->nosortflag)qsort((void *)a,3,sizeof(struct pair),pair_comparefn); /* set new axies */ for(i=0;i<3;i++){ ep->axis[i] = a[i].value; for(j=0;j<3;j++)ep->orientation[i][j] = orientation[a[i].index][j]; } /* determine handedness of coordinate system */ for(i=0;i<3;i++){ row[i][X] = ep->orientation[i][0]; row[i][Y] = ep->orientation[i][1]; row[i][Z] = ep->orientation[i][2]; } if(debug > 2){ efit_print_point("row 0",row[0]); efit_print_point("row 1",row[1]); efit_print_point("row 2",row[2]); } vec_cross(row[1],row[2],tmppoint); /* y cross z */ if(debug > 1)fprintf(stderr,"cross %g %g %g\n", tmppoint[X],tmppoint[Y],tmppoint[Z]); if((dotvalue = vec_dot(row[0],tmppoint)) < 0.0){ /* invert handedness */ if(debug > 1)fprintf(stderr,"inverting handedness\n"); for(i=0;i<3;i++){ for(j=0;j<3;j++) ep->orientation[i][j] *= -1.0; } } if(debug > 1)fprintf(stderr,"dotvalue %g\n",dotvalue); /* compute inverse mat */ mat_transpose(ep->orientation,ep->inv_orientation); return EFIT_OK; } scale_ellipsoid(e,s) struct ellipsoid *e; float s; { if(e == NULL){ fprintf(stderr,"scale_ellipsoid: null ptr\n"); return EFIT_ERROR; } e->axis[0] *= s; e->axis[1] *= s; e->axis[2] *= s; return EFIT_OK; } /* * given a points array and its centroid, compute inertia tensor * as a 3x3 matrix */ void inertia_tensor(npoints,points,centroid,tensor,eptr) int npoints; struct datum *points; float centroid[3]; matrix33 tensor; struct efit_info *eptr; { int i; double i11,i22,i33,i12,i31,i32; double ti11,ti22,ti33,ti12,ti31,ti32; float p[3]; /* init */ i11=i22=i33=i12=i31=i32=0.0; /* loop */ for (i=0;inocenterflag){ p[X] = points[i].point[X]; p[Y] = points[i].point[Y]; p[Z] = points[i].point[Z]; } else { vec_sub(points[i].point,centroid,p); } ti11 = p[Y]*p[Y] + p[Z]*p[Z]; ti22 = p[X]*p[X] + p[Z]*p[Z]; ti33 = p[Y]*p[Y] + p[X]*p[X]; ti12 = p[X]*p[Y]; ti31 = p[Z]*p[X]; ti32 = p[Z]*p[Y]; if(eptr->weightflag){ i11 += points[i].weight * ti11; i22 += points[i].weight * ti22; i33 += points[i].weight * ti33; i12 += points[i].weight * ti12; i31 += points[i].weight * ti31; i32 += points[i].weight * ti32; } else { i11 += ti11; i22 += ti22; i33 += ti33; i12 += ti12; i31 += ti31; i32 += ti32; } } tensor[0][0] = i11; tensor[1][1] = i22; tensor[2][2] = i33; tensor[0][1] = tensor[1][0] = -i12; tensor[2][0] = tensor[0][2] = -i31; tensor[2][1] = tensor[1][2] = -i32; } efit_covar_1(npoints,points,centroid,tensor,eptr) int npoints; struct datum *points; float centroid[3]; matrix33 tensor; struct efit_info *eptr; { int i; double i11,i22,i33,i12,i31,i32; double ti11,ti22,ti33,ti12,ti31,ti32; float p[3]; /* init */ i11=i22=i33=i12=i31=i32=0.0; if(debug)fprintf(stderr,"covar\n"); /* loop */ for (i=0;iweightflag){ i11 += points[i].weight * ti11; i22 += points[i].weight * ti22; i33 += points[i].weight * ti33; i12 += points[i].weight * ti12; i31 += points[i].weight * ti31; i32 += points[i].weight * ti32; } else { i11 += ti11; i22 += ti22; i33 += ti33; i12 += ti12; i31 += ti31; i32 += ti32; } } tensor[0][0] = i11; tensor[1][1] = i22; tensor[2][2] = i33; tensor[0][1] = tensor[1][0] = i12; tensor[2][0] = tensor[0][2] = i31; tensor[2][1] = tensor[1][2] = i32; } efit_covar(npoints,points,centroid,covmat,eptr) int npoints; struct datum *points; float centroid[3]; matrix33 covmat; struct efit_info *eptr; { int i; double i11,i22,i33,i12,i31,i32; double ti11,ti22,ti33,ti12,ti31,ti32; double sx,sy,sz; float p[3]; /* init */ sx=sy=sz=0.0; i11=i22=i33=i12=i31=i32=0.0; /* loop */ if(debug)fprintf(stderr,"covar\n"); for (i=0;iweightflag){ i11 += points[i].weight * ti11; i22 += points[i].weight * ti22; i33 += points[i].weight * ti33; i12 += points[i].weight * ti12; i31 += points[i].weight * ti31; i32 += points[i].weight * ti32; } else { i11 += ti11; i22 += ti22; i33 += ti33; i12 += ti12; i31 += ti31; i32 += ti32; } } i11 = i11/(npoints - 1) - sx*sx/(npoints*npoints); i22 = i22/(npoints - 1) - sy*sy/(npoints*npoints); i33 = i33/(npoints - 1) - sz*sz/(npoints*npoints); i12 = i12/(npoints - 1) - sx*sy/(npoints*npoints); i31 = i31/(npoints - 1) - sz*sx/(npoints*npoints); i32 = i32/(npoints - 1) - sz*sy/(npoints*npoints); covmat[0][0] = i11; covmat[1][1] = i22; covmat[2][2] = i33; covmat[0][1] = covmat[1][0] = i12; covmat[2][0] = covmat[0][2] = i31; covmat[2][1] = covmat[1][2] = i32; return EFIT_OK; } /* * fit an ellipsoid to a collection of points by using moments of inertia */ fit_ellipsoid(npoints,points, ellipsoid,eptr) int npoints; struct datum *points; struct ellipsoid *ellipsoid; struct efit_info *eptr; { int i; double sum, weightsum; float eigenvalues[3]; /* init */ if(debug)fprintf(stderr,"fit_ellipsoid:\n"); weightsum = 0.0; for(i=0;iweightflag){ efit_wcentroid(npoints,points,ellipsoid->position); } else { efit_centroid(npoints,points,ellipsoid->position); } if(eptr->covarflag) { efit_covar(npoints,points,ellipsoid->position,ellipsoid->tensor,eptr); } else { inertia_tensor(npoints,points,ellipsoid->position,ellipsoid->tensor,eptr); } if(debug > 1){ fprintf(stderr,"centroid: %f %f %f\n", ellipsoid->position[X], ellipsoid->position[Y], ellipsoid->position[Z]); fprintf(stderr,"tensor\n"); for(i=0;i<3;i++)fprintf(stderr,"%f %f %f\n", ellipsoid->tensor[i][0], ellipsoid->tensor[i][1], ellipsoid->tensor[i][2]); } (void)mat_jacobi(ellipsoid->tensor,eigenvalues,ellipsoid->inv_orientation); /* NB jacobi returns inverse matrix -> transpose to get normal mat */ mat_transpose(ellipsoid->inv_orientation,ellipsoid->orientation); sum = eigenvalues[0] + eigenvalues[1] + eigenvalues[2]; /* from the principal moments, compute equivalent physical ellipsoid */ if(debug){ fprintf(stderr,"eigenvalues: %g %g %g\n", eigenvalues[0],eigenvalues[1],eigenvalues[2]); if(debug > 1)fprintf(stderr,"weightsum %g\n", weightsum); } if(eptr->covarflag){ if(debug){ fprintf(stderr,"std_deviation: %g %g %g\n", sqrt((double)eigenvalues[0]), sqrt((double)eigenvalues[1]), sqrt((double)eigenvalues[2])); } /* scale sigma axies */ for(i=0; i<3; i++){ ellipsoid->axis[i] = eptr->cov_scale*sqrt((double)eigenvalues[i]); } } else { for(i=0; i<3; i++){ ellipsoid->axis[i] = sqrt((double)(5./(2.*weightsum))*(sum - 2.*eigenvalues[i])); } } return EFIT_OK; } /* compute the radius of gyration of an ellipsoid */ float gyration_of_ellipsoid(ellipsoid) struct ellipsoid ellipsoid; { double sum; sum = (ellipsoid.axis[0] * ellipsoid.axis[0]) + (ellipsoid.axis[1] * ellipsoid.axis[1]) + (ellipsoid.axis[2] * ellipsoid.axis[2]); return((double)sqrt(sum/5.)); } /* m33totrans(m1,position,m2) matrix33 m1; float position*; transform_matrix m2; { m2[0][0] = m1[0][0]; m2[0][1] = m1[0][1]; m2[0][2] = m1[0][2]; m2[1][0] = m1[1][0]; m2[1][1] = m1[1][1]; m2[1][2] = m1[1][2]; m2[2][0] = m1[2][0]; m2[2][1] = m1[2][1]; m2[2][2] = m1[2][2]; m2[3][0] = position[X]; m2[3][1] = position[Y]; m2[3][2] = position[Z]; } */ /* transtom33(m1,m2,position) transform_matrix m1; matrix33 m2; struct point position; { m2[0][0] = m1[0][0]; m2[0][1] = m1[0][1]; m2[0][2] = m1[0][2]; m2[1][0] = m1[1][0]; m2[1][1] = m1[1][1]; m2[1][2] = m1[1][2]; m2[2][0] = m1[2][0]; m2[2][1] = m1[2][1]; m2[2][2] = m1[2][2]; position[X] = m1[3][0]; position[Y] = m1[3][1]; position[Z] = m1[3][2]; } */ /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/efit_io.c0000644000175000017500000000651410020707053022541 0ustar debiandebian/* * efit_io.c */ #include #include "efit.h" efit_print_point(s,p) char *s; float *p; { printf("%s: %g %g %g\n",s,p[X],p[Y],p[Z]); } /* print an ellipsoid matrix on fp */ /* includes scalefactors */ print_ellipsoid_matrix(fp, ellipsoid,eptr) FILE *fp; struct ellipsoid ellipsoid; struct efit_info *eptr; { if(!eptr->noscaleflag) fprintf(fp, MATRIXFORMAT, ellipsoid.orientation[0][0]*ellipsoid.axis[0], ellipsoid.orientation[0][1]*ellipsoid.axis[0], ellipsoid.orientation[0][2]*ellipsoid.axis[0], ellipsoid.orientation[1][0]*ellipsoid.axis[1], ellipsoid.orientation[1][1]*ellipsoid.axis[1], ellipsoid.orientation[1][2]*ellipsoid.axis[1], ellipsoid.orientation[2][0]*ellipsoid.axis[2], ellipsoid.orientation[2][1]*ellipsoid.axis[2], ellipsoid.orientation[2][2]*ellipsoid.axis[2]); else fprintf(fp, MATRIXFORMAT, ellipsoid.orientation[0][0], ellipsoid.orientation[0][1], ellipsoid.orientation[0][2], ellipsoid.orientation[1][0], ellipsoid.orientation[1][1], ellipsoid.orientation[1][2], ellipsoid.orientation[2][0], ellipsoid.orientation[2][1], ellipsoid.orientation[2][2]); fprintf(fp, POSITIONFORMAT, ellipsoid.position[X], ellipsoid.position[Y], ellipsoid.position[Z]); } print_ellipsoid_tensor(fp, ellipsoid,eptr) FILE *fp; struct ellipsoid ellipsoid; struct efit_info *eptr; { fprintf(fp, MATRIXFORMAT, ellipsoid.tensor[0][0], ellipsoid.tensor[0][1], ellipsoid.tensor[0][2], ellipsoid.tensor[1][0], ellipsoid.tensor[1][1], ellipsoid.tensor[1][2], ellipsoid.tensor[2][0], ellipsoid.tensor[2][1], ellipsoid.tensor[2][2]); fprintf(fp, POSITIONFORMAT, ellipsoid.position[X], ellipsoid.position[Y], ellipsoid.position[Z]); } print_ellipsoid_location(fp, ellipsoid,eptr) FILE *fp; struct ellipsoid ellipsoid; struct efit_info eptr; { fprintf(fp, MATRIXFORMAT, ellipsoid.orientation[0][0], ellipsoid.orientation[0][1], ellipsoid.orientation[0][2], ellipsoid.orientation[1][0], ellipsoid.orientation[1][1], ellipsoid.orientation[1][2], ellipsoid.orientation[2][0], ellipsoid.orientation[2][1], ellipsoid.orientation[2][2]); fprintf(fp, POSITIONFORMAT, ellipsoid.position[X], ellipsoid.position[Y], ellipsoid.position[Z]); } print_ellipsoid(fp, ellipsoid,eptr) FILE *fp; struct ellipsoid ellipsoid; struct efit_info *eptr; { fprintf(fp, "ellipsoid\nposition %.4f %.4f %.4f\naxis %.4f %.4f %.4f\n", ellipsoid.position[X], ellipsoid.position[Y], ellipsoid.position[Z], ellipsoid.axis[X], ellipsoid.axis[Y], ellipsoid.axis[Z]); fprintf(fp, "orientation\n%.5f %.5f %.5f\n%.5f %.5f %.5f\n%.5f %.5f %.5f\n", ellipsoid.orientation[0][0], ellipsoid.orientation[0][1], ellipsoid.orientation[0][2], ellipsoid.orientation[1][0], ellipsoid.orientation[1][1], ellipsoid.orientation[1][2], ellipsoid.orientation[2][0], ellipsoid.orientation[2][1], ellipsoid.orientation[2][2]); } /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/vec.h0000644000175000017500000000553210020707053021704 0ustar debiandebian/* vec.h */ #ifndef __VEC_H_ #define __VEC_H_ 1 #include #ifndef MAXFLOAT #define MAXFLOAT ((float)3.40282346638528860e+38) #endif #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_2PI #define M_2PI (2.0*M_PI) #endif #define VEC_FUZZ 1.0e-8 #define VEC_INBUFSIZE 128 #ifndef VEC_FZEROP #define VEC_FZEROP(x) ((x < VEC_FUZZ) && (x > -VEC_FUZZ)) #endif #ifdef NO_DRAND48 #define RANDFLOAT_MASK 03777777 /* mask for random function */ #define VEC_SRANDFLOAT(x) srandom(x) #define VEC_RANDFLOAT() ((random() & RANDFLOAT_MASK)/(float)(RANDFLOAT_MASK)) #else double drand48(void); void srand48(long int); #define VEC_RANDFLOAT() drand48() #define VEC_SRANDFLOAT(x) srand48(x) #endif /* NO_DRAND48 */ #define VEC_SQRT(x) (sqrt((double)(x))) #define VEC_RANDRANGE() (2.0*(VEC_RANDFLOAT() - .5)) #define VEC_ONETHIRD (float).3333333 /** typedef float matrix33[3][3]; **/ typedef float MATRIX33[3][3]; /* vector/matrix FUNCTIONS */ int vec_normalize(float *p); int vec_centroid(int count, float *src, float *p); float vec_dot(float *p1, float *p2); float vec_magsq(float *p); float vec_mag(float *p); float vec_distancesq(float *p1, float *p2); float vec_distance(float *p1, float *p2); float vec_max(float *v); float vec_length(float *p); void vec_ctos(float *p, float *q); void vec_stoc(float *a, float *b); void vec_sub(float *p1, float *p2, float *p); void vec_copy(float *p1, float *p2); void vec_add(float *p1, float *p2, float *p); void vec_scale(float f, float *p1, float *p2); void vec_zero(float *p); void vec_zeropoints(int count, float *src); void vec_cross(float *a, float *b, float *c); void vec_align(float *p1, float *p2, float *p3, float *p4, float (*m)[3], float *t); void vec_mult(float *a, float *b, float *c); void vec_offset(float s, float *a, float *b, float *c); void vec_rand(float *v); void vec_average(float *p1, float *p2, float *p3, float *ave); void vec_copypoints(int count, float *src, float *dest); void vec_print(FILE *fp, float *p); void vec_printpair(FILE *fp, float *p, float *n); void vec_zeropoints(int count, float *src); void vec_transform(float *p, float (*m)[3], float *q); void vec_ftransform(float *p, float (*m)[3], float *q); int mat_inverse(float (*m)[3], float (*minv)[3]); float mat_det(float (*m)[3]); void mat_smallrotmatrix(float *nvec, float angle, float (*m)[3]); void mat_axisrotation(float *nvec, float radians, float (*m)[3]); void mat_read(FILE *fp, float (*m)[3], float *v); void mat_write(FILE *fp, float (*m)[3]); void mat_identity(float (*m)[3]); void mat_copy(float (*m1)[3], float (*m2)[3]); void mat_transpose(float (*m1)[3], float (*m2)[3]); void mat_mult(float (*m1)[3], float (*m2)[3], float (*m)[3]); void mat_copy(float (*m1)[3], float (*m2)[3]); void quat_to_mat (float *q, float (*m)[3]); void mat_to_quat (float (*m)[3], float *q); #endif /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/efit.c0000644000175000017500000001332710020707053022052 0ustar debiandebian/* * efit pointfile * * fit an inertial ellipsoid to input data points */ #include #include #define EFIT_MAIN 1 #include "efit.h" /* globals */ static char helpstring[] = "-NoScale -Cscale cscale -covar\n\t-volume -matrix -scale escale\n\t-weightflag -nocenter pointfile"; /* MAIN */ #include int fitEllipse(float *pts, int nbpts, float ell_scale, float cov_scale, struct efit_info *eptr, struct ellipsoid *ellipsoid) { int i; float weight, *pt=pts; if(efit_init(eptr) != EFIT_OK) return EFIT_ERROR; if (cov_scale > 0.) { eptr->cov_scale = cov_scale; /* multiplier for covariance std axies */ eptr->covarflag++; } if (ell_scale > 0.) eptr->ell_scale = ell_scale; /* multiplier for ellipsoid axies */ if(nbpts >= MAXPOINTS){ fprintf(stderr,"%s: too many points (max %d)\n", programname, MAXPOINTS); return EFIT_ERROR; } if(nbpts == 0){ fprintf(stderr,"%s: null input\n",programname); return EFIT_ERROR; } if(nbpts < 2){ fprintf(stderr,"%s: too few points\n",programname); return EFIT_ERROR; } if(!eptr->weightflag) weight = 1.0; if(eptr->volumeflag) weight = weight*weight*weight; for (i=0; icount = nbpts; if(fit_ellipsoid(eptr->count, ellipsedata, ellipsoid, eptr) != EFIT_OK){ return(EFIT_ERROR); } scale_ellipsoid(ellipsoid,eptr->ell_scale); /*print_ellipsoid(stdout,ellipsoid,eptr);*/ return(EFIT_OK); } main(argc,argv) int argc; char **argv; { int argindex; FILE *fp; char *filename = NULL; struct ellipsoid ellipsoid; struct efit_info *eptr; /* init */ eptr = &efit_info; if(efit_init(eptr) != EFIT_OK) return EFIT_ERROR; /* get args */ argindex = efit_setflags(argc,argv,eptr); if((argc == 1) && isatty(0)) efit_usage(); /* get filename if any*/ if(argindex == (argc - 1)){ filename = argv[argindex]; if((fp = fopen(filename,"r")) == NULL){ fprintf(stderr,"fit: can't open %s\n", filename); return EFIT_ERROR; } strcpy(ellipsoid.name,argv[argindex]); } else fp = stdin; if(debug){ fprintf(stderr,"%s:\n",programname); if(debug > 1)fprintf(stderr,"\tdebug %d\n",debug); if(filename)fprintf(stderr,"\tfilename %s\n",filename); if(testflag)fprintf(stderr,"\ttestflag %d\n",testflag); if(eptr->weightflag)fprintf(stderr,"\tweightflag %d\n",eptr->weightflag); if(eptr->volumeflag)fprintf(stderr,"\tvolumeflag %d\n",eptr->volumeflag); if(eptr->nocenterflag)fprintf(stderr,"\tnocenterflag %d\n", eptr->nocenterflag); if(eptr->noscaleflag)fprintf(stderr,"\tnoscaleflag %d\n", eptr->noscaleflag); if(eptr->nosortflag)fprintf(stderr,"\tnosortflag %d\n",eptr->nosortflag); fprintf(stderr,"\tell_scale %g\n",eptr->ell_scale); fprintf(stderr,"\tcov_scale %g\n",eptr->cov_scale); } if(efit_read_points(eptr,ellipsedata,fp) != EFIT_OK) return(EFIT_ERROR); if(fit_ellipsoid(eptr->count,ellipsedata,&ellipsoid,eptr) != EFIT_OK){ return(EFIT_ERROR); } /* define canonical orientation largest axies x > y > z */ if(eptr->nosortflag)canonical_ellipsoid(eptr,&ellipsoid); if(!eptr->noscaleflag)scale_ellipsoid(&ellipsoid,eptr->ell_scale); /* print results */ if(debug) print_ellipsoid(stderr,ellipsoid,eptr); if(eptr->matrixflag){ /* print transformation matrix for ellipsoid */ print_ellipsoid_matrix(stdout,ellipsoid,eptr); } else if(eptr->covarflag > 1){ print_ellipsoid_tensor(stdout,ellipsoid,eptr); } else { print_ellipsoid(stdout,ellipsoid,eptr); } return(EFIT_OK); } /* * efit_setflags * * read flags from argv * return index of first non arg */ efit_setflags(argc,argv,eptr) int argc; char **argv; struct efit_info *eptr; { int argindex; /* init */ argindex = 1; programname = argv[0]; if(!eptr) { fprintf(stderr,"efit_setflags: null eptr\n"); exit(1); } /* loop over args */ while((argc > 1) && (argv[1][0] == '-')){ switch(argv[1][1]){ case 'C': eptr->cov_scale = atof(argv[2]); argv++; argc--; argindex++; break; case 's': eptr->ell_scale = atof(argv[2]); argv++; argc--; argindex++; break; case 'c': eptr->covarflag++; break; case 'v': eptr->volumeflag++; break; case 'w': eptr->weightflag++; break; case 'N': eptr->noscaleflag++; break; case 'S': eptr->nosortflag++; break; case 'm': eptr->matrixflag++; break; case 'n': eptr->nocenterflag++; break; case 't': testflag++; break; case 'd': debug++; break; case 'u': efit_usage(); break; default: fprintf(stderr, "%s: unknown switch -%c\n",programname,argv[1][1]); exit(1); break; } argindex++; argc--; argv++; } return(argindex); } efit_usage() { fprintf(stderr,"usage: %s %s\n",programname,helpstring); exit(0); } /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/efit_globals.h0000644000175000017500000000052610020707053023557 0ustar debiandebian/* efit_globals.h */ #ifdef EFIT_MAIN #define WHERE #else #define WHERE extern #endif WHERE struct efit_info efit_info; WHERE int debug,verbose,testflag; WHERE char *programname; WHERE struct datum ellipsedata[MAXPOINTS]; /* input points and weights */ /* FUNCTIONS */ /*char *index(); */ float gyration_of_ellipsoid(); /* end of file */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/efit/vec.c0000644000175000017500000003410110020707053021671 0ustar debiandebian/* * vec.c vector/matrix functions float args and types */ #include #include #include "vec.h" #define VEC_DEG_TO_RAD(x) ((x)*M_PI/180.0) #define VEC_RAD_TO_DEG(x) ((x)*180.0/M_PI) void mat_identity(float (*m)[3]) { m[0][0] = m[1][1] = m[2][2] = 1.0; m[0][1] = m[0][2] = 0.0; m[1][0] = m[1][2] = 0.0; m[2][0] = m[2][1] = 0.0; } void mat_transpose(float (*m1)[3], float (*m2)[3]) { m2[0][0] = m1[0][0]; m2[0][1] = m1[1][0]; m2[0][2] = m1[2][0]; m2[1][0] = m1[0][1]; m2[1][1] = m1[1][1]; m2[1][2] = m1[2][1]; m2[2][0] = m1[0][2]; m2[2][1] = m1[1][2]; m2[2][2] = m1[2][2]; } float vec_length(float *p) { return(VEC_SQRT(vec_dot(p,p))); } void mat_copy(float (*m1)[3], float (*m2)[3]) /* m2 = m1 */ { m2[0][0] = m1[0][0]; m2[0][1] = m1[0][1]; m2[0][2] = m1[0][2]; m2[1][0] = m1[1][0]; m2[1][1] = m1[1][1]; m2[1][2] = m1[1][2]; m2[2][0] = m1[2][0]; m2[2][1] = m1[2][1]; m2[2][2] = m1[2][2]; } void mat_mult(float (*m1)[3], float (*m2)[3], float (*m)[3]) /* return m= m1 * m2 */ /* NOTE: THE DESTINATION MATRIX MUST NOT BE ONE OF THE SOURCES */ { m[0][0] = m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0]; m[1][0] = m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0]; m[2][0] = m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0]; m[0][1] = m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1]; m[1][1] = m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1]; m[2][1] = m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1]; m[0][2] = m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2]; m[1][2] = m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2]; m[2][2] = m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2]; } void vec_transform(float *p, float (*m)[3], float *q) /* return p * m [premultiplication] */ { float x,y,z; x = p[0]; y = p[1]; z = p[2]; q[0] = m[0][0]*x + m[1][0]*y + m[2][0]*z; q[1] = m[0][1]*x + m[1][1]*y + m[2][1]*z; q[2] = m[0][2]*x + m[1][2]*y + m[2][2]*z; } void vec_ftransform(float *p, float (*m)[3], float *q) /* return p * m [premultiplication] */ /* src != dest */ { q[0] = m[0][0]*p[0] + m[1][0]*p[1] + m[2][0]*p[2]; q[1] = m[0][1]*p[0] + m[1][1]*p[1] + m[2][1]*p[2]; q[2] = m[0][2]*p[0] + m[1][2]*p[1] + m[2][2]*p[2]; } void vec_zero(float *p) { p[0] = 0.0; p[1] = 0.0; p[2] = 0.0; } void vec_scale(float f, float *p1, float *p2) { p2[0] = f*p1[0]; p2[1] = f*p1[1]; p2[2] = f*p1[2]; } void vec_sub(float *p1, float *p2, float *p) { p[0] = p1[0] - p2[0]; p[1] = p1[1] - p2[1]; p[2] = p1[2] - p2[2]; } void vec_add(float *p1, float *p2, float *p) { p[0] = p1[0] + p2[0]; p[1] = p1[1] + p2[1]; p[2] = p1[2] + p2[2]; } void vec_copy(float *p1, float *p2) { p2[0] = p1[0]; p2[1] = p1[1]; p2[2] = p1[2]; } float vec_dot(float *p1, float *p2) { return(p1[0]*p2[0] + p1[1]*p2[1] + p1[2]*p2[2]); } int vec_normalize(float *p) { float sum; sum = p[0]*p[0] + p[1]*p[1] + p[2]*p[2]; if(sum < VEC_FUZZ)return -1; sum = VEC_SQRT(sum); p[0] /= sum; p[1] /= sum; p[2] /= sum; return 0; } float vec_magsq(float *p) { return(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]); } float vec_mag(float *p) { return(VEC_SQRT(p[0]*p[0] + p[1]*p[1] + p[2]*p[2])); } void vec_transform_points(int count, float *src, float *dest, float (*matrix)[3]) { int i; for(i=0;i 1.0){ if(dot > 1.1)fprintf(stderr,"align: dot: %g\n",dot); dot = 1.0; } if(dot < -1.0){ if(dot < -1.1)fprintf(stderr,"align: dot: %g\n",dot); dot = -1.0; } angle = acos(dot); angle = angle - M_PI; vec_normalize(axis); mat_axisrotation(axis,angle,m); vec_transform(axispoint,m,tpoint); vec_sub(axispoint,tpoint,axispoint); vec_add(t,axispoint,t); } int vec_centroid(int count, float *src, float *p) { float *ptr; int i; float sx,sy,sz; ptr = src; sx = sy = sz = 0.0; if(count == 0){ fprintf(stderr,"centroid: zero points\n"); p[0] = p[1] = p[2] = 0.0; return -1; } for(i = 0;i max) max = v[1]; if(v[2] > max) max = v[2]; return max; } /* coordinate transformations */ void vec_stoc(float *a, float *b) { b[0] = a[0]*sin((double)a[1])*cos((double)a[2]); b[1] = a[0]*sin((double)a[1])*sin((double)a[2]); b[2] = a[0]*cos((double)a[1]); } void vec_ctos(float *p, float *q) { double r,theta,phi; r = sqrt((double)(p[0] * p[0] + p[1] * p[1] + p[2] * p[2])); if (r < .001) { q[0] = q[1] = q[2] = 0.0; } else { theta = acos((double)p[2]/r); if(VEC_FZEROP(p[1]) && VEC_FZEROP(p[0])) { phi = 0.0; } else { phi = atan2((double)p[1], (double)p[0]); if(phi < 0.0) phi += M_2PI; } q[0] = r; q[1] = theta; q[2] = phi; } } void mat_read(FILE *fp, float (*m)[3], float *v) { char buf[VEC_INBUFSIZE]; /* init */ vec_zero(v); mat_identity(m); /* read input */ fgets(buf,sizeof(buf),fp); sscanf(buf,"%f %f %f %f", &m[0][0],&m[0][1],&m[0][2],&v[0]); fgets(buf,sizeof(buf),fp); sscanf(buf,"%f %f %f %f", &m[1][0],&m[1][1],&m[1][2],&v[1]); fgets(buf,sizeof(buf),fp); sscanf(buf,"%f %f %f %f", &m[2][0],&m[2][1],&m[2][2],&v[2]); if(fgets(buf,sizeof(buf),fp) != NULL){ sscanf(buf,"%f %f %f",&v[0],&v[1],&v[2]); } } /* * mat_jacobi Jacobi diagonalization of 3x3 symmetic matrix */ #define JACOBI_MAXOFFDIAG 1.0e-6 /* Maximum Off Diag Element for Jacobi */ #define JACOBI_MAXANGLE 0.25 /* Maximum angular error for Jacobi */ #define JACOBI_MAXITERATIONS 25 int mat_jacobi(float (*matrix)[3], float *eigenvalues, float (*eigenvectors)[3]) { MATRIX33 a, u, w, r, tv; float sval, cval, diff; double angle; /* rotation angle (RADIANS) */ int x, y; int iteration; /* init */ mat_copy(matrix,a); mat_identity(r); iteration = 0; label1: #ifdef VEC_DEBUG if(debug > 5) fprintf(stderr, "jacobi: iteration %d\n",iteration); #endif /* find largest off diagonal element */ if((fabs(a[0][1]) > fabs(a[0][2])) && (fabs(a[0][1]) > fabs(a[1][2]))){ x = 0; y = 1; } else if(fabs(a[0][2]) > fabs(a[1][2])) { x = 0; y = 2; } else { x = 1; y = 2; } #ifdef VEC_DEBUG if(debug > 5) fprintf(stderr, "jacobi: maxoffdiag = %g\n", a[x][y]); #endif if(fabs(a[x][y]) < (double)JACOBI_MAXOFFDIAG) { /* done */ eigenvalues[0] = a[0][0]; eigenvalues[1] = a[1][1]; eigenvalues[2] = a[2][2]; mat_copy(r, eigenvectors); return 0; } /* compute rotation angle (RADIANS) */ diff = a[x][x] - a[y][y]; if(fabs((double)diff) > (double)1.e-12) angle = .5*atan(2.*a[x][y]/diff); else angle = M_PI/4.; /* check angle termination condition */ #ifdef VEC_DEBUG if(debug > 5) fprintf(stderr, "jacobi: angle = %g (degrees)\n", VEC_RAD_TO_DEG(angle)); #endif /* PROBLEM HERE */ if(fabs(angle) < (VEC_DEG_TO_RAD(JACOBI_MAXANGLE))){ /* done */ eigenvalues[0] = a[0][0]; eigenvalues[1] = a[1][1]; eigenvalues[2] = a[2][2]; mat_copy(r, eigenvectors); return 0; } cval = cos(angle); sval = sin(angle); mat_identity(tv); tv[x][x] = tv[y][y] = cval; tv[y][x] = sval; tv[x][y] = - sval; mat_copy(tv, u); u[x][y] = sval; u[y][x] = -sval; mat_mult(a, tv, w); mat_mult(u,w,a); mat_mult(r,tv,w); mat_copy(w,r); iteration++; if(iteration > JACOBI_MAXITERATIONS){ eigenvalues[0] = a[0][0]; eigenvalues[1] = a[1][1]; eigenvalues[2] = a[2][2]; mat_copy(r, eigenvectors); return -1; } goto label1; } void mat_to_quat (float (*m)[3], float *q) { float w,wsq,tmp,ysq; float x,y,z,xsq; wsq = .25*(1.0 + m[0][0] + m[1][1] + m[2][2]); if(wsq > VEC_FUZZ){ w = sqrtf(wsq); tmp = .25/w; x = (m[1][2] - m[2][1])*tmp; y = (m[2][0] - m[0][2])*tmp; z = (m[0][1] - m[1][0])*tmp; } else { w = 0.0; xsq = .5*(m[1][1] + m[2][2]); if(xsq > VEC_FUZZ){ x = sqrtf(xsq); tmp = .5/x; y = m[0][1]*tmp; z = m[0][2]*tmp; } else { x = 0.0; ysq = .5*(1.0 - m[2][2]); if(ysq > VEC_FUZZ){ y = sqrtf(ysq); z = m[1][2]/(2.0*y); } else { y = 0.0; z = 1.0; } } } q[0] = x; q[1] = y; q[2] = z; q[3] = w; } /* convert normalized quat to matrix */ void quat_to_mat (float *q, float (*m)[3]) { float w, x, y, z; float tx, ty, tz; float twx, txx, txy, txz; float twy, tyy, tyz; float twz, tzz; x = q[0]; y = q[1]; z = q[2]; w = q[3]; tx = x+x; ty = y+y; tz = z+z; twx = w*tx; txx = x*tx; txy = y*tx; txz = z*tx; twy = w*ty; tyy = y*ty; tyz = z*ty; twz = w*tz; tzz = z*tz; m[0][0] = 1. - tyy - tzz; m[0][1] = txy + twz; m[0][2] = txz - twy; m[1][0] = txy - twz; m[1][1] = 1. - txx - tzz; m[1][2] = tyz + twx; m[2][0] = txz + twy; m[2][1] = tyz - twx; m[2][2] = 1. - txx - tyy; } void quat_normalize(float *q) { float mag; mag = sqrtf((float)(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3])); mag = 1.0/mag; q[0] *= mag; q[1] *= mag; q[2] *= mag; q[3] *= mag; } /* eof */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/0000755000175000017500000000000012146210053023003 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/distance.h0000644000175000017500000000345010267500030024747 0ustar debiandebian#ifndef SS_Distance_H #define SS_Distance_H #include "geomstructs.h" // closest2D_Point_to_Line(): finds the closest 2D Point to a Line // Input: an array P[] of n points, and a Line L // Return: the index i of the Point P[i] closest to L int closest2D_Point_to_Line( Point P[], int n, Line L); // dist_Point_to_Line(): get the distance of a point to a line. // Input: a Point P and a Line L (in any dimension) // Return: the shortest distance from P to L float dist_Point_to_Line( Point P, Line L); // dist_Point_to_Segment(): get the distance of a point to a segment. // Input: a Point P and a Segment S (in any dimension) // Return: the shortest distance from P to S float dist_Point_to_Segment( Point P, Segment S); // pbase_Plane(): get base of perpendicular from point to a plane // Input: P = a 3D point // PL = a plane with point V0 and normal n // Output: *B = base point on PL of perpendicular from P // Return: the distance from P to the plane PL float pbase_Plane( Point P, Plane PL, Point* B); // dist3D_Line_to_Line(): // Input: two 3D lines L1 and L2 // Return: the shortest distance between L1 and L2 float dist3D_Line_to_Line( Line L1, Line L2); // dist3D_Segment_to_Segment(): // Input: two 3D line segments S1 and S2 // Return: the shortest distance between S1 and S2 float dist3D_Segment_to_Segment( Segment S1, Segment S2); // cpa_time(): compute the time of CPA for two tracks // Input: two tracks Tr1 and Tr2 // Return: the time at which the two tracks are closest float cpa_time( Track Tr1, Track Tr2 ); // cpa_distance(): compute the distance at CPA for two tracks // Input: two tracks Tr1 and Tr2 // Return: the distance for which the two tracks are closest float cpa_distance( Track Tr1, Track Tr2 ); #endif //SS_Distance_H mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/boundingContainers.h0000644000175000017500000000057510267500030027015 0ustar debiandebian#ifndef _BoundingContainers_H #define _BoundingContainers_H #include "geomstructs.h" // fastBall(): a fast approximation of the bounding ball for a point set // based on the algorithm given by [Jack Ritter, 1990] // Input: an array V[] of n points // Output: a bounding ball = {Point center; float radius;} void fastBall( Point V[], int n, Ball* B); #endif mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/polygonArea.h0000644000175000017500000000232510267500030025435 0ustar debiandebian#ifndef _PolygonArea_ #define _PolygonArea_ typedef struct {double x, y, z;} Vert; // exclude z for 2D // orientation2D_Polygon(): tests the orientation of a simple polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+1 vertices with V[n]=V[0] // Return: >0 for counterclockwise // =0 for none (degenerate) // <0 for clockwise // Note: this algorithm is faster than computing the signed area. int orientation2D_Polygon( int n, Vert* V ); // area2D_Polygon(): computes the area of a 2D polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+2 vertices // with V[n]=V[0] and V[n+1]=V[1] // Return: the (float) area of the polygon float area2D_Polygon( int n, Vert* V ); // area3D_Polygon(): computes the area of a 3D planar polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+2 vertices in a plane // with V[n]=V[0] and V[n+1]=V[1] // Vert N = unit normal vector of the polygon's plane // Return: the (float) area of the polygon float area3D_Polygon( int n, Vert* V, Vert N ); #endif mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/common.h0000755000175000017500000000274211015372566024470 0ustar debiandebian//------------------------------------------------------------------ // Copyright 2002, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from it's use. // Users of this code must verify correctness for their application. //------------------------------------------------------------------ #ifndef SS_Common_H #define SS_Common_H #include #include //enum boolean {FALSE=0, TRUE=1, ERROR=(-1)}; enum softSurferBoolean {FALSE_=0, TRUE_=1, ERROR_=(-1)}; // Error codes enum Error { Enot, // no error Edim, // error: dim of point invalid for operation Esum // error: sum not affine (cooefs add to 1) }; // utility macros #define SMALL_NUM 0.00000001 // anything that avoids division overflow #define abs(x) ((x) >= 0 ? x : -(x)); #define min(x,y) ((x) < (y) ? (x) : (y)); #define max(x,y) ((x) > (y) ? (x) : (y)); // dot product (3D) which allows vector operations in arguments #define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z) #define norm(v) sqrt(dot(v,v)) // norm = length of vector #define norm2(v) dot(v,v) // The distance between points is implemented in point.cpp //#define d(u,v) norm(u-v) // distance = norm of difference #define perp(u,v) ((u).x * (v).y - (u).y * (v).x) // perp product (2D) #endif //SS_Common_H mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/distance.cpp0000644000175000017500000002217010267500030025302 0ustar debiandebian//About Lines and Distance of a Point to a Line (2D & 3D) // Copyright 2001, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from its use. // Users of this code must verify correctness for their application. // Assume that classes are already given for the objects: // Point and Vector with // coordinates {float x, y, z;} (z=0 for 2D) // appropriate operators for: // Point = Point ± Vector // Vector = Point - Point // Vector = Scalar * Vector // Line with defining endpoints {Point P0, P1;} // Segment with defining endpoints {Point P0, P1;} //=================================================================== #include "distance.h" // closest2D_Point_to_Line(): finds the closest 2D Point to a Line // Input: an array P[] of n points, and a Line L // Return: the index i of the Point P[i] closest to L int closest2D_Point_to_Line( Point P[], int n, Line L) { // Get coefficients of the implicit line equation. // Do NOT normalize since scaling by a constant // is irrelevant for just comparing distances. int i; float a = L.P0.y - L.P1.y; float b = L.P1.x - L.P0.x; float c = L.P0.x * L.P1.y - L.P1.x * L.P0.y; // initialize min index and distance to P[0] int mi = 0; float min = a * P[0].x + b * P[0].y + c; if (min < 0) min = -min; // absolute value // loop through Point array testing for min distance to L for (i=1; i= 0 float b = dot(u,v); float c = dot(v,v); // always >= 0 float d = dot(u,w); float e = dot(v,w); float D = a*c - b*b; // always >= 0 float sc, tc; // compute the line parameters of the two closest points if (D < SMALL_NUM) { // the lines are almost parallel sc = 0.0; tc = (b>c ? d/b : e/c); // use the largest denominator } else { sc = (b*e - c*d) / D; tc = (a*e - b*d) / D; } // get the difference of the two closest points Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc) return norm(dP); // return the closest distance } //=================================================================== // dist3D_Segment_to_Segment(): // Input: two 3D line segments S1 and S2 // Return: the shortest distance between S1 and S2 float dist3D_Segment_to_Segment( Segment S1, Segment S2) { Vector u = S1.P1 - S1.P0; Vector v = S2.P1 - S2.P0; Vector w = S1.P0 - S2.P0; float a = dot(u,u); // always >= 0 float b = dot(u,v); float c = dot(v,v); // always >= 0 float d = dot(u,w); float e = dot(v,w); float D = a*c - b*b; // always >= 0 float sc, sN, sD = D; // sc = sN / sD, default sD = D >= 0 float tc, tN, tD = D; // tc = tN / tD, default tD = D >= 0 float asN, atN; // compute the line parameters of the two closest points if (D < SMALL_NUM) { // the lines are almost parallel sN = 0.0; // force using point P0 on segment S1 sD = 1.0; // to prevent possible division by 0.0 later tN = e; tD = c; } else { // get the closest points on the infinite lines sN = (b*e - c*d); tN = (a*e - b*d); if (sN < 0.0) { // sc < 0 => the s=0 edge is visible sN = 0.0; tN = e; tD = c; } else if (sN > sD) { // sc > 1 => the s=1 edge is visible sN = sD; tN = e + b; tD = c; } } if (tN < 0.0) { // tc < 0 => the t=0 edge is visible tN = 0.0; // recompute sc for this edge if (-d < 0.0) sN = 0.0; else if (-d > a) sN = sD; else { sN = -d; sD = a; } } else if (tN > tD) { // tc > 1 => the t=1 edge is visible tN = tD; // recompute sc for this edge if ((-d + b) < 0.0) sN = 0; else if ((-d + b) > a) sN = sD; else { sN = (-d + b); sD = a; } } // finally do the division to get sc and tc //sc = (abs(sN) < SMALL_NUM ? 0.0 : sN / sD); // A.O.commented out, caused syntax error //tc = (abs(tN) < SMALL_NUM ? 0.0 : tN / tD); asN = abs(sN); atN = abs(tN); sc = (asN < SMALL_NUM ? 0.0 : sN/sD); tc = (atN < SMALL_NUM ? 0.0 : tN/tD); // get the difference of the two closest points Vector dP = w + (sc * u) - (tc * v); // = S1(sc) - S2(tc) return norm(dP); // return the closest distance } //=================================================================== // cpa_time(): compute the time of CPA for two tracks // Input: two tracks Tr1 and Tr2 // Return: the time at which the two tracks are closest float cpa_time( Track Tr1, Track Tr2 ) { Vector dv = Tr1.v - Tr2.v; float dv2 = dot(dv,dv); if (dv2 < SMALL_NUM) // the tracks are almost parallel return 0.0; // any time is ok. Use time 0. Vector w0 = Tr1.P0 - Tr2.P0; float cpatime = -dot(w0,dv) / dv2; return cpatime; // time of CPA } //=================================================================== // cpa_distance(): compute the distance at CPA for two tracks // Input: two tracks Tr1 and Tr2 // Return: the distance for which the two tracks are closest float cpa_distance( Track Tr1, Track Tr2 ) { float ctime = cpa_time( Tr1, Tr2); Point P1 = Tr1.P0 + (ctime * Tr1.v); Point P2 = Tr2.P0 + (ctime * Tr2.v); return d(P1,P2); // distance at CPA } //=================================================================== mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/point.cpp0000755000175000017500000002056110354564205024661 0ustar debiandebian//================================================================== // Copyright 2002, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from it's use. // Users of this code must verify correctness for their application. //================================================================== #include "point.h" #include "Vector.h" //================================================================== // Point Class Methods //================================================================== //------------------------------------------------------------------ // Constructors (add more as needed) //------------------------------------------------------------------ // n-dim Point Point::Point( int n, int a[]) { x = y = z = 0; err = Enot; switch (dimn = n) { case 3: z = a[2]; case 2: y = a[1]; case 1: x = a[0]; break; default: err=Edim; } } Point::Point( int n, double a[]) { x = y = z = 0.0; err = Enot; switch (dimn = n) { case 3: z = a[2]; case 2: y = a[1]; case 1: x = a[0]; break; default: err=Edim; } } //------------------------------------------------------------------ // IO streams //------------------------------------------------------------------ // Read input Point format: "(%f)", "(%f, %f)", or "(%f, %f, %f)" istream& operator>>( istream& input, Point& P) { char c; input >> c; // skip '(' input >> P.x; input >> c; if (c == ')') { P.setdim(1); // 1D coord return input; } // else // skip ',' input >> P.y; input >> c; if (c == ')') { P.setdim(2); // 2D coord return input; } // else // skip ',' input >> P.z; P.setdim(3); // 3D coord input >> c; // skip ')' return input; } // Write output Point in format: "(%f)", "(%f, %f)", or "(%f, %f, %f)" ostream& operator<<( ostream& output, Point P) { switch (P.dim()) { case 1: output << "(" << P.x << ")"; break; case 2: output << "(" << P.x << ", " << P.y << ")"; break; case 3: output << "(" << P.x << ", " << P.y << ", " << P.z << ")"; break; default: output << "Error: P.dim = " << P.dim(); } return output; } //------------------------------------------------------------------ // Assign (set) dimension //------------------------------------------------------------------ int Point::setdim( int n) { switch (n) { case 1: y = 0; case 2: z = 0; case 3: return dimn = n; default: // out of range value err = Edim; // just flag the error return ERROR_; } } //------------------------------------------------------------------ // Comparison (note: dimension must compare) //------------------------------------------------------------------ int Point::operator==( Point Q) { if (dimn != Q.dim()) return FALSE_; switch (dimn) { case 1: return (x==Q.x); case 2: return (x==Q.x && y==Q.y); case 3: default: return (x==Q.x && y==Q.y && z==Q.z); } } int Point::operator!=( Point Q) { if (dimn != Q.dim()) return TRUE_; switch (dimn) { case 1: return (x!=Q.x); case 2: return (x!=Q.x || y!=Q.y); case 3: default: return (x!=Q.x || y!=Q.y || z!=Q.z); } } //------------------------------------------------------------------ // Point Vector Operations //------------------------------------------------------------------ Vector Point::operator-( Point Q) // Vector diff of Points { Vector v; v.x = x - Q.x; v.y = y - Q.y; v.z = z - Q.z; v.dimn = max( dimn, Q.dim()); return v; } Point Point::operator+( Vector v) // +ve translation { Point P; P.x = x + v.x; P.y = y + v.y; P.z = z + v.z; P.dimn = max( dimn, v.dim()); return P; } Point Point::operator-( Vector v) // -ve translation { Point P; P.x = x - v.x; P.y = y - v.y; P.z = z - v.z; P.dimn = max( dimn, v.dim()); return P; } Point& Point::operator+=( Vector v) // +ve translation { x += v.x; y += v.y; z += v.z; dimn = max( dimn, v.dim()); return *this; } Point& Point::operator-=( Vector v) // -ve translation { x -= v.x; y -= v.y; z -= v.z; dimn = max( dimn, v.dim()); return *this; } //------------------------------------------------------------------ // Point Scalar Operations (convenient but often illegal) // are not valid for points in general, // unless they are 'affine' as coeffs of // a sum in which all the coeffs add to 1, // such as: the sum (a*P + b*Q) with (a+b == 1). // The programmer must enforce this (if they want to). //------------------------------------------------------------------ Point operator*( int c, Point Q) { Point P; P.x = c * Q.x; P.y = c * Q.y; P.z = c * Q.z; P.dimn = Q.dim(); return P; } Point operator*( double c, Point Q) { Point P; P.x = c * Q.x; P.y = c * Q.y; P.z = c * Q.z; P.dimn = Q.dim(); return P; } Point operator*( Point Q, int c) { Point P; P.x = c * Q.x; P.y = c * Q.y; P.z = c * Q.z; P.dimn = Q.dim(); return P; } Point operator*( Point Q, double c) { Point P; P.x = c * Q.x; P.y = c * Q.y; P.z = c * Q.z; P.dimn = Q.dim(); return P; } Point operator/( Point Q, int c) { Point P; P.x = Q.x / c; P.y = Q.y / c; P.z = Q.z / c; P.dimn = Q.dim(); return P; } Point operator/( Point Q, double c) { Point P; P.x = Q.x / c; P.y = Q.y / c; P.z = Q.z / c; P.dimn = Q.dim(); return P; } //------------------------------------------------------------------ // Point Addition (also convenient but often illegal) // is not valid unless part of an affine sum. // The programmer must enforce this (if they want to). //------------------------------------------------------------------ Point operator+( Point Q, Point R) { Point P; P.x = Q.x + R.x; P.y = Q.y + R.y; P.z = Q.z + R.z; P.dimn = max( Q.dim(), R.dim()); return P; } //------------------------------------------------------------------ // Affine Sums // Returns weighted sum, even when not affine, but... // Tests if coeffs add to 1. If not, sets: err = Esum. //------------------------------------------------------------------ Point asum( int n, int c[], Point Q[]) { int maxd = 0; int cs = 0; int i; Point P; for (i=0; i maxd) maxd = Q[i].dim(); } if (cs != 1) // not an affine sum P.err = Esum; // flag error, but compute sum anyway for (i=0; i maxd) maxd = Q[i].dim(); } if (cs != 1) // not an affine sum P.err = Esum; // flag error, but compute sum anyway for (i=0; iP2 // - makes sense in 2D only //------------------------------------------------------------------ double Point::isLeft( Point P1, Point P2) { if (dimn != 2 || P1.dim() != 2 || P2.dim() != 2) { err = Edim; // flag error, but compute anyway } return ((P1.x - x) * (P2.y - y) - (P2.x - x) * (P1.y - y)); } //------------------------------------------------------------------ // Error Routines //------------------------------------------------------------------ char* Point::errstr() { // return error string switch (err) { case Enot: return "no error"; case Edim: return "error: invalid dimension for operation"; case Esum: return "error: Point sum is not affine"; default: return "error: unknown err value"; } } mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/polygonArea.cpp0000644000175000017500000001250510267500030025771 0ustar debiandebian// Copyright 2000, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from its use. // Users of this code must verify correctness for their application. // a vertex point (or vector) is defined by its coordinates //typedef struct {int x, y, z;} Vert; // exclude z for 2D // a Triangle is given by three points: Vert V0, V1, V2 // a Polygon is given by: // int n = number of vertex points // Vert* V[] = an array of points with V[n]=V[0], V[n+1]=V[1] // Note: for efficiency low-level functions are declared to be inline. // isLeft(): tests if a point is Left|On|Right of an infinite line. // Input: three points P0, P1, and P2 // Return: >0 for P2 left of the line through P0 and P1 // =0 for P2 on the line // <0 for P2 right of the line #include "polygonArea.h" #include inline int isLeft( Vert P0, Vert P1, Vert P2 ) { return ( (P1.x - P0.x) * (P2.y - P0.y) - (P2.x - P0.x) * (P1.y - P0.y) ); } //=================================================================== // orientation2D_Triangle(): test the orientation of a triangle // Input: three vertex points V0, V1, V2 // Return: >0 for counterclockwise // =0 for none (degenerate) // <0 for clockwise inline int orientation2D_Triangle( Vert V0, Vert V1, Vert V2 ) { return isLeft(V0, V1, V2); } //=================================================================== // area2D_Triangle(): compute the area of a triangle // Input: three vertex points V0, V1, V2 // Return: the (float) area of T inline float area2D_Triangle( Vert V0, Vert V1, Vert V2 ) { return (float)isLeft(V0, V1, V2) / 2.0; } //=================================================================== // orientation2D_Polygon(): tests the orientation of a simple polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+1 vertices with V[n]=V[0] // Return: >0 for counterclockwise // =0 for none (degenerate) // <0 for clockwise // Note: this algorithm is faster than computing the signed area. int orientation2D_Polygon( int n, Vert* V ) { // first find rightmost lowest vertex of the polygon int rmin = 0; int xmin = V[0].x; int ymin = V[0].y; for (int i=1; i ymin) continue; if (V[i].y == ymin) { // just as low if (V[i].x < xmin) // and to left continue; } rmin = i; // a new rightmost lowest vertex xmin = V[i].x; ymin = V[i].y; } // test orientation at this rmin vertex // ccw <=> the edge leaving is left of the entering edge if (rmin == 0) return isLeft( V[n-1], V[0], V[1] ); else return isLeft( V[rmin-1], V[rmin], V[rmin+1] ); } //=================================================================== // area2D_Polygon(): computes the area of a 2D polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+2 vertices // with V[n]=V[0] and V[n+1]=V[1] // Return: the (float) area of the polygon float area2D_Polygon( int n, Vert* V ) { float area = 0; int i, j, k; // indices for (i=1, j=2, k=0; i<=n; i++, j++, k++) { area += V[i].x * (V[j].y - V[k].y); } return area / 2.0; } //=================================================================== // area3D_Polygon(): computes the area of a 3D planar polygon // Input: int n = the number of vertices in the polygon // Vert* V = an array of n+2 vertices in a plane // with V[n]=V[0] and V[n+1]=V[1] // Vert N = unit normal vector of the polygon's plane // Return: the (float) area of the polygon float area3D_Polygon( int n, Vert* V, Vert N ) { float area = 0; float an, ax, ay, az; // abs value of normal and its coords int coord; // coord to ignore: 1=x, 2=y, 3=z int i, j, k; // loop indices // select largest abs coordinate to ignore for projection ax = (N.x>0 ? N.x : -N.x); // abs x-coord ay = (N.y>0 ? N.y : -N.y); // abs y-coord az = (N.z>0 ? N.z : -N.z); // abs z-coord coord = 3; // ignore z-coord if (ax > ay) { if (ax > az) coord = 1; // ignore x-coord } else if (ay > az) coord = 2; // ignore y-coord // compute area of the 2D projection for (i=1, j=2, k=0; i<=n; i++, j++, k++) switch (coord) { case 1: area += (V[i].y * (V[j].z - V[k].z)); continue; case 2: area += (V[i].x * (V[j].z - V[k].z)); continue; case 3: area += (V[i].x * (V[j].y - V[k].y)); continue; } // scale to get area before projection an = sqrt( ax*ax + ay*ay + az*az); // length of normal vector switch (coord) { case 1: area *= (an / (2*ax)); break; case 2: area *= (an / (2*ay)); break; case 3: area *= (an / (2*az)); } return area; } //=================================================================== mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/objfile.h0000644000175000017500000000203610640045002024564 0ustar debiandebian#ifndef OBJFILE_H #define OBJFILE_H #ifdef __cplusplus extern "C" #endif /* __cplusplus */ bool detectObjFileContent ( char const * const aFilename , char aoGroupNames [ ] [ 256 ] , unsigned int * const aiNumOfGroupNames , char aoMaterialLibraries [ ] [ 256 ] , unsigned int * const aiNumOfMaterialLibraries , char aoMaterialNames [ ] [ 256 ] , unsigned int * const aiNumOfMaterialNames ) ; #ifdef __cplusplus extern "C" #endif /* __cplusplus */ bool readObjFileGroup ( char const * const aFilename , char const * const aGroupName , char aoMaterialNames [ ] [ 256 ] , unsigned int * const aiNumOfMaterialNames , float aoVertices [ ] [ 3 ] , unsigned int * const aiNumOfVertices , int aoTriangles [ ] [ 3 ] , unsigned int * const aiNumOfTriangles , float aoTextureVertices [ ] [ 2 ] , unsigned int * const aiNumOfTextureVertices , int aoTextureTriangles [ ] [ 3 ] , unsigned int * const aiNumOfTextureTriangles , int aoTriangleMaterialIndices [ ] , unsigned int * const aiNumOfTriangleMaterialIndices ) ; #endif /* OBJFILE_H */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/Vector.h0000755000175000017500000000606610354563754024453 0ustar debiandebian//================================================================== // Copyright 2002, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from it's use. // Users of this code must verify correctness for their application. //================================================================== #ifndef SS_Vector_H #define SS_Vector_H #include "common.h" //================================================================== // Vector Class Definition //================================================================== class Vector : public Point { public: // Constructors same as Point class Vector() : Point() {}; Vector( int a) : Point(a) {}; Vector( double a) : Point(a) {}; Vector( int a, int b) : Point(a,b) {}; Vector( double a, double b) : Point(a,b) {}; Vector( int a, int b, int c) : Point(a,b,c) {}; Vector( double a, double b, double c) : Point(a,b,c) {}; Vector( int n, int a[]) : Point(n,a) {}; Vector( int n, double a[]) : Point(n,a) {}; ~Vector() {}; //---------------------------------------------------------- // IO streams and Comparisons: inherit from Point class //---------------------------------------------------------- // Vector Unary Operations Vector operator-(); // unary minus Vector operator~(); // unary 2D perp operator //---------------------------------------------------------- // Scalar Multiplication friend Vector operator*( int, Vector); friend Vector operator*( double, Vector); friend Vector operator*( Vector, int); friend Vector operator*( Vector, double); // Scalar Division friend Vector operator/( Vector, int); friend Vector operator/( Vector, double); //---------------------------------------------------------- // Vector Arithmetic Operations Vector operator+( Vector); // vector add Vector operator-( Vector); // vector subtract double operator*( Vector); // inner dot product double operator|( Vector); // 2D exterior perp product Vector operator^( Vector); // 3D exterior cross product Vector& operator*=( double); // vector scalar mult Vector& operator/=( double); // vector scalar div Vector& operator+=( Vector); // vector increment Vector& operator-=( Vector); // vector decrement Vector& operator^=( Vector); // 3D exterior cross product //---------------------------------------------------------- // Vector Properties double len() { // vector length return sqrt(x*x + y*y + z*z); } double len2() { // vector length squared (faster) return (x*x + y*y + z*z); } //---------------------------------------------------------- // Special Operations void normalize(); // convert vector to unit length friend Vector sum( int, int[], Vector[]); // vector sum friend Vector sum( int, double[], Vector[]); // vector sum }; #endif //SS_Vector_H mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/intersections.cpp0000644000175000017500000002773310272266225026426 0ustar debiandebian// Intersections of Lines, Segments and Planes (2D and 3D) // Copyright 2001, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from its use. // Users of this code must verify correctness for their application. // Assume that classes are already given for the objects: // Point and Vector with // coordinates {float x, y, z;} // operators for: // == to test equality // != to test inequality // Point = Point ± Vector // Vector = Point - Point // Vector = Scalar * Vector (scalar product) // Vector = Vector * Vector (3D cross product) // Line and Ray and Segment with defining points {Point P0, P1;} // (a Line is infinite, Rays and Segments start at P0) // (a Ray extends beyond P1, but a Segment ends at P1) // Plane with a point and a normal {Point V0; Vector n;} //=================================================================== #include "intersections.h" // intersect2D_2Segments(): the intersection of 2 finite 2D segments // Input: two finite segments S1 and S2 // Output: *I0 = intersect point (when it exists) // *I1 = endpoint of intersect segment [I0,I1] (when it exists) // Return: 0=disjoint (no intersect) // 1=intersect in unique point I0 // 2=overlap in segment from I0 to I1 int intersect2D_Segments( Segment S1, Segment S2, Point* I0, Point* I1 ) { Vector u = S1.P1 - S1.P0; Vector v = S2.P1 - S2.P0; Vector w = S1.P0 - S2.P0; float D = perp(u,v); // test if they are parallel (includes either being a point) if (fabs(D) < SMALL_NUM) { // S1 and S2 are parallel if (perp(u,w) != 0 || perp(v,w) != 0) { return 0; // they are NOT collinear } // they are collinear or degenerate // check if they are degenerate points float du = dot(u,u); float dv = dot(v,v); if (du==0 && dv==0) { // both segments are points if (S1.P0 != S2.P0) // they are distinct points return 0; *I0 = S1.P0; // they are the same point return 1; } if (du==0) { // S1 is a single point if (inSegment(S1.P0, S2) == 0) // but is not in S2 return 0; *I0 = S1.P0; return 1; } if (dv==0) { // S2 a single point if (inSegment(S2.P0, S1) == 0) // but is not in S1 return 0; *I0 = S2.P0; return 1; } // they are collinear segments - get overlap (or not) float t0, t1; // endpoints of S1 in eqn for S2 Vector w2 = S1.P1 - S2.P0; if (v.x != 0) { t0 = w.x / v.x; t1 = w2.x / v.x; } else { t0 = w.y / v.y; t1 = w2.y / v.y; } if (t0 > t1) { // must have t0 smaller than t1 float t=t0; t0=t1; t1=t; // swap if not } if (t0 > 1 || t1 < 0) { return 0; // NO overlap } t0 = t0<0? 0 : t0; // clip to min 0 t1 = t1>1? 1 : t1; // clip to max 1 if (t0 == t1) { // intersect is a point *I0 = S2.P0 + t0 * v; return 1; } // they overlap in a valid subsegment *I0 = S2.P0 + t0 * v; *I1 = S2.P0 + t1 * v; return 2; } // the segments are skew and may intersect in a point // get the intersect parameter for S1 float sI = perp(v,w) / D; if (sI < 0 || sI > 1) // no intersect with S1 return 0; // get the intersect parameter for S2 float tI = perp(u,w) / D; if (tI < 0 || tI > 1) // no intersect with S2 return 0; *I0 = S1.P0 + sI * u; // compute S1 intersect point return 1; } //=================================================================== // inSegment(): determine if a point is inside a segment // Input: a point P, and a collinear segment S // Return: 1 = P is inside S // 0 = P is not inside S int inSegment( Point P, Segment S) { if (S.P0.x != S.P1.x) { // S is not vertical if (S.P0.x <= P.x && P.x <= S.P1.x) return 1; if (S.P0.x >= P.x && P.x >= S.P1.x) return 1; } else { // S is vertical, so test y coordinate if (S.P0.y <= P.y && P.y <= S.P1.y) return 1; if (S.P0.y >= P.y && P.y >= S.P1.y) return 1; } return 0; } //=================================================================== // intersect3D_SegmentPlane(): intersect a segment and a plane // Input: S = a segment, and Pn = a plane = {Point V0; Vector n;} // Output: *I0 = the intersect point (when it exists) // Return: 0 = disjoint (no intersection) // 1 = intersection in the unique point *I0 // 2 = the segment lies in the plane int intersect3D_SegmentPlane( Segment S, Plane Pn, Point* I ) { Vector u = S.P1 - S.P0; Vector w = S.P0 - Pn.V0; float D = dot(Pn.n, u); float N = -dot(Pn.n, w); if (fabs(D) < SMALL_NUM) { // segment is parallel to plane if (N == 0) // segment lies in plane return 2; else return 0; // no intersection } // they are not parallel // compute intersect param float sI = N / D; if (sI < 0 || sI > 1) return 0; // no intersection *I = S.P0 + sI * u; // compute segment intersect point return 1; } //=================================================================== // intersect3D_2Planes(): the 3D intersect of two planes // Input: two planes Pn1 and Pn2 // Output: *L = the intersection line (when it exists) // Return: 0 = disjoint (no intersection) // 1 = the two planes coincide // 2 = intersection in the unique line *L int intersect3D_2Planes( Plane Pn1, Plane Pn2, Line* L ) { Vector u = Pn1.n * Pn2.n; // cross product float ax = (u.x >= 0 ? u.x : -u.x); float ay = (u.y >= 0 ? u.y : -u.y); float az = (u.z >= 0 ? u.z : -u.z); // test if the two planes are parallel if ((ax+ay+az) < SMALL_NUM) { // Pn1 and Pn2 are near parallel // test if disjoint or coincide Vector v = Pn2.V0 - Pn1.V0; if (dot(Pn1.n, v) == 0) // Pn2.V0 lies in Pn1 return 1; // Pn1 and Pn2 coincide else return 0; // Pn1 and Pn2 are disjoint } // Pn1 and Pn2 intersect in a line // first determine max abs coordinate of cross product int maxc; // max coordinate if (ax > ay) { if (ax > az) maxc = 1; else maxc = 3; } else { if (ay > az) maxc = 2; else maxc = 3; } // next, to get a point on the intersect line // zero the max coord, and solve for the other two Point iP; // intersect point float d1, d2; // the constants in the 2 plane equations d1 = -dot(Pn1.n, Pn1.V0); // note: could be pre-stored with plane d2 = -dot(Pn2.n, Pn2.V0); // ditto switch (maxc) { // select max coordinate case 1: // intersect with x=0 iP.x = 0; iP.y = (d2*Pn1.n.z - d1*Pn2.n.z) / u.x; iP.z = (d1*Pn2.n.y - d2*Pn1.n.y) / u.x; break; case 2: // intersect with y=0 iP.x = (d1*Pn2.n.z - d2*Pn1.n.z) / u.y; iP.y = 0; iP.z = (d2*Pn1.n.x - d1*Pn2.n.x) / u.y; break; case 3: // intersect with z=0 iP.x = (d2*Pn1.n.y - d1*Pn2.n.y) / u.z; iP.y = (d1*Pn2.n.x - d2*Pn1.n.x) / u.z; iP.z = 0; } L->P0 = iP; L->P1 = iP + u; return 2; } //=================================================================== // Intersections of Rays, Segments, Planes and Triangles in 3D // Assume that classes are already given for the objects: // Point and Vector with // coordinates {float x, y, z;} // operators for: // == to test equality // != to test inequality // (Vector)0 = (0,0,0) (null vector) // Point = Point ± Vector // Vector = Point - Point // Vector = Scalar * Vector (scalar product) // Vector = Vector * Vector (cross product) // Line and Ray and Segment with defining points {Point P0, P1;} // (a Line is infinite, Rays and Segments start at P0) // (a Ray extends beyond P1, but a Segment ends at P1) // Plane with a point and a normal {Point V0; Vector n;} // Triangle with defining vertices {Point V0, V1, V2;} // Polyline and Polygon with n vertices {int n; Point *V;} // (a Polygon has V[n]=V[0]) //=================================================================== // intersect_RayTriangle(): intersect a ray with a 3D triangle // Input: a ray R, and a triangle T // Output: *I = intersection point (when it exists) // Return: -1 = triangle is degenerate (a segment or point) // 0 = disjoint (no intersect) // 1 = intersect in unique point I1 // 2 = are in the same plane int intersect_RayTriangle( Ray R, Triangle T, Point* I ) { Vector u, v, n; // triangle vectors Vector dir, w0, w; // ray vectors float r, a, b; // params to calc ray-plane intersect // get triangle edge vectors and plane normal u = T.V1 - T.V0; v = T.V2 - T.V0; n = u ^ v; // cross product if (n == (Vector)0) // triangle is degenerate return -1; // do not deal with this case dir = R.P1 - R.P0; // ray direction vector w0 = R.P0 - T.V0; a = -dot(n,w0); b = dot(n,dir); if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane if (a == 0) // ray lies in triangle plane return 2; else return 0; // ray disjoint from plane } // get intersect point of ray with triangle plane r = a / b; if (r < 0.0) // ray goes away from triangle return 0; // => no intersect // for a segment, also test if (r > 1.0) => no intersect *I = R.P0 + r * dir; // intersect point of ray and plane //printf ("I: (%f, %f, %f) \n", I->x, I->y, I->z); // is I inside T? float uu, uv, vv, wu, wv, D; uu = dot(u,u); uv = dot(u,v); vv = dot(v,v); w = *I - T.V0; wu = dot(w,u); wv = dot(w,v); D = uv * uv - uu * vv; // get and test parametric coords float s, t; s = (uv * wv - vv * wu) / D; if (s < 0.0 || s > 1.0) // I is outside T return 0; t = (uv * wu - uu * wv) / D; if (t < 0.0 || (s + t) > 1.0) // I is outside T return 0; //printf ("I is in T: (%f, %f, %f) \n", I->x, I->y, I->z); //printf ("T:[[%f, %f, %f],[%f,%f,%f],[%f,%f,%f]]\n", T.V0.x, T.V0.y, T.V0.z, T.V1.x, T.V1.y, T.V1.z, T.V2.x, T.V2.y, T.V2.z); return 1; // I is in T } /* rays = [ [[10.082968845963478, 54.963155567646027, 20.209468066692352], [9.9849128723144531, 54.28094482421875, 19.484897613525391]] ] t = [[9.6853628158569336, 54.199100494384766, 19.562088012695312], [10.186515808105469, 54.1707763671875, 19.562088012695312], [10.186515808105469, 54.432743072509766, 19.302522659301758]] intersect_RayTriangle(rays[0], t) #right answer (1, (9.9834707538105185, 54.270911486115345, 19.474241287153518)) */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/geomstructs.h0000644000175000017500000000155010354564205025546 0ustar debiandebian#ifndef SS_Geomstructs_H #define SS_Geomstructs_H #include "point.h" #include "Vector.h" // Line, Ray and Segment with defining points {Point P0, P1;}. // Line is infinite, Rays and Segments start at P0, // a Ray extends beyond P1, but a Segment ends at P1. typedef struct { Point P0, P1; } Line; typedef struct { Point P0, P1; } Segment; typedef struct { Point P0, P1; } Ray; typedef struct { Point V0; Vector n; } Plane; typedef struct { //initial position and velocity vector Point P0; Vector v; }Track; // Triangle with defining vertices {Point V0, V1, V2;} typedef struct { Point V0, V1, V2; } Triangle; // Polyline and Polygon with n vertices {int n; Point *V;} // (a Polygon has V[n]=V[0]) // Ball with a center and radius typedef struct { Point center; float radius; } Ball; #endif //SS_Geomstructs_H mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/boundingContainers.cpp0000644000175000017500000000661310271251057027356 0ustar debiandebian// Copyright 2001, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from its use. // Users of this code must verify correctness for their application. // Assume that classes are already given for the objects: // Point and Vector with // coordinates {float x, y;} // operators for: // Point = Point ± Vector // Vector = Point - Point // Vector = Vector ± Vector // Vector = Scalar * Vector (scalar product) // Vector = Vector / Scalar (scalar division) // Ball with a center and radius {Point center; float radius;} //=================================================================== #include "boundingContainers.h" // fastBall(): a fast approximation of the bounding ball for a point set // based on the algorithm given by [Jack Ritter, 1990] // Input: an array V[] of n points // Output: a bounding ball = {Point center; float radius;} void fastBall( Point V[], int n, Ball* B) { Point C; // Center of ball float rad, rad2; // radius and radius squared float xmin, xmax, ymin, ymax; // bounding box extremes int Pxmin, Pxmax, Pymin, Pymax; // index of V[] at box extreme int i; // find a large diameter to start with // first get the bounding box and V[] extreme points for it xmin = xmax = V[0].x; ymin = ymax = V[0].y; Pxmin = Pxmax = Pymin = Pymax = 0; for (i=1; i xmax) { xmax = V[i].x; Pxmax = i; } if (V[i].y < ymin) { ymin = V[i].y; Pymin = i; } else if (V[i].y > ymax) { ymax = V[i].y; Pymax = i; } } // select the largest extent as an initial diameter for the ball Vector dVx = V[Pxmax] - V[Pxmin]; // diff of Vx max and min Vector dVy = V[Pymax] - V[Pymin]; // diff of Vy max and min float dx2 = norm2(dVx); // Vx diff squared float dy2 = norm2(dVy); // Vy diff squared if (dx2 >= dy2) { // x direction is largest extent C = V[Pxmin] + (dVx / 2.0); // Center = midpoint of extremes rad2 = norm2(V[Pxmax] - C); // radius squared } else { // y direction is largest extent C = V[Pymin] + (dVy / 2.0); // Center = midpoint of extremes rad2 = norm2(V[Pymax] - C); // radius squared } rad = sqrt(rad2); // now check that all points V[i] are in the ball // and if not, expand the ball just enough to include them Vector dV; float dist, dist2; for (i=0; icenter = C; B->radius = rad; return; } mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/objfile.cpp0000644000175000017500000003560511224501545025137 0ustar debiandebian#include #include #include #include "objfile.h" extern "C" bool detectObjFileContent ( char const * const aFilename , char aoGroupNames [ ] [ 256 ] , unsigned int * const aiNumOfGroupNames , char aoMaterialLibraries [ ] [ 256 ] , unsigned int * const aiNumOfMaterialLibraries , char aoMaterialNames [ ] [ 256 ] , unsigned int * const aiNumOfMaterialNames ) { char a ; unsigned int i ; char lTmpName [ 1024 ] ; assert ( aFilename ) ; assert ( * aFilename != 0 ) ; assert ( aiNumOfGroupNames ) ; assert ( aiNumOfMaterialLibraries ) ; assert ( aiNumOfMaterialNames ) ; unsigned int lNumOfGroupNames = 1 ; // 1 as a placeholder for the default unsigned int lNumOfMaterialLibraries = 0 ; unsigned int lNumOfMaterialNames = 1 ; // 1 as a placeholder for the default material strcpy ( aoGroupNames [ 0 ] , "default" ) ; strcpy ( aoMaterialNames [ 0 ] , "default" ) ; std :: ifstream file_in ( aFilename ) ; if ( file_in . eof ( ) ) { file_in . close ( ) ; return false ; } file_in.get(a); while ( ! file_in.eof ( ) ) { if ( a == 0x0D ) { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && a == 0x0A ) { file_in . get ( a ) ; } switch ( a ) { case 'g' : if ( * aiNumOfGroupNames <= lNumOfGroupNames ) { file_in . close ( ) ; return false ; } file_in >> aoGroupNames [ lNumOfGroupNames ] ; // we add only groupnames that are not already in the list for ( i = 0 ; i < lNumOfGroupNames ; i ++ ) { if ( 0 == strcmp ( aoGroupNames [ i ] , aoGroupNames [ lNumOfGroupNames ] ) ) { break ; } } if ( i == lNumOfGroupNames ) { lNumOfGroupNames ++ ; } break ; case 'm' : file_in . putback ( a ) ; file_in >> lTmpName ; if ( 0 == strcmp( "mtllib" , lTmpName ) ) { assert ( aoMaterialLibraries ) ; file_in . get ( a ) ; while ( ! file_in.eof ( ) && ( a != 0x0D && a != 0x0A ) ) { file_in . putback ( a ) ; file_in >> aoMaterialLibraries [ lNumOfMaterialLibraries ] ; for ( i = 0 ; i < lNumOfMaterialLibraries ; i ++ ) { if ( 0 == strcmp ( aoMaterialLibraries [ i ] , aoMaterialLibraries [ lNumOfMaterialLibraries ] ) ) { break ; } } if ( i == lNumOfMaterialLibraries ) { lNumOfMaterialLibraries ++ ; } do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; } file_in . putback ( a ) ; } break ; case 'u' : file_in . putback ( a ) ; file_in >> lTmpName ; if ( 0 == strcmp( "usemtl" , lTmpName ) ) { if ( aoMaterialNames ) { file_in >> aoMaterialNames [ lNumOfMaterialNames ] ; for ( i = 0 ; i < lNumOfMaterialNames ; i ++ ) { if ( 0 == strcmp ( aoMaterialNames [ i ] , aoMaterialNames [ lNumOfMaterialNames ] ) ) { break ; } } if ( i == lNumOfMaterialNames ) { lNumOfMaterialNames ++ ; } } else { lNumOfMaterialNames ++ ; } } break ; default : ; } do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && a != 0x0D && a != 0x0A ) ; } file_in . close ( ) ; * aiNumOfGroupNames = lNumOfGroupNames ; * aiNumOfMaterialLibraries = lNumOfMaterialLibraries ; * aiNumOfMaterialNames = lNumOfMaterialNames ; return true ; } extern "C" bool readObjFileGroup ( char const * const aFilename , char const * const aGroupName , char aMaterialNames [ ] [ 256 ] , unsigned int * const aNumOfMaterialNames , float aoVertices [ ] [ 3 ] , unsigned int * const aiNumOfVertices , int aoTriangles [ ] [ 3 ] , unsigned int * const aiNumOfTriangles , float aoTextureVertices [ ] [ 2 ] , unsigned int * const aiNumOfTextureVertices , int aoTextureTriangles [ ] [ 3 ] , unsigned int * const aiNumOfTextureTriangles , int aoTriangleMaterialIndices [ ] , unsigned int * const aiNumOfTriangleMaterialIndices ) { char a ; unsigned int i ; assert ( aFilename ) ; assert ( * aFilename != 0 ) ; assert ( aGroupName ) ; assert ( * aGroupName != 0 ) ; assert ( aNumOfMaterialNames ) ; assert ( aiNumOfVertices ) ; assert ( aiNumOfTriangles ) ; assert ( aiNumOfTextureVertices ) ; assert ( aiNumOfTextureTriangles ) ; assert ( aiNumOfTriangleMaterialIndices ) ; unsigned int lTmpU ; char lTmpName [ 1024 ] ; char * const & lGroupName = lTmpName ; unsigned int lNumOfVertices = 0 ; unsigned int lNumOfTriangles = 0 ; unsigned int lNumOfTextureVertices = 0 ; unsigned int lNumOfTextureTriangles = 0 ; unsigned int lNumOfTriangleMaterialIndices = 0 ; unsigned int lCurrentMaterialIndex = 0 ; bool lAskedGroupName ; if ( ( 0 == aGroupName [ 0 ] ) || ( 0 == strcmp ( aGroupName , "default" ) ) ) { lAskedGroupName = true ; } else { lAskedGroupName = false ; } std :: ifstream file_in ( aFilename ) ; if ( file_in . eof ( ) ) { file_in . close ( ) ; return false ; } file_in.get(a); while ( ! file_in.eof ( ) ) { if ( a == 0x0D ) { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && a == 0x0A ) { file_in . get ( a ) ; } switch ( a ) { case 'g' : file_in >> lGroupName ; if ( 0 == strcmp( aGroupName , lGroupName ) ) { lAskedGroupName = true ; } else { lAskedGroupName = false ; } break ; case 'u' : file_in . putback ( a ) ; file_in >> lTmpName ; if ( 0 == strcmp( "usemtl" , lTmpName ) ) { if ( aMaterialNames ) { file_in >> lTmpName ; for ( i = 0 ; i < * aNumOfMaterialNames ; i ++ ) { if ( 0 == strcmp ( aMaterialNames [ i ] , lTmpName ) ) { lCurrentMaterialIndex = i ; break ; } } if ( i == * aNumOfMaterialNames ) { assert ( false ) ; } } } break ; case 'v' : file_in . get ( a ) ; switch ( a ) { case ' ' : if ( aoVertices ) { if ( * aiNumOfVertices <= lNumOfVertices ) { file_in . close ( ) ; return false ; } file_in >> aoVertices [ lNumOfVertices ] [ 0 ] ; file_in >> aoVertices [ lNumOfVertices ] [ 1 ] ; file_in >> aoVertices [ lNumOfVertices ] [ 2 ] ; } lNumOfVertices ++ ; break ; case 't' : if ( aoTextureVertices ) { if ( * aiNumOfTextureVertices <= lNumOfTextureVertices ) { file_in . close ( ) ; return false ; } file_in >> aoTextureVertices [ lNumOfTextureVertices ] [ 0 ] ; file_in >> aoTextureVertices [ lNumOfTextureVertices ] [ 1 ] ; aoTextureVertices [ lNumOfTextureVertices ] [ 1 ] = 1 - aoTextureVertices [ lNumOfTextureVertices ] [ 1 ] ; } lNumOfTextureVertices ++ ; break ; default : ; } break ; case 'f' : if ( lAskedGroupName == false ) { break ; } file_in . get ( a ) ; if ( a == 'o' ) { file_in . get ( a ) ; } if ( a == ' ' ) { if (aoTriangles) { if ( * aiNumOfTriangles <= lNumOfTriangles ) { file_in . close ( ) ; return false ; } file_in >> aoTriangles [ lNumOfTriangles ] [ 0 ] ; } else { file_in >> lTmpU ; } do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { file_in >> lTmpU ; } else { file_in . putback ( a ) ; if (aoTextureTriangles) { if ( * aiNumOfTextureTriangles <= lNumOfTextureTriangles ) { file_in . close ( ) ; return false ; } file_in >> aoTextureTriangles [ lNumOfTextureTriangles ] [ 0 ] ; } else { file_in >> lTmpU ; } do { file_in . get ( a ) ; } while ( ! ( file_in . eof ( ) || a == ' ' || a == 0x0D || a == 0x0A ) ) ; } } else { file_in . putback ( a ) ; } if (aoTriangles) { file_in >> aoTriangles [ lNumOfTriangles ] [ 1 ] ; } else { file_in >> lTmpU ; } do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { file_in >> lTmpU ; } else { file_in . putback ( a ) ; if (aoTextureTriangles) { file_in >> aoTextureTriangles [ lNumOfTextureTriangles ] [ 1 ] ; } else { file_in >> lTmpU ; } do { file_in . get ( a ) ; } while ( ! ( file_in . eof ( ) || a == ' ' || a == 0x0D || a == 0x0A ) ) ; } } else file_in . putback ( a ) ; if ( aoTriangles ) { file_in >> aoTriangles [ lNumOfTriangles ] [ 2 ] ; aoTriangles [ lNumOfTriangles ] [ 0 ] -- ; aoTriangles [ lNumOfTriangles ] [ 1 ] -- ; aoTriangles [ lNumOfTriangles ] [ 2 ] -- ; if ( aoTriangleMaterialIndices ) { aoTriangleMaterialIndices [ lNumOfTriangles ] = lCurrentMaterialIndex ; } } else { file_in >> lTmpU ; } lNumOfTriangles ++ ; do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { file_in >> lTmpU ; } else { file_in . putback ( a ) ; if ( aoTextureTriangles ) { file_in >> aoTextureTriangles [ lNumOfTextureTriangles ] [ 2 ] ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 0 ] -- ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 1 ] -- ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 2 ] -- ; } else { file_in >> lTmpU ; } lNumOfTextureTriangles ++ ; } do { file_in . get ( a ) ; } while ( ! ( file_in . eof ( ) || a == ' ' || a == 0x0D || a == 0x0A ) ) ; file_in.putback ( a ) ; do { file_in.get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; } file_in . putback ( a ) ; if ( ! file_in . eof ( ) && a != 0x0D && a != 0x0A) { if (aoTriangles) { if ( * aiNumOfTriangles <= lNumOfTriangles ) { file_in . close ( ) ; return false ; } file_in >> aoTriangles [ lNumOfTriangles ] [ 0 ] ; aoTriangles [ lNumOfTriangles ] [ 0 ] -- ; aoTriangles [ lNumOfTriangles ] [ 1 ] = aoTriangles [ lNumOfTriangles - 1 ] [ 0 ] ; aoTriangles [ lNumOfTriangles ] [ 2 ] = aoTriangles [ lNumOfTriangles - 1 ] [ 2 ] ; if ( aoTriangleMaterialIndices ) { aoTriangleMaterialIndices [ lNumOfTriangles ] = lCurrentMaterialIndex ; } } else { file_in >> lTmpU ; } lNumOfTriangles ++ ; do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && a == ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && ( a == ' ' || a == '\t' ) ) ; if ( a == '/' ) { file_in >> lTmpU ; } else { file_in . putback ( a ) ; if (aoTextureTriangles) { if ( * aiNumOfTextureTriangles <= lNumOfTextureTriangles ) { file_in . close ( ) ; return false ; } file_in >> aoTextureTriangles [ lNumOfTextureTriangles ] [ 0 ] ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 0 ] -- ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 1 ] = aoTextureTriangles [ lNumOfTextureTriangles - 1 ] [ 0 ] ; aoTextureTriangles [ lNumOfTextureTriangles ] [ 2 ] = aoTextureTriangles [ lNumOfTextureTriangles - 1 ] [ 2 ] ; } else { file_in >> lTmpU ; } lNumOfTextureTriangles ++ ; } } else { file_in . putback ( a ) ; } } } break ; default : ; } do { file_in . get ( a ) ; } while ( ! file_in.eof ( ) && a != 0x0D && a != 0x0A ) ; } file_in . close ( ) ; * aiNumOfVertices = lNumOfVertices ; * aiNumOfTriangles = lNumOfTriangles ; * aiNumOfTextureVertices = lNumOfTextureVertices ; * aiNumOfTextureTriangles = lNumOfTextureTriangles ; return true ; } mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/intersections.h0000644000175000017500000000357510267500030026056 0ustar debiandebian#ifndef SS_Intersections_H #define SS_Intersections_H #include "geomstructs.h" // intersect2D_2Segments(): the intersection of 2 finite 2D segments // Input: two finite segments S1 and S2 // Output: *I0 = intersect point (when it exists) // *I1 = endpoint of intersect segment [I0,I1] (when it exists) // Return: 0=disjoint (no intersect) // 1=intersect in unique point I0 // 2=overlap in segment from I0 to I1 int intersect2D_Segments( Segment S1, Segment S2, Point* I0, Point* I1 ); // inSegment(): determine if a point is inside a segment // Input: a point P, and a collinear segment S // Return: 1 = P is inside S // 0 = P is not inside S int inSegment( Point P, Segment S); // intersect3D_SegmentPlane(): intersect a segment and a plane // Input: S = a segment, and Pn = a plane = {Point V0; Vector n;} // Output: *I0 = the intersect point (when it exists) // Return: 0 = disjoint (no intersection) // 1 = intersection in the unique point *I0 // 2 = the segment lies in the plane int intersect3D_SegmentPlane( Segment S, Plane Pn, Point* I ); // intersect3D_2Planes(): the 3D intersect of two planes // Input: two planes Pn1 and Pn2 // Output: *L = the intersection line (when it exists) // Return: 0 = disjoint (no intersection) // 1 = the two planes coincide // 2 = intersection in the unique line *L int intersect3D_2Planes( Plane Pn1, Plane Pn2, Line* L ); // intersect_RayTriangle(): intersect a ray with a 3D triangle // Input: a ray R, and a triangle T // Output: *I = intersection point (when it exists) // Return: -1 = triangle is degenerate (a segment or point) // 0 = disjoint (no intersect) // 1 = intersect in unique point I1 // 2 = are in the same plane int intersect_RayTriangle( Ray R, Triangle T, Point* I ); #endif mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/point.h0000755000175000017500000001147011015600572024316 0ustar debiandebian//================================================================== // Copyright 2002, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from it's use. // Users of this code must verify correctness for their application. //================================================================== #ifndef SS_Point_H #define SS_Point_H // forward declaration (added by guillaume) class Vector; #include "common.h" using namespace std; //================================================================== // Point Class Definition //================================================================== class Point { friend class Vector; protected: int dimn; // # coords (1, 2, or 3 max here) Error err; // error indicator public: double x, y, z; // z=0 for 2D, y=z=0 for 1D //---------------------------------------------------------- // Lots of Constructors (add more as needed) Point() { dimn=3; x=y=z=0; err=Enot; } // 1D Point Point( int a) { dimn=1; x=a; y=z=0; err=Enot; } Point( double a) { dimn=1; x=a; y=z=0; err=Enot; } // 2D Point Point( int a, int b) { dimn=2; x=a; y=b; z=0; err=Enot; } Point( double a, double b) { dimn=2; x=a; y=b; z=0; err=Enot; } // 3D Point Point( int a, int b, int c) { dimn=3; x=a; y=b; z=c; err=Enot; } Point( double a, double b, double c) { dimn=3; x=a; y=b; z=c; err=Enot; } // n-dim Point Point( int n, int a[]); Point( int n, double a[]); // Destructor ~Point() {}; //---------------------------------------------------------- // Input/Output streams friend istream& operator>>( istream&, Point&); friend ostream& operator<<( ostream&, Point); //---------------------------------------------------------- // Assignment "=": use the default to copy all members int dim() { return dimn; } // get dimension int setdim( int); // set new dimension //---------------------------------------------------------- // Comparison (dimension must match, or not) int operator==( Point); int operator!=( Point); //---------------------------------------------------------- // Point and Vector Operations (always valid) Vector operator-( Point); // Vector difference Point operator+( Vector); // +translate Point operator-( Vector); // -translate Point& operator+=( Vector); // inc translate Point& operator-=( Vector); // dec translate //---------------------------------------------------------- // Point Scalar Operations (convenient but often illegal) // using any type of scalar (int, float, or double) // are not valid for points in general, // unless they are 'affine' as coeffs of // a sum in which all the coeffs add to 1, // such as: the sum (a*P + b*Q) with (a+b == 1). // The programmer must enforce this (if they want to). // Scalar Multiplication friend Point operator*( int, Point); friend Point operator*( double, Point); friend Point operator*( Point, int); friend Point operator*( Point, double); // Scalar Division friend Point operator/( Point, int); friend Point operator/( Point, double); //---------------------------------------------------------- // Point Addition (also convenient but often illegal) // is not valid unless part of an affine sum. // The programmer must enforce this (if they want to). friend Point operator+( Point, Point); // add points // Affine Sum // Returns weighted sum, even when not affine, but... // Tests if coeffs add to 1. If not, sets: err = Esum. friend Point asum( int, int[], Point[]); friend Point asum( int, double[], Point[]); //---------------------------------------------------------- // Point Relations friend double d( Point, Point); // Distance friend double d2( Point, Point); // Distance^2 double isLeft( Point, Point); // 2D only double Area( Point, Point); // any dim for triangle PPP // Collinearity Conditions (any dim n) softSurferBoolean isOnLine( Point, Point, char); // is On line (char= flag) softSurferBoolean isOnLine( Point, Point); // is On line (flag= all) softSurferBoolean isBefore( Point, Point); // is On line (flag= before) softSurferBoolean isBetween( Point, Point); // is On line (flag= between) softSurferBoolean isAfter( Point, Point); // is On line (flag= after) softSurferBoolean isOnRay( Point, Point); // is On line (flag= between|after) //---------------------------------------------------------- // Error Handling void clerr() { err = Enot;} // clear error int geterr() { return err;} // get error char* errstr(); // return error string }; #endif //SS_Point_H mgltools-geomutils-1.5.7~rc1~cvs.20130519/src/geomAlgorithms/Vector.cpp0000755000175000017500000001167710354563754025012 0ustar debiandebian//================================================================== // Copyright 2002, softSurfer (www.softsurfer.com) // This code may be freely used and modified for any purpose // providing that this copyright notice is included with it. // SoftSurfer makes no warranty for this code, and cannot be held // liable for any real or imagined damage resulting from it's use. // Users of this code must verify correctness for their application. //================================================================== #include "point.h" #include "Vector.h" //================================================================== // Vector Class Methods //================================================================== //------------------------------------------------------------------ // Unary Ops //------------------------------------------------------------------ // Unary minus Vector Vector::operator-() { Vector v; v.x = -x; v.y = -y; v.z = -z; v.dimn = dimn; return v; } // Unary 2D perp operator Vector Vector::operator~() { if (dimn != 2) err = Edim; // and continue anyway Vector v; v.x = -y; v.y = x; v.z = z; v.dimn = dimn; return v; } //------------------------------------------------------------------ // Scalar Ops //------------------------------------------------------------------ // Scalar multiplication Vector operator*( int c, Vector w ) { Vector v; v.x = c * w.x; v.y = c * w.y; v.z = c * w.z; v.dimn = w.dim(); return v; } Vector operator*( double c, Vector w ) { Vector v; v.x = c * w.x; v.y = c * w.y; v.z = c * w.z; v.dimn = w.dim(); return v; } Vector operator*( Vector w, int c ) { Vector v; v.x = c * w.x; v.y = c * w.y; v.z = c * w.z; v.dimn = w.dim(); return v; } Vector operator*( Vector w, double c ) { Vector v; v.x = c * w.x; v.y = c * w.y; v.z = c * w.z; v.dimn = w.dim(); return v; } // Scalar division Vector operator/( Vector w, int c ) { Vector v; v.x = w.x / c; v.y = w.y / c; v.z = w.z / c; v.dimn = w.dim(); return v; } Vector operator/( Vector w, double c ) { Vector v; v.x = w.x / c; v.y = w.y / c; v.z = w.z / c; v.dimn = w.dim(); return v; } //------------------------------------------------------------------ // Arithmetic Ops //------------------------------------------------------------------ Vector Vector::operator+( Vector w ) { Vector v; v.x = x + w.x; v.y = y + w.y; v.z = z + w.z; v.dimn = max( dimn, w.dim()); return v; } Vector Vector::operator-( Vector w ) { Vector v; v.x = x - w.x; v.y = y - w.y; v.z = z - w.z; v.dimn = max( dimn, w.dim()); return v; } //------------------------------------------------------------------ // Products //------------------------------------------------------------------ // Inner Dot Product double Vector::operator*( Vector w ) { return (x * w.x + y * w.y + z * w.z); } // 2D Exterior Perp Product double Vector::operator|( Vector w ) { if (dimn != 2) err = Edim; // and continue anyway return (x * w.y - y * w.x); } // 3D Exterior Cross Product Vector Vector::operator^( Vector w ) { Vector v; v.x = y * w.z - z * w.y; v.y = z * w.x - x * w.z; v.z = x * w.y - y * w.x; v.dimn = 3; return v; } //------------------------------------------------------------------ // Shorthand Ops //------------------------------------------------------------------ Vector& Vector::operator*=( double c ) { // vector scalar mult x *= c; y *= c; z *= c; return *this; } Vector& Vector::operator/=( double c ) { // vector scalar div x /= c; y /= c; z /= c; return *this; } Vector& Vector::operator+=( Vector w ) { // vector increment x += w.x; y += w.y; z += w.z; dimn = max(dimn, w.dim()); return *this; } Vector& Vector::operator-=( Vector w ) { // vector decrement x -= w.x; y -= w.y; z -= w.z; dimn = max(dimn, w.dim()); return *this; } Vector& Vector::operator^=( Vector w ) { // 3D exterior cross product double ox=x, oy=y, oz=z; x = oy * w.z - oz * w.y; y = oz * w.x - ox * w.z; z = ox * w.y - oy * w.x; dimn = 3; return *this; } //------------------------------------------------------------------ // Special Operations //------------------------------------------------------------------ void Vector::normalize() { // convert to unit length double ln = sqrt( x*x + y*y + z*z ); if (ln == 0) return; // do nothing for nothing x /= ln; y /= ln; z /= ln; } Vector sum( int n, int c[], Vector w[] ) { // vector sum int maxd = 0; Vector v; int i; for (i=0; i maxd) maxd = w[i].dim(); } v.dimn = maxd; for (i=0; i maxd) maxd = w[i].dim(); } v.dimn = maxd; for (i=0; idimensions[0]; dims[1] = array->dimensions[1]; cdata = array->data; if(dims[1] != 3 && dims[1] != 2) { PyErr_SetString(PyExc_ValueError, "Wrong shape of the input array; Expected (n,3) or (n,2)"); return NULL; } $1 = (Point *)malloc(dims[0]*sizeof(Point)); for (int i =0; i< dims[0]; i++) { double x, y,z; x = *(double *)(cdata + i*array->strides[0]); y = *(double *)(cdata + i*array->strides[0] + array->strides[1]); if (dims[1] ==2) { z = 0; $1[i] = Point(x, y); } else // dims[1] ==3 { z = *(double *)(cdata + i*array->strides[0] + 2*array->strides[1]); $1[i] = Point(x, y, z); } //printf ("point [%d] = (%f, %f, %f )\n", i, x, y, z); $2 = dims[0]; } } %typemap(freearg)(Point P[], int n) { if (array$argnum ) Py_DECREF((PyObject *)array$argnum); if ($1) free($1); } //typemap for Point to input list [x,y], or list [x,y,z] from Python %typemap (in) Point (PyObject *o = NULL , double temp[3] = {0.0, 0.0, 0.0}, int dim ) { if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); return NULL; } dim = PySequence_Length($input); if (dim != 3 && dim != 2) { PyErr_SetString(PyExc_ValueError,"Wrong list size; Expected 2 or 3 elements"); return NULL; } for (int i = 0; i < dim; i++) { o = PyList_GetItem($input,i); if (PyNumber_Check(o)) temp[i] = (double) PyFloat_AsDouble(o); else { PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); return NULL; } } if (dim == 2) { $1.x = temp[0]; $1.y = temp[1]; } else // dim == 3 { $1.x = temp[0]; $1.y = temp[1]; $1.z = temp[2]; } $1.setdim(dim); } //typemap for Line , Segment, Ray to input list [[x, y], [x,y]] or [[x,y,z], [x,y,z]] %typemap (in) Line (PyObject *pyobj = NULL, PyObject *item = NULL, Point P[2], double temp[3] = {0.0, 0.0, 0.0}, int dim) { if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a list of 2 lists"); return NULL; } if( PySequence_Length($input) != 2) { PyErr_SetString(PyExc_ValueError,"Wrong list size; Expected a list of 2 lists"); return NULL; } for (int i = 0; i < 2; i++) { pyobj = PyList_GetItem($input, i); if ( !PyList_Check(pyobj)) { PyErr_SetString(PyExc_ValueError, "Expecting a list of 2 lists"); return NULL; } dim = PySequence_Length(pyobj); if (dim != 3 && dim != 2) { PyErr_SetString(PyExc_ValueError,"Wrong list size; Expected 2 or 3 elements"); return NULL; } for (int j = 0; j < dim; j++) { item = PyList_GetItem(pyobj, j); temp[j] = (double) PyFloat_AsDouble(item); } if (dim == 2) P[i] = Point(temp[0], temp[1]); else // dim == 3 P[i]= Point(temp[0], temp[1], temp[2]); } $1.P0 = P[0]; $1.P1 = P[1]; } %apply Line {Segment, Ray}; //typemap for Point* to output a list [x,y,z] from Python // (in 2D case z = 0.0) //%include "fragments.i" %typemap(in, numinputs=0) Point* (Point point) { $1 = &point; } //%typemap(argout,fragment="t_output_helper" ) Point* (PyObject *newlist= NULL) %typemap(argout ) Point* (PyObject *newlist= NULL) { newlist = PyList_New(3); PyList_SetItem(newlist, 0, PyFloat_FromDouble($1->x) ); PyList_SetItem(newlist, 1, PyFloat_FromDouble($1->y) ); if ($1->dim()==3) PyList_SetItem(newlist, 2, PyFloat_FromDouble($1->z) ); else // $1->dim()== 2 PyList_SetItem(newlist, 2, PyFloat_FromDouble(0.0) ); $result = t_output_helper2($result, newlist); } // typemap for argument Triangle to input a sequence : [[x1,y1,z1],[x2,y2,z2],[x3,y3,z3]] %typemap (in) Triangle (PyObject *pyobj = NULL, PyObject *item = NULL, Point P[3], double temp[3] = {0.0, 0.0, 0.0}, int dim) { if (!PySequence_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a sequence: [[x1,y1,z1],[x2,y2,z2],[x3,y3,z3]]"); return NULL; } if( PySequence_Length($input) != 3) { PyErr_SetString(PyExc_ValueError,"Wrong sequence size; Expecting (3, 3)"); return NULL; } for (int i = 0; i < 3; i++) { pyobj = PySequence_GetItem($input, i); if ( !PySequence_Check(pyobj)) { PyErr_SetString(PyExc_ValueError, "Expecting a sequence: [x, y, z]"); return NULL; } dim = PySequence_Length(pyobj); if (dim != 3) { PyErr_SetString(PyExc_ValueError,"Wrong sequence size; Expecting (3, 3)"); return NULL; } for (int j = 0; j < dim; j++) { item = PyList_GetItem(pyobj, j); temp[j] = (double) PyFloat_AsDouble(item); } P[i]= Point(temp[0], temp[1], temp[2]); } $1.V0 = P[0]; $1.V1 = P[1]; $1.V2 = P[2]; } //typemap for argument Plane={Point V0; Vector n;} // to input a list [[x1, y1, z1], [x2, y2, z2]] in Python %typemap (in) Plane (PyObject *pyobj = NULL, PyObject *item = NULL, double coords[2][3]={{.0, .0, .0}, {.0,.0,.0}}, int dim) { if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expected a list: [[x1, y1, z1], [x2, y2, z2]] "); return NULL; } if( PySequence_Length($input) != 2) { PyErr_SetString(PyExc_ValueError,"Wrong list size. Expected a list of 2 lists; "); return NULL; } for (int i = 0; i < 2; i++) { pyobj = PyList_GetItem($input, i); if ( !PyList_Check(pyobj)) { PyErr_SetString(PyExc_ValueError, "Wrong input type. Expected a list of 2 lists"); return NULL; } dim = PySequence_Length(pyobj); if (dim != 3 && dim != 2) { PyErr_SetString(PyExc_ValueError,"Wrong list size; Expected 2 or 3 elements"); return NULL; } for (int j = 0; j < dim; j++) { item = PyList_GetItem(pyobj, j); coords[i][j] = (double) PyFloat_AsDouble(item); } } $1.V0 = Point(coords[0][0], coords[0][1], coords[0][2]); $1.n = Vector(coords[1][0], coords[1][1], coords[1][2]); } //typemap for Line* to output a list [[x1,y1,z1], [x2, y2, z2]] from Python // (in 2D case z = 0.0) //%include "fragments.i" %typemap(in, numinputs=0) Line* (Line line) { $1 = &line; } //%typemap(argout,fragment="t_output_helper" ) Line* (PyObject * l, PyObject * ll, Point PP[2]) %typemap(argout ) Line* (PyObject * l, PyObject * ll, Point PP[2]) { l = PyList_New(2); ll = PyList_New(3); PP[0] = $1->P0; PP[1] = $1->P1; for (int i = 0; i<2; i++) { PyList_SetItem(ll, 0, PyFloat_FromDouble(PP[i].x) ); PyList_SetItem(ll, 1, PyFloat_FromDouble(PP[i].y) ); PyList_SetItem(ll, 2, PyFloat_FromDouble(PP[i].z) ); PyList_SetItem(l, i, ll); } $result = t_output_helper2($result, l); } //typemap for multiple arg list (int n, Vert* V) to input a numpy array of vertices. // V is an array of n+1 vertices with V[n] = V[0] (see polygonArea.h for deatails) %typemap(in) (int n, Vert* V) ( PyArrayObject *array, int arrdims[2], char *cdata) { array = (PyArrayObject *)PyArray_ContiguousFromObject($input, PyArray_DOUBLE, 2, 2); if (array ==NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create 2D contiguous array of type double"); return NULL; } arrdims[0] = array->dimensions[0]; arrdims[1] = array->dimensions[1]; cdata = array->data; if(arrdims[1] != 3) { PyErr_SetString(PyExc_ValueError, "Wrong shape of the input array; Expected (n,3)."); return NULL; } $2 = (Vert *)malloc(arrdims[0]*sizeof(Vert)); for (int i =0; i< arrdims[0]; i++) { double x, y,z; x = *(double *)(cdata + i*array->strides[0]); y = *(double *)(cdata + i*array->strides[0] + array->strides[1]); z = *(double *)(cdata + i*array->strides[0] + 2*array->strides[1]); $2[i].x = x; $2[i].y = y; $2[i].z = z; //printf ("vert[%d] = (%f, %f, %f )\n", i, x, y, z); $1 = arrdims[0]; } } %typemap(freearg)(int n, Vert* V) { if (array$argnum ) Py_DECREF((PyObject *)array$argnum); if ($2) free($2); } %typemap (in) Vert (PyObject *o = NULL , double temp[3] = {0.0, 0.0, 0.0}, int dim ) { if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); return NULL; } dim = PySequence_Length($input); if (dim != 3) { PyErr_SetString(PyExc_ValueError,"Wrong list size; Expected 2 or 3 elements"); return NULL; } for (int i = 0; i < dim; i++) { o = PyList_GetItem($input,i); if (PyNumber_Check(o)) temp[i] = (double) PyFloat_AsDouble(o); else { PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers"); return NULL; } } $1.x = temp[0]; $1.y = temp[1]; $1.z = temp[2]; } %include src/geomAlgorithms/distance.h %include src/geomAlgorithms/intersections.h %include src/geomAlgorithms/polygonArea.h %include src/geomAlgorithms/boundingContainers.h %include typemaps.i /* *********************** start of readObjFile *********************************** */ %typemap(in) (char aoGroupNames[][256], unsigned int * aiNumOfGroupNames)(PyArrayObject *array=NULL,unsigned int dd) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_CHAR, 2, NULL); if (! array) return NULL; $1 = (char (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (char aoGroupNames[][256], unsigned int * aiNumOfGroupNames) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(char aoGroupNames[][256], unsigned int * aiNumOfGroupNames) (PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result, intobj); %} %typemap(in) (float aoVertices[][3], unsigned int * aiNumOfVertices)(PyArrayObject *array=NULL,unsigned int dd) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_FLOAT, 2, NULL); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (float aoVertices[][3], unsigned int * aiNumOfVertices) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(float aoVertices[][3], unsigned int * aiNumOfVertices) (PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result, intobj); %} %typemap(in) (int aoTriangles[][3], unsigned int * aiNumOfTriangles)(PyArrayObject *array=NULL,unsigned int dd ) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_INT, 2, NULL); if (! array) return NULL; $1 = (int (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (int aoTriangles[][3], unsigned int * aiNumOfTriangles) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(int aoTriangles[][3], unsigned int * aiNumOfTriangles)(PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result,intobj); %} %typemap(in) (float aoTextureVertices[][2], unsigned int * aiNumOfTextureVertices)(PyArrayObject *array=NULL,unsigned int dd) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_FLOAT, 2, NULL); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (float aoTextureVertices[][3], unsigned int * aiNumOfTextureVertices) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(float aoTextureVertices[][2], unsigned int * aiNumOfTextureVertices) (PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result, intobj); %} %typemap(in) (int aoTextureTriangles[][3], unsigned int * aiNumOfTextureTriangles)(PyArrayObject *array=NULL,unsigned int dd ) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_INT, 2, NULL); if (! array) return NULL; $1 = (int (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (int aoTextureTriangles[][3], unsigned int * aiNumOfTextureTriangles) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(int aoTextureTriangles[][3], unsigned int * aiNumOfTextureTriangles)(PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result,intobj); %} %typemap(in) (char aoMaterialLibraries[][256], unsigned int * aiNumOfMaterialLibraries)(PyArrayObject *array=NULL,unsigned int dd) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_CHAR, 2, NULL); if (! array) return NULL; $1 = (char (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (char aoMaterialLibraries[][256], unsigned int * aiNumOfMaterialLibraries) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(char aoMaterialLibraries[][256], unsigned int * aiNumOfMaterialLibraries) (PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result, intobj); %} %typemap(in) (char aoMaterialNames[][256], unsigned int * aiNumOfMaterialNames)(PyArrayObject *array=NULL,unsigned int dd) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_CHAR, 2, NULL); if (! array) return NULL; $1 = (char (*)[$1_dim1])array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (char aoMaterialNames[][256], unsigned int * aiNumOfMaterialNames) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(char aoMaterialNames[][256], unsigned int * aiNumOfMaterialNames) (PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result, intobj); %} %typemap(in) (int aoTriangleMaterialIndices[], unsigned int * aiNumOfTriangleMaterialIndices)(PyArrayObject *array=NULL,unsigned int dd ) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_INT, 1, NULL); if (! array) return NULL; $1 = (int *)array->data; dd = (unsigned int)((PyArrayObject *)(array))->dimensions[0]; $2 = ⅆ } else { array = NULL; $1 = NULL; dd = 0; $2 = ⅆ } %} %typemap(freearg) (int aoTriangleMaterialIndices[], unsigned int * aiNumOfTriangleMaterialIndices) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %typemap(argout)(int aoTriangleMaterialIndices[], unsigned int * aiNumOfTriangleMaterialIndices)(PyObject * intobj) %{ intobj = PyInt_FromLong((long)(*$2)); $result = l_output_helper2($result,intobj); %} %include src/geomAlgorithms/objfile.h /* *********************** end of readObjFile *********************************** */ mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/sdf.i.floats0000644000175000017500000000671610316561336023504 0ustar debiandebian%module sdflib #include #include %{ struct sdfgrid { int size[3]; float gridSpacing; float origin[3]; float corner[3]; float *gridpoint; }; /* Read SDF (signed distance field) grid and return the grid object */ struct sdfgrid * readSDF (char *sdfgridfile) { FILE *fp; int i, j, k, n; int size[3]; float gridSpacing, origin[3], corner[3]; float *gridpoint; /* store signed distance field */ struct sdfgrid *sdfgrid; /* open grid file */ fp = fopen(sdfgridfile, "r"); /* read the first line */ fscanf(fp, "%d %d %d %f %f %f %f %f %f %f\n", &size[0], &size[1], &size[2], &gridSpacing, &origin[0], &origin[1], &origin[2], &corner[0], &corner[1], &corner[2]); /* printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", size[0], size[1], size[2], gridSpacing, origin[0], origin[1], origin[2], corner[0], corner[1], corner[2]); */ /* allocate space for the grid points */ gridpoint = (float *) calloc( size[0]*size[1]*size[2], sizeof(float) ); /* read the rest lines (grid points) */ n = 0; for ( i=0; isize[0] = size[0]; sdfgrid->size[1] = size[1]; sdfgrid->size[2] = size[2]; sdfgrid->gridSpacing = gridSpacing; sdfgrid->origin[0] = origin[0]; sdfgrid->origin[1] = origin[1]; sdfgrid->origin[2] = origin[2]; sdfgrid->corner[0] = corner[0]; sdfgrid->corner[1] = corner[1]; sdfgrid->corner[2] = corner[2]; sdfgrid->gridpoint = gridpoint; /* printf("sdfgrid works!: gridSpacing = %8.3f\n", sdfgrid->gridSpacing); */ return sdfgrid; } /* look up a point's transformed coordinates tcoord in a SDF grid -- 9/25/2005 QZ */ float lookup (struct sdfgrid *sdfgrid, float x, float y, float z) { float x, y, z, xo, yo, zo, xm, ym, zm, gs; int sx, sy, sz, xi, yi, zi; static float outside = 9999.0; /* x = tcoord[0]; y = tcoord[1]; z = tcoord[2]; */ /* printf("after = %8.3f %8.3f %8.3f\n", x, y, z); */ sx = sdfgrid->size[0]; sy = sdfgrid->size[1]; sz = sdfgrid->size[2]; gs = sdfgrid->gridSpacing; xo = sdfgrid->origin[0]; yo = sdfgrid->origin[1]; zo = sdfgrid->origin[2]; xm = sdfgrid->corner[0]; ym = sdfgrid->corner[1]; zm = sdfgrid->corner[2]; /*printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", sx, sy, sz, gs, xo, yo, zo, xm, ym, zm); */ if ( xxm ) return outside; if ( yym ) return outside; if ( zzm ) return outside; xi = (int) (rintf((x-xo)/gs)); /* do not use nearbyintf, which causes segmentation fault */ yi = (int) (rintf((y-yo)/gs)); zi = (int) (rintf((z-zo)/gs)); /* printf("[%8.3f, %8.3f, %8.3f] -> [%5d %5d %5d] ", x, y, z, xi, yi, zi); */ return sdfgrid->gridpoint[xi*sy*sz + yi*sz + zi]; } %} /* %include numarr.i %apply float VECTOR[ANY] {float tcoord[3]}; struct sdfgrid * readSDF (char *sdfgridfile); float lookup (struct sdfgrid *sdfgrid, float tcoord[3]); */ struct sdfgrid * readSDF (char *sdfgridfile); float lookup (struct sdfgrid *sdfgrid, float x, float y, float z); mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/surface.py0000644000175000017500000001244710676030651023267 0ustar debiandebianfrom math import sqrt def triangleArea(p1, p2, p3): """Compute the surface area of a triangle. """ x1,y1,z1 = p1 x2,y2,z2 = p2 x3,y3,z3 = p3 dx, dy, dz = x1-x2, y1-y2, z1-z2 a = sqrt( dx*dx + dy*dy + dz*dz ) dx, dy, dz = x2-x3, y2-y3, z2-z3 b = sqrt( dx*dx + dy*dy + dz*dz ) dx, dy, dz = x1-x3, y1-y3, z1-z3 c = sqrt( dx*dx + dy*dy + dz*dz ) s = .5*(a+b+c) area = s*(s-a)*(s-b)*(s-c) if area <= 0.: # print "area = %f for triangles: " % area, p1, p2, p3 return 0. return sqrt(area) def meshVolume(verts, norm, tri): """Compute the Volume of a mesh specified by vertices, their normals, and indices of triangular faces """ # TEST zeronorms = [] for i, n in enumerate(norm): #if n == [0., 0., 0.] or n == (0., 0., 0.): if n[0] == 0 and n[1] == 0 and n[2] == 0: #print "normal %d is zero!" % i, n zeronorms.append(i) #print "in meshVolume, zeronorms length: ", len(zeronorms), "normals length:", len(norm) # Initialize volSum = 0.0 oneThird = 1./3. # Compute face normals trinorm = [] for t in tri: n1 = norm[t[0]] n2 = norm[t[1]] n3 = norm[t[2]] tn = [ (n1[0]+n2[0]+n3[0])*oneThird, (n1[1]+n2[1]+n3[1])*oneThird, (n1[2]+n2[2]+n3[2])*oneThird ] trinorm.append(tn) # print trinorm # TEST # Compute volume for t,tn in zip(tri, trinorm): s1 = verts[t[0]] s2 = verts[t[1]] s3 = verts[t[2]] area = triangleArea(s1,s2,s3) g = [ (s1[0]+s2[0]+s3[0])*oneThird, (s1[1]+s2[1]+s3[1])*oneThird, (s1[2]+s2[2]+s3[2])*oneThird ] volSum += (g[0]*tn[0] + g[1]*tn[1] + g[2]*tn[2])*area return volSum*oneThird def findComponents(verts, faces, normals=None, returnOption=0): """find the components of a geometry. normals are normals of verts not faces. returnOptiont: component return option = 0: return all components = 1: return all outside surfaces (volume > 0; normals must be given) The code is based on the Vision node ConnectedComponents. """ fdict = {} vdict = {} #dictionary with key - vertex index, #value - list of face indices in which the vertex is found flag1 = True; flag2 = True newfaces = [] newverts = [] if normals is not None: newnorms = [] while flag2: for i, fs in enumerate(faces): for v in fs: if not vdict.has_key(v): vdict[v] = [i] else: vdict[v].append(i) fdict[i] = fs Vco = faces[0][:] newfaces1 = [] newverts1 = [] if normals is not None: newnorms1 = [] vertinds = {} # keys - vertex indices from the input verts list # values - new vertex indices of current surface vcount = 0 # find a surface while flag1: _Vco = [] flag1 = False # find all vertices that share the same triangles with the vertices in Vco. for vert in Vco: vfs = vdict[vert] for i in vfs: if fdict.has_key(i): flag1 = True fs = fdict.pop(i) fsnew = [] # remapped face (with new vertex idices) for v in fs: if v not in Vco: if v not in _Vco: _Vco.append(v) if not vertinds.has_key(v): vertinds[v] = vcount newverts1.append(verts[v]) if normals is not None: newnorms1.append(normals[v]) fsnew.append(vcount) vcount = vcount + 1 else: fsnew.append(vertinds[v]) newfaces1.append(fsnew) # add found triangle to the list of triangles of current surface Vco = _Vco newfaces.append( newfaces1 ) newverts.append( newverts1 ) if normals is not None: newnorms.append( newnorms1 ) if len(fdict): faces = fdict.values() fdict = {} vdict = {} flag1 = True else: flag2 = False # return all surfaces if returnOption == 0: if normals is not None: return newverts, newfaces, newnorms else: return newverts, newfaces # return only outside surfaces outverts = [] outfaces = [] outnorms = [] for i in range( len(newfaces) ): Nvert = len(outverts) volume = meshVolume(newverts[i], newnorms[i], newfaces[i]) print i, len(newverts[i]), len(newfaces[i]), volume # TEST if volume > 0: outverts += newverts[i] outnorms += newnorms[i] # update face vertex indices to reflect lengthened vertices newfaces_i_mod = [] for v1, v2, v3 in newfaces[i]: newfaces_i_mod.append( [v1+Nvert, v2+Nvert, v3+Nvert] ) outfaces += newfaces_i_mod return outverts, outfaces, outnorms mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/sdf.i.1Darray0000644000175000017500000000650710316561253023513 0ustar debiandebian%module sdflib #include #include %{ struct sdfgrid { int size[3]; float gridSpacing; float origin[3]; float corner[3]; float *gridpoint; }; /* Read SDF (signed distance field) grid and return the grid object */ struct sdfgrid * readSDF (char *sdfgridfile) { FILE *fp; int i, j, k, n; int size[3]; float gridSpacing, origin[3], corner[3]; float *gridpoint; /* store signed distance field */ struct sdfgrid *sdfgrid; /* open grid file */ fp = fopen(sdfgridfile, "r"); /* read the first line */ fscanf(fp, "%d %d %d %f %f %f %f %f %f %f\n", &size[0], &size[1], &size[2], &gridSpacing, &origin[0], &origin[1], &origin[2], &corner[0], &corner[1], &corner[2]); /* printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", size[0], size[1], size[2], gridSpacing, origin[0], origin[1], origin[2], corner[0], corner[1], corner[2]); */ /* allocate space for the grid points */ gridpoint = (float *) calloc( size[0]*size[1]*size[2], sizeof(float) ); /* read the rest lines (grid points) */ n = 0; for ( i=0; isize[0] = size[0]; sdfgrid->size[1] = size[1]; sdfgrid->size[2] = size[2]; sdfgrid->gridSpacing = gridSpacing; sdfgrid->origin[0] = origin[0]; sdfgrid->origin[1] = origin[1]; sdfgrid->origin[2] = origin[2]; sdfgrid->corner[0] = corner[0]; sdfgrid->corner[1] = corner[1]; sdfgrid->corner[2] = corner[2]; sdfgrid->gridpoint = gridpoint; /* printf("sdfgrid works!: gridSpacing = %8.3f\n", sdfgrid->gridSpacing); */ return sdfgrid; } /* look up a point's transformed coordinates tcoord in a SDF grid -- 9/25/2005 QZ */ float lookup (struct sdfgrid *sdfgrid, float tcoord[3]) { float x, y, z, xo, yo, zo, xm, ym, zm, gs; int sx, sy, sz, xi, yi, zi; static float outside = 9999.0; x = tcoord[0]; y = tcoord[1]; z = tcoord[2]; /* printf("after = %8.3f %8.3f %8.3f\n", x, y, z); */ sx = sdfgrid->size[0]; sy = sdfgrid->size[1]; sz = sdfgrid->size[2]; gs = sdfgrid->gridSpacing; xo = sdfgrid->origin[0]; yo = sdfgrid->origin[1]; zo = sdfgrid->origin[2]; xm = sdfgrid->corner[0]; ym = sdfgrid->corner[1]; zm = sdfgrid->corner[2]; /*printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", sx, sy, sz, gs, xo, yo, zo, xm, ym, zm); */ if ( xxm ) return outside; if ( yym ) return outside; if ( zzm ) return outside; xi = (int) (rintf((x-xo)/gs)); /* do not use nearbyintf, which causes segmentation fault */ yi = (int) (rintf((y-yo)/gs)); zi = (int) (rintf((z-zo)/gs)); /* printf("[%8.3f, %8.3f, %8.3f] -> [%5d %5d %5d] ", x, y, z, xi, yi, zi); */ return sdfgrid->gridpoint[xi*sy*sz + yi*sz + zi]; } %} %include numarr.i %apply float VECTOR[ANY] {float tcoord[3]}; struct sdfgrid * readSDF (char *sdfgridfile); float lookup (struct sdfgrid *sdfgrid, float tcoord[3]); mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/efitlib.i0000644000175000017500000001202210653507546023051 0ustar debiandebian %module efitlib %include numarr.i %init %{ import_array(); /* load the Numpy PyCObjects */ %} %{ #include "efit.h" #define EFIT_NAME_LENGTH 64 #include "vec.h" %} struct ellipsoid { char name[EFIT_NAME_LENGTH]; float position[3]; /* center of mass */ double axis[3]; /* major, minor, middle axis lengths */ float orientation[3][3]; /* orientation matrix */ float inv_orientation[3][3];/* inverse orientation matrix */ float tensor[3][3]; /* inertia or covariance */ }; %extend ellipsoid { void getPosition( float OUT_VECTOR[3] ) { OUT_VECTOR[0] = self->position[0]; OUT_VECTOR[1] = self->position[1]; OUT_VECTOR[2] = self->position[2]; } void getAxis( double OUT_VECTOR[3] ) { OUT_VECTOR[0] = self->axis[0]; OUT_VECTOR[1] = self->axis[1]; OUT_VECTOR[2] = self->axis[2]; } void getOrientation( float OUT_ARRAY2D[3][3] ) { OUT_ARRAY2D[0][0] = self->orientation[0][0]; OUT_ARRAY2D[0][1] = self->orientation[0][1]; OUT_ARRAY2D[0][2] = self->orientation[0][2]; OUT_ARRAY2D[1][0] = self->orientation[1][0]; OUT_ARRAY2D[1][1] = self->orientation[1][1]; OUT_ARRAY2D[1][2] = self->orientation[1][2]; OUT_ARRAY2D[2][0] = self->orientation[2][0]; OUT_ARRAY2D[2][1] = self->orientation[2][1]; OUT_ARRAY2D[2][2] = self->orientation[2][2]; } } struct efit_info { int weightflag; int covarflag; int volumeflag; int matrixflag; int nocenterflag; int noscaleflag; int nosortflag; int count; float cov_scale; /* multiplier for covariance std axies */ float ell_scale; /* multiplier for ellipsoid axies */ }; %typemap(in) (float *pts, int nbpts) { int expected_dims[2] = {0,3}; PyArrayObject *array; array = contiguous_typed_array($input, PyArray_FLOAT, 2, expected_dims); if (!array) return NULL; $1 = (float(*))array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } extern int fitEllipse(float *pts, int nbpts, float ell_scale, float cov_scale, struct efit_info *eptr, struct ellipsoid *ellipsoid); %typemap(in) float vector_in_out[ANY] (PyArrayObject *array, int expected_dims[1]) %{ expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_FLOAT, 1, expected_dims); if (! array) return NULL; $1 = (float *)array->data; %} %typemap (argout) float vector_in_out[ANY] (int i) %{ $result = PyList_New($1_dim0); for (i = 0; i < $1_dim0; i++) { PyObject *o = PyFloat_FromDouble((double) $1[i]); PyList_SetItem($result,i,o); } Py_DECREF((PyObject *)array$argnum); %} /** %typemap(freearg) float vector_in_out[ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} **/ int vec_normalize(float vector_in_out[3]); int vec_centroid(int count, float *src, float *p); float vec_dot(float VECTOR[3], float VECTOR[3]); float vec_magsq(float VECTOR[3]); float vec_mag(float VECTOR[3]); float vec_distancesq(float VECTOR[3], float VECTOR[3]); float vec_distance(float VECTOR[3], float VECTOR[3]); float vec_max(float VECTOR[3]); float vec_length(float VECTOR[3]); void vec_ctos(float VECTOR[3], float OUT_VECTOR[3]); void vec_stoc(float VECTOR[3], float OUT_VECTOR[3]); void vec_sub(float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); void vec_copy(float VECTOR[3], float OUT_VECTOR[3]); void vec_add(float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); void vec_scale(float f, float VECTOR[3], float OUT_VECTOR[3]); void vec_zero(float OUT_VECTOR[3]); void vec_cross(float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); /**void vec_align(float *p1, float *p2, float *p3, float *p4, float (*m)[3], float *t); **/ void vec_mult(float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); void vec_offset(float s, float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); void vec_rand(float OUT_VECTOR[3]); void vec_average(float VECTOR[3], float VECTOR[3], float VECTOR[3], float OUT_VECTOR[3]); /** void vec_copypoints(int count, float *src, float *dest); **/ /** void vec_print(FILE *fp, float *p); **/ /** void vec_printpair(FILE *fp, float *p, float *n); **/ void vec_transform(float VECTOR[3], float ARRAY2D[3][3], float OUT_VECTOR[3]); void vec_ftransform(float VECTOR[3], float ARRAY2D[3][3], float OUT_VECTOR[3]); /** int mat_inverse(float (*m)[3], float (*minv)[3]); **/ /** float mat_det(float (*m)[3]); **/ /** void mat_smallrotmatrix(float *nvec, float angle, float (*m)[3]); **/ /** void mat_axisrotation(float *nvec, float radians, float (*m)[3]); **/ /** void mat_read(FILE *fp, float (*m)[3], float *v); **/ /** void mat_write(FILE *fp, float (*m)[3]); **/ /** void mat_identity(float (*m)[3]); **/ /** void mat_copy(float (*m1)[3], float (*m2)[3]); **/ /** void mat_transpose(float (*m1)[3], float (*m2)[3]); **/ /** void mat_mult(float (*m1)[3], float (*m2)[3], float (*m)[3]); **/ int mat_jacobi(float ARRAY2D[3][3], float OUT_VECTOR[3], float OUT_ARRAY2D[3][3]); void quat_to_mat (float VECTOR[4], float OUT_ARRAY2D[3][3]); void mat_to_quat (float ARRAY2D[3][3], float VECTOR[4]); mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/geomutils.i0000644000175000017500000004701711165214050023437 0ustar debiandebian%feature ("kwargs"); %{ //#include //#include #include #include #include #include #ifdef _MSC_VER #include #define WinVerMajor() LOBYTE(LOWORD(GetVersion())) #endif #ifdef __APPLE__ #undef max #endif using namespace std; /**************************************************************************** Compute vector v, normal to the triangle (p1,p2,p3) assuming that the order of the points p1,p2,p3 provides the face's orientation *****************************************************************************/ static void triangle_normal(double *p1,double *p2, double *p3, float *v) { double v1[3],v2[3],norm; short i; for (i=0; i<3; i++) { v1[i] = p2[i]-p1[i]; /* vector (p1,p2) */ v2[i] = p3[i]-p2[i]; /* vector (p2,p3) */ } v[0] = v1[1]*v2[2] - v1[2]*v2[1]; /* v3 = v1^v2 */ v[1] = v1[2]*v2[0] - v1[0]*v2[2]; v[2] = v1[0]*v2[1] - v1[1]*v2[0]; norm = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); if (norm != 0.) { for (i=0;i<3;i++) v[i] /= norm; } else { for (i=0;i<3;i++) v[i] = 0.0; } } /******************************************************** Computes the vector normal to each triangle using triangle_normal. The resulting normals are returned in a m*3 array of floats. ********************************************************/ int triangleNormalsPerFace(double *v_data, int lenv[2], int *t_data, int lent[2], float *trinorm) { int i; for (i=0; i<3*lent[0]; i+=3) { int v1,v2,v3; v1 = t_data[i]; if ( v1 >= lenv[0] ) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range\n", v1, i/3); return 0; } v2 = t_data[i+1]; if ( v2 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range\n", v1, i/3); return 0; } v3 = t_data[i+2]; if ( v3 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range\n", v3, i/3); return 0; } triangle_normal( &v_data[v1*3], &v_data[v2*3], &v_data[v3*3], &trinorm[i] ); } return 1; } /************************************************************************** Computes the vector normal to each triangle (face) using triangle_normal. The normals for each vertex are obtained by summing up the faces normals of each triangle this vertex belongs to. The resulting normals are returned in a n*3 array of floats. ***************************************************************************/ int triangleNormalsPerVertex(double *v_data, int lenv[2], float *vnorm, int *t_data, int lent[2]) { int i, j, k, *tric; float *trinorm; /*trinorm = (float *)malloc(lent[0] * 3 * sizeof(float)); */ trinorm = (float *)malloc(lent[0] * lent[1] * sizeof(float)); if (!trinorm) { fprintf(stderr, "Failed to allocate memory for the triangle normals \n"); return 0; } for (i=0; i<3*lent[0]; i+=3) { int v1,v2,v3; v1 = t_data[i]; if ( v1 >= lenv[0] ) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v1, i/3); return 0; } v2 = t_data[i+1]; if ( v2 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v2, i/3); return 0; } v3 = t_data[i+2]; if ( v3 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v3, i/3); return 0; } triangle_normal( &v_data[v1*3], &v_data[v2*3], &v_data[v3*3], &trinorm[i] ); } /* compute the vertices normals */ tric = (int *)malloc(lenv[0] * sizeof(int)); /*printf("vrnorm at %p, tric at %p\n", vnorm, tric);*/ if (!tric) { fprintf(stderr, "Failed to allocate memory for the normals('tric') \n"); free(trinorm); return 0; } for (i=0; i= lenv[0] ) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v1, i/3); return 0; } v2 = t_data[i+1]; if ( v2 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v2, i/3); return 0; } v3 = t_data[i+2]; if ( v3 >= lenv[0]) { fprintf(stderr, "Error: Coordinates index %d in face %d out of range \n", v3, i/3); return 0; } triangle_normal( &v_data[v1*3], &v_data[v2*3], &v_data[v3*3], &trinorm[i] ); } /* compute the vertices normals */ tric = (int *)malloc(lenv[0] * sizeof(int)); /*printf("vrnorm at %p, tric at %p\n", vnorm, tric);*/ /** if (!vnorm || !tric) **/ if (!tric) { fprintf(stderr, "Failed to allocate memory for the normals \n"); return 0; } for (i=0; i DoubleVec; typedef vector > DoubleArray; typedef vector IntVector; typedef vector > IntArray; //Remove duplicated vertices from supplied verts array and remap faces. void removeDuplicatedVertices(float verts[][3], int *lenv, int *faces, int* lenf, DoubleArray *newverts, IntArray *newfaces, float norms[][3], DoubleArray *newnorms) { char st1[256]; map newInds; // maps vertices to unique indices map oldToNew; // maps old indices to new, unique ones int nvert = 0; int i, j, ci; vector v; vector n; v.resize(3); n.resize(3); //printf ("len verts : %d, len faces: %d\n", lenv[0], lenf[0]); if (lenv[0]==0 || lenf[0]==0) { newverts->clear(); newfaces->clear(); newnorms->clear(); return; } if (!norms) { newnorms->clear(); } for (i = 0; i< lenv[0]; i++) { sprintf(st1, "%f%f%f\0", verts[i][0], verts[i][1], verts[i][2]); string st2(st1); if (newInds.find(st2) == newInds.end() ) { newInds[st2] = nvert; oldToNew[i] = nvert; nvert = nvert+1; for (j = 0; j<3; j++) { //v.push_back(verts[i][j]); v[j] = verts[i][j]; if (norms) { n[j] = norms[i][j]; } } newverts->push_back(v); if (norms) { newnorms->push_back(n); } } else { oldToNew[i] = newInds[st2]; } } /*** map::iterator pos; for(pos=newInds.begin(); pos != newInds.end(); ++pos) { cout << "key:" << pos->first << "\t" << "value:" << pos->second << endl; } **/ vector f; f.resize(lenf[1]); for(i = 0; ipush_back(f); //f.clear(); } } float computeRMSD(float Coords[][3], float refCoords[][3], int lenCoords) { float SumOfSquaredDev, dx, dy, dz, RMSD; int i; SumOfSquaredDev = 0.0; for ( i = 0; i < lenCoords; i++ ) { dx = Coords[i][0] - refCoords[i][0]; dy = Coords[i][1] - refCoords[i][1]; dz = Coords[i][2] - refCoords[i][2]; SumOfSquaredDev += dx*dx + dy*dy + dz*dz; } RMSD = sqrt( SumOfSquaredDev / lenCoords ); return RMSD; } %} %include numarr.i /** typemaps for triangleNormals....() **/ %typemap(in) (double *v_data, int lenv[2]) (PyArrayObject *inv, int expected_dims[2], int intdims[2]) %{ expected_dims[0] = 0; expected_dims[1] = 3; inv = contiguous_typed_array($input, PyArray_DOUBLE, 2, expected_dims); if (! inv) return NULL; $1 = (double *)inv->data; intdims[0] = inv->dimensions[0]; intdims[1] = inv->dimensions[1]; $2 = intdims; %} %typemap(freearg)(double *v_data, int lenv[2]) %{ if (inv$argnum) Py_DECREF(inv$argnum); %} %typemap(in) (int *t_data, int lent[2], float *trinorm) (PyArrayObject *intr, int expected_dims[2], int intdims[2]) %{ expected_dims[0] = 0; expected_dims[1] = 3; intr = contiguous_typed_array($input, PyArray_INT, 2, expected_dims); if (! intr) return NULL; $1 = (int *)intr->data; intdims[0] = intr->dimensions[0]; intdims[1] = intr->dimensions[1]; $2 = intdims; $3 = (float *)malloc(intr->dimensions[0] * 3 * sizeof(float)); if (!$3) { PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory for the normals"); return NULL; } %} %typemap(argout) (int *t_data, int lent[2], float *trinorm)(PyArrayObject *out, npy_intp lDim[2]) %{ lDim[0] = $2[0]; lDim[1] = $2[1]; if ($result == NULL) { free($3); PyErr_SetString(PyExc_RuntimeError,"Failed to compute normals\n"); return NULL; } out = (PyArrayObject *)PyArray_SimpleNewFromData(2, lDim, PyArray_FLOAT, (char *)$3); if (!out) { PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory for normals"); return NULL; } #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: out->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected out->flags |= NPY_OWNDATA; #endif $result = l_output_helper2($result, (PyObject *)out); %} %typemap(freearg)(int *t_data, int lent[2], float *trinorm) %{ if (intr$argnum) Py_DECREF(intr$argnum); %} %typemap(out) int %{ if(!$1) $result = NULL; else { Py_INCREF(Py_None); $result = Py_None; } %} int triangleNormalsPerFace(double *v_data, int lenv[2], int *t_data, int lent[2], float *trinorm); %typemap(in) (double *v_data, int lenv[2], float *vnorm) (PyArrayObject * inv, int expected_dims[2], int intdims[2]) %{ expected_dims[0] = 0; expected_dims[1] = 3; inv = contiguous_typed_array($input, PyArray_DOUBLE, 2, expected_dims); if (! inv) return NULL; $1 = (double *)inv->data; intdims[0] = inv->dimensions[0]; intdims[1] = inv->dimensions[1]; $2 = intdims; $3 = (float *)malloc(inv->dimensions[0] * 3 * sizeof(float)); if (!$3) { PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory for the vertex normals"); return NULL; } %} %typemap(argout) (double *v_data, int lenv[2], float *vnorm)(PyArrayObject *out, npy_intp lDim[2]) %{ lDim[0] = $2[0]; lDim[1] = $2[1]; if ($result == NULL) { free($3); PyErr_SetString(PyExc_RuntimeError,"Failed to compute normals\n"); return NULL; } out = (PyArrayObject *)PyArray_SimpleNewFromData(2, lDim, PyArray_FLOAT, (char *)$3); if (!out) { PyErr_SetString(PyExc_RuntimeError, "Failed to allocate memory for normals"); return NULL; } #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: out->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected out->flags |= NPY_OWNDATA; #endif $result = l_output_helper2($result, (PyObject *)out); %} %typemap(freearg)(double *v_data, int lenv[2], float *vnorm) %{ if (inv$argnum) Py_DECREF(inv$argnum); %} %typemap (in) (int *t_data, int lent[2])(PyArrayObject *intr, int expected_dims[2], int intdims[2]) %{ expected_dims[0] = 0; expected_dims[1] = 3; intr = contiguous_typed_array($input, PyArray_INT, 2, expected_dims); if (! intr) return NULL; $1 = (int *)intr->data; intdims[0] = intr->dimensions[0]; intdims[1] = intr->dimensions[1]; $2 = intdims; %} %typemap(freearg)(int *t_data, int lent[2]) %{ if (intr$argnum) Py_DECREF(intr$argnum); %} int triangleNormalsPerVertex(double *v_data, int lenv[2], float *vnorm, int *t_data, int lent[2]); int triangleNormalsBoth(double *v_data, int lenv[2], float *vnorm, int *t_data, int lent[2], float *trinorm); /* Typemaps for removeDuplicatedVertices(): */ /* to output newverts as a list from Python */ %typemap(in, numinputs=0) DoubleArray *newverts (DoubleArray temp) { $1 = &temp; } %typemap(argout) DoubleArray *newverts { int sizei, sizej; double element; PyObject * res; PyObject * res1; if (!(*$1).empty()) { sizei = (*$1).size(); sizej = (*$1)[0].size(); res = PyList_New(sizei); for (unsigned int i=0; idata; intdims[0] = ((PyArrayObject *)(array))->dimensions[0]; intdims[1] = ((PyArrayObject *)(array))->dimensions[1]; $2 = intdims; } else { array = NULL; $1 = NULL; $2 = 0; } %} %typemap(freearg) ( float verts[1][3], int* lenv ) %{ if (array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /* to input faces as a Numeric arrray or a Python list */ %typemap(in) ( int *faces, int* lenf)(PyArrayObject *array, int intdims[2]) %{ if ($input != Py_None) { array = contiguous_typed_array($input, PyArray_INT, 2, NULL); if (! array) return NULL; $1 = (int *)array->data; intdims[0] = ((PyArrayObject *)(array))->dimensions[0]; intdims[1] = ((PyArrayObject *)(array))->dimensions[1]; $2 = intdims; } else { array = NULL; $1 = NULL; $2 = NULL; } %} %typemap(freearg) (int *faces, int* lenf) %{ if (array$argnum) Py_DECREF((PyObject *)array$argnum); %} /* to input norms as a Numeric arrray or a Python list */ %apply float ARRAY2D[ANY][ANY] {float norms[1][3]}; void removeDuplicatedVertices(float verts[1][3], int *lenv, int *faces, int *lenf, DoubleArray *newverts, IntArray *newfaces, float norms[1][3] = NULL, DoubleArray *newnorms= NULL); %apply float ARRAY2D[ANY][ANY]{float Coords[1][3]}; %typemap(in) ( float refCoords[][3], int lenCoords)(PyArrayObject *array=NULL, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = 0; expected_dims[1] = $1_dim1; array = contiguous_typed_array($input, PyArray_FLOAT, 2, expected_dims); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } else { $1 = NULL; $2 = 0; } %} %typemap(freearg) (float refCoords[][3], int lenCoords) %{ if (array$argnum ) Py_DECREF((PyObject *)array$argnum); %} float computeRMSD(float Coords[1][3], float refCoords[][3], int lenCoords); /* Compute normal vector for a bunch of triangles specified as: an n*3 sequence of floats for the vertices coordinates and an m*3 array of integers for the triangle's topology The thirds and optional (string) argument specifies the computation mode. This function can work in three different modes (default: 'PER_VERTEX'): 'PER_FACE': computes the vector normal to each triangle using triangle_normal. The resulting normals are returned in a m*3 array of floats. 'PER_VERTEX': after the face normals have been computed they normals for each vertex are obtained by summing up the faces normals of each triangle this vertex belongs to. The resulting normals are returned in a n*3 array of floats. 'BOTH': The face and vertex normals are computed and both are returned. uses: contiguous_typed_array, triangle_normal available from the interpreter as: glTriangleNormals( vertices, triangles, | mode ) */ /** Insert the python code into the python module containing shadow classes **/ %insert("shadow") %{ def TriangleNormals(vertices, triangles, mode = "PER_FACE" ): import numpy.oldnumeric as Numeric import numpy if (type(vertices) == Numeric.arraytype) \ or (type(vertices) == numpy.ndarray): vertices = vertices.astype('f') if type(triangles) == Numeric.arraytype \ or (type(triangles) == numpy.ndarray): triangles = triangles.astype('i') if mode == "PER_FACE": return triangleNormalsPerFace(vertices, triangles) elif mode == "PER_VERTEX": return triangleNormalsPerVertex(vertices, triangles) elif mode == "BOTH": return triangleNormalsBoth(vertices, triangles) %} mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/numarr.i0000644000175000017500000003300511165214050022723 0ustar debiandebian%init %{ import_array(); /* load the Numeric PyCObjects */ %} %{ #ifdef _MSC_VER #include #define WinVerMajor() LOBYTE(LOWORD(GetVersion())) #endif #include "numpy/arrayobject.h" static PyArrayObject *contiguous_typed_array(PyObject *obj, int typecode, int expectnd, int *expectdims) { PyArrayObject *arr; int i; char buf[255]; /* if the shape and type are OK, this function increments the reference count and arr points to obj */ if((arr = (PyArrayObject *)PyArray_ContiguousFromObject(obj, typecode, 0, 10)) == NULL) { sprintf(buf,"Failed to make a contiguous array of type %d\n", typecode); PyErr_SetString(PyExc_ValueError, buf); return NULL; } if(expectnd>0) { if(arr->nd > expectnd + 1 || arr->nd < expectnd) { Py_DECREF((PyObject *)arr); PyErr_SetString(PyExc_ValueError, "Array has wrong number of dimensions"); return NULL; } if(arr->nd == expectnd + 1) { if(arr->dimensions[arr->nd - 1] != 1) { Py_DECREF((PyObject *)arr); PyErr_SetString(PyExc_ValueError, "Array has wrong number of dimensions"); return NULL; } } if(expectdims) { for(i = 0; i < expectnd; i++) if(expectdims[i]>0) if(expectdims[i] != arr->dimensions[i]) { Py_DECREF((PyObject *)arr); sprintf(buf,"The extent of dimension %d is %d while %d was expected\n", i, arr->dimensions[i], expectdims[i]); PyErr_SetString(PyExc_ValueError, buf); return NULL; } } } return arr; } %} /**********************************************************/ /* OUTPUT */ /**********************************************************/ %{ static PyObject* l_output_helper2(PyObject* target, PyObject* o) { PyObject* o2; if (!target) { target = o; } else if (target == Py_None) { Py_DECREF(Py_None); target = o; } else { if (!PyList_Check(target)) { o2 = target; target = PyList_New(0); PyList_Append(target, o2); Py_XDECREF(o2); } PyList_Append(target,o); Py_XDECREF(o); } return target; } PyObject* t_output_helper2(PyObject* target, PyObject* o) { PyObject* o2; PyObject* o3; if (!target) { target = o; } else if (target == Py_None) { Py_DECREF(Py_None); target = o; } else { if (!PyTuple_Check(target)){ o2 = target; target = PyTuple_New(1); PyTuple_SetItem(target, 0, o2); } o3 = PyTuple_New(1); PyTuple_SetItem(o3, 0, o); o2 = target; target = PySequence_Concat(o2, o3); Py_DECREF(o2); Py_DECREF(o3); } return target; } %} /**********************************************************/ /* OUTPUT: int VECTOR, ARRAY */ /**********************************************************/ %typemap(argout) int OUT_VECTOR[ANY], int OUT_ARRAY2D[ANY][ANY] { $result = l_output_helper2($result, (PyObject *)array$argnum); } %typemap(in, numinputs=0) int OUT_VECTOR[ANY] (PyArrayObject *array, npy_intp out_dims[1]) %{ out_dims[0] = $1_dim0; $1 = (int *)malloc($1_dim0*sizeof(int)); if ($1 == NULL) { PyErr_SetString(PyExc_ValueError, "failed to allocate memory"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(1, out_dims, PyArray_INT, (char *)$1); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif %} %typemap(in, numinputs=0) int OUT_ARRAY2D[ANY][ANY] (PyArrayObject *array, npy_intp out_dims[2]) { int *data = (int *)malloc($1_dim0*$1_dim1*sizeof(int)); out_dims[0] = $1_dim0; out_dims[1] = $1_dim1; if (!data) { PyErr_SetString(PyExc_ValueError, "failed to allocate data array"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(2, out_dims, PyArray_INT, (char *)(data)); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif $1 = (int (*)[$1_dim1])data; } /**********************************************************/ /* OUTPUT: float VECTOR, ARRAY */ /**********************************************************/ %typemap(argout) float OUT_VECTOR[ANY], float OUT_ARRAY2D[ANY][ANY] { $result = l_output_helper2($result, (PyObject *)array$argnum); } %typemap(in, numinputs=0) float OUT_VECTOR[ANY](PyArrayObject *array, npy_intp out_dims[1]) %{ out_dims[0] = $1_dim0; $1= (float *)malloc($1_dim0*sizeof(float)); if ($1 == NULL) { PyErr_SetString(PyExc_ValueError, "failed to allocate memory"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(1, out_dims, PyArray_FLOAT, (char *)($1)); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif %} %typemap(in, numinputs=0) float OUT_ARRAY2D[ANY][ANY] (PyArrayObject *array, npy_intp out_dims[2]) { float *data = (float *)malloc($1_dim0*$1_dim1*sizeof(float)); out_dims[0] = $1_dim0; out_dims[1] = $1_dim1; if (!data) { PyErr_SetString(PyExc_ValueError, "failed to allocate data array"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(2, out_dims, PyArray_FLOAT, (char *)(data)); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif $1 = (float (*)[$1_dim1])data; } /**********************************************************/ /* OUTPUT: double VECTOR, ARRAY */ /**********************************************************/ %typemap(argout) double OUT_VECTOR[ANY], double OUT_ARRAY2D[ANY][ANY] { $result = l_output_helper2($result, (PyObject *)array$argnum); } %typemap(in, numinputs=0) double OUT_VECTOR[ANY] (PyArrayObject *array, npy_intp out_dims[1]) { out_dims[0] = $1_dim0; $1= (double *)malloc($1_dim0*sizeof(double)); if ($1 == NULL) { PyErr_SetString(PyExc_ValueError, "failed to allocate memory"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(1, out_dims, PyArray_DOUBLE, (char *)($1)); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif } %typemap(in, numinputs=0) double OUT_ARRAY2D[ANY][ANY] (PyArrayObject *array, npy_intp out_dims[2]) { double *data = (double *)malloc($1_dim0*$1_dim1*sizeof(double)); out_dims[0] = $1_dim0; out_dims[1] = $1_dim1; if (!data) { PyErr_SetString(PyExc_ValueError, "failed to allocate data array"); return NULL; } array = (PyArrayObject *)PyArray_SimpleNewFromData(2, out_dims, PyArray_DOUBLE, (char *)(data)); #ifdef _MSC_VER switch ( WinVerMajor() ) { case 6: break; // Vista default: array->flags |= NPY_OWNDATA; } #else // so we'll free this memory when this // array will be garbage collected array->flags |= NPY_OWNDATA; #endif $1 = (double (*)[$1_dim1])data; } /*************************************************************/ /* INPUT */ /*************************************************************/ /* INPUT: u_char VECTOR, 2D ARRAY */ /* VECTOR */ %typemap(in) u_char VECTOR[ANY] (PyArrayObject *array=NULL, int expected_dims[1]) %{ expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_UBYTE, 1, expected_dims); if (! array) return NULL; $1 = (u_char *)array->data; %} %typemap(freearg) u_char VECTOR[ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /* 2D ARRAY */ %typemap(in) u_char ARRAY2D[ANY][ANY](PyArrayObject *array=NULL, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_UBYTE, 2, expected_dims); if (! array) return NULL; $1 = (u_char (*)[$1_dim1])array->data; } else { array = NULL; $1 = NULL; } %} %typemap(freearg) u_char ARRAY2D[ANY][ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %define UCHAR_ARRAY2D( DIM, ARRAYNAME, ARRAYSHAPE) %typemap(in) ( int* DIM, u_char ARRAYNAME##ARRAYSHAPE) (PyArrayObject *array=NULL, int expected_dims[2], int intdims[2]) %{ if ($input != Py_None) { expected_dims[0] = $2_dim0; expected_dims[1] = $2_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_UBYTE, 2, expected_dims); if (! array) return NULL; intdims[0] = ((PyArrayObject *)(array))->dimensions[0]; intdims[1] = ((PyArrayObject *)(array))->dimensions[1]; $1 = intdims; $2 = (u_char (*)[$2_dim1])array->data; } else { array = NULL; $2 = NULL; $1 = NULL; } %} %typemap(freearg) (int* DIM, u_char ARRAYNAME##ARRAYSHAPE) %{ %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} %enddef /*************** INPUT: int VECTOR, ARRAY2D ************************/ /* VECTOR */ %typemap(in) int VECTOR[ANY] (PyArrayObject *array=NULL, int expected_dims[1]) %{ expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_INT, 1, expected_dims); if (! array) return NULL; $1 = (int *)array->data; %} %typemap(freearg) int VECTOR[ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /* ARRAY2D */ %typemap(in) int ARRAY2D[ANY][ANY](PyArrayObject *array=NULL, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_INT, 2, expected_dims); if (! array) return NULL; $1 = (int (*)[$1_dim1])array->data; } else { array = NULL; $1 = NULL; } %} %typemap(freearg) int ARRAY2D[ANY][ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /** INPUT: float VECTOR, ARRAY2D **/ /* Vector */ %typemap(in) float VECTOR[ANY] (PyArrayObject *array=NULL, int expected_dims[1]) %{ expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_FLOAT, 1, expected_dims); if (! array) return NULL; $1 = (float *)array->data; %} %typemap(freearg) float VECTOR[ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /* ARRAY2D */ %typemap(in) float ARRAY2D[ANY][ANY](PyArrayObject *array=NULL, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_FLOAT, 2, expected_dims); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; } else { array = NULL; $1 = NULL; } %} %typemap(freearg) float ARRAY2D[ANY][ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /** INPUT: double VECTOR, ARRAY2D **/ /* VECTOR */ %typemap(in) double VECTOR[ANY] (PyArrayObject *array=NULL, int expected_dims[1]) %{ expected_dims[0] = $1_dim0; if (expected_dims[0]==1) expected_dims[0]=0; array = contiguous_typed_array($input, PyArray_DOUBLE, 1, expected_dims); if (! array) return NULL; $1 = (double *)array->data; %} %typemap(freearg) double VECTOR[ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} /* ARRAY2D */ %typemap(in) double ARRAY2D[ANY][ANY](PyArrayObject *array=NULL, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_DOUBLE, 2, expected_dims); if (! array) return NULL; $1 = (double (*)[$1_dim1])array->data; } else { array = NULL; $1 = NULL; } %} %typemap(freearg) double ARRAY2D[ANY][ANY] %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/0000755000175000017500000000000012146210051022343 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/Data/0000755000175000017500000000000012146210051023214 5ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/Data/cv_coords.py0000644000175000017500000000310610653444130025557 0ustar debiandebian## Automatically adapted for numpy.oldnumeric Jul 30, 2007 by import numpy.oldnumeric as Numeric cv_coords = Numeric.array([ [0.601, -1.594, -0.306], [-0.339, -1.512, -1.485], [-0.759, -0.072, -1.891], [0.513, 0.787, -2.119], [1.489, 0.746, -0.907], [2.782, 1.566, -1.187], [3.854, 1.494, -0.069], [4.885, 2.443, -0.013], [5.866, 2.353, 0.972], [5.834, 1.320, 1.901], [4.820, 0.369, 1.854], [3.831, 0.440, 0.870], [2.689, -0.609, 0.878], [1.840, -0.720, -0.439], [4.964, 3.475, -0.916], [-1.672, 0.597, -0.912], [-3.162, 0.169, -0.819], [-3.261, -1.094, -0.408], [-3.727, 0.205, -2.026], [-3.960, 1.089, 0.162], [-4.589, 0.000, 2.337], [-3.626, 0.955, 1.623], [-4.169, 2.509, -0.278], [-5.547, 3.062, 0.117], [0.805, -3.010, 0.163], [-0.334, -3.935, -0.316], [-0.149, -5.389, 0.134], [-5.635, 0.355, 2.282], [-4.559, -1.020, 1.911], [-4.332, -0.090, 3.408], [-3.651, 1.931, 2.144], [-2.588, 0.593, 1.743], [-3.365, 3.160, 0.115], [-4.079, 2.579, -1.377], [-5.681, 3.095, 1.214], [-5.682, 4.093, -0.257], [-6.369, 2.453, -0.302], [1.783, -3.397, -0.185], [0.870, -3.073, 1.262], [-1.305, -3.563, 0.061], [-0.410, -3.911, -1.420], [-0.978, -6.025, -0.226], [0.790, -5.823, -0.258], [-0.123, -5.477, 1.236], [0.146, -1.992, -2.358], [-1.237, -2.132, -1.306], [-1.294, -0.132, -2.857], [1.036, 0.416, -3.022], [0.238, 1.832, -2.359], [0.969, 1.250, -0.067], [3.245, 1.216, -2.130], [2.502, 2.620, -1.374], [6.660, 3.085, 1.017], [6.597, 1.257, 2.664], [3.130, -1.594, 1.119], [2.018, -0.380, 1.727], [2.487, -1.176, -1.215], [4.808, -0.421, 2.592], [-1.198, 0.611, -0.002], [5.728, 4.017, -0.706], ], 'f' ) mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/Data/crn_coords.py0000644000175000017500000001770110653444130025737 0ustar debiandebian## Automatically adapted for numpy.oldnumeric Jul 30, 2007 by import numpy.oldnumeric as Numeric crn_coords = Numeric.array([ [17.047, 14.099, 3.625], [16.967, 12.784, 4.338], [15.685, 12.755, 5.133], [15.268, 13.825, 5.594], [18.170, 12.703, 5.337], [19.334, 12.829, 4.463], [18.150, 11.546, 6.304], [15.115, 11.555, 5.265], [13.856, 11.469, 6.066], [14.164, 10.785, 7.379], [14.993, 9.862, 7.443], [12.732, 10.711, 5.261], [13.308, 9.439, 4.926], [12.484, 11.442, 3.895], [13.488, 11.241, 8.417], [13.660, 10.707, 9.787], [12.269, 10.431, 10.323], [11.393, 11.308, 10.185], [14.368, 11.748, 10.691], [15.885, 12.426, 10.016], [12.019, 9.272, 10.928], [10.646, 8.991, 11.408], [10.654, 8.793, 12.919], [11.659, 8.296, 13.491], [10.057, 7.752, 10.682], [9.837, 8.018, 8.904], [9.561, 9.108, 13.563], [9.448, 9.034, 15.012], [9.288, 7.670, 15.606], [9.490, 7.519, 16.819], [8.230, 9.957, 15.345], [7.338, 9.786, 14.114], [8.366, 9.804, 12.958], [8.875, 6.686, 14.796], [8.673, 5.314, 15.279], [8.753, 4.376, 14.083], [8.726, 4.858, 12.923], [7.340, 5.121, 15.996], [6.274, 5.220, 15.031], [8.881, 3.075, 14.358], [8.912, 2.083, 13.258], [7.581, 2.090, 12.506], [7.670, 2.031, 11.245], [9.207, 0.677, 13.924], [10.714, 0.702, 14.312], [8.811, -0.477, 12.969], [11.185, -0.516, 15.142], [6.458, 2.162, 13.159], [5.145, 2.209, 12.453], [5.115, 3.379, 11.461], [4.664, 3.268, 10.343], [3.995, 2.354, 13.478], [2.716, 2.891, 12.869], [3.758, 1.032, 14.208], [5.606, 4.546, 11.941], [5.598, 5.767, 11.082], [6.441, 5.527, 9.850], [6.052, 5.933, 8.744], [6.022, 6.977, 11.891], [7.647, 4.909, 10.005], [8.496, 4.609, 8.837], [7.798, 3.609, 7.876], [7.878, 3.778, 6.651], [9.847, 4.020, 9.305], [10.752, 3.607, 8.149], [11.226, 4.699, 7.244], [12.143, 5.571, 8.035], [12.758, 6.609, 7.443], [12.539, 6.932, 6.158], [13.601, 7.322, 8.202], [7.186, 2.582, 8.445], [6.500, 1.584, 7.565], [5.382, 2.313, 6.773], [5.213, 2.016, 5.557], [5.908, 0.462, 8.400], [6.990, -0.272, 9.012], [4.648, 3.182, 7.446], [3.545, 3.935, 6.751], [4.107, 4.851, 5.691], [3.536, 5.001, 4.617], [2.663, 4.677, 7.748], [1.802, 3.735, 8.610], [1.567, 2.613, 8.165], [1.394, 4.252, 9.767], [5.259, 5.498, 6.005], [5.929, 6.358, 5.055], [6.304, 5.578, 3.799], [6.136, 6.072, 2.653], [7.183, 6.994, 5.754], [7.884, 8.006, 4.883], [8.906, 7.586, 4.027], [7.532, 9.373, 4.983], [9.560, 8.539, 3.194], [8.176, 10.281, 4.145], [9.141, 9.845, 3.292], [6.900, 4.390, 3.989], [7.331, 3.607, 2.791], [6.116, 3.210, 1.915], [6.240, 3.144, 0.684], [8.145, 2.404, 3.240], [9.555, 2.856, 3.730], [10.013, 3.895, 3.323], [10.120, 1.956, 4.539], [4.993, 2.927, 2.571], [3.782, 2.599, 1.742], [3.296, 3.871, 1.004], [2.947, 3.817, -0.189], [2.698, 1.953, 2.608], [1.384, 1.826, 1.806], [3.174, 0.533, 3.005], [3.321, 4.987, 1.720], [2.890, 6.285, 1.126], [3.687, 6.597, -0.111], [3.200, 7.147, -1.103], [3.039, 7.369, 2.240], [2.559, 9.014, 1.649], [4.997, 6.227, -0.100], [5.895, 6.489, -1.213], [5.738, 5.560, -2.409], [6.228, 5.901, -3.507], [7.370, 6.507, -0.731], [7.717, 7.687, 0.206], [7.949, 8.947, -0.615], [9.212, 8.856, -1.337], [9.537, 9.533, -2.431], [8.659, 10.350, -3.032], [10.793, 9.491, -2.899], [5.051, 4.411, -2.204], [4.933, 3.431, -3.326], [4.397, 4.014, -4.620], [4.988, 3.755, -5.687], [4.196, 2.184, -2.863], [4.960, 1.178, -1.991], [3.907, 0.097, -1.634], [6.129, 0.606, -2.768], [3.329, 4.795, -4.543], [2.792, 5.376, -5.797], [3.573, 6.540, -6.322], [3.260, 7.045, -7.422], [1.358, 5.766, -5.472], [1.223, 5.694, -3.993], [2.421, 4.941, -3.408], [4.565, 7.047, -5.559], [5.366, 8.191, -6.018], [5.007, 9.481, -5.280], [5.535, 10.510, -5.730], [4.181, 9.438, -4.262], [3.767, 10.609, -3.513], [5.017, 11.397, -3.042], [5.947, 10.757, -2.523], [2.992, 10.188, -2.225], [2.051, 9.144, -2.623], [2.260, 11.349, -1.551], [4.971, 12.703, -3.176], [6.143, 13.513, -2.696], [6.400, 13.233, -1.225], [5.485, 13.061, -0.382], [5.703, 14.969, -2.920], [4.676, 14.893, -3.996], [3.964, 13.567, -3.811], [7.728, 13.297, -0.921], [8.114, 13.103, 0.500], [7.427, 14.073, 1.410], [7.036, 13.682, 2.540], [9.648, 13.285, 0.660], [10.440, 12.093, 0.063], [11.941, 12.170, 0.391], [12.416, 13.225, 0.681], [12.539, 11.070, 0.292], [7.212, 15.334, 0.966], [6.614, 16.317, 1.913], [5.212, 15.936, 2.350], [4.782, 16.166, 3.495], [6.605, 17.695, 1.246], [4.445, 15.318, 1.405], [3.074, 14.894, 1.756], [3.085, 13.643, 2.645], [2.315, 13.523, 3.578], [2.204, 14.637, 0.462], [1.815, 16.048, -0.129], [0.903, 13.864, 0.811], [0.756, 16.761, 0.757], [4.032, 12.764, 2.313], [4.180, 11.549, 3.187], [4.632, 11.944, 4.596], [4.227, 11.252, 5.547], [5.038, 10.518, 2.539], [4.349, 9.794, 1.022], [5.408, 13.012, 4.694], [5.879, 13.502, 6.026], [4.696, 13.908, 6.882], [4.528, 13.422, 8.025], [6.880, 14.615, 5.830], [3.827, 14.802, 6.358], [2.691, 15.221, 7.194], [1.672, 14.132, 7.434], [0.947, 14.112, 8.468], [1.986, 16.520, 6.614], [1.664, 16.221, 5.230], [2.914, 17.739, 6.700], [1.621, 13.190, 6.511], [0.715, 12.045, 6.657], [1.125, 11.125, 7.815], [0.286, 10.632, 8.545], [0.755, 11.229, 5.322], [-0.203, 10.044, 5.354], [-1.547, 10.337, 5.645], [0.193, 8.750, 5.100], [-2.496, 9.329, 5.673], [-0.801, 7.705, 5.156], [-2.079, 8.031, 5.430], [-3.097, 7.057, 5.458], [2.470, 10.984, 7.995], [2.986, 9.994, 8.950], [3.609, 10.505, 10.230], [3.766, 9.715, 11.186], [4.076, 9.103, 8.225], [5.125, 10.027, 7.824], [3.493, 8.324, 7.035], [3.984, 11.764, 10.241], [4.769, 12.336, 11.360], [6.255, 12.243, 11.106], [7.037, 12.750, 11.954], [6.710, 11.631, 9.992], [8.140, 11.694, 9.635], [8.500, 13.141, 9.206], [7.581, 13.949, 8.944], [8.504, 10.686, 8.530], [8.048, 8.987, 8.881], [9.793, 13.410, 9.173], [10.280, 14.760, 8.823], [11.346, 14.658, 7.743], [11.971, 13.583, 7.552], [10.790, 15.535, 10.085], [12.059, 14.803, 10.671], [9.684, 15.686, 11.138], [12.733, 15.676, 11.781], [11.490, 15.773, 7.038], [12.552, 15.877, 6.036], [13.590, 16.917, 6.560], [13.168, 18.006, 6.945], [11.987, 16.360, 4.681], [10.914, 15.338, 4.163], [13.131, 16.517, 3.629], [10.151, 16.024, 2.938], [14.856, 16.493, 6.536], [15.930, 17.454, 6.941], [16.913, 17.550, 5.819], [17.097, 16.660, 4.970], [16.622, 16.995, 8.285], [17.360, 15.651, 8.067], [15.592, 16.974, 9.434], [18.298, 15.206, 9.219], [17.664, 18.669, 5.806], [18.635, 18.861, 4.738], [19.925, 18.042, 4.949], [20.593, 17.742, 3.945], [18.945, 20.364, 4.783], [18.238, 20.937, 5.908], [17.371, 19.900, 6.596], [20.172, 17.730, 6.217], [21.452, 16.969, 6.513], [21.143, 15.478, 6.427], [20.138, 15.023, 5.878], [22.055, 14.701, 7.032], [22.019, 13.242, 7.020], [21.944, 12.628, 8.396], [21.869, 11.387, 8.435], [23.246, 12.697, 6.275], [21.894, 13.435, 9.436], [21.936, 12.911, 10.809], [20.615, 13.191, 11.521], [20.357, 14.317, 11.948], [23.131, 13.601, 11.593], [24.284, 13.401, 10.709], [23.340, 12.935, 12.962], [19.827, 12.110, 11.642], [18.504, 12.312, 12.298], [18.684, 12.451, 13.784], [19.533, 11.718, 14.362], [17.582, 11.117, 11.996], [17.199, 10.929, 10.237], [17.880, 13.266, 14.426], [17.924, 13.421, 15.877], [17.392, 12.206, 16.594], [16.652, 11.368, 16.033], [17.076, 14.658, 16.145], [16.098, 14.689, 14.997], [16.859, 14.150, 13.779], [17.728, 12.124, 17.884], [17.334, 10.956, 18.691], [15.875, 10.688, 18.871], [15.434, 9.550, 19.166], [15.036, 11.747, 18.715], [13.564, 11.573, 18.836], [12.936, 11.227, 17.470], [11.720, 11.040, 17.428], [12.933, 12.737, 19.580], [13.140, 14.094, 18.958], [14.109, 14.303, 18.212], [12.267, 14.963, 19.265], [13.725, 11.174, 16.425], [13.257, 10.745, 15.081], [14.275, 9.687, 14.612], [14.930, 9.862, 13.568], [13.200, 11.914, 14.071], [12.000, 12.819, 14.399], [12.119, 13.853, 15.332], [10.775, 12.617, 13.762], [11.045, 14.675, 15.610], [9.676, 13.433, 14.048], [9.802, 14.456, 14.996], [8.740, 15.265, 15.269], [14.342, 8.640, 15.422], [15.445, 7.667, 15.246], [15.171, 6.533, 14.280], [16.093, 5.705, 14.039], [15.680, 7.099, 16.682], [13.966, 6.502, 13.739], [13.512, 5.395, 12.878], [13.311, 5.853, 11.455], [13.733, 6.929, 11.026], [12.266, 4.769, 13.501], [12.538, 4.304, 14.922], [11.982, 4.849, 15.886], [13.407, 3.298, 15.015], [12.703, 4.973, 10.746], ], 'f' ) mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/Data/__init__.py0000644000175000017500000000000010070606742025325 0ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/__init__.py0000644000175000017500000000000010021735016024445 0ustar debiandebianmgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/test_dependencies.py0000644000175000017500000000152210406105035026404 0ustar debiandebian# ################################################################# # Author: Sowjanya Karnati ################################################################# # #Purpose:To update dependencies list # # $Id: test_dependencies.py,v 1.2 2006/03/15 21:41:49 sowjanya Exp $ from mglutil.TestUtil.Tests.dependenciestest import DependencyTester import unittest d = DependencyTester() result_expected =[] class test_dep(unittest.TestCase): def test_dep_1(self): result = d.rundeptester('geomutils') if result !=[]: print "\nThe Following Packages are not present in CRITICAL or NONCRITICAL DEPENDENCIES of geomutils :\n %s" %result self.assertEqual(result,result_expected) else: self.assertEqual(result,result_expected) if __name__ == '__main__': unittest.main() mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/Tests/test.py0000644000175000017500000000350510267503416023713 0ustar debiandebianimport sys from mglutil.regression import testplus def setUpSuite(): from geomutils import efitlib def test_lib(): from geomutils import efitlib ellipse = efitlib.ellipsoid() ellipseInfo = efitlib.efit_info() from Data.crn_coords import crn_coords ell_scale = 1.0 # 0.0 or belove defaults to 1.0 cov_scale= 1.75 # 0.0 or smaller defaults to 1.75 efitlib.fitEllipse(crn_coords, ell_scale, cov_scale, ellipseInfo, ellipse) print 'center:', ellipse.getPosition() print 'scaling:', ellipse.getAxis() print 'orientation', ellipse.getOrientation() ellipse = efitlib.ellipsoid() ellipseInfo = efitlib.efit_info() from Data.cv_coords import cv_coords efitlib.fitEllipse(cv_coords, ell_scale, cov_scale, ellipseInfo, ellipse) ## print 'weightflag:', ellipseInfo.weightflag ## print 'covarflag:', ellipseInfo.covarflag ## print 'volumeflag:', ellipseInfo.volumeflag ## print 'matrixflag:', ellipseInfo.matrixflag ## print 'nocenterflag:', ellipseInfo.nocenterflag ## print 'noscaleflag:', ellipseInfo.noscaleflag ## print 'nosortflag:', ellipseInfo.nosortflag ## print 'count:', ellipseInfo.count ## print 'cov_scale:', ellipseInfo.cov_scale ## print 'ell_scale:', ellipseInfo.ell_scale print 'center:', ellipse.getPosition() print 'scaling:', ellipse.getAxis() print 'orientation', ellipse.getOrientation() vec = [.28, 0.89, 1.5] vec1=efitlib.vec_normalize(vec) print "vector:", vec print "normalized vector:", vec1 if __name__ == '__main__': testplus.chdir() harness = testplus.TestHarness( __name__, connect = (setUpSuite, (), {}), funs = testplus.testcollect( globals()), ) print harness sys.exit( len( harness)) mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/__init__.py0000644000175000017500000000016010653507546023372 0ustar debiandebian __MGLTOOLSVersion__ = '1-4alpha3' CRITICAL_DEPENDENCIES = ['mglutil' , 'Numpy'] NONCRITICAL_DEPENDENCIES = [] mgltools-geomutils-1.5.7~rc1~cvs.20130519/geomutils/sdf.i0000644000175000017500000001075210367460160022207 0ustar debiandebian%module sdflib #include #include %{ struct sdfgrid { int size[3]; float gridSpacing; float origin[3]; float corner[3]; float *gridpoint; }; /* Read SDF (signed distance field) grid and return the grid object */ struct sdfgrid * readSDF (char *sdfgridfile) { FILE *fp; int i, j, k, n; int size[3]; float gridSpacing, origin[3], corner[3]; float *gridpoint; /* store signed distance field */ struct sdfgrid *sdfgrid; /* open grid file */ fp = fopen(sdfgridfile, "r"); /* read the first line */ fscanf(fp, "%d %d %d %f %f %f %f %f %f %f\n", &size[0], &size[1], &size[2], &gridSpacing, &origin[0], &origin[1], &origin[2], &corner[0], &corner[1], &corner[2]); /* printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", size[0], size[1], size[2], gridSpacing, origin[0], origin[1], origin[2], corner[0], corner[1], corner[2]); */ /* allocate space for the grid points */ gridpoint = (float *) calloc( size[0]*size[1]*size[2], sizeof(float) ); /* read the rest lines (grid points) */ n = 0; for ( i=0; isize[0] = size[0]; sdfgrid->size[1] = size[1]; sdfgrid->size[2] = size[2]; sdfgrid->gridSpacing = gridSpacing; sdfgrid->origin[0] = origin[0]; sdfgrid->origin[1] = origin[1]; sdfgrid->origin[2] = origin[2]; sdfgrid->corner[0] = corner[0]; sdfgrid->corner[1] = corner[1]; sdfgrid->corner[2] = corner[2]; sdfgrid->gridpoint = gridpoint; /* printf("sdfgrid works!: gridSpacing = %8.3f\n", sdfgrid->gridSpacing); */ return sdfgrid; } /* Look up transformed coordinates tcoord in a SDF grid, tcoordLen is the length of tcoord, and * largestOverlapAllowed is the largest overlap allowed in the search. The subroutine returns * 0 if no overlap larger than largestOverlapAllowed or 1 if there is. Last update: 1/19/2006 QZ */ int lookup (struct sdfgrid *sdfgrid, float tcoord[][3], int tcoordLen, float largestOverlapAllowed) { float x, y, z, xo, yo, zo, xm, ym, zm, gs; int sx, sy, sz, xi, yi, zi; static float outside = 9999.0; static int OK = 0, violation = 1; int i; float dist; for ( i = 0; i < tcoordLen; i++ ) { x = tcoord[i][0]; y = tcoord[i][1]; z = tcoord[i][2]; /* printf("point %d = %8.3f %8.3f %8.3f\n", i, x, y, z); */ sx = sdfgrid->size[0]; sy = sdfgrid->size[1]; sz = sdfgrid->size[2]; gs = sdfgrid->gridSpacing; xo = sdfgrid->origin[0]; yo = sdfgrid->origin[1]; zo = sdfgrid->origin[2]; xm = sdfgrid->corner[0]; ym = sdfgrid->corner[1]; zm = sdfgrid->corner[2]; /* printf("%5d %5d %5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", sx, sy, sz, gs, xo, yo, zo, xm, ym, zm); */ if ( xxm ) continue; if ( yym ) continue; if ( zzm ) continue; xi = (int) (rintf((x-xo)/gs)); /* do not use nearbyintf, which causes segmentation fault */ yi = (int) (rintf((y-yo)/gs)); zi = (int) (rintf((z-zo)/gs)); /* printf("[%8.3f, %8.3f, %8.3f] -> [%5d %5d %5d] ", x, y, z, xi, yi, zi); */ dist = sdfgrid->gridpoint[xi*sy*sz + yi*sz + zi]; /* printf("dist = %8.3f\n", dist); */ if ( dist < -largestOverlapAllowed ) { return violation; } } return OK; } %} %include numarr.i %typemap(in) ( float tcoord[1][3], int tcoordLen) (PyArrayObject *array, int expected_dims[2]) %{ if ($input != Py_None) { expected_dims[0] = $1_dim0; expected_dims[1] = $1_dim1; if (expected_dims[0]==1) expected_dims[0]=0; if (expected_dims[1]==1) expected_dims[1]=0; array = contiguous_typed_array($input, PyArray_FLOAT, 2, expected_dims); if (! array) return NULL; $1 = (float (*)[$1_dim1])array->data; $2 = ((PyArrayObject *)(array))->dimensions[0]; } else { array = NULL; $1 = NULL; $2 = 0; } %} %typemap(freearg)( float tcoord[1][3], int tcoordLen) %{ if ( array$argnum ) Py_DECREF((PyObject *)array$argnum); %} struct sdfgrid * readSDF (char *sdfgridfile); int lookup (struct sdfgrid *sdfgrid, float tcoord[1][3], int tcoordLen, float largestOverlapAllowed); mgltools-geomutils-1.5.7~rc1~cvs.20130519/LICENSE0000644000175000017500000000436411033241674020256 0ustar debiandebianThis software is copyrighted by Michel F. Sanner (sanner@scripps.edu) and TSRI. The following terms apply to all files associated with the software unless explicitly disclaimed in individual files. MGLTOOLS SOFTWARE LICENSE AGREEMENT. 1. Grant Of Limited License; Software Use Restrictions. The programs received by you will be used only for NON COMMERCIAL purposes. This license is issued to you as an individual. For COMMERCIAL use done with the software please contact Michel F. Sanner for details about commercial usage license agreements. For any question regarding license agreements, please contact Michel Sanner: TSRI, Molecular Biology Department, TCP 26, 10550 North Torrey Pines Road, La Jolla, CA 92037 sanner@scripps.edu tel (858) 784-7742 fax (858) 784-2341 2. COMMERCIAL USAGE is defined as revenues generating activities. These include using this software for consulting activities and selling applications built on top of, or using this software. Scientific research in an academic environment and teaching are considered NON COMMERCIAL. 3. Copying Restrictions. You will not sell or otherwise distribute commercially these programs or derivatives to any other party, whether with or without consideration. 4. Ownership of Software. You will not obtain, and will not attempt to obtain copyright coverage thereon without the express purpose written consent of The Scripps Research Institute and Dr. Sanner. 5. IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. mgltools-geomutils-1.5.7~rc1~cvs.20130519/version.py0000644000175000017500000000002011475262464021303 0ustar debiandebianVERSION="1.5.6" mgltools-geomutils-1.5.7~rc1~cvs.20130519/README0000644000175000017500000000162110260336213020115 0ustar debiandebianThis package builds _geomutilslib.so library and installs it in /lib/python2.4/site-packages/geomutils/ directory. Distutils are used to build and install the extension. "setup.cfg" file can be used to specify the installation directory( other than the default one). SWIG (version swig1.3.20 or higher) is used for generating wrappers. (Currently there is no way to specify the version of swig to be used by Distutils - the default version has to be 1.3.20 or the one that automatically generates python shadow classes). To buid the extension: python2.4 setup.py build_ext This puts the .py and .so into automatically generated directory build/lib_platform. To install: python2.4 setup.py install The 'inplace' option tells the Distutils to put the .so into the current directory: python2.4 setup.py build_ext --inplace To create MANIFEST: python2.4 setup.py sdist --manifest-only mgltools-geomutils-1.5.7~rc1~cvs.20130519/MANIFEST.in0000644000175000017500000000062011033242620020766 0ustar debiandebianinclude MANIFEST.in include CVS/* include geomutils/*.i include geomutils/CVS/* include geomutils/Tests/CVS/* include geomutils/Tests/Data/CVS/* include src/efit/*.h include src/geomAlgorithms/*.h include src/CVS/* include src/efit/CVS/* include src/geomAlgorithms/CVS/* exclude geomutils/efitlib.py exclude geomutils/geomalgorithms.py include version.py include geomutils/doc.tar.gz include LICENSE