Changeset 185:33ee25e05181
- Timestamp:
- 04/30/2012 07:22:02 PM (13 months ago)
- Author:
- Andreas Schaefer <gentryx@…>
- Branch:
- default
- Message:
-
stripped FixedCoord? from out of place ID
- Location:
- src
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r104
|
r185
|
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | | * A real valued coordinate class, which contains an optional ID. |
| | 11 | * A real valued coordinate class. Can also be seen as a short, |
| | 12 | * fixed-size vector. |
| 12 | 13 | */ |
| 13 | 14 | template<int DIM> |
| … |
… |
|
| 27 | 28 | |
| 28 | 29 | boost::array<double, DIM> c; |
| 29 | | // fixme: get rid of this |
| 30 | | int id; |
| 31 | 30 | }; |
| 32 | 31 | |
| … |
… |
|
| 40 | 39 | explicit |
| 41 | 40 | inline |
| 42 | | FloatCoord(const double& x = 0, const int _id = 0) |
| | 41 | FloatCoord(const double& x = 0) |
| 43 | 42 | { |
| 44 | 43 | c[0] = x; |
| 45 | | id = _id; |
| 46 | 44 | } |
| 47 | 45 | |
| … |
… |
|
| 61 | 59 | template<> |
| 62 | 60 | class FloatCoord<2> : public FloatCoordBase<2> |
| | 61 | { |
| | 62 | public: |
| | 63 | |
| | 64 | explicit |
| | 65 | inline |
| | 66 | FloatCoord( |
| | 67 | const double& x = 0, |
| | 68 | const double& y = 0) |
| | 69 | { |
| | 70 | c[0] = x; |
| | 71 | c[1] = y; |
| | 72 | } |
| | 73 | |
| | 74 | inline |
| | 75 | double length() const |
| | 76 | { |
| | 77 | return sqrt(c[0] * c[0] + |
| | 78 | c[1] * c[1]); |
| | 79 | } |
| | 80 | |
| | 81 | inline |
| | 82 | double sum() const |
| | 83 | { |
| | 84 | return c[0] + c[1]; |
| | 85 | } |
| | 86 | }; |
| | 87 | |
| | 88 | template<> |
| | 89 | class FloatCoord<3> : public FloatCoordBase<3> |
| 63 | 90 | { |
| 64 | 91 | public: |
| … |
… |
|
| 69 | 96 | const double& x = 0, |
| 70 | 97 | const double& y = 0, |
| 71 | | const int _id = 0) |
| 72 | | { |
| 73 | | c[0] = x; |
| 74 | | c[1] = y; |
| 75 | | id = _id; |
| 76 | | } |
| 77 | | |
| 78 | | inline |
| 79 | | double length() const |
| 80 | | { |
| 81 | | return sqrt(c[0] * c[0] + |
| 82 | | c[1] * c[1]); |
| 83 | | } |
| 84 | | |
| 85 | | inline |
| 86 | | double sum() const |
| 87 | | { |
| 88 | | return c[0] + c[1]; |
| 89 | | } |
| 90 | | }; |
| 91 | | |
| 92 | | template<> |
| 93 | | class FloatCoord<3> : public FloatCoordBase<3> |
| 94 | | { |
| 95 | | public: |
| 96 | | |
| 97 | | explicit |
| 98 | | inline |
| 99 | | FloatCoord( |
| 100 | | const double& x = 0, |
| 101 | | const double& y = 0, |
| 102 | | const double& z = 0, |
| 103 | | const int _id = 0) |
| | 98 | const double& z = 0) |
| 104 | 99 | { |
| 105 | 100 | c[0] = x; |
| 106 | 101 | c[1] = y; |
| 107 | 102 | c[2] = z; |
| 108 | | id = _id; |
| 109 | 103 | } |
| 110 | 104 | |
-
|
r33
|
r185
|
|
| 24 | 24 | static const int MAX_SIZE = 300000; |
| 25 | 25 | |
| 26 | | typedef std::list<FloatCoord<DIM> > CoordList; |
| | 26 | typedef std::list<std::pair<FloatCoord<DIM>, int> > CoordList; |
| 27 | 27 | typedef Grid<CoordList, TOPOLOGY> CoordListGrid; |
| 28 | | typedef SuperVector<FloatCoord<DIM> > CoordVec; |
| | 28 | typedef SuperVector<std::pair<FloatCoord<DIM>, int> > CoordVec; |
| 29 | 29 | typedef SuperVector<SuperVector<int> > Graph; |
| 30 | 30 | |
| … |
… |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | | inline void insert(CoordListGrid *grid, const FloatCoord<DIM>& pos) const |
| | 60 | inline void insert(CoordListGrid *grid, const FloatCoord<DIM>& pos, const int& id) const |
| 61 | 61 | { |
| 62 | 62 | Coord<2> c = posToCoord(pos); |
| 63 | | (*grid)[c].push_back(pos); |
| | 63 | (*grid)[c].push_back(std::make_pair(pos, id)); |
| 64 | 64 | } |
| 65 | 65 | |
| … |
… |
|
| 96 | 96 | CoordBoxSequence<DIM> s = box.sequence(); |
| 97 | 97 | while (s.hasNext()) { |
| 98 | | const std::list<FloatCoord<DIM> >& list = positions[s.next()]; |
| 99 | | for (typename std::list<FloatCoord<DIM> >::const_iterator iter = list.begin(); |
| | 98 | const CoordList& list = positions[s.next()]; |
| | 99 | for (typename CoordList::const_iterator iter = list.begin(); |
| 100 | 100 | iter != list.end(); |
| 101 | 101 | ++iter) { |
| … |
… |
|
| 189 | 189 | for (SuperVector<int>::const_iterator n = graph[i].begin(); |
| 190 | 190 | n != graph[i].end(); ++n) |
| 191 | | if (manhattanDistance(positions[i], positions[*n]) > 1) |
| | 191 | if (manhattanDistance(positions[i].first, positions[*n].first) > 1) |
| 192 | 192 | return false; |
| 193 | 193 | |
| … |
… |
|
| 267 | 267 | |
| 268 | 268 | bool searchList( |
| 269 | | const std::list<FloatCoord<DIM> >& list, |
| | 269 | const CoordList& list, |
| 270 | 270 | const FloatCoord<DIM>& pos, |
| 271 | 271 | std::set<int> *coords = 0) const |
| … |
… |
|
| 273 | 273 | bool found = false; |
| 274 | 274 | |
| 275 | | for (typename std::list<FloatCoord<DIM> >::const_iterator iter = list.begin(); |
| | 275 | for (typename CoordList::const_iterator iter = list.begin(); |
| 276 | 276 | iter != list.end(); |
| 277 | 277 | ++iter) { |
| 278 | | if (distance2(pos, *iter) < radius2) { |
| | 278 | if (distance2(pos, iter->first) < radius2) { |
| 279 | 279 | found = true; |
| 280 | 280 | if (coords) |
| 281 | | coords->insert(iter->id); |
| | 281 | coords->insert(iter->second); |
| 282 | 282 | } |
| 283 | 283 | } |
-
|
r27
|
r185
|
|
| 65 | 65 | |
| 66 | 66 | for (int i = 0; i < 6; ++i) |
| 67 | | adapter.insert(&grid, FloatCoord<2>(i + 0.5, 0.5, i)); |
| | 67 | adapter.insert(&grid, FloatCoord<2>(i + 0.5, 0.5), i); |
| 68 | 68 | |
| 69 | 69 | std::set<int> coords; |
| … |
… |
|
| 124 | 124 | MyAdapter::Graph graph; |
| 125 | 125 | for (int i = 0; i < width; ++i) { |
| 126 | | positions.push_back(FloatCoord<2>(i * 0.5, 0.5, i)); |
| | 126 | positions.push_back(std::make_pair(FloatCoord<2>(i * 0.5, 0.5), i)); |
| 127 | 127 | SuperVector<int> neighbors; |
| 128 | 128 | neighbors << ((i + width - 1) % width) |
-
|
r184
|
r185
|
|
| 151 | 151 | coefficients, |
| 152 | 152 | source, |
| | 153 | index + |
| 153 | 154 | coord.x() + |
| 154 | 155 | coord.y() * DIM_X + |
| … |
… |
|
| 198 | 199 | operator[](FixedCoord<X, Y, Z> /*unused*/) const |
| 199 | 200 | { |
| 200 | | return FixedNeighborhood<DIM_X, DIM_Y, DIM_Z, X + Y * DIM_X + Z * DIM_X * DIM_Y>(coefficients, source); |
| | 201 | return FixedNeighborhood<DIM_X, DIM_Y, DIM_Z, INDEX + X + Y * DIM_X + Z * DIM_X * DIM_Y>(coefficients, source); |
| | 202 | } |
| | 203 | |
| | 204 | Neighborhood<DIM_X, DIM_Y, DIM_Z> |
| | 205 | operator[](Coord<3> coord) const |
| | 206 | { |
| | 207 | return Neighborhood<DIM_X, DIM_Y, DIM_Z>( |
| | 208 | coefficients, |
| | 209 | source, |
| | 210 | INDEX + |
| | 211 | coord.x() + |
| | 212 | coord.y() * DIM_X + |
| | 213 | coord.z() * DIM_X * DIM_Y); |
| 201 | 214 | } |
| 202 | 215 | |