//#####################################################################
// Copyright 2005, 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 QT_TETRAHEDRALIZED_VOLUME
//#####################################################################
#ifndef __QT_TETRAHEDRALIZED_VOLUME__
#define __QT_TETRAHEDRALIZED_VOLUME__

#include <Core/Meshes/TETRAHEDRON_MESH.h>
#include "QT_COMPONENT.h"
#include "QT_SPLIT_OBJECT.h"
#include <memory>

namespace PhysBAM
{
template<class OBJ> class QT_OBJECT;

template<class T>
class QT_TETRAHEDRALIZED_VOLUME:public QT_SPLIT_OBJECT<VECTOR<T,3>,MESH_OBJECT<VECTOR<T,3>,3>>
{
public:
    typedef VECTOR<T,3> TV;
    typedef MESH_OBJECT<TV,3> TYPE;

    typedef MESH_OPTIONS<3> OPT;
    typedef QT_SPLIT_OBJECT<VECTOR<T,3>,MESH_OBJECT<VECTOR<T,3>,3>> BASE;
private:
    OPT opt,raw_opt[4];
    using typename BASE::FV;using BASE::Obj;using BASE::valid;
    using BASE::name;using BASE::action;

    int selected_vertex=-1;
    int selected_segment=-1;
    int selected_triangle=-1;
    int selected_tetrahedron=-1;
    static const QT_COMPONENT_OPTION options[];
    static const int num_options;
    typedef QT_TETRAHEDRALIZED_VOLUME SELF;

    TRIANGULATED_SURFACE<T>* ts=nullptr;
public:

    int cutaway_mode=0;
    T cutaway_fraction=(T).5;

    QT_TETRAHEDRALIZED_VOLUME(QT_WORLD& world,const std::string& name,const std::string& file);
    QT_TETRAHEDRALIZED_VOLUME(QT_WORLD& world,const std::string& name,const std::string& mesh_file,const std::string& part_file);
    QT_TETRAHEDRALIZED_VOLUME(QT_WORLD& world,const std::string& name,const std::shared_ptr<QT_OBJECT<TYPE>>& obj);

    virtual ~QT_TETRAHEDRALIZED_VOLUME();

    RANGE<FV> Bounding_Box() override;
    void Render(QT_RENDER_UTILS& ru) override;
    void Read() override;
    void Set_Selection(ARRAY_VIEW<int> selection) override;
    void Clear_Selection() override;
    FV Selection_Point() override;
    void Make_Dialog(QT_WINDOW& window) override;
    void Read_Option(std::istream& in,int level) override;
    void Set_Draw(bool draw) override;
    bool Draw() const override;
    void Save_Settings(std::ostream& out) override;
    void Clear_Settings() override;

    void Cycle_Cutaway_Mode()
    {cutaway_mode=(cutaway_mode+1)%8;}

    void Decrease_Cutaway_Fraction()
    {cutaway_fraction-=(T).05;if(cutaway_fraction<0)cutaway_fraction+=1;}

    void Increase_Cutaway_Fraction()
    {cutaway_fraction+=(T).05;if(cutaway_fraction>1)cutaway_fraction-=1;}

//#####################################################################
    void Select_Tetrahedron_From_Triangle();
//#####################################################################
};
}

#endif
