]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_ModulusArray.hxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / MEDMEM_ModulusArray.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #ifndef __MEDMODULUSARRAY_H__
21 #define __MEDMODULUSARRAY_H__
22
23 #include "MEDMEM.hxx"
24
25 #include "MEDMEM_Utilities.hxx"
26 #include "MEDMEM_define.hxx"
27
28
29 /*
30   This class is use to set cyclic (modulus length) array.
31   (array[length+1]==array[1])
32
33   We use it in particular to compare faces nodes lists to know if
34   they are the same (positive or negative cycle) !
35 */
36
37 namespace MEDMEM {
38 class MEDMEM_EXPORT MEDMODULUSARRAY {
39 private:
40   // nb vertex nodes; only vertex nodes are in cycle
41   int   _length ;
42   // total nb nodes; not vertex nodes exists in 2-nd order elements,
43   // only presence of not vertex nodes is checked by compare()
44   int   _length2;
45   const int * _array ;
46
47   bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
48
49 public:
50   MEDMODULUSARRAY(int length, const int * array) ;
51   MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array);
52   ~MEDMODULUSARRAY() ;
53
54   const int operator[](const int &i) const ;
55
56   int compare(const MEDMODULUSARRAY &modulusArray) const;
57
58   const int  *getArray(int& length) const { length=_length; return _array; }
59 };
60
61
62 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : 
63   _length(length), _array(array), _length2(0)
64 {
65 //    SCRUTE(_length);
66 //    for (int i=0;i<_length;i++){
67 //      MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
68 //    }
69 };
70
71   MEDMODULUSARRAY::MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
72   _length(vertexLength), _length2( totalLength ), _array(array)
73 {
74 }
75
76 MEDMODULUSARRAY::~MEDMODULUSARRAY()
77 {
78   // do nothing because nothing is allocated !
79   //  MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
80 };
81
82
83 const int MEDMODULUSARRAY::operator[](const int &i) const
84 {
85   int position = i%_length ;
86   //int position = i%_length2 ;
87   if (position < 0)
88     position+=_length ;
89   //position += _length2 ;
90   return _array[position] ;
91 };
92
93 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
94 {
95   int ret = 0 ;
96
97   if (modulusArray._length  != _length ||
98       modulusArray._length2 != _length2 )
99     return ret ;
100
101   if (_length==1)
102     if (_array[0]==modulusArray[0])
103       return 1;
104     else 
105       return 0;
106
107   if (_length==2) {
108     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
109       ret = 1;
110     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
111       ret = -1;
112     else
113       return 0;
114     if ( !compareNotVertexNodes( modulusArray ) )
115       ret = 0;
116     return ret;
117   }
118
119   //search if there is one start point in common in two array
120   for(int i=0;i<_length;i++)
121     if ( _array[0] == modulusArray[i] ) {
122       // we search if cycle is the same
123       if (_array[1]==modulusArray[i+1]){ // positive order
124         ret=1;
125         for(int j=2;j<_length;j++)
126           if (_array[j]!=modulusArray[i+j]) {
127             ret = 0 ;
128             break ;
129           }
130       } else if(_array[1]==modulusArray[i-1]) { //negative order
131         ret=-1;
132         for(int j=2;j<_length;j++)
133           if (_array[j]!=modulusArray[i-j]) {
134             ret = 0 ;
135             break ;
136           }
137       }
138       if (ret!=0) {// we have found it !
139         if ( !compareNotVertexNodes( modulusArray ) )
140           ret = 0;
141         break ;
142       }
143       // else we continue if there is another start point i
144     }
145     return ret ;
146 }
147
148 /*!
149  * \brief Check presence of the same not vertex nodes
150   * \retval bool - comparison result
151  */
152 bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
153 {
154   if ( _length2 > _length ) {
155     for ( int i = _length; i < _length2; ++i ) {
156       bool found = false;
157       for ( int j = _length; ( j < _length2 && !found ); ++j )
158         found = ( _array[ i ] == modulusArray._array[ j ] );
159       if ( !found )
160         return false;
161     }
162   }
163   return true;
164 }
165
166 }
167
168 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
169