11/* *
2- * Copyright 2013 Heiko Burau, Rene Widera
2+ * Copyright 2013-2014 Heiko Burau, Rene Widera
33 *
44 * This file is part of libPMacc.
55 *
2020 */
2121
2222
23- #ifndef POSITIONFILTER_HPP
24- #define POSITIONFILTER_HPP
23+ #pragma once
2524
2625#include " types.h"
2726#include " particles/frame_types.hpp"
@@ -35,13 +34,15 @@ namespace PMacc
3534namespace privatePositionFilter
3635{
3736
38- template <unsigned DIM , class Base = NullFrame>
37+ template <unsigned T_dim , class Base = NullFrame>
3938class PositionFilter : public Base
4039{
40+ public:
41+ static const uint32_t dim = T_dim;
4142protected:
42- DataSpace<DIM > offset;
43- DataSpace<DIM > max;
44- DataSpace<DIM > superCellIdx;
43+ DataSpace<dim > offset;
44+ DataSpace<dim > max;
45+ DataSpace<dim > superCellIdx;
4546
4647public:
4748
@@ -53,45 +54,66 @@ class PositionFilter : public Base
5354 {
5455 }
5556
56- HDINLINE void setWindowPosition (DataSpace<DIM > offset, DataSpace<DIM > size)
57+ HDINLINE void setWindowPosition (DataSpace<dim > offset, DataSpace<dim > size)
5758 {
5859 this ->offset = offset;
5960 this ->max = offset + size;
6061 }
6162
62- HDINLINE void setSuperCellPosition (DataSpace<DIM > superCellIdx)
63+ HDINLINE void setSuperCellPosition (DataSpace<dim > superCellIdx)
6364 {
6465 this ->superCellIdx = superCellIdx;
6566 }
6667
67- HDINLINE DataSpace<DIM > getOffset ()
68+ HDINLINE DataSpace<dim > getOffset ()
6869 {
6970 return offset;
7071 }
7172
73+ template <class FRAME >
74+ HDINLINE bool operator ()(FRAME & frame, lcellId_t id)
75+ {
76+ DataSpace<dim> localCellIdx = DataSpaceOperations<dim>::template map<
77+ typename FRAME::SuperCellSize
78+ > ((uint32_t ) (frame[id][localCellIdx_]));
79+ DataSpace<dim> pos = this ->superCellIdx + localCellIdx;
80+ bool result = false ;
81+ for (uint32_t d = 0 ; d < dim; ++d)
82+ result= result && (this ->offset [d] <= pos[d]) && (pos[d]<this ->max [d]);
83+ return Base::operator () (frame, id) && result;
84+ }
85+
7286};
7387
7488} // namespace privatePositionFilter
7589
90+ /* * This wrapper class is needed because for filters we are only allowed to
91+ * define one template parameter "base" (it is a constrain from FilterFactory)
92+ */
7693template <class Base = NullFrame>
7794class PositionFilter3D : public privatePositionFilter ::PositionFilter<DIM3, Base>
7895{
79- public:
96+ };
8097
81- template <class FRAME >
82- HDINLINE bool operator ()(FRAME & frame, lcellId_t id)
83- {
84- DataSpace<DIM3> localCellIdx3D = DataSpaceOperations<DIM3>::template map<
85- typename FRAME::SuperCellSize
86- > ((uint32_t ) (frame[id][localCellIdx_]));
87- DataSpace<DIM3> pos = this ->superCellIdx + localCellIdx3D;
88- return (this ->offset .x () <= pos.x () && this ->offset .y () <= pos.y () && this ->offset .z () <= pos.z () &&
89- this ->max .x () > pos.x () && this ->max .y () > pos.y () && this ->max .z () > pos.z ()) &&
90- Base::operator () (frame, id);
91- }
98+ template <class Base = NullFrame>
99+ class PositionFilter2D : public privatePositionFilter ::PositionFilter<DIM2, Base>
100+ {
92101};
93102
94- } // namespace Frame
103+ template <unsigned dim>
104+ struct GetPositionFilter ;
105+
106+ template <>
107+ struct GetPositionFilter <DIM3>
108+ {
109+ typedef PositionFilter3D<> type;
110+ };
111+
112+ template <>
113+ struct GetPositionFilter <DIM2>
114+ {
115+ typedef PositionFilter2D<> type;
116+ };
95117
96- #endif /* POSITIONFILTER_HPP */
97118
119+ } // namespace PMacc
0 commit comments