SpatialOps
MemoryWindow.cpp
1 /*
2  * Copyright (c) 2014-2017 The University of Utah
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 
24 
25 #include <ostream>
26 using namespace std;
27 
28 namespace SpatialOps{
29 
30  inline bool check_ge_zero ( const IntVec& v ){ return (v[0]>=0) & (v[1]>=0) & (v[2]>=0); }
31 
32  //---------------------------------------------------------------
33 
34  MemoryWindow::MemoryWindow( const int npts[3],
35  const int offset[3],
36  const int extent[3] )
37  : nptsGlob_( npts ),
38  offset_( offset ),
39  extent_( extent )
40  {
41 # ifndef NDEBUG
42  assert( sanity_check() );
43 # endif
44  }
45 
47  const IntVec& offset,
48  const IntVec& extent )
49  : nptsGlob_( npts ),
50  offset_( offset ),
51  extent_( extent )
52  {
53 # ifndef NDEBUG
54  assert( sanity_check() );
55 # endif
56  }
57 
58  MemoryWindow::MemoryWindow( const int npts[3] )
59  : nptsGlob_( npts ), offset_(0,0,0), extent_( npts )
60  {
61 # ifndef NDEBUG
62  assert( sanity_check() );
63 # endif
64  }
65 
67  : nptsGlob_( npts ), offset_(0,0,0), extent_( npts )
68  {
69 # ifndef NDEBUG
70  assert( sanity_check() );
71 # endif
72  }
73 
74  //---------------------------------------------------------------
75 
77  MemoryWindow::operator=( const MemoryWindow& other )
78  {
79  nptsGlob_ = other.nptsGlob_;
80  offset_ = other.offset_;
81  extent_ = other.extent_;
82  return *this;
83  }
84 
85  //---------------------------------------------------------------
86 
87  MemoryWindow::~MemoryWindow()
88  {}
89 
90  //---------------------------------------------------------------
91 
92  ostream& operator<<(ostream& os, const MemoryWindow& w ){
93  os << w.nptsGlob_ << w.offset_ << w.extent_;
94  return os;
95  }
96 
97  bool
99  {
100  return check_ge_zero( nptsGlob_ ) &&
101  check_ge_zero( offset_ ) &&
102  check_ge_zero( extent_ ) &&
103  check_ge_zero( nptsGlob_ - extent_ );
104  }
105 
106 } // namespace SpatialOps
Provides tools to index into a sub-block of memory.
Definition: MemoryWindow.h:63
MemoryWindow(const int npts[3], const int offset[3], const int extent[3])
construct a MemoryWindow object
STL namespace.
bool sanity_check() const
performs basic sanity checks to see if there is anything obviously wrong with this window...