SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriSamplingSchemes.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /// @todo Documentation Core/Basis/TriSamplingSchemes.h
30 
31 #ifndef CORE_BASIS_TRISAMPLINGSCHEMES_H
32 #define CORE_BASIS_TRISAMPLINGSCHEMES_H 1
33 
34 #include <vector>
36 
37 #include <Core/Basis/share.h>
38 
39 namespace SCIRun {
40 namespace Core {
41 namespace Basis {
42 
44 {
45  public:
46 
47  template <class ARRAY1, class ARRAY2>
48  void get_gaussian_scheme(ARRAY1& coords, ARRAY2& weights, int order)
49  {
50  typedef typename ARRAY1::value_type coords_type;
51 
52  if (order == 1 || order == 0)
53  {
54  const double gaussian_weights[1] = { 1.0};
55  const double gaussian_coords[1][2] = {{1./3.,1./3.}};
56  const unsigned int num_coords = 2;
57  const unsigned int num_points = 1;
58 
59  coords.resize(num_points);
60  weights.resize(num_points);
61  for (unsigned int i=0; i<num_points; i++)
62  {
63  coords[i].resize(num_coords);
64  for (unsigned int j=0; j<num_coords; j++)
65  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
66  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
67  }
68  }
69  else if (order == 2)
70  {
71  const double gaussian_weights[3] =
72  {1./3., 1./3., 1./3.};
73  const double gaussian_coords[3][2] =
74  {{1./6.,1./6.}, {2./3.,1./6.}, {1./6.,2./3.}};
75  const unsigned int num_coords = 2;
76  const unsigned int num_points = 3;
77 
78  coords.resize(num_points);
79  weights.resize(num_points);
80  for (unsigned int i=0; i<num_points; i++)
81  {
82  coords[i].resize(num_coords);
83  for (unsigned int j=0; j<num_coords; j++)
84  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
85  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
86  }
87  }
88  else if (order == 3)
89  {
90  const double gaussian_weights[7] =
91  { 0.1259391805, 0.1259391805, 0.1259391805, 0.1323941527,
92  0.1323941527, 0.1323941527, 0.225};
93  const double gaussian_coords[7][2] = {
94  {0.1012865073, 0.1012865073}, {0.7974269853, 0.1012865073},
95  {0.1012865073, 0.7974269853}, {0.4701420641, 0.0597158717},
96  {0.4701420641, 0.4701420641}, {0.0597158717, 0.4701420641},
97  {0.3333333333, 0.3333333333}};
98  const unsigned int num_coords = 2;
99  const unsigned int num_points = 7;
100 
101  coords.resize(num_points);
102  weights.resize(num_points);
103  for (unsigned int i=0; i<num_points; i++)
104  {
105  coords[i].resize(num_coords);
106  for (unsigned int j=0; j<num_coords; j++)
107  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
108  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
109  }
110  }
111  else
112  {
113  REPORT_NOT_IMPLEMENTED("Only Gaussian scheme 1, 2, and 3 are implemented");
114  }
115  }
116 
117  template <class ARRAY1, class ARRAY2>
118  void get_regular_scheme(ARRAY1& coords,ARRAY2& weights, int order)
119  {
120  typedef typename ARRAY1::value_type coords_type;
121 
122  int m = 0;
123  for (int j=0; j<order;j++) m += (2*j+1);
124  coords.resize(m);
125 
126  weights.resize(m);
127  for (int p=0; p<m;p++) weights[p] = static_cast<typename ARRAY2::value_type>(1.0/static_cast<double>(m));
128 
129  int k= 0;
130  for (int p=0;p<order;p++)
131  {
132  int r=0;
133  for (; r<p; r++)
134  {
135  coords[k].resize(2);
136  coords[k][1] = static_cast<typename coords_type::value_type>((static_cast<double>(order-1-p)+1.0/3.0)/static_cast<double>(order));
137  coords[k][0] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/3.0)/static_cast<double>(order));
138  k++;
139  coords[k].resize(2);
140  coords[k][1] = static_cast<typename coords_type::value_type>((static_cast<double>(order-1-p)+2.0/3.0)/static_cast<double>(order));
141  coords[k][0] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+2.0/3.0)/static_cast<double>(order));
142  k++;
143  }
144  coords[k].resize(2);
145  coords[k][1] = static_cast<typename coords_type::value_type>((static_cast<double>(order-1-p)+1.0/3.0)/static_cast<double>(order));
146  coords[k][0] = static_cast<typename coords_type::value_type>((static_cast<double>(r)+1.0/3.0)/static_cast<double>(order));
147  k++;
148  }
149  }
150 };
151 
152 }}}
153 
154 #endif
void get_regular_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: TriSamplingSchemes.h:118
#define SCISHARE
Definition: share.h:39
Utility for specifying data invariants (Assertions)
#define REPORT_NOT_IMPLEMENTED(message)
Definition: Exception.h:106
void get_gaussian_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: TriSamplingSchemes.h:48
Definition: TriSamplingSchemes.h:43