/******************************************************************************
** Copyright (c) 2023 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/

//! \file OsgST_InstancesContainer.h 
//! \brief Contains makOsgSpeedTree::Core class. 
//! \ingroup makOsgSpeedTree
#pragma once
#include "OSG/OsgST_PreReqs.h"
#include "OSG/OsgST_Types.h"

#include <unordered_set>
#include <unordered_map>

#include <Forest/Forest.h>

namespace makOsgSpeedTree
{
   typedef std::unordered_set<const SpeedTree::CTreeInstance*>                       ConstTreeInstanceSet;
   typedef std::unordered_map<const SpeedTree::CTree*, ConstTreeInstanceSet>         ConstMapTreeTypeToInstances;

   class TreeInstance;

   class InstancesContainer
   {

   public:
      InstancesContainer();
      ~InstancesContainer();

      void                                AddInstance(const TreeInstance* pInstance);
      void                                RemoveInstance(const TreeInstance* pInstance);
      void                                InstanceXFormChanged(const TreeInstance* pInstance);
      SpeedTree::st_int32                 GetNumInstances(void) const;
      SpeedTree::st_bool                  IsEmpty(void) const;

      const ConstMapTreeTypeToInstances&  GetInstances(void) const{return m_MapTreeTypeToInstances;}
      const SpeedTree::CExtents_64&       GetExtents(void) const{return m_ForestExtents;}
      float32                             GetLongestCellOverhang(void) const;

   private:

      void                                UpdateOverHang(const TreeInstance* pInstance);

      void                                UpdateForestExtents(const TreeInstance* pInstance);
      
      SpeedTree::CExtents_64              m_ForestExtents;

      ConstMapTreeTypeToInstances m_MapTreeTypeToInstances;

      // culling parameters
      float64 m_fLongestCellOverhang;

   };
}