//#####################################################################
// Copyright 2003-2007, Robert Bridson, Ronald Fedkiw, Eran Guendelman, Geoffrey Irving.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
// Class PARTICLE_PARTITION
//#####################################################################
#ifndef __PARTICLE_PARTITION__
#define __PARTICLE_PARTITION__

#include <Core/Arrays/ARRAYS_ND.h>
#include <Core/Geometry_Particles/GEOMETRY_PARTICLES.h>
#include <Core/Grids/CELL_ITERATOR.h>
#include <Core/Implicit_Objects/IMPLICIT_OBJECT.h>
#include <Core/Math_Tools/RANGE.h>
namespace PhysBAM{

template<class TV>
class PARTICLE_PARTITION
{
    typedef typename TV::SCALAR T;
    enum WORKAROUND {d=TV::m};
    typedef VECTOR<int,TV::m> IV;typedef ARRAY<T,IV> T_ARRAYS_T;
public:
    GRID<TV> grid;
    ARRAY<ARRAY<int>,IV> partition;
private:
    bool use_radius;
    T_ARRAYS_T radius;
public:

    PARTICLE_PARTITION(const RANGE<TV>& box,const IV& counts,const GEOMETRY_PARTICLES<TV>& particles,
        const bool use_radius=true,GRID_TYPE<1> is_mac_grid=mac_grid_type);

    void Add_To_Partition(const TV& location,const int particle_id);
    RANGE<IV> Range(const RANGE<TV>& box) const;
    void Intersection_List(const IMPLICIT_OBJECT<TV>& test_surface,const MATRIX<T,d>& rotation,
        const TV& translation,ARRAY<IV>& intersection_list,const T contour_value=0) const;
    void Proximity_List(const TV& location,const T proximity,ARRAY<int>& proximity_list);
//#####################################################################
};
}
#endif
