Commit 4fc90d6d authored by Mohcine Chraibi's avatar Mohcine Chraibi

Refactor choosing point to add in a function

parent c4d6153b
......@@ -1524,10 +1524,10 @@ bool IniFileParser::ParseStrategyNodeToObject(const TiXmlNode& strategyNode)
if (pExitStrategy == 8 || pExitStrategy ==9){
_config->set_write_VTK_files_direction(false);
if (strategyNode.FirstChild("write_VTK_files")) {
const char* tmp =
const char* tmp1 =
strategyNode.FirstChild("write_VTK_files")->FirstChild()->Value();
//remark: std::strcmp returns 0 if the strings are equal
bool tmp_write_VTK = !std::strcmp(tmp, "true");
bool tmp_write_VTK = !std::strcmp(tmp1, "true");
_config->set_write_VTK_files_direction(tmp_write_VTK);
}
......
......@@ -300,7 +300,7 @@ void Simulation::UpdateRoutesAndLocations()
auto allRooms = _building->GetAllRooms();
#pragma omp parallel for shared(pedsToRemove, allRooms)
for (signed int p = 0; p < allPeds.size(); ++p) {
for (unsigned int p = 0; p < allPeds.size(); ++p) {
auto ped = allPeds[p];
Room* room = _building->GetRoom(ped->GetRoomID());
SubRoom* sub0 = room->GetSubRoom(ped->GetSubRoomID());
......
......@@ -370,55 +370,27 @@ bool Building::correct() const {
for(auto&& room: this->GetAllRooms()) {
for(auto&& subroom: room.second->GetAllSubRooms()) {
std::vector<Wall> walls = subroom.second->GetAllWalls();
for(auto wall: walls) //self checking
for(auto const & bigWall: walls) //self checking
{
for(auto&& other: walls) {
if((wall == other) || (wall.ShareCommonPointWith(other))) continue;
for(auto const & other: walls) {
if((bigWall == other) || (bigWall.ShareCommonPointWith(other))) continue;
Point intersectionPoint;
if(wall.IntersectionWith(other, intersectionPoint))
if(bigWall.IntersectionWith(other, intersectionPoint))
{
if(intersectionPoint == wall.GetPoint1() || intersectionPoint == wall.GetPoint2()) continue;
if(intersectionPoint == bigWall.GetPoint1() || intersectionPoint == bigWall.GetPoint2()) continue;
Log->Write("INFO Cutting a big line in Room %d | Subroom %d with:", room.first, subroom.first);
wall.WriteToErrorLog();
bigWall.WriteToErrorLog();
//other.WriteToErrorLog();
//string s = intersectionPoint.toString();
//std::cout << "\t >> Intersection at Point: " << s.c_str() << "\n";
Wall newWall(intersectionPoint, wall.GetPoint2());// [IP -- P2]
Wall newWall2(wall.GetPoint1(), intersectionPoint);// [IP -- P2]
bool res = subroom.second->RemoveWall(wall);
Wall newWall(intersectionPoint, bigWall.GetPoint2());// [IP -- P2]
Wall newWall2(bigWall.GetPoint1(), intersectionPoint);// [IP -- P2]
bool res = subroom.second->RemoveWall(bigWall);
if(!res) {
Log->Write("ERROR: Correct fails, because could not remove wall");
return false;
}
// we add new wall with >= 2 common walls
// and reject the new wall with <= 1 common points
int count = 0;
for(auto const & checkWall: walls)
{
if( (checkWall == newWall) || (checkWall == wall)) continue;// don't count big wall
if(newWall.ShareCommonPointWith(checkWall)) count++;
}
auto transitions = subroom.second->GetAllTransitions();
auto crossings = subroom.second->GetAllCrossings();
//auto h = subroom.second->GetAllHlines();
for(auto transition: transitions)
if(newWall.ShareCommonPointWith(*transition)) count++;
for(auto crossing: crossings)
if(newWall.ShareCommonPointWith(*crossing)) count++;
if (count >=2)
{
subroom.second->AddWall(newWall);
walls.push_back(newWall);
//std::cout << "\n---new walls ---\n";
//newWall.WriteToErrorLog();
}
else{
subroom.second->AddWall(newWall2);
walls.push_back(newWall2);
//std::cout << "\n---new wall2 ---\n";
//newWall2.WriteToErrorLog();
}
add_wall_to_subroom(subroom.second, bigWall, newWall, newWall2);
}
}//other walls
}//
......@@ -430,6 +402,42 @@ bool Building::correct() const {
return true;
}
bool Building::add_wall_to_subroom(
const std::shared_ptr<SubRoom> & subroom,
const Wall& bigWall,
const Wall& newWall, const Wall& newWall2) const
{
int count = 0;
auto walls = subroom->GetAllWalls();
for(auto const & checkWall: walls)
{
if( (checkWall == newWall) || (checkWall == bigWall)) continue;// don't count big wall
if(newWall.ShareCommonPointWith(checkWall)) count++;
}
auto transitions = subroom->GetAllTransitions();
auto crossings = subroom->GetAllCrossings();
//auto h = subroom.second->GetAllHlines();
for(auto transition: transitions)
if(newWall.ShareCommonPointWith(*transition)) count++;
for(auto crossing: crossings)
if(newWall.ShareCommonPointWith(*crossing)) count++;
if (count >=2)
{
subroom->AddWall(newWall);
walls.push_back(newWall);
//std::cout << "\n---new walls ---\n";
//newWall.WriteToErrorLog();
}
else{
subroom->AddWall(newWall2);
walls.push_back(newWall2);
//std::cout << "\n---new wall2 ---\n";
//newWall2.WriteToErrorLog();
}
return false;
}
const string& Building::GetProjectFilename() const
{
return _configuration->GetProjectFile();
......
......@@ -260,28 +260,41 @@ private:
* For example:
* C
* A x------------------------o-----------------x B
* ^ |
* wall1 |
* | <--- wall2
* o
* D
* Here wall [AB] is a big wall, then it intersects wall [CD] whether in A not in B
* ^ |
* wall1 |
* | <--- wall2
* o
* D
* Here wall [AB] is a big wall, then it intersects wall [CD] whether in A nor in B
* What happens in this method:
* 1. [AB] will be splited in two lines [AC] and [CB]
* 2. [AB] will be removed
* 3. [AC] or [CB] will be added to the subroom
*
* How do we choose between [AC] and [CB]
* We count for [AC] if it has more than 2 common points with walls+transitions+crossings of the subroom.
* If so, then we take [AC] otherwise we take [CB]
*
* Assumption: We assume one of the new lines need to be added.
*
* Is there a case where none should be chosen?
* @TODO: What happens if the line is "really" big? Here we should call the function in a recursive way..
*
*/
bool correct() const;
/**
* bigWall split into newWall and newWall2
* Add newWall OR newWall2 to subroom
*
* How do we choose between [AC] and [CB]
*
* We count for [AC] if it has more than 2 common points with walls+transitions+crossings of the subroom.
* If so, then we take [AC] otherwise we take [CB]
* Assumption: We assume one of the new lines need to be added.
*
* Is there a case where none should be chosen?
*
* @TODO: Maybe we should not pass bigWall here. It's just checked for equality
*
*/
bool add_wall_to_subroom(
const std::shared_ptr<SubRoom> & subroom,
const Wall& bigWall,
const Wall& newWall, const Wall& newWall2) const;
};
#endif /* _BUILDING_H */
......@@ -120,7 +120,7 @@ bool GradientModel::Init (Building* building)
pedsToRemove.clear();
bool error_occurred = false;
#pragma omp parallel for
for(signed int p=0;p<allPeds.size();p++) {
for(unsigned int p=0;p<allPeds.size();p++) {
Pedestrian* ped = allPeds[p];
double cosPhi, sinPhi;
//a destination could not be found for that pedestrian
......
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