File: base.h

package info (click to toggle)
meshlab 2020.09%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 45,124 kB
  • sloc: cpp: 400,238; ansic: 31,952; javascript: 1,578; sh: 387; yacc: 238; lex: 139; python: 86; makefile: 29
file content (296 lines) | stat: -rw-r--r-- 12,407 bytes parent folder | download | duplicates (2)
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/****************************************************************************
* VCGLib                                                            o o     *
* Visual and Computer Graphics Library                            o     o   *
*                                                                _   O  _   *
* Copyright(C) 2004-2016                                           \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* 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 (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/
#ifndef __VCG_MESH
#error "This file should not be included alone. It is automatically included by complex.h"
#endif
#ifndef __VCG_FACE_PLUS
#define __VCG_FACE_PLUS

namespace vcg {

/*------------------------------------------------------------------*/
/*
The base class of all the recusive definition chain. It is just a container of the typenames of the various simplexes.
These typenames must be known form all the derived classes.
*/

template <class UserTypes>
                class FaceTypeHolder: public UserTypes {
  public:

    template <class LeftF>
    void ImportData(const LeftF & ){}
    static void Name(std::vector<std::string> & /* name */){}


 // prot
        inline int VN()  const { return 3;}
        inline int Prev(const int & i) const { return (i+(3-1))%3;}
        inline int Next(const int & i) const { return (i+1)%3;}
    inline void Alloc(const int & ){}
    inline void Dealloc(){}
};

/* The base class form which we start to add our components.
it has the empty definition for all the standard members (coords, color flags)
Note:
in order to avoid both virtual classes and ambiguous definitions all
the subsequent overrides must be done in a sequence of derivation.

In other words we cannot derive and add in a single derivation step
(with multiple ancestor), both the real (non-empty) normal and color but
we have to build the type a step a time (deriving from a single ancestor at a time).


*/
template <class UserTypes>
class FaceBase: public
            face::EmptyCore< FaceTypeHolder <UserTypes> > {
};


/* The Real Big Face class;

The class __FaceArityMax__ is the one that is the Last to be derived,
and therefore is the only one to know the real members
(after the many overrides) so all the functions with common behaviour
using the members defined in the various Empty/nonEmpty component classes
MUST be defined here.

I.e. IsD() that uses the overridden Flags() member must be defined here.

*/

template < class UserTypes,
          template <typename> class A, template <typename> class B,
          template <typename> class C, template <typename> class D,
          template <typename> class E, template <typename> class F,
          template <typename> class G, template <typename> class H,
          template <typename> class I, template <typename> class J,
          template <typename> class K, template <typename> class L >
                    class FaceArityMax: public L<Arity11<FaceBase<UserTypes>, A, B, C, D, E, F, G, H, I, J, K> > {

public:
    typedef typename  FaceArityMax::ScalarType ScalarType;
// ----- Flags stuff -----

    enum {

        DELETED     = 0x00000001,		// Face is deleted from the mesh
        NOTREAD     = 0x00000002,		// Face of the mesh is not readable
        NOTWRITE    = 0x00000004,		// Face of the mesh is not writable
        VISITED     = 0x00000010,		// Face has been visited. Usualy this is a per-algorithm used bit.
        SELECTED    = 0x00000020,		// Face is selected. Algorithms should try to work only on selected face (if explicitly requested)
        // Border _flags, it is assumed that BORDERi = BORDER0<<i
        BORDER0     = 0x00000040,
        BORDER1     = 0x00000080,
        BORDER2     = 0x00000100,
        BORDER012     = BORDER0 | BORDER1 | BORDER2 ,
        // Face Orientation Flags, used efficiently compute point face distance
        NORMX				= 0x00000200,
        NORMY				= 0x00000400,
        NORMZ				= 0x00000800,
        // Face-Edge Selection Flags
        FACEEDGESEL0    = 0x00008000,
        FACEEDGESEL1    = 0x00010000,
        FACEEDGESEL2    = 0x00020000,
        FACEEDGESEL012     = FACEEDGESEL0 | FACEEDGESEL1 | FACEEDGESEL2 ,
        // Faux edges. (semantics: when a mesh is polygonal, edges which are inside a polygonal face are "faux"
        FAUX0       = 0x00040000,
        FAUX1       = 0x00080000,
        FAUX2       = 0x00100000,
        FAUX012     = FAUX0 | FAUX1 | FAUX2 ,
        // First user bit
        USER0       = 0x00200000
            };


    ///  checks if the Face is deleted
    bool IsD() const {return (this->cFlags() & DELETED) != 0;}
    ///  checks if the Face is readable
    bool IsR() const {return (this->cFlags() & NOTREAD) == 0;}
    ///  checks if the Face is modifiable
    bool IsW() const {return (this->cFlags() & NOTWRITE)== 0;}
    /// This funcion checks whether the Face is both readable and modifiable
    bool IsRW() const {return (this->cFlags() & (NOTREAD | NOTWRITE)) == 0;}
    ///  checks if the Face is Modified
    bool IsS() const {return (this->cFlags() & SELECTED) != 0;}
    ///  checks if the Face is Modified
    bool IsV() const {return (this->cFlags() & VISITED) != 0;}

    /** Set the flag value
        @param flagp Valore da inserire nel flag
    */
    void SetFlags(int flagp) {this->Flags()=flagp;}

    /** Set the flag value
        @param flagp Valore da inserire nel flag
    */
    void ClearFlags() {this->Flags()=0;}

    ///  deletes the Face from the mesh
    void SetD() {this->Flags() |=DELETED;}
    ///  un-delete a Face
    void ClearD() {this->Flags() &=(~DELETED);}
    ///  marks the Face as readable
    void SetR() {this->Flags() &=(~NOTREAD);}
    ///  marks the Face as not readable
    void ClearR() {this->Flags() |=NOTREAD;}
    ///  marks the Face as writable
    void SetW() {this->Flags() &=(~NOTWRITE);}
    ///  marks the Face as notwritable
    void ClearW() {this->Flags() |=NOTWRITE;}
    ///  select the Face
    void SetS()		{this->Flags() |=SELECTED;}
    /// Un-select a Face
  void ClearS()	{this->Flags() &= ~SELECTED;}
    ///  select the Face
    void SetV()		{this->Flags() |=VISITED;}
    /// Un-select a Face
  void ClearV()	{this->Flags() &= ~VISITED;}

    /// This function checks if the face is selected
    bool IsB(int i) const {return (this->cFlags() & (BORDER0<<i)) != 0;}
    /// This function select the face
  void SetB(int i)		{this->Flags() |=(BORDER0<<i);}
    /// This funcion execute the inverse operation of SetS()
    void ClearB(int i)	{this->Flags() &= (~(BORDER0<<i));}

    /// This function checks if the i-th face-edge is selected
    bool IsFaceEdgeS(int i) const {return (this->cFlags() & (FACEEDGESEL0<<i)) != 0;}
    /// This function select the i-th face-edge
    void SetFaceEdgeS(int i){this->Flags() |=(FACEEDGESEL0<<i);}
    /// This function de-select the i-th face-edge
    void ClearFaceEdgeS(int i)	{this->Flags() &= (~(FACEEDGESEL0<<i));}

    /// This function checks if a given side of the face is a feature/internal edge
    /// it is used by some importer to mark internal
    /// edges of polygonal faces that have been triangulated
    bool IsF(int i) const {return (this->cFlags() & (FAUX0<<i) ) != 0;}
    bool IsAnyF() const {return (this->cFlags() & (FAUX0|FAUX1|FAUX2)) != 0;}
    /// This function select the face
    void SetF(int i)		{this->Flags() |=(FAUX0<<i);}
    /// This funcion execute the inverse operation of SetS()
    void ClearF(int i)	{this->Flags() &= (~(FAUX0<<i));}
    void ClearAllF() { this->Flags() &= (~(FAUX0|FAUX1|FAUX2)); }

    ///  Return the first bit that is not still used
    static int &FirstUnusedBitFlag()
    {
      static int b =USER0;
      return b;
    }

    /// Allocate a bit among the flags that can be used by user. It updates the FirstUnusedBitFlag.
    static inline int NewBitFlag()
    {
      int bitForTheUser = FirstUnusedBitFlag();
      FirstUnusedBitFlag()=FirstUnusedBitFlag()<<1;
      return bitForTheUser;
    }

    /// De-allocate a pre allocated bit. It updates the FirstUnusedBitFlag.
    // Note you must deallocate bit in the inverse order of the allocation (as in a stack)
    static inline bool DeleteBitFlag(int bitval)
    {
      if(FirstUnusedBitFlag()>>1==bitval) {
        FirstUnusedBitFlag() = FirstUnusedBitFlag()>>1;
        return true;
      }
      assert(0);
      return false;
    }

    /// This function checks if the given user bit is true
    bool IsUserBit(int userBit){return (this->Flags() & userBit) != 0;}

    /// This function set the given user bit
    void SetUserBit(int userBit){this->Flags() |=userBit;}

    /// This function clear the given user bit
    void ClearUserBit(int userBit){this->Flags() &= (~userBit);}


  void GetBBox(Box3<ScalarType>& bb ) const
  {
    if(this->IsD()) {
        bb.SetNull();
        return;
      }
        bb.Set(this->cP(0));
        bb.Add(this->cP(1));
        bb.Add(this->cP(2));
  }


};


/*

These are the three main classes that are used by the library user to define its own Facees.
The user MUST specify the names of all the type involved in a generic complex.
so for example when defining a Face of a trimesh you must know the name of the type of the edge and of the face.
Typical usage example:

A Face with coords, flags and normal for use in a standard trimesh:

class MyFaceNf   : public FaceSimp2< VertProto, EdgeProto, MyFaceNf, face::Flag, face::Normal3f  > {};


A Face with coords, and normal for use in a tetrahedral mesh AND in a standard trimesh:

class TetraFace   : public FaceSimp3< VertProto, EdgeProto, TetraFace, TetraProto, face::Coord3d, face::Normal3f  > {};


A summary of the components that can be added to a face (see components.h for details):

VertexRef
NormalFromVert, WedgeNormal
Normal3s, Normal3f, Normal3d
WedgeTexCoord2s, WedgeTexCoord2f, WedgeTexCoord2d
BitFlags
WedgeColor, Color4b
Qualitys, Qualityf, Qualityd
Mark                                            //Incremental mark (int)
VFAdj                                           //Topology vertex face adjacency
                                                 (pointers to next face in the ring of the vertex
FFAdj                                           //topology: face face adj
                                                  pointers to adjacent faces

*/

template <class UserTypes,
          template <typename> class A = DefaultDeriver, template <typename> class B = DefaultDeriver,
          template <typename> class C = DefaultDeriver, template <typename> class D = DefaultDeriver,
          template <typename> class E = DefaultDeriver, template <typename> class F = DefaultDeriver,
          template <typename> class G = DefaultDeriver, template <typename> class H = DefaultDeriver,
          template <typename> class I = DefaultDeriver, template <typename> class J = DefaultDeriver,
          template <typename> class K = DefaultDeriver, template <typename> class L = DefaultDeriver >
                            class Face: public FaceArityMax<UserTypes, A, B, C, D, E, F, G, H, I, J, K, L>  {
                            public: typedef AllTypes::AFaceType IAm; typedef UserTypes TypesPool;};


}// end namespace
#endif