From 1e65a9db114e16e0da6cf8a876f7fd854c823798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Sat, 14 Dec 2013 09:26:34 +0100 Subject: [PATCH] NNC: Added NNCGeometryGenerator --- .../ModelVisualization/CMakeLists_files.cmake | 2 + .../RivNNCGeometryGenerator.cpp | 177 ++++++++++++++++++ .../RivNNCGeometryGenerator.h | 70 +++++++ 3 files changed, 249 insertions(+) create mode 100644 ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp create mode 100644 ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.h diff --git a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake index f8fe538d97..53b7f0d2db 100644 --- a/ApplicationCode/ModelVisualization/CMakeLists_files.cmake +++ b/ApplicationCode/ModelVisualization/CMakeLists_files.cmake @@ -9,6 +9,7 @@ ${CEE_CURRENT_LIST_DIR}RivCellEdgeEffectGenerator.h ${CEE_CURRENT_LIST_DIR}RivColorTableArray.h ${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.h ${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.h +${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.h ${CEE_CURRENT_LIST_DIR}RivGridPartMgr.h ${CEE_CURRENT_LIST_DIR}RivReservoirPartMgr.h ${CEE_CURRENT_LIST_DIR}RivReservoirViewPartMgr.h @@ -26,6 +27,7 @@ ${CEE_CURRENT_LIST_DIR}RivCellEdgeEffectGenerator.cpp ${CEE_CURRENT_LIST_DIR}RivColorTableArray.cpp ${CEE_CURRENT_LIST_DIR}RivFaultPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivFaultGeometryGenerator.cpp +${CEE_CURRENT_LIST_DIR}RivNNCGeometryGenerator.cpp ${CEE_CURRENT_LIST_DIR}RivGridPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivReservoirFaultsPartMgr.cpp ${CEE_CURRENT_LIST_DIR}RivReservoirPartMgr.cpp diff --git a/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp new file mode 100644 index 0000000000..01156defd6 --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp @@ -0,0 +1,177 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RivNNCGeometryGenerator.h" + +#include + +#include "cvfDrawableGeo.h" +#include "cvfPrimitiveSetIndexedUInt.h" +#include "cvfScalarMapper.h" +#include "RigNNCData.h" +#include "RigCell.h" +#include "RigMainGrid.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RivNNCGeometryGenerator::RivNNCGeometryGenerator(const RigNNCData* nncData, const cvf::Vec3d& offset, const cvf::Array* nncIndexes ) + : m_nncData(nncData), + m_nncIndexes(nncIndexes), + m_offset(offset) +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RivNNCGeometryGenerator::~RivNNCGeometryGenerator() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// Generate surface drawable geo from the specified region +//-------------------------------------------------------------------------------------------------- +cvf::ref RivNNCGeometryGenerator::generateSurface() +{ + computeArrays(); + + CVF_ASSERT(m_vertices.notNull()); + + if (m_vertices->size() == 0) return NULL; + + cvf::ref geo = new cvf::DrawableGeo; + geo->setFromTriangleVertexArray(m_vertices.p()); + + return geo; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivNNCGeometryGenerator::computeArrays() +{ + std::vector vertices; + std::vector triangleToNNC; + + const cvf::Vec3d offset = m_offset; + long long numConnections = static_cast(m_nncIndexes.isNull()? m_nncData->connections().size(): m_nncIndexes->size()); + + bool isVisibilityCalcActive = m_cellVisibility.notNull() && m_grid.notNull(); + std::vector* allCells = NULL; + if (isVisibilityCalcActive) + { + allCells = &(m_grid->mainGrid()->cells()); + } + +#pragma omp parallel for ordered + for (long long nIdx = 0; nIdx < numConnections; ++nIdx) + { + size_t conIdx = m_nncIndexes.isNull()? nIdx: (*m_nncIndexes)[nIdx]; + + const RigConnection& conn = m_nncData->connections()[conIdx]; + + if (conn.m_polygon.size()) + { + bool isVisible = true; + if (isVisibilityCalcActive) + { + size_t cell1GridLocalIdx = (*allCells)[conn.m_c1GlobIdx].cellIndex(); + size_t cell2GridLocalIdx = (*allCells)[conn.m_c1GlobIdx].cellIndex(); + isVisible = ((*m_cellVisibility)[cell1GridLocalIdx] || (*m_cellVisibility)[cell2GridLocalIdx]); + } + + if (isVisible) + { + cvf::Vec3f vx1 = cvf::Vec3f(conn.m_polygon[0] - offset); + cvf::Vec3f vx2; + cvf::Vec3f vx3 = cvf::Vec3f(conn.m_polygon[1] - offset); + + for (size_t vxIdx = 2; vxIdx < conn.m_polygon.size() ; ++vxIdx) + { + vx2 = vx3; + vx3 = cvf::Vec3f( conn.m_polygon[vxIdx] - offset); +#pragma omp critical + { + vertices.push_back(vx1); + vertices.push_back(vx2); + vertices.push_back(vx3); + triangleToNNC.push_back(conIdx); + } + } + } + } + } + + m_vertices = new cvf::Vec3fArray; + m_vertices->assign(vertices); + m_triangleIndexToNNCIndex = new cvf::Array; + m_triangleIndexToNNCIndex->assign(triangleToNNC); +} + +//-------------------------------------------------------------------------------------------------- +/// Calculates the texture coordinates in a "nearly" one dimensional texture. +/// Undefined values are coded with a y-texture coordinate value of 1.0 instead of the normal 0.5 +//-------------------------------------------------------------------------------------------------- +void RivNNCGeometryGenerator::textureCoordinates(cvf::Vec2fArray* textureCoords, const cvf::ScalarMapper* mapper) const +{ + size_t numVertices = m_vertices->size(); + + textureCoords->resize(numVertices); + cvf::Vec2f* rawPtr = textureCoords->ptr(); + + double cellScalarValue; + cvf::Vec2f texCoord; + +#pragma omp parallel for private(texCoord, cellScalarValue) + for (int tIdx = 0; tIdx < static_cast(m_triangleIndexToNNCIndex->size()); tIdx++) + { + cellScalarValue = m_nncData->connections()[(*m_triangleIndexToNNCIndex)[tIdx]].m_transmissibility; + texCoord = mapper->mapToTextureCoord(cellScalarValue); + if (cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue) // a != a is true for NAN's + { + texCoord[1] = 1.0f; + } + + size_t j; + for (j = 0; j < 3; j++) + { + rawPtr[tIdx*3 + j] = texCoord; + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivNNCGeometryGenerator::setCellVisibility(const cvf::UByteArray* cellVisibility, const RigGridBase * grid) +{ + m_cellVisibility = cellVisibility; + m_grid = grid; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref > RivNNCGeometryGenerator::triangleToNNCIndex() const +{ + return m_triangleIndexToNNCIndex; +} + diff --git a/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.h b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.h new file mode 100644 index 0000000000..ec58e9041b --- /dev/null +++ b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.h @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfArray.h" + +namespace cvf +{ + class ScalarMapper; + class DrawableGeo; +} + +class RigNNCData; +class RigGridBase; + +//================================================================================================== +/// +/// +//================================================================================================== + +class RivNNCGeometryGenerator : public cvf::Object +{ +public: + RivNNCGeometryGenerator(const RigNNCData* nncData, const cvf::Vec3d& offset, const cvf::Array* nncIndexes ); + ~RivNNCGeometryGenerator(); + + void setCellVisibility( const cvf::UByteArray* cellVisibilities, const RigGridBase * grid); + + void textureCoordinates(cvf::Vec2fArray* textureCoords, + const cvf::ScalarMapper* mapper) const; + + // Mapping between cells and geometry + cvf::ref > triangleToNNCIndex() const; + + // Generated geometry + cvf::ref generateSurface(); + +private: + void computeArrays(); + +private: + // Input + cvf::cref m_nncData; + cvf::cref> m_nncIndexes; + cvf::cref m_cellVisibility; + cvf::cref m_grid; + cvf::Vec3d m_offset; + // Triangles + cvf::ref m_vertices; + + // Mappings + cvf::ref > m_triangleIndexToNNCIndex; +};