Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPolyligneParcours.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 /*
17  *
18  */
19 
20 #include "TYPolyligneParcours.h"
21 
22 #include "Tympan/core/macros.h"
23 #include <stdio.h>
24 #include <assert.h>
25 
27 {
28  _nNbPoint = 0;
29  _nNbPointAlloue = 0;
30  _PtrPoints = NULL;
31  _PolyligneP0 = NULL;
32  _PolyligneP1 = NULL;
33 }
34 
36 {
37  desallouer();
38 }
39 
40 bool TYPolyligneParcours::allouer(int nNbPoint)
41 {
42  this->_nNbPointAlloue = nNbPoint;
44  return NULL != this->_PtrPoints;
45 }
46 
48 {
50 }
51 
53 {
54  assert(indexe < _nNbPointAlloue);
55  setPoint(indexe, p);
56  if (indexe >= _nNbPoint)
57  {
58  _nNbPoint++;
59  }
60 }
61 
63 {
64  _PtrPoints[indexe] = p;
65 }
66 
68 {
69  // Pour l'instant, cette fonction est tres simplifiee (on considere qu'on n'a pas encore de points):
70  assert(_nNbPoint == 0);
71  assert(_PtrPoints == NULL);
72  allouer(2);
73  ajoutePoint(0, p1);
74  ajoutePoint(1, p2);
75 #ifndef NDEBUG
76  bool bverifieNaturePolylignes =
77 #endif
79  assert(bverifieNaturePolylignes);
80 }
81 
83 {
84  assert(_nNbPoint == 2);
85  return (_PtrPoints[0]->isInfra && _PtrPoints[1]->isInfra);
86 }
87 
89 {
90  assert(_nNbPoint == 2);
91  return (_PtrPoints[0]->isEcran && _PtrPoints[1]->isEcran);
92 }
93 
95 {
96  assert(_nNbPoint == 2);
97  bool isInfra0 = _PtrPoints[0]->isInfra;
98  bool isInfra1 = _PtrPoints[1]->isInfra;
99  bool isEcran0 = _PtrPoints[0]->isEcran;
100  bool isEcran1 = _PtrPoints[1]->isEcran;
101  // 1. verifier que l'infrastructure ne se melange pas a la topo,
102  // et que dans l;'infra, les ecrans ne se melangent pas avec le reste:
103  if (isInfra0 != isInfra1 || isEcran0 != isEcran1)
104  {
105  return false;
106  }
107  // 2. verifier la coherence infra-ecran,
108  if ((!isInfra0 && isEcran0) || (!isInfra1 && isEcran1))
109  {
110  return false;
111  }
112 
113  return true;
114 }
115 
117 {
118  assert(_nNbPoint == 2);
119  if (_PolyligneP1 == NULL && _PolyligneP0 == NULL)
120  {
121  return estFermee();
122  }
123  else // il faut parcourir toutes les voisines jusqu'a bouclage
124  {
125  int IndexPoint = _PtrPoints[0]->Identifiant;
126  TYPolyligneParcours* PolyligneSuivante = NULL;
127  do
128  {
129  IndexPoint = indexePointSuivant(IndexPoint, PolyligneSuivante);
130  } while (PolyligneSuivante != NULL && this != PolyligneSuivante);
131  bool bFermee = (this == PolyligneSuivante);
132  return bFermee;
133  }
134  return false;
135 }
136 
137 int TYPolyligneParcours::indexePointSuivant(int IndexPoint, TYPolyligneParcours*& PolyligneSuivante)
138 {
139  // Verifications
140  assert(_nNbPoint == 2);
142  if (bAssert)
143  {
144  bAssert = true;
145  }
146  // Cherchons l'index du prochain point; il ne doit pas etre egal a l'indexe courant
147  int IndexPointSuivant = autrePointDuSegment(IndexPoint);
148  assert(IndexPointSuivant >= 0);
149  // Trouver la polyligne suivante
150  PolyligneSuivante =
151  polyligneSuivante(IndexPointSuivant); // point suivant, partage par la prochaine polyligne
152 
153  return IndexPointSuivant;
154 }
155 
157 {
158  assert(_nNbPoint == 2); //_PolyligneP0 & _PolyligneP1 sont relatives aux points P0 & P1
159  if (_PolyligneP0 == _PolyligneP1)
160  {
161  if (_PolyligneP0 != NULL)
162  {
163  return true;
164  }
165  }
166  return false;
167 }
168 
170 {
171  assert(_nNbPoint == 2); //_PolyligneP0 & _PolyligneP1 sont relatives aux points P0 & P1
172  if (IndexPoint == _PtrPoints[0]->Identifiant)
173  {
174  return _PtrPoints[1]->Identifiant;
175  }
176  else
177  {
178  if (IndexPoint == _PtrPoints[1]->Identifiant)
179  {
180  return _PtrPoints[0]->Identifiant;
181  }
182  }
183 
184  return -1; // pas de point trouve
185 }
186 
188 {
189  // IndexPoint = point suivant, partage par la prochaine polyligne
190  if (IndexPoint == _PtrPoints[0]->Identifiant)
191  {
192  return _PolyligneP0;
193  }
194  if (IndexPoint == _PtrPoints[1]->Identifiant)
195  {
196  return _PolyligneP1;
197  }
198  return NULL;
199 }
200 
202 {
204  {
205  return false;
206  }
207  return true;
208 }
209 
211 {
212  assert(_nNbPoint > 0);
213  return _PtrPoints[i]->Identifiant;
214 }
215 
217 {
218  return _PtrPoints[0]->Identifiant;
219 }
220 
222 {
223  return _PtrPoints[_nNbPoint - 1]->Identifiant;
224 }
225 
227 {
228  desallouer();
229  allouer(p._nNbPoint);
230  // Copie des ptr de points
231  for (int i = 0; i < _nNbPoint; i++)
232  {
233  _PtrPoints[i] = p._PtrPoints[i];
234  }
235  // Copie des ptr de TYPolyligneParcours
238 }
239 
240 bool TYPolyligneParcours::extendPtrPoints(int nNouvelleTaille)
241 {
242  assert(nNouvelleTaille >= _nNbPoint);
243  TYPointParcours** newPtrPoints = new TYPointParcours*[nNouvelleTaille];
244  // Copie des ptr de points
245  for (int i = 0; i < _nNbPoint; i++)
246  {
247  newPtrPoints[i] = this->pointPtr(i);
248  }
249 
251  this->_PtrPoints = newPtrPoints;
252 
253  this->_nNbPointAlloue = nNouvelleTaille;
254  return NULL != this->_PtrPoints;
255 }
Polylines path class used by the TYSetGeometriqueParcours class.
void ajoutePoint(int indexe, TYPointParcours *p)
Add a point.
TYPointParcours ** _PtrPoints
Array of pointers to points.
int indexePremierPoint()
Return point id of first point of the polyline.
int _nNbPoint
Number of points on the polyline.
TYPolyligneParcours * _PolyligneP1
Pointer to the next polyline (from P1 point)
bool allouer(int nNbPoint)
Allocate nNbPoint points to the polyline.
void desallouer()
Delete list of points of the polyline.
void ajouteSegment(TYPointParcours *p1, TYPointParcours *p2)
Add a first polyline with two points p1 and p2.
bool extendPtrPoints(int nNouvelleTaille)
Extends the attribute array _PtrPoints.
bool estSurUnParcourFermee()
Return true if the polyline belongs to a closed path.
bool polylignesVoisinesPointentSurLaMemePolyligne()
Return true if _PolyligneP0 and _PolyligneP1 exist and are the same.
int indexeDernierPoint()
Return point id of last point of the polyline.
void setPoint(int indexe, TYPointParcours *p)
Change a point.
int indexePointSuivant(int IndexPoint, TYPolyligneParcours *&PolyligneSuivante)
Return the point id of the next point given by IndexPoint id.
bool estFermee()
Return true if the polyline is closed.
TYPointParcours * pointPtr(int indexe)
Return a pointer on the point Pi.
int autrePointDuSegment(int IndexPoint)
Return P0 if IndexPoint is the point id of P1, else P1 if it is the id of P0, else -1.
bool isEcran()
Return true if P0 and P1 are Ecran.
~TYPolyligneParcours()
Destructor.
TYPolyligneParcours * polyligneSuivante(int IndexPoint)
Return the next polyline pointed by the Point id IndexPoint.
TYPolyligneParcours * _PolyligneP0
Pointer to the previous polyline (from P0 point)
bool isInfra()
Return true if P0 and P1 are Infra.
void Copy(TYPolyligneParcours &p)
Copy operator.
TYPolyligneParcours()
Default constructor.
int indexePoint(int i)
Return point id of point i of the polyline.
int _nNbPointAlloue
Number of allocated points on the polyline.
#define SAFE_DELETE_LIST(_p)
Definition: macros.h:239
Point of a path.
bool isInfra
Flag set to indicate if the point is an infrastructure.
int Identifiant
Point id.
bool isEcran
Flag set to indicate if the point is a screen.