Add option for unit.

Some expertimens are in cm
parent dfb7c8cb
Pipeline #1910 passed with stages
in 5 minutes and 16 seconds
......@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
## v0.8.2 [unreleased]
Repository moved to [new server](https://gitlab.version.fz-juelich.de/jupedsim/jpscore)
### Added
- New opstion for `groups`. It is now possible to load the first positions of peedestrians from a file.
Needed for better comparison with experiments. Use attribute: `positions_dir="/path/to/directory/"` `unit="cm"`.
The unit of the trajectories can be specified. Default is meter.
### Changed
- New Progressbar (ec7c9b0c)
......@@ -118,4 +120,4 @@ First release of the the Juelich Pedestrian Simulator. Most noteworthy features:
- Loading and visualizing trajectories and geometries
- Easy to use visualization interface
- Making high quality videos directly from the visualization interface or generating png sequences
- XML based input files
\ No newline at end of file
- XML based input files
......@@ -74,6 +74,7 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
//double risk_tolerance_mean = xmltof(e->Attribute("risk_tolerance_mean"), 0);
//double risk_tolerance_sigma = xmltof(e->Attribute("risk_tolerance_sigma"), 0);
string positions_dir = xmltoa(e->Attribute("positions_dir"), "");
string unit_traj = xmltoa(e->Attribute("unit"), "m");
double x_min = xmltof(e->Attribute("x_min"), -FLT_MAX);
double x_max = xmltof(e->Attribute("x_max"), FLT_MAX);
double y_min = xmltof(e->Attribute("y_min"), -FLT_MAX);
......@@ -103,6 +104,7 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
dis->SetPatience(patience);
dis->InitPremovementTime(premovement_mean, premovement_sigma);
dis->SetPositionsDir(positions_dir);
dis->SetUnitTraj(unit_traj);
if (dis->GetPositionsDir().length())
{
......
......@@ -123,6 +123,7 @@ bool PedDistributor::Distribute(Building *building) const {
bool fromDirectory = false;
if(dist->GetPositionsDir().length()){
string directory = dist->GetPositionsDir();
string unit = dist->GetUnitTraj();
fs::path the_path(directory);
if(fs::exists(directory) && fs::is_directory(directory)){
fs::directory_iterator it(the_path), eod;
......@@ -132,7 +133,7 @@ bool PedDistributor::Distribute(Building *building) const {
{
std::string basename = fs::basename(p);
std::string extention = fs::extension(p);
auto tmpPositions = GetPositionsFromFile(p.string(), dist->GetAgentsNumber());
auto tmpPositions = GetPositionsFromFile(p.string(), dist->GetAgentsNumber(), unit);
//check if positions are
//empty. May happen if file
//is misformed.
......@@ -413,7 +414,11 @@ vector<Point>PedDistributor::PositionsOnFixY(double min_x, double max_x, double
}
// format: id fr x y
const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename, int n) const{
const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename, int n, std::string unit) const{
float m2cm = 1.0;
if(unit == "cm")
m2cm = 100.0;
std::ifstream infile(filename);
// read all data from file in xpos, ypos, ids and frames
// @todo: need to read z too
......@@ -422,8 +427,6 @@ const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename,
std::vector<int> ids;
std::vector<int> frames;
// here we push_back only the first (x,y) of every id.
// std::vector<double> first_xpos;
// std::vector<double> first_ypos;
std::vector<Point> positions;
std::vector<int> first_ids;
if (infile.good()){
......@@ -438,8 +441,8 @@ const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename,
boost::split(strs, sLine, boost::is_any_of("\t "));
id = atoi(strs[0].c_str());
fr = atoi(strs[1].c_str());
x = atof(strs[2].c_str());
y = atof(strs[3].c_str());
x = atof(strs[2].c_str())/m2cm;
y = atof(strs[3].c_str())/m2cm;
// @todo: check for z component. Some data don't have. Some do.
xpos.push_back(x);
ypos.push_back(y);
......
......@@ -99,7 +99,7 @@ public:
* WARNING: It is assumed that positions should be in the corresponding room/subroom.
* checks with n if the file delivers the right number of peds
*/
const vector<Point> GetPositionsFromFile(std::string filename, int n) const;
const vector<Point> GetPositionsFromFile(std::string filename, int n, std::string unit) const;
};
......
......@@ -63,6 +63,7 @@ StartDistribution::StartDistribution(int seed)
_yMax=FLT_MAX;
_groupParameters=NULL;
_positions_dir = "";
_unit_traj = "m";
static bool _seeded = false; // seed only once, not every time
if(!_seeded) {
_generator = std::default_random_engine(seed); // mt19937 g(static_cast<uint32_t>(_configuration->GetSeed()));
......@@ -399,3 +400,12 @@ const std::string& StartDistribution::GetPositionsDir() const
{
return _positions_dir;
}
void StartDistribution::SetUnitTraj(const std::string& unit)
{
_unit_traj = unit;
}
const std::string& StartDistribution::GetUnitTraj() const
{
return _unit_traj;
}
......@@ -53,7 +53,8 @@ private:
//demographic parameters
//TODO: should also follow a distribution, see _premovement
std::string _gender;
std::string _positions_dir; // directory containing >=1 file(s) used to setup starting positions
std::string _positions_dir; // directory containing >=1 file(s) used to setup starting positions
std::string _unit_traj; //unit of traj from file
int _age;
int _height;
double _patience;
......@@ -125,6 +126,8 @@ public:
double GetRiskTolerance();
void SetPositionsDir(const std::string& dir);
const std::string& GetPositionsDir() const;
void SetUnitTraj(const std::string& unit);
const std::string& GetUnitTraj() const;
Pedestrian* GenerateAgent(Building* building, int* pid, std::vector<Point>& positions);
};
......
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