| 1 |
/* -*- C -*- */ |
| 2 |
// Copyright (C) 2010 Johan Hake |
| 3 |
// Licensed under the GNU LGPL Version 2.1. |
| 4 |
// |
| 5 |
// First added: 2010-08-06 |
| 6 |
// Last changed: 2010-10-06 |
| 7 |
// |
| 8 |
// =========================================================================== |
| 9 |
// SWIG directives for GAMer |
| 10 |
// |
| 11 |
// The directives in this file are applied _after_ the header files has been |
| 12 |
// loaded. |
| 13 |
// =========================================================================== |
| 14 |
|
| 15 |
// Code that will both be verbitim inserted in the header section in the |
| 16 |
// generated wrapper code, but also parsed by SWIG to generate wrapper code |
| 17 |
%inline%{ |
| 18 |
|
| 19 |
static FLTVECT* _Vertex_getitem(SurfaceMesh* surfmesh, unsigned int i){ |
| 20 |
return surfmesh->vertex + i; |
| 21 |
} |
| 22 |
|
| 23 |
static INT3VECT* _Face_getitem(SurfaceMesh* surfmesh, unsigned int i){ |
| 24 |
return surfmesh->face + i; |
| 25 |
} |
| 26 |
|
| 27 |
static void SurfaceMesh_set_vertex_marker(SurfaceMesh* surfmesh, unsigned int i, int value){ |
| 28 |
surfmesh->vertex_markers[i] = value; |
| 29 |
} |
| 30 |
|
| 31 |
static int SurfaceMesh_get_vertex_marker(SurfaceMesh* surfmesh, unsigned int i){ |
| 32 |
return surfmesh->vertex_markers[i]; |
| 33 |
} |
| 34 |
|
| 35 |
static void SurfaceMesh_set_face_marker(SurfaceMesh* surfmesh, unsigned int i, int value){ |
| 36 |
surfmesh->face_markers[i] = value; |
| 37 |
} |
| 38 |
|
| 39 |
static int SurfaceMesh_get_face_marker(SurfaceMesh* surfmesh, unsigned int i){ |
| 40 |
return surfmesh->face_markers[i]; |
| 41 |
} |
| 42 |
|
| 43 |
%} |
| 44 |
|
| 45 |
// Extend both the C and Python interface of SurfaceMesh |
| 46 |
%extend SurfaceMesh { |
| 47 |
|
| 48 |
// Create an empty mesh |
| 49 |
SurfaceMesh(unsigned int num_vertices, unsigned int num_faces) |
| 50 |
{ |
| 51 |
return SurfaceMesh_ctor(num_vertices, num_faces); |
| 52 |
} |
| 53 |
|
| 54 |
// Create a spherical surface mesh |
| 55 |
SurfaceMesh(unsigned int level) |
| 56 |
{ |
| 57 |
return SurfaceMesh_sphere(level); |
| 58 |
} |
| 59 |
|
| 60 |
// Constructor for pdb or off files |
| 61 |
SurfaceMesh(char* filename) |
| 62 |
{ |
| 63 |
char* basename_end_pointer; |
| 64 |
|
| 65 |
// Check if input is a .off file |
| 66 |
basename_end_pointer = strstr(filename, ".off"); |
| 67 |
if (basename_end_pointer != NULL){ |
| 68 |
return SurfaceMesh_readOFF(filename); |
| 69 |
} |
| 70 |
|
| 71 |
// Check if input is a .pdb file |
| 72 |
basename_end_pointer = strstr(filename, ".pdb"); |
| 73 |
if (basename_end_pointer != NULL){ |
| 74 |
return SurfaceMesh_readPDB(filename); |
| 75 |
} |
| 76 |
|
| 77 |
// If neither is correct file format |
| 78 |
printf("Provide a file in either \'.off\' or \'.pdb\' format.\n"); |
| 79 |
exit(1); |
| 80 |
return 0; |
| 81 |
} |
| 82 |
|
| 83 |
// Constructor for LatticeData |
| 84 |
SurfaceMesh(char* segmentation_filename, float isovalue, bool padd) |
| 85 |
{ |
| 86 |
return SurfaceMesh_readLattice(segmentation_filename, isovalue, padd); |
| 87 |
} |
| 88 |
|
| 89 |
// Constructor for LatticeData together with intensity values |
| 90 |
SurfaceMesh(char* segmentation_filename, char* intensity_filename, |
| 91 |
float isovalue, bool padd) |
| 92 |
{ |
| 93 |
return SurfaceMesh_readLattice(segmentation_filename, |
| 94 |
intensity_filename, isovalue, padd); |
| 95 |
} |
| 96 |
|
| 97 |
// Constructor that merges two surface meshes |
| 98 |
SurfaceMesh(SurfaceMesh* in0, SurfaceMesh* in1) |
| 99 |
{ |
| 100 |
return SurfaceMesh_merge(in0, in1); |
| 101 |
} |
| 102 |
|
| 103 |
// Destructor |
| 104 |
~SurfaceMesh() |
| 105 |
{ |
| 106 |
SurfaceMesh_dtor($self); |
| 107 |
} |
| 108 |
|
| 109 |
// Python interface |
| 110 |
%pythoncode %{ |
| 111 |
|
| 112 |
def vertex(self, i): |
| 113 |
"Return the ith vertex" |
| 114 |
if not isinstance(i, int): |
| 115 |
raise TypeError, "expected an int for the index value" |
| 116 |
if i >= self.nv: |
| 117 |
raise IndexError, "index out of range" |
| 118 |
return _Vertex_getitem(self, i) |
| 119 |
|
| 120 |
def face(self, i): |
| 121 |
"Return the ith vertex" |
| 122 |
if not isinstance(i, int): |
| 123 |
raise TypeError, "expected an int for the index value" |
| 124 |
if i >= self.nf: |
| 125 |
raise IndexError, "index out of range" |
| 126 |
return _Face_getitem(self, i) |
| 127 |
|
| 128 |
def refine(self): |
| 129 |
"Refine a surface mesh uniformly" |
| 130 |
SurfaceMesh_refine(self) |
| 131 |
|
| 132 |
def smooth(self, max_min_angle = 15, min_max_angle = 150, |
| 133 |
max_iter = 6, flip_edges = True): |
| 134 |
"Smooth the mesh" |
| 135 |
return SurfaceMesh_smooth(self, max_min_angle, min_max_angle, |
| 136 |
max_iter, flip_edges) |
| 137 |
|
| 138 |
def normal_smooth(self): |
| 139 |
"Smooth the facet normals of the mesh" |
| 140 |
SurfaceMesh_normalSmooth(self) |
| 141 |
|
| 142 |
def correct_normals(self): |
| 143 |
"Correct any normals that might be screwed" |
| 144 |
SurfaceMesh_correctNormals(self) |
| 145 |
|
| 146 |
def write_off(self, filename): |
| 147 |
"Write the mesh to file" |
| 148 |
SurfaceMesh_writeOFF(self, filename) |
| 149 |
|
| 150 |
def coarse_flat(self, rate=0.016): |
| 151 |
"Coarse flat areas" |
| 152 |
SurfaceMesh_coarse(self, rate, 1, 0, -1) |
| 153 |
|
| 154 |
def coarse_dense(self, rate=1.6, numiter=1): |
| 155 |
"Coarse flat areas" |
| 156 |
if not isinstance(rate, (int, float)) or rate <= 0: |
| 157 |
raise TypeError, "expected a positive scalar for the 'rate' argument" |
| 158 |
if not isinstance(numiter, int) or numiter < 1: |
| 159 |
raise TypeError, "expected a positive scalar for the 'numiter' argument" |
| 160 |
for i in xrange(numiter): |
| 161 |
SurfaceMesh_coarse(self, rate, 0, 10, -1) |
| 162 |
|
| 163 |
def get_center_radius(self): |
| 164 |
"Return an ATOM structor of the radius and center of a surface mesh" |
| 165 |
return SurfaceMesh_getCenterRadius(self) |
| 166 |
|
| 167 |
def set_vertex_marker(self, i, value): |
| 168 |
"Sets the ith vertex marker" |
| 169 |
if not isinstance(i, int) or i < 0: |
| 170 |
raise TypeError, "expected a non negative integer for the first argument" |
| 171 |
|
| 172 |
if not isinstance(value, int) or value < 0: |
| 173 |
raise TypeError, "expected a non negative integer for the second argument" |
| 174 |
if i >= self.nvm: |
| 175 |
raise IndexError, "index out of range" |
| 176 |
SurfaceMesh_set_vertex_marker(self, i, value) |
| 177 |
|
| 178 |
def get_vertex_marker(self, i): |
| 179 |
"Return the ith vertex marker" |
| 180 |
if not isinstance(i, int) or i < 0: |
| 181 |
raise TypeError, "expected a non negative integer for the first argument" |
| 182 |
|
| 183 |
if i >= self.nvm: |
| 184 |
raise IndexError, "index out of range" |
| 185 |
return SurfaceMesh_get_vertex_marker(self, i, value) |
| 186 |
|
| 187 |
def set_face_marker(self, i, value): |
| 188 |
"Sets the ith face marker" |
| 189 |
if not isinstance(i, int) or i < 0: |
| 190 |
raise TypeError, "expected a non negative integer for the first argument" |
| 191 |
|
| 192 |
if not isinstance(value, int) or value < 0: |
| 193 |
raise TypeError, "expected a non negative integer for the second argument" |
| 194 |
if i >= self.nfm: |
| 195 |
raise IndexError, "index out of range" |
| 196 |
SurfaceMesh_set_face_marker(self, i, value) |
| 197 |
|
| 198 |
def get_face_marker(self, i): |
| 199 |
"Returns the ith face marker" |
| 200 |
if not isinstance(i, int) or i < 0: |
| 201 |
raise TypeError, "expected a non negative integer for the first argument" |
| 202 |
|
| 203 |
if i >= self.nfm: |
| 204 |
raise IndexError, "index out of range" |
| 205 |
return SurfaceMesh_get_face_marker(self, i, value) |
| 206 |
|
| 207 |
def reset_vertex_markers(self): |
| 208 |
"Resets the vertex markers" |
| 209 |
SurfaceMesh_resetVertexMarkers(self) |
| 210 |
|
| 211 |
def reset_face_markers(self): |
| 212 |
"Resets the face markers" |
| 213 |
SurfaceMesh_resetFaceMarkers(self) |
| 214 |
|
| 215 |
%} |
| 216 |
|
| 217 |
// def getMinMaxAngles(self, max_min_angle=15, min_max_angle=150): |
| 218 |
// """Return angle statistics""" |
| 219 |
// return SurfaceMesh_getMinMaxAngles(max_min_angle, min_max_angle) |
| 220 |
|
| 221 |
} |
| 222 |
|
| 223 |
// Extend both the C and Python interface of GemMesh |
| 224 |
%extend GemMesh { |
| 225 |
|
| 226 |
GemMesh(SurfaceMesh* surfmesh, char* tetgen_quality_params="q1.333") |
| 227 |
{ |
| 228 |
char tetgen_params[20]; |
| 229 |
char default_params[] = "nnepAAY"; |
| 230 |
sprintf(tetgen_params, "%s%s", default_params, tetgen_quality_params); |
| 231 |
return GemMesh_fromSurfaceMesh(surfmesh, tetgen_params); |
| 232 |
} |
| 233 |
|
| 234 |
~GemMesh() |
| 235 |
{ |
| 236 |
GemMesh_dtor($self); |
| 237 |
} |
| 238 |
|
| 239 |
void write_mcsf(char* filename) |
| 240 |
{ |
| 241 |
GemMesh_writeMcsf(self, filename); |
| 242 |
} |
| 243 |
|
| 244 |
void write_off(char* filename) |
| 245 |
{ |
| 246 |
GemMesh_writeOFF(self, filename); |
| 247 |
} |
| 248 |
|
| 249 |
} |