MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

triangle.h
1 //
2 // triangle.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27
28 #ifndef _math_isosurf_triangle_h
29 #define _math_isosurf_triangle_h
30
31 #ifdef __GNUC__
32 #pragma interface
33 #endif
34
35 #include <math/isosurf/tricoef.h>
36 #include <math/isosurf/edge.h>
37
38 namespace sc {
39
40 class Triangle: public RefCount {
41 protected:
42 // these break gcc 2.5.8
43 //unsigned int _order:5;
44 //unsigned int _orientation0:1;
45 //unsigned int _orientation1:1;
46 //unsigned int _orientation2:1;
47 //unsigned char _order;
48 //unsigned char _orientation0;
49 //unsigned char _orientation1;
50 //unsigned char _orientation2;
51 unsigned int _order;
52 unsigned int _orientation0;
53 unsigned int _orientation1;
54 unsigned int _orientation2;
55 Ref<Edge> _edges[3];
56 Ref<Vertex> *_vertices;
57 public:
58 enum {max_order = 10};
59
60 Triangle(const Ref<Edge>& v1, const Ref<Edge>& v2, const Ref<Edge>& v3,
61 unsigned int orient0 = 0);
62 Ref<Edge> edge(int i) { return _edges[i]; };
63 int contains(const Ref<Edge>&) const;
64 unsigned int orientation(int i) const
65 {
66 return i==0?_orientation0:i==1?_orientation1:_orientation2;
67 }
68 unsigned int orientation(const Ref<Edge>&) const;
69 ~Triangle();
70 void add_edges(std::set<Ref<Edge> >&);
71 void add_vertices(std::set<Ref<Vertex> >&);
72
73 // returns the surface area element
74 // 0<=r<=1, 0<=s<=1, 0<=r+s<=1
75 // Ref<Vertex> is the intepolated vertex (both point and normal)
76 void interpolate(const Ref<TriInterpCoef>&,
77 double r,double s,const Ref<Vertex>&v, SCVector3& dA);
78 void interpolate(double r,double s,const Ref<Vertex>&v, SCVector3& dA);
79 void interpolate(double r,double s,const Ref<Vertex>&v, SCVector3& dA,
80 const Ref<Volume> &vol, double isovalue);
81
82 // returns a corner vertex from the triangle
83 // i = 0 is the (0,0) vertex (or L1 = 1, L2 = 0, L3 = 0)
84 // i = 1 is the (r=1,s=0) vertex (or L1 = 0, L2 = 1, L3 = 0)
85 // i = 2 is the (r=0,s=1) vertex (or L1 = 0, L2 = 0, L3 = 1)
86 Ref<Vertex> vertex(int i);
87
88 double flat_area();
89
90 // flip the orientation
91 void flip();
92
93 unsigned int order() const { return _order; }
94
95 void set_order(int order, const Ref<Volume>&vol,double isovalue);
96 };
97
98
99
100 class TriangleIntegrator: public DescribedClass {
101 private:
102 int _n;
103 double* _r;
104 double* _s;
105 double* _w;
106 // precomputed interpolation coefficients for triangles of various orders
107 Ref<TriInterpCoef> **coef_; // max_order by _n
108 protected:
109 void set_r(int i,double r);
110 void set_s(int i,double s);
111 void set_w(int i,double w);
112 void init_coef();
113 void clear_coef();
114 public:
115 TriangleIntegrator(const Ref<KeyVal>&);
116 TriangleIntegrator(int n);
117 virtual ~TriangleIntegrator();
118 inline double w(int i) { return _w[i]; }
119 inline double r(int i) { return _r[i]; }
120 inline double s(int i) { return _s[i]; }
121 inline int n() { return _n; }
122 virtual void set_n(int n);
123 Ref<TriInterpCoef> coef(int order, int i) { return coef_[order-1][i]; }
124 };
125
126
127 class GaussTriangleIntegrator: public TriangleIntegrator {
128 private:
129 void init_rw(int order);
130 public:
131 GaussTriangleIntegrator(const Ref<KeyVal>&);
132 GaussTriangleIntegrator(int order);
133 ~GaussTriangleIntegrator();
134 void set_n(int n);
135 };
136
137 }
138
139 #endif
140
141 // Local Variables:
142 // mode: c++
143 // c-file-style: "CLJ"
144 // End: