SheafSystem  0.0.0.0
binary_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 binary_index_space
19 
20 #include "SheafSystem/binary_index_space.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace fiber_bundle; // Workaround for MS C++ bug.
25 
26 // ===========================================================
27 // BINARY_INDEX_SPACE FACET
28 // ===========================================================
29 
34 {
35  // Preconditions:
36 
37  // Body:
38 
39  // Create the block neighborhoods.
40 
41  binary_index lblock_id, lnbr_id;
43 
44  for(lblock_id.i=0; lblock_id.i<i_size; lblock_id.i++)
45  {
46  for(lblock_id.j=0; lblock_id.j<j_size; lblock_id.j++)
47  {
48 
49  // Make a list of the members in the neighborhood of
50  // the current member, including the current member itself.
51 
52  binary_index ldelta;
53  for(ldelta.i=-1; ldelta.i<2; ldelta.i++)
54  {
55  for(ldelta.j=-1; ldelta.j<2; ldelta.j++)
56  {
57  lnbr_id = lblock_id + ldelta;
58  if(contains(lnbr_id))
59  {
60  result->push_back(to_row_major_offset(lnbr_id));
61  }
62  }
63  }
64 
65  if(result->row_ct() < size)
66  {
67  // Move the the next row.
68 
69  result->new_back_row();
70  }
71  }
72  }
73 
74  // Postconditions:
75 
76  ensure(result != 0);
77  ensure(result->row_ct() == size);
78 
79  // Exit:
80 
81  return result;
82 }
83 
84 
85 // ===========================================================
86 // NON-MEMBER FUNCTIONS
87 // ===========================================================
88 
89 std::ostream&
91 operator<<(std::ostream& os, const fiber_bundle::binary_index_space& xbis)
92 {
93  os << "i_size: " << xbis.i_size
94  << " j_size: " << xbis.j_size
95  << " size: " << xbis.size;
96  return os;
97 }
98 
99 
A pair of indices (i,j).
Definition: binary_index.h:44
unary_index j_size
Upper bound for the second index.
void push_back(const T &xvalue)
Add a value to the back of the back row.
index_type row_ct() const
The number of rows.
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...
unary_index size
Number in the space.
A bounded domain for binary_index objects.
unary_index i
The first index.
Definition: binary_index.h:51
unary_index j
The second index.
Definition: binary_index.h:56
void new_back_row()
Creates a new last row.
A two index array with variable length rows.
unary_index i_size
Upper bound for the first index.
Namespace for the fiber_bundles component of the sheaf system.
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