Lagrangian Liquid Simulation
Master Thesis project on simulation of liquids using Lagrangian approach and SPH
|
manage list of cache items per frame and writes them to disk at a regular interval More...
#include <Cache.h>
Public Member Functions | |
Cache () | |
ctor | |
void | addItem (const CacheItem &_cacheItem) |
add cache items to the cache | |
int | getCacheCount () const |
return the number of items in the cache | |
void | flushCache (const std::string _path) |
writes the contents of the cache to file | |
Private Member Functions | |
void | writePointData (std::vector< ngl::Vector > &_positionList, const std::string &_filename) |
write point positions (fluid and sphere) to file | |
void | writeBoundaryData (std::vector< ngl::Vector > &_positionList, const std::string &_filename) |
write the boundary box information to file | |
Private Attributes | |
std::vector< CacheItem > | m_fluidCache |
the list of cache items held in the cache |
manage list of cache items per frame and writes them to disk at a regular interval
void Cache::addItem | ( | const CacheItem & | _cacheItem | ) |
add cache items to the cache
[in] | _cacheItem | the item to add to the cache list |
Definition at line 13 of file Cache.cpp.
References m_fluidCache.
{ m_fluidCache.push_back(_cacheItem); }
void Cache::flushCache | ( | const std::string | _path | ) |
writes the contents of the cache to file
Definition at line 18 of file Cache.cpp.
References BOUNDARY_CACHE, CAPSULE_CACHE, FLUID_CACHE, CacheItem::getCacheItemType(), CacheItem::getFrameNumber(), CacheItem::getNameList(), CacheItem::getPositionList(), m_fluidCache, SPHERE_CACHE, writeBoundaryData(), and writePointData().
{ //loop through cache items for (int i = 0; i < m_fluidCache.size(); ++i) { //get cache item CacheItem item = m_fluidCache[i]; //loop through name list of the item for (int j = 0; j < item.getNameList().size(); ++j) { //determine type of item std::string itemType; if (item.getCacheItemType() == FLUID_CACHE) itemType = "Fluid"; else if (item.getCacheItemType() == BOUNDARY_CACHE) itemType = "Boundary"; else if (item.getCacheItemType() == SPHERE_CACHE) itemType = "Sphere"; else if (item.getCacheItemType() == CAPSULE_CACHE) itemType = "Capsule"; else itemType = "NA"; //construct filename of the item for the current frame number QString text = QString("%1%2_%3_Frame_%4.geo") .arg(_path.c_str()) .arg(itemType.c_str()) .arg(std::string(item.getNameList()[j]).c_str()) .arg(item.getFrameNumber()); //write data to file if (item.getCacheItemType() == FLUID_CACHE || item.getCacheItemType() == SPHERE_CACHE || item.getCacheItemType() == CAPSULE_CACHE) writePointData(item.getPositionList()[j], text.toStdString()); else if (item.getCacheItemType() == BOUNDARY_CACHE) writeBoundaryData(item.getPositionList()[j], text.toStdString()); } } //clear cache m_fluidCache.clear(); }
int Cache::getCacheCount | ( | ) | const [inline] |
return the number of items in the cache
Definition at line 27 of file Cache.h.
References m_fluidCache.
{ return m_fluidCache.size(); }
void Cache::writeBoundaryData | ( | std::vector< ngl::Vector > & | _positionList, |
const std::string & | _filename | ||
) | [private] |
write the boundary box information to file
[in] | _positionList | the position list to write out |
[in] | _filename | the name of the file on disk |
Definition at line 96 of file Cache.cpp.
{ //open file for writing std::ofstream outFile(_filename.c_str(), std::ios::out); //write header outFile << "PGEOMETRY V5\n"; outFile << "NPoints 8 NPrims 6\n"; outFile << "NPointGroups 0 NPrimGroups 0\n"; outFile << "NPointAttrib 0 NVertexAttrib 0 NPrimAttrib 0 NAttrib 0\n"; //loop through position list for (int i = 0; i < _positionList.size(); ++i) { outFile << _positionList[i].m_x << " " << _positionList[i].m_y << " " << _positionList[i].m_z << " " << _positionList[i].m_w << "\n"; } //write box vertex connections outFile << "Run 6 Poly\n"; outFile << " 4 < 1 5 4 0\n"; outFile << " 4 < 2 6 5 1\n"; outFile << " 4 < 3 7 6 2\n"; outFile << " 4 < 0 4 7 3\n"; outFile << " 4 < 2 1 0 3\n"; outFile << " 4 < 5 6 7 4\n"; //write the outro outFile << "beginExtra\n"; outFile << "endExtra"; //close file outFile.close(); }
void Cache::writePointData | ( | std::vector< ngl::Vector > & | _positionList, |
const std::string & | _filename | ||
) | [private] |
write point positions (fluid and sphere) to file
[in] | _positionList | the position list to write out |
[in] | _filename | the name of the file on disk |
Definition at line 63 of file Cache.cpp.
{ //open file for writing std::ofstream outFile(_filename.c_str(), std::ios::out); //write header outFile << "PGEOMETRY V5\n"; outFile << "NPoints " << _positionList.size() << " NPrims 0\n"; outFile << "NPointGroups 0 NPrimGroups 0\n"; outFile << "NPointAttrib 0 NVertexAttrib 0 NPrimAttrib 0 NAttrib 0\n"; //loop through position list for (int i = 0; i < _positionList.size(); ++i) { outFile << _positionList[i].m_x << " " << _positionList[i].m_y << " " << _positionList[i].m_z << " " << _positionList[i].m_w << "\n"; } //write the outro outFile << "beginExtra\n"; outFile << "endExtra"; //close file outFile.close(); }
std::vector<CacheItem> Cache::m_fluidCache [private] |