SheafSystem  0.0.0.0
ternary_index_space.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class ternary_index_space
19 
20 #include "SheafSystem/ternary_index_space.h"
21 #include "SheafSystem/assert_contract.h"
22 
23 using namespace fiber_bundle; // Workaround for MS C++ bug.
24 
25 // ===========================================================
26 // TERNARY_INDEX_SPACE FACET
27 // ===========================================================
28 
33 {
34  // Preconditions:
35 
36  // Body:
37 
38  // Create the block neighborhoods.
39 
40  ternary_index lblock_id, lnbr_id;
42 
43  for(lblock_id.i=0; lblock_id.i<i_size; lblock_id.i++)
44  {
45  for(lblock_id.j=0; lblock_id.j<j_size; lblock_id.j++)
46  {
47  for(lblock_id.k=0; lblock_id.k<k_size; lblock_id.k++)
48  {
49 
50  // Make a list of the members in the neighborhood of
51  // the current member, including the current member itself.
52 
53  ternary_index ldelta;
54  for(ldelta.i=-1; ldelta.i<2; ldelta.i++)
55  {
56  for(ldelta.j=-1; ldelta.j<2; ldelta.j++)
57  {
58  for(ldelta.k=-1; ldelta.k<2; ldelta.k++)
59  {
60  lnbr_id = lblock_id + ldelta;
61  if(contains(lnbr_id))
62  {
63  result->push_back(to_row_major_offset(lnbr_id));
64  }
65  }
66  }
67  }
68 
69  if(result->row_ct() < size)
70  {
71  // Move the the next row.
72 
73  result->new_back_row();
74  }
75  }
76  }
77  }
78 
79  // Postconditions:
80 
81  ensure(result != 0);
82  ensure(result->row_ct() == size);
83 
84  // Exit:
85 
86  return result;
87 }
88 
89 
90 // ===========================================================
91 // NON-MEMBER FUNCTIONS
92 // ===========================================================
93 
94 std::ostream&
96 operator<<(std::ostream& os, const fiber_bundle::ternary_index_space& xbis)
97 {
98  os << "i_size: " << xbis.i_size
99  << " j_size: " << xbis.j_size
100  << " k_size: " << xbis.k_size
101  << " size: " << xbis.size;
102  return os;
103 }
104 
105 
A triple of indices (i,j, k).
Definition: ternary_index.h:45
unary_index j
The second index.
Definition: ternary_index.h:57
unary_index i
The first index.
Definition: ternary_index.h:52
void push_back(const T &xvalue)
Add a value to the back of the back row.
ragged_array< unary_index > * neighbor_list() const
Create a ragged array containing the row major offsets of the neighbors of each index in the index sp...
index_type row_ct() const
The number of rows.
A bounded domain for ternary_index objects.
unary_index size
Number in the space.
unary_index k
The third index.
Definition: ternary_index.h:62
void new_back_row()
Creates a new last row.
unary_index j_size
Upper bound for the second index.
unary_index k_size
Upper bound for the third index.
A two index array with variable length rows.
Namespace for the fiber_bundles component of the sheaf system.
unary_index i_size
Upper bound for the first index.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const binary_index &xbi)
Insert binary_index& xbi into ostream& os.
Definition: binary_index.cc:35