1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __PARAMEDMEM_MEDCOUPLINGPOINTSET_HXX__
21 #define __PARAMEDMEM_MEDCOUPLINGPOINTSET_HXX__
23 #include "MEDCoupling.hxx"
24 #include "MEDCouplingMesh.hxx"
28 namespace INTERP_KERNEL
30 class DirectedBoundingBox;
36 class DataArrayDouble;
39 * This class is abstract and not instanciable.
40 * ParaMEDMEM::MEDCouplingUMesh class inherits from this class.
41 * This class aggregates an array '_coords' containing nodes coordinates.
42 * So all operations on coordinates are managed by this class.
43 * This is the case for example for following methods :
44 * rotation, translation, scaling, getNodeIdsNearPoint, boundingbox...
46 class MEDCOUPLING_EXPORT MEDCouplingPointSet : public MEDCouplingMesh
49 MEDCouplingPointSet();
50 MEDCouplingPointSet(const MEDCouplingPointSet& other, bool deepCopy);
51 ~MEDCouplingPointSet();
53 void updateTime() const;
54 int getNumberOfNodes() const;
55 int getSpaceDimension() const;
56 void setCoords(const DataArrayDouble *coords);
57 //! This method returns directly the array in 'this' \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer
58 const DataArrayDouble *getCoords() const { return _coords; }
59 //! This method returns directly the array in 'this' \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer
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 bool areCoordsEqualIfNotWhy(const MEDCouplingPointSet& other, double prec, std::string& reason) const;
66 bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const;
67 bool areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const;
68 virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0;
69 virtual DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0;
70 void getCoordinatesOfNode(int nodeId, std::vector<double>& coo) const throw(INTERP_KERNEL::Exception);
71 DataArrayInt *buildPermArrayForMergeNode(double precision, int limitNodeId, bool& areNodesMerged, int& newNbOfNodes) const;
72 std::vector<int> getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception);
73 void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, std::vector<int>& c, std::vector<int>& cI) const throw(INTERP_KERNEL::Exception);
74 void findCommonNodes(double prec, int limitNodeId, DataArrayInt *&comm, DataArrayInt *&commIndex) const;
75 DataArrayInt *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex,
76 int& newNbOfNodes) const;
77 void getBoundingBox(double *bbox) const throw(INTERP_KERNEL::Exception);
79 double getCaracteristicDimension() const;
80 void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception);
81 void rotate(const double *center, const double *vector, double angle);
82 void translate(const double *vector);
83 void scale(const double *point, double factor);
84 void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception);
85 void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception);
86 void duplicateNodesInCoords(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd) throw(INTERP_KERNEL::Exception);
87 virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) = 0;
88 void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector<int>& nodes) const throw(INTERP_KERNEL::Exception);
89 void findNodesOnLine(const double *pt, const double *vec, double eps, std::vector<int>& nodes) const throw(INTERP_KERNEL::Exception);
90 static DataArrayDouble *MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception);
91 static DataArrayDouble *MergeNodesArray(const std::vector<const MEDCouplingPointSet *>& ms) throw(INTERP_KERNEL::Exception);
92 static MEDCouplingPointSet *BuildInstanceFromMeshType(MEDCouplingMeshType type);
93 static void Rotate2DAlg(const double *center, double angle, int nbNodes, double *coords);
94 static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, double *coords);
95 MEDCouplingMesh *buildPart(const int *start, const int *end) const;
96 MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const;
97 virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords=true) const = 0;
98 virtual MEDCouplingPointSet *buildPartOfMySelf2(int start, int end, int step, bool keepCoords=true) const throw(INTERP_KERNEL::Exception) = 0;
99 virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0;
100 virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0;
101 virtual DataArrayInt *findBoundaryNodes() const = 0;
102 virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0;
103 virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes);
104 virtual void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes);
105 virtual bool isEmptyMesh(const std::vector<int>& tinyInfo) const = 0;
106 //! size of returned tinyInfo must be always the same.
107 void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
108 void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
109 void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const;
110 void unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2,
111 const std::vector<std::string>& littleStrings);
112 virtual void getCellsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems) const = 0;
113 virtual void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector<int>& elems) = 0;
114 virtual DataArrayInt *zipCoordsTraducer() = 0;
116 virtual void checkFullyDefined() const throw(INTERP_KERNEL::Exception) = 0;
117 static bool intersectsBoundingBox(const double* bb1, const double* bb2, int dim, double eps);
118 static bool intersectsBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bb1, const double* bb2, int dim, double eps);
119 void rotate2D(const double *center, double angle);
120 void rotate3D(const double *center, const double *vect, double angle);
121 void project2DCellOnXY(const int *startConn, const int *endConn, std::vector<double>& res) const;
122 static bool isButterfly2DCell(const std::vector<double>& res, bool isQuad, double eps);
124 DataArrayDouble *_coords;