FreeCAD

Форк
0
/
Info.cpp 
241 строка · 8.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2005 Imetric 3D GmbH                                    *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
#include <iomanip>
27
#include <iostream>
28
#include <map>
29
#include <set>
30
#endif
31

32
#include "Info.h"
33
#include "Iterator.h"
34

35

36
using namespace MeshCore;
37

38
MeshInfo::MeshInfo(const MeshKernel& rclM)
39
    : _rclMesh(rclM)
40
{}
41

42
std::ostream& MeshInfo::GeneralInformation(std::ostream& rclStream) const
43
{
44
    unsigned long ulCtPt {}, ulCtEd {}, ulCtFc {};
45
    ulCtPt = _rclMesh.CountPoints();
46
    ulCtFc = _rclMesh.CountFacets();
47
    ulCtEd = _rclMesh.CountEdges();
48

49
    rclStream << "Mesh: [" << ulCtFc << " Faces, ";
50
    rclStream << ulCtEd << " Edges, ";
51
    rclStream << ulCtPt << " Points"
52
              << "]" << std::endl;
53

54
    return rclStream;
55
}
56

57
std::ostream& MeshInfo::DetailedPointInfo(std::ostream& rclStream) const
58
{
59
    // print points
60
    rclStream << _rclMesh.CountPoints() << " Points:" << std::endl;
61
    MeshPointIterator pPIter(_rclMesh), pPEnd(_rclMesh);
62
    pPIter.Begin();
63
    pPEnd.End();
64
    PointIndex i = 0;
65

66
    rclStream.precision(3);
67
    rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
68
    while (pPIter < pPEnd) {
69
        rclStream << "P " << std::setw(4) << (i++) << ": (" << std::setw(8) << (*pPIter).x << ", "
70
                  << std::setw(8) << (*pPIter).y << ", " << std::setw(8) << (*pPIter).z << ")"
71
                  << std::endl;
72
        ++pPIter;
73
    }
74

75
    return rclStream;
76
}
77

78
std::ostream& MeshInfo::DetailedEdgeInfo(std::ostream& rclStream) const
79
{
80
    // print edges
81
    // get edges from facets
82
    std::map<std::pair<PointIndex, PointIndex>, int> lEdges;
83

84
    const MeshFacetArray& rFacets = _rclMesh.GetFacets();
85
    MeshFacetArray::_TConstIterator pFIter;
86
    pFIter = rFacets.begin();
87
    while (pFIter < rFacets.end()) {
88
        const MeshFacet& rFacet = *pFIter;
89
        for (int j = 0; j < 3; j++) {
90
            PointIndex ulPt0 =
91
                std::min<PointIndex>(rFacet._aulPoints[j], rFacet._aulPoints[(j + 1) % 3]);
92
            PointIndex ulPt1 =
93
                std::max<PointIndex>(rFacet._aulPoints[j], rFacet._aulPoints[(j + 1) % 3]);
94
            std::pair<PointIndex, PointIndex> cEdge(ulPt0, ulPt1);
95
            lEdges[cEdge]++;
96
        }
97

98
        pFIter++;
99
    }
100

101
    // print edges
102
    rclStream << lEdges.size() << " Edges:" << std::endl;
103
    std::map<std::pair<PointIndex, PointIndex>, int>::const_iterator pEIter;
104
    pEIter = lEdges.begin();
105

106
    rclStream.precision(3);
107
    rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
108
    unsigned long i = 0;
109
    const MeshPointArray& rPoints = _rclMesh.GetPoints();
110
    while (pEIter != lEdges.end()) {
111
        int ct = pEIter->second;
112
        const Base::Vector3f& rP0 = rPoints[pEIter->first.first];
113
        const Base::Vector3f& rP1 = rPoints[pEIter->first.second];
114

115
        rclStream << "E " << std::setw(4) << (i++) << ": "
116
                  << "  P (" << std::setw(8) << rP0.x << ", " << std::setw(8) << rP0.y << ", "
117
                  << std::setw(8) << rP0.z << "); "
118
                  << "  P (" << std::setw(8) << rP1.x << ", " << std::setw(8) << rP1.y << ", "
119
                  << std::setw(8) << rP1.z << "),  B: " << (ct == 2 ? "n" : "y") << std::endl;
120
        ++pEIter;
121
    }
122

123
    return rclStream;
124
}
125

126
std::ostream& MeshInfo::DetailedFacetInfo(std::ostream& rclStream) const
127
{
128
    // print facets
129
    unsigned long i {}, j {};
130
    rclStream << _rclMesh.CountFacets() << " Faces:" << std::endl;
131
    MeshFacetIterator pFIter(_rclMesh), pFEnd(_rclMesh);
132
    pFIter.Begin();
133
    pFEnd.End();
134
    i = 0;
135

136
    rclStream.precision(3);
137
    rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
138
    while (pFIter < pFEnd) {
139
        rclStream << "F " << std::setw(4) << (i++) << ":" << std::endl;
140
        rclStream << "  N (" << std::setw(8) << (*pFIter).GetNormal().x << ", " << std::setw(8)
141
                  << (*pFIter).GetNormal().y << ", " << std::setw(8) << (*pFIter).GetNormal().z
142
                  << ")" << std::endl;
143
        for (j = 0; j < 3; j++) {
144
            rclStream << "  P (" << std::setw(8) << (*pFIter)._aclPoints[j].x << ", "
145
                      << std::setw(8) << (*pFIter)._aclPoints[j].y << ", " << std::setw(8)
146
                      << (*pFIter)._aclPoints[j].z << ")" << std::endl;
147
        }
148
        ++pFIter;
149
    }
150

151
    return rclStream;
152
}
153

154
std::ostream& MeshInfo::DetailedInformation(std::ostream& rclStream) const
155
{
156
    DetailedPointInfo(rclStream);
157
    DetailedEdgeInfo(rclStream);
158
    DetailedFacetInfo(rclStream);
159

160
    return rclStream;
161
}
162

163
std::ostream& MeshInfo::InternalPointInfo(std::ostream& rclStream) const
164
{
165
    // print points
166
    unsigned long i {};
167
    rclStream << _rclMesh.CountPoints() << " Points:" << std::endl;
168
    MeshPointIterator pPIter(_rclMesh), pPEnd(_rclMesh);
169
    pPIter.Begin();
170
    pPEnd.End();
171
    i = 0;
172

173
    rclStream.precision(3);
174
    rclStream.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
175
    while (pPIter < pPEnd) {
176
        rclStream << "P " << std::setw(4) << (i++) << ": (" << std::setw(8) << (*pPIter).x << ", "
177
                  << std::setw(8) << (*pPIter).y << ", " << std::setw(8) << (*pPIter).z << ")";
178
        if (pPIter->IsValid()) {
179
            rclStream << std::endl;
180
        }
181
        else {
182
            rclStream << " invalid" << std::endl;
183
        }
184
        ++pPIter;
185
    }
186

187
    return rclStream;
188
}
189

190
std::ostream& MeshInfo::InternalFacetInfo(std::ostream& rclStream) const
191
{
192
    // print facets
193
    unsigned long i {};
194
    rclStream << _rclMesh.CountFacets() << " Faces:" << std::endl;
195

196
    const MeshFacetArray& rFacets = _rclMesh.GetFacets();
197
    MeshFacetArray::_TConstIterator pFIter;
198
    pFIter = rFacets.begin();
199
    i = 0;
200
    while (pFIter < rFacets.end()) {
201
        rclStream << "F " << std::setw(4) << (i++) << ": P (" << std::setw(4)
202
                  << pFIter->_aulPoints[0] << ", " << std::setw(4) << pFIter->_aulPoints[1] << ", "
203
                  << std::setw(4) << pFIter->_aulPoints[2] << ")  "
204
                  << "N (" << std::setw(4) << pFIter->_aulNeighbours[0] << ", " << std::setw(4)
205
                  << pFIter->_aulNeighbours[1] << ", " << std::setw(4) << pFIter->_aulNeighbours[2]
206
                  << ") ";
207

208
        if (pFIter->IsValid()) {
209
            rclStream << std::endl;
210
        }
211
        else {
212
            rclStream << " invalid" << std::endl;
213
        }
214

215
        pFIter++;
216
    }
217

218
    return rclStream;
219
}
220

221
std::ostream& MeshInfo::InternalInformation(std::ostream& rclStream) const
222
{
223
    InternalPointInfo(rclStream);
224
    InternalFacetInfo(rclStream);
225

226
    return rclStream;
227
}
228

229
std::ostream& MeshInfo::TopologyInformation(std::ostream& rclStream) const
230
{
231
    unsigned long index = 0;
232
    const MeshFacetArray& rFAry = _rclMesh.GetFacets();
233
    for (MeshFacetArray::_TConstIterator it = rFAry.begin(); it != rFAry.end(); ++it, ++index) {
234
        rclStream << "F " << std::setw(4) << index << ": P (" << it->_aulPoints[0] << ", "
235
                  << it->_aulPoints[1] << ", " << it->_aulPoints[2] << "), N ("
236
                  << it->_aulNeighbours[0] << ", " << it->_aulNeighbours[1] << ", "
237
                  << it->_aulNeighbours[2] << ")" << std::endl;
238
    }
239

240
    return rclStream;
241
}
242

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.