Files
ResInsight/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h

230 lines
8.5 KiB
C
Raw Normal View History

//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfArray.h"
#include "cvfCollection.h"
2020-06-19 07:53:59 +02:00
#include "cvfObject.h"
#include "cvfStructGrid.h"
2020-06-19 07:53:59 +02:00
namespace cvf
{
class DrawableGeo;
class ScalarMapper;
class StructGridScalarDataAccess;
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
class CellRangeFilter
{
public:
CellRangeFilter();
2020-06-19 07:53:59 +02:00
void addCellIncludeRange( size_t minI, size_t minJ, size_t minK, size_t maxI, size_t maxJ, size_t maxK, bool applyToSubGridAreas );
void addCellInclude( size_t i, size_t j, size_t k, bool applyToSubGridAreas );
2020-06-19 07:53:59 +02:00
void addCellExcludeRange( size_t minI, size_t minJ, size_t minK, size_t maxI, size_t maxJ, size_t maxK, bool applyToSubGridAreas );
void addCellExclude( size_t i, size_t j, size_t k, bool applyToSubGridAreas );
2020-06-19 07:53:59 +02:00
bool isCellVisible( size_t i, size_t j, size_t k, bool isInSubGridArea ) const;
bool isCellExcluded( size_t i, size_t j, size_t k, bool isInSubGridArea ) const;
2020-06-19 07:53:59 +02:00
bool hasIncludeRanges() const;
private:
class CellRange
{
public:
CellRange()
2020-06-19 07:53:59 +02:00
: m_min( cvf::Vec3st::ZERO )
, m_max( UNDEFINED_SIZE_T, UNDEFINED_SIZE_T, UNDEFINED_SIZE_T )
, m_applyToSubGridAreas( true )
{
}
2020-06-19 07:53:59 +02:00
CellRange( size_t minI, size_t minJ, size_t minK, size_t maxI, size_t maxJ, size_t maxK, bool applyToSubGridAreas )
: m_min( minI, minJ, minK )
, m_max( maxI, maxJ, maxK )
, m_applyToSubGridAreas( applyToSubGridAreas )
{
}
2020-06-19 07:53:59 +02:00
bool isInRange( size_t i, size_t j, size_t k, bool isInSubGridArea ) const
{
2020-06-19 07:53:59 +02:00
if ( isInSubGridArea && !m_applyToSubGridAreas ) return false;
cvf::Vec3st test( i, j, k );
int idx;
2020-06-19 07:53:59 +02:00
for ( idx = 0; idx < 3; idx++ )
{
2020-06-19 07:53:59 +02:00
if ( test[idx] < m_min[idx] || m_max[idx] <= test[idx] )
{
return false;
}
}
return true;
}
public:
cvf::Vec3st m_min;
cvf::Vec3st m_max;
2020-06-19 07:53:59 +02:00
bool m_applyToSubGridAreas;
};
private:
std::vector<CellRange> m_includeRanges;
std::vector<CellRange> m_excludeRanges;
};
//--------------------------------------------------------------------------------------------------
2020-06-19 07:53:59 +02:00
///
//--------------------------------------------------------------------------------------------------
class CellFaceVisibilityFilter
{
public:
2020-06-19 07:53:59 +02:00
virtual bool isFaceVisible( size_t i,
size_t j,
size_t k,
StructGridInterface::FaceType face,
const UByteArray* cellVisibility ) const = 0;
};
class StructGridQuadToCellFaceMapper : public Object
{
public:
2020-06-19 07:53:59 +02:00
size_t quadCount() const { return m_quadsToCells.size(); }
2020-06-19 07:53:59 +02:00
size_t cellIndex( size_t quadIdx ) const { return m_quadsToCells[quadIdx]; }
StructGridInterface::FaceType cellFace( size_t quadIdx ) const { return m_quadsToFace[quadIdx]; }
// Interface for building the mappings
2020-06-19 07:53:59 +02:00
std::vector<size_t>& quadToCellIndexMap() { return m_quadsToCells; }
std::vector<StructGridInterface::FaceType>& quadToCellFaceMap() { return m_quadsToFace; }
private:
2020-06-19 07:53:59 +02:00
std::vector<size_t> m_quadsToCells;
std::vector<StructGridInterface::FaceType> m_quadsToFace;
};
class StuctGridTriangleToCellFaceMapper : public Object
{
public:
2020-06-19 07:53:59 +02:00
explicit StuctGridTriangleToCellFaceMapper( const StructGridQuadToCellFaceMapper* quadMapper )
{
m_quadMapper = quadMapper;
}
size_t triangleCount() const { return 2 * m_quadMapper->quadCount(); }
2020-06-19 07:53:59 +02:00
size_t cellIndex( size_t triangleIdx ) const { return m_quadMapper->cellIndex( triangleIdx / 2 ); }
StructGridInterface::FaceType cellFace( size_t triangleIdx ) const
{
return m_quadMapper->cellFace( triangleIdx / 2 );
}
private:
cref<StructGridQuadToCellFaceMapper> m_quadMapper;
};
//==================================================================================================
//
2020-06-19 07:53:59 +02:00
//
//
//==================================================================================================
class StructGridGeometryGenerator : public Object
{
public:
2020-06-19 07:53:59 +02:00
explicit StructGridGeometryGenerator( const StructGridInterface* grid, bool useOpenMP );
~StructGridGeometryGenerator() override;
// Setup methods
2020-06-19 07:53:59 +02:00
void setCellVisibility( const UByteArray* cellVisibility );
void addFaceVisibilityFilter( const CellFaceVisibilityFilter* cellVisibilityFilter );
// Access, valid after generation is done
const StructGridInterface* activeGrid() { return m_grid.p(); }
2020-06-19 07:53:59 +02:00
void textureCoordinates( Vec2fArray* textureCoords,
const StructGridScalarDataAccess* resultAccessor,
const ScalarMapper* mapper ) const;
// Mapping between cells and geometry
2020-06-19 07:53:59 +02:00
const StructGridQuadToCellFaceMapper* quadToCellFaceMapper() { return m_quadMapper.p(); }
const StuctGridTriangleToCellFaceMapper* triangleToCellFaceMapper() { return m_triangleMapper.p(); }
// Generated geometry
2020-06-19 07:53:59 +02:00
ref<DrawableGeo> generateSurface();
ref<DrawableGeo> createMeshDrawable();
ref<DrawableGeo> createOutlineMeshDrawable( double creaseAngle );
2020-06-19 07:53:59 +02:00
static ref<DrawableGeo> createMeshDrawableFromSingleCell( const StructGridInterface* grid, size_t cellIndex );
2020-06-19 07:53:59 +02:00
static ref<DrawableGeo> createMeshDrawableFromSingleCell( const StructGridInterface* grid,
size_t cellIndex,
const cvf::Vec3d& displayModelOffset );
static ref<UIntArray> lineIndicesFromQuadVertexArray( const Vec3fArray* vertexArray );
private:
bool isCellFaceVisible( size_t i, size_t j, size_t k, StructGridInterface::FaceType face ) const;
2020-06-19 07:53:59 +02:00
void computeArrays();
private:
// Input
2020-06-19 07:53:59 +02:00
cref<StructGridInterface> m_grid; // The grid being processed
std::vector<const CellFaceVisibilityFilter*> m_cellVisibilityFilters;
cref<UByteArray> m_cellVisibility;
// Created arrays
2020-06-19 07:53:59 +02:00
cvf::ref<cvf::Vec3fArray> m_vertices;
// Mappings
2020-06-19 07:53:59 +02:00
ref<StructGridQuadToCellFaceMapper> m_quadMapper;
ref<StuctGridTriangleToCellFaceMapper> m_triangleMapper;
// Multiple treads can be used when building geometry data structures.
// This causes visual artifacts due to transparency algorithm, and a stable visual image
// can be produced if OpenMP is disabled. Currently used by regression test comparing images
bool m_useOpenMP;
};
2020-06-19 07:53:59 +02:00
} // namespace cvf