Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GeomCleaner.h « geometry « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aee8ed6963df46aa21e63fcd07f000b2f8788ea3 (plain)
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
186
187
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __GEOMCLEANER_H__
#define __GEOMCLEANER_H__

/** \file
 * \ingroup freestyle
 * \brief Class to define a cleaner of geometry providing a set of useful tools
 */

#include "Geom.h"

#include "../system/FreestyleConfig.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

namespace Freestyle {

using namespace Geometry;

class GeomCleaner {
 public:
  inline GeomCleaner()
  {
  }
  inline ~GeomCleaner()
  {
  }

  /*! Sorts an array of Indexed vertices
   *    iVertices
   *      Array of vertices to sort.
   *      It is organized as a float series of vertex coordinates: XYZXYZXYZ...
   *    iVSize
   *      The size of iVertices array.
   *    iIndices
   *      The array containing the vertex indices
   *      (used to refer to the vertex coordinates in an indexed face).
   *      Each element is an unsignedeger multiple of 3.
   *    iISize
   *      The size of iIndices array
   *    oVertices
   *      Output of sorted vertices.
   *      A vertex v1 precedes another one v2 in this array
   *      if v1.x<v2.x, or v1.x=v2.x && v1.y < v2.y or v1.x=v2.y && v1.y=v2.y && v1.z < v2.z.
   *      The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
   *    oIndices
   *      Output corresponding to the iIndices array but reorganized in
   *      order to match the sorted vertex array.
   */
  static void SortIndexedVertexArray(const float *iVertices,
                                     unsigned iVSize,
                                     const unsigned *iIndices,
                                     unsigned iISize,
                                     float **oVertices,
                                     unsigned **oIndices);

  /*! Compress a SORTED indexed vertex array by eliminating multiple
   *  appearing occurrences of a single vertex.
   *    iVertices
   *      The SORTED vertex array to compress.
   *      It is organized as a float series of vertex coordinates: XYZXYZXYZ...
   *    iVSize
   *      The size of iVertices array.
   *    iIndices
   *      The array containing the vertex indices
   *      (used to refer to the vertex coordinates in an indexed face).
   *      Each element is an unsignedeger multiple of 3.
   *    iISize
   *      The size of iIndices array
   *    oVertices
   *      The vertex array, result of the compression.
   *      The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
   *    oVSize
   *      The size of oVertices.
   *    oIndices
   *      The indices array, reorganized to match the compressed oVertices array.
   */
  static void CompressIndexedVertexArray(const float *iVertices,
                                         unsigned iVSize,
                                         const unsigned *iIndices,
                                         unsigned iISize,
                                         float **oVertices,
                                         unsigned *oVSize,
                                         unsigned **oIndices);

  /*! Sorts and compress an array of indexed vertices.
   *    iVertices
   *      The vertex array to sort then compress. It is organized as a float series of
   *      vertex coordinates: XYZXYZXYZ...
   *    iVSize
   *      The size of iVertices array.
   *    iIndices
   *      The array containing the vertex indices
   *      (used to refer to the vertex coordinates in an indexed face).
   *      Each element is an unsignedeger multiple of 3.
   *    iISize
   *      The size of iIndices array
   *    oVertices
   *      The vertex array, result of the sorting-compression.
   *      The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
   *    oVSize
   *      The size of oVertices.
   *    oIndices
   *      The indices array, reorganized to match the sorted and compressed oVertices array.
   */
  static void SortAndCompressIndexedVertexArray(const float *iVertices,
                                                unsigned iVSize,
                                                const unsigned *iIndices,
                                                unsigned iISize,
                                                float **oVertices,
                                                unsigned *oVSize,
                                                unsigned **oIndices);

  /*! Cleans an indexed vertex array.
   *  (Identical to SortAndCompress except that we use here a hash table to create the new array.)
   *    iVertices
   *      The vertex array to sort then compress. It is organized as a float series of
   *      vertex coordinates: XYZXYZXYZ...
   *    iVSize
   *      The size of iVertices array.
   *    iIndices
   *      The array containing the vertex indices
   *      (used to refer to the vertex coordinates in an indexed face).
   *      Each element is an unsignedeger multiple of 3.
   *    iISize
   *      The size of iIndices array
   *    oVertices
   *      The vertex array, result of the sorting-compression.
   *      The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
   *    oVSize
   *      The size of oVertices.
   *    oIndices
   *      The indices array, reorganized to match the sorted and compressed oVertices array.
   */
  static void CleanIndexedVertexArray(const float *iVertices,
                                      unsigned iVSize,
                                      const unsigned *iIndices,
                                      unsigned iISize,
                                      float **oVertices,
                                      unsigned *oVSize,
                                      unsigned **oIndices);

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GeomCleaner")
#endif
};

/*! Binary operators */
// inline bool operator<(const IndexedVertex& iv1, const IndexedVertex& iv2);

/*! Class Indexed Vertex. Used to represent an indexed vertex by storing the vertex coordinates as
 * well as its index */
class IndexedVertex {
 private:
  Vec3f _Vector;
  unsigned _index;

 public:
  inline IndexedVertex()
  {
  }

  inline IndexedVertex(Vec3f iVector, unsigned iIndex)
  {
    _Vector = iVector;
    _index = iIndex;
  }

  /*! accessors */
  inline const Vec3f &vector() const
  {
    return _Vector;
  }

  inline unsigned index()
  {
    return _index;
  }

  inline float x()
  {
    return _Vector[0];
  }

  inline float y()
  {
    return _Vector[1];
  }

  inline float z()
  {
    return _Vector[2];
  }

  /*! modifiers */
  inline void setVector(const Vec3f &iVector)
  {
    _Vector = iVector;
  }

  inline void setIndex(unsigned iIndex)
  {
    _index = iIndex;
  }

  /*! operators */
  IndexedVertex &operator=(const IndexedVertex &iv)
  {
    _Vector = iv._Vector;
    _index = iv._index;
    return *this;
  }

  inline float operator[](const unsigned i)
  {
    return _Vector[i];
  }

  // friend inline bool operator<(const IndexedVertex& iv1, const IndexedVertex& iv2);
  inline bool operator<(const IndexedVertex &v) const
  {
    return (_Vector < v._Vector);
  }

  inline bool operator==(const IndexedVertex &v)
  {
    return (_Vector == v._Vector);
  }

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedVertex")
#endif
};

#if 0
bool operator<(const IndexedVertex &iv1, const IndexedVertex &iv2)
{
  return iv1.operator<(iv2);
}
#endif

} /* namespace Freestyle */

#endif  // __GEOMCLEANER_H__