]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/OrientationInverter.cxx
Salome HOME
Cell inverter - in progress
[tools/medcoupling.git] / src / INTERP_KERNEL / OrientationInverter.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
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 // Author : Anthony Geay (EDF R&D)
20
21 #include "OrientationInverter.hxx"
22 #include "InterpKernelException.hxx"
23
24 #include <sstream>
25 #include <algorithm>
26
27 using namespace INTERP_KERNEL;
28
29 void OrientationInverterChecker::check(int *beginPt, int *endPt) const
30 {
31   if(std::distance(beginPt,endPt)!=getNbNodes())
32     {
33       std::ostringstream oss; oss << "OrientationInverterChecker::check : length of nodal connectivity mismatches ! Expecting " << getNbNodes() << " having " << std::distance(beginPt,endPt) << " !";
34       throw INTERP_KERNEL::Exception(oss.str());
35     }
36 }
37
38 void OrientationInverterSEG2::operateAndShutUp(int *beginPt) const
39 {
40   std::swap(beginPt[0],beginPt[1]);
41 }
42
43 void OrientationInverterSEG3::operateAndShutUp(int *beginPt) const
44 {
45   std::swap(beginPt[0],beginPt[2]);
46 }
47
48 void OrientationInverter2DLinear::operateAndShutUp(int *beginPt) const
49 {
50   std::reverse(beginPt+1,beginPt+getNbNodes());
51 }
52
53 void OrientationInverter2DQuadratic::operateAndShutUp(int *beginPt) const
54 {
55   int nbNodes(getNbNodes());
56   std::reverse(beginPt+1,beginPt+nbNodes/2);
57   std::reverse(beginPt+nbNodes/2,beginPt+nbNodes);
58 }
59
60 void OrientationInverterPolygon::operate(int *beginPt, int *endPt) const
61 {
62   std::reverse(beginPt+1,endPt);
63 }
64
65 void OrientationInverterQPolygon::operate(int *beginPt, int *endPt) const
66 {
67   std::size_t sz(std::distance(beginPt,endPt));
68   std::reverse(beginPt+1,beginPt+sz/2);
69   std::reverse(beginPt+sz/2,endPt);
70 }
71
72 void OrientationInverterTetra4::operateAndShutUp(int *beginPt) const
73 {
74   std::swap(beginPt[1],beginPt[2]);
75 }
76
77 void OrientationInverterTetra10::operateAndShutUp(int *beginPt) const
78 {
79   std::swap(beginPt[1],beginPt[2]);
80   std::swap(beginPt[4],beginPt[6]);
81   std::swap(beginPt[8],beginPt[9]);
82 }
83
84 void OrientationInverterPyra5::operateAndShutUp(int *beginPt) const
85 {
86   std::reverse(beginPt+1,beginPt+4);
87 }
88
89 void OrientationInverterPyra13::operateAndShutUp(int *beginPt) const
90 {
91   std::reverse(beginPt+1,beginPt+4);
92   std::reverse(beginPt+5,beginPt+9);
93   std::swap(beginPt[10],beginPt[12]);
94 }
95
96 void OrientationInverter3DExtrusionLinear::operateAndShutUp(int *beginPt) const
97 {
98   int nbNodes(getNbNodes());
99   std::reverse(beginPt+1,beginPt+nbNodes/2);
100   std::reverse(beginPt+nbNodes/2+1,beginPt+nbNodes);
101 }
102
103 void OrientationInverter3DExtrusionQuadratic::operateAndShutUp(int *beginPt) const
104 {
105   int nbNodes(getNbNodes()),nbNodesLinearBase(nbNodes/5);
106   std::reverse(beginPt+1,beginPt+nbNodesLinearBase);
107   std::reverse(beginPt+nbNodesLinearBase+1,beginPt+2*nbNodesLinearBase);
108   std::reverse(beginPt+2*nbNodesLinearBase,beginPt+3*nbNodesLinearBase);
109   std::reverse(beginPt+3*nbNodesLinearBase,beginPt+4*nbNodesLinearBase);
110   std::reverse(beginPt+4*nbNodesLinearBase+1,beginPt+5*nbNodesLinearBase);
111 }