1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef __MEDMODULUSARRAY_H__
24 #define __MEDMODULUSARRAY_H__
28 #include "MEDMEM_Utilities.hxx"
29 #include "MEDMEM_define.hxx"
33 This class is use to set cyclic (modulus length) array.
34 (array[length+1]==array[1])
36 We use it in particular to compare faces nodes lists to know if
37 they are the same (positive or negative cycle) !
41 class MEDMEM_EXPORT MEDMODULUSARRAY {
43 // nb vertex nodes; only vertex nodes are in cycle
45 // total nb nodes; not vertex nodes exists in 2-nd order elements,
46 // only presence of not vertex nodes is checked by compare()
50 inline bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
53 MEDMODULUSARRAY(int length, const int * array) :
54 _length(length), _length2(length), _array(array) {}
56 MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
57 _length(vertexLength), _length2( totalLength ), _array(array) {}
61 inline const int operator[](const int &i) const ;
63 inline int compare(const MEDMODULUSARRAY &modulusArray) const;
65 const int *getArray(int& length) const { length=_length; return _array; }
69 inline const int MEDMODULUSARRAY::operator[](const int &i) const
71 int position = i%_length ;
72 //int position = i%_length2 ;
75 //position += _length2 ;
76 return _array[position] ;
79 inline int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
83 if (modulusArray._length != _length ||
84 modulusArray._length2 != _length2 )
89 if (_array[0]==modulusArray[0])
96 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
98 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
102 if ( !compareNotVertexNodes( modulusArray ) )
107 //search if there is one start point in common in two array
108 for(int i=0;i<_length;i++)
109 if ( _array[0] == modulusArray[i] ) {
110 // we search if cycle is the same
111 if (_array[1]==modulusArray[i+1]){ // positive order
113 for(int j=2;j<_length;j++)
114 if (_array[j]!=modulusArray[i+j]) {
118 } else if(_array[1]==modulusArray[i-1]) { //negative order
120 for(int j=2;j<_length;j++)
121 if (_array[j]!=modulusArray[i-j]) {
126 if (ret!=0) {// we have found it !
127 if ( !compareNotVertexNodes( modulusArray ) )
131 // else we continue if there is another start point i
137 * \brief Check presence of the same not vertex nodes
138 * \retval bool - comparison result
140 inline bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
142 if ( _length2 > _length ) {
143 for ( int i = _length; i < _length2; ++i ) {
145 for ( int j = _length; ( j < _length2 && !found ); ++j )
146 found = ( _array[ i ] == modulusArray._array[ j ] );
156 # endif /* # ifndef __MEDMODULUSARRAY_H__ */