Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSurfaceInterface.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #include <cassert>
17 
21 #include "TYSurfaceInterface.h"
22 
24 {
25  if (!pSurf)
26  {
27  return INTERS_NULLE;
28  }
29 
30  int res = INTERS_NULLE;
31  bool ptAFind = false, ptBFind = false;
32  OPoint3D ptTmp;
33 
34  // Contour 2
35  TYTabPoint3D contour2 = pSurf->getOContour();
36  size_t nbPts = contour2.size();
37 
38  // Pour chaque segment composant le contour 2
39  for (size_t i = 0; i < nbPts; i++)
40  {
41  // On chercher les points d'intersection entre les segments du contour 2 et cette surface
42  if (this->intersects(OSegment3D(contour2[i], contour2[(i + 1) % nbPts]), ptTmp) != INTERS_NULLE)
43  {
44  if (!ptAFind)
45  {
46  // Un 1er point a ete trouve
47  seg._ptA = ptTmp;
48  ptAFind = true;
49  }
50  else if (!ptBFind)
51  {
52  // Un 2eme point a ete trouve
53  seg._ptB = ptTmp;
54  ptBFind = true;
55  }
56  }
57  }
58 
59  // Contour 1
60  TYTabPoint3D contour1 = getOContour();
61  nbPts = contour1.size();
62 
63  // Pour chaque segment composant le contour 2
64  for (size_t i = 0; i < nbPts; i++)
65  {
66  // On chercher les points d'intersection entre les segments du contour 1 et la surface a tester
67  if (pSurf->intersects(OSegment3D(contour1[i], contour1[(i + 1) % nbPts]), ptTmp) != INTERS_NULLE)
68  {
69  if (!ptAFind)
70  {
71  // Un 1er point a ete trouve
72  seg._ptA = ptTmp;
73  ptAFind = true;
74  }
75  else if (!ptBFind)
76  {
77  // Un 2eme point a ete trouve
78  seg._ptB = ptTmp;
79  ptBFind = true;
80  }
81  }
82  }
83 
84  // Les 2 points ont ete trouve ?
85  if (ptBFind && ptBFind)
86  {
87  // Nous avons donc notre segment intersection
88  res = INTERS_OUI;
89  }
90 
91  return res;
92 }
93 
95 {
96  int res = INTERS_NULLE;
97  bool ptAFind = false, ptBFind = false;
98  OPoint3D ptIntersec;
99 
100  // Contour
101  TYTabPoint3D contour = this->getOContour();
102  size_t nbPts = contour.size();
103 
104  // Pour chaque segment composant le contour
105  for (size_t i = 0; i < nbPts; i++)
106  {
107  if (plan.intersectsSegment(contour[i], contour[(i + 1) % nbPts], ptIntersec) == INTERS_OUI)
108  {
109  if (!ptAFind)
110  {
111  // Un 1er point a ete trouve
112  seg._ptA = ptIntersec;
113  ptAFind = true;
114  }
115  else if (!ptBFind)
116  {
117  // Un 2eme point a ete trouve
118  if (ptIntersec == seg._ptA)
119  {
120  continue;
121  } // Cas ou le plan passe exactement par un point
122  seg._ptB = ptIntersec;
123  ptBFind = true;
124 
125  // Si on a trouve point B c'est qu'on a trouve point A on peut sortir victorieusement
126  res = INTERS_OUI;
127  break;
128  }
129  }
130  }
131 
132  return res;
133 }
134 
135 void TYSurfaceInterface::exportMesh(std::deque<OPoint3D>& points, std::deque<OTriangle>& triangles,
136  const TYGeometryNode& geonode) const
137 {
138  assert(false && "OPROTO does not support pure virtual methods");
139 }
All base classes related to 3D manipulation.
#define INTERS_OUI
The intersection exists.
Definition: 3d.h:33
#define INTERS_NULLE
No intersection.
Definition: 3d.h:35
std::deque< OPoint3D > TYTabPoint3D
Collection de OPoint3D.
Definition: TYDefines.h:403
Plan defined by its equation : ax+by+cz+d=0.
Definition: plan.h:31
int intersectsSegment(const OPoint3D &pt1, const OPoint3D &pt2, OPoint3D &ptIntersec) const
Calculate the intersection of this plane with a segment defined by two points.
Definition: plan.cpp:140
The 3D point class.
Definition: 3d.h:487
Class to define a segment.
Definition: 3d.h:1141
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1253
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
virtual int intersectsPlan(const OPlan &plan, OSegment3D &seg) const
virtual int intersects(const OPoint3D &pt) const =0
virtual TYTabPoint3D getOContour(int n=-1) const =0
virtual OPlan plan() const =0
virtual void exportMesh(std::deque< OPoint3D > &points, std::deque< OTriangle > &triangles, const TYGeometryNode &geonode) const
Exports the surface as a triangular mesh in global reference coordinate system.