22 #include <boost/algorithm/string.hpp>
46 MITK_INFO <<
"Writing connectomics network";
50 MITK_ERROR <<
"Sorry, input to ConnectomicsNetworkMatrixWriter is NULL!";
54 this->ValidateOutputLocation();
57 std::ofstream outStream;
59 if( this->GetOutputStream() )
61 out = this->GetOutputStream();
65 outStream.open( this->GetOutputLocation().c_str() );
76 const std::string& locale =
"C";
77 const std::string& currLocale = setlocale( LC_ALL, NULL );
78 setlocale(LC_ALL, locale.c_str());
80 std::locale previousLocale(out->getloc());
85 std::stringstream header;
88 if(addHeaderInfoProperty.IsNotNull())
90 std::string additionalHeaderInfo = addHeaderInfoProperty->GetValue();
93 std::vector<std::string> strings;
94 boost::split(strings, additionalHeaderInfo, boost::is_any_of(
"\n"));
95 for(
unsigned int index(0); index < strings.size(); ++index)
97 header <<
"#" << strings[index] <<
"\n";
102 std::stringstream body;
104 std::vector< InputType::VertexDescriptorType > nodes = input->GetVectorOfAllVertexDescriptors();
105 for(
unsigned int i(0); i < nodes.size(); ++i)
107 for(
unsigned int j(0); j < i; ++j)
110 if( input->EdgeExists(nodes[i], nodes[j]) )
112 weight = (input->GetEdge(nodes[i], nodes[j])).edge_weight;
114 body << (input->GetNode(nodes[i])).label <<
" "
115 << (input->GetNode(nodes[j])).label <<
" "
120 (*out)<< header.str() << body.str();
122 setlocale(LC_ALL, currLocale.c_str());
123 MITK_INFO <<
"Connectomics network connection list written";
127 mitkThrow() <<
"Error while writing to stream.";
140 return PartiallySupported;
This file defines the data properties for connectomics networks in MITK.
DataCollection - Class to facilitate loading/accessing structured data.
virtual ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
mitk::IFileIO::ConfidenceLevel GetConfidenceLevel() const
The confidence level of the reader or writer implementation.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
virtual void Write()
Write the base data to the specified location or output stream.
static const char * GetStaticNameOfClass()
ConnectomicsNetworkCSVWriter()
virtual mitk::ConnectomicsNetworkCSVWriter * Clone() const
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
const std::string connectomicsDataAdditionalHeaderInformation
Additional header information.
virtual ~ConnectomicsNetworkCSVWriter()
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Base class for writing mitk::BaseData objects to files or streams.
Connectomics Network Class.
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)