FibreWriter.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "FibreWriter.hpp"
00030 #include "Version.hpp"
00031
00032 template<unsigned DIM>
00033 FibreWriter<DIM>::FibreWriter(const std::string& rDirectory,
00034 const std::string& rBaseName,
00035 const bool clearOutputDir)
00036 : mBaseName(rBaseName),
00037 mFileIsBinary(false)
00038 {
00039 mpOutputFileHandler = new OutputFileHandler(rDirectory, clearOutputDir);
00040 }
00041
00042 template<unsigned DIM>
00043 FibreWriter<DIM>::~FibreWriter()
00044 {
00045 delete mpOutputFileHandler;
00046 }
00047
00048 template<unsigned DIM>
00049 void FibreWriter<DIM>::WriteAllAxi(const std::vector< c_vector<double, DIM> >& fibres)
00050 {
00051
00052 out_stream p_axi_file = OpenFileAndWriteHeader(this->mBaseName + ".axi", fibres.size());
00053
00054
00055 for (unsigned i=0; i<fibres.size();i++ )
00056 {
00057 if (this->mFileIsBinary)
00058 {
00059 p_axi_file->write((char*)&fibres[i][0], DIM*sizeof(double));
00060 }
00061 else
00062 {
00063 for(unsigned j=0; j<DIM; j++)
00064 {
00065 *p_axi_file << fibres[i][j] << "\t";
00066 }
00067 *p_axi_file <<"\n";
00068 }
00069 }
00070 *p_axi_file << "#\n# " << ChasteBuildInfo::GetProvenanceString();
00071 p_axi_file->close();
00072 }
00073
00074 template<unsigned DIM>
00075 void FibreWriter<DIM>::WriteAllOrtho(const std::vector< c_vector<double, DIM> >& fibres,
00076 const std::vector< c_vector<double, DIM> >& second,
00077 const std::vector< c_vector<double, DIM> >& third)
00078 {
00079 assert(fibres.size() == second.size());
00080 assert(second.size() == third.size());
00081
00082 out_stream p_file = OpenFileAndWriteHeader(this->mBaseName + ".ortho", fibres.size());
00083
00084
00085 for (unsigned i=0; i<fibres.size();i++ )
00086 {
00087 if (this->mFileIsBinary)
00088 {
00089
00090 p_file->write((char*)&fibres[i][0], DIM*sizeof(double));
00091 p_file->write((char*)&second[i][0], DIM*sizeof(double));
00092 p_file->write((char*)&third[i][0], DIM*sizeof(double));
00093 }
00094 else
00095 {
00096
00097 for(unsigned j=0; j<DIM; j++)
00098 {
00099 *p_file << fibres[i][j] << "\t";
00100 }
00101 for(unsigned j=0; j<DIM; j++)
00102 {
00103 *p_file << second[i][j] << "\t";
00104 }
00105 for(unsigned j=0; j<DIM; j++)
00106 {
00107 *p_file << third[i][j] << "\t";
00108 }
00109 *p_file <<"\n";
00110 }
00111 }
00112 *p_file << "#\n# " << ChasteBuildInfo::GetProvenanceString();
00113 p_file->close();
00114 }
00115
00116 template<unsigned DIM>
00117 out_stream FibreWriter<DIM>::OpenFileAndWriteHeader(const std::string& rFileName, unsigned numItems)
00118 {
00119 out_stream p_fibre_file = this->mpOutputFileHandler->OpenOutputFile(rFileName);
00120
00121
00122 *p_fibre_file << numItems;
00123
00124 if (this->mFileIsBinary)
00125 {
00126 *p_fibre_file << "\tBIN\n";
00127 }
00128 else
00129 {
00130 *p_fibre_file << "\n";
00131 }
00132 return p_fibre_file;
00133 }
00134
00135
00136 template<unsigned DIM>
00137 void FibreWriter<DIM>::SetWriteFileAsBinary()
00138 {
00139 mFileIsBinary = true;
00140 }
00141
00142 template class FibreWriter<1>;
00143 template class FibreWriter<2>;
00144 template class FibreWriter<3>;
00145
00146
00147
00148
00149