owlps/owlps-positioner/src/area.cc

208 lines
4.8 KiB
C++
Raw Normal View History

/*
* This file is part of the Owl Positioning System (OwlPS).
* OwlPS is a project of the University of Franche-Comte
* (Université de Franche-Comté), France.
*
* Copyright © Université de Franche-Comté 2007-2012.
*
* Corresponding author: Matteo Cypriani <mcy@lm7.fr>
*
***********************************************************************
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL:
* http://www.cecill.info
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided
* only with a limited warranty and the software's authors, the holder
* of the economic rights, and the successive licensors have only
* limited liability.
*
* In this respect, the user's attention is drawn to the risks
* associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status
* of free software, that may mean that it is complicated to manipulate,
* and that also therefore means that it is reserved for developers and
* experienced professionals having in-depth computer knowledge. Users
* are therefore encouraged to load and test the software's suitability
* as regards their requirements in conditions enabling the security of
* their systems and/or data to be ensured and, more generally, to use
* and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
***********************************************************************
*/
#include "area.hh"
#include "building.hh"
using namespace std ;
/* *** Constructors *** */
Area::Area(const Building *_building, const string &_name,
const Point3D &p1, const Point3D &p2):
building(const_cast<Building*>(_building)), name(_name)
{
set_coordinates(p1, p2) ;
}
/* *** Operations *** */
/**
* @return \em true if \em p is into the Area.
* @return \em false if \em p is not into the Area.
*/
bool Area::contains_point(const Point3D &p) const
{
return
p.get_x() >= p_min.get_x() &&
p.get_x() <= p_max.get_x() &&
p.get_y() >= p_min.get_y() &&
p.get_y() <= p_max.get_y() &&
p.get_z() >= p_min.get_z() &&
p.get_z() <= p_max.get_z() ;
}
/**
* Changes the Area coordinates so that #p_min is the South-West-lower
* point and #p_max the North-East-higher point.
*/
void Area::reorder_coordinates()
{
float
x1 = p_min.get_x(),
y1 = p_min.get_y(),
z1 = p_min.get_z(),
x2 = p_max.get_x(),
y2 = p_max.get_y(),
z2 = p_max.get_z(),
x_min, x_max, y_min,
y_max, z_min, z_max ;
// 2-D coordinates (X and Y) //
// First point is North-West
if (x1 < x2 && y1 > y2)
{
x_min = x1 ;
x_max = x2 ;
y_min = y2 ; // We swap the two Y
y_max = y1 ;
}
// First point is South-East
else if (x1 > x2 && y1 < y2)
{
x_min = x2 ; // We swap the two X
x_max = x1 ;
y_min = y1 ;
y_max = y2 ;
}
// First point is North-East
else if (x1 > x2 && y1 > y2)
{
x_min = x2 ; // We swap the two X
x_max = x1 ;
y_min = y2 ; // and we swap the two Y
y_max = y1 ;
}
// First point is South-West
2011-05-04 19:20:46 +02:00
// (or other cases such as coordinates equal to zero)
else
{
// We swap nothing
x_min = x1 ;
x_max = x2 ;
y_min = y1 ;
y_max = y2 ;
}
// Vertical coordinate (Z) //
// First point is lower
if (z1 < z2)
{
z_min = z1 ;
z_max = z2 ;
}
// First point is higher
else
{
// We swap the two Z
z_min = z2 ;
z_max = z1 ;
}
p_min = Point3D(x_min, y_min, z_min) ;
p_max = Point3D(x_max, y_max, z_max) ;
}
/* *** Operators *** */
Area& Area::operator=(const Area &source)
{
if (this == &source)
return *this ;
building = source.building ;
name = source.name ;
p_min = source.p_min ;
p_max = source.p_max ;
return *this ;
}
bool Area::operator==(const Area &source) const
{
if (this == &source)
return true ;
return
building == source.building &&
name == source.name &&
p_min == source.p_min &&
p_max == source.p_max ;
}
GuiNuMo : gestion topologie server.{hh,cc} : * Utilisation d'une map plutôt que d'une multimap pour stocker la liste des pièces. Conséquence : les noms des zones doivent être uniques, il faut donc numéroter les zones des pièces composites (par exemple « Couloir N1 A » et « Couloir N1 B »). * Ajout de la fonction inWhichAreas() qui permet d'obtenir la liste des zones auxquelles appartient un point. * Modification de la fonction makeWaypointDistancesFromFile() (renommée makeWaypointListFromFile()) de manière à ce qu'elle calcule la matrice des distances entre points de passage (lecture d'une liste de points). Abandon du format décrivant les points en visibilité (voir le fichier cfg/distances.csv, supprimé à cette révision), puisque nous nous servons des points de passage et de la description des zones pour calculer les liens entre points. RESTE À FAIRE : prise en comppte de la topologie dans le calcul de distance. * Ajout de deux fonctions areaConnection() qui permettent de récupérer la liste des points de passage d'une zone, ou faisant l'intersection entre deux zones. * Ajout de la fonction distanceTopology, qui calcule la distance entre deux points en tenant compte de la topologie (zones et points de passage entre elles). * Ajout de la fonction makeReferencePointDistances(), qui calcule les distances entre points de référence, en tenant compte de la topologie. * Ajout de la fonction point_vector_idx(), semblable à point_tab_idx() mais pour un vector<Point>. referencepoint.{hh,cc} : * Ajout de l'operator de cast en Point (operator Point()). area.{hh,cc} : * Ajout de l'operator==(Area). cfg/distances.csv * Suppression de ce fichier obsolète. git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@47 785a6c6c-259e-4ff1-8b91-dc31627914f0
2008-06-25 16:19:07 +02:00
/**
* Note: to avoid looping, the Building associated with the Area is
* not displayed.
*/
ostream &operator<<(ostream &os, const Area &a)
{
os
<< (a.building ? a.building->get_name() : "No building") << ';'
<< a.name << ';'
<< a.p_min.get_x() << ';'
<< a.p_max.get_x() << ';'
<< a.p_min.get_y() << ';'
<< a.p_max.get_y() << ';'
<< a.p_min.get_z() << ';'
<< a.p_max.get_z() ;
return os ;
}