SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HexSamplingSchemes.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/HexSamplingSchemes.h
30 
31 #ifndef CORE_BASIS_HEXSAMPLINGSCHEMES_H
32 #define CORE_BASIS_HEXSAMPLINGSCHEMES_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 == 0 || order == 1)
53  {
54  const double gaussian_weights[1] = { 1.0};
55  const double gaussian_coords[1][3] = {{0.5, 0.5, 0.5}};
56  const unsigned int num_coords = 3;
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[8] = {.125, .125, .125, .125,
72  .125, .125, .125, .125};
73  const double gaussian_coords[8][3] = {
74  {0.211324865405, 0.211324865405, 0.211324865405},
75  {0.788675134595, 0.211324865405, 0.211324865405},
76  {0.788675134595, 0.788675134595, 0.211324865405},
77  {0.211324865405, 0.788675134595, 0.211324865405},
78  {0.211324865405, 0.211324865405, 0.788675134595},
79  {0.788675134595, 0.211324865405, 0.788675134595},
80  {0.788675134595, 0.788675134595, 0.788675134595},
81  {0.211324865405, 0.788675134595, 0.788675134595}};
82  const unsigned int num_coords = 3;
83  const unsigned int num_points = 8;
84 
85  coords.resize(num_points);
86  weights.resize(num_points);
87  for (unsigned int i=0; i<num_points; i++)
88  {
89  coords[i].resize(num_coords);
90  for (unsigned int j=0; j<num_coords; j++)
91  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
92  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
93  }
94  }
95  else if (order == 3)
96  {
97  const double gaussian_weights[27] = {
98  0.03429355278944, 0.05486968447298, 0.03429355278944,
99  0.05486968447298, 0.08779149517257, 0.05486968447298,
100  0.03429355278944, 0.05486968447298, 0.03429355278944,
101 
102  0.03429355278944, 0.05486968447298, 0.03429355278944,
103  0.05486968447298, 0.08779149517257, 0.05486968447298,
104  0.03429355278944, 0.05486968447298, 0.03429355278944,
105 
106  0.03429355278944, 0.05486968447298, 0.03429355278944,
107  0.05486968447298, 0.08779149517257, 0.05486968447298,
108  0.03429355278944, 0.05486968447298, 0.03429355278944
109  };
110  const double gaussian_coords[27][3] = {
111  {0.11270166537950, 0.11270166537950, 0.11270166537950},
112  {0.5, 0.11270166537950, 0.11270166537950},
113  {0.88729833462050, 0.11270166537950, 0.11270166537950},
114  {0.11270166537950, 0.5, 0.11270166537950},
115  {0.5, 0.5, 0.11270166537950},
116  {0.88729833462050, 0.5, 0.11270166537950},
117  {0.11270166537950, 0.88729833462050, 0.11270166537950},
118  {0.5, 0.88729833462050, 0.11270166537950},
119  {0.88729833462050, 0.88729833462050, 0.11270166537950},
120 
121  {0.11270166537950, 0.11270166537950, 0.5},
122  {0.5, 0.11270166537950, 0.5},
123  {0.88729833462050, 0.11270166537950, 0.5},
124  {0.11270166537950, 0.5, 0.5},
125  {0.5, 0.5, 0.5},
126  {0.88729833462050, 0.5, 0.5},
127  {0.11270166537950, 0.88729833462050, 0.5},
128  {0.5, 0.88729833462050, 0.5},
129  {0.88729833462050, 0.88729833462050, 0.5},
130 
131  {0.11270166537950, 0.11270166537950, 0.88729833462050},
132  {0.5, 0.11270166537950, 0.88729833462050},
133  {0.88729833462050, 0.11270166537950, 0.88729833462050},
134  {0.11270166537950, 0.5, 0.88729833462050},
135  {0.5, 0.5, 0.88729833462050},
136  {0.88729833462050, 0.5, 0.88729833462050},
137  {0.11270166537950, 0.88729833462050, 0.88729833462050},
138  {0.5, 0.88729833462050, 0.88729833462050},
139  {0.88729833462050, 0.88729833462050, 0.88729833462050}
140  };
141  const unsigned int num_coords = 3;
142  const unsigned int num_points = 27;
143 
144  coords.resize(num_points);
145  weights.resize(num_points);
146  for (unsigned int i=0; i<num_points; i++)
147  {
148  coords[i].resize(num_coords);
149  for (unsigned int j=0; j<num_coords; j++)
150  coords[i][j] = static_cast<typename coords_type::value_type>(gaussian_coords[i][j]);
151  weights[i] = static_cast<typename ARRAY2::value_type>(gaussian_weights[i]);
152  }
153  }
154  else
155  {
156  REPORT_NOT_IMPLEMENTED("Only Gaussian scheme 1, 2, and 3 are implemented");
157  }
158  }
159 
160  template <class ARRAY1, class ARRAY2>
161  void get_regular_scheme(ARRAY1& coords, ARRAY2& weights, int order)
162  {
163  typedef typename ARRAY1::value_type coords_type;
164 
165  coords.resize(order*order*order);
166  weights.resize(order*order*order);
167  for (int i=0; i< order; i++)
168  {
169  for (int j=0; j< order; j++)
170  {
171  for (int k=0; k< order; k++)
172  {
173  coords[i+order*j+order*order*k].resize(3);
174  coords[i+order*j+order*order*k][0] =
175  static_cast<typename coords_type::value_type>(static_cast<double>(i+1)/static_cast<double>(order+1));
176  coords[i+order*j+order*order*k][1] =
177  static_cast<typename coords_type::value_type>(static_cast<double>(j+1)/static_cast<double>(order+1));
178  coords[i+order*j+order*order*k][2] =
179  static_cast<typename coords_type::value_type>(static_cast<double>(k+1)/static_cast<double>(order+1));
180  weights[i+order*j+order*order*k] =
181  static_cast<typename ARRAY2::value_type>(1.0/static_cast<double>(order*order*order));
182  }
183  }
184  }
185  }
186 };
187 
188 }}}
189 
190 #endif
#define SCISHARE
Definition: share.h:39
Utility for specifying data invariants (Assertions)
void get_regular_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: HexSamplingSchemes.h:161
void get_gaussian_scheme(ARRAY1 &coords, ARRAY2 &weights, int order)
Definition: HexSamplingSchemes.h:48
#define REPORT_NOT_IMPLEMENTED(message)
Definition: Exception.h:106
Definition: HexSamplingSchemes.h:43