Adding cfMesh-v1.0 into the repository
[foam-extend-3.2.git] / src / meshLibrary / utilities / meshes / triSurf / triSurf.C
blob1d2891679440f2660a8a8258ef3405c40a8f9d81
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
11     cfMesh is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 3 of the License, or (at your
14     option) any later version.
16     cfMesh is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "triSurf.H"
29 #include "demandDrivenData.H"
30 #include "IFstream.H"
31 #include "OFstream.H"
32 #include "Time.H"
34 #include "gzstream.h"
36 #include "triSurface.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 void triSurf::readFromFTR(const fileName& fName)
47     IFstream fStream(fName);
49     fStream >> triSurfFacets::patches_;
51     fStream >> triSurfPoints::points_;
53     fStream >> triSurfFacets::triangles_;
56 void triSurf::writeToFTR(const fileName& fName) const
58     OFstream fStream(fName);
60     fStream << triSurfFacets::patches_;
62     fStream << nl;
64     fStream << triSurfPoints::points_;
66     fStream << nl;
68     fStream << triSurfFacets::triangles_;
71 void triSurf::readFromFMS(const fileName& fName)
73     IFstream fStream(fName);
75     //- read the list of patches defined on the surface mesh
76     fStream >> triSurfFacets::patches_;
78     //- read points
79     fStream >> triSurfPoints::points_;
81     //- read surface triangles
82     fStream >> triSurfFacets::triangles_;
84     //- read feature edges
85     fStream >> triSurfFeatureEdges::featureEdges_;
87     List<meshSubset> subsets;
89     //- read point subsets
90     fStream >> subsets;
91     forAll(subsets, subsetI)
92         triSurfPoints::pointSubsets_.insert(subsetI, subsets[subsetI]);
94     subsets.clear();
96     //- read facet subsets
97     fStream >> subsets;
98     forAll(subsets, subsetI)
99         triSurfFacets::facetSubsets_.insert(subsetI, subsets[subsetI]);
101     subsets.clear();
103     //- read subsets on feature edges
104     fStream >> subsets;
105     forAll(subsets, subsetI)
106         triSurfFeatureEdges::featureEdgeSubsets_.insert
107         (
108             subsetI,
109             subsets[subsetI]
110         );
113 void triSurf::writeToFMS(const fileName& fName) const
115     OFstream fStream(fName);
117     //- write patches
118     fStream << triSurfFacets::patches_;
120     fStream << nl;
122     //- write points
123     fStream << triSurfPoints::points_;
125     fStream << nl;
127     //- write triangles
128     fStream << triSurfFacets::triangles_;
130     fStream << nl;
132     //- write feature edges
133     fStream << triSurfFeatureEdges::featureEdges_;
135     fStream << nl;
137     //- write point subsets
138     List<meshSubset> subsets;
139     label i(0);
140     subsets.setSize(pointSubsets_.size());
141     forAllConstIter(Map<meshSubset>, pointSubsets_, it)
142         subsets[i++] = it();
143     fStream << subsets;
145     fStream << nl;
147     //- write subsets of facets
148     subsets.setSize(triSurfFacets::facetSubsets_.size());
149     i = 0;
150     forAllConstIter(Map<meshSubset>, triSurfFacets::facetSubsets_, it)
151         subsets[i++] = it();
152     fStream << subsets;
154     fStream << nl;
156     //- write subets of feature edges
157     subsets.setSize(triSurfFeatureEdges::featureEdgeSubsets_.size());
158     i = 0;
159     forAllConstIter
160     (
161         Map<meshSubset>,
162         triSurfFeatureEdges::featureEdgeSubsets_,
163         it
164     )
165         subsets[i++] = it();
166     fStream << subsets;
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 triSurf::triSurf()
173     triSurfPoints(),
174     triSurfFacets(),
175     triSurfFeatureEdges(),
176     triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
179 //- Construct from parts
180 triSurf::triSurf
182     const LongList<labelledTri>& triangles,
183     const geometricSurfacePatchList& patches,
184     const edgeLongList& featureEdges,
185     const pointField& points
188     triSurfPoints(points),
189     triSurfFacets(triangles, patches),
190     triSurfFeatureEdges(featureEdges),
191     triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
194 //- Read from file
195 triSurf::triSurf(const fileName& fName)
197     triSurfPoints(),
198     triSurfFacets(),
199     triSurfFeatureEdges(),
200     triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
202     readSurface(fName);
205 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
207 triSurf::~triSurf()
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 void triSurf::readSurface(const fileName& fName)
214     if( fName.ext() == "fms" || fName.ext() == "FMS" )
215     {
216         readFromFMS(fName);
217     }
218     else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
219     {
220         readFromFTR(fName);
221     }
222     else
223     {
224         triSurface copySurface(fName);
226         //- copy the points
227         triSurfPoints::points_.setSize(copySurface.points().size());
228         forAll(copySurface.points(), pI)
229             triSurfPoints::points_[pI] = copySurface.points()[pI];
231         //- copy the triangles
232         triSurfFacets::triangles_.setSize(copySurface.size());
233         forAll(copySurface, tI)
234             triSurfFacets::triangles_[tI] = copySurface[tI];
236         //- copy patches
237         triSurfFacets::patches_ = copySurface.patches();
238     }
241 void triSurf::writeSurface(const fileName& fName) const
243     if( fName.ext() == "fms" || fName.ext() == "FMS" )
244     {
245         writeToFMS(fName);
246     }
247     else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
248     {
249         writeToFTR(fName);
250     }
251     else
252     {
253         const pointField& pts = this->points();
254         const LongList<labelledTri>& facets = this->facets();
255         const geometricSurfacePatchList& patches = this->patches();
257         List<labelledTri> newTrias(facets.size());
258         forAll(facets, tI)
259             newTrias[tI] = facets[tI];
261         triSurface newSurf(newTrias, patches, pts);
262         newSurf.write(fName);
263     }
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 } // End namespace Foam
270 // ************************************************************************* //