39 DynamicList<label>& bPointRegions
42 if (bPointRegions.empty())
44 bPointRegions.append(regionI);
46 else if (
findIndex(bPointRegions, regionI) == -1)
48 bPointRegions.append(regionI);
55 List<DynamicList<label> >& boundaryPointRegions
60 const edge&
e = iter.key();
61 const label& regionI = iter();
63 const label startI =
e.start();
64 const label endI =
e.end();
66 addRegion(regionI, boundaryPointRegions[startI]);
67 addRegion(regionI, boundaryPointRegions[endI]);
74 const MeshedSurface<face>& surfMesh,
75 const List<DynamicList<label> >& boundaryPtRegions,
77 EdgeMap<label>& mapEdgesRegion,
81 EdgeMap<label> newMapEdgesRegion(mapEdgesRegion.size());
83 const edgeList& edges = surfMesh.edges();
84 const labelList& meshPoints = surfMesh.meshPoints();
86 patchSizes.
setSize(patchNames_.size(), 0);
91 if (surfMesh.isInternalEdge(edgeI))
96 const edge&
e = edges[edgeI];
98 const label startI = meshPoints[
e[0]];
99 const label endI = meshPoints[
e[1]];
103 const DynamicList<label> startPtRegions =
104 boundaryPtRegions[surfPtToBoundaryPt[startI]];
105 const DynamicList<label> endPtRegions =
106 boundaryPtRegions[surfPtToBoundaryPt[endI]];
108 if (startPtRegions.size() > 1 && endPtRegions.size() > 1)
110 region = startPtRegions[0];
113 <<
"Both points in edge are in different regions."
114 <<
" Assigning edge to region " << region
117 else if (startPtRegions.size() > 1 || endPtRegions.size() > 1)
121 startPtRegions.size() > 1
128 startPtRegions[0] == endPtRegions[0]
129 && startPtRegions[0] != -1
132 region = startPtRegions[0];
137 newMapEdgesRegion.insert(
e, region);
138 patchSizes[region]++;
142 mapEdgesRegion.transfer(newMapEdgesRegion);
151 const dictionary&
dict
156 edgeAttachedToBoundaryFactor_
158 dict.lookupOrDefault<scalar>(
"edgeAttachedToBoundaryFactor", 2.0)
186 OFstream str(
"indirectPatchEdges.obj");
189 Info<<
"Writing indirectPatchEdges to " << str.name() <<
endl;
193 const edge&
e = iter.key();
209 Info<<
"Meshed surface stats before edge filtering :" <<
endl;
210 ms_.writeStats(
Info);
216 ms_.write(
"MeshedSurface_preFilter.obj");
234 const edgeList& edges = ms_.edges();
235 const faceList& faces = ms_.faces();
236 const labelList& meshPoints = ms_.meshPoints();
237 const labelList& boundaryPoints = ms_.boundaryPoints();
240 label nPointsToRemove = 0;
242 labelList pointsToRemove(ms_.points().size(), -1);
245 labelList newFaceVertexCount(faces.size(), -1);
248 newFaceVertexCount[faceI] = faces[faceI].size();
258 assignBoundaryPointRegions(boundaryPointRegions);
262 Info<<
" Marking edges attached to boundaries." <<
endl;
263 boolList edgeAttachedToBoundary(edges.size(),
false);
266 const edge&
e = edges[edgeI];
267 const label startVertex =
e.start();
268 const label endVertex =
e.end();
270 forAll(boundaryPoints, bPoint)
274 boundaryPoints[bPoint] == startVertex
275 || boundaryPoints[bPoint] == endVertex
278 edgeAttachedToBoundary[edgeI] =
true;
285 const edge&
e = edges[edgeI];
288 const label startVertex =
e.start();
289 const label endVertex =
e.end();
294 points[meshPoints[startVertex]]
295 -
points[meshPoints[endVertex]]
298 if (edgeAttachedToBoundary[edgeI])
300 edgeLength *= edgeAttachedToBoundaryFactor_;
303 scalar shortEdgeFilterValue = 0.0;
305 const labelList& psEdges = ms_.pointEdges()[startVertex];
306 const labelList& peEdges = ms_.pointEdges()[endVertex];
310 const edge& psE = edges[psEdges[psEdgeI]];
311 if (edgeI != psEdges[psEdgeI])
313 shortEdgeFilterValue +=
316 points[meshPoints[psE.start()]]
317 -
points[meshPoints[psE.end()]]
324 const edge& peE = edges[peEdges[peEdgeI]];
325 if (edgeI != peEdges[peEdgeI])
327 shortEdgeFilterValue +=
330 points[meshPoints[peE.start()]]
331 -
points[meshPoints[peE.end()]]
336 shortEdgeFilterValue *=
337 shortEdgeFilterFactor_
338 /(psEdges.size() + peEdges.size() - 2);
340 edge lookupInPatchEdge
342 meshPoints[startVertex],
343 meshPoints[endVertex]
348 edgeLength < shortEdgeFilterValue
349 || indirectPatchEdge_.found(lookupInPatchEdge)
352 bool flagDegenerateFace =
false;
357 const face&
f = ms_.localFaces()[
pFaces[pFaceI]];
361 if (
f[fp] == endVertex)
364 if (newFaceVertexCount[
pFaces[pFaceI]] < 4)
366 flagDegenerateFace =
true;
370 newFaceVertexCount[
pFaces[pFaceI]]--;
377 if (newFaceVertexCount[
pFaces[pFaceI]] < 3)
379 flagDegenerateFace =
true;
388 pointsToRemove[meshPoints[startVertex]] == -1
389 && pointsToRemove[meshPoints[endVertex]] == -1
390 && !flagDegenerateFace
393 const DynamicList<label>& startVertexRegions =
394 boundaryPointRegions[meshPoints[startVertex]];
395 const DynamicList<label>& endVertexRegions =
396 boundaryPointRegions[meshPoints[endVertex]];
398 if (startVertexRegions.size() && endVertexRegions.size())
400 if (startVertexRegions.size() > 1)
402 pointsToRemove[meshPoints[endVertex]] =
403 meshPoints[startVertex];
407 pointsToRemove[meshPoints[startVertex]] =
408 meshPoints[endVertex];
411 else if (startVertexRegions.size())
413 pointsToRemove[meshPoints[endVertex]] =
414 meshPoints[startVertex];
418 pointsToRemove[meshPoints[startVertex]] =
419 meshPoints[endVertex];
427 label totalNewPoints =
points.size() - nPointsToRemove;
429 pointField newPoints(totalNewPoints, vector::zero);
431 label numberRemoved = 0;
434 labelList newPtToOldPt(totalNewPoints, -1);
439 if (pointsToRemove[pointI] == -1)
441 newPoints[pointI - numberRemoved] =
points[pointI];
442 newPointNumbers[pointI] = pointI - numberRemoved;
443 newPtToOldPt[pointI - numberRemoved] = pointI;
456 label newFaceSize = 0;
461 const face&
f = faces[faceI];
464 newFace.setSize(
f.size());
471 if (pointsToRemove[pointI] == -1)
473 newFace[newFaceSize++] = newPointNumbers[pointI];
477 label newPointI = pointsToRemove[pointI];
482 f.nextLabel(fp) != newPointI
483 &&
f.prevLabel(fp) != newPointI
486 label pChain = newPointI;
487 label totalChain = 0;
488 for (
label nChain = 0; nChain <= totalChain; ++nChain)
490 if (newPointNumbers[pChain] != -1)
492 newFace[newFaceSize++] = newPointNumbers[pChain];
493 newPointNumbers[pointI] = newPointNumbers[pChain];
494 maxChain =
max(totalChain, maxChain);
499 <<
"Point " << pChain
500 <<
" marked for deletion as well as point "
502 <<
" Incrementing maxChain by 1 from "
503 << totalChain <<
" to " << totalChain + 1
507 pChain = pointsToRemove[pChain];
512 if (newPointNumbers[newPointI] != -1)
514 newPointNumbers[pointI] = newPointNumbers[newPointI];
520 newFace.setSize(newFaceSize);
522 if (newFace.size() > 2)
524 newFaces[newFaceI++] = face(newFace);
529 <<
"Only " << newFace.size() <<
" in face " << faceI
534 newFaces.setSize(newFaceI);
536 MeshedSurface<face> fMesh
546 boundaryPointRegions,
552 forAll(newPointNumbers, pointI)
554 if (newPointNumbers[pointI] == -1)
557 << pointI <<
" will be deleted and " << newPointNumbers[pointI]
558 <<
", so it will not be replaced. "
559 <<
"This will cause edges to be deleted." <<
endl;
567 Info<<
" Maximum number of chained collapses = " << maxChain <<
endl;
576 os <<
"Short Edge Filtering Information:" <<
nl
577 <<
" shortEdgeFilterFactor: " << shortEdgeFilterFactor_ <<
nl
578 <<
" edgeAttachedToBoundaryFactor: " << edgeAttachedToBoundaryFactor_
581 forAll(patchNames_, patchI)
583 os <<
" Patch " << patchNames_[patchI]
584 <<
", size " << patchSizes_[patchI] <<
endl;
587 os <<
" There are " << mapEdgesRegion_.size()
588 <<
" boundary edges." <<
endl;
590 os <<
" Mesh Info:" <<
nl
591 <<
" Points: " << ms_.nPoints() <<
nl
592 <<
" Faces: " << ms_.size() <<
nl
593 <<
" Edges: " << ms_.nEdges() <<
nl
594 <<
" Internal: " << ms_.nInternalEdges() <<
nl
595 <<
" External: " << ms_.nEdges() - ms_.nInternalEdges()