Commit d6a7205f authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add program to convert output Gray Scott hdf5 into png

parent 687610a0
......@@ -6,5 +6,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Naive ${CMAKE_CURRENT_SOURCE_DIR
add_subdirectory(Naive)
add_subdirectory(GrayScottDataFormat)
add_subdirectory(Program)
add_subdirectory(GrayScott2Pic)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
add_executable(gray_scott2pic main.cpp)
set_property(TARGET gray_scott2pic PROPERTY COMPILE_FLAGS "-O3")
target_link_libraries(gray_scott2pic gray_scott_data_format tensor_alloc phoenix_png option_parser data_stream string_utils ${HDF5_CXX_LIBRARIES} TBB::tbb)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <sstream>
#include "OptionParser.h"
#include "PImagePng.h"
#include "MatrixHdf5.h"
///Create the OptionParser of this program
/** @return OptionParser of this program
*/
OptionParser createOptionParser(){
OptionParser parser(true, __PROGRAM_VERSION__);
parser.setExampleLongOption("gray_scott2pic --input=file.h5 --output=/output/dir/name");
parser.setExampleShortOption("gray_scott2pic -i file.h5 -o /output/dir/name");
parser.addOption("input", "i", OptionType::FILENAME, true, "input hdf5 file name");
std::string defaultOutputDir("./");
parser.addOption("output", "o", defaultOutputDir, "Output directory of the created images");
return parser;
}
///Simulate the images
/** @param inputFile : input hdf5 file name
* @param outputDir : Output directory of the created images
* @return true on succsess, false otherwise
*/
bool simulateImage(const std::string & inputFile, const std::string & outputDir){
MatrixHdf5 fullMat;
fullMat.read(inputFile);
size_t nbImage(fullMat.getNbEntries()), nbRow(fullMat.getNbRow()), nbCol(fullMat.getNbCol());
std::cout << "simulateImage : nbImage = "<<nbImage<<", nbRow = " << nbRow << ", nbCol = " << nbCol << std::endl;
PImagePng image;
if(!image.createImage(nbCol, nbRow, PImagePng::RGB)){
std::cerr << "simulateImage : cannot create image" << std::endl;
return false;
}
PColorMap colorMap;
// 0,#000000,0.2,#00FF00,0.21,#FFFF00,0.4,#FF0000,0.6,#FFFFFF
colorMap.addColor(0.0, "000000");
colorMap.addColor(0.2, "00FF00");
colorMap.addColor(0.21, "FFFF00");
colorMap.addColor(0.4, "FF0000");
colorMap.addColor(0.6, "FFFFFF");
for(size_t i(0lu); i < nbImage; ++i){
float * matValue = fullMat.getTabMat(i);
image.setColor(matValue, nbRow, nbCol, colorMap);
std::stringstream fileName;
fileName << outputDir << i << ".png";
if(!image.write(fileName.str())){
std::cerr << "simulateImage : cannot save image " << i << " in file '"<<fileName.str()<<"'" << std::endl;
return false;
}
}
std::cerr << "Done" << std::endl;
return true;
}
int main(int argc, char** argv){
OptionParser parser = createOptionParser();
parser.parseArgument(argc, argv);
const OptionMode & defaultMode = parser.getDefaultMode();
std::string inputFile("");
defaultMode.getValue(inputFile, "input");
std::string outputDir("./");
defaultMode.getValue(outputDir, "output");
bool b(simulateImage(inputFile, outputDir));
return b - 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment