//#####################################################################
// Copyright 2020, Craig Schroeder, Tamar Shinar.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#ifndef __GRID_SURFACE_INTERSECTION__
#define __GRID_SURFACE_INTERSECTION__

#include <Core/Arrays/ARRAYS_ND.h>
#include <Core/Data_Structures/HASHTABLE.h>
#include <Core/Grids/EDGE_INDEX.h>
#include <Core/Grids/GRID.h>
#include <Core/Meshes/MESHES_FORWARD.h>
namespace PhysBAM{


template<class TV>
struct GRID_SURFACE_INTERSECTION_DATA
{
    typedef typename TV::SCALAR T;
    // whether endpoint nodes are inside object
    VECTOR<bool,2> in;

    // element index, edge theta, barycentric coordinates
    ARRAY<tuple<int,T,TV> > cut_elements;
};

// Node grid, return cut edges.
template<class T,class TV>
void Grid_Surface_Intersection(
    HASHTABLE<EDGE_INDEX<1>,GRID_SURFACE_INTERSECTION_DATA<TV> >& hash,
    const GRID<TV>& grid,const POINT_SIMPLICES_1D<T>& surface,bool compute_inside);

// Node grid, return cut edges.
template<class T,class TV>
void Grid_Surface_Intersection(
    HASHTABLE<EDGE_INDEX<2>,GRID_SURFACE_INTERSECTION_DATA<TV> >& hash,
    const GRID<TV>& grid,const SEGMENTED_CURVE<VECTOR<T,2> >& surface,bool compute_inside);

template<class T,class TV>
void Grid_Surface_Intersection(
    HASHTABLE<EDGE_INDEX<3>,GRID_SURFACE_INTERSECTION_DATA<TV> >& hash,
    const GRID<TV>& grid,const TRIANGULATED_SURFACE<T>& surface,bool compute_inside);

template<class TV>
void Flood_Fill(ARRAY<bool,VECTOR<int,TV::m> >& a,
    const HASHTABLE<EDGE_INDEX<TV::m>,GRID_SURFACE_INTERSECTION_DATA<TV> >& hash);

}
#endif
