Salome HOME
Copyright update 2020
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingSkyLineArray.hxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__
21 #define __PARAMEDMEM_MEDCOUPLINGSKYLINEARRAY_HXX__
22
23 #include "MEDCoupling.hxx"
24 #include "MEDCouplingMemArray.hxx"
25 #include "MCAuto.hxx"
26 #include "NormalizedGeometricTypes"
27
28 #include <vector>
29
30 namespace MEDCoupling
31 {
32   /**!
33    * Class allowing the easy manipulation of the indexed array format, where the first array (the "indices") is a set of offsets to
34    * be used in the second array (the "values"), to extract packs of values.
35    *
36    * Example:
37    *    index = [0,2,7,10]
38    *    values = [1,24,2,33,6,7,10,11,9,28]
39    * which describes 3 packs of (integer) values : [1,24] and [2,33,6,7,10] and [11,9,28]
40    *
41    * Thus the index array is always monotic ascendant.
42    *
43    * This class allows to pursue this logic up to 3 levels, i.e. the first array (the "indices") points to packs in the
44    * second (the "values"), which itself points to identifiers in a third array (the "sub-values").
45    *
46    * This particularly useful for connectivity of pure polygonal/polyhedral meshes.
47    *
48    * Example:
49    *     super-index = [0,1,3]
50    *     index = [0,3,6,10]
51    *     values = [28,1,4,2,35,8,9,10,1,12]
52    * which represent two 3 packs and two super-packs. The first super-pack is [[28,1,4]] and has only one pack [28,1,4].
53    * The second super-pack is [[2,35,8], [9,10,1,12]] and has two packs [2,35,8] and [9,10,1,12].
54    * Note that contrary to index, the integers in super-index are interpreted as being inclusive: the first super-pack
55    * goes from offset 0 to offset 1, inclusive. This is not the same for index, where the upper bound is exclusive.
56    */
57   class MEDCOUPLING_EXPORT MEDCouplingSkyLineArray : public RefCountObject
58   {
59   public:
60     static MEDCouplingSkyLineArray * New();
61     static MEDCouplingSkyLineArray * New( const std::vector<mcIdType>& index, const std::vector<mcIdType>& value);
62     static MEDCouplingSkyLineArray * New( DataArrayIdType* index, DataArrayIdType* value );
63     static MEDCouplingSkyLineArray * New( const MEDCouplingSkyLineArray & other );
64
65     static MEDCouplingSkyLineArray * BuildFromPolyhedronConn( const DataArrayIdType* c, const DataArrayIdType* cI );
66     std::string getClassName() const override { return std::string("MEDCouplingSkyLineArray"); }
67     std::size_t getHeapMemorySizeWithoutChildren() const;
68     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
69
70     void set( DataArrayIdType* index, DataArrayIdType* value );
71     void set3( DataArrayIdType* superIndex, DataArrayIdType* index, DataArrayIdType* value );
72
73     mcIdType getSuperNumberOf()   const { return ToIdType(_super_index->getNbOfElems())-1; }
74     mcIdType getNumberOf() const { return ToIdType(_index->getNbOfElems())-1; }
75     mcIdType getLength()   const { return ToIdType(_values->getNbOfElems()); }
76
77     const mcIdType* getSuperIndex() const { return _super_index->begin(); }
78     const mcIdType* getIndex() const { return _index->begin(); }
79     const mcIdType* getValues() const { return _values->begin(); }
80
81     DataArrayIdType* getSuperIndexArray() const;
82     DataArrayIdType* getIndexArray() const;
83     DataArrayIdType* getValuesArray() const;
84
85     std::string simpleRepr() const;
86
87     void getSimplePackSafe(const mcIdType absolutePackId, std::vector<mcIdType> & pack) const;
88     const mcIdType * getSimplePackSafePtr(const mcIdType absolutePackId, mcIdType & packSize) const;
89     void findPackIds(const std::vector<mcIdType> & superPackIndices, const mcIdType *packBg, const mcIdType *packEnd,
90                      std::vector<mcIdType>& out) const;
91
92     void deletePack(const mcIdType superIdx, const mcIdType idx);
93     void deleteSimplePack(const mcIdType idx);
94     void pushBackPack(const mcIdType superIdx, const mcIdType * packBg, const mcIdType * packEnd);
95
96     void replaceSimplePack(const mcIdType idx, const mcIdType * packBg, const mcIdType * packEnd);
97     void replacePack(const mcIdType superIdx, const mcIdType idx, const mcIdType * packBg, const mcIdType * packEnd);
98
99     void deleteSimplePacks(const DataArrayIdType* idx);
100     void replaceSimplePacks(const DataArrayIdType* idx, const std::vector<const DataArrayIdType*>& packs);
101     
102     void convertToPolyhedronConn( MCAuto<DataArrayIdType>& c,  MCAuto<DataArrayIdType>& cI) const;
103
104   private:
105     MEDCouplingSkyLineArray();
106     ~MEDCouplingSkyLineArray();
107
108     void checkSuperIndex(const std::string& func) const;
109     void validSuperIndex(const std::string& func, mcIdType superIndex) const;
110     void validIndex(const std::string& func, mcIdType index) const;
111     void validSuperIndexAndIndex(const std::string& func, mcIdType superIndex, mcIdType index) const;
112
113     MCAuto<DataArrayIdType> _super_index;
114     MCAuto<DataArrayIdType> _index;
115     MCAuto<DataArrayIdType> _values;
116   };
117
118 }
119 # endif