//#####################################################################
// Copyright 2002-2004, Zhaosheng Bao.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#include <Core/Spatial_Acceleration/MESH_HIERARCHY.h>
#include <Core/Meshes/MESH_OBJECT.h>
#include <Core/Meshes/POINT_SIMPLEX_MESH.h>
#include <Core/Meshes/SEGMENT_MESH.h>
#include <Core/Meshes/TRIANGLE_MESH.h>
using namespace PhysBAM;
//#####################################################################
// Function Compute
//#####################################################################
template<class TV,class T_MESH> void MESH_HIERARCHY<TV,T_MESH>::
Compute(ARRAY_VIEW<const TV> X,bool update_order)
{
    ARRAY<RANGE<TV> > boxes(mesh.elements.m);
    for(int i=0;i<mesh.elements.m;i++)
        boxes(i)=RANGE<TV>::Bounding_Box(X.Subset(mesh.elements(i)));
    Compute(boxes,update_order);
}
//#####################################################################
// Function Compute
//#####################################################################
template<class TV,class T_MESH> void MESH_HIERARCHY<TV,T_MESH>::
Compute(ARRAY_VIEW<const TV> X,ARRAY_VIEW<const TV> Y,bool update_order)
{
    ARRAY<RANGE<TV> > boxes(mesh.elements.m);
    for(int i=0;i<mesh.elements.m;i++)
    {
        auto xb=RANGE<TV>::Bounding_Box(X.Subset(mesh.elements(i)));
        auto yb=RANGE<TV>::Bounding_Box(Y.Subset(mesh.elements(i)));
        boxes(i)=xb.Unite(yb);
    }
    Compute(boxes,update_order);
}
//#####################################################################
namespace PhysBAM{
template class MESH_HIERARCHY<VECTOR<double,1>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<double,1>,SIMPLEX_MESH<1> >;
template class MESH_HIERARCHY<VECTOR<double,2>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<double,2>,SEGMENT_MESH>;
template class MESH_HIERARCHY<VECTOR<double,2>,SIMPLEX_MESH<2> >;
template class MESH_HIERARCHY<VECTOR<double,3>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<double,3>,SEGMENT_MESH>;
template class MESH_HIERARCHY<VECTOR<double,3>,SIMPLEX_MESH<3> >;
template class MESH_HIERARCHY<VECTOR<double,3>,TRIANGLE_MESH>;
template class MESH_HIERARCHY<VECTOR<float,1>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<float,1>,SIMPLEX_MESH<1> >;
template class MESH_HIERARCHY<VECTOR<float,2>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<float,2>,SEGMENT_MESH>;
template class MESH_HIERARCHY<VECTOR<float,2>,SIMPLEX_MESH<2> >;
template class MESH_HIERARCHY<VECTOR<float,3>,POINT_SIMPLEX_MESH>;
template class MESH_HIERARCHY<VECTOR<float,3>,SEGMENT_MESH>;
template class MESH_HIERARCHY<VECTOR<float,3>,SIMPLEX_MESH<3> >;
template class MESH_HIERARCHY<VECTOR<float,3>,TRIANGLE_MESH>;
}
