//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::calculateCurrentTotalCellVisibility(cvf::UByteArray* totalVisibility, int timeStepIndex)
{
    if (!m_geomechView->geoMechCase()) return;

    size_t gridCount = m_geomechView->femParts()->partCount();
    
    if (gridCount == 0) return;

    RigFemPart* part = m_geomechView->femParts()->part(0);
    int elmCount = part->elementCount();

    totalVisibility->resize(elmCount);
    totalVisibility->setAll(false);

    std::vector<RivGeoMechPartMgrCache::Key> visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex);
    for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx)
    {
        RivGeoMechPartMgr*  partMgr = m_partMgrCache->partMgr(visiblePartMgrs[pmIdx]);

        cvf::ref<cvf::UByteArray> visibility =  partMgr->cellVisibility(0);
        for (int elmIdx = 0; elmIdx < elmCount; ++ elmIdx)
        {
            (*totalVisibility)[elmIdx] |= (*visibility)[elmIdx];
        }
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::updateStaticCellColors(int timeStepIndex)
{
    std::vector<RivGeoMechPartMgrCache::Key> visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex);
    for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx)
    {
        RivGeoMechPartMgr*  partMgr = m_partMgrCache->partMgr(visiblePartMgrs[pmIdx]);
        partMgr->updateCellColor(cvf::Color4f(cvf::Color3f::ORANGE));
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::updateCellResultColor(int timeStepIndex, RimGeoMechCellColors* cellResultColors)
{
    std::vector<RivGeoMechPartMgrCache::Key> visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex);
    for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx)
    {
        RivGeoMechPartMgr*  partMgr = m_partMgrCache->partMgr(visiblePartMgrs[pmIdx]);
        partMgr->updateCellResultColor(timeStepIndex, cellResultColors);
    }

}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivGeoMechVizLogic::appendPartsToModel(int timeStepIndex, cvf::ModelBasicList* model)
{
    std::vector<RivGeoMechPartMgrCache::Key> visiblePartMgrs = keysToVisiblePartMgrs(timeStepIndex);
    for (size_t pmIdx = 0; pmIdx < visiblePartMgrs.size(); ++pmIdx)
    {
        RivGeoMechPartMgr*  partMgr = getUpdatedPartMgr(visiblePartMgrs[pmIdx]);

        partMgr->appendGridPartsToModel(model);
    }

}