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 "UblasCustomFunctions.hpp"
00030 #include "HeartConfig.hpp"
00031 #include "PostProcessingWriter.hpp"
00032 #include "PetscTools.hpp"
00033 #include "OutputFileHandler.hpp"
00034 #include <iostream>
00035
00036 PostProcessingWriter::PostProcessingWriter(Hdf5DataReader* pDataReader)
00037 {
00038 mpCalculator = new PropagationPropertiesCalculator(pDataReader);
00039 mNumberOfNodes = pDataReader->GetNumberOfRows();
00040 }
00041
00042 PostProcessingWriter::~PostProcessingWriter()
00043 {
00044 delete mpCalculator;
00045 }
00046
00047
00048 void PostProcessingWriter::WriteApdMapFile(double threshold, double repolarisationPercentage)
00049 {
00050 OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00051 if(PetscTools::AmMaster())
00052 {
00053 out_stream p_file=out_stream(NULL);
00054 std::stringstream stream;
00055 stream << repolarisationPercentage;
00056 p_file = output_file_handler.OpenOutputFile("Apd" + stream.str() + "Map.dat");
00057 for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00058 {
00059 std::vector<double> apds;
00060 try
00061 {
00062 apds = mpCalculator->CalculateAllActionPotentialDurations(repolarisationPercentage, node_index, threshold);
00063 assert(apds.size() != 0);
00064 }
00065 catch(Exception& e)
00066 {
00067 apds.push_back(0);
00068 assert(apds.size() == 1);
00069 }
00070 for (unsigned i = 0; i < apds.size(); i++)
00071 {
00072 *p_file << apds[i] << "\t";
00073 }
00074 *p_file << std::endl;
00075 }
00076 p_file->close();
00077 }
00078 }
00079
00080
00081 void PostProcessingWriter::WriteUpstrokeTimeMap(double threshold)
00082 {
00083 if(PetscTools::AmMaster())
00084 {
00085 out_stream p_file=out_stream(NULL);
00086 OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00087 p_file = output_file_handler.OpenOutputFile("UpstrokeTimeMap.dat");
00088 for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00089 {
00090 std::vector<double> upstroke_times;
00091 upstroke_times = mpCalculator->CalculateUpstrokeTimes(node_index, threshold);
00092 assert(upstroke_times.size()!=0);
00093 for (unsigned i = 0; i < upstroke_times.size(); i++)
00094 {
00095 *p_file << upstroke_times[i] << "\t";
00096 }
00097 *p_file << std::endl;
00098 }
00099 p_file->close();
00100 }
00101 }
00102
00103 void PostProcessingWriter::WriteMaxUpstrokeVelocityMap(double threshold)
00104 {
00105 if(PetscTools::AmMaster())
00106 {
00107 out_stream p_file=out_stream(NULL);
00108 OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00109 p_file = output_file_handler.OpenOutputFile("MaxUpstrokeVelocityMap.dat");
00110 for (unsigned node_index = 0; node_index < mNumberOfNodes; node_index++)
00111 {
00112 std::vector<double> upstroke_velocities;
00113 upstroke_velocities = mpCalculator->CalculateAllMaximumUpstrokeVelocities(node_index, threshold);
00114 assert(upstroke_velocities.size()!=0);
00115 for (unsigned i = 0; i < upstroke_velocities.size(); i++)
00116 {
00117 *p_file << upstroke_velocities[i] << "\t";
00118 }
00119 *p_file << std::endl;
00120 }
00121 p_file->close();
00122 }
00123 }
00124
00125 void PostProcessingWriter::WriteConductionVelocityMap(unsigned originNode, std::vector<double> distancesFromOriginNode)
00126 {
00127 if(PetscTools::AmMaster())
00128 {
00129 out_stream p_file=out_stream(NULL);
00130 OutputFileHandler output_file_handler(HeartConfig::Instance()->GetOutputDirectory() + "/output", false);
00131
00132 std::stringstream filename;
00133 filename << "ConductionVelocityFromNode" << originNode << ".dat";
00134 p_file = output_file_handler.OpenOutputFile(filename.str());
00135 for (unsigned dest_node = 0; dest_node < mNumberOfNodes; dest_node++)
00136 {
00137 std::vector<double> conduction_velocities;
00138 conduction_velocities = mpCalculator->CalculateAllConductionVelocities(originNode, dest_node, distancesFromOriginNode[dest_node]);
00139 assert(conduction_velocities.size()!=0);
00140 for (unsigned i = 0; i < conduction_velocities.size(); i++)
00141 {
00142 *p_file << conduction_velocities[i] << "\t";
00143 }
00144 *p_file << std::endl;
00145 }
00146 p_file->close();
00147 }
00148 }
00149