Salome HOME
d76dc55c675c81957cc66e2860bbb56a19dd91a6
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingPointSet.hxx
1 // Copyright (C) 2007-2019  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 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __PARAMEDMEM_MEDCOUPLINGPOINTSET_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGPOINTSET_HXX__
23
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingMesh.hxx"
26
27 #include "InterpKernelHashMap.hxx"
28
29 #include <vector>
30
31 namespace INTERP_KERNEL
32 {
33   class DirectedBoundingBox;
34 }
35
36 namespace MEDCoupling
37 {
38   class DataArrayIdType;
39   class DataArrayDouble;
40   
41   /*!
42    * This class is abstract and not instanciable.
43    * MEDCoupling::MEDCouplingUMesh class inherits from this class.
44    * This class aggregates an array '_coords' containing nodes coordinates.
45    * So all operations on coordinates are managed by this class.
46    * This is the case for example for following methods :
47    * rotation, translation, scaling, getNodeIdsNearPoint, boundingbox...
48    */
49   class MEDCouplingPointSet : public MEDCouplingMesh
50   {
51   protected:
52     MEDCOUPLING_EXPORT MEDCouplingPointSet();
53     MEDCOUPLING_EXPORT MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCpy);
54     MEDCOUPLING_EXPORT ~MEDCouplingPointSet();
55   public:
56     MEDCOUPLING_EXPORT void updateTime() const;
57     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
58     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
59     MEDCOUPLING_EXPORT mcIdType getNumberOfNodes() const;
60     MEDCOUPLING_EXPORT int getSpaceDimension() const;
61     MEDCOUPLING_EXPORT void setCoords(const DataArrayDouble *coords);
62     MEDCOUPLING_EXPORT const DataArrayDouble *getCoords() const { return _coords; }
63     MEDCOUPLING_EXPORT DataArrayDouble *getCoords() { return _coords; }
64     MEDCOUPLING_EXPORT DataArrayDouble *getCoordinatesAndOwner() const;
65     MEDCOUPLING_EXPORT const DataArrayDouble *getDirectAccessOfCoordsArrIfInStructure() const { return _coords; }
66     MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingMesh *other);
67     MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const;
68     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const;
69     MEDCOUPLING_EXPORT void checkFastEquivalWith(const MEDCouplingMesh *other, double prec) const;
70     MEDCOUPLING_EXPORT void checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
71                                                  DataArrayIdType *&cellCor, DataArrayIdType *&nodeCor) const;
72     MEDCOUPLING_EXPORT void checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
73                                                             DataArrayIdType *&cellCor) const;
74     MEDCOUPLING_EXPORT bool areCoordsEqualIfNotWhy(const MEDCouplingPointSet& other, double prec, std::string& reason) const;
75     MEDCOUPLING_EXPORT bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const;
76     MEDCOUPLING_EXPORT bool areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const;
77     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *deepCopyConnectivityOnly() const = 0;
78     MEDCOUPLING_EXPORT virtual void shallowCopyConnectivityFrom(const MEDCouplingPointSet *other) = 0;
79     MEDCOUPLING_EXPORT virtual DataArrayIdType *mergeNodes(double precision, bool& areNodesMerged, mcIdType& newNbOfNodes);
80     MEDCOUPLING_EXPORT virtual DataArrayIdType *mergeNodesCenter(double precision, bool& areNodesMerged, mcIdType& newNbOfNodes);
81     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *mergeMyselfWithOnSameCoords(const MEDCouplingPointSet *other) const = 0;
82     MEDCOUPLING_EXPORT virtual void computeNodeIdsAlg(std::vector<bool>& nodeIdsInUse) const = 0;
83     MEDCOUPLING_EXPORT void getCoordinatesOfNode(mcIdType nodeId, std::vector<double>& coo) const;
84     MEDCOUPLING_EXPORT DataArrayIdType *buildPermArrayForMergeNode(double precision, mcIdType limitNodeId, bool& areNodesMerged, mcIdType& newNbOfNodes) const;
85     MEDCOUPLING_EXPORT DataArrayIdType *getNodeIdsNearPoint(const double *pos, double eps) const;
86     MEDCOUPLING_EXPORT void getNodeIdsNearPoints(const double *pos, mcIdType nbOfPoints, double eps, DataArrayIdType *& c, DataArrayIdType *& cI) const;
87     MEDCOUPLING_EXPORT void findCommonNodes(double prec, mcIdType limitNodeId, DataArrayIdType *&comm, DataArrayIdType *&commIndex) const;
88     MEDCOUPLING_EXPORT virtual void findCommonCells(int compType, mcIdType startCellId, DataArrayIdType *& commonCellsArr, DataArrayIdType *& commonCellsIArr) const = 0;
89     MEDCOUPLING_EXPORT DataArrayIdType *buildNewNumberingFromCommonNodesFormat(const DataArrayIdType *comm, const DataArrayIdType *commIndex,
90                                                                             mcIdType& newNbOfNodes) const;
91     MEDCOUPLING_EXPORT void getBoundingBox(double *bbox) const;
92     MEDCOUPLING_EXPORT void zipCoords();
93     MEDCOUPLING_EXPORT double getCaracteristicDimension() const;
94     MEDCOUPLING_EXPORT void recenterForMaxPrecision(double eps);
95     MEDCOUPLING_EXPORT void rotate(const double *center, const double *vector, double angle);
96     MEDCOUPLING_EXPORT void translate(const double *vector);
97     MEDCOUPLING_EXPORT void scale(const double *point, double factor);
98     MEDCOUPLING_EXPORT void changeSpaceDimension(int newSpaceDim, double dftVal=0.);
99     MEDCOUPLING_EXPORT void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon);
100     MEDCOUPLING_EXPORT void duplicateNodesInCoords(const mcIdType *nodeIdsToDuplicateBg, const mcIdType *nodeIdsToDuplicateEnd);
101     MEDCOUPLING_EXPORT virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon);
102     MEDCOUPLING_EXPORT void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector<mcIdType>& nodes) const;
103     MEDCOUPLING_EXPORT void findNodesOnLine(const double *pt, const double *vec, double eps, std::vector<mcIdType>& nodes) const;
104     MEDCOUPLING_EXPORT static DataArrayDouble *MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2);
105     MEDCOUPLING_EXPORT static DataArrayDouble *MergeNodesArray(const std::vector<const MEDCouplingPointSet *>& ms);
106     MEDCOUPLING_EXPORT static MEDCouplingPointSet *BuildInstanceFromMeshType(MEDCouplingMeshType type);
107     MEDCOUPLING_EXPORT static DataArrayIdType *ComputeNbOfInteractionsWithSrcCells(const MEDCouplingPointSet *srcMesh, const MEDCouplingPointSet *trgMesh, double eps);
108     MEDCOUPLING_EXPORT MEDCouplingMesh *buildPart(const mcIdType *start, const mcIdType *end) const;
109     MEDCOUPLING_EXPORT MEDCouplingMesh *buildPartAndReduceNodes(const mcIdType *start, const mcIdType *end, DataArrayIdType*& arr) const;
110     MEDCOUPLING_EXPORT MEDCouplingMesh *buildPartRange(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds) const;
111     MEDCOUPLING_EXPORT MEDCouplingMesh *buildPartRangeAndReduceNodes(mcIdType beginCellIds, mcIdType endCellIds, mcIdType stepCellIds, mcIdType& beginOut, mcIdType& endOut, mcIdType& stepOut, DataArrayIdType*& arr) const;
112     MEDCOUPLING_EXPORT DataArrayIdType *getCellIdsFullyIncludedInNodeIds(const mcIdType *partBg, const mcIdType *partEnd) const;
113     MEDCOUPLING_EXPORT DataArrayIdType *getCellIdsLyingOnNodes(const mcIdType *begin, const mcIdType *end, bool fullyIn) const;
114     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildPartOfMySelf(const mcIdType *start, const mcIdType *end, bool keepCoords=true) const;
115     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildPartOfMySelfSlice(mcIdType start, mcIdType end, mcIdType step, bool keepCoords=true) const;
116     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildPartOfMySelfKeepCoords(const mcIdType *begin, const mcIdType *end) const = 0;
117     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildPartOfMySelfKeepCoordsSlice(mcIdType start, mcIdType end, mcIdType step) const = 0;
118     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildPartOfMySelfNode(const mcIdType *start, const mcIdType *end, bool fullyIn) const;
119     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const mcIdType *start, const mcIdType *end, bool fullyIn) const = 0;
120     MEDCOUPLING_EXPORT virtual DataArrayIdType *findBoundaryNodes() const = 0;
121     MEDCOUPLING_EXPORT virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0;
122     MEDCOUPLING_EXPORT virtual mcIdType getNumberOfNodesInCell(mcIdType cellId) const = 0;
123     MEDCOUPLING_EXPORT virtual DataArrayIdType *computeFetchedNodeIds() const = 0;
124     MEDCOUPLING_EXPORT virtual DataArrayIdType *getNodeIdsInUse(mcIdType& nbrOfNodesInUse) const = 0;
125     MEDCOUPLING_EXPORT virtual void fillCellIdsToKeepFromNodeIds(const mcIdType *begin, const mcIdType *end, bool fullyIn, DataArrayIdType *&cellIdsKeptArr) const = 0;
126     MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const mcIdType *newNodeNumbersO2N) = 0;
127     MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const INTERP_KERNEL::HashMap<mcIdType,mcIdType>& newNodeNumbersO2N) = 0;
128     MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const std::map<mcIdType,mcIdType>& newNodeNumbersO2N) = 0;
129     MEDCOUPLING_EXPORT virtual void renumberNodesWithOffsetInConn(mcIdType offset) = 0;
130     MEDCOUPLING_EXPORT virtual void renumberNodes(const mcIdType *newNodeNumbers, mcIdType newNbOfNodes);
131     MEDCOUPLING_EXPORT virtual void renumberNodesCenter(const mcIdType *newNodeNumbers, mcIdType newNbOfNodes);
132     MEDCOUPLING_EXPORT virtual bool isEmptyMesh(const std::vector<mcIdType>& tinyInfo) const = 0;
133     MEDCOUPLING_EXPORT virtual void invertOrientationOfAllCells() = 0;
134     MEDCOUPLING_EXPORT virtual void checkFullyDefined() const = 0;
135     MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<mcIdType>& tinyInfo, std::vector<std::string>& littleStrings) const;
136     MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<mcIdType>& tinyInfo, DataArrayIdType *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
137     MEDCOUPLING_EXPORT void serialize(DataArrayIdType *&a1, DataArrayDouble *&a2) const;
138     MEDCOUPLING_EXPORT void unserialization(const std::vector<double>& tinyInfoD, const std::vector<mcIdType>& tinyInfo, const DataArrayIdType *a1, DataArrayDouble *a2,
139                                             const std::vector<std::string>& littleStrings);
140     MEDCOUPLING_EXPORT virtual DataArrayDouble *getBoundingBoxForBBTree(double arcDetEps=1e-12) const = 0;
141     MEDCOUPLING_EXPORT virtual DataArrayIdType *getCellsInBoundingBox(const double *bbox, double eps) const = 0;
142     MEDCOUPLING_EXPORT virtual DataArrayIdType *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) = 0;
143     MEDCOUPLING_EXPORT virtual MEDCouplingFieldDouble *computeDiameterField() const = 0;
144     MEDCOUPLING_EXPORT virtual DataArrayIdType *zipCoordsTraducer();
145     MEDCOUPLING_EXPORT virtual DataArrayIdType *zipConnectivityTraducer(int compType, mcIdType startCellId=0);
146     MEDCOUPLING_EXPORT virtual bool areAllNodesFetched() const;
147     //tools
148   public:
149     MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingPointSet *other, mcIdType cellId, double prec) const;
150   protected:
151     MEDCOUPLING_EXPORT void checkConsistencyLight() const;
152     MEDCOUPLING_EXPORT static bool intersectsBoundingBox(const double* bb1, const double* bb2, int dim, double eps);
153     MEDCOUPLING_EXPORT static bool intersectsBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bb1, const double* bb2, int dim, double eps);
154     MEDCOUPLING_EXPORT void rotate2D(const double *center, double angle);
155     MEDCOUPLING_EXPORT void rotate3D(const double *center, const double *vect, double angle);
156     MEDCOUPLING_EXPORT void project2DCellOnXY(const mcIdType *startConn, const mcIdType *endConn, std::vector<double>& res) const;
157     MEDCOUPLING_EXPORT static bool isButterfly2DCell(const std::vector<double>& res, bool isQuad, double eps);
158   protected:
159     DataArrayDouble *_coords;
160   };
161 }
162
163 #endif