Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "edgeMesh.H"
00027 #include <OpenFOAM/mergePoints.H>
00028 #include <OpenFOAM/StaticHashTable.H>
00029
00030
00031
00032
00033
00034 void Foam::edgeMesh::calcPointEdges() const
00035 {
00036 if (pointEdgesPtr_.valid())
00037 {
00038 FatalErrorIn("edgeMesh::calcPointEdges() const")
00039 << "pointEdges already calculated." << abort(FatalError);
00040 }
00041
00042 pointEdgesPtr_.reset(new labelListList(points_.size()));
00043 labelListList& pointEdges = pointEdgesPtr_();
00044
00045
00046 labelList nEdgesPerPoint(points_.size(), 0);
00047
00048 forAll(edges_, edgeI)
00049 {
00050 const edge& e = edges_[edgeI];
00051
00052 nEdgesPerPoint[e[0]]++;
00053 nEdgesPerPoint[e[1]]++;
00054 }
00055
00056
00057 forAll(pointEdges, pointI)
00058 {
00059 pointEdges[pointI].setSize(nEdgesPerPoint[pointI]);
00060 }
00061
00062
00063 nEdgesPerPoint = 0;
00064
00065 forAll(edges_, edgeI)
00066 {
00067 const edge& e = edges_[edgeI];
00068
00069 label p0 = e[0];
00070 pointEdges[p0][nEdgesPerPoint[p0]++] = edgeI;
00071 label p1 = e[1];
00072 pointEdges[p1][nEdgesPerPoint[p1]++] = edgeI;
00073 }
00074 }
00075
00076
00077
00078
00079
00080 Foam::edgeMesh::edgeMesh(const pointField& points, const edgeList& edges)
00081 :
00082 points_(points),
00083 edges_(edges)
00084 {}
00085
00086
00087
00088 Foam::edgeMesh::edgeMesh(const edgeMesh& em)
00089 :
00090 points_(em.points_),
00091 edges_(em.edges_),
00092 pointEdgesPtr_(NULL)
00093 {}
00094
00095
00096
00097
00098 Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
00099 {
00100 edgeRegion.setSize(edges_.size());
00101 edgeRegion = -1;
00102
00103 label startEdgeI = 0;
00104
00105 label currentRegion = 0;
00106
00107 while (true)
00108 {
00109 while (startEdgeI < edges_.size() && edgeRegion[startEdgeI] != -1)
00110 {
00111 startEdgeI++;
00112 }
00113
00114 if (startEdgeI == edges_.size())
00115 {
00116 break;
00117 }
00118
00119
00120
00121
00122 edgeRegion[startEdgeI] = currentRegion;
00123 labelList edgesToVisit(1, startEdgeI);
00124
00125 while (edgesToVisit.size())
00126 {
00127
00128 DynamicList<label> newEdgesToVisit(edgesToVisit.size());
00129
00130
00131 forAll(edgesToVisit, i)
00132 {
00133 label edgeI = edgesToVisit[i];
00134
00135
00136 const edge& e = edges_[edgeI];
00137
00138 forAll(e, fp)
00139 {
00140 const labelList& pEdges = pointEdges()[e[fp]];
00141
00142 forAll(pEdges, pEdgeI)
00143 {
00144 label nbrEdgeI = pEdges[pEdgeI];
00145
00146 if (edgeRegion[nbrEdgeI] == -1)
00147 {
00148 edgeRegion[nbrEdgeI] = currentRegion;
00149 newEdgesToVisit.append(nbrEdgeI);
00150 }
00151 }
00152 }
00153 }
00154
00155 edgesToVisit.transfer(newEdgesToVisit);
00156 }
00157
00158 currentRegion++;
00159 }
00160 return currentRegion;
00161 }
00162
00163
00164 void Foam::edgeMesh::mergePoints(const scalar mergeDist)
00165 {
00166 pointField newPoints;
00167 labelList pointMap;
00168
00169 bool hasMerged = Foam::mergePoints
00170 (
00171 points_,
00172 mergeDist,
00173 false,
00174 pointMap,
00175 newPoints,
00176 vector::zero
00177 );
00178
00179 if (hasMerged)
00180 {
00181 pointEdgesPtr_.clear();
00182
00183 points_.transfer(newPoints);
00184
00185
00186 forAll(edges_, edgeI)
00187 {
00188 edge& e = edges_[edgeI];
00189
00190 label p0 = pointMap[e[0]];
00191 label p1 = pointMap[e[1]];
00192
00193 if (p0 < p1)
00194 {
00195 e[0] = p0;
00196 e[1] = p1;
00197 }
00198 else
00199 {
00200 e[0] = p1;
00201 e[1] = p0;
00202 }
00203 }
00204
00205
00206 StaticHashTable<label, edge, Hash<edge> > edgeToLabel
00207 (
00208 2*edges_.size()
00209 );
00210
00211 label newEdgeI = 0;
00212
00213 forAll(edges_, edgeI)
00214 {
00215 const edge& e = edges_[edgeI];
00216
00217 if (e[0] != e[1])
00218 {
00219 if (edgeToLabel.insert(e, newEdgeI))
00220 {
00221 newEdgeI++;
00222 }
00223 }
00224 }
00225
00226 edges_.setSize(newEdgeI);
00227
00228 for
00229 (
00230 StaticHashTable<label, edge, Hash<edge> >::const_iterator iter =
00231 edgeToLabel.begin();
00232 iter != edgeToLabel.end();
00233 ++iter
00234 )
00235 {
00236 edges_[iter()] = iter.key();
00237 }
00238 }
00239 }
00240
00241
00242
00243
00244 void Foam::edgeMesh::operator=(const edgeMesh& rhs)
00245 {
00246 points_ = rhs.points_;
00247 edges_ = rhs.edges_;
00248 pointEdgesPtr_.reset(NULL);
00249 }
00250
00251
00252