35 #ifndef AIMS_ROI_CLUSTERARG_D_H
36 #define AIMS_ROI_CLUSTERARG_D_H
62 std::string graphsyntax = gr.getSyntax();
63 std::string vertexsyntax =
"cluster";
72 GraphType gtype = Cluster;
84 if( graphsyntax ==
"CorticalFoldArg" )
87 vertexsyntax =
"fold";
115 bec.
syntax = vertexsyntax;
116 mec.
syntax = vertexsyntax;
120 gr.setProperty( graphsyntax +
"_VERSION", std::string(
"1.0" ) );
121 std::vector<float> vs = data->getVoxelSize();
122 gr.setProperty(
"voxel_size", vs );
127 gr.setProperty(
"boundingbox_min", bb );
128 bb[0] = data->getSizeX() - 1;
129 bb[1] = data->getSizeY() - 1;
130 bb[2] = data->getSizeZ() - 1;
131 gr.setProperty(
"boundingbox_max", bb );
132 std::string outdir = _fileout;
133 std::string::size_type pos = outdir.rfind(
'.' );
134 if( pos != std::string::npos )
135 outdir.erase( pos, outdir.length() - pos );
136 pos = outdir.rfind(
'/' );
137 if( pos != std::string::npos )
138 outdir.erase( 0, pos + 1 );
140 gr.setProperty(
"filename_base", outdir );
141 std::vector<int> colors;
142 colors.push_back( 0 );
143 colors.push_back( 255 );
144 colors.push_back( 0 );
150 std::map<std::string,GraphElementCode>
151 & cltab = (*objtable)[ vertexsyntax ];
152 cltab[ bec.
id ] = bec;
155 cltab[ mec.
id ] = mec;
159 gr.setProperty(
"aims_objects_table", objtable );
166 if( _upth != FLT_MAX )
169 if( _lowth != -FLT_MAX )
178 else if( _lowth != -FLT_MAX )
187 if( _lowth == -FLT_MAX )
201 std::cout <<
"threshold: " << _lowth <<
", bin: " << _binarize
204 datat = th.
bin( data );
213 std::cout <<
"extracting connected components...\n";
223 bool bgfound =
false;
225 std::vector<int> dim = datat->
getSize();
227 for( z=0; z<dim[2] && !bgfound; ++z )
228 for( y=0; y<dim[1] && !bgfound; ++y )
229 for( x=0; x<dim[0]; ++x )
230 if( datat( x, y, z ) == 0 )
232 bg = datac( x, y, z );
237 AimsConnectedComponent<short>( datac, _connectivity, bg,
false, _minsize,
239 std::cout <<
"done\n";
244 if( !_matrix.empty() )
246 std::cout <<
"reading transformation...\n";
247 std::ifstream ms( _matrix.c_str() );
250 std::cerr <<
"Can't open transformation file " << _matrix
254 std::vector<float> transl( 3 ), rot( 9 );
255 ms >> transl[0] >> transl[1] >> transl[2];
256 ms >> rot[0] >> rot[1] >> rot[2];
257 ms >> rot[3] >> rot[4] >> rot[5];
258 ms >> rot[6] >> rot[7] >> rot[8];
261 std::cerr <<
"transformation file " << _matrix <<
" has wrong format\n";
264 std::cout <<
"done\n";
277 rm(0, 3) = transl[0];
278 rm(1, 3) = transl[1];
279 rm(2, 3) = transl[2];
285 gr.setProperty(
"Talairach_translation", transl );
286 gr.setProperty(
"Talairach_rotation", rot );
295 std::cout <<
"converting to buckets...\n";
300 std::cout <<
"done, " << bck.size() <<
" buckets\n";
304 std::map<size_t, AimsSurfaceTriangle> mesh;
308 std::cout <<
"meshing components...\n";
309 std::map<size_t, std::list<AimsSurfaceTriangle> > meshl;
311 mesher.
setDecimation( 100.0, _deciMaxClearance, _deciMaxError, 120.0 );
315 mesher.
doit( datac, meshl );
316 std::cout <<
"done\n";
319 std::cout <<
"regrouping meshes...\n";
320 std::map<size_t, std::list<AimsSurfaceTriangle> >
::iterator
321 im, em = meshl.end();
322 for( im=meshl.begin(); im!=em; ++im )
330 std::cout <<
"done\n";
344 std::vector<float> pf(3);
347 std::cout <<
"making cluster vertices...\n";
348 for( ib=bck.begin(); ib!=eb; ++ib )
350 std::cout <<
"cluster " << ib->first <<
"..." << std::endl;
354 (*b)[0] = ib->second;
356 v->setProperty(
"index", (
int) ib->first );
357 pt = ib->second.begin()->first;
358 sprintf( num,
"%d", (
int) datat( pt[0], pt[1], pt[2] ) );
359 v->setProperty(
"name", std::string( num ) );
360 v->setProperty(
"point_number", (
int) ib->second.size() );
361 v->setProperty(
"size", voxvol * ib->second.size() );
364 v->setProperty(
"skeleton_label", index++ );
365 v->setProperty(
"ss_point_number", (
int) ib->second.size() );
366 v->setProperty(
"bottom_point_number", (
int) 0 );
375 pf[0] = pf[1] = pf[2] = 0;
377 for( ibb=bk.begin(), ebb=bk.end(); ibb!=ebb; ++ibb )
379 pf[0] += ibb->first[0];
380 pf[1] += ibb->first[1];
381 pf[2] += ibb->first[2];
383 pf[0] = vs[0] * pf[0] / bk.size();
384 pf[1] = vs[1] * pf[1] / bk.size();
385 pf[2] = vs[2] * pf[2] / bk.size();
386 v->setProperty(
"gravity_center", pf );
388 pm = motion.
transform( pf[0], pf[1], pf[2] );
393 v->setProperty(
"refgravity_center", pf );
395 v->setProperty(
"Talairach(mm)", pf );
396 sprintf( num,
"%f %f %f", pf[0], pf[1], pf[2] );
397 v->setProperty(
"label", std::string( num ) );
399 std::cout <<
"clusters created\n";
carto::VolumeRef< U > bin(const carto::VolumeRef< T > &sqv)
Vertex * addVertex(const std::string &s="")
void doit(const carto::rc_ptr< carto::Volume< short > > &thing, const std::string &name, const std::string &mode="binar")
void setSmoothing(SmoothingType smoothType, int smoothIt, float smoothRate)
Smoothing.
void setDecimation(float deciReductionRate, float deciMaxClearance, float deciMaxError, float deciFeatureAngle)
Decimation.
void setMinFacetNumber(uint m)
void setSmoothingLaplacian(float smoothFeatureAngle)
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
void make(Graph &gr, const carto::rc_ptr< carto::Volume< T > > &data)
static void meshMerge(AimsTimeSurface< D, T > &dst, const AimsTimeSurface< D, T > &add)
virtual void convert(const INP &in, OUTP &out) const
void convert(const INP &in, OUTP &out) const
void fillBorder(const T &value)
std::vector< int > getSize() const
std::map< std::string, std::map< std::string, GraphElementCode > > GraphElementTable
std::string global_filename
std::string global_index_attribute
std::string local_file_attribute
AIMSDATA_API AimsTimeSurface< 3, Void > AimsSurfaceTriangle