File: EdgeSwapConfig.h

package info (click to toggle)
madlib 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,196 kB
  • sloc: cpp: 39,851; sh: 10,041; makefile: 473
file content (173 lines) | stat: -rw-r--r-- 6,052 bytes parent folder | download | duplicates (6)
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
// -*- C++ -*-
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Arnaud Francois, Gaetan Compere, Jean-Francois Remacle
// -------------------------------------------------------------------

#ifndef _H_EDGESWAPCONFIG
#define _H_EDGESWAPCONFIG

namespace MAd
{
  // -------------------------------------------------------------------
  class EdgeSwapTemplate  // 3D case
  {
  public:
    EdgeSwapTemplate() {}
    virtual ~EdgeSwapTemplate() {}
    virtual int getConfig(){ return 0; }       // nb of faces attached to edge
    virtual int nb_triangulations() = 0;       // nb of possible triangulations
    virtual int nb_triangles() = 0;            // nb of different triangles
    virtual int nb_tri_triangulation() = 0;    // nb of triangles in a triangulation
    virtual const int* triangle( int i ) = 0;  // return the triangle i 
    virtual const int* triangulation( int i ) = 0;  // return the triangulation i
  };

  // -------------------------------------------------------------------
  // Null edge swap template
  class EdgeSwap0 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap0() { }
    int getConfig(){ return 0; }
    int nb_triangles(){ return -1; }
    int nb_triangulations(){ return -1; }
    int nb_tri_triangulation(){ return -1; }
    const int* triangle( int i) { return 0; }
    const int* triangulation( int i) { return 0; }
  };

  // -------------------------------------------------------------------
  // Edge swap template with 3 faces connected to the edge
  class EdgeSwap3 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap3() { }
    int getConfig(){ return 3; }
    int nb_triangles(){ return 1; }
    int nb_triangulations(){ return 1; }
    int nb_tri_triangulation(){ return 1; }
    const int* triangle( int i) { return triangles[i]; }
    const int* triangulation( int i) { return triangulations[i]; }
  private:
    static const int triangles[1][3];
    static const int triangulations[1][1];
  };

  // -------------------------------------------------------------------
  // Edge swap template with 4 faces connected to the edge
  class EdgeSwap4 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap4() { }
    int getConfig(){ return 4; }
    int nb_triangles(){ return 4; }
    int nb_triangulations(){ return 2; }
    int nb_tri_triangulation(){ return 2; }
    const int* triangle( int i) { return triangles[i]; }
    const int* triangulation( int i) { return triangulations[i]; }
  private:
    static const int triangles[4][3];
    static const int triangulations[2][2];
  };

  // -------------------------------------------------------------------
  // Edge swap template with 5 faces connected to the edge
  class EdgeSwap5 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap5() { }
    int getConfig(){ return 5; }
    int nb_triangles(){ return 10; }
    int nb_triangulations(){ return 5; }
    int nb_tri_triangulation(){ return 3; }
    const int* triangle( int i) { return triangles[i]; }
    const int* triangulation( int i) { return triangulations[i]; }
  private:
    static const int triangles[10][3];
    static const int triangulations[5][3];
  };

  // -------------------------------------------------------------------
  // Edge swap template with 6 faces connected to the edge
  class EdgeSwap6 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap6() { }
    int getConfig(){ return 6; }
    int nb_triangles(){ return 20; }
    int nb_triangulations(){ return 14; }
    int nb_tri_triangulation(){ return 4; }
    const int* triangle( int i) { return triangles[i]; }
    const int* triangulation( int i) { return triangulations[i]; }
  protected:
    static const int triangles[20][3];
    static const int triangulations[14][4];
  };

  // -------------------------------------------------------------------
  // Edge swap template with 7 faces connected to the edge
  class EdgeSwap7 : public EdgeSwapTemplate
  {
  public:
    EdgeSwap7() { }
    int getConfig(){ return 7; }
    int nb_triangles(){ return 35; }
    int nb_triangulations(){ return 42; }
    int nb_tri_triangulation(){ return 5; }
    const int* triangle( int i) { return triangles[i]; }
    const int* triangulation( int i) { return triangulations[i]; }
  protected:
    static const int triangles[35][3];
    static const int triangulations[42][5];
  };

  // -------------------------------------------------------------------
  // Interface
  class EdgeSwapConfiguration
  {
  public:

    EdgeSwapConfiguration( ) { set(0); }
    EdgeSwapConfiguration( int n ) { set( n ); }
    EdgeSwapConfiguration( const EdgeSwapConfiguration &x ) { set( x.get() ); }
    ~EdgeSwapConfiguration() { }

    // select edge swap template with n faces connected to the edge
    void set( int n );

    // return the nodes of triangle i for the selected configuration
    const int* triangle( int i ) const {  return (*c).triangle(i); }

    // return the node j of triangle i for the selected configuration
    int triangle( int i, int j ) const {  return (*c).triangle(i)[j]; }

    // return the triangle j of triangulation i
    int triangulation( int i, int j ) const {  return (*c).triangulation(i)[j]; }

    int nb_triangles() const { return c->nb_triangles(); }
    int nb_triangulations() const { return c->nb_triangulations(); }
    int nb_tri_triangulation() const { return c->nb_tri_triangulation(); }

    int get() const { return c->getConfig(); }

  private:
    EdgeSwap0         cNull;
    EdgeSwap3         c3;
    EdgeSwap4         c4;
    EdgeSwap5         c5;
    EdgeSwap6         c6;
    EdgeSwap7         c7;
    EdgeSwapTemplate * c;
  };

  // -------------------------------------------------------------------
}
#endif