/////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) Statoil ASA
//  Copyright (C) Ceetron Solutions AS
//
//  ResInsight is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
//  WARRANTY; without even the implied warranty of MERCHANTABILITY or
//  FITNESS FOR A PARTICULAR PURPOSE.
//
//  See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
//  for more details.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "RiaDefines.h"

#include "cvfArray.h"
#include "cvfObject.h"

namespace cvf
{
class ScalarMapper;
class DrawableGeo;
} // namespace cvf

class RigNNCData;
class RigGridBase;
class RigEclipseResultAddress;

//==================================================================================================
///
///
//==================================================================================================

class RivNNCGeometryGenerator : public cvf::Object
{
public:
    RivNNCGeometryGenerator( bool includeAllan, RigNNCData* nncData, const cvf::Vec3d& offset, const std::vector<size_t>& nncIndexes );

    ~RivNNCGeometryGenerator() override;

    void setCellVisibility( const cvf::UByteArray* cellVisibilities, const RigGridBase* grid );

    void textureCoordinates( cvf::Vec2fArray*               textureCoords,
                             const cvf::ScalarMapper*       mapper,
                             RiaDefines::ResultCatType      resultType,
                             const RigEclipseResultAddress& resVarAddr,
                             size_t                         nativeTimeStepIndex ) const;

    // Mapping between cells and geometry
    cvf::ref<cvf::Array<size_t>> triangleToNNCIndex() const;

    // Generated geometry
    cvf::ref<cvf::DrawableGeo> generateSurface();

private:
    void computeArrays();

private:
    bool m_includeAllanDiagramGeometry;

    // Input
    cvf::ref<RigNNCData>       m_nncData;
    std::vector<size_t>        m_nncIndexes;
    cvf::cref<cvf::UByteArray> m_cellVisibility;
    cvf::cref<RigGridBase>     m_grid;
    cvf::Vec3d                 m_offset;
    // Triangles
    cvf::ref<cvf::Vec3fArray> m_vertices;

    // Mappings
    cvf::ref<cvf::Array<size_t>> m_triangleIndexToNNCIndex;
};
