Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticSemiCylinder.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 #include "Tympan/core/logging.h"
18 #if TY_USE_IHM
22 #endif
23 #include "TYAcousticSemiCylinder.h"
24 
27 
29 {
31 
32  // Couleur par default
33  float r = 255.0f, g = 67.0f, b = 133.0f;
34 
35 #if TY_USE_IHM
36  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "TYAcousticSemiCylinderGraphicColorR"))
37  {
38  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "TYAcousticSemiCylinderGraphicColor", r, g, b);
39  }
40  else
41  {
42  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "TYAcousticSemiCylinderGraphicColor", r, g, b);
43  }
44 #endif // TY_USE_IHM
45 
46  OColor color;
47  color.r = r / 255;
48  color.g = g / 255;
49  color.b = b / 255;
50 
51  setColor(color);
52 
54  _pEnveloppe->setParent(this);
55 
58  TYRectangle(TYPoint(0, 1, 0.5), TYPoint(1, 1, 0.5), TYPoint(1, -1, 0.5), TYPoint(0, -1, 0.5));
59  _pSemiCircTop->setParent(this);
60 
63  TYRectangle(TYPoint(0, -1, -0.5), TYPoint(1, -1, -0.5), TYPoint(1, 1, -0.5), TYPoint(0, 1, -0.5));
65 
66  // Surface laterale
68  _pAccRect->setParent(this);
69  _pAccRect->setColor(color);
70  updateRect();
71 
76 }
77 
79 {
80  *this = other;
81 }
82 
84 
86 {
87  if (this != &other)
88  {
90  _pEnveloppe = other._pEnveloppe;
91  _pAccRect = other._pAccRect;
94  }
95 
100 
101  return *this;
102 }
103 
105 {
106  if (this != &other)
107  {
108  if (TYAcousticVolume::operator!=(other))
109  {
110  return false;
111  }
112  if (_pEnveloppe != other._pEnveloppe)
113  {
114  return false;
115  }
116  if (_pAccRect != other._pAccRect)
117  {
118  return false;
119  }
120  if (_pSemiCircTop != other._pSemiCircTop)
121  {
122  return false;
123  }
124  if (_pSemiCircBottom != other._pSemiCircBottom)
125  {
126  return false;
127  }
128  }
129  return true;
130 }
131 
133 {
134  return !operator==(other);
135 }
136 
137 bool TYAcousticSemiCylinder::deepCopy(const TYElement* pOther, bool copyId /*=true*/,
138  bool pUseCopyTag /*=false*/)
139 {
140  if (!TYAcousticVolume::deepCopy(pOther, copyId))
141  {
142  return false;
143  }
144 
145  TYAcousticSemiCylinder* pOtherSemiCyl = (TYAcousticSemiCylinder*)pOther;
146 
147  _pEnveloppe->deepCopy(pOtherSemiCyl->_pEnveloppe, copyId);
148  _pEnveloppe->setParent(this);
149  _pAccRect->deepCopy(pOtherSemiCyl->_pAccRect, copyId);
150  _pAccRect->setParent(this);
151  _pSemiCircTop->deepCopy(pOtherSemiCyl->_pSemiCircTop, copyId);
152  _pSemiCircTop->setParent(this);
153  _pSemiCircBottom->deepCopy(pOtherSemiCyl->_pSemiCircBottom, copyId);
155 
156  _volEnglob = volEnglob();
160 
161  return true;
162 }
163 
165 {
166  return "TYAcousticSemiCylinder";
167 }
168 
170 {
171  DOM_Element domNewElem = TYAcousticVolume::toXML(domElement);
172 
173  _pEnveloppe->toXML(domNewElem);
174  _pSemiCircTop->toXML(domNewElem);
175  _pSemiCircBottom->toXML(domNewElem);
176  _pAccRect->toXML(domNewElem);
177 
178  return domNewElem;
179 }
180 
182 {
183  TYAcousticVolume::fromXML(domElement);
184 
185  bool semiCircTopFound = false;
186  bool semiCircBottomFound = false;
187  bool enveloppeFound = false;
188 
189  DOM_Element elemCur;
190 
191  QDomNodeList childs = domElement.childNodes();
192  for (unsigned int i = 0; i < childs.length(); i++)
193  {
194  elemCur = childs.item(i).toElement();
195 
196  if (!enveloppeFound)
197  {
198  enveloppeFound = _pEnveloppe->callFromXMLIfEqual(elemCur);
199  }
200 
201  if (!semiCircTopFound)
202  {
203  semiCircTopFound = _pSemiCircTop->callFromXMLIfEqual(elemCur);
204  }
205  else if (!semiCircBottomFound)
206  {
207  semiCircBottomFound = _pSemiCircBottom->callFromXMLIfEqual(elemCur);
208  }
209 
210  _pAccRect->callFromXMLIfEqual(elemCur);
211  }
212 
213  if (!enveloppeFound) // Lecture d'un fichier TYMPAN 3.2
214  {
217 
218  // On ajoute autant de regime a l'enveloppe qu'il y a de regime a la machine.
219  // On prend la machine comme reference car il y a un probleme sur le modele chinon
220  // un cylindre possede 11 regimes alors que la machine n'en possede que 2.
222  size_t nbRegMachine = pMachine->getNbRegimes();
223 
224  size_t j = 0;
225  for (j = 0; j < nbRegMachine - 1; j++) // (-1) car l'enveloppe possede deja au moins un regime
226  {
228  }
229 
230  // On "construit" les regimes
231  bool statusFrom = true;
232  bool statusTo = true;
233  for (j = 0; j < _pEnveloppe->getNbRegimes(); j++)
234  {
235  TYRegime& regimeFrom = this->getRegimeNb(static_cast<int>(j), statusFrom);
236  TYRegime& regimeTo = _pEnveloppe->getRegimeNb(static_cast<int>(j), statusTo);
237 
238  if (!statusFrom || !statusTo)
239  {
240  break;
241  }
242 
243  regimeTo.deepCopy(&regimeFrom, false);
244  }
245 
247  _pEnveloppe->loadRegime(-1); // On met l'etat de l'enveloppe par rapport au regime courant
248  }
249 
250  _volEnglob = volEnglob();
254 
255  return 1;
256 }
257 
258 void TYAcousticSemiCylinder::getChilds(LPTYElementArray& childs, bool recursif /*=true*/)
259 {
260  childs.push_back(_pSemiCircTop);
261  childs.push_back(_pSemiCircBottom);
262  childs.push_back(_pAccRect);
263  childs.push_back(_pEnveloppe);
264 
265  if (recursif)
266  {
267  _pSemiCircTop->getChilds(childs, recursif);
268  _pSemiCircBottom->getChilds(childs, recursif);
269  _pAccRect->getChilds(childs, recursif);
270  _pEnveloppe->getChilds(childs, recursif);
271  }
272 
273  TYAcousticVolume::getChilds(childs, recursif);
274 }
275 
276 void TYAcousticSemiCylinder::setRegime(TYSpectre& Spectre, int regime /*=-1*/, bool recursif /*=false*/)
277 {
278  if (recursif)
279  {
280  _pEnveloppe->setRegime(Spectre, regime, recursif);
281  _pSemiCircTop->setRegime(Spectre, regime, recursif);
282  _pSemiCircBottom->setRegime(Spectre, regime, recursif);
283  _pAccRect->setRegime(Spectre, regime, recursif);
284  }
285 
286  TYAcousticInterface::setRegime(Spectre, regime, recursif);
287 }
288 
290 {
294  _pAccRect->addRegime();
295 
297 }
298 
300 {
301  _pEnveloppe->remRegime(regime);
302  _pSemiCircTop->remRegime(regime);
303  _pSemiCircBottom->remRegime(regime);
304  _pAccRect->remRegime(regime);
305 
306  return TYAcousticInterface::remRegime(regime);
307 }
308 
310 {
311  _pEnveloppe->loadRegime(regimeNb);
312  _pSemiCircTop->loadRegime(regimeNb);
313  _pSemiCircBottom->loadRegime(regimeNb);
314  _pAccRect->loadRegime(regimeNb);
315 
317 }
318 
320 {
321  _pEnveloppe->setCurRegime(regime);
322  _pSemiCircTop->setCurRegime(regime);
324  _pAccRect->setCurRegime(regime);
325 
327 
328  setIsAcousticModified(true);
329 }
330 
332 {
333  _pEnveloppe->propagateAtt(pAtt);
336  _pAccRect->propagateAtt(pAtt);
337 
339 }
340 
342 {
343  TYTabSourcePonctuelleGeoNode tab, tabTmp;
344 
345  tabTmp = _pSemiCircTop->getSrcs();
346  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
347 
348  tabTmp = _pSemiCircBottom->getSrcs();
349  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
350 
351  tabTmp = _pAccRect->getSrcs();
352  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
353 
354  tabTmp = _pEnveloppe->getSrcs();
355  tab.insert(tab.end(), tabTmp.begin(), tabTmp.end());
356 
357  return tab;
358 }
359 
361 {
362  return TYSourcePonctuelle();
363 }
364 
365 void TYAcousticSemiCylinder::setDensiteSrcsH(double densite, bool recursif /*=true*/)
366 {
367  TYAcousticVolume::setDensiteSrcsH(densite, recursif);
368 
369  if (recursif)
370  {
371  // Demi cercle bottom
373 
374  // Demi cercle top
376 
377  // Face laterale
379 
380  // Enveloppe (src surf)
382  }
383 }
384 
385 void TYAcousticSemiCylinder::setDensiteSrcsV(double densite, bool recursif /*=true*/)
386 {
387  TYAcousticVolume::setDensiteSrcsV(densite, recursif);
388 
389  if (recursif)
390  {
391  // Demi cercle bottom
393 
394  // Demi cercle top
396 
397  // Face laterale
399 
400  // Enveloppe (src surf)
402  }
403 }
404 
406 {
411 }
412 
414 {
415  if (_isRayonnant == false)
416  {
417  // Pas de calcul
418  return;
419  }
420 
421  // Demi cercle bottom
423  {
425  }
426 
427  // Demi cercle top
429  {
431  }
432 
433  // Face laterale
434  if (_pAccRect->getIsRayonnant())
435  {
437  }
438 
439  // Enveloppe (src surf)
440  if (!_pEnveloppe->getIsRayonnant() || (_pEnveloppe->getDensiteSrcsH() == 0) ||
441  (_pEnveloppe->getDensiteSrcsV() == 0))
442  {
443  return;
444  }
445 
446  // On travaille directement sur la source surfacique de l'enveloppe
448 
449  // Distance angulaire (sur la circonference de chaque cercle
450  // concentrique)
451 
452  const double distAngle = pSrcSurf->getDensiteSrcsH();
453  int nbSrcs = ROUND(M_PI * getDiameter() / (2 * distAngle)); // (pi * r /Dist
454  nbSrcs = (nbSrcs == 0) ? 1 : nbSrcs; // Minimum une source
455 
456  const double anglePortion = M_PI / (nbSrcs + 1); // Distance angulaire entre les sources
457  double distHauteur = pSrcSurf->getDensiteSrcsV();
458 
459  const double hauteurCyl = getHauteur();
460 
461  int nbCercle = (int)(hauteurCyl / distHauteur);
462  if (nbCercle == 0)
463  {
464  nbCercle = 1;
465  distHauteur = hauteurCyl / 2;
466  }
467  // Si la hauteur residuelle est inferieure a 1/2 distance entre les cercles, on retire un cercle
468  const double HResiduel = (hauteurCyl - (distHauteur * nbCercle)) / 2.0;
469  if ((nbCercle > 1) && ((HResiduel < (distHauteur / 2.0))))
470  {
471  nbCercle--;
472  }
473 
474  // Position du premier cercle de sources en partant du bas
475  double base = (hauteurCyl - (nbCercle - 1) * distHauteur) / 2.0;
476 
477  OPoint3D pt;
478  double angle = 0.0;
479  double hauteur = base;
480  double rayon = (getDiameter() / 2.0) + _offsetSources; // Decalage des sources pour le lancer de rayons
481  const double demiPi = M_PI / 2.0;
482  const double hauteurOffset = _pSemiCircBottom->getCenter()._z;
483  OPoint3D center = _pSemiCircBottom->getCenter();
484 
485  // To define directivity
486  double diag = getDiameter();
487  double specificSize = sqrt(diag * diag + (diag / 2) * (diag / 2));
489 
490  if (anglePortion > 0.0)
491  {
492  // Parcours sur la hauteur
493  for (int i = 0; i < nbCercle; i++)
494  {
495  // Init angle
496  angle = anglePortion - demiPi;
497 
498  // Pour chaque portion d'angle
499  for (int j = 0; j < nbSrcs; j++)
500  {
501  // Point correspondant
502  pt._x = cos(angle) * rayon;
503  pt._y = sin(angle) * rayon;
504  pt._z = hauteurOffset + hauteur;
505 
506  // Pour trouver la normale
507  center._z = pt._z;
508  OVector3D faceNormal(center, pt);
509  faceNormal.normalize();
510 
511  // Creation d'une source ponctuelle
513  pSrc->setDirectivity(new TYComputedDirectivity(faceNormal, type, specificSize));
514 
515  // Definition de sa position
516  *pSrc->getPos() = pt;
517 
518  // Definition des sources comme sources a directivite calculee
519  pSrc->setTypeRaynt(CALCULATED);
520 
521  // Ajout de la src ponct a la src surf
522  pSrcSurf->addSrc(pSrc);
523 
524  // Increment de la portion (sens horaire)
525  angle += anglePortion;
526  }
527 
528  // Increment de la hauteur
529  hauteur += distHauteur;
530  }
531  }
532 
533  // _pSrcSurf->setParent(this); // DT-- 20060505 Desactive pour le moment// Permet de corriger un bug
534  // (perte de parent...) constate
535 }
536 
538 {
540  {
542  }
544  {
546  }
548  {
550  }
551  if (_pAccRect->getIsRayonnant())
552  {
553  _pAccRect->setSrcsLw();
554  }
555 
556  return true;
557 }
558 
560 {
561  // (Pi.Ri¿½.h) / 2
562  double rayon = getDiameter() / 2.0;
563  return ((M_PI * rayon * rayon * getHauteur()) / 2.0);
564 }
565 
567 {
568  // Somme des surf
569  return ((2 * M_PI * (getDiameter() / 2.0) * getHauteur()) / 2.0) + // Aire laterale / 2
571 }
572 
574 {
575  double res = 0.0;
576 
578  {
579  res += _pEnveloppe->surface();
580  }
582  {
583  res = res + _pSemiCircBottom->surface();
584  }
586  {
587  res = res + _pSemiCircTop->surface();
588  }
589  if (_pAccRect->getIsRayonnant())
590  {
591  res = res + _pAccRect->surface();
592  }
593 
594  return res;
595 }
596 
598 {
599  double res = 0.0;
600 
602  {
603  res += _pSemiCircBottom->surface();
604  }
606  {
607  res += _pSemiCircTop->surface();
608  }
609  if (_pAccRect->getIsRayonnant())
610  {
611  res += _pAccRect->surface();
612  }
614  {
615  res += _pEnveloppe->surface();
616  }
617 
618  return res;
619 }
620 
622 {
623  TYTabVector tab;
624 
625  tab.push_back(_pSemiCircBottom->getShape()->normal());
626  tab.push_back(_pSemiCircTop->getShape()->normal());
627 
628  TYTabRectangle tabRect = getEnveloppe();
629  for (unsigned int i = 0; i < tabRect.size(); i++)
630  {
631  tab.push_back(tabRect[i].normal());
632  }
633 
634  return tab;
635 }
636 
638 {
639  TYTabPoint tab;
640 
641  TYTabRectangle tabRect = getEnveloppe();
642  tab.reserve(tabRect.size() * 4);
643 
644  // Chaque rectangle
645  for (unsigned int i = 0; i < tabRect.size(); i++)
646  {
647  // Chaque point du rectangle
648  for (int j = 0; j < 4; j++)
649  {
650  // Ajout du sommet au tableau
651  tab.push_back(tabRect[i]._pts[j]);
652  }
653  }
654 
655  return tab;
656 }
657 
659 {
660  TYTabLPPolygon tab;
661 
662  TYTabRectangle enveloppe = getEnveloppe();
663  for (unsigned int i = 0; i < enveloppe.size(); i++)
664  {
665  tab.push_back(enveloppe[i].toPolygon());
666  }
667 
668  tab.push_back(_pSemiCircBottom->getBoundingRect()->toPolygon());
669  tab.push_back(_pSemiCircTop->getBoundingRect()->toPolygon());
670 
671  return tab;
672 }
673 
675 {
677 }
678 
680 {
681  return getCenter();
682 }
683 
685 {
686  return TYVolumeInterface::intersects(seg, ptList);
687 }
688 
690 {
691  int res = INTERS_NULLE;
692 
693  // Test de la position du point par rapport au vol englob
694  if (_volEnglob.isInside(pt) == INTERS_NULLE)
695  {
696  return res;
697  }
698 
699  // Le point doit verifier Xi¿½+Yi¿½ < Ri¿½ pour Z a l'interieur
700  // du cylindre (Le cylindre ne doit pas etre un ci¿½ne...)
701  // Le test avec l'equation du cercle complet est correcte ici
702  // car on a deja teste si le point appartenait a la bonne moitie
703  // du cylindre avec le test de la boi¿½te englobante.
704  // La verification de l'appartenance au cone infini est aussi
705  // suffisante car on a deja teste si le point est compris
706  // entre les plan haut et bas du cylindre (boi¿½te englobante)
707 
708  // Obtention de la matrice de changement de repere
710  repere._origin = getCenter();
711 
712  // On passe dans le repere du cylindre pour travailler en 2D
713  OPoint3D ptBis = repere.asMatrix() * pt;
714 
715  // Test Xi¿½ + Yi¿½ <= Ri¿½
716  double rayon = getDiameter() / 2.0;
717  if ((pt._x * ptBis._x) + (pt._y * ptBis._y) <= (rayon * rayon))
718  {
719  // Le point est a l'interieur du cylindre
720  res = INTERS_OUI;
721  }
722 
723  return res;
724 }
725 
727 {
729 
730  // Demi cercle top
731  tab.push_back(new TYAcousticSurfaceGeoNode((LPTYElement&)_pSemiCircTop));
732  // Demi cercle bottom
734  // Face laterale
735  tab.push_back(new TYAcousticSurfaceGeoNode((LPTYElement&)_pAccRect));
736 
737  // Enveloppe
738  // Resolution pour l'enveloppe
739  int resolution = TYDEFAULTRESOLUTIONIONCIRCLE;
740 
741 #if TY_USE_IHM
742  // static const char prefName[] = "ResolutionCircle";
743 
744  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "ResolutionCircle"))
745  {
746  resolution = TYPreferenceManager::getInt(TYDIRPREFERENCEMANAGER, "ResolutionCircle");
747  }
748  else
749  {
750  TYPreferenceManager::setInt(TYDIRPREFERENCEMANAGER, "ResolutionCircle", resolution);
751  }
752 
753 #endif // TY_USE_IHM
754 
755  TYTabRectangle enveloppe = getEnveloppe(resolution);
756  TYAcousticRectangle* pEnvElt = NULL;
757 
758  for (unsigned int i = 0; i < enveloppe.size() - 1; i++)
759  {
760  // Element de l'enveloppe
761  pEnvElt = new TYAcousticRectangle();
762  pEnvElt->setParent(this);
764 
765  // Geometrie
766  *pEnvElt->getShape() = enveloppe[i];
767 
768  // Acoustique
769  pEnvElt->setSrcSurf(_pEnveloppe->getSrcSurf());
770 
771  // Ajout
772  tab.push_back(new TYAcousticSurfaceGeoNode(pEnvElt));
773  }
774 
775  return tab;
776 }
777 
779 {
780  bool ret = false;
781 
782  if (((TYAcousticSurface*)_pSemiCircBottom._pObj == pAccSurf) ||
783  ((TYAcousticSurface*)_pSemiCircTop._pObj == pAccSurf) ||
784  ((TYAcousticSurface*)_pAccRect._pObj == pAccSurf))
785  {
786  // Pas de changement de repere pour ces surfaces
787  ret = true;
788  }
789 
790  return ret;
791 }
792 
794 {
795  return _pSemiCircBottom->getDiameter();
796 }
797 
799 {
800  _pSemiCircBottom->setDiameter(diameter);
801  _pSemiCircTop->setDiameter(diameter);
802 
803  updateRect();
804 
805  _volEnglob = volEnglob();
806  if (_pParent)
807  {
808  TYAcousticVolumeNode::safeDownCast(_pParent)->updateVolEnglob();
809  } // Informe le parent de se mettre a jour
810 
813  // Recalcul de la surface de l'enveloppe affectee au rectangle associe a l'acousticsurface
815 }
816 
818 {
820 }
821 
823 {
824  // On attribue +hauteur/2 au cercle du dessus
825  // et -hauteur/2 au cercle du dessous
826  // On calcul en fait des facteurs en fonction de la taille actuelle
827  // Les vecteurs obtenus font abstraction de la position du cylindre
828 
829  // Demi cercle top
831  vecTop = vecTop * (((hauteur / 2.0) / vecTop.norme()) - 1.0);
832 
833  // Demi cercle bottom
835  vecBottom = vecBottom * (((hauteur / 2.0) / vecBottom.norme()) - 1.0);
836 
837  // Pour chaque point
838  for (int i = 0; i < 4; i++)
839  {
840  // On applique le vecteur facteur
841  _pSemiCircTop->getShape()->_pts[i] = OVector3D(_pSemiCircTop->getShape()->_pts[i]) + vecTop;
843  }
844 
845  // Mise a jour de la surface laterale
846  updateRect();
847 
848  _volEnglob = volEnglob();
849  if (_pParent)
850  {
851  TYAcousticVolumeNode::safeDownCast(_pParent)->updateVolEnglob();
852  } // Informe le parent de se mettre a jour
853 
856 
857  // Recalcul de la surface de l'enveloppe affectee au rectangle associe a l'acousticsurface
859 }
860 
862 {
863  // Les coordonnees de la face laterale sont calculees a partir de
864  // celle des demi-cercles top et bottom
869 
871  setIsGeometryModified(true);
872 }
873 
875 {
876  TYTabRectangle tab;
877 
878  if (n == -1)
879  {
880  // Prise en compte de la precision
881  n = ROUND(((getDiameter() / 2.0) / TYPRECISIONCIRCLE) / 2.0);
882 
883  // On veut au moins tous les Pi/2 (90i¿½)
884  n = ROUND(n / 2 * 2);
885  }
886 
887  if (n < 3)
888  {
889  return tab;
890  }
891 
892  // Obtention des contours des demi-cercles top et bottom
893  // (Le nombre de points generes doit etre le meme)
894  TYTabPoint tabPtBottom = _pSemiCircBottom->getContour(n);
895  TYTabPoint tabPtTop = _pSemiCircTop->getContour(n);
896 
897  // n faces + la face laterale
898  int nbFaces = n + 1;
899  // On genere une face pour chaque couple de points top bottom
900  // + une face pour la face laterale (celle-ci sera redondante par
901  // rapport a '_rect')
902  for (int i = 0; i < nbFaces; i++)
903  {
904  TYRectangle rect(tabPtTop[(i + 1) % nbFaces], tabPtTop[i], tabPtBottom[nbFaces - i - 1],
905  tabPtBottom[(nbFaces - 1) - ((i + 1) % nbFaces)]);
906  tab.push_back(rect);
907  }
908 
909  return tab;
910 }
911 
913 {
915  return (OVector3D(_pSemiCircBottom->getCenter()) + (vec * 0.5));
916 }
917 
918 bool TYAcousticSemiCylinder::updateAcoustic(const bool& force) // force = false
919 {
920  /*
921  NB : On travaille sur un regime donne.
922  */
923 
924  bool ret = true;
925 
926  // Si le volume n'est pas rayonnant, inutile de tenter de distribuer
927  // la puissance, mais ce n'est pas une raison pour bloquer le calcul
928  if (!_isRayonnant)
929  {
930  return true;
931  }
932 
933  // 1/ Recuperer la surface totale
934  double surfTotale = this->activeSurface();
935 
936  OSpectre LWc = OSpectre::getEmptyLinSpectre(); // Spectre cumule de l'ensemble des elements
937  OSpectre LWg = getCurrentSpectre().toGPhy(); // Spectre global du regime courant
938  OSpectre LWv; // Spectre de puissance de la face courante
939 
940  LWc.setType(SPECTRE_TYPE_LW); // LWc represente une puissance
941 
943  {
944  LWv = _pSemiCircTop->setGlobalLW(LWg, surfTotale);
945  LWc = LWc.sum(LWv);
946  }
947  else
948  {
949  TYSpectre aTYSpectre;
950  _pSemiCircTop->setRegime(aTYSpectre);
951  }
952 
954  {
955  LWv = _pSemiCircBottom->setGlobalLW(LWg, surfTotale);
956  LWc = LWc.sum(LWv);
957  }
958  else
959  {
960  TYSpectre aTYSpectre;
961  _pSemiCircBottom->setRegime(aTYSpectre);
962  }
963 
964  if (_pAccRect->getIsRayonnant())
965  {
966  LWv = _pAccRect->setGlobalLW(LWg, surfTotale);
967  LWc = LWc.sum(LWv);
968  }
969  else
970  {
971  TYSpectre aTYSpectre;
972  _pAccRect->setRegime(aTYSpectre);
973  }
974 
976  {
977  LWv = _pEnveloppe->setGlobalLW(LWg, surfTotale);
978  LWc = LWc.sum(LWv);
979  }
980  else
981  {
982  TYSpectre aTYSpectre;
983  _pEnveloppe->setRegime(aTYSpectre);
984  }
985 
987  {
988  // Il faut s'assurer que la somme des puissances des volumes egale la puissance de la machine
989  double residu = ABS(10 * log10(LWg.sigma()) - 10 * log10(LWc.sigma()));
990 
991  // Si l'ecart est inferieur a 1 dB on accepte
992  ret = residu < 1 ? true : false;
993  }
995  {
996 
999 
1001  {
1002  LWc = LWc.sum(_pSemiCircTop->getCurrentSpectre().toGPhy());
1003  }
1005  {
1006  LWc = LWc.sum(_pSemiCircBottom->getCurrentSpectre().toGPhy());
1007  }
1008  if (_pAccRect->getIsRayonnant())
1009  {
1010  LWc = LWc.sum(_pAccRect->getCurrentSpectre().toGPhy());
1011  }
1012  if (_pEnveloppe->getIsRayonnant())
1013  {
1014  LWc = LWc.sum(_pEnveloppe->getCurrentSpectre().toGPhy());
1015  }
1016 
1017  TYSpectre temp = LWc.toDB();
1018  setRegime(temp, -1, false); // Pas de problemes, la puissance peut etre modifiee
1019  ret = true;
1020  }
1021 
1022  return ret;
1023 }
1024 
1026 {
1027  TYTabLPAcousticSurface tabSubFaces;
1028 
1029  // On balaye toutes les faces
1030  for (unsigned int i = 0; i < 6; i++)
1031  {
1033 
1034  for (unsigned int j = 0; j < tabFaces.size(); j++)
1035  {
1036  LPTYAcousticSurface pSurface = TYAcousticSurface::safeDownCast(tabFaces[j]->getElement());
1037 
1038  if (pSurface->getIsSub())
1039  {
1040  tabSubFaces.push_back(pSurface);
1041  }
1042  }
1043  }
1044 
1045  return tabSubFaces;
1046 }
1047 
1048 void TYAcousticSemiCylinder::setIsRayonnant(bool rayonnant /*= true*/, bool recursif /*=true*/)
1049 {
1050  TYAcousticVolume::setIsRayonnant(rayonnant, recursif);
1051 }
1052 
1054 {
1055  _nextRegime = next;
1056 
1059  _pAccRect->setNextRegimeNb(next);
1061 }
1062 
1064 {
1066 
1071 }
1072 
1074 {
1075  double sizeRectangle = sqrt(getDiameter() * M_PI * getHauteur() / 2.0); // = pi.r.h
1076  _pEnveloppe->getBoundingRect()->setDimension(sizeRectangle, sizeRectangle);
1077 }
1078 
1079 void TYAcousticSemiCylinder::exportCSV(std::ofstream& ofs)
1080 {
1081  // Export du nom de l'objet
1082  ofs << getName().toLatin1().data() << '\n';
1083 
1084  // Export du type de l'objet
1085  ofs << toString() << '\n';
1086 
1087  // Export des donnees acoustiques
1089 
1090  _pSemiCircTop->exportCSV(ofs);
1092  _pAccRect->exportCSV(ofs);
1093  _pEnveloppe->exportCSV(ofs);
1094 }
int ROUND(double a)
Compute the rounded value of a number.
Definition: 3d.h:192
#define INTERS_OUI
The intersection exists.
Definition: 3d.h:33
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
#define INTERS_NULLE
No intersection.
Definition: 3d.h:35
QDomElement DOM_Element
Definition: QT2DOM.h:30
Representation graphique d'un 1/2 cylindre acoustique (fichier header)
outil IHM pour un demi cylindre acoustique (fichier header)
TY_EXT_GRAPHIC_INST(TYAcousticSemiCylinder)
TY_EXTENSION_INST(TYAcousticSemiCylinder)
TYGeometryNode TYAcousticSurfaceGeoNode
Noeud geometrique de type TYAcousticSurface.
std::vector< LPTYAcousticSurface > TYTabLPAcousticSurface
Tableau de TYAcousticSurfaces.
std::vector< LPTYAcousticSurfaceGeoNode > TYTabAcousticSurfaceGeoNode
Collection de noeuds geometriques de type TYAcousticSurface.
std::vector< TYRectangle > TYTabRectangle
Collection de TYRectangle.
Definition: TYDefines.h:346
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
#define TYDEFAULTRESOLUTIONIONCIRCLE
Resolution par defaut pour la representation des cercles par des segments.
Definition: TYDefines.h:415
#define TYPRECISIONCIRCLE
Precision pour la representation des cercles par des segments.
Definition: TYDefines.h:412
std::vector< OVector3D > TYTabVector
Collection de OVector3D.
Definition: TYDefines.h:398
std::vector< LPTYPolygon > TYTabLPPolygon
Collection de pointeurs de TYPolygon.
Definition: TYDefines.h:349
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:345
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
const char * name
std::vector< LPTYSourcePonctuelleGeoNode > TYTabSourcePonctuelleGeoNode
Collection de noeuds geometriques de type TYSourcePonctuelle.
@ CALCULATED
Definition: color.h:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
The 4x4 matrix class.
Definition: 3d.h:625
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:249
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
3D frame with a point and 3 vectors.
Definition: 3d.h:1211
OPoint3D _origin
The origin point.
Definition: 3d.h:1279
OMatrix asMatrix() const
return the transformation matrix from unity to this pose such as this = transform * unity
Definition: 3d.cpp:1462
Class to define a segment.
Definition: 3d.h:1089
OSpectreAbstract & sum(const OSpectreAbstract &spectre) const
Arithmetic sum of two spectrums in one-third Octave.
Definition: spectre.cpp:219
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:634
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:152
double sigma()
Sum the values of the spectrum.
Definition: spectre.cpp:553
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:590
static OSpectre getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
Definition: spectre.cpp:1115
The 3D vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
void normalize()
Normalizes this vector.
Definition: 3d.cpp:225
T * _pObj
The real pointer, must derived IRefCount.
Definition: smartptr.h:307
Spectrum class.
Definition: Spectre.h:25
double _densiteSrcsV
Densite verticale de sources.
double getDensiteSrcsH() const
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual void setNextRegimeNb(const int &next)
TYRegime & getRegimeNb(const int &nb, bool &status)
size_t getNbRegimes() const
double getDensiteSrcsV() const
int _typeDistribution
Indique le type de distribution a utiliser. pour l'etat courant.
double _offsetSources
Offset de decalage des sources ponctuelles sur les surfaces.
virtual void loadRegime(int regimeNb=-1)
TYSpectre & getCurrentSpectre()
virtual int addRegime(const TYRegime &regime)
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
virtual void setRegime(TYSpectre &Spectre, int regime=-1, bool recursif=false)
virtual void setCurRegime(int regimeNumber)
int _nextRegime
Numero d'ordre du regime suivant.
virtual void propagateAtt(LPTYAttenuateur pAtt)
double _densiteSrcsH
Densite horizontale de sources.
virtual bool remRegime(int regime)
virtual void setRegimeName(const QString &name)
bool _isRayonnant
Etat courant de l'element (rayonnant ou non rayonnant)
virtual DOM_Element toXML(DOM_Element &domElement)
TYRectangle * getShape()
virtual double surface() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual double surface() const
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual DOM_Element toXML(DOM_Element &domElement)
void setDiameter(double diameter)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual TYTabPoint getContour(int n=-1) const
virtual int fromXML(DOM_Element domElement)
virtual double surface() const
virtual TYSourcePonctuelle srcPonctEquiv() const
virtual void setRegime(TYSpectre &Spectre, int regime=-1, bool recursif=false)
TYTabRectangle getEnveloppe(int n=-1) const
virtual void setNextRegimeNb(const int &next)
bool operator!=(const TYAcousticSemiCylinder &other) const
Operateur !=.
virtual TYTabPoint sommets() const
virtual double activeSurface() const
virtual DOM_Element toXML(DOM_Element &domElement)
virtual TYTabAcousticSurfaceGeoNode acousticFaces()
virtual void setCurRegime(int regime)
TYTabLPAcousticSurface getSubFace()
virtual void setRegimeName(const QString &name)
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual TYPoint centreGravite() const
virtual bool remRegime(int regime)
virtual int isInside(const TYPoint &pt) const
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual TYBox volEnglob() const
virtual int intersects(const OSegment3D &seg, TYTabPoint &ptList) const
virtual void loadRegime(int regimeNb=-1)
bool updateAcoustic(const bool &force=false)
LPTYAcousticRectangle _pAccRect
Surface laterale.
virtual TYTabVector normals() const
LPTYAcousticSemiCircle _pSemiCircBottom
Surface de dessous.
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
void setHauteur(double hauteur)
LPTYAcousticSemiCircle _pSemiCircTop
Surface de dessus.
virtual void propagateAtt(LPTYAttenuateur pAtt)
void setDiameter(double diameter)
virtual double volume() const
TYAcousticSemiCylinder & operator=(const TYAcousticSemiCylinder &other)
Operateur =.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual std::string toString() const
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
virtual bool findAcousticSurface(const TYAcousticSurface *pAccSurf, OMatrix *pMatrix=0)
virtual TYTabLPPolygon faces() const
LPTYAcousticSurface _pEnveloppe
Enveloppe.
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
bool operator==(const TYAcousticSemiCylinder &other) const
Operateur ==.
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual void remAllSrcs()
virtual void setCurRegime(int regime)
virtual double surface() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual TYTabSourcePonctuelleGeoNode getSrcs() const
virtual void exportCSV(std::ofstream &ofs)
Export au format csv sur un flux transmis.
TYSpectre setGlobalLW(const TYSpectre &spectre, const double &surfGlobale, const int &regime=-1)
LPTYSourceSurfacic getSrcSurf()
void setSrcSurf(const LPTYSourceSurfacic pSrcSurf)
virtual void setDensiteSrcsH(double densite, bool recursif=true)
virtual bool setSrcsLw()
TYRectangle * getBoundingRect()
virtual DOM_Element toXML(DOM_Element &domElement)
TYAcousticVolume & operator=(const TYAcousticVolume &other)
Operateur =.
virtual DOM_Element toXML(DOM_Element &domElement)
virtual int fromXML(DOM_Element domElement)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual void setIsAcousticModified(bool isModified)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
Definition: TYBox.h:34
int isInside(const TYPoint &pt) const
Definition: TYBox.cpp:236
virtual void setColor(const OColor &color)
TYElement * getParent() const
Definition: TYElement.h:699
virtual bool isInCurrentCalcul()
Definition: TYElement.h:541
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
virtual QString getName() const
Definition: TYElement.h:684
TYElement * _pParent
Reference sur l'element parent.
Definition: TYElement.h:969
virtual void setInCurrentCalcul(bool state, bool recurschild=true, bool recursparent=true)
Definition: TYElement.cpp:410
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:532
void setParent(TYElement *pParent)
Definition: TYElement.h:692
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
ORepere3D getORepere3D() const
void setDimension(float lon, float haut)
TYPoint _pts[4]
Sommets.
Definition: TYRectangle.h:274
TYPolygon * toPolygon() const
virtual OVector3D normal() const
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYRegime.cpp:99
void setDirectivity(TYDirectivity *directivity_)
: Get/Set directivity to source
void setTypeRaynt(TYTypeRaynt type)
double getDensiteSrcsH() const
bool addSrc(LPTYSourcePonctuelle pSrcPonct)
double getDensiteSrcsV() const
virtual int intersects(const OSegment3D &seg, TYTabPoint &ptList) const
virtual TYBox volEnglob() const
void calculRayonSphere(const TYBox &volEnglob)
virtual void calculCentreGravite()
#define M_PI
Pi.
Definition: color.cpp:25
@ SPECTRE_TYPE_LW
Definition: spectre.h:30