Version: 9.16.0
SMESH_RegularGridTemplate.hxx
Go to the documentation of this file.
1// Copyright (C) 2016-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library 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. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19// File : SMESH_TemplateRegularGrid.hxx
20// Created : Fry April 05 11:20 2024
21// Author : Cesar Conopoima (cce)
22
23
24#ifndef __SMESH_RegularGridTemplate_HXX__
25#define __SMESH_RegularGridTemplate_HXX__
26
27//STD
28#include <functional>
29
30//SMESH::Utils
31#include "SMESH_RegularGrid.hxx"
32
33namespace SMESHUtils
34{
35 template<typename FUNCTION>
36 void SMESH_RegularGrid::foreachGridSide( const FUNCTION& fSide ) const
37 {
38 for (size_t edgeType = BOTTOM; edgeType <= LEFT; edgeType++)
39 fSide( static_cast<EdgeType>( edgeType ) );
40 }
41
42 template<typename FUNCTION>
43 void SMESH_RegularGrid::foreachGridFace( const FUNCTION& fSide ) const
44 {
45 for (size_t faceType = B_BOTTOM; faceType <= B_TOP; faceType++)
46 fSide( static_cast<FaceType>( faceType ) );
47 }
48
49 void SMESH_RegularGrid::foreachNodeOnSide( SMESH_RegularGrid::EdgeType edge, const std::function<void(const std::shared_ptr<gp_Pnt> point, const int index )>& function ) const
50 {
51 for (auto node : nodesOfSide(edge))
52 function(myCoordinates[node],node);
53 }
54
55 void SMESH_RegularGrid::foreachNodeOnFace( SMESH_RegularGrid::FaceType face, const std::function<void(const std::shared_ptr<gp_Pnt> point, const int index )>& function ) const
56 {
57 for (auto node : nodesOfFace(face))
58 function(myCoordinates[node],node);
59 }
60
61 template<typename T>
62 std::vector<T> SMESH_RegularGrid::getEdgeIndexLimits( const EdgeType edge ) const
63 {
64 switch ( edge ) {
65 case EdgeType::BOTTOM:
66 return std::vector<T>{1,1,mnx,1};
67 break;
68 case EdgeType::RIGHT:
69 return std::vector<T>{mnx,1,mnx,mny};
70 break;
71 case EdgeType::TOP:
72 return std::vector<T>{mnx,mny,1,mny};
73 break;
74 case EdgeType::LEFT:
75 return std::vector<T>{1,mny,1,1};
76 break;
77 default:
78 return std::vector<T>{1,1,mnx,1};
79 break;
80 }
81 }
82
83 /* Define vertex numeration convention for vertex and face index limits!
84 *
85 * V7 V6
86 * +--------+--------+--------+
87 * / / / /|
88 * +--------+--------+--------+ |
89 * / / / /| |
90 * +--------+--------+--------+ | +
91 * / / / V5 /| |/|
92 * V4 +--------+--------+--------+ | + |
93 * | | | |/| |
94 * | | | + | +
95 * | | |/| |/|
96 * + | | + |
97 * | | | |/| |
98 * | +-------+----------+-| + | + V2
99 * | / V3 |/| |/
100 * + / | +
101 * | / | |/
102 * | / | +
103 * |/ |/
104 * +--------+--------+--------+
105 * V0 V1
106 *
107 * Canonical cartesian axis orientation
108 *
109 * ^ ^ j (or y)
110 * k (or z)| /
111 * | /
112 * |/
113 * +------> i (or x)
114 *
115 *
116 */
117 template<typename T>
118 std::vector<T> SMESH_RegularGrid::getFaceIndexLimits( const FaceType face ) const
119 {
120 switch ( face ) {
122 return std::vector<T>{1,1,1,mnx,mny,1}; /*V0-V2*/
123 break;
125 return std::vector<T>{mnx,1,1,mnx,mny,mnz}; /*V1-V6*/
126 break;
127 case FaceType::B_BACK:
128 return std::vector<T>{1,mny,1,mnx,mny,mnz}; /*V3-V6*/
129 break;
130 case FaceType::B_LEFT:
131 return std::vector<T>{1,1,1,1,mny,mnz}; /*V0-V7*/
132 break;
134 return std::vector<T>{1,1,1,mnx,1,mnz}; /*V0-V5*/
135 break;
136 case FaceType::B_TOP:
137 return std::vector<T>{1,1,mnz,mnx,mny,mnz}; /*V4-V6*/
138 break;
139 default:
140 return std::vector<T>{1,1,1,mnx,mny,1};
141 break;
142 }
143 }
144
145 template<typename T>
146 void SMESH_RegularGrid::getAllEdgeIndexLimits(std::vector<std::vector<T>>& allRanges)
147 {
148 this->foreachGridSide( [&]( EdgeType edge )
149 {
150 allRanges.push_back( getEdgeIndexLimits<T>(edge) );
151 });
152 }
153
154 template<typename T>
155 void SMESH_RegularGrid::getAllFaceIndexLimits(std::vector<std::vector<T>>& allRanges)
156 {
157 this->foreachGridFace( [&]( FaceType face )
158 {
159 allRanges.push_back( getFaceIndexLimits<T>(face) );
160 });
161 }
162}
163
164
165#endif
@ B_LEFT
Definition: StdMeshers_CompositeHexa_3D.cxx:88
@ B_FRONT
Definition: StdMeshers_CompositeHexa_3D.cxx:88
@ B_RIGHT
Definition: StdMeshers_CompositeHexa_3D.cxx:88
@ B_BACK
Definition: StdMeshers_CompositeHexa_3D.cxx:88
@ B_TOP
Definition: StdMeshers_CompositeHexa_3D.cxx:88
@ B_BOTTOM
Definition: StdMeshers_CompositeHexa_3D.cxx:88
EdgeType
Definition: SMESH_RegularGrid.hxx:102
@ BOTTOM
Definition: SMESH_RegularGrid.hxx:103
@ LEFT
Definition: SMESH_RegularGrid.hxx:106
std::vector< int > nodesOfFace(SMESH_RegularGrid::FaceType face) const
Definition: SMESH_RegularGrid.cxx:154
void foreachGridFace(const FUNCTION &fSide) const
Definition: SMESH_RegularGridTemplate.hxx:43
std::vector< int > nodesOfSide(SMESH_RegularGrid::EdgeType edge) const
Definition: SMESH_RegularGrid.cxx:208
void getAllFaceIndexLimits(std::vector< std::vector< T > > &allRanges)
Definition: SMESH_RegularGridTemplate.hxx:155
void foreachGridSide(const FUNCTION &fSide) const
Definition: SMESH_RegularGridTemplate.hxx:36
int mnx
Definition: SMESH_RegularGrid.hxx:368
int mny
Definition: SMESH_RegularGrid.hxx:368
void foreachNodeOnSide(SMESH_RegularGrid::EdgeType edge, const std::function< void(const std::shared_ptr< gp_Pnt > point, const int index)> &function) const
Definition: SMESH_RegularGridTemplate.hxx:49
std::vector< T > getFaceIndexLimits(SMESH_RegularGrid::FaceType face) const
Definition: SMESH_RegularGridTemplate.hxx:118
int mnz
Definition: SMESH_RegularGrid.hxx:368
void getAllEdgeIndexLimits(std::vector< std::vector< T > > &allRanges)
Definition: SMESH_RegularGridTemplate.hxx:146
FaceType
Definition: SMESH_RegularGrid.hxx:157
@ B_BOTTOM
Definition: SMESH_RegularGrid.hxx:158
@ B_TOP
Definition: SMESH_RegularGrid.hxx:163
void foreachNodeOnFace(SMESH_RegularGrid::FaceType face, const std::function< void(const std::shared_ptr< gp_Pnt > point, const int index)> &function) const
Definition: SMESH_RegularGridTemplate.hxx:55
NCollection_Array1< std::shared_ptr< gp_Pnt > > myCoordinates
Definition: SMESH_RegularGrid.hxx:369
std::vector< T > getEdgeIndexLimits(const EdgeType edge) const
Definition: SMESH_RegularGridTemplate.hxx:62
Definition: SMESH_BoostTxtArchive.hxx:35