void mitk::PlanarFigureCompositeWriter::Write() { std::ostream* out; std::ofstream outStream; if( this->GetOutputStream() ) { out = this->GetOutputStream(); }else{ outStream.open( this->GetOutputLocation().c_str() ); out = &outStream; } if ( !out->good() ) { mitkThrow() << "Stream not good."; } try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); setlocale(LC_ALL, locale.c_str()); std::locale previousLocale(out->getloc()); std::locale I("C"); out->imbue(I); std::string filename = this->GetOutputLocation().c_str(); mitk::PlanarFigureComposite::ConstPointer input = dynamic_cast<const mitk::PlanarFigureComposite*>(this->GetInput()); std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str()); boost::property_tree::ptree type; type.put("comptype", input->getOperationType()); boost::property_tree::xml_writer_settings<std::string> writerSettings(' ', 2); boost::property_tree::xml_parser::write_xml(filename, type, std::locale(), writerSettings); setlocale(LC_ALL, currLocale.c_str()); } catch(...) { throw; } }
void mitk::ContourModelWriter::Write() { std::ostream* out; std::ofstream outStream; if( this->GetOutputStream() ) { out = this->GetOutputStream(); } else { outStream.open( this->GetOutputLocation().c_str() ); out = &outStream; } if ( !out->good() ) { mitkThrow() << "Stream not good."; } std::locale previousLocale(out->getloc()); std::locale I("C"); out->imbue(I); /*+++++++++++ Here the actual xml writing begins +++++++++*/ /*++++ <?xml version="1.0" encoding="utf-8"?> ++++*/ WriteXMLHeader( *out ); // // for each input object write its xml representation to // the stream // mitk::ContourModel::ConstPointer contourModel = dynamic_cast<const mitk::ContourModel*>(this->GetInput()); assert( contourModel.IsNotNull() ); WriteXML( contourModel.GetPointer(), *out ); out->imbue(previousLocale); if ( !out->good() ) // some error during output { throw std::ios_base::failure("Some error during contour writing."); } }
void mitk::ConnectomicsNetworkCSVWriter::Write() { MITK_INFO << "Writing connectomics network"; InputType::ConstPointer input = dynamic_cast<const InputType*>(this->GetInput()); if (input.IsNull() ) { MITK_ERROR <<"Sorry, input to ConnectomicsNetworkMatrixWriter is nullptr!"; return; } this->ValidateOutputLocation(); std::ostream* out; std::ofstream outStream; if( this->GetOutputStream() ) { out = this->GetOutputStream(); } else { outStream.open( this->GetOutputLocation().c_str() ); out = &outStream; } if ( !out->good() ) { mitkThrow() << "Could not open stream."; } try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, nullptr ); setlocale(LC_ALL, locale.c_str()); std::locale previousLocale(out->getloc()); std::locale I("C"); out->imbue(I); // construct header std::stringstream header; mitk::StringProperty::Pointer addHeaderInfoProperty = dynamic_cast<mitk::StringProperty*>(input->GetProperty(connectomicsDataAdditionalHeaderInformation.c_str()).GetPointer()); if(addHeaderInfoProperty.IsNotNull()) { std::string additionalHeaderInfo = addHeaderInfoProperty->GetValue(); // if the additional header info contains newlines we need to add # // in front of the new lines std::vector<std::string> strings; boost::split(strings, additionalHeaderInfo, boost::is_any_of("\n")); for( unsigned int index(0); index < strings.size(); ++index) { header << "#" << strings[index] << "\n"; } } // construct body std::stringstream body; std::vector< InputType::VertexDescriptorType > nodes = input->GetVectorOfAllVertexDescriptors(); for(unsigned int i(0); i < nodes.size(); ++i) { for(unsigned int j(0); j < i; ++j) { double weight(0); if( input->EdgeExists(nodes[i], nodes[j]) ) { weight = (input->GetEdge(nodes[i], nodes[j])).edge_weight; } body << (input->GetNode(nodes[i])).label << " " << (input->GetNode(nodes[j])).label << " " << weight << "\n"; } } (*out)<< header.str() << body.str(); setlocale(LC_ALL, currLocale.c_str()); MITK_INFO << "Connectomics network connection list written"; } catch(...) { mitkThrow() << "Error while writing to stream."; } }