From adeeae6a04ff11c3671c3734f2426125e43f60fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 24 Jun 2014 17:19:30 +0200 Subject: [PATCH] Created StructGrid...ToCellFaceMapper Done to start refactoring to pave way for many new combined result properties --- .../RivCellEdgeEffectGenerator.cpp | 13 +- .../RivFaultGeometryGenerator.cpp | 67 ++------- .../RivFaultGeometryGenerator.h | 23 ++-- .../ModelVisualization/RivFaultPartMgr.cpp | 33 ++--- .../ModelVisualization/RivGridPartMgr.cpp | 127 ++++++++++-------- .../ModelVisualization/RivGridPartMgr.h | 5 +- .../ModelVisualization/RivSourceInfo.cpp | 5 +- .../ModelVisualization/RivSourceInfo.h | 10 +- ApplicationCode/UserInterface/RiuViewer.cpp | 15 ++- .../cvfStructGridGeometryGenerator.cpp | 86 ++++++------ .../cvfStructGridGeometryGenerator.h | 49 +++++-- 11 files changed, 203 insertions(+), 230 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp b/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp index b2e37f55bc..a195179b51 100644 --- a/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp +++ b/ApplicationCode/ModelVisualization/RivCellEdgeEffectGenerator.cpp @@ -78,8 +78,7 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( size_t gridIndex, float opacityLevel) { - const std::vector& quadToCell = generator->quadToGridCellIndices(); - const std::vector& quadToFace = generator->quadToFace(); + const cvf::StructGridQuadToCellFaceMapper* quadToCellFace = generator->quadToCellFaceMapper(); size_t vertexCount = geo->vertexArray()->size(); size_t quadCount = vertexCount / 4; @@ -166,13 +165,13 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo( localCoords->set(quadIdx * 4 + 2, cvf::Vec2f(1, 1)); localCoords->set(quadIdx * 4 + 3, cvf::Vec2f(0, 1)); - faceIndexArray->set(quadIdx * 4 + 0, quadToFace[quadIdx] ); - faceIndexArray->set(quadIdx * 4 + 1, quadToFace[quadIdx] ); - faceIndexArray->set(quadIdx * 4 + 2, quadToFace[quadIdx] ); - faceIndexArray->set(quadIdx * 4 + 3, quadToFace[quadIdx] ); + faceIndexArray->set(quadIdx * 4 + 0, quadToCellFace->cellFace(quadIdx) ); + faceIndexArray->set(quadIdx * 4 + 1, quadToCellFace->cellFace(quadIdx) ); + faceIndexArray->set(quadIdx * 4 + 2, quadToCellFace->cellFace(quadIdx) ); + faceIndexArray->set(quadIdx * 4 + 3, quadToCellFace->cellFace(quadIdx) ); float cellColorTextureCoord = 0.5f; // If no results exists, the texture will have a special color - size_t cellIndex = quadToCell[quadIdx]; + size_t cellIndex = quadToCellFace->cellIndex(quadIdx); { double scalarValue = HUGE_VAL; diff --git a/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.cpp index 0a8b3efe2f..e9ed113620 100644 --- a/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.cpp +++ b/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.cpp @@ -24,6 +24,8 @@ #include "cvfPrimitiveSetIndexedUInt.h" #include "cvfOutlineEdgeExtractor.h" #include "cvfStructGridScalarDataAccess.h" +#include "cvfStructGridGeometryGenerator.h" + #include "cvfScalarMapper.h" #include "RigFault.h" @@ -38,6 +40,8 @@ RivFaultGeometryGenerator::RivFaultGeometryGenerator(const cvf::StructGridInterf m_fault(fault), m_computeNativeFaultFaces(computeNativeFaultFaces) { + m_quadMapper = new cvf::StructGridQuadToCellFaceMapper; + m_triangleMapper = new cvf::StuctGridTriangleToCellFaceMapper(m_quadMapper.p()); } //-------------------------------------------------------------------------------------------------- @@ -149,8 +153,8 @@ cvf::ref RivFaultGeometryGenerator::lineIndicesFromQuadVertexArr void RivFaultGeometryGenerator::computeArrays() { std::vector vertices; - m_quadsToGridCells.clear(); - m_quadsToFace.clear(); + m_quadMapper->quadToCellIndexMap().clear(); + m_quadMapper->quadToCellFaceMap().clear(); cvf::Vec3d offset = m_grid->displayModelOffset(); @@ -186,8 +190,8 @@ void RivFaultGeometryGenerator::computeArrays() } // Keep track of the source cell index per quad - m_quadsToGridCells.push_back(cellIndex); - m_quadsToFace.push_back(face); + m_quadMapper->quadToCellIndexMap().push_back(cellIndex); + m_quadMapper->quadToCellFaceMap().push_back(face); } } @@ -203,7 +207,7 @@ void RivFaultGeometryGenerator::textureCoordinates(cvf::Vec2fArray* textureCoord { if (!dataAccessObject) return; - size_t numVertices = m_quadsToGridCells.size()*4; + size_t numVertices = m_quadMapper->quadCount()*4; textureCoords->resize(numVertices); cvf::Vec2f* rawPtr = textureCoords->ptr(); @@ -212,9 +216,9 @@ void RivFaultGeometryGenerator::textureCoordinates(cvf::Vec2fArray* textureCoord cvf::Vec2f texCoord; #pragma omp parallel for private(texCoord, cellScalarValue) - for (int i = 0; i < static_cast(m_quadsToGridCells.size()); i++) + for (int i = 0; i < static_cast(m_quadMapper->quadCount()); i++) { - cellScalarValue = dataAccessObject->cellScalar(m_quadsToGridCells[i]); + cellScalarValue = dataAccessObject->cellScalar(m_quadMapper->cellIndex(i)); texCoord = mapper->mapToTextureCoord(cellScalarValue); if (cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue) // a != a is true for NAN's { @@ -229,38 +233,6 @@ void RivFaultGeometryGenerator::textureCoordinates(cvf::Vec2fArray* textureCoord } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref > RivFaultGeometryGenerator::triangleToSourceGridCellMap() const -{ - cvf::ref > triangles = new cvf::Array(2*m_quadsToGridCells.size()); -#pragma omp parallel for - for (int i = 0; i < static_cast(m_quadsToGridCells.size()); i++) - { - triangles->set(i*2, m_quadsToGridCells[i]); - triangles->set(i*2+1, m_quadsToGridCells[i]); - } - - return triangles; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref > RivFaultGeometryGenerator::triangleToFaceType() const -{ - cvf::ref > triangles = new cvf::Array(2*m_quadsToFace.size()); -#pragma omp parallel for - for (int i = 0; i < static_cast(m_quadsToFace.size()); i++) - { - triangles->set(i*2, m_quadsToFace[i]); - triangles->set(i*2+1, m_quadsToFace[i]); - } - - return triangles; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -268,20 +240,3 @@ void RivFaultGeometryGenerator::setCellVisibility(const cvf::UByteArray* cellVis { m_cellVisibility = cellVisibility; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& RivFaultGeometryGenerator::quadToGridCellIndices() const -{ - return m_quadsToGridCells; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& RivFaultGeometryGenerator::quadToFace() const -{ - return m_quadsToFace; -} - diff --git a/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.h b/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.h index 43329a408d..81162a67c7 100644 --- a/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.h +++ b/ApplicationCode/ModelVisualization/RivFaultGeometryGenerator.h @@ -52,11 +52,9 @@ public: const cvf::ScalarMapper* mapper) const; // Mapping between cells and geometry - cvf::ref > triangleToSourceGridCellMap() const; - cvf::ref > triangleToFaceType() const; - const std::vector& quadToGridCellIndices() const; - const std::vector& quadToFace() const; + const cvf::StructGridQuadToCellFaceMapper * cellFromQuadMapper() { return m_quadMapper.p(); } + const cvf::StuctGridTriangleToCellFaceMapper * cellFromTriangleMapper() { return m_triangleMapper.p(); } // Generated geometry cvf::ref generateSurface(); @@ -70,18 +68,19 @@ private: private: // Input - cvf::cref m_grid; - cvf::cref m_fault; - cvf::cref m_cellVisibility; + cvf::cref m_grid; + cvf::cref m_fault; + cvf::cref m_cellVisibility; - bool m_computeNativeFaultFaces; + bool m_computeNativeFaultFaces; // Created arrays - cvf::ref m_vertices; + cvf::ref m_vertices; // Mappings - std::vector m_triangleIndexToGridCellIndex; - std::vector m_quadsToGridCells; + std::vector m_quadsToGridCells; std::vector m_quadsToFace; - std::vector m_triangleToFace; + + cvf::ref m_quadMapper; + cvf::ref m_triangleMapper; }; diff --git a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp index 33e3474d97..f9354a83b6 100644 --- a/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivFaultPartMgr.cpp @@ -126,17 +126,15 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { surfaceFacesColorArray = new cvf::Color3ubArray; - const std::vector& quadsToGridCells = m_nativeFaultGenerator->quadToGridCellIndices(); - - RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), quadsToGridCells); + RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), + surfaceFacesColorArray.p(), m_nativeFaultGenerator->cellFromQuadMapper()); } else if (cellResultSlot->resultVariable().compare(RimDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive) == 0) { - const std::vector& quadsToFaceTypes = m_nativeFaultGenerator->quadToFace(); - const std::vector& quadsToGridCells = m_nativeFaultGenerator->quadToGridCellIndices(); cvf::Vec2fArray* textureCoords = m_nativeFaultFacesTextureCoords.p(); - RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, quadsToFaceTypes, quadsToGridCells); + RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, + m_nativeFaultGenerator->cellFromQuadMapper()); } else { @@ -150,14 +148,15 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { const std::vector& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex); cvf::ref gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex()); - const std::vector& quadsToGridCells = m_nativeFaultGenerator->quadToGridCellIndices(); + const cvf::StructGridQuadToCellFaceMapper* quadsToGridCells = m_nativeFaultGenerator->cellFromQuadMapper(); for(size_t i = 0; i < m_nativeFaultFacesTextureCoords->size(); ++i) { if ((*m_nativeFaultFacesTextureCoords)[i].y() == 1.0f) continue; // Do not touch undefined values size_t quadIdx = i/4; - size_t cellIndex = quadsToGridCells[quadIdx]; + size_t cellIndex = quadsToGridCells->cellIndex(quadIdx); + cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex); if (wellIndex != cvf::UNDEFINED_UINT) { @@ -200,17 +199,13 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { surfaceFacesColorArray = new cvf::Color3ubArray; - const std::vector& quadsToGridCells = m_oppositeFaultGenerator->quadToGridCellIndices(); - - RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), quadsToGridCells); + RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), m_oppositeFaultGenerator->cellFromQuadMapper()); } else if (cellResultSlot->resultVariable().compare(RimDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive) == 0) { - const std::vector& quadsToFaceTypes = m_oppositeFaultGenerator->quadToFace(); - const std::vector& quadsToGridCells = m_oppositeFaultGenerator->quadToGridCellIndices(); cvf::Vec2fArray* textureCoords = m_oppositeFaultFacesTextureCoords.p(); - RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, quadsToFaceTypes, quadsToGridCells); + RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, m_oppositeFaultGenerator->cellFromQuadMapper()); } else { @@ -224,14 +219,14 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { const std::vector& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex); cvf::ref gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex()); - const std::vector& quadsToGridCells = m_oppositeFaultGenerator->quadToGridCellIndices(); + const cvf::StructGridQuadToCellFaceMapper* quadsToGridCells = m_nativeFaultGenerator->cellFromQuadMapper(); for(size_t i = 0; i < m_oppositeFaultFacesTextureCoords->size(); ++i) { if ((*m_oppositeFaultFacesTextureCoords)[i].y() == 1.0f) continue; // Do not touch undefined values size_t quadIdx = i/4; - size_t cellIndex = quadsToGridCells[quadIdx]; + size_t cellIndex = quadsToGridCells->cellIndex(quadIdx); cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex); if (wellIndex != cvf::UNDEFINED_UINT) { @@ -307,8 +302,7 @@ void RivFaultPartMgr::generatePartGeometry() // Set mapping from triangle face index to cell index cvf::ref si = new RivSourceInfo; - si->m_cellIndices = m_nativeFaultGenerator->triangleToSourceGridCellMap().p(); - si->m_faceTypes = m_nativeFaultGenerator->triangleToFaceType().p(); + si->m_cellFaceFromTriangleMapper = m_nativeFaultGenerator->cellFromTriangleMapper(); part->setSourceInfo(si.p()); part->updateBoundingBox(); @@ -361,8 +355,7 @@ void RivFaultPartMgr::generatePartGeometry() // Set mapping from triangle face index to cell index cvf::ref si = new RivSourceInfo; - si->m_cellIndices = m_oppositeFaultGenerator->triangleToSourceGridCellMap().p(); - si->m_faceTypes = m_oppositeFaultGenerator->triangleToFaceType().p(); + si->m_cellFaceFromTriangleMapper = m_oppositeFaultGenerator->cellFromTriangleMapper(); part->setSourceInfo(si.p()); part->updateBoundingBox(); diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp index ddf67713c6..193571e2b8 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp @@ -123,8 +123,8 @@ void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoB // Set mapping from triangle face index to cell index cvf::ref si = new RivSourceInfo; - si->m_cellIndices = geoBuilder.triangleToSourceGridCellMap().p(); - si->m_faceTypes = geoBuilder.triangleToFaceTypes().p(); + si->m_cellFaceFromTriangleMapper = geoBuilder.triangleToCellFaceMapper(); + part->setSourceInfo(si.p()); part->updateBoundingBox(); @@ -269,17 +269,12 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { surfaceFacesColorArray = new cvf::Color3ubArray; - const std::vector& quadsToGridCells = m_surfaceGenerator.quadToGridCellIndices(); - - RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), quadsToGridCells); + RivTransmissibilityColorMapper::updateTernarySaturationColorArray(timeStepIndex, cellResultSlot, m_grid.p(), surfaceFacesColorArray.p(), m_surfaceGenerator.quadToCellFaceMapper()); } else if (cellResultSlot->resultVariable().compare(RimDefines::combinedTransmissibilityResultName(), Qt::CaseInsensitive) == 0) { - const std::vector& quadsToFaceTypes = m_surfaceGenerator.quadToFace(); - const std::vector& quadsToGridCells = m_surfaceGenerator.quadToGridCellIndices(); cvf::Vec2fArray* textureCoords = m_surfaceFacesTextureCoords.p(); - - RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, quadsToFaceTypes, quadsToGridCells); + RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(cellResultSlot, m_grid.p(), textureCoords, m_surfaceGenerator.quadToCellFaceMapper()); } else { @@ -304,14 +299,14 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { const std::vector& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex); cvf::ref gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex()); - const std::vector& quadsToGridCells = m_surfaceGenerator.quadToGridCellIndices(); + const cvf::StructGridQuadToCellFaceMapper* quadsToGridCells = m_surfaceGenerator.quadToCellFaceMapper(); for(size_t i = 0; i < m_surfaceFacesTextureCoords->size(); ++i) { if ((*m_surfaceFacesTextureCoords)[i].y() == 1.0f) continue; // Do not touch undefined values size_t quadIdx = i/4; - size_t cellIndex = quadsToGridCells[quadIdx]; + size_t cellIndex = quadsToGridCells->cellIndex(quadIdx); cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex); if (wellIndex != cvf::UNDEFINED_UINT) { @@ -373,14 +368,15 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* { const std::vector& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex); cvf::ref gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex()); - const std::vector& quadsToGridCells = m_faultGenerator.quadToGridCellIndices(); + const cvf::StructGridQuadToCellFaceMapper* quadsToGridCells = m_surfaceGenerator.quadToCellFaceMapper(); for(size_t i = 0; i < m_faultFacesTextureCoords->size(); ++i) { if ((*m_faultFacesTextureCoords)[i].y() == 1.0f) continue; // Do not touch undefined values size_t quadIdx = i/4; - size_t cellIndex = quadsToGridCells[quadIdx]; + size_t cellIndex = quadsToGridCells->cellIndex(quadIdx); + cvf::uint wellIndex = gridCellToWellindexMap->get(cellIndex); if (wellIndex != cvf::UNDEFINED_UINT) { @@ -520,8 +516,7 @@ cvf::ref RivGridPartMgr::createPerVertexColoringEffect(float opacit void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(RimResultSlot* cellResultSlot, const RigGridBase* grid, cvf::Vec2fArray* textureCoords, - const std::vector& quadsToFaceTypes, - const std::vector& quadsToGridCells) + const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper) { const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper(); if (!mapper) return; @@ -545,7 +540,8 @@ void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordi cvf::ref dataAccessObjectTranZ = eclipseCase->dataAccessObject(grid, porosityModel, resTimeStepIdx, tranPosZScalarSetIndex); - size_t numVertices = quadsToGridCells.size()*4; + int quadCount = static_cast(quadToCellFaceMapper->quadCount()); + size_t numVertices = quadCount*4; textureCoords->resize(numVertices); cvf::Vec2f* rawPtr = textureCoords->ptr(); @@ -554,53 +550,68 @@ void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordi cvf::Vec2f texCoord; #pragma omp parallel for private(texCoord, cellScalarValue) - for (int idx = 0; idx < static_cast(quadsToGridCells.size()); idx++) + for (int quadIdx = 0; quadIdx < quadCount; quadIdx++) { cellScalarValue = HUGE_VAL; - if (quadsToFaceTypes[idx] == cvf::StructGridInterface::POS_I) - { - cellScalarValue = dataAccessObjectTranX->cellScalar(quadsToGridCells[idx]); - } - else if (quadsToFaceTypes[idx] == cvf::StructGridInterface::NEG_I) - { - size_t i, j, k, neighborGridCellIdx; - grid->ijkFromCellIndex(quadsToGridCells[idx], &i, &j, &k); + size_t cellIndex = quadToCellFaceMapper->cellIndex(quadIdx); + cvf::StructGridInterface::FaceType cellFace = quadToCellFaceMapper->cellFace(quadIdx); - if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_I, &neighborGridCellIdx)) + switch (cellFace) + { + case cvf::StructGridInterface::POS_I: { - cellScalarValue = dataAccessObjectTranX->cellScalar(neighborGridCellIdx); + cellScalarValue = dataAccessObjectTranX->cellScalar(cellIndex); } - } - else if (quadsToFaceTypes[idx] == cvf::StructGridInterface::POS_J) - { - cellScalarValue = dataAccessObjectTranY->cellScalar(quadsToGridCells[idx]); - } - else if (quadsToFaceTypes[idx] == cvf::StructGridInterface::NEG_J) - { - size_t i, j, k, neighborGridCellIdx; - grid->ijkFromCellIndex(quadsToGridCells[idx], &i, &j, &k); + break; + case cvf::StructGridInterface::NEG_I: + { + size_t i, j, k, neighborGridCellIdx; + grid->ijkFromCellIndex(cellIndex, &i, &j, &k); - if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_J, &neighborGridCellIdx)) - { - cellScalarValue = dataAccessObjectTranY->cellScalar(neighborGridCellIdx); + if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_I, &neighborGridCellIdx)) + { + cellScalarValue = dataAccessObjectTranX->cellScalar(neighborGridCellIdx); + } } - } - else if (quadsToFaceTypes[idx] == cvf::StructGridInterface::POS_K) - { - cellScalarValue = dataAccessObjectTranZ->cellScalar(quadsToGridCells[idx]); - } - else if (quadsToFaceTypes[idx] == cvf::StructGridInterface::NEG_K) - { - size_t i, j, k, neighborGridCellIdx; - grid->ijkFromCellIndex(quadsToGridCells[idx], &i, &j, &k); + break; + case cvf::StructGridInterface::POS_J: + { + cellScalarValue = dataAccessObjectTranY->cellScalar(cellIndex); + } + break; + case cvf::StructGridInterface::NEG_J: + { + size_t i, j, k, neighborGridCellIdx; + grid->ijkFromCellIndex(cellIndex, &i, &j, &k); - if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_K, &neighborGridCellIdx)) - { - cellScalarValue = dataAccessObjectTranZ->cellScalar(neighborGridCellIdx); + if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_J, &neighborGridCellIdx)) + { + cellScalarValue = dataAccessObjectTranY->cellScalar(neighborGridCellIdx); + } } + break; + case cvf::StructGridInterface::POS_K: + { + cellScalarValue = dataAccessObjectTranZ->cellScalar(cellIndex); + } + break; + case cvf::StructGridInterface::NEG_K: + { + size_t i, j, k, neighborGridCellIdx; + grid->ijkFromCellIndex(cellIndex, &i, &j, &k); + + if(grid->cellIJKNeighbor(i, j, k, cvf::StructGridInterface::NEG_K, &neighborGridCellIdx)) + { + cellScalarValue = dataAccessObjectTranZ->cellScalar(neighborGridCellIdx); + } + } + break; + default: + CVF_ASSERT(false); } + texCoord = mapper->mapToTextureCoord(cellScalarValue); if (cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue) // a != a is true for NAN's { @@ -610,7 +621,7 @@ void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordi size_t j; for (j = 0; j < 4; j++) { - rawPtr[idx*4 + j] = texCoord; + rawPtr[quadIdx*4 + j] = texCoord; } } @@ -640,7 +651,9 @@ public: /// Loads ternary saturation results SOIL, SWAT and SGAS /// If any of these are not present, the values for a missing component is set to 0.0 //-------------------------------------------------------------------------------------------------- -void RivTransmissibilityColorMapper::updateTernarySaturationColorArray(size_t timeStepIndex, RimResultSlot* cellResultSlot, const RigGridBase* grid, cvf::Color3ubArray* colorArray, const std::vector& quadsToGridCells) +void RivTransmissibilityColorMapper::updateTernarySaturationColorArray(size_t timeStepIndex, RimResultSlot* cellResultSlot, + const RigGridBase* grid, cvf::Color3ubArray* colorArray, + const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper) { RimReservoirCellResultsStorage* gridCellResults = cellResultSlot->currentGridCellResults(); if (!gridCellResults) return; @@ -690,7 +703,7 @@ void RivTransmissibilityColorMapper::updateTernarySaturationColorArray(size_t ti double swatRange = swatMax - swatMin; double swatFactor = 255.0 / swatRange; - size_t numVertices = quadsToGridCells.size()*4; + size_t numVertices = quadToCellFaceMapper->quadCount()*4; colorArray->resize(numVertices); @@ -698,9 +711,9 @@ void RivTransmissibilityColorMapper::updateTernarySaturationColorArray(size_t ti double v, vNormalized; #pragma omp parallel for private(ternaryColorByte, v, vNormalized) - for (int idx = 0; idx < static_cast(quadsToGridCells.size()); idx++) + for (int quadIdx = 0; quadIdx < static_cast(quadToCellFaceMapper->quadCount()); quadIdx++) { - size_t gridCellIndex = quadsToGridCells[idx]; + size_t gridCellIndex = quadToCellFaceMapper->cellIndex(quadIdx); { v = dataAccessObjectSgas->cellScalar(gridCellIndex); @@ -729,7 +742,7 @@ void RivTransmissibilityColorMapper::updateTernarySaturationColorArray(size_t ti size_t j; for (j = 0; j < 4; j++) { - colorArray->set(idx*4 + j, ternaryColorByte); + colorArray->set(quadIdx*4 + j, ternaryColorByte); } } } diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.h b/ApplicationCode/ModelVisualization/RivGridPartMgr.h index d205256381..d866bd5f34 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.h @@ -49,15 +49,14 @@ public: RimResultSlot* cellResultSlot, const RigGridBase* grid, cvf::Vec2fArray* textureCoords, - const std::vector& quadsToFaceTypes, - const std::vector& quadsToGridCells); + const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper); static void updateTernarySaturationColorArray( size_t timeStepIndex, RimResultSlot* cellResultSlot, const RigGridBase* grid, cvf::Color3ubArray* colorArray, - const std::vector& quadsToGridCells); + const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper); }; diff --git a/ApplicationCode/ModelVisualization/RivSourceInfo.cpp b/ApplicationCode/ModelVisualization/RivSourceInfo.cpp index 9df69e03a9..1e67105cde 100644 --- a/ApplicationCode/ModelVisualization/RivSourceInfo.cpp +++ b/ApplicationCode/ModelVisualization/RivSourceInfo.cpp @@ -17,14 +17,15 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RivSourceInfo.h" +#include "cvfStructGridGeometryGenerator.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RivSourceInfo::hasCellIndices() const +bool RivSourceInfo::hasCellFaceMapping() const { - return m_cellIndices.notNull(); + return m_cellFaceFromTriangleMapper.notNull(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ModelVisualization/RivSourceInfo.h b/ApplicationCode/ModelVisualization/RivSourceInfo.h index de670c52a7..b4e5f1306c 100644 --- a/ApplicationCode/ModelVisualization/RivSourceInfo.h +++ b/ApplicationCode/ModelVisualization/RivSourceInfo.h @@ -21,17 +21,15 @@ #include "cvfBase.h" #include "cvfObject.h" #include "cvfArray.h" -#include "cvfStructGrid.h" +#include "cvfStructGridGeometryGenerator.h" class RivSourceInfo : public cvf::Object { public: - bool hasCellIndices() const; + bool hasCellFaceMapping() const; bool hasNNCIndices() const; public: - cvf::ref > m_cellIndices; - cvf::ref > m_faceTypes; - - cvf::ref > m_NNCIndices; + cvf::cref m_cellFaceFromTriangleMapper; + cvf::ref > m_NNCIndices; }; diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 354cc30af3..e58a7bb8a7 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -274,10 +274,10 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) const RivSourceInfo* rivSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); if (rivSourceInfo) { - if (rivSourceInfo->hasCellIndices()) + if (rivSourceInfo->hasCellFaceMapping()) { m_currentGridIdx = firstHitPart->id(); - m_currentCellIndex = rivSourceInfo->m_cellIndices->get(faceIndex); + m_currentCellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(faceIndex); QMenu menu; menu.addAction(QString("I-slice range filter"), this, SLOT(slotRangeFilterI())); @@ -436,13 +436,14 @@ void RiuViewer::handlePickAction(int winPosX, int winPosY) const RivSourceInfo* rivSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); if (rivSourceInfo) { - if (rivSourceInfo->hasCellIndices()) + if (rivSourceInfo->hasCellFaceMapping()) { - size_t cellIndex = cvf::UNDEFINED_SIZE_T; - cellIndex = rivSourceInfo->m_cellIndices->get(faceIndex); + CVF_ASSERT(rivSourceInfo->m_cellFaceFromTriangleMapper.notNull()); - CVF_ASSERT(rivSourceInfo->m_faceTypes.notNull()); - cvf::StructGridInterface::FaceType face = rivSourceInfo->m_faceTypes->get(faceIndex); + size_t cellIndex = cvf::UNDEFINED_SIZE_T; + cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex(faceIndex); + + cvf::StructGridInterface::FaceType face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace(faceIndex); m_reservoirView->pickInfo(gridIndex, cellIndex, face, localIntersectionPoint, &pickInfo); diff --git a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp index 977b451e63..a5dbdd0633 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp +++ b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp @@ -159,6 +159,8 @@ StructGridGeometryGenerator::StructGridGeometryGenerator(const StructGridInterfa : m_grid(grid) { CVF_ASSERT(grid); + m_quadMapper = new StructGridQuadToCellFaceMapper; + m_triangleMapper = new StuctGridTriangleToCellFaceMapper(m_quadMapper.p()); } @@ -309,8 +311,8 @@ bool StructGridGeometryGenerator::isCellFaceVisible(size_t i, size_t j, size_t k void StructGridGeometryGenerator::computeArrays() { std::vector vertices; - m_quadsToGridCells.clear(); - m_quadsToFace.clear(); + m_quadMapper->quadToCellIndexMap().clear(); + m_quadMapper->quadToCellFaceMap().clear(); cvf::Vec3d offset = m_grid->displayModelOffset(); @@ -362,8 +364,8 @@ void StructGridGeometryGenerator::computeArrays() } // Keep track of the source cell index per quad - m_quadsToGridCells.push_back(cellIndex); - m_quadsToFace.push_back(face); + m_quadMapper->quadToCellIndexMap().push_back(cellIndex); + m_quadMapper->quadToCellFaceMap().push_back(face); } } } @@ -385,7 +387,7 @@ void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, { if (!dataAccessObject) return; - size_t numVertices = m_quadsToGridCells.size()*4; + size_t numVertices = m_quadMapper->quadCount()*4; textureCoords->resize(numVertices); cvf::Vec2f* rawPtr = textureCoords->ptr(); @@ -394,9 +396,9 @@ void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, cvf::Vec2f texCoord; #pragma omp parallel for private(texCoord, cellScalarValue) - for (int i = 0; i < static_cast(m_quadsToGridCells.size()); i++) + for (int i = 0; i < static_cast(m_quadMapper->quadCount()); i++) { - cellScalarValue = dataAccessObject->cellScalar(m_quadsToGridCells[i]); + cellScalarValue = dataAccessObject->cellScalar(m_quadMapper->cellIndex(i)); texCoord = mapper->mapToTextureCoord(cellScalarValue); if (cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue) // a != a is true for NAN's { @@ -411,37 +413,43 @@ void StructGridGeometryGenerator::textureCoordinates(Vec2fArray* textureCoords, } } +#if 0 //-------------------------------------------------------------------------------------------------- /// -//-------------------------------------------------------------------------------------------------- -ref > StructGridGeometryGenerator::triangleToSourceGridCellMap() const -{ - ref > triangles = new Array(2*m_quadsToGridCells.size()); -#pragma omp parallel for - for (int i = 0; i < static_cast(m_quadsToGridCells.size()); i++) - { - triangles->set(i*2, m_quadsToGridCells[i]); - triangles->set(i*2+1, m_quadsToGridCells[i]); - } - - return triangles; -} - -//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref > StructGridGeometryGenerator::triangleToFaceTypes() const +void StructGridGeometryGenerator::textureCoordinatesFromSingleFaceValues(Vec2fArray* textureCoords, const ScalarMapper* mapper, const CellFaceValueCalculator* dataAccessObject) const { - ref > triangles = new Array(2*m_quadsToFace.size()); -#pragma omp parallel for - for (int i = 0; i < static_cast(m_quadsToFace.size()); i++) - { - triangles->set(i*2, m_quadsToFace[i]); - triangles->set(i*2+1, m_quadsToFace[i]); - } + if (!dataAccessObject) return; - return triangles; + textureCoords->resize(m_quadMapper->quadCount()*4); + + cvf::Vec2f* rawPtr = textureCoords->ptr(); + + double cellFaceValue; + cvf::Vec2f texCoord; + int quadCount = static_cast(m_quadMapper->quadCount()); + +#pragma omp parallel for private(texCoord, cellFaceValue) + for (int qIdx = 0; qIdx < quadCount; qIdx++) + { + cellFaceValue = dataAccessObject->cellFaceScalar(m_quadMapper->cellIndex(qIdx), m_quadMapper->faceType(qIdx)); + + texCoord = mapper->mapToTextureCoord(cellFaceValue); + + if (cellFaceValue == HUGE_VAL || cellFaceValue != cellFaceValue) // a != a is true for NAN's + { + texCoord[1] = 1.0f; + } + + size_t j; + for (j = 0; j < 4; j++) + { + rawPtr[qIdx*4 + j] = texCoord; + } + } } +#endif //-------------------------------------------------------------------------------------------------- /// @@ -451,21 +459,5 @@ void StructGridGeometryGenerator::setCellVisibility(const UByteArray* cellVisibi m_cellVisibility = cellVisibility; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& StructGridGeometryGenerator::quadToGridCellIndices() const -{ - return m_quadsToGridCells; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -const std::vector& StructGridGeometryGenerator::quadToFace() const -{ - return m_quadsToFace; -} - } // namespace cvf diff --git a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h index 9b95797a1d..32f0c2cafa 100644 --- a/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h +++ b/Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h @@ -121,6 +121,37 @@ public: }; +class StructGridQuadToCellFaceMapper : public Object +{ +public: + size_t quadCount() const { return m_quadsToCells.size();} + + 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 + std::vector& quadToCellIndexMap() { return m_quadsToCells; } + std::vector& quadToCellFaceMap() { return m_quadsToFace; } + +private: + std::vector m_quadsToCells; + std::vector m_quadsToFace; +}; + + +class StuctGridTriangleToCellFaceMapper : public Object +{ +public: + StuctGridTriangleToCellFaceMapper(const StructGridQuadToCellFaceMapper* quadMapper) { m_quadMapper = quadMapper; } + size_t triangleCount() const { return 2* m_quadMapper->quadCount();} + + 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 m_quadMapper; +}; + //================================================================================================== // @@ -145,16 +176,9 @@ public: void textureCoordinates(Vec2fArray* textureCoords, const StructGridScalarDataAccess* dataAccessObject, const ScalarMapper* mapper) const; // Mapping between cells and geometry - ref > - triangleToSourceGridCellMap() const; - - cvf::ref > - triangleToFaceTypes() const; - const std::vector& - quadToGridCellIndices() const; - const std::vector& - quadToFace() const; + const StructGridQuadToCellFaceMapper * quadToCellFaceMapper() { return m_quadMapper.p(); } + const StuctGridTriangleToCellFaceMapper * triangleToCellFaceMapper() { return m_triangleMapper.p(); } // Generated geometry ref generateSurface(); @@ -176,11 +200,10 @@ private: // Created arrays cvf::ref m_vertices; + // Mappings - std::vector m_triangleIndexToGridCellIndex; - std::vector m_quadsToGridCells; - std::vector m_quadsToFace; - + ref m_quadMapper; + ref m_triangleMapper; }; }