1 #ifndef SUMA_GEOMCOMP_INCLUDED
2 #define SUMA_GEOMCOMP_INCLUDED
3 
4 #ifndef MAX_NCODE
5 #define MAX_NCODE 111
6 #endif
7 
8 /*
9    faster than SUMA_ApproxNeighbors but a lot more dangerous!
10 */
11 #define SUMA_APPROX_NEIGHBORS(SO, SOf, cent, dnei, SegDist, mask_record, nmask, N_nmask)   \
12 {  \
13    static int m_i;   \
14    static float m_dnei_sp, m_alph, m_rsearch;   \
15    /* Now cleanup the previous record */  \
16    for (m_i=0; m_i<N_nmask; ++m_i) { nmask[mask_record[m_i]] = 0; }  \
17    /* Calculate the Equivalent neighborhood distance on the spherical version of the surface */ \
18    m_dnei_sp = dnei * SegDist[cent];  \
19    m_alph = m_dnei_sp / SOf->SphereRadius; \
20    m_rsearch = sin(m_alph/2.0)*2.0*SOf->SphereRadius; \
21    SUMA_NODESINSPHERE2( SOf->NodeList, SOf->N_Node, &(SOf->NodeList[3*cent]), m_rsearch, mask_record, N_nmask);   \
22    for (m_i=0; m_i<N_nmask; ++m_i) nmask[mask_record[m_i]] = 1;  \
23 }
24 
25 typedef enum { NO_PRJ = -1,
26                E1_PLN_PRJ  , E2_PLN_PRJ, E3_PLN_PRJ,
27                EZ_PLN_PRJ  , EY_PLN_PRJ, EX_PLN_PRJ,
28                E1_DIR_PRJ  , E2_DIR_PRJ, E3_DIR_PRJ,
29                EZ_DIR_PRJ  , EY_DIR_PRJ, EX_DIR_PRJ,
30                N_PRJ} SUMA_PC_PROJ;
31 
32 typedef enum { NO_ROT = 0, ROT_2_Z = 1, ROT_2_Y, ROT_2_X } SUMA_PC_ROT;
33 
34 typedef struct {
35    double avg[3]; /*center of mass XYZ of input data */
36    double eig[3]; /* 3 eigen values */
37    double PC[9];  /* 3 eigen vectors, x1 y1 z1 x2 y2 z2 x3 y3 z3 */
38    float *xyzp;   /* Projected coordinates, should be same as input
39                      when no projection, no rotation done, and mean
40                      put back. (x0 y0 z0 x1 y1 z1 x2 y2 z2 ...) */
41    int N_xyz;     /* Number of triplets in xyzp */
42    char closest[3];/* The closest cardinal directions to each
43                       of the three eigen vectors */
44    char target[32];/* Target of projection, "plane", or "line" */
45    double target_params[4]; /* Equation of target, 4 values for plane,
46                                3 for line */
47    double RotMat[4][4];/* Rotation matrix applied to coordinates in xyzp */
48 
49    int highest_node;
50    int lowest_node;
51    float highest_proj[3];
52    float lowest_proj[3];
53 } SUMA_PC_XYZ_PROJ;
54 
55 
56 typedef enum { SUMA_SMOOTH_NOT_SET, SUMA_EQUAL, SUMA_FUJIWARA, SUMA_DESBRUN } SUMA_TAUBIN_SMOOTH_OPTIONS;
57 
58 static int SUMA_SSidbg=-1; /*!< Index of node for debug */
59 
60 typedef struct {
61    int ni;
62    int layer;
63    float off;
64 }  SUMA_OFFSET_LL_DATUM;
65 
66 typedef struct {
67    int N_TriIndex;            /*!< Number of triangles considered */
68    int *TriIndex;             /*!< vector (N_TriIndex x 1) of 1D indices
69                                    of triangles considered */
70    int **IntersectedVoxels;   /*!< sparse matrix (N_TriIndex x
71                   N_InteresectedVoxels[i]) containing
72                   1D indices of voxels intersected by the triangle. For example,
73                   triangle of index TriIndex[i] intesects N_InteresectedVoxels[i]
74                   whose 1D indices are stored in IntersectedVoxels[i] */
75    float **SignedIJKDistance; /*!< sparse matrix (N_TriIndex x
76                   N_InteresectedVoxels[i]) containing signed distance
77                         *** in index units, NOT mm ***
78                   from triangle. */
79    int *N_IntersectedVoxels;  /*!< Number of voxels intersected by some triangle */
80 } SUMA_VTI; /*!< Voxel Triangle Intersection Structure. Create with SUMA_CreateVTI, Destroy with SUMA_FreeVTI*/
81 
82 SUMA_Boolean SUMA_BuildRotationMatrix(double *C, double *Ax,
83                                       double alpha, double mat[4][4]);
84 int SUMA_BoundaryTriangles (SUMA_SurfaceObject *SO, int *boundt,
85                             int boundt_asmask );
86 
87 SUMA_Boolean SUMA_TriTrig(float *p1, float *p2, float *p3,
88                            double *s, double *c, double *a);
89 
90 SUMA_VTI *SUMA_CreateVTI(int N_TriIndex, int *TriIndex);
91 SUMA_VTI * SUMA_FreeVTI(SUMA_VTI *vti);
92 SUMA_VTI *SUMA_GetVoxelsIntersectingTriangle(
93          SUMA_SurfaceObject *SO, SUMA_VOLPAR *VolPar, float *NodeIJKlist,
94          SUMA_VTI *vti);
95 THD_3dim_dataset *SUMA_SurfaceIntersectionVolume(
96                         SUMA_SurfaceObject *SOo, THD_3dim_dataset *gdset);
97 THD_3dim_dataset *SUMA_VoxelToSurfDistances(SUMA_SurfaceObject *SO,
98                      THD_3dim_dataset *master, byte *mask,
99                      short *isin, short inval);
100 THD_3dim_dataset *SUMA_VoxelizeSurface(SUMA_SurfaceObject *SO,
101                                        THD_3dim_dataset *gdset,
102                                        int closed_surf,
103                                        byte *mask);
104 THD_3dim_dataset *SUMA_MaskizeSurface(SUMA_SurfaceObject *SO,
105                                        THD_3dim_dataset *gdset,
106                                        int method);
107 DList * SUMA_SPI_to_EdgeStrips(SUMA_SurfaceObject *SO,
108                                SUMA_SURF_PLANE_INTERSECT *SPI);
109 SUMA_Boolean SUMA_isEdgeStripClosed(DList *edgestrip, SUMA_SurfaceObject *SO);
110 int SUMA_isSelfIntersect(SUMA_SurfaceObject *SO, int FullCount, byte * report);
111 int SUMA_VoxelNeighbors (int ijk, int ni, int nj, int nk, SUMA_VOX_NEIGHB_TYPES ntype, int *nl);
112 byte *SUMA_FillToVoxelMask(byte *ijkmask, int ijkseed, int ni, int nj, int nk, int *N_in, byte *usethisisin);
113 SUMA_Boolean SUMA_VoxelsInBox(int *voxelsijk, int *N_in, float *c1, float *c2);
114 SUMA_SurfaceObject *SUMA_Patch2Surf(float *NodeList, int N_NodeList, int *PatchFaces, int N_PatchFaces, int PatchDim);
115 SUMA_PATCH * SUMA_getPatch (  int *NodesSelected, int N_Nodes, int MaxNodeMax,
116                               int *Full_FaceSetList, int N_Full_FaceSetList,
117                               SUMA_MEMBER_FACE_SETS *Memb, int MinHits,
118                               int FixBowTie, int verb);
119 SUMA_Boolean SUMA_freePatch (SUMA_PATCH *Patch);
120 byte *SUMA_MaskOfNodesInPatch(SUMA_SurfaceObject *SO, int *N_NodesUsedInPatch);
121 SUMA_BRANCH * SUMA_FindBranch (int ** InterMat, int N_InterMat, float ** InterNodes, int ** NodeLoc_in_InterMat, int verbose,  int * WBsz);
122 SUMA_SURF_PLANE_INTERSECT *SUMA_Surf_Plane_Intersect (SUMA_SurfaceObject *SO, float *PlaneEq);
123 SUMA_ROI_DATUM *SUMA_Surf_Plane_Intersect_ROI (SUMA_SurfaceObject *SO, int Nfrom, int Nto, float *P);
124 void SUMA_WeldBranches ( SUMA_BRANCH *branch, int *sz_Branch, int brIndx1, int brIndx2 , int brEnd1, int brEnd2 );
125 float * SUMA_Plane_Equation (float * P1, float *P2, float *P3, float *thiseq);
126 int SUMA_Find_Edge_Nhost (SUMA_EDGE_LIST *EL, int *IsInter, int N_IsInter, int *kedge, int Nhost);
127 SUMA_Boolean SUMA_Mark_Tri (SUMA_EDGE_LIST *EL, int E1, int iBranch, int *TriBranch, int *IsInter, int *N_IsInter, int *VisitationOrder, int *ivisit);
128 int * SUMA_Dijkstra (SUMA_SurfaceObject *SO, int Nx, int Ny, SUMA_Boolean *isNodeInMesh, int *N_isNodeInMesh, int Method_Number, float *Lfinal, int *N_Path);
129 int * SUMA_Dijkstra_usegen (SUMA_SurfaceObject *SO, int Nx,
130                      int Ny, SUMA_Boolean *isNodeInMeshp,
131                      int *N_isNodeInMesh, int Method_Number,
132                      float *Lfinal, int *N_Path);
133 void SUMA_free_SPI (SUMA_SURF_PLANE_INTERSECT *SPI);
134 SUMA_SURF_PLANE_INTERSECT * SUMA_Allocate_SPI (SUMA_SurfaceObject *SO);
135 SUMA_TRI_BRANCH* SUMA_AssignTriBranch (SUMA_SurfaceObject *SO, SUMA_SURF_PLANE_INTERSECT *SPI, int Nx, int *BranchCount, SUMA_Boolean DoCopy);
136 SUMA_Boolean SUMA_show_STB (SUMA_TRI_BRANCH *B, FILE *Out);
137 void SUMA_free_STB (SUMA_TRI_BRANCH *Bv, int N_Bv);
138 SUMA_Boolean SUMA_Show_SPI (SUMA_SURF_PLANE_INTERSECT *SPI, FILE * Out, SUMA_SurfaceObject *SO, char *opref, SUMA_SurfaceViewer *sv);
139 int *SUMA_NodePath_to_EdgePath (SUMA_EDGE_LIST *EL, int *Path, int N_Path, int *N_Edge);
140 int *SUMA_NodePath_to_TriPath_Inters_OLD (SUMA_SurfaceObject *SO, SUMA_TRI_BRANCH *Bv, int *Path, int N_Path, int *N_Tri);
141 int *SUMA_NodePath_to_TriPath_Inters ( SUMA_SurfaceObject *SO, SUMA_SURF_PLANE_INTERSECT *SPI, int *nPath, int N_nPath, int *N_tPath);
142 int * SUMA_IntersectionStrip (SUMA_SurfaceObject *SO, SUMA_SURF_PLANE_INTERSECT *SPI,  int *nPath, int N_nPath, float *dinters, float dmax, int *N_tPath);
143 SUMA_Boolean SUMA_FromIntEdgeToIntEdge (int Tri, int E1, int E2, SUMA_EDGE_LIST *EL, SUMA_SURF_PLANE_INTERSECT *SPI, int Ny, SUMA_Boolean *Visited, float *d, float dmax, int *tPath, int *N_tPath);
144 SUMA_Boolean SUMA_isSameEdge (SUMA_EDGE_LIST *EL, int E1, int E2);
145 SUMA_CONTOUR_EDGES *SUMA_GetContour (SUMA_SurfaceObject *SO, int *Nodes,
146                                      int N_Node, int *N_ContEdges, int mode,
147                                      SUMA_PATCH *UseThisPatch,
148                                      byte **isNodeInNodes, int verb);
149 SUMA_Boolean SUMA_ShowPatch (SUMA_PATCH *Patch, FILE *Out) ;
150 void SUMA_Set_OffsetDebugNode (int d);
151 SUMA_Boolean SUMA_getoffsets  (int n, SUMA_SurfaceObject *SO, float *Off,
152                                float lim);
153 SUMA_Boolean SUMA_getoffsets2 (  int n, SUMA_SurfaceObject *SO,
154                                  float lim, SUMA_GET_OFFSET_STRUCT *OffS,
155                                  int * CoverThisNode, int N_CoverThisNode);
156 byte *SUMA_NodeNeighborMask(SUMA_SurfaceObject *SO, int node,
157                             int maxlay, int *N_inmask);
158 DList * SUMA_getoffsets_ll (int n, SUMA_SurfaceObject *SO, float lim,
159                             int *CoverThisNode, int N_CoverThisNode);
160 SUMA_GET_OFFSET_STRUCT *SUMA_Initialize_getoffsets (int N_Node);
161 SUMA_Boolean SUMA_AddNodeToLayer (int n, int LayInd,
162                                   SUMA_GET_OFFSET_STRUCT *OffS);
163 SUMA_GET_OFFSET_STRUCT * SUMA_Free_getoffsets (SUMA_GET_OFFSET_STRUCT *OffS);
164 SUMA_Boolean SUMA_Recycle_getoffsets (SUMA_GET_OFFSET_STRUCT *OffS);
165 float ** SUMA_CalcNeighbDist (SUMA_SurfaceObject *SO);
166 int SUMA_Chung_Smooth_05_N_iter (double fwhm, double AvgLe, double *sigmap);
167 float SUMA_SigFromBeta (float Beta);
168 double SUMA_SigForFWHM(float AvgLe, double dfwhm, int *niter, double *beta);
169 float ** SUMA_Chung_Smooth_Weights (SUMA_SurfaceObject *SO);
170 float * SUMA_Chung_Smooth (SUMA_SurfaceObject *SO, float **wgt,
171                            int N_iter, float FWHM, float *fin,
172                         int vpn, SUMA_INDEXING_ORDER d_order, float *fout_user,
173                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
174 SUMA_Boolean SUMA_Chung_Smooth_dset (SUMA_SurfaceObject *SO, float **wgt,
175                            int N_iter, float FWHM, SUMA_DSET *dset,
176                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
177 SUMA_Boolean SUMA_DotNormals(SUMA_SurfaceObject *SO, float *dir, float **dots);
178 SUMA_Boolean SUMA_PrepMaskEval_Params(char *expr, int N_vals,
179                                       SUMA_MASK_EVAL_PARAMS **mepp);
180 SUMA_MASK_EVAL_PARAMS *SUMA_FreeMaskEval_Params(SUMA_MASK_EVAL_PARAMS *mep);
181 SUMA_MASK_EVAL_PARAMS *SUMA_AllocMaskEval_Params(void);
182 
183 /* NOTE THAT x passed to the macro must be in units of distance^2 */
184 #define SUMA_CHUNG_KERNEL_NUMER(x,s) (exp(-(x)/(2.0*(s)*(s))))
185 #define SUMA_FWHM_MEAN(fwhmv, N_fwhmv, meanfwhm, FWHM_mixmode, N) {\
186    int m_k=0; \
187    N = 0; meanfwhm = 0; \
188    if (SUMA_iswordin_ci(FWHM_mixmode, "geom")) {   \
189      for (m_k=0; m_k<N_fwhmv; ++m_k) { \
190       if (fwhmv[m_k] >= 0.0) { meanfwhm += log(fwhmv[m_k]); ++N; }   \
191      }   \
192      if (N) meanfwhm = exp(meanfwhm/(double)N) ;  \
193      else meanfwhm = 0.0;  \
194    } else if (SUMA_iswordin_ci(FWHM_mixmode, "arit")) {  \
195      for (m_k=0; m_k<N_fwhmv; ++m_k) { \
196       if (fwhmv[m_k] >= 0.0) { meanfwhm += (fwhmv[m_k]); ++N; }  \
197      }   \
198      if (N) meanfwhm = (meanfwhm/(double)N) ;   \
199      else meanfwhm = 0.0;  \
200    } else { \
201       SUMA_S_Err("Bad or NULL FWHM_mixmode");   \
202       N = -1;   \
203    }  \
204 }
205 
206 float ** SUMA_Chung_Smooth_Weights_05_single (SUMA_SurfaceObject *SO, float fwhm);
207 float ** SUMA_Chung_Smooth_Weights_05_Pre_07 (SUMA_SurfaceObject *SO, float fwhm);
208 double ** SUMA_Chung_Smooth_Weights_07 (SUMA_SurfaceObject *SO, double fwhm);
209 float * SUMA_Chung_Smooth_05 (SUMA_SurfaceObject *SO, float **wgt,
210                            int N_iter, float FWHM, float *fin,
211                            int vpn, SUMA_INDEXING_ORDER d_order, float *fout_user,
212                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
213 SUMA_Boolean SUMA_Chung_Smooth_05_single_dset (SUMA_SurfaceObject *SO, float **wgt,
214                            int N_iter, float FWHM, SUMA_DSET *dset,
215                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
216 SUMA_Boolean SUMA_Chung_Smooth_05_Pre_07_dset (SUMA_SurfaceObject *SO, float **wgt,
217                            int N_iter, float FWHM, SUMA_DSET *dset,
218                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
219 SUMA_Boolean SUMA_Chung_Smooth_07_dset (SUMA_SurfaceObject *SO, double **wgt,
220                            int *N_iter, double *FWHM, SUMA_DSET *dset,
221                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
222 SUMA_Boolean SUMA_Chung_Smooth_07_toFWHM_dset (SUMA_SurfaceObject *SO, double **wgt,
223                            int *N_iter, double *FWHM, SUMA_DSET *dset,
224                            byte *nmask, byte strict_mask,
225                            char *FWHM_mixmode, float **fwhmrecord);
226 SUMA_Boolean SUMA_WriteSmoothingRecord (  SUMA_SurfaceObject *SO,
227                                           float *fwhmg, int Niter,
228                                           double *sigma, int cnst_sig,
229                                           char *prefix);
230 SUMA_Boolean  SUMA_Taubin_Smooth_TransferFunc (float l, float m, int N, FILE *Out);
231 SUMA_Boolean SUMA_Taubin_Smooth_Coef (float k, float *l, float *m);
232 void SUMA_Set_Taubin_Weights(SUMA_TAUBIN_SMOOTH_OPTIONS tb);
233 byte SUMA_Get_Taubin_Weights(void);
234 void SUMA_Set_SurfSmooth_NodeDebug(int n);
235 float ** SUMA_Taubin_Desbrun_Smooth_Weights (SUMA_SurfaceObject *SO, float *NewNodeList, float ***UseThisWeight);
236 float ** SUMA_Taubin_Fujiwara_Smooth_Weights (SUMA_SurfaceObject *SO, float *NewNodeList, float ***UseThisWeight);
237 float * SUMA_Taubin_Smooth (SUMA_SurfaceObject *SO, float **wgt,
238                             float lambda, float mu, float *fin,
239                             int N_iter, int vpn, SUMA_INDEXING_ORDER d_order,
240                             float *fout_user, SUMA_COMM_STRUCT *cs,
241                             byte *nmask, byte strict_mask);
242 int SUMA_Taubin_Smooth_SO(  SUMA_SurfaceObject *SO,
243                             SUMA_TAUBIN_SMOOTH_OPTIONS smopt,
244                             float kpb, byte *mask, byte strict_mask,
245                             int Niter);
246 int SUMA_NN_Smooth_SO(   SUMA_SurfaceObject *SO,
247                          byte *mask, byte strict_mask,
248                          int Niter);
249 int SUMA_NN_GeomSmooth_SO(   SUMA_SurfaceObject *SO,
250                          byte *nmask, byte strict_mask,
251                          int Niter);
252 int SUMA_NN_GeomSmooth2_SO(   SUMA_SurfaceObject *SO,
253                          byte *nmask, byte strict_mask,
254                          int Niter, int anchor_each,
255                               SUMA_SurfaceObject *SOe,
256                          float *anchor_loc, float *anchor_wght);
257 int SUMA_NN_GeomSmooth3_SO(   SUMA_SurfaceObject *SO,
258                          byte *nmask, byte strict_mask,
259                          int Niter, int anchor_each,
260                          SUMA_SurfaceObject *SOe,
261                          float *anchor_wght, THD_3dim_dataset *voxelize,
262                          SUMA_COMM_STRUCT *cs);
263 SUMA_Boolean SUMA_ApplyAffine (float *NodeList, int N_Node, float M[][4],
264                                float *center);
265 float *SUMA_NN_GeomSmooth( SUMA_SurfaceObject *SO, int Niter, float *fin_orig,
266                            int vpn, SUMA_INDEXING_ORDER d_order,
267                            float *fout_final_user,
268                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
269 float *SUMA_NN_GeomSmooth2( SUMA_SurfaceObject *SO, int N_iter, float *fin_orig,
270                            int vpn, SUMA_INDEXING_ORDER d_order,
271                            float *fout_final_user,
272                            SUMA_COMM_STRUCT *cs, byte *nmask, int MaskEnforce,
273                            SUMA_SurfaceObject *SOe,
274                            float *anchor_loc, float *anchor_wght);
275 float *SUMA_NN_GeomSmooth3( SUMA_SurfaceObject *SO, int N_iter, float *fin_orig,
276                            int vpn, SUMA_INDEXING_ORDER d_order,
277                            float *fout_final_user,
278                            SUMA_COMM_STRUCT *cs, byte *nmask, int MaskEnforce,
279                            SUMA_SurfaceObject *SOe,
280                            float *anchor_wght, THD_3dim_dataset *voxelize);
281 SUMA_Boolean SUMA_EquateSurfaceSize(SUMA_SurfaceObject *SO,
282                SUMA_SurfaceObject *SOref, float max_off, SUMA_COMM_STRUCT *cs);
283 SUMA_Boolean SUMA_EquateSurfaceVolumes(SUMA_SurfaceObject *SO,
284                SUMA_SurfaceObject *SOref, float perc_tol, SUMA_COMM_STRUCT *cs);
285 SUMA_Boolean SUMA_EquateSurfaceCenters (SUMA_SurfaceObject *SO,
286                                         SUMA_SurfaceObject *SOref,
287                                         int recompute);
288 SUMA_Boolean SUMA_EquateSurfaceAreas(SUMA_SurfaceObject *SO,
289                SUMA_SurfaceObject *SOref, float perc_tol, SUMA_COMM_STRUCT *cs);
290 double SUMA_Mesh_Volume(SUMA_SurfaceObject *SO, int *FSI, int N_FaceSet,
291                         int verb, int *prec_prob) ;
292 double SUMA_Mesh_Area(SUMA_SurfaceObject *SO, int *FSI, int N_FaceSet) ;
293 double SUMA_Pattie_Volume (SUMA_SurfaceObject *SO1, SUMA_SurfaceObject *SO2,
294                            int *Nodes, int N_Node,
295                            SUMA_SurfaceObject *UseThisSO,
296                            int minhits, int FixBowTie, int adjust_contour,
297                            byte *adj_N, int verb);
298 double SUMA_NewAreaAtRadius(SUMA_SurfaceObject *SO, double r, double Rref,
299                             float *tmpList);
300 SUMA_Boolean SUMA_ProjectSurfaceToSphere(SUMA_SurfaceObject *SO, SUMA_SurfaceObject *SOref, float radius, SUMA_COMM_STRUCT *cs);
301 SUMA_OFFSET_STRUCT *SUMA_FormNeighbOffset ( SUMA_SurfaceObject *SO, float OffsetLim, const char *opts, byte *nmask, float FWHM);
302 SUMA_OFFSET_STRUCT * SUMA_free_NeighbOffset (SUMA_SurfaceObject *SO, SUMA_OFFSET_STRUCT *OffS_out);
303 float *SUMA_Offset_GeomSmooth( SUMA_SurfaceObject *SO, int N_iter,
304                                float Offestlim, float *fin_orig,
305                                int vpn, SUMA_INDEXING_ORDER d_order,
306                                float *fout_final_user,
307                                SUMA_COMM_STRUCT *cs);
308 byte *SUMA_GetOffset2bytemask (SUMA_GET_OFFSET_STRUCT *GOS, byte *thismask);
309 SUMA_Boolean SUMA_GetOffset2Offset (SUMA_GET_OFFSET_STRUCT *GOS,
310                                     SUMA_OFFSET_STRUCT *OS);
311 char * SUMA_ShowOffset_ll_Info (DList *list, int detail);
312 char * SUMA_ShowOffset_Info (SUMA_GET_OFFSET_STRUCT *OffS, int detail);
313 SUMA_Boolean SUMA_FixNN_Oversampling ( SUMA_SurfaceObject *SO, SUMA_DSET *dset,
314                                        byte *nmask,
315                                        int icol, SUMA_Boolean MaskZeros);
316 
317 /* Begin function prototypes for VolData.c */
318 THD_fvec3 SUMA_THD_3dfind_to_3dmm( SUMA_SurfaceObject *SO, THD_fvec3 iv );
319 THD_fvec3 SUMA_THD_3dfind_to_3dmm_vp( SUMA_VOLPAR *vp, THD_fvec3 iv );
320 THD_fvec3 SUMA_THD_3dind_to_3dmm( SUMA_SurfaceObject *SO, THD_ivec3 iv );
321 THD_fvec3 SUMA_THD_3dmm_to_3dfind( SUMA_SurfaceObject *SO , THD_fvec3 fv );
322 THD_ivec3 SUMA_THD_3dmm_to_3dind( SUMA_SurfaceObject *SO  , THD_fvec3 fv );
323 THD_ivec3 SUMA_THD_3dmm_to_3dind_warn( SUMA_SurfaceObject *SO  ,
324                                        THD_fvec3 fv, int *out );
325 THD_fvec3 SUMA_THD_3dmm_to_dicomm( int xxorient, int yyorient, int zzorient ,
326                                     THD_fvec3 imv );
327 THD_fvec3 SUMA_THD_dicomm_to_3dmm( int xxorient, int yyorient, int zzorient ,
328                                     THD_fvec3 dicv );
329 void SUMA_orcode_to_orstring (int xxorient, int yyorient, int zzorient,
330                               char *orstr);
331 void SUMA_sizeto3d_2_deltaHEAD(THD_ivec3 orient, THD_fvec3 *delta);
332 void SUMA_originto3d_2_originHEAD(THD_ivec3 orient, THD_fvec3 *origin);
333 SUMA_Boolean SUMA_vec_3dfind_to_3dmm (float *NodeList, int N_Node,
334                                        SUMA_VOLPAR *VolPar);
335 SUMA_Boolean SUMA_vec_3dmm_to_3dfind (float *NodeList, int N_Node,
336                                        SUMA_VOLPAR *VolPar);
337 SUMA_Boolean SUMA_vec_dicomm_to_3dfind (float *NodeList, int N_Node,
338                                        SUMA_VOLPAR *VolPar);
339 SUMA_Boolean SUMA_vec_3dfind_to_dicomm (float *NodeList, int N_Node,
340                                        SUMA_VOLPAR *VolPar);
341 SUMA_Boolean SUMA_vec_3dmm_to_dicomm (float *NodeList, int N_Node,
342                                        SUMA_VOLPAR *VolPar);
343 SUMA_Boolean SUMA_vec_dicomm_to_3dmm (float *NodeList, int N_Node,
344                                        SUMA_VOLPAR *VolPar);
345 SUMA_Boolean SUMA_THD_3dfind_to_dicomm(THD_3dim_dataset *dset,
346                                        float ii, float jj, float kk,
347                                        float *xyz);
348 SUMA_Boolean SUMA_THD_dicomm_to_3dfind(THD_3dim_dataset *dset,
349                                        float RR, float AA, float II,
350                                        float *ijk) ;
351 int SUMA_THD_dicomm_to_1dind(THD_3dim_dataset *dset,
352                               float RR, float AA, float II,
353                               int *ijk);
354 SUMA_Boolean SUMA_CoordChange (char *orc_in, char *orc_out,
355                                float *XYZ, int N_xyz);
356 int SUMA_flip_orient(int xxorient);
357 int SUMA_ok_orstring (char *orstr);
358 SUMA_Boolean SUMA_orstring_to_orcode (char *orstr, int *orient);
359 int SUMA_Subdivide_Mesh(float **NodeListp, int *N_Node, int **FaceSetListp,
360                         int *N_FaceSet, float maxarea);
361 SUMA_SurfaceObject *SUMA_MergeSurfs(SUMA_SurfaceObject **SOv, int N_SOv);
362 SUMA_Boolean SUMA_FlipTriangles (int *FaceSetList,int N_FaceSet);
363 SUMA_Boolean SUMA_FlipSOTriangles(SUMA_SurfaceObject *SO);
364 int SUMA_OrientTriangles (float *NodeList, int N_Node,
365                           int *FaceSetList, int N_FaceSet,
366                           int orient, int Force, float *c,
367                           byte *fliphappened);
368 int SUMA_OrientSOTriangles(SUMA_SurfaceObject *SO,
369                            int orient, int Force,
370                            float *cu);
371 SUMA_Boolean SUMA_Offset_Smooth_dset( SUMA_SurfaceObject *SO,
372                            float FWHM, float OffsetLim,
373                            int N_iter,
374                            SUMA_DSET *dset,
375                            SUMA_COMM_STRUCT *cs, byte *nmask, byte strict_mask);
376 float SUMA_estimate_FWHM_1dif( SUMA_SurfaceObject *SO, float *fim , byte *nmask, int nodup );
377 float *SUMA_estimate_dset_FWHM_1dif(SUMA_SurfaceObject *SO, SUMA_DSET *dset,
378                                     int *icols, int N_icols, byte *nmask,
379                                     int nodup, char *options);
380 float SUMA_estimate_slice_FWHM_1dif( SUMA_SurfaceObject *SO, float *fim , byte *nmask, int nodup, float *ssvr, DList **striplist_vec);
381 void SUMA_Set_UseSliceFWHM(int v);
382 int SUMA_Get_UseSliceFWHM(void);
383 SUMA_Boolean SUMA_NewSurfaceRadius(SUMA_SurfaceObject *SO, double r, float *Center);
384 void SUMA_SetDbgFWHM(int i);
385 int SUMA_GetDbgFWHM(void);
386 SUMA_Boolean SUMA_CenterOfSphere(double *p1, double *p2, double *p3, double *p4, double *c);
387 SUMA_Boolean SUMA_GetCenterOfSphereSurface(SUMA_SurfaceObject *SO, int Nquads, double *cs, double *cm);
388 float *SUMA_SegmentDistortion (SUMA_SurfaceObject *SO1, SUMA_SurfaceObject *SO2);
389 int SUMA_ApproxNeighbors ( SUMA_SurfaceObject *SO,
390                            SUMA_SurfaceObject *SOf,  /* the spherical (or someday flat) version of SO */
391                            int cent,      /* the central node*/
392                            float dnei,     /* the search distance, along the surface from node cent */
393                            byte *nmask     /* to contain the nodes within rad from Cent */);
394 
395 /* End function prototypes for VolData.c */
396 
397 /* Begin function prototypes for SUMA_ConvexHull.c */
398 int SUMA_qhull_wrap( int npt , float * xyz , int ** ijk ,
399                      int fliporient, char *opt);
400 int SUMA_qdelaunay_wrap( int npt , float * xyz , int ** ijk ,
401                      int fliporient, char *opt);
402 int SUMA_q_wrap( int npt , float * xyz , int ** ijk , int fliporient,
403                  char *qprog, char *qopt, int dim);
404 /* End function prototypes for SUMA_ConvexHull.c */
405 
406 DList *SUMA_SliceAlongPlane(SUMA_SurfaceObject *SO, float *Eq, float step);
407 
408 SUMA_DSET *SUMA_RandomDset(int N_Node, int nc, unsigned int seed,
409                            float scale, byte norm);
410 
411 SUMA_Boolean SUMA_FillRandXform(double xform[][4], int seed, int type);
412 SUMA_Boolean SUMA_FillScaleXform(double xform[][4], double sc[3]);
413 SUMA_Boolean SUMA_FillXYnegXform(double xform[][4]);
414 SUMA_Boolean SUMA_Write_PC_XYZ_Proj(SUMA_PC_XYZ_PROJ *pcp, char *prefix);
415 SUMA_PC_XYZ_PROJ *SUMA_Free_PC_XYZ_Proj(SUMA_PC_XYZ_PROJ *pcp);
416 SUMA_PC_XYZ_PROJ *SUMA_New_PC_XYZ_Proj(void);
417 
418 SUMA_PC_XYZ_PROJ *SUMA_Project_Coords_PCA (float *xyz, int N_xyz, int iref,
419                                 float *xyzref,
420                                 SUMA_PC_PROJ compnum, SUMA_PC_ROT rotate,
421                                 int remean);
422 SUMA_Boolean SUMA_WriteNodeDepth(char *prefix, SUMA_PC_XYZ_PROJ *pcp,
423                                  float *dpth, float mx);
424 int SUMA_NodeDepth(float *NodeList, int N_Node, SUMA_PC_PROJ prjdir,
425                    float **dpth,
426                    float thr, byte **cmaskp, float *mxdpth,
427                    SUMA_PC_XYZ_PROJ **pcpu);
428 int SUMA_VoxelDepth(THD_3dim_dataset *dset, SUMA_PC_PROJ prjdir, float **dpth,
429                     float thr, byte **cmaskp, int applymask);
430 int SUMA_VoxelDepth_Z(THD_3dim_dataset *dset, byte *cmasku,
431                      float **dpth,
432                      float thr, byte **cmaskp, int applymask,
433                      float peakperc, float *ztop);
434 int SUMA_VoxelPlaneCut(THD_3dim_dataset *dset, float *Eq,
435                        byte **cmaskp, int applymask);
436 int SUMA_is_Flat_Surf_Coords_PCA (float *xyz, int N_xyz,
437                                   float tol, float sampfrac);
438 int SUMA_is_Constant_Z_Coord(float *NodeList, int N_Node, float tol);
439 int SUMA_PlaneBoxIntersect(float *cam, float *PlEq,
440                             float *cvert, float p[18]);
441 int SUMA_PlaneBoxSlice( float *cam, float *PlEq,
442                                  float *cvert,
443                                  float *pv, int *hits, float *PlOff, int N_slc);
444 int SUMA_TractMaskIntersect(SUMA_TractDO *TDO, SUMA_MaskDO *MDO, byte **IsInp);
445 int SUMA_TractMasksIntersect(SUMA_TractDO *TDO, char *expr);
446 
447 /*!
448    Macros to merge / join two lists together
449    elements of lst2 are set to NULL and you should free lst2
450    when these macros are done.
451 */
452 #define SUMA_MergeLists_Beg2_End1(lst2,lst1){  \
453    DListElmt *m_elm = NULL;   \
454    if (dlist_size(lst2)){  \
455       do{   \
456          if (!m_elm) m_elm = dlist_head(lst2);   \
457          else m_elm = dlist_next(m_elm);   \
458          dlist_ins_next(lst1, dlist_tail(lst1), m_elm->data);   m_elm->data = NULL; /* protect element from erasure */\
459       } while (m_elm != dlist_tail(lst2));  \
460    }  \
461 }
462 #define SUMA_MergeLists_End2_End1(lst2, lst1) {   \
463    DListElmt *m_elm = NULL;   \
464    if (dlist_size(lst2)){  \
465       do{   \
466          if (!m_elm) m_elm = dlist_tail(lst2);   \
467          else m_elm = dlist_prev(m_elm);   \
468          dlist_ins_next(lst1, dlist_tail(lst1), m_elm->data);   m_elm->data = NULL; /* protect element from erasure */\
469      } while (m_elm != dlist_head(lst2));  \
470    }  \
471 }
472 
473 #define SUMA_MergeLists_End2_Beg1(lst2, lst1) {   \
474    DListElmt *m_elm = NULL;   \
475    if (dlist_size(lst2)){  \
476       do{   \
477          if (!m_elm) m_elm = dlist_tail(lst2);   \
478          else m_elm = dlist_prev(m_elm);   \
479          dlist_ins_prev(lst1, dlist_head(lst1), m_elm->data);   m_elm->data = NULL; /* protect element from erasure */\
480       } while (m_elm != dlist_head(lst2));     \
481    }\
482 }
483 #define SUMA_MergeLists_Beg2_Beg1(lst2, lst1){ \
484    DListElmt *m_elm=NULL;  \
485    if (dlist_size(lst2)) { \
486       do{   \
487          if (!m_elm) m_elm = dlist_head(lst2);   \
488          else m_elm = dlist_next(m_elm);   \
489          dlist_ins_prev(lst1, dlist_head(lst1), m_elm->data);   m_elm->data = NULL; /* protect element from erasure */\
490       } while (m_elm != dlist_tail(lst2));  \
491    }  \
492 }
493 
494 
495 #endif
496 
497 
498 
499 
500 
501 
502