File size: 5,620 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// SPDX-License-Identifier: LGPL-2.1-or-later

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

 *   Copyright (c) 2005 Imetric 3D GmbH                                    *

 *                                                                         *

 *   This file is part of the FreeCAD CAx development system.              *

 *                                                                         *

 *   This library is free software; you can redistribute it and/or         *

 *   modify it under the terms of the GNU Library General Public           *

 *   License as published by the Free Software Foundation; either          *

 *   version 2 of the License, or (at your option) any later version.      *

 *                                                                         *

 *   This library  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 Library General Public License for more details.                  *

 *                                                                         *

 *   You should have received a copy of the GNU Library General Public     *

 *   License along with this library; see the file COPYING.LIB. If not,    *

 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *

 *   Suite 330, Boston, MA  02111-1307, USA                                *

 *                                                                         *

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

#ifndef MESH_HELPERS_H
#define MESH_HELPERS_H

#include "Elements.h"


namespace MeshCore
{

/**

 * Helper class for points.

 */
struct MeshExport MeshHelpPoint

{
    inline void Set(FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f& rclPt);

    inline bool operator<(const MeshHelpPoint& rclObj) const;
    inline bool operator==(const MeshHelpPoint& rclObj) const;

    FacetIndex Index() const
    {
        return _ulInd >> 2;
    }

    FacetIndex Corner() const
    {
        return _ulInd & 3;
    }

    MeshPoint _clPt;
    FacetIndex _ulInd {FACET_INDEX_MAX};
};

/**

 * Helper class for list of points.

 */
struct MeshPointBuilder: public std::vector<MeshHelpPoint>
{
    inline void Add(FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f& rclPt);
};

/**

 * Helper class for edges.

 */
struct MeshExport MeshHelpBuilderEdge

{
    FacetIndex Side() const
    {
        return _ulFIndex & 3;
    }

    FacetIndex Index() const
    {
        return _ulFIndex >> 2;
    }

    inline void Set(PointIndex ulInd1, PointIndex ulInd2, FacetIndex ulSide, FacetIndex ulFInd);

    inline bool operator<(const MeshHelpBuilderEdge& rclObj) const;

    inline bool operator==(const MeshHelpBuilderEdge& rclObj) const;


    inline bool operator!=(const MeshHelpBuilderEdge& rclObj) const;

    FacetIndex _ulFIndex;   // facet index
    PointIndex _aulInd[2];  // point index
};

/**

 * Helper class to build up list of edges.

 */
struct MeshEdgeBuilder: public std::vector<MeshHelpBuilderEdge>
{
    using _TIterator = std::vector<MeshHelpBuilderEdge>::iterator;
    inline void Add(PointIndex ulInd1, PointIndex ulInd2, FacetIndex ulSide, FacetIndex ulFInd);
};

inline void MeshHelpPoint::Set(FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f& rclPt)
{
    _ulInd = (ulFacet << 2) | ulCorner;
    _clPt = rclPt;
}

inline bool MeshHelpPoint::operator<(const MeshHelpPoint& rclObj) const
{
    if (_clPt.x == rclObj._clPt.x) {
        if (_clPt.y == rclObj._clPt.y) {
            return _clPt.z < rclObj._clPt.z;
        }
        else {
            return _clPt.y < rclObj._clPt.y;
        }
    }
    else {
        return _clPt.x < rclObj._clPt.x;
    }
}

inline bool MeshHelpPoint::operator==(const MeshHelpPoint& rclObj) const
{
    return Base::DistanceP2(_clPt, rclObj._clPt) < MeshDefinitions::_fMinPointDistanceP2;
}

inline void MeshPointBuilder::Add(FacetIndex ulCorner, FacetIndex ulFacet, const Base::Vector3f& rclPt)
{
    MeshHelpPoint clObj;
    clObj.Set(ulCorner, ulFacet, rclPt);
    push_back(clObj);
}

inline void MeshHelpBuilderEdge::Set(

    PointIndex ulInd1,

    PointIndex ulInd2,

    FacetIndex ulSide,

    FacetIndex ulFInd

)
{
    if (ulInd1 < ulInd2) {
        _aulInd[0] = ulInd1;
        _aulInd[1] = ulInd2;
    }
    else {
        _aulInd[0] = ulInd2;
        _aulInd[1] = ulInd1;
    }
    _ulFIndex = (ulFInd << 2) | ulSide;
}

inline bool MeshHelpBuilderEdge::operator<(const MeshHelpBuilderEdge& rclObj) const
{
    if (_aulInd[0] == rclObj._aulInd[0]) {
        return _aulInd[1] < rclObj._aulInd[1];
    }
    else {
        return _aulInd[0] < rclObj._aulInd[0];
    }
}

inline bool MeshHelpBuilderEdge::operator==(const MeshHelpBuilderEdge& rclObj) const
{
    return (_aulInd[0] == rclObj._aulInd[0]) && (_aulInd[1] == rclObj._aulInd[1]);
}

inline bool MeshHelpBuilderEdge::operator!=(const MeshHelpBuilderEdge& rclObj) const
{
    return (_aulInd[0] != rclObj._aulInd[0]) || (_aulInd[1] != rclObj._aulInd[1]);
}


inline void MeshEdgeBuilder::Add(PointIndex ulInd1, PointIndex ulInd2, FacetIndex ulSide, FacetIndex ulFInd)
{
    MeshHelpBuilderEdge clObj {};
    clObj.Set(ulInd1, ulInd2, ulSide, ulFInd);
    push_back(clObj);
}

}  // namespace MeshCore

#endif  // MESH_HELPERS_H