FreeCAD

Форк
0
/
Segment.cpp 
190 строк · 5.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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
#ifndef _PreComp_
25
#include <algorithm>
26
#include <sstream>
27
#endif
28

29
#include "Mesh.h"
30
#include "MeshPy.h"
31
#include "Segment.h"
32

33

34
using namespace Mesh;
35

36
Segment::Segment(const MeshObject* mesh, bool mod)
37
    : _mesh(mesh)
38
    , _save(false)
39
    , _modifykernel(mod)
40
{}
41

42
Segment::Segment(const MeshObject* mesh, const std::vector<FacetIndex>& inds, bool mod)
43
    : _mesh(mesh)
44
    , _indices(inds)
45
    , _save(false)
46
    , _modifykernel(mod)
47
{
48
    if (_modifykernel) {
49
        _mesh->updateMesh(inds);
50
    }
51
}
52

53
void Segment::addIndices(const std::vector<FacetIndex>& inds)
54
{
55
    _indices.insert(_indices.end(), inds.begin(), inds.end());
56
    std::sort(_indices.begin(), _indices.end());
57
    _indices.erase(std::unique(_indices.begin(), _indices.end()), _indices.end());
58
    if (_modifykernel) {
59
        _mesh->updateMesh(inds);
60
    }
61
}
62

63
void Segment::removeIndices(const std::vector<FacetIndex>& inds)
64
{
65
    // make difference
66
    std::vector<FacetIndex> result;
67
    std::set<FacetIndex> s1(_indices.begin(), _indices.end());
68
    std::set<FacetIndex> s2(inds.begin(), inds.end());
69
    std::set_difference(s1.begin(),
70
                        s1.end(),
71
                        s2.begin(),
72
                        s2.end(),
73
                        std::back_insert_iterator<std::vector<FacetIndex>>(result));
74

75
    _indices = result;
76
    if (_modifykernel) {
77
        _mesh->updateMesh();
78
    }
79
}
80

81
const std::vector<FacetIndex>& Segment::getIndices() const
82
{
83
    return _indices;
84
}
85

86
Segment::Segment(const Segment& s) = default;
87

88
Segment::Segment(Segment&& s) = default;
89

90
Segment& Segment::operator=(const Segment& s)
91
{
92
    // Do not copy the MeshObject pointer
93
    if (this != &s) {
94
        this->_indices = s._indices;
95
    }
96
    if (_modifykernel) {
97
        _mesh->updateMesh();
98
    }
99
    return *this;
100
}
101

102
Segment& Segment::operator=(Segment&& s)
103
{
104
    // Do not copy the MeshObject pointer
105
    if (this != &s) {
106
        this->_indices = s._indices;
107
    }
108
    if (_modifykernel) {
109
        _mesh->updateMesh();
110
    }
111
    return *this;
112
}
113

114
bool Segment::operator==(const Segment& s) const
115
{
116
    return this->_indices == s._indices;
117
}
118

119
// ----------------------------------------------------------------------------
120

121
// clang-format off
122
Segment::const_facet_iterator::const_facet_iterator
123
(const Segment* segm, std::vector<FacetIndex>::const_iterator it)
124
  : _segment(segm), _f_it(segm->_mesh->getKernel()), _it(it)
125
{
126
    this->_f_it.Set(0);
127
    this->_f_it.Transform(_segment->_mesh->getTransform());
128
    this->_facet.Mesh = _segment->_mesh;
129
}
130

131
Segment::const_facet_iterator::const_facet_iterator
132
(const Segment::const_facet_iterator& fi) = default;
133

134
Segment::const_facet_iterator::const_facet_iterator
135
(Segment::const_facet_iterator&& fi) = default;
136

137
Segment::const_facet_iterator::~const_facet_iterator() = default;
138

139
Segment::const_facet_iterator& Segment::const_facet_iterator::operator=
140
(const Segment::const_facet_iterator& fi) = default;
141

142
Segment::const_facet_iterator& Segment::const_facet_iterator::operator=
143
(Segment::const_facet_iterator&& fi) = default;
144

145
void Segment::const_facet_iterator::dereference() const
146
{
147
    this->_f_it.Set(*_it);
148
    this->_facet.MeshCore::MeshGeomFacet::operator = (*_f_it);
149
    this->_facet.Index = *_it;
150
    const MeshCore::MeshFacet& face = _f_it.GetReference();
151
    for (int i=0; i<3;i++) {
152
        this->_facet.PIndex[i] = face._aulPoints[i];
153
        this->_facet.NIndex[i] = face._aulNeighbours[i];
154
    }
155
}
156

157
const Facet& Segment::const_facet_iterator::operator*() const
158
{
159
    this->dereference();
160
    return this->_facet;
161
}
162

163
const Facet* Segment::const_facet_iterator::operator->() const
164
{
165
    this->dereference();
166
    return &(this->_facet);
167
}
168

169
bool Segment::const_facet_iterator::operator==(const Segment::const_facet_iterator& fi) const
170
{
171
    return (this->_segment == fi._segment) && (this->_it == fi._it);
172
}
173

174
bool Segment::const_facet_iterator::operator!=(const Segment::const_facet_iterator& fi) const
175
{
176
    return !operator==(fi);
177
}
178

179
Segment::const_facet_iterator& Segment::const_facet_iterator::operator++()
180
{
181
    ++(this->_it);
182
    return *this;
183
}
184

185
Segment::const_facet_iterator& Segment::const_facet_iterator::operator--()
186
{
187
    --(this->_it);
188
    return *this;
189
}
190
// clang-format on
191

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

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

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

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