37 #ifndef AIMS_MESH_TEX2GRAPH_D_H 38 #define AIMS_MESH_TEX2GRAPH_D_H 65 return label2index[label];
73 std::set<std::set<short> > all_lab;
74 std::set<std::set<short> >::iterator bl,fl;
75 int inc = 0, n = tex.nItem();
77 for(
int i=0; i<n; ++i )
78 all_lab.insert( tex.item(i) );
80 for (bl=all_lab.begin(), fl=all_lab.end(); bl != fl; ++bl,++inc)
81 label2index[*bl] = inc;
87 const std::map<T,std::string> & lab2name,
float epsilon )
91 std::map<T,Vertex*> nodeLabels;
92 typename std::map<T,std::set<unsigned> >::iterator il,el;
93 std::map<T,std::set<unsigned> > triLabels;
94 std::set<unsigned>::iterator it,et;
96 const std::vector< AimsVector<uint, 3 > > & initpoly = initmesh.polygon();
97 unsigned n = tex.
nItem(), i, m = initpoly.size();
98 typename std::map <T,std::string>::const_iterator iname,ename = lab2name.end();
100 if ( n != initmesh.vertex().size() )
101 throw std::logic_error(
"Mesh and texture must have the same size");
105 std::vector<Point3df> &vert = mesh.vertex();
106 std::vector<Point3df> &normal = mesh.normal();
107 std::vector< AimsVector<uint, 3 > > &poly = mesh.polygon();
111 vert[i][0] = vert[i][0] + epsilon * normal[i][0];
112 vert[i][1] = vert[i][1] + epsilon * normal[i][1];
113 vert[i][2] = vert[i][2] + epsilon * normal[i][2];
116 std::vector<float> vs;
120 g.setProperty(
"voxel_size", vs );
121 g.setProperty(
"filename_base",
"*" );
123 std::vector<int> bbmin(3), bbmax(3);
126 typename std::set<T>::iterator bl,fl;
128 fillLabel2index(tex);
134 if ( nodeLabels.find( lab ) == nodeLabels.end() )
138 v->setProperty(
"roi_label", getIndex(lab) );
139 iname = lab2name.find(lab);
142 name = iname->second ;
143 v->setProperty(
"name", name );
147 std::cerr <<
"Cannot translate a label " << std::endl ;
148 v->setProperty(
"name", (std::string)
"unknown" );
154 const Point3df & pt = mesh.vertex()[i];
157 bbmin[0] = bbmax[0] = (int) rint( pt[0] );
158 bbmin[1] = bbmax[1] = (int) rint( pt[1] );
159 bbmin[2] = bbmax[2] = (int) rint( pt[2] );
164 if( pt[0] < bbmin[0] )
165 bbmin[0] = (int) rint( pt[0] );
166 if( pt[1] < bbmin[1] )
167 bbmin[1] = (int) rint( pt[1] );
168 if( pt[2] < bbmin[2] )
169 bbmin[2] = (int) rint( pt[2] );
170 if( pt[0] > bbmax[0] )
171 bbmax[0] = (int) rint( pt[0] );
172 if( pt[1] > bbmax[1] )
173 bbmax[1] = (int) rint( pt[1] );
174 if( pt[2] > bbmax[2] )
175 bbmax[2] = (int) rint( pt[2] );
179 g.setProperty(
"boundingbox_min", bbmin );
180 g.setProperty(
"boundingbox_max", bbmax );
183 for ( i=0; i<m; ++i )
185 if ( tex.
item(poly[i][0]) == tex.
item(poly[i][1]) &&
186 tex.
item(poly[i][2]) == tex.
item(poly[i][1]) )
187 triLabels[tex.
item(poly[i][0])].insert(i);
190 for ( il = triLabels.begin(), el = triLabels.end(); il != el; ++il )
193 std::map<uint,uint> conversion;
194 std::map<uint,uint>::iterator ic;
199 for (it = il->second.begin(), et = il->second.end(); it != et; ++it)
202 if ( (ic=conversion.find( tri[0] )) == conversion.end() )
204 conversion[tri[0] ] = ind;
207 surface->vertex().push_back(mesh.vertex()[tri[0] ] );
212 if ( (ic=conversion.find(tri[1] )) == conversion.end() )
214 conversion[tri[1] ] = ind;
217 surface->vertex().push_back(mesh.vertex()[tri[1] ] );
222 if ( (ic=conversion.find( tri[2] )) == conversion.end() )
224 conversion[ tri[2] ] = ind;
227 surface->vertex().push_back(mesh.vertex()[tri[2] ] );
234 v = nodeLabels[il->first];
235 surface->updateNormals();
237 v->setProperty(
"aims_Tmtktri",surface);
248 std::map<T,Vertex*> nodeLabels;
249 typename std::map<T,std::set<unsigned> >::iterator il,el;
250 std::map<T,std::set<unsigned> > triLabels;
251 std::set<unsigned>::iterator it,et;
253 const std::vector< AimsVector<uint, 3 > > & initpoly = initmesh.polygon();
254 unsigned n = tex.
nItem(), i, m = initpoly.size();
256 if ( n != initmesh.vertex().size() )
257 throw std::logic_error(
"Mesh and texture must have the same size");
260 std::vector<Point3df> &vert = mesh.vertex() ;
261 std::vector<Point3df> &normal = mesh.normal();
262 std::vector< AimsVector<uint, 3 > > &poly = mesh.polygon();
266 vert[i][0] = vert[i][0] + epsilon * normal[i][0];
267 vert[i][1] = vert[i][1] + epsilon * normal[i][1];
268 vert[i][2] = vert[i][2] + epsilon * normal[i][2];
271 std::vector<float> vs;
275 g.setProperty(
"voxel_size", vs );
276 g.setProperty(
"filename_base",
"*" );
278 std::vector<int> bbmin(3), bbmax(3);
282 fillLabel2index(tex);
288 if ( nodeLabels.find( lab ) == nodeLabels.end() )
291 v->setProperty(
"roi_label", getIndex(lab) );
292 sprintf( name,
"%d", getIndex(lab) );
293 v->setProperty(
"name",
"label_"+std::string( name ) );
296 const Point3df & pt = mesh.vertex()[i];
299 bbmin[0] = bbmax[0] = (int) rint( pt[0] );
300 bbmin[1] = bbmax[1] = (int) rint( pt[1] );
301 bbmin[2] = bbmax[2] = (int) rint( pt[2] );
306 if( pt[0] < bbmin[0] )
307 bbmin[0] = (int) rint( pt[0] );
308 if( pt[1] < bbmin[1] )
309 bbmin[1] = (int) rint( pt[1] );
310 if( pt[2] < bbmin[2] )
311 bbmin[2] = (int) rint( pt[2] );
312 if( pt[0] > bbmax[0] )
313 bbmax[0] = (int) rint( pt[0] );
314 if( pt[1] > bbmax[1] )
315 bbmax[1] = (int) rint( pt[1] );
316 if( pt[2] > bbmax[2] )
317 bbmax[2] = (int) rint( pt[2] );
321 g.setProperty(
"boundingbox_min", bbmin );
322 g.setProperty(
"boundingbox_max", bbmax );
324 for ( i=0; i<m; ++i )
326 if ( tex.
item(poly[i][0]) == tex.
item(poly[i][1]) &&
327 tex.
item(poly[i][2]) == tex.
item(poly[i][1]) )
328 triLabels[tex.
item(poly[i][0])].insert(i);
331 for ( il = triLabels.begin(), el = triLabels.end(); il != el; ++il )
334 std::map<uint,uint> conversion;
335 std::map<uint,uint>::iterator ic;
338 for (it = il->second.begin(), et = il->second.end(); it != et; ++it)
341 if ( (ic=conversion.find( tri[0] )) == conversion.end() )
343 conversion[tri[0] ] = ind;
346 surface->vertex().push_back(mesh.vertex()[tri[0] ] );
347 surface->normal().push_back(mesh.normal()[tri[0] ] );
352 if ( (ic=conversion.find(tri[1] )) == conversion.end() )
354 conversion[tri[1] ] = ind;
357 surface->vertex().push_back(mesh.vertex()[tri[1] ] );
358 surface->normal().push_back(mesh.normal()[tri[1] ] );
363 if ( (ic=conversion.find( tri[2] )) == conversion.end() )
365 conversion[ tri[2] ] = ind;
368 surface->vertex().push_back(mesh.vertex()[tri[2] ] );
369 surface->normal().push_back(mesh.normal()[tri[2] ] );
374 v = nodeLabels[il->first];
375 v->setProperty(
"aims_Tmtktri",surface);
380 objmap(
new std::map<std::string,std::map<std::string,GraphElementCode> > );
391 g.setProperty(
"aims_objects_table",objmap);
Vertex * addVertex(const std::string &s="")
std::string local_file_attribute
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle
std::string syntax
syntactic attribute of attributed objects
const T & item(int n) const
std::string dataType
data type as in Aims Finder: "S16", "U8", "FLOAT", ...
Describe how Aims objects are stored in graph objects.
std::string global_index_attribute
The class for EcatSino data write operation.
std::string attribute
attribute found in graph objects, this attribute is a reference-counting pointer (carto::rc_ptr<T>) t...
void fillLabel2index(const Texture< T > &)
void makeGraph(Graph &g, const AimsSurfaceTriangle &mesh, const Texture< T > &tex, float epsilon=0.01)
Fills graph g from texture of labels tex on the mesh mesh.
int getIndex(const T &label)
std::string objectType
object type as in aims Finder: "Volume", "Bucket", "Mesh", ...
std::string id
ID for object: filename (globals) or attribute for filename (locals)
std::string global_filename
static void storeAims(Graph &graph, GraphObject *vertex, const std::string &attribute, carto::rc_ptr< T > obj)
This template function stores the given object in the given Vertex / Edge of the graph and takes care...