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