1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDMODULUSARRAY_H__
21 #define __MEDMODULUSARRAY_H__
25 #include "MEDMEM_Utilities.hxx"
26 #include "MEDMEM_define.hxx"
30 This class is use to set cyclic (modulus length) array.
31 (array[length+1]==array[1])
33 We use it in particular to compare faces nodes lists to know if
34 they are the same (positive or negative cycle) !
38 class MEDMEM_EXPORT MEDMODULUSARRAY {
40 // nb vertex nodes; only vertex nodes are in cycle
42 // total nb nodes; not vertex nodes exists in 2-nd order elements,
43 // only presence of not vertex nodes is checked by compare()
47 bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
50 MEDMODULUSARRAY(int length, const int * array) ;
51 MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array);
54 const int operator[](const int &i) const ;
56 int compare(const MEDMODULUSARRAY &modulusArray) const;
58 const int *getArray(int& length) const { length=_length; return _array; }
62 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) :
63 _length(length), _array(array), _length2(0)
66 // for (int i=0;i<_length;i++){
67 // MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
71 MEDMODULUSARRAY::MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
72 _length(vertexLength), _length2( totalLength ), _array(array)
76 MEDMODULUSARRAY::~MEDMODULUSARRAY()
78 // do nothing because nothing is allocated !
79 // MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
83 const int MEDMODULUSARRAY::operator[](const int &i) const
85 int position = i%_length ;
86 //int position = i%_length2 ;
89 //position += _length2 ;
90 return _array[position] ;
93 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
97 if (modulusArray._length != _length ||
98 modulusArray._length2 != _length2 )
102 if (_array[0]==modulusArray[0])
108 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
110 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
114 if ( !compareNotVertexNodes( modulusArray ) )
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
125 for(int j=2;j<_length;j++)
126 if (_array[j]!=modulusArray[i+j]) {
130 } else if(_array[1]==modulusArray[i-1]) { //negative order
132 for(int j=2;j<_length;j++)
133 if (_array[j]!=modulusArray[i-j]) {
138 if (ret!=0) {// we have found it !
139 if ( !compareNotVertexNodes( modulusArray ) )
143 // else we continue if there is another start point i
149 * \brief Check presence of the same not vertex nodes
150 * \retval bool - comparison result
152 bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
154 if ( _length2 > _length ) {
155 for ( int i = _length; i < _length2; ++i ) {
157 for ( int j = _length; ( j < _length2 && !found ); ++j )
158 found = ( _array[ i ] == modulusArray._array[ j ] );
168 # endif /* # ifndef __MEDMODULUSARRAY_H__ */