22 #include <boost/current_function.hpp>
23 #include <boost/foreach.hpp>
42 static inline double grid_step(
double nb_triangles)
44 return sqrt(nb_triangles) / 2;
91 if (TYElement::operator!=(other))
116 assert(pOtherAlt &&
"The TYElement given was no TYAltimetry.");
120 for (
unsigned int i = 0; i <
_listFaces.size(); i++)
130 for (
int k = 0; k <
_gridSX; k++)
131 for (
int l = 0; l <
_gridSY; l++)
135 for (
unsigned int m = 0; m < nbFaces; m++)
148 return "TYAltimetrie";
166 std::deque<LPTYSol>& materials)
168 assert(vertices.empty() &&
"'vertices' output argument must be passed empty to TYAltimetrie::exportMesh");
169 assert(faces.empty() &&
"'faces' output argument must be passed empty to TYAltimetrie::exportMesh");
170 assert(materials.empty() &&
171 "'materials' output argument must be passed empty to TYAltimetrie::exportMesh");
178 std::deque<OTriangle>& triangles,
179 const std::deque<LPTYSol>& materials)
181 const size_t nbTriangles = triangles.size();
205 for (i = 0; i < nbTriangles; i++)
211 oTriangle.
_A = vertices[oTriangle.
_p1];
213 oTriangle.
_B = vertices[oTriangle.
_p2];
215 oTriangle.
_C = vertices[oTriangle.
_p3];
222 if (nbTriangles == 0)
230 float fsx = grid_step(nbTriangles);
238 for (i = 0; i < nbTriangles; i++)
245 for (j = 0; j < 3; j++)
247 tabPt[j] = oTriangle.
vertex(j);
250 assert(pPolygon != NULL);
259 unsigned int ipmin = 0, ipmax = 0, iqmin = 0, iqmax = 0;
260 ipmin = iqmin = std::numeric_limits<unsigned int>::max();
262 for (j = 0; j < 3; j++)
272 ipmax = std::max(ipmax, idx.
pi);
273 iqmax = std::max(iqmax, idx.
qi);
279 for (
int k = ipmin; k <= ipmax; k++)
280 for (
int l = iqmin; l <= iqmax; l++)
306 TYTabLPPolygon::iterator ite;
326 TYTabLPPolygon::iterator ite;
330 if ((*ite)->getID() == idFace)
350 double x = NAN, y = NAN;
351 double xa = NAN, ya = NAN, xb = NAN, yb = NAN, xc = NAN, yc = NAN;
352 double bx = NAN, by = NAN, cx = NAN, cy = NAN;
353 double hx = NAN, hy = NAN;
354 double a2 = NAN, a3 = NAN;
371 a2 = (bx * hy - by * hx) / (bx * cy - by * cx);
372 a3 = (hx * cy - hy * cx) / (bx * cy - by * cx);
399 unsigned int pi = idx.
pi, qi = idx.
qi;
406 for (
size_t i = 0; i < pDivRef->size(); i++)
408 pFace = pDivRef->at(i);
426 unsigned int iMinMax[4];
439 unsigned int faceCount = 0;
440 for (
size_t i = 0; i < faces.size(); i++)
443 for (
size_t y = 0; y < pts.size(); y++)
447 tabPolygon.push_back(faces[i]);
456 for (
size_t i = 0; i < faces.size(); i++)
458 tabPolygon.push_back(faces[i]);
468 unsigned int pointCount = 0;
475 unsigned int iMinMax[4];
489 for (
size_t i = 0; i < faces.size(); i++)
492 for (
size_t y = 0; y < ptsFaces.size(); y++)
496 tabPoints.push_back(ptsFaces[y]);
527 double p = NAN, q = NAN;
528 unsigned pi = 0, qi = 0;
541 assert((pi >= 0) && (qi >= 0) && (pi <
_gridSX) && (qi <
_gridSY));
551 unsigned minX = std::numeric_limits<unsigned>::max();
553 unsigned minY = std::numeric_limits<unsigned>::max();
561 for (
size_t i = 0; i < 4; i++)
566 maxX = std::max(maxX, iXY.
pi);
567 maxY = std::max(maxY, iXY.
qi);
582 for (
int i = 1, j = 0; i < 5; i++, j++)
593 std::map<LPTYPolygon, int> mapFaces;
597 for (
unsigned int i = minX; i <= maxX; i++)
599 for (
unsigned int j = minY; j <= maxY; j++)
602 for (
size_t k = 0; k < pDivRef->size(); k++)
604 mapFaces[pDivRef->at(k)] = i * j *
static_cast<int>(k);
610 std::map<LPTYPolygon, int>::iterator it;
611 for (it = mapFaces.begin(); it != mapFaces.end(); it++)
613 faces.push_back(it->first);
622 const double M_DOUBLE_INFINITE = 1e6;
643 segTest.
_ptA = ptTest;
644 segTest.
_ptB = ptTest;
645 segTest.
_ptA.
_z = +M_DOUBLE_INFINITE;
646 segTest.
_ptB.
_z = -M_DOUBLE_INFINITE;
655 assert(ptTest.
_z ==
invalid_altitude &&
"invalid_altitude expected to denote failure");
679 double dHauteurMoyenne = 0;
683 for (
unsigned int i = 0; i < pts.size(); i++)
689 dHauteurMoyenne += pts.at(i)._z - pt.
_z;
693 if (nNbHauteurs == 0 || dHauteurMoyenne < 0)
698 dHauteurMoyenne /= nNbHauteurs;
699 return dHauteurMoyenne;
710 courant.
_x = ptsIn.at(i)._x;
711 courant.
_y = ptsIn.at(i)._y;
717 dHauteur = ptsIn.at(i)._z - courant.
_z;
719 }
while (dHauteur < 0 && i < (
int)ptsIn.size());
742 for (
int k = 0; k <
_gridSX; k++)
744 for (
int l = 0; l <
_gridSY; l++)
757 assert(
_pSortedFaces == NULL &&
"The accelerating grid must have been cleared.");
758 assert(
_gridSX &&
_gridSY &&
"The size of the grid must be positive.");
761 for (
int k = 0; k <
_gridSX; k++)
764 for (
int l = 0; l <
_gridSY; l++)
781 for (
int k = 0; k <
_gridSX; k++)
782 for (
int l = 0; l <
_gridSY; l++)
All base classes related to 3D manipulation.
#define INTERS_OUI
The intersection exists.
Representation graphique de l'altimetrie (fichier header)
TY_EXTENSION_INST(TYAltimetrie)
TY_EXT_GRAPHIC_INST(TYAltimetrie)
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
std::vector< LPTYPolygon > TYTabLPPolygon
Collection de pointeurs de TYPolygon.
Class to define a box (not necessary parallel to the axis as OBox)
virtual bool isInside(const OPoint3D &pt) const
Test whether the point is inside the box or not.
OPoint3D BoxCoord(int N) const
Returns the coordinates of one of the box corner. \ We consider that the first corner is the one on t...
virtual bool isInside2D(const OPoint3D &pt) const
Test whether the point is inside the box or not (from upper point of view).
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
OPoint3D _min
Minimal coordinates of the OBox.
OPoint3D _max
Maximal coordinates of the OBox.
double _y
y coordinate of OCoord3D
double _z
z coordinate of OCoord3D
double _x
x coordinate of OCoord3D
static bool pointInPolygonRayCasting(const OPoint3D &ptP, const OPoint3D *pts, int nbPts)
Tests if a point is inside a polygon using ray casting algorithm.
virtual OPrototype * clone() const =0
virtual const char * getClassName() const
Class to define a segment.
OPoint3D _ptA
Point A of the segment.
OPoint3D _ptB
Point B of the segment.
OPoint3D _A
First OPoint3D.
int _p1
Index of the first OPoint3D _A.
int _p3
Index of the third OPoint3D _C.
OPoint3D _C
Third OPoint3D.
OPoint3D _B
Second OPoint3D.
int _p2
Index of the second OPoint3D _B.
OPoint3D & vertex(unsigned i)
Get the OPoint3D from the specific index.
Assigne une altitude a chaque point de l'espace.
void copyAcceleratingGrid(const TYAltimetrie &other)
Clear the grid and reinitialise it as a copy of other.
static const double invalid_altitude
LPTYPolygon getFace(int index)
double PremiereHauteurPositiveOuNulle(TYTabPoint &ptsIn)
void exportMesh(std::deque< OPoint3D > &vertices, std::deque< OTriangle > &faces, std::deque< LPTYSol > &materials)
bool operator!=(const TYAltimetrie &other) const
Operateur !=.
double HauteurMoyenne(TYTabPoint &pts)
std::deque< LPTYSol > _materials
bool operator==(const TYAltimetrie &other) const
Operateur ==.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYTabLPPolygon ** _pSortedFaces
void clearAcceleratingGrid()
clean the accelerating structure
bool addFace(LPTYPolygon pFace)
void initNullGrid()
Initilise the grid related attributes for a null grid.
virtual DOM_Element toXML(DOM_Element &domElement)
void getFacesinIndices(unsigned int &minX, unsigned int &maxX, unsigned int &minY, unsigned int &maxY, TYTabLPPolygon &faces)
Select faces in the interval minX, maxX, minY, maxY.
TYAltimetrie & operator=(const TYAltimetrie &other)
Operateur =.
bool getGridIndices(const OPoint3D &pt, grid_index &indXY) const
Select indices of faces to test.
OBox _bbox
Bounding Box 2D de l'altimetrie.
unsigned int getPointsInBox(const OPoint3D &pt0, const OPoint3D &pt1, const OPoint3D &pt2, const OPoint3D &pt3, TYTabPoint &tabPolygon)
find a list of point included in a box defined by four points
OPoint3D projection(const OPoint3D &pt) const
Calcule les coordonnees de la projection au sol d'un point de l'espace.
LPTYPolygon getFaceUnder(OPoint3D pt)
Return the face under a point.
unsigned int getFacesInBox(const OBox2 &box, TYTabLPPolygon &tabPolygon)
find a list of triangle partialy or totaly included in a box
double altitude(const OPoint3D &pt)
virtual int fromXML(DOM_Element domElement)
bool updateAltitude(OPoint3D &pt) const
Modifie l'altitude d'un point donn�. Si le point est hors de la zone dans laquelle l'altim�trie e...
bool remFace(const LPTYPolygon pFace)
bool IsInsideFace(const TYTabPoint &pts, OPoint3D &pt) const
void plugBackTriangulation(const std::deque< OPoint3D > &points, std::deque< OTriangle > &triangles, const std::deque< LPTYSol > &materials)
plug back triangulation providfed by the TYTopographie
unsigned _gridSX
Size along each dimension of the accelerating grid.
double _gridDX
Step along each dimension of the accelerating grid.
std::deque< OTriangle > _faces
void initAcceleratingGrid(unsigned to_be_reserved=0)
initialise the accelerating structure given current _bbox and _gridS{XY}
TYTabLPPolygon _listFaces
Liste des polygones correspondant aux faces de cet altimetrie.
std::deque< OPoint3D > _vertices
virtual std::string toString() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual DOM_Element toXML(DOM_Element &domElement)
QString _name
Nom courant de l'element.
TYElement & operator=(const TYElement &other)
void setParent(TYElement *pParent)
virtual int fromXML(DOM_Element domElement)
virtual void setIsGeometryModified(bool isModified)
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
const TYTabPoint & getPoints() const
void setConvex(bool bConvex)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual int intersects(const TYSurfaceInterface *pSurf, OSegment3D &seg) const
#define tympan_source_loc
This macro build a source_loc object to be attached to a tympan::Exception.
boost::error_info< struct tag_position, OPoint3D > position_errinfo
Integer coordinates into the grid.
The base exception class for errors due to invalid data.
The base exception class for internal logic / algorithmic errors.