Commit 43498383 authored by berenger-bramas's avatar berenger-bramas

New class to save a tree in csv format.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@347 2616d619-271b-44dc-8df4-d4a8f33a7222
parent e88d284f
#ifndef FTREECSVSAVER_HPP
#define FTREECSVSAVER_HPP
#include "../Utils/FGlobal.hpp"
#include <cstring>
#include <iostream>
#include <fstream>
/** This class is to export a tree in csv file
*
*/
template <class OctreeClass, class ContainerClass , class ParticleClass>
class FTreeCsvSaver {
const bool includeHeader; //< To include a line of header
int nbFrames; //< The current frame
char basefile[512]; //< The base file name like "~/OUT/simulation%d.csv"
public:
/** Constructor
* @param inBasefile is the output file name, you must put %d in it
*/
FTreeCsvSaver(const char inBasefile[], const bool inIncludeHeader = false)
: includeHeader(inIncludeHeader), nbFrames(0) {
strcpy(basefile, inBasefile);
}
/** Virtual destructor
*/
virtual ~FTreeCsvSaver(){
}
/** to know how many frame has been saved
*/
int getNbFrames() const {
return nbFrames;
}
/** export a tree
*/
void exportTree(OctreeClass*const tree){
char currentFilename[512];
sprintf(currentFilename, basefile, nbFrames++);
std::ofstream file(currentFilename, std::ofstream::out );
if(includeHeader){
file << "x, y, z, value\n";
}
typename OctreeClass::Iterator octreeIterator(tree);
octreeIterator.gotoBottomLeft();
do{
typename ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
//const bool isUsingTsm = (octreeIterator.getCurrentListTargets() != octreeIterator.getCurrentListSrc());
while( iter.hasNotFinished() ){
file << iter.data().getPosition().getX() << "," << iter.data().getPosition().getY() << "," <<
iter.data().getPosition().getZ() << "," << getValue(&iter.data()) << "\n";
iter.gotoNext();
}
} while(octreeIterator.moveRight());
file.close();
}
/** Inherit from this class and customize this function if you need it
*/
virtual FReal getValue(ParticleClass*const part){
return FReal(0);
}
};
#endif // FTREECSVSAVER_HPP
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