1 | #include "./bamgobjects.h"
|
---|
2 |
|
---|
3 | using namespace std;
|
---|
4 | namespace bamg {
|
---|
5 |
|
---|
6 | /*Constructor*/
|
---|
7 | /*FUNCTION SetOfEdges4::SetOfEdges4(long mmx,long nnx){{{*/
|
---|
8 | SetOfEdges4::SetOfEdges4(long mmx,long nnx){
|
---|
9 | /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/SetOfEdges4)*/
|
---|
10 |
|
---|
11 | /*Intermediary*/
|
---|
12 | int i;
|
---|
13 |
|
---|
14 | //initialize fields
|
---|
15 | nx =nnx; //number of vertices
|
---|
16 | nbax =mmx; // 3 * number of triangles
|
---|
17 | NbOfEdges=0;
|
---|
18 | head = new long [nx];
|
---|
19 | Edges= new IntEdge[nbax];
|
---|
20 |
|
---|
21 | //initialize head (-1 everywhere)
|
---|
22 | i=nx;
|
---|
23 | while(i--) head[i]=-1;
|
---|
24 | }
|
---|
25 | /*}}}*/
|
---|
26 |
|
---|
27 | /*Methods*/
|
---|
28 | /*FUNCTION SetOfEdges4::add{{{*/
|
---|
29 | long SetOfEdges4::add(long ii,long jj) {
|
---|
30 | /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/add)*/
|
---|
31 |
|
---|
32 | /*Intermediary*/
|
---|
33 | int h,n;
|
---|
34 |
|
---|
35 | //get n from h (usually h=ii)
|
---|
36 | _assert_(head);
|
---|
37 | n=head[h=Abs(ii)%nx];
|
---|
38 |
|
---|
39 | //go through the existing edges that holds h (=ii) and check that
|
---|
40 | //the edge ii jj is not already in Edge
|
---|
41 | while (n >= 0){
|
---|
42 |
|
---|
43 | //if the edge ii jj is already in Edges, return n
|
---|
44 | if (ii == Edges[n].i && jj == Edges[n].j) return n;
|
---|
45 |
|
---|
46 | //else go to next edge that holds ii
|
---|
47 | else n = Edges[n].next;
|
---|
48 | }
|
---|
49 |
|
---|
50 | //check that nbax <=NbOfEdges
|
---|
51 | if (nbax <=NbOfEdges ) {
|
---|
52 | _error_("SetOfEdges4::add overflow: NbOfEdges=" << NbOfEdges << " > nbax=" << nbax);
|
---|
53 | }
|
---|
54 |
|
---|
55 | //update chain
|
---|
56 | Edges[NbOfEdges].i=ii;
|
---|
57 | Edges[NbOfEdges].j=jj;
|
---|
58 | Edges[NbOfEdges].next= head[h];
|
---|
59 | head[h] = NbOfEdges;
|
---|
60 | return NbOfEdges ++;
|
---|
61 | }
|
---|
62 | /*}}}*/
|
---|
63 | /*FUNCTION SetOfEdges4::find {{{*/
|
---|
64 | long SetOfEdges4::find(long ii,long jj) {
|
---|
65 | /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, SetOfEdges4.cpp/find)*/
|
---|
66 |
|
---|
67 | /*Intermediary*/
|
---|
68 | int n;
|
---|
69 |
|
---|
70 | //check that head is not empty
|
---|
71 | _assert_(head);
|
---|
72 |
|
---|
73 | //get n from h (usually h=ii)
|
---|
74 | n=head[Abs(ii)%nx];
|
---|
75 |
|
---|
76 | //go through the existing edges that holds h (=ii) and return position in Edge
|
---|
77 | while (n >= 0){
|
---|
78 |
|
---|
79 | //if the edge ii jj is already in Edges, return n
|
---|
80 | if (ii == Edges[n].i && jj == Edges[n].j) return n;
|
---|
81 |
|
---|
82 | //else go to next edge that holds ii
|
---|
83 | else n = Edges[n].next;
|
---|
84 | }
|
---|
85 |
|
---|
86 | //if we reach this point, the edge does not exist return -1
|
---|
87 | return -1;
|
---|
88 | }
|
---|
89 | /*}}}*/
|
---|
90 | /*FUNCTION SetOfEdges4::i{{{*/
|
---|
91 | long SetOfEdges4::i(long k){
|
---|
92 | return Edges[k].i;
|
---|
93 | }
|
---|
94 | /*}}}*/
|
---|
95 | /*FUNCTION SetOfEdges4::j{{{*/
|
---|
96 | long SetOfEdges4::j(long k){
|
---|
97 | return Edges[k].j;
|
---|
98 | }
|
---|
99 | /*}}}*/
|
---|
100 | /*FUNCTION SetOfEdges4::nb{{{*/
|
---|
101 | long SetOfEdges4::nb(){
|
---|
102 | return NbOfEdges;
|
---|
103 | }
|
---|
104 | /*}}}*/
|
---|
105 | /*FUNCTION SetOfEdges4::SortAndAdd{{{*/
|
---|
106 | long SetOfEdges4::SortAndAdd (long ii,long jj) {
|
---|
107 | return ii <=jj ? add (ii,jj) : add (jj,ii) ;
|
---|
108 | }
|
---|
109 | /*}}}*/
|
---|
110 | /*FUNCTION SetOfEdges4::SortAndFind{{{*/
|
---|
111 | long SetOfEdges4::SortAndFind (long ii,long jj) {
|
---|
112 | return ii <=jj ? find (ii,jj) : find (jj,ii) ;
|
---|
113 | }
|
---|
114 | /*}}}*/
|
---|
115 | }
|
---|