triSurfaceRemoveFacetsFunctions.C 6.07 KB
Newer Older
Franjo's avatar
Franjo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
    This file is part of cfMesh.

    cfMesh is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 3 of the License, or (at your
    option) any later version.

    cfMesh is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.

Description

\*---------------------------------------------------------------------------*/

#include "triSurfaceRemoveFacets.H"
#include "triSurfModifier.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

void triSurfaceRemoveFacets::markFacetsForRemoval(boolList& removeFacet) const
{
    removeFacet.setSize(surf_.size());
    removeFacet = false;

    const geometricSurfacePatchList& patches = surf_.patches();

    //- mark patches which will be removed
    boolList removePatch(patches.size(), false);

    forAll(patches, patchI)
    {
        if( selectedEntities_.contains(patches[patchI].name()) )
            removePatch[patchI] = true;
    }

    //- select facets affected by the deletion of a patch
    forAll(surf_, triI)
    {
        if( removePatch[surf_[triI].region()] )
            removeFacet[triI] = true;
    }

    //- mark facets contained in selected subsets
    DynList<label> facetSubsetsIDs;
    surf_.facetSubsetIndices(facetSubsetsIDs);

    forAll(facetSubsetsIDs, i)
    {
        const word fsName = surf_.facetSubsetName(facetSubsetsIDs[i]);

        if( selectedEntities_.contains(fsName) )
        {
            labelLongList containedFacets;
            surf_.facetsInSubset(facetSubsetsIDs[i], containedFacets);

            forAll(containedFacets, cfI)
                removeFacet[containedFacets[cfI]] = true;
        }
    }
}

void triSurfaceRemoveFacets::removeFacets()
{
    boolList removeFacet;
    markFacetsForRemoval(removeFacet);

    //- calculate new indices of vertices and facets
    const pointField& points = surf_.points();
    labelLongList newPointLabel(surf_.points().size(), -1);
    labelLongList newFacetLabel(surf_.size(), -1);

    label pointCounter(0), facetCounter(0);

    forAll(removeFacet, triI)
    {
        if( removeFacet[triI] )
            continue;

        const labelledTri& tri = surf_[triI];

        forAll(tri, pI)
        {
            if( newPointLabel[tri[pI]] == -1 )
                newPointLabel[tri[pI]] = pointCounter++;
        }

        newFacetLabel[triI] = facetCounter++;
    }

    //- remove vertices
    pointField newPts(pointCounter);
    forAll(newPointLabel, pI)
    {
        if( newPointLabel[pI] < 0 )
            continue;

        newPts[newPointLabel[pI]] = points[pI];
    }

    triSurfModifier(surf_).pointsAccess().transfer(newPts);
    surf_.updatePointSubsets(newPointLabel);

    //- remove facets
    LongList<labelledTri> newFacets(facetCounter);

    forAll(newFacetLabel, triI)
    {
        if( newFacetLabel[triI] < 0 )
            continue;

        const labelledTri& tri = surf_[triI];

        newFacets[newFacetLabel[triI]] =
            labelledTri
            (
                newPointLabel[tri[0]],
                newPointLabel[tri[1]],
                newPointLabel[tri[2]],
                tri.region()
            );
    }

    triSurfModifier(surf_).facetsAccess().transfer(newFacets);
    surf_.updateFacetsSubsets(newFacetLabel);

    //- update feature edges
    const edgeLongList& featureEdges = surf_.featureEdges();
Franjo's avatar
Franjo committed
146
147
148
149
    const VRWGraph& pointEdges = surf_.pointEdges();
    const edgeLongList& edges = surf_.edges();
    const VRWGraph& edgeFacets = surf_.edgeFacets();

Franjo's avatar
Franjo committed
150
151
152
153
154
155
156
157
158
159
    label edgeCounter(0);
    labelLongList newFeatureEdgeLabel(featureEdges.size(), -1);

    forAll(featureEdges, feI)
    {
        const edge& e = featureEdges[feI];

        if( (newPointLabel[e.start()] < 0) || (newPointLabel[e.end()] < 0) )
            continue;

Franjo's avatar
Franjo committed
160
161
162
163
164
165
166
167
168
169
170
171
        //- find global edge label
        label eI(-1);
        forAllRow(pointEdges, e.start(), peI)
        {
            const label eJ = pointEdges(e.start(), peI);
            if( edges[eJ] == e )
            {
                eI = eJ;
                break;
            }
        }

172
173
174
        if( eI < 0 )
            continue;

Franjo's avatar
Franjo committed
175
176
177
178
        //- check if the edge is attached to at least one triangle
        bool foundTriangle(false);
        forAllRow(edgeFacets, eI, efI)
        {
Franjo's avatar
Franjo committed
179
            if( newFacetLabel[edgeFacets(eI, efI)] >= 0 )
Franjo's avatar
Franjo committed
180
181
182
183
184
185
186
187
            {
                foundTriangle = true;
                break;
            }
        }
        if( !foundTriangle )
            continue;

Franjo's avatar
Franjo committed
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
        newFeatureEdgeLabel[feI] = edgeCounter++;
    }

    edgeLongList newFeatureEdges(edgeCounter);
    forAll(newFeatureEdgeLabel, eI)
    {
        if( newFeatureEdgeLabel[eI] < 0 )
            continue;

        const edge& e = featureEdges[eI];

        newFeatureEdges[newFeatureEdgeLabel[eI]] =
            edge
            (
                newPointLabel[e.start()],
                newPointLabel[e.end()]
            );
    }

    triSurfModifier(surf_).featureEdgesAccess().transfer(newFeatureEdges);
    surf_.updateEdgeSubsets(newFeatureEdgeLabel);

    selectedEntities_.clear();
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// ************************************************************************* //