Doxygen Source Code Documentation
SUMA_gts.h File Reference
#include "gts.h"
#include "gts-private.h"
#include "SUMA_suma.h"
Go to the source code of this file.
Defines | |
#define | GTS_OUT(fname, s) |
#define | GTS_VTK_OUT(fname, s) |
Functions | |
void | gts_surface_suma (GtsSurface *s, float **NodeListp, int *N_Nodep, int *NodeDimp, int **FaceSetListp, int *N_FaceSetp, int *FaceSetDimp) |
GtsSurface * | SumaToGts (SUMA_SurfaceObject *SO) |
void | coarsen (GtsSurface *s, int stop) |
void | refine (GtsSurface *s, int stop) |
SUMA_SurfaceObject * | SUMA_Mesh_Resample (SUMA_SurfaceObject *SO, float edge_factor) |
resample a mesh so that the resultant surface has edge_factor as many edges as the original one |
Define Documentation
|
Value: {\ FILE *m_fp = fopen(fname, "w"); \ if (!m_fp) { SUMA_S_Err("Failed to write GTS surface"); } \ else { gts_surface_write(s, m_fp); fclose(m_fp); m_fp = NULL; } \ } Definition at line 27 of file SUMA_gts.h. Referenced by SUMA_Mesh_Resample(). |
|
Value: {\ FILE *m_fp = fopen(fname, "w"); \ if (!m_fp) { SUMA_S_Err("Failed to write VTK surface"); } \ else { gts_surface_write_vtk(s, m_fp); fclose(m_fp); m_fp = NULL; } \ } Definition at line 32 of file SUMA_gts.h. Referenced by SUMA_Mesh_Resample(). |
Function Documentation
|
coarsens with set parameters Definition at line 258 of file SUMA_gts.c. References fold(). Referenced by SUMA_Mesh_Resample().
00259 { 00260 GtsVolumeOptimizedParams params = { 0.5, 0.5, 0. }; 00261 gdouble fold = PI/180.; 00262 gts_surface_coarsen (s, 00263 (GtsKeyFunc) gts_volume_optimized_cost, 00264 ¶ms, 00265 (GtsCoarsenFunc) gts_volume_optimized_vertex, 00266 ¶ms, 00267 (GtsStopFunc) gts_coarsen_stop_number, 00268 &stop, 00269 fold); 00270 } |
|
Definition at line 42 of file SUMA_gts_insert.c. References calloc, face_load(), and vertex_load(). Referenced by SUMA_Mesh_Resample().
00045 { 00046 guint n = 0; 00047 gpointer data[2]; 00048 GtsSurfaceStats stats; 00049 float *NodeList = NULL; 00050 int *FaceSetList = NULL; 00051 00052 g_return_if_fail (s != NULL); 00053 00054 00055 00056 gts_surface_stats (s, &stats); 00057 00058 /* get the stats */ 00059 fprintf (stderr, 00060 "gts_surface_suma: Number of vertices %u\n", 00061 stats.edges_per_vertex.n); 00062 fprintf (stderr, 00063 "gts_surface_suma: Number of triangles %u\n", 00064 stats.n_faces); 00065 NodeList = (float *)calloc( stats.edges_per_vertex.n * 3, sizeof(float)); 00066 FaceSetList = (int *)calloc(stats.n_faces * 3, sizeof(int)); 00067 00068 if (!NodeList || !FaceSetList) { 00069 fprintf(stderr,"Critical Error gts_surface_suma: Could not allocate.\n"); 00070 g_return_if_fail (0); 00071 } 00072 00073 /* get the nodes */ 00074 n = 0; 00075 data[0] = (gpointer)NodeList; 00076 data[1] = (gpointer)&n; 00077 gts_surface_foreach_vertex (s, (GtsFunc) vertex_load, data); 00078 00079 /* get the facesets */ 00080 n = 0; 00081 data[0] = (gpointer)FaceSetList; 00082 data[1] = (gpointer)&n; 00083 gts_surface_foreach_face (s, (GtsFunc) face_load , data); 00084 00085 /* don't know what these two are for, 00086 assuming it has to do with the ->reserved business in vertex_load and face_load above */ 00087 gts_surface_foreach_vertex (s, (GtsFunc) gts_object_reset_reserved, NULL); 00088 gts_surface_foreach_face (s, (GtsFunc) gts_object_reset_reserved, NULL); 00089 00090 /* set results */ 00091 *N_FaceSetp = (int)stats.n_faces; 00092 *N_Nodep = (int)stats.edges_per_vertex.n; 00093 *NodeListp = NodeList; 00094 *FaceSetListp = FaceSetList; 00095 *NodeDimp = 3; 00096 *FaceSetDimp = 3; 00097 return; 00098 } |
|
coarsens with set parameters Definition at line 279 of file SUMA_gts.c. References stop_number(). Referenced by SUMA_Mesh_Resample().
00280 { 00281 gts_surface_refine(s, NULL, NULL, NULL, NULL, 00282 (GtsStopFunc)stop_number, &stop); 00283 } |
|
resample a mesh so that the resultant surface has edge_factor as many edges as the original one
Definition at line 288 of file SUMA_gts.c. References coarsen(), SUMA_SurfaceObject::EL, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, GTS_OUT, gts_surface_suma(), GTS_VTK_OUT, LocalHead, SUMA_EDGE_LIST::N_Distinct_Edges, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, refine(), SUMA_Alloc_SurfObject_Struct(), SUMA_Boolean, SUMA_ENTRY, SUMA_RETURN, SUMA_S_Err, SUMA_S_Note, SUMA_S_Warn, SUMA_SL_Err, SUMA_SurfaceMetrics(), and SumaToGts(). Referenced by main().
00289 { 00290 static char FuncName[]={"SUMA_Mesh_Resample"}; 00291 SUMA_SurfaceObject *S2=NULL; 00292 GtsSurface* s = NULL; 00293 SUMA_Boolean LocalHead = NOPE; 00294 00295 SUMA_ENTRY; 00296 00297 if (!SO) { 00298 SUMA_SL_Err("NULL SO"); 00299 SUMA_RETURN(S2); 00300 } 00301 if (!SO->EL) { 00302 SUMA_S_Warn("NULL Edge List, computing it"); 00303 if (!SUMA_SurfaceMetrics(SO, "EdgeList", NULL)) { 00304 SUMA_SL_Err("Failed to create EdgeList"); 00305 SUMA_RETURN(S2); 00306 } 00307 } 00308 /* create a GTS surface */ 00309 s = SumaToGts(SO); 00310 if (!s) { 00311 SUMA_S_Err("Failed to change SO to GTS surface"); 00312 SUMA_RETURN(S2); 00313 } 00314 if (LocalHead) { /* see if surface was created well in GTS format */ 00315 SUMA_S_Note("Writing initial surface in GTS form"); 00316 GTS_OUT("gtsout.surf",s); 00317 GTS_VTK_OUT("vtkout.surf",s); 00318 } 00319 00320 /* resample */ 00321 if (1) { 00322 SUMA_S_Note("Changing mesh density\n"); 00323 if (edge_factor < 1) 00324 coarsen(s, SO->EL->N_Distinct_Edges * edge_factor); 00325 else 00326 refine(s, SO->EL->N_Distinct_Edges * edge_factor); 00327 } else { 00328 SUMA_S_Note("Leaving surface untouched\n"); 00329 } 00330 if (!s) { 00331 SUMA_SL_Err("Failed to refine"); 00332 SUMA_RETURN(S2); 00333 } 00334 00335 /* change the surface back to SUMA */ 00336 S2 = SUMA_Alloc_SurfObject_Struct(1); 00337 gts_surface_suma (s, 00338 &(S2->NodeList), &(S2->N_Node), &(S2->NodeDim), 00339 &(S2->FaceSetList), &(S2->N_FaceSet), &(S2->FaceSetDim)); 00340 00341 gts_object_destroy((GtsObject*)s); s = NULL; 00342 00343 SUMA_RETURN(S2); 00344 } |
|
copies suma surface into a gts surface Definition at line 34 of file SUMA_gts.c. References SUMA_EDGE_LIST::EL, SUMA_SurfaceObject::EL, SUMA_EDGE_LIST::ELps, SUMA_SurfaceObject::FaceSetList, i, LocalHead, n1, n2, SUMA_EDGE_LIST::N_Distinct_Edges, SUMA_EDGE_LIST::N_EL, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeList, SUMA_Boolean, SUMA_ENTRY, SUMA_FindEdge(), SUMA_LH, SUMA_Print_Surface_Object(), SUMA_RETURN, SUMA_SL_Err, and v1. Referenced by SUMA_Mesh_Resample().
00035 { 00036 static char FuncName[]={"SumaToGts"}; 00037 GtsSurface* s = NULL; 00038 GtsVertex ** vertices = NULL; 00039 GtsEdge ** edges = NULL; 00040 int i = 0; /*counters */ 00041 int n = 0; 00042 int *MapToGts = NULL; /*used to map EL vector to edge vector*/ 00043 SUMA_Boolean LocalHead = NOPE; 00044 00045 SUMA_ENTRY; 00046 00047 if (!SO->EL) { 00048 SUMA_SL_Err("Null Edgeist!"); 00049 SUMA_RETURN(s); 00050 } 00051 00052 SUMA_LH("In with "); 00053 if (LocalHead) SUMA_Print_Surface_Object(SO, stderr); 00054 00055 s = gts_surface_new( gts_surface_class (), 00056 gts_face_class (), 00057 gts_edge_class (), 00058 gts_vertex_class ()); 00059 vertices = (GtsVertex **)g_malloc (SO->N_Node * sizeof (GtsVertex *)); 00060 n = 0; 00061 for ( i=0; i< SO->N_Node*3; i+=3) 00062 { 00063 vertices[n] = gts_vertex_new( s->vertex_class, 00064 (gdouble)SO->NodeList[i], 00065 (gdouble)SO->NodeList[i+1], 00066 (gdouble)SO->NodeList[i+2]); 00067 if (LocalHead) 00068 fprintf(SUMA_STDERR, "Added vertex (%d/%d)%f %f %f\n" 00069 "Stored gts (fails for some reason, but surface is OK) %f %f %f\n" 00070 , n, SO->N_Node-1, SO->NodeList[i], SO->NodeList[i+1], SO->NodeList[i+2] 00071 , (float)(vertices[n]->p.x), (float)(vertices[n]->p.y), (float)(vertices[n]->p.z)); 00072 ++n; 00073 } 00074 edges = (GtsEdge**)g_malloc (SO->EL->N_Distinct_Edges * sizeof (GtsEdge*)); 00075 n = 0; 00076 MapToGts = (int *)g_malloc ( SO->EL->N_EL * sizeof(int)); 00077 for ( i=0; i< SO->EL->N_EL; i++) 00078 { 00079 if (SO->EL->ELps[i][2] > 0) 00080 { /* a unique edge*/ 00081 GtsVertex* v1 = vertices[SO->EL->EL[i][0]]; 00082 GtsVertex* v2 = vertices[SO->EL->EL[i][1]]; 00083 if (SO->EL->ELps[i][0] == 1) { 00084 edges[n++] = gts_edge_new ( s->edge_class, v2, v1 ); 00085 if (LocalHead) fprintf(SUMA_STDERR,"Added edge of vertices: %d %d \n", SO->EL->EL[i][1], SO->EL->EL[i][0]); 00086 } else { 00087 edges[n++] = gts_edge_new ( s->edge_class, v1, v2 ); 00088 if (LocalHead) fprintf(SUMA_STDERR,"Added edge of nodes: %d %d \n", SO->EL->EL[i][0], SO->EL->EL[i][1]); 00089 } 00090 } 00091 MapToGts[i] = n-1; /* n-1 bc n was just incremented */ 00092 if (LocalHead) fprintf(SUMA_STDERR,"SUMA edge %d is mapped to GTS edge %d\n", i, n-1); 00093 } 00094 00095 if (n != SO->EL->N_Distinct_Edges) 00096 { 00097 fprintf(SUMA_STDERR, "distinct edges didn't equal N_Distinct_Edges"); 00098 exit(1); 00099 } 00100 /* this loop isn't working, stupid tri_limb 00101 for ( i=0; i< SO->N_FaceSet; i++) 00102 { 00103 gts_surface_add_face(s, 00104 gts_face_new ( s->face_class, 00105 edges[MapToGts[SO->EL->Tri_limb[i][0]]], 00106 edges[MapToGts[SO->EL->Tri_limb[i][1]]], 00107 edges[MapToGts[SO->EL->Tri_limb[i][2]]])); 00108 } 00109 */ 00110 for ( i=0; i< SO->N_FaceSet*3; i+=3) 00111 { 00112 int n1 = SO->FaceSetList[i]; 00113 int n2 = SO->FaceSetList[i+1]; 00114 int n3 = SO->FaceSetList[i+2]; 00115 GtsEdge* e1 = edges[MapToGts[SUMA_FindEdge( SO->EL, n1, n2)]]; 00116 GtsEdge* e2 = edges[MapToGts[SUMA_FindEdge( SO->EL, n2, n3)]]; 00117 GtsEdge* e3 = edges[MapToGts[SUMA_FindEdge( SO->EL, n3, n1)]]; 00118 gts_surface_add_face(s, 00119 gts_face_new ( s->face_class, e1, e2, e3)); 00120 if (LocalHead) fprintf(SUMA_STDERR, "Added face of SUMA edges: %d %d %d\n" 00121 " MapToGTS : %d %d %d\n", 00122 SUMA_FindEdge( SO->EL, n1, n2), SUMA_FindEdge( SO->EL, n2, n3), SUMA_FindEdge( SO->EL, n3, n1), 00123 MapToGts[SUMA_FindEdge( SO->EL, n1, n2)], MapToGts[SUMA_FindEdge( SO->EL, n2, n3)], MapToGts[SUMA_FindEdge( SO->EL, n3, n1)]); 00124 } 00125 00126 g_free (vertices); 00127 g_free (edges); 00128 g_free (MapToGts); 00129 SUMA_RETURN( s ); 00130 } |