1 // Copyright (C) 2007-2008 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
22 #ifndef __MEDMODULUSARRAY_H__
23 #define __MEDMODULUSARRAY_H__
27 #include "MEDMEM_Utilities.hxx"
28 #include "MEDMEM_define.hxx"
32 This class is use to set cyclic (modulus length) array.
33 (array[length+1]==array[1])
35 We use it in particular to compare faces nodes lists to know if
36 they are the same (positive or negative cycle) !
40 class MEDMEM_EXPORT MEDMODULUSARRAY {
42 // nb vertex nodes; only vertex nodes are in cycle
44 // total nb nodes; not vertex nodes exists in 2-nd order elements,
45 // only presence of not vertex nodes is checked by compare()
49 inline bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
52 MEDMODULUSARRAY(int length, const int * array) :
53 _length(length), _length2(length), _array(array) {}
55 MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
56 _length(vertexLength), _length2( totalLength ), _array(array) {}
60 inline const int operator[](const int &i) const ;
62 inline int compare(const MEDMODULUSARRAY &modulusArray) const;
64 const int *getArray(int& length) const { length=_length; return _array; }
68 inline const int MEDMODULUSARRAY::operator[](const int &i) const
70 int position = i%_length ;
71 //int position = i%_length2 ;
74 //position += _length2 ;
75 return _array[position] ;
78 inline int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
82 if (modulusArray._length != _length ||
83 modulusArray._length2 != _length2 )
87 if (_array[0]==modulusArray[0])
93 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
95 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
99 if ( !compareNotVertexNodes( modulusArray ) )
104 //search if there is one start point in common in two array
105 for(int i=0;i<_length;i++)
106 if ( _array[0] == modulusArray[i] ) {
107 // we search if cycle is the same
108 if (_array[1]==modulusArray[i+1]){ // positive order
110 for(int j=2;j<_length;j++)
111 if (_array[j]!=modulusArray[i+j]) {
115 } else if(_array[1]==modulusArray[i-1]) { //negative order
117 for(int j=2;j<_length;j++)
118 if (_array[j]!=modulusArray[i-j]) {
123 if (ret!=0) {// we have found it !
124 if ( !compareNotVertexNodes( modulusArray ) )
128 // else we continue if there is another start point i
134 * \brief Check presence of the same not vertex nodes
135 * \retval bool - comparison result
137 inline bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
139 if ( _length2 > _length ) {
140 for ( int i = _length; i < _length2; ++i ) {
142 for ( int j = _length; ( j < _length2 && !found ); ++j )
143 found = ( _array[ i ] == modulusArray._array[ j ] );
153 # endif /* # ifndef __MEDMODULUSARRAY_H__ */