18 #include "Tympan/core/config.h"
42 double b_x,
double b_y)
44 double l2 = (a_x - b_x) * (a_x - b_x) + (a_y - b_y) * (a_y - b_y);
47 double t = ((point_x - a_x) * (b_x - a_x) + (point_y - a_y) * (b_y - a_y)) / l2;
50 return (point_x - a_x) * (point_x - a_x) + (point_y - a_y) * (point_y - a_y);
54 return (point_x - b_x) * (point_x - b_x) + (point_y - b_y) * (point_y - b_y);
58 return (point_x - (a_x + t * (b_x - a_x))) * (point_x - (a_x + t * (b_x - a_x))) +
59 (point_y - (a_y + t * (b_y - a_y))) * (point_y - (a_y + t * (b_y - a_y)));
62 return (point_x - a_x) * (point_x - a_x) + (point_y - a_y) * (point_y - a_y);
105 if (TYMaillage::operator!=(rhs))
152 return "TYBoundaryNoiseMap";
166 for (
size_t i = 0; i < nbPoints; ++i)
178 bool nbPointsIsOk =
false;
179 bool bOldDatas =
false;
189 QDomNodeList childs = domElement.childNodes();
190 for (
unsigned int i = 0; i < childs.length(); i++)
192 elemCur = childs.item(i).toElement();
209 compatibilityVector->push_back(pSpectre);
214 if (bOldDatas ==
true)
220 delete compatibilityVector;
232 QString fileName = QString(sFilePath.c_str());
233 int i = fileName.lastIndexOf(
'/');
234 QDir fileDirectory = QDir(fileName.mid(0, i));
235 if (!fileDirectory.exists())
237 fileDirectory.mkdir(fileName.mid(0, i));
240 if (fileName.isEmpty())
244 if (!fileName.endsWith(
".xml"))
251 xmlManager.
createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
254 if (xmlManager.
save(fileName) == 0)
265 QString fileName = QString(sFilePath.c_str());
267 if (fileName.isEmpty())
274 if (xmlManager.
load(fileName, elements))
276 if (elements.size() == 1)
279 if (strcmp(elt->
getClassName(),
"TYBoundaryNoiseMap") == 0)
295 xmlManager.
createDoc(TY_PRODUCT_XMLTAG_, TY_PRODUCT_VERSION_);
300 return retString.toStdString();
309 if (xmlManager.
loadFromString(QString(sXMLString.c_str()), elements))
311 if (elements.size() == 1)
314 if (strcmp(elt->
getClassName(),
"TYBoundaryNoiseMap") == 0)
344 const size_t nbPoints =
_tabPoint.size();
345 for (
size_t i = 0; i < nbPoints; ++i)
350 double box_x_min = 0., box_x_max = 0., box_y_min = 0., box_y_max = 0.;
359 double& box_y_max)
const
368 double current_x = 0.;
369 double current_y = 0.;
370 for (
size_t i = 1; i < length; ++i)
375 box_x_min =
std::min(box_x_min, current_x);
376 box_x_max = std::max(box_x_max, current_x);
378 box_y_min =
std::min(box_y_min, current_y);
379 box_y_max = std::max(box_y_max, current_y);
391 int nb_points_x = std::ceil((box_x_max - box_x_min) *
_density);
392 int nb_points_y = std::ceil((box_y_max - box_y_min) *
_density);
393 const double step_x = (box_x_max - box_x_min) / (
double)nb_points_x;
394 const double step_y = (box_y_max - box_y_min) / (
double)nb_points_y;
400 int nbPoints = nb_points_x * nb_points_y;
404 double current_x = 0.;
405 double current_y = 0.;
408 const size_t nb_segment =
_closed ? length : length - 1;
410 for (
int i = 0; i < nb_points_x; ++i)
412 current_x = box_x_min + i * step_x;
413 for (
int j = 0; j < nb_points_y; ++j)
415 int index2D = i * nb_points_y + j;
416 current_y = box_y_min + j * step_y;
417 for (
size_t k = 0; k < nb_segment; ++k)
419 l = (k < length - 1) ? k + 1 : 0;
422 if (squared_distance <= squared_thick)
438 return 2.0 / thickness;
Graphical representation of the BoundaryNoiseMap entity (header file)
double compute_segment_point_square_distance(double point_x, double point_y, double a_x, double a_y, double b_x, double b_y)
Compute the squared distance between a point and a segment.
TY_EXTENSION_INST(TYBoundaryNoiseMap)
TY_EXT_GRAPHIC_INST(TYBoundaryNoiseMap)
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
std::vector< LPTYSpectre > TYTabLPSpectre
Collection de TYSpectre.
std::vector< LPTYElement > LPTYElementArray
virtual const char * getClassName() const
This class represents a polyline with a thickness. Acoustic receptors are sampled inside this region.
virtual DOM_Element toXML(DOM_Element &domElement)
std::vector< int > _ptsIndices
Array of points indices : -1 means the point doesn't exist.
void computePoints(double box_x_min, double box_x_max, double box_y_min, double box_y_max)
Compute the calcul points.
bool fromXMLString(const std::string &sXMLString)
virtual void clearResult()
Clear result.
TYTabPoint _tabPoint
The tab point defining the polyline.
bool _canBeClosed
If the polyline can be closed.
bool operator!=(const TYBoundaryNoiseMap &other) const
Operator !=.
static double computeMinimumDensity(double thickness)
Return the minimum density to get a correct sampling.
int _nbPointsY
Number of points in column y (rectangular bounding box).
virtual void make(const TYTabPoint &tabPoints, double thickness, bool closed, double density=TY_MAILLAGE_DEFAULT_DENSITE)
Build the table of TYPointCalcul around the polyline.
void computeBoundingBox(double &box_x_min, double &box_x_max, double &box_y_min, double &box_y_max) const
Compute the bounding box of the polyline.
double _density
Density of points (number of points per meter).
virtual int getIndexPtCalcul(int x, int y) const
Return the index.
virtual std::string toString() const
TYPoint _posLabel
The position of the label.
virtual int fromXML(DOM_Element domElement)
virtual void getDimensions(int &x, int &y) const
Return the dimensions in x and y.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
std::string toXMLString()
bool _closed
If the polyline is closed.
double _thickness
Thickness of the polyline (in meters).
bool operator==(const TYBoundaryNoiseMap &other) const
Operator ==.
virtual ~TYBoundaryNoiseMap()
Destructor. TYBoundaryNoiseMap destructor.
TYBoundaryNoiseMap & operator=(const TYBoundaryNoiseMap &other)
Operator =.
TYBoundaryNoiseMap()
Constructor. TYBoundaryNoiseMap constructor.
QString _name
Nom courant de l'element.
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
void setAllUses(void *allUses)
virtual void setIsGeometryModified(bool isModified)
double _hauteur
La hauteur par rapport au sol (a l'altimetrie en fait) a laquelle se trouve ce maillage.
virtual void clearResult()
bool addPointCalcul(LPTYPointCalcul pPtCalcul)
Ajoute un nouveau point de calcul.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYTabLPPointCalcul _ptsCalcul
Liste des points de calcul.
virtual int fromXML(DOM_Element domElement)
TYMaillage & operator=(const TYMaillage &other)
Operateur =.
void remAllPointCalcul()
Suppression de tous les elements.
virtual DOM_Element toXML(DOM_Element &domElement)
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
void setSpectre(const LPTYSpectre spectre)
Set du spectre resultat d'un calcul donne.
int save(QString fileName)
int load(const QString &fileName, LPTYElementArray &eltCollection)
void createDoc(QString docName, QString version)
int addElement(TYElement *pElt)
int loadFromString(const QString &xmlString, LPTYElementArray &eltCollection)