Doxygen Source Code Documentation
SUMA_ConvexHull.c File Reference
#include "SUMA_suma.h"Go to the source code of this file.
Functions | |
| int | SUMA_qhull_wrap (int npt, float *xyz, int **ijk, int fliporient) |
| SUMA_SurfaceObject * | SUMA_ConvexHullSurface (SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt) |
Variables | |
| SUMA_CommonFields * | SUMAg_CF |
| SUMA_DO * | SUMAg_DOv |
| SUMA_SurfaceViewer * | SUMAg_SVv |
| int | SUMAg_N_SVv |
| int | SUMAg_N_DOv |
Function Documentation
|
|
A function to call SUMA_qhull_wrap Definition at line 133 of file SUMA_ConvexHull.c. References THD_3dim_dataset::daxes, SUMA_GENERIC_PROG_OPTIONS_STRUCT::debug, DSET_DX, DSET_DY, DSET_DZ, DSET_NX, DSET_NY, DSET_NZ, DSET_XORG, DSET_YORG, DSET_ZORG, free, i, SUMA_GENERIC_PROG_OPTIONS_STRUCT::in_vol, SUMA_GENERIC_PROG_OPTIONS_STRUCT::mcdatav, SUMA_GENERIC_PROG_OPTIONS_STRUCT::N_XYZ, SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_Patch2Surf(), SUMA_qhull_wrap(), SUMA_RETURN, SUMA_S_Err, SUMA_THD_3dmm_to_dicomm(), THD_dataxes::xxorient, SUMA_GENERIC_PROG_OPTIONS_STRUCT::XYZ, THD_fvec3::xyz, THD_dataxes::yyorient, and THD_dataxes::zzorient.
00134 {
00135 static char FuncName[]={"SUMA_ConvexHullSurface"};
00136 SUMA_SurfaceObject *SO=NULL;
00137 float *xyz=NULL;
00138 int npt, *ijk=NULL, nf, cnt, i, j, k, nxx, nyy, nzz;
00139 FILE *fid=NULL;
00140 THD_fvec3 fv, iv;
00141
00142 SUMA_ENTRY;
00143
00144 npt = 0;
00145 if (Opt->in_vol) {
00146 cnt = 0; npt = 0;
00147 nxx = (DSET_NX(Opt->in_vol));
00148 nyy = (DSET_NY(Opt->in_vol));
00149 nzz = (DSET_NZ(Opt->in_vol));
00150
00151 if (Opt->debug) fprintf(SUMA_STDERR,"%s:\nRunning qhull...\n", FuncName);
00152 xyz = (float *)SUMA_malloc(3*nxx*nyy*nzz*sizeof(float));
00153 if (!xyz) {
00154 SUMA_S_Err("Failed to allocate"); SUMA_RETURN(NULL);
00155 }
00156 for( k = 0 ; k < nzz ; k++ ) {
00157 for( j = 0 ; j < nyy ; j++ ) {
00158 for( i = 0 ; i < nxx ; i++ ) {
00159 if (Opt->mcdatav[cnt] == 1) {
00160 fv.xyz[0] = DSET_XORG(Opt->in_vol) + i * DSET_DX(Opt->in_vol);
00161 fv.xyz[1] = DSET_YORG(Opt->in_vol) + j * DSET_DY(Opt->in_vol);
00162 fv.xyz[2] = DSET_ZORG(Opt->in_vol) + k * DSET_DZ(Opt->in_vol);
00163 /* change mm to RAI coords */
00164 iv = SUMA_THD_3dmm_to_dicomm( Opt->in_vol->daxes->xxorient, Opt->in_vol->daxes->yyorient, Opt->in_vol->daxes->zzorient, fv );
00165 xyz[3*npt] = iv.xyz[0]; xyz[3*npt+1] = iv.xyz[1]; xyz[3*npt+2] = iv.xyz[2];
00166 npt++;
00167 }
00168 ++cnt;
00169 }
00170 }
00171 }
00172 } else if (Opt->XYZ) {
00173 xyz = (float *)SUMA_malloc(3*Opt->N_XYZ*sizeof(float));
00174 if (!xyz) {
00175 SUMA_S_Err("Failed to allocate"); SUMA_RETURN(NULL);
00176 }
00177 for( k = 0 ; k < 3*Opt->N_XYZ ; k++ ) { xyz[k] = Opt->XYZ[k]; npt = Opt->N_XYZ; }
00178 } else {
00179 SUMA_S_Err("No input");
00180 SUMA_RETURN(NULL);
00181 }
00182 if (! (nf = SUMA_qhull_wrap(npt, xyz, &ijk, 1)) ) {
00183 fprintf(SUMA_STDERR,"%s:\nFailed in SUMA_qhull_wrap\n", FuncName);
00184 SUMA_RETURN(SO);
00185 }
00186
00187 if (Opt->debug) fprintf(SUMA_STDERR,"%s:\n%d triangles.\n", FuncName, nf);
00188
00189
00190 SO = SUMA_Patch2Surf(xyz, npt, ijk, nf, 3);
00191 free(ijk); ijk=NULL;
00192 SUMA_free(xyz); xyz = NULL;
00193
00194 SUMA_RETURN(SO);
00195 }
|
|
||||||||||||||||||||
|
Definition at line 62 of file SUMA_ConvexHull.c. References close(), fd, fdopen(), free, malloc, pclose, and popen. Referenced by SUMA_ConvexHullSurface(), and SUMA_LoadPrepInVol().
00063 {
00064 static char FuncName[]={"SUMA_qhull_wrap"};
00065 int ii,jj , nfac , *fac ;
00066 int fd ; FILE *fp ;
00067 char qbuf[128] ;
00068
00069 #ifndef DONT_USE_MKSTEMP
00070 char fname[] = "/tmp/afniXXXXXX" ;
00071 #else
00072 char *fname ;
00073 #endif
00074
00075 if( npt < 3 || xyz == NULL || ijk == NULL ){
00076 fprintf(stderr,"SUMA_qhull_wrap: bad inputs\n") ;
00077 return 0 ;
00078 }
00079
00080 #ifndef DONT_USE_MKSTEMP
00081 fd = mkstemp( fname ) ;
00082 if( fd == -1 ){ fprintf(stderr,"SUMA_qhull_wrap: mkstemp fails\n"); return 0; }
00083 fp = fdopen( fd , "w" ) ;
00084 if( fp == NULL ){ fprintf(stderr,"SUMA_qhull_wrap: fdopen fails\n"); close(fd); return 0; }
00085 #else
00086 fname = tmpnam(NULL) ;
00087 if( fname == NULL ){ fprintf(stderr,"SUMA_qhull_wrap: tmpnam fails\n"); return 0; }
00088 fp = fopen( fname , "w" ) ;
00089 if( fp == NULL ){ fprintf(stderr,"SUMA_qhull_wrap: fopen fails\n"); return 0; }
00090 #endif
00091
00092 fprintf(fp,"3\n%d\n",npt) ;
00093 for( ii=0 ; ii < npt ; ii++ )
00094 fprintf(fp,"%g %g %g\n",xyz[3*ii],xyz[3*ii+1],xyz[3*ii+2]) ;
00095
00096 fclose(fp) ;
00097
00098 sprintf(qbuf,"qhull QJ i < %s",fname) ;
00099 fp = popen( qbuf , "r" ) ;
00100 if( fp == NULL ){ fprintf(stderr,"SUMA_qhull_wrap: popen fails\n"); remove(fname); return 0; }
00101
00102 jj = fscanf(fp,"%d",&nfac) ;
00103 if( jj != 1 || nfac < 1 ){ fprintf(stderr,"SUMA_qhull_wrap: 1st fscanf fails\n"); pclose(fp); remove(fname); return 0; }
00104
00105 fac = (int *) malloc( sizeof(int)*3*nfac ) ;
00106 if( fac == NULL ){ fprintf(stderr,"SUMA_qhull_wrap: malloc fails\n"); pclose(fp); remove(fname); return 0; }
00107
00108 if (fliporient) {
00109 for( ii=0 ; ii < nfac ; ii++ ){
00110 jj = fscanf(fp,"%d %d %d",fac+(3*ii+2),fac+(3*ii+1),fac+(3*ii)) ;
00111 if( jj < 3 ){
00112 fprintf(stderr,"SUMA_qhull_wrap: fscanf fails at ii=%d\n",ii) ;
00113 pclose(fp); remove(fname); free(fac); return 0;
00114 }
00115 }
00116 } else {
00117 for( ii=0 ; ii < nfac ; ii++ ){
00118 jj = fscanf(fp,"%d %d %d",fac+(3*ii),fac+(3*ii+1),fac+(3*ii+2)) ;
00119 if( jj < 3 ){
00120 fprintf(stderr,"SUMA_qhull_wrap: fscanf fails at ii=%d\n",ii) ;
00121 pclose(fp); remove(fname); free(fac); return 0;
00122 }
00123 }
00124 }
00125 pclose(fp); remove(fname);
00126
00127 *ijk = fac ; return nfac ;
00128 }
|
Variable Documentation
|
|
Global pointer to structure containing info common to all viewers Definition at line 20 of file SUMA_ConvexHull.c. |
|
|
Global pointer to Displayable Object structure vector Definition at line 21 of file SUMA_ConvexHull.c. |
|
|
Number of DOs stored in DOv Definition at line 24 of file SUMA_ConvexHull.c. |
|
|
Number of SVs stored in SVv Definition at line 23 of file SUMA_ConvexHull.c. |
|
|
Global pointer to the vector containing the various Surface Viewer Structures Definition at line 22 of file SUMA_ConvexHull.c. |