]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_SkyLineArray.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_SkyLineArray.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_SkyLineArray.hxx"
23 #include "MEDMEM_Utilities.hxx"
24 #include <map>
25
26 using namespace std;
27 using namespace MEDMEM;
28
29 MEDSKYLINEARRAY::MEDSKYLINEARRAY(): _count(0), _length(0),
30                                 _index((int*)NULL),_value((int*)NULL)
31 {
32   MESSAGE_MED("Constructeur MEDSKYLINEARRAY sans parametre");
33 }
34
35 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const MEDSKYLINEARRAY &myArray):
36                                 _count(myArray._count),_length(myArray._length),
37                                 _index(_count+1),_value(_length)
38 {
39   const char* LOC = "MEDSKYLINEARRAY(const MEDSKYLINEARRAY &)";
40   BEGIN_OF_MED(LOC);
41   memcpy(_index,myArray._index,sizeof(int)*(_count+1));
42   memcpy(_value,myArray._value,sizeof(int)*_length);
43   END_OF_MED(LOC);
44 }
45
46 MEDSKYLINEARRAY::~MEDSKYLINEARRAY()
47 {
48   MESSAGE_MED("Destructeur ~MEDSKYLINEARRAY");
49
50   //if (_index != NULL) delete [] _index;
51   //if (_value != NULL) delete [] _value;
52 }
53
54 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length):
55                                 _count(count), _length(length),
56                                 _index(_count+1),_value(_length)
57 {
58         MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
59 }
60
61 MEDSKYLINEARRAY::MEDSKYLINEARRAY(const int count, const int length,
62                                  const int* index, const int* value,bool shallowCopy):
63                                 _count(count), _length(length)
64 {
65 //      MESSAGE_MED("Constructeur MEDSKYLINEARRAY(count="<<count<<", length="<<length<<") avec parametres");
66                 if(shallowCopy)
67           {
68             _index.setShallowAndOwnership(index);
69             _value.setShallowAndOwnership(value);
70           }
71         else
72           {
73             _index.set(_count+1,index);
74             _value.set(_length,value);
75           }
76 }
77
78 //creates the reverse array
79 //creates an array with count maxvalue, where maxvalue
80 //is the maximum of the value_ of the present array
81 //length is the same as present array
82 //
83 // For instance
84 // 1 : 2 4
85 // 2 : 1 2
86 //
87 //will give
88 // 1 : 2
89 // 2 : 1 2
90 // 3 :
91 // 4 : 1
92
93 MEDSKYLINEARRAY* MEDSKYLINEARRAY::makeReverseArray()
94 {
95         multimap<int,int > reverse;
96         int size=0;
97   for (int i=0; i<_count;i++)
98                 for (int j=_index[i];j<_index[i+1];j++)
99                         {
100                                 int value=_value[j-1];
101                                 reverse.insert(make_pair(value,i+1));
102                                 if (value>size) size=value;
103                         }
104         int* r_index=new int [size+1];
105         int* r_value=new int [_length];
106         r_index[0]=1;
107         pair<multimap<int,int>::iterator,multimap<int,int>::iterator>piter;
108         int* ptr_value=r_value;
109         for (int i=0; i<size;i++)
110                 {
111                         piter=reverse.equal_range(i);
112                         int index_incr=0;
113                         for (multimap<int,int>::iterator iter=piter.first; iter!=piter.second; iter++)
114                                 {
115                                         *ptr_value++=iter->second;
116                                         index_incr++;
117                                 }
118                         r_index[i+1]=r_index[i]+index_incr;
119                 }
120         return new MEDSKYLINEARRAY(size,_length,r_index,r_value,true);
121 }
122 ostream& MEDMEM::operator<<(ostream &os, const MEDSKYLINEARRAY &sky) {
123   os << "_count : " << sky._count << " ,_length : " << sky._length;
124   for (int i = 0; i < sky._count ; i++) {
125     os << endl << "Values of type n°" << i+1 << " (index["<<i<<"]="<< sky._index[i]<<") :" << endl;
126     for (int j=sky._index[i]-1;j < sky._index[i+1]-1;j++)
127       os << sky._value[j] << " " ;
128   }
129   return os;
130 }
131
132 //  void MEDSKYLINEARRAY::setMEDSKYLINEARRAY( const int count , const int length, int* index , int* value )
133 //  {
134 //    MESSAGE_MED("void MEDSKYLINEARRAY::setMEDSKYLINEARRAY(count, length, index, value)");
135 //    _count  = count  ;
136 //    _length = length ;
137
138 //    //if (_index != NULL) delete [] _index;
139 //    //if (_value != NULL) delete [] _value;
140
141 //        _index.set(index);
142 //        _value.set(value);
143 //  }