returnValue Matrix::printToFile( const char* const filename, const char* const name, PrintScheme printScheme ) const { FILE* file = 0; MatFile* matFile = 0; switch ( printScheme ) { case PS_MATLAB_BINARY: matFile = new MatFile; matFile->open( filename ); matFile->write( *this,name ); matFile->close( ); delete matFile; return SUCCESSFUL_RETURN; default: file = fopen( filename,"w+" ); if ( file == 0 ) return ACADOERROR( RET_FILE_CAN_NOT_BE_OPENED ); printToFile( file, name,printScheme ); fclose( file ); return SUCCESSFUL_RETURN; } }
virtual void end(Voxel& voxel,MatFile& mat_writer) { mat_writer.add_matrix("free_water_quantity",&voxel.qa_scaling,1,1); mat_writer.add_matrix("jdet",&*jdet.begin(),1,jdet.size()); double trans_to_mni[16]; std::fill(trans_to_mni,trans_to_mni+16,0.0); trans_to_mni[0] = scale[0]; trans_to_mni[5] = scale[1]; trans_to_mni[10] = scale[2]; trans_to_mni[3] = bounding_box_lower[0]-scale[0]; trans_to_mni[7] = bounding_box_lower[1]-scale[1]; trans_to_mni[11] = bounding_box_lower[2]-scale[2]; mat_writer.add_matrix("mni",&*trans_to_mni,4,3); mat_writer.add_matrix("R2",&R2,1,1); }
returnValue GenericMatrix< T >::print( std::ostream& _stream, const std::string& _name, PrintScheme _printScheme ) const { MatFile< T >* matFile; switch ( _printScheme ) { case PS_MATLAB_BINARY: matFile = new MatFile<T>(); matFile->write(_stream, *this, _name.c_str()); delete matFile; return SUCCESSFUL_RETURN; default: char* startString = 0; char* endString = 0; uint width = 0; uint precision = 0; char* colSeparator = 0; char* rowSeparator = 0; returnValue ret = getGlobalStringDefinitions(_printScheme, &startString, &endString, width, precision, &colSeparator, &rowSeparator); if (ret != SUCCESSFUL_RETURN) return ret; returnValue status = print(_stream, _name, startString, endString, width, precision, colSeparator, rowSeparator); if ( startString != 0 ) delete[] startString; if ( endString != 0 ) delete[] endString; if ( colSeparator != 0 ) delete[] colSeparator; if ( rowSeparator != 0 ) delete[] rowSeparator; return status; } }
virtual void end(Voxel& voxel,MatFile& mat_writer) { for (unsigned int index = 0;index < voxel.max_fiber_number;++index) { std::ostringstream out; out << index; std::string num = out.str(); std::string index_str = "dir"; index_str += num; set_title(index_str.c_str()); mat_writer.add_matrix(index_str.c_str(),&*dir[index].begin(),1,dir[index].size()); } }
virtual void end(Voxel& voxel,MatFile& mat_writer) { if (voxel.need_odf) { set_title("output odfs"); for (unsigned int index = 0;index < voxel.template_odfs.size();++index) { std::ostringstream out; out << "odf" << index; mat_writer.add_matrix(out.str().c_str(),&*voxel.template_odfs[index].begin(), voxel.ti.half_vertices_count, voxel.template_odfs[index].size()/(voxel.ti.half_vertices_count)); } } }
virtual void end(Voxel& voxel,MatFile& mat_writer) { if (!voxel.need_odf) return; { set_title("output odfs"); for (unsigned int index = 0;index < odf_data.size();++index) { if (!voxel.odf_deconvolusion) std::for_each(odf_data[index].begin(),odf_data[index].end(),boost::lambda::_1 /= voxel.qa_scaling); std::ostringstream out; out << "odf" << index; mat_writer.add_matrix(out.str().c_str(),&*odf_data[index].begin(), voxel.ti.half_vertices_count, odf_data[index].size()/(voxel.ti.half_vertices_count)); } odf_data.clear(); } }
virtual void end(Voxel& voxel,MatFile& mat_writer) { set_title("output gfa"); mat_writer.add_matrix("gfa",&*gfa.begin(),1,gfa.size()); if(!voxel.odf_deconvolusion) { voxel.qa_scaling = *std::max_element(iso.begin(),iso.end()); // scaled to 1mm cubic if(voxel.vs[0] != 0.0 && voxel.vs[1] != 0.0 && voxel.vs[2] != 0.0) { voxel.qa_scaling /= voxel.vs[0]; voxel.qa_scaling /= voxel.vs[1]; voxel.qa_scaling /= voxel.vs[2]; } mat_writer.add_matrix("qa_scaling",&voxel.qa_scaling,1,1); std::for_each(iso.begin(),iso.end(),boost::lambda::_1 /= voxel.qa_scaling); mat_writer.add_matrix("iso",&*iso.begin(),1,iso.size()); if (voxel.qa_scaling != 0.0) for (unsigned int i = 0;i < voxel.max_fiber_number;++i) std::for_each(fa[i].begin(),fa[i].end(),boost::lambda::_1 /= voxel.qa_scaling); // cellularity int max_fa_index = std::max_element(fa[0].begin(),fa[0].end())-fa[0].begin(); float ratio = iso[max_fa_index]/fa[0][max_fa_index]; for(unsigned int index = 0;index < iso.size();++index) iso[index] -= fa[0][index]*ratio; mat_writer.add_matrix("cell",&*iso.begin(),1,iso.size()); } for (unsigned int index = 0;index < voxel.max_fiber_number;++index) { std::ostringstream out; out << index; std::string num = out.str(); std::string fa_str = "fa"; fa_str += num; set_title(fa_str.c_str()); mat_writer.add_matrix(fa_str.c_str(),&*fa[index].begin(),1,fa[index].size()); } // output normalized qa { float max_qa = 0.0; for (unsigned int i = 0;i < voxel.max_fiber_number;++i) max_qa = std::max<float>(*std::max_element(fa[i].begin(),fa[i].end()),max_qa); if(max_qa != 0.0) for (unsigned int index = 0;index < voxel.max_fiber_number;++index) { std::for_each(fa[index].begin(),fa[index].end(),boost::lambda::_1 /= max_qa); std::ostringstream out; out << index; std::string num = out.str(); std::string fa_str = "nqa"; fa_str += num; set_title(fa_str.c_str()); mat_writer.add_matrix(fa_str.c_str(),&*fa[index].begin(),1,fa[index].size()); } } }