LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Pixel_omp.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
26 
27 namespace lsst {
28 namespace meas {
29 namespace algorithms {
30 namespace shapelet {
31 
33  _shouldUsePool(false), _v1(new std::vector<Pixel>())
34  {}
35 
36  PixelList::PixelList(const int n) :
37  _shouldUsePool(false), _v1(new std::vector<Pixel>(n))
38  {}
39 
41  _shouldUsePool(false), _v1(new std::vector<Pixel>(rhs.size()))
42  {
43  if (rhs._shouldUsePool)
44  std::copy(rhs._v2->begin(),rhs._v2->end(),_v1->begin());
45  else *_v1 = *rhs._v1;
46  }
47 
49  {
50  if (size() != rhs.size()) resize(rhs.size());
51 
52  if (_shouldUsePool) {
53  if (rhs._shouldUsePool) *_v2 = *rhs._v2;
54  else std::copy(rhs._v1->begin(),rhs._v1->end(),_v2->begin());
55  } else {
56  if (rhs._shouldUsePool)
57  std::copy(rhs._v2->begin(),rhs._v2->end(),_v1->begin());
58  else *_v1 = *rhs._v1;
59  }
60  return *this;
61  }
62 
64  {
65 #ifdef _OPENMP
66 #pragma omp critical (PixelList)
67 #endif
68  {
69  _v2.reset();
70  }
71  }
72 
74  {
75 #ifdef PIXELLIST_USE_POOL
76  // This should be done before any elements are added.
77  if (_v1.get()) Assert(_v1->size() == 0);
78  if (_v2.get()) Assert(_v2->size() == 0);
79  _v1.reset();
80 #ifdef _OPENMP
81 #pragma omp critical (PixelList)
82 #endif
83  {
84  _v2.reset(new std::vector<Pixel,PoolAllocPixel>());
85  }
86  _shouldUsePool = true;
87 #endif
88  }
89 
90  size_t PixelList::size() const
91  {
92  if (_shouldUsePool) return _v2->size();
93  else return _v1->size();
94  }
95 
96  void PixelList::reserve(const int n)
97  {
98  if (_shouldUsePool) {
99 #ifdef _OPENMP
100 #pragma omp critical (PixelList)
101 #endif
102  {
103  _v2->reserve(n);
104  }
105  } else {
106  _v1->reserve(n);
107  }
108  }
109 
110  size_t PixelList::capacity() const
111  { return _shouldUsePool ? _v2->capacity() : _v1->capacity(); }
112 
113  void PixelList::resize(const int n)
114  {
115  if (_shouldUsePool) {
116 #ifdef _OPENMP
117 #pragma omp critical (PixelList)
118 #endif
119  {
120  _v2->resize(n);
121  }
122  } else {
123  _v1->resize(n);
124  }
125  }
126 
128  {
129  if (_shouldUsePool) {
130 #ifdef _OPENMP
131 #pragma omp critical (PixelList)
132 #endif
133  {
134  _v2->clear();
135  }
136  } else {
137  _v1->clear();
138  }
139  }
140 
142  {
143  if (_shouldUsePool) {
144 #ifdef _OPENMP
145 #pragma omp critical (PixelList)
146 #endif
147  {
148  _v2->push_back(p);
149  }
150  } else {
151  _v1->push_back(p);
152  }
153  }
154 
156  {
157  if (_shouldUsePool) return (*_v2)[i];
158  else return (*_v1)[i];
159  }
160 
161  const Pixel& PixelList::operator[](const int i) const
162  {
163  if (_shouldUsePool) return (*_v2)[i];
164  else return (*_v1)[i];
165  }
166 
168  {
170  PixelListSorter(const Position& cen) : _cen(cen) {}
171  bool operator()(const Pixel& p1, const Pixel& p2) const
172  { return std::norm(p1.getPos()-_cen) < std::norm(p2.getPos()-_cen); }
173  };
174 
175  void PixelList::sort(const Position& cen)
176  {
177  PixelListSorter sorter(cen);
178  if (_shouldUsePool) std::sort(_v2->begin(),_v2->end(),sorter);
179  else std::sort(_v1->begin(),_v1->end(),sorter);
180  }
181 
182 }}}}
std::complex< double > getPos() const
Definition: Pixel.h:47
boost::shared_ptr< std::vector< Pixel > > _v2
Definition: Pixel.h:103
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
T norm(const T &x)
Definition: Integrate.h:191
boost::shared_ptr< std::vector< Pixel > > _v1
Definition: Pixel.h:98
PixelList & operator=(const PixelList &rhs)
Definition: Pixel_omp.cc:48
bool operator()(const Pixel &p1, const Pixel &p2) const
Definition: Pixel_omp.cc:171
#define Assert(x)
Definition: dbg.h:73