Created StructGrid...ToCellFaceMapper

Done to start refactoring to pave way for many new combined result
properties
This commit is contained in:
Jacob Støren 2014-06-24 17:19:30 +02:00 committed by Magne Sjaastad
parent 549e61af77
commit 710395bb85
11 changed files with 203 additions and 230 deletions

View File

@ -78,8 +78,7 @@ void RivCellEdgeGeometryGenerator::addCellEdgeResultsToDrawableGeo(
size_t gridIndex,
float opacityLevel)
{
const std::vector<size_t>& quadToCell = generator->quadToGridCellIndices();
const std::vector<cvf::StructGridInterface::FaceType>& 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;

View File

@ -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<cvf::UIntArray> RivFaultGeometryGenerator::lineIndicesFromQuadVertexArr
void RivFaultGeometryGenerator::computeArrays()
{
std::vector<cvf::Vec3f> 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<int>(m_quadsToGridCells.size()); i++)
for (int i = 0; i < static_cast<int>(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<cvf::Array<size_t> > RivFaultGeometryGenerator::triangleToSourceGridCellMap() const
{
cvf::ref<cvf::Array<size_t> > triangles = new cvf::Array<size_t>(2*m_quadsToGridCells.size());
#pragma omp parallel for
for (int i = 0; i < static_cast<int>(m_quadsToGridCells.size()); i++)
{
triangles->set(i*2, m_quadsToGridCells[i]);
triangles->set(i*2+1, m_quadsToGridCells[i]);
}
return triangles;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> > RivFaultGeometryGenerator::triangleToFaceType() const
{
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> > triangles = new cvf::Array<cvf::StructGridInterface::FaceType>(2*m_quadsToFace.size());
#pragma omp parallel for
for (int i = 0; i < static_cast<int>(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<size_t>& RivFaultGeometryGenerator::quadToGridCellIndices() const
{
return m_quadsToGridCells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<cvf::StructGridInterface::FaceType>& RivFaultGeometryGenerator::quadToFace() const
{
return m_quadsToFace;
}

View File

@ -52,11 +52,9 @@ public:
const cvf::ScalarMapper* mapper) const;
// Mapping between cells and geometry
cvf::ref<cvf::Array<size_t> > triangleToSourceGridCellMap() const;
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> > triangleToFaceType() const;
const std::vector<size_t>& quadToGridCellIndices() const;
const std::vector<cvf::StructGridInterface::FaceType>& quadToFace() const;
const cvf::StructGridQuadToCellFaceMapper * cellFromQuadMapper() { return m_quadMapper.p(); }
const cvf::StuctGridTriangleToCellFaceMapper * cellFromTriangleMapper() { return m_triangleMapper.p(); }
// Generated geometry
cvf::ref<cvf::DrawableGeo> generateSurface();
@ -70,18 +68,19 @@ private:
private:
// Input
cvf::cref<cvf::StructGridInterface> m_grid;
cvf::cref<RigFault> m_fault;
cvf::cref<cvf::UByteArray> m_cellVisibility;
cvf::cref<cvf::StructGridInterface> m_grid;
cvf::cref<RigFault> m_fault;
cvf::cref<cvf::UByteArray> m_cellVisibility;
bool m_computeNativeFaultFaces;
bool m_computeNativeFaultFaces;
// Created arrays
cvf::ref<cvf::Vec3fArray> m_vertices;
cvf::ref<cvf::Vec3fArray> m_vertices;
// Mappings
std::vector<size_t> m_triangleIndexToGridCellIndex;
std::vector<size_t> m_quadsToGridCells;
std::vector<size_t> m_quadsToGridCells;
std::vector<cvf::StructGridInterface::FaceType> m_quadsToFace;
std::vector<cvf::StructGridInterface::FaceType> m_triangleToFace;
cvf::ref<cvf::StructGridQuadToCellFaceMapper> m_quadMapper;
cvf::ref<cvf::StuctGridTriangleToCellFaceMapper> m_triangleMapper;
};

View File

@ -126,17 +126,15 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
{
surfaceFacesColorArray = new cvf::Color3ubArray;
const std::vector<size_t>& 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<cvf::StructGridInterface::FaceType>& quadsToFaceTypes = m_nativeFaultGenerator->quadToFace();
const std::vector<size_t>& 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
{
@ -152,14 +150,15 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
{
const std::vector<cvf::ubyte>& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex);
cvf::ref<cvf::UIntArray> gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex());
const std::vector<size_t>& 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)
{
@ -202,17 +201,13 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
{
surfaceFacesColorArray = new cvf::Color3ubArray;
const std::vector<size_t>& 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<cvf::StructGridInterface::FaceType>& quadsToFaceTypes = m_oppositeFaultGenerator->quadToFace();
const std::vector<size_t>& 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
{
@ -228,14 +223,14 @@ void RivFaultPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot*
{
const std::vector<cvf::ubyte>& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex);
cvf::ref<cvf::UIntArray> gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex());
const std::vector<size_t>& 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)
{
@ -311,8 +306,7 @@ void RivFaultPartMgr::generatePartGeometry()
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> 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();
@ -365,8 +359,7 @@ void RivFaultPartMgr::generatePartGeometry()
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> 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();

View File

@ -123,8 +123,8 @@ void RivGridPartMgr::generatePartGeometry(cvf::StructGridGeometryGenerator& geoB
// Set mapping from triangle face index to cell index
cvf::ref<RivSourceInfo> 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<size_t>& 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<cvf::StructGridInterface::FaceType>& quadsToFaceTypes = m_surfaceGenerator.quadToFace();
const std::vector<size_t>& 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<cvf::ubyte>& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex);
cvf::ref<cvf::UIntArray> gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex());
const std::vector<size_t>& 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<cvf::ubyte>& isWellPipeVisible = cellResultSlot->reservoirView()->wellCollection()->isWellPipesVisible(timeStepIndex);
cvf::ref<cvf::UIntArray> gridCellToWellindexMap = eclipseCase->gridCellToWellIndex(m_grid->gridIndex());
const std::vector<size_t>& 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<cvf::Effect> RivGridPartMgr::createPerVertexColoringEffect(float opacit
void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordinates(RimResultSlot* cellResultSlot,
const RigGridBase* grid,
cvf::Vec2fArray* textureCoords,
const std::vector<cvf::StructGridInterface::FaceType>& quadsToFaceTypes,
const std::vector<size_t>& quadsToGridCells)
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper)
{
const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper();
if (!mapper) return;
@ -545,7 +540,8 @@ void RivTransmissibilityColorMapper::updateCombinedTransmissibilityTextureCoordi
cvf::ref<cvf::StructGridScalarDataAccess> dataAccessObjectTranZ = eclipseCase->dataAccessObject(grid, porosityModel, resTimeStepIdx, tranPosZScalarSetIndex);
size_t numVertices = quadsToGridCells.size()*4;
int quadCount = static_cast<int>(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<int>(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<size_t>& 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<int>(quadsToGridCells.size()); idx++)
for (int quadIdx = 0; quadIdx < static_cast<int>(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);
}
}
}

View File

@ -49,15 +49,14 @@ public:
RimResultSlot* cellResultSlot,
const RigGridBase* grid,
cvf::Vec2fArray* textureCoords,
const std::vector<cvf::StructGridInterface::FaceType>& quadsToFaceTypes,
const std::vector<size_t>& quadsToGridCells);
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper);
static void updateTernarySaturationColorArray(
size_t timeStepIndex,
RimResultSlot* cellResultSlot,
const RigGridBase* grid,
cvf::Color3ubArray* colorArray,
const std::vector<size_t>& quadsToGridCells);
const cvf::StructGridQuadToCellFaceMapper* quadToCellFaceMapper);
};

View File

@ -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();
}
//--------------------------------------------------------------------------------------------------

View File

@ -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<cvf::Array<size_t> > m_cellIndices;
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> > m_faceTypes;
cvf::ref<cvf::Array<size_t> > m_NNCIndices;
cvf::cref<cvf::StuctGridTriangleToCellFaceMapper> m_cellFaceFromTriangleMapper;
cvf::ref<cvf::Array<size_t> > m_NNCIndices;
};

View File

@ -274,10 +274,10 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event)
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(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<const RivSourceInfo*>(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);

View File

@ -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<Vec3f> 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<int>(m_quadsToGridCells.size()); i++)
for (int i = 0; i < static_cast<int>(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<cvf::Array<size_t> > StructGridGeometryGenerator::triangleToSourceGridCellMap() const
{
ref<Array<size_t> > triangles = new Array<size_t>(2*m_quadsToGridCells.size());
#pragma omp parallel for
for (int i = 0; i < static_cast<int>(m_quadsToGridCells.size()); i++)
{
triangles->set(i*2, m_quadsToGridCells[i]);
triangles->set(i*2+1, m_quadsToGridCells[i]);
}
return triangles;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> > StructGridGeometryGenerator::triangleToFaceTypes() const
void StructGridGeometryGenerator::textureCoordinatesFromSingleFaceValues(Vec2fArray* textureCoords, const ScalarMapper* mapper, const CellFaceValueCalculator* dataAccessObject) const
{
ref<Array<cvf::StructGridInterface::FaceType> > triangles = new Array<cvf::StructGridInterface::FaceType>(2*m_quadsToFace.size());
#pragma omp parallel for
for (int i = 0; i < static_cast<int>(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<int>(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<size_t>& StructGridGeometryGenerator::quadToGridCellIndices() const
{
return m_quadsToGridCells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<StructGridInterface::FaceType>& StructGridGeometryGenerator::quadToFace() const
{
return m_quadsToFace;
}
} // namespace cvf

View File

@ -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<size_t>& quadToCellIndexMap() { return m_quadsToCells; }
std::vector<StructGridInterface::FaceType>& quadToCellFaceMap() { return m_quadsToFace; }
private:
std::vector<size_t> m_quadsToCells;
std::vector<StructGridInterface::FaceType> 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<StructGridQuadToCellFaceMapper> m_quadMapper;
};
//==================================================================================================
//
@ -145,16 +176,9 @@ public:
void textureCoordinates(Vec2fArray* textureCoords, const StructGridScalarDataAccess* dataAccessObject, const ScalarMapper* mapper) const;
// Mapping between cells and geometry
ref<cvf::Array<size_t> >
triangleToSourceGridCellMap() const;
cvf::ref<cvf::Array<cvf::StructGridInterface::FaceType> >
triangleToFaceTypes() const;
const std::vector<size_t>&
quadToGridCellIndices() const;
const std::vector<StructGridInterface::FaceType>&
quadToFace() const;
const StructGridQuadToCellFaceMapper * quadToCellFaceMapper() { return m_quadMapper.p(); }
const StuctGridTriangleToCellFaceMapper * triangleToCellFaceMapper() { return m_triangleMapper.p(); }
// Generated geometry
ref<DrawableGeo> generateSurface();
@ -176,11 +200,10 @@ private:
// Created arrays
cvf::ref<cvf::Vec3fArray> m_vertices;
// Mappings
std::vector<size_t> m_triangleIndexToGridCellIndex;
std::vector<size_t> m_quadsToGridCells;
std::vector<StructGridInterface::FaceType> m_quadsToFace;
ref<StructGridQuadToCellFaceMapper> m_quadMapper;
ref<StuctGridTriangleToCellFaceMapper> m_triangleMapper;
};
}