SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QuadSamplingSchemes.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/QuadSamplingSchemes.h
30 #ifndef CORE_BASIS_QUADSAMPLINGSCHEMES_H
31 #define CORE_BASIS_QUADSAMPLINGSCHEMES_H 1
32 
33 #include <vector>
35 
36 #include <Core/Basis/share.h>
37 
38 namespace SCIRun {
39 namespace Core {
40 namespace Basis {
41 
43 {
44  public:
45 
46  template <class ARRAY1, class ARRAY2>
47  void get_gaussian_scheme(ARRAY1& coords, ARRAY2& weights, int order)
48  {
49  typedef typename ARRAY1::value_type coords_type;
50 
51  if (order == 1 || order == 0)
52  {
53  const double gaussian_weights[1] = {1.0};
54  const double gaussian_coords[1][2] = {{.5,.5}};
55  const unsigned int num_coords = 2;
56  const unsigned int num_points = 1;
57 
58  coords.resize(num_points);
59  weights.resize(num_points);
60  for (unsigned int i=0; i<num_points; i++)
61  {
62  coords[i].resize(num_coords);
63  for (unsigned int j=0; j<num_coords; j++)
64  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
65  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
66  }
67  }
68  else if (order == 2)
69  {
70  const double gaussian_weights[4] = {.25, .25, .25, .25};
71  const double gaussian_coords[4][2] = {
72  {0.211324865405, 0.211324865405},
73  {0.788675134595, 0.211324865405},
74  {0.788675134595, 0.788675134595},
75  {0.211324865405, 0.788675134595}};
76  const unsigned int num_coords = 2;
77  const unsigned int num_points = 4;
78 
79  coords.resize(num_points);
80  weights.resize(num_points);
81  for (unsigned int i=0; i<num_points; i++)
82  {
83  coords[i].resize(num_coords);
84  for (unsigned int j=0; j<num_coords; j++)
85  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
86  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
87  }
88  }
89  else if (order == 3)
90  {
91  const double gaussian_weights[9] = {
92  0.07716049378395, 0.12345679007654, 0.07716049378395,
93  0.12345679007654, 0.19753086415802, 0.12345679007654,
94  0.07716049378395, 0.12345679007654, 0.07716049378395 };
95  const double gaussian_coords[9][2] = {
96  {0.11270166537950, 0.11270166537950}, {0.5, 0.11270166537950},
97  {0.88729833462050, 0.11270166537950},
98  {0.11270166537950, 0.5}, {0.5, 0.5}, {0.88729833462050, 0.5},
99  {0.11270166537950, 0.88729833462050}, {0.5, 0.88729833462050},
100  {0.88729833462050, 0.88729833462050}};
101  const unsigned int num_coords = 2;
102  const unsigned int num_points = 9;
103 
104  coords.resize(num_points);
105  weights.resize(num_points);
106  for (unsigned int i=0; i<num_coords; i++)
107  {
108  coords[i].resize(num_points);
109  for (unsigned int j=0; j<num_coords; j++)
110  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
111  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
112  }
113  }
114  else
115  {
116  REPORT_NOT_IMPLEMENTED("Only Gaussian scheme 1, 2, and 3 are implemented");
117  }
118  }
119 
120  template <class ARRAY1, class ARRAY2>
121  void get_regular_scheme(ARRAY1& coords, ARRAY2& weights, int order)
122  {
123  typedef typename ARRAY1::value_type coords_type;
124 
125  coords.resize(order*order);
126  weights.resize(order*order);
127  for (int i=0; i< order; i++)
128  {
129  for (int j=0; j< order; j++)
130  {
131  coords[i+order*j].resize(2);
132  coords[i+order*j][0] = static_cast<typename coords_type::value_type>(static_cast<double>(i+1)/static_cast<double>(order+1));
133  coords[i+order*j][1] = static_cast<typename coords_type::value_type>(static_cast<double>(j+1)/static_cast<double>(order+1));
134  weights[i+order*j] = static_cast<typename ARRAY2::value_type>(1.0/static_cast<double>(order*order));
135  }
136  }
137  }
138 };
139 
140 }}}
141 
142 #endif
#define SCISHARE
Definition: share.h:39
void get_regular_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: QuadSamplingSchemes.h:121
Utility for specifying data invariants (Assertions)
Definition: QuadSamplingSchemes.h:42
#define REPORT_NOT_IMPLEMENTED(message)
Definition: Exception.h:106
void get_gaussian_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: QuadSamplingSchemes.h:47