mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#166) More refactoring to support geomech cross sections
This commit is contained in:
parent
e593361b91
commit
fbfd6fd212
@ -31,10 +31,10 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionGeometryGenerator::RivCrossSectionGeometryGenerator(const std::vector<cvf::Vec3d> &polyline,
|
||||
const cvf::Vec3d& extrusionDirection,
|
||||
const RigMainGrid* grid)
|
||||
const RivCrossSectionHexGridIntf* grid)
|
||||
: m_polyLine(polyline),
|
||||
m_extrusionDirection(extrusionDirection),
|
||||
m_mainGrid(grid)
|
||||
m_hexGrid(grid)
|
||||
{
|
||||
m_triangleVxes = new cvf::Vec3fArray;
|
||||
m_cellBorderLineVxes = new cvf::Vec3fArray;
|
||||
@ -968,17 +968,15 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
|
||||
if (m_triangleVxes->size()) return;
|
||||
|
||||
m_extrusionDirection.normalize();
|
||||
std::vector<cvf::Vec3d> m_adjustedPolyline;
|
||||
|
||||
adjustPolyline();
|
||||
adjustPolyline(m_polyLine, m_extrusionDirection, &m_adjustedPolyline);
|
||||
|
||||
std::vector<cvf::Vec3f> triangleVertices;
|
||||
std::vector<cvf::Vec3f> cellBorderLineVxes;
|
||||
|
||||
EclipseCrossSectionGrid eclHexGrid(m_mainGrid.p());
|
||||
cvf::CrossSectionHexGridIntf* hexGrid = &eclHexGrid;
|
||||
|
||||
cvf::Vec3d displayOffset = hexGrid->displayOffset();
|
||||
cvf::BoundingBox gridBBox = hexGrid->boundingBox();
|
||||
cvf::Vec3d displayOffset = m_hexGrid->displayOffset();
|
||||
cvf::BoundingBox gridBBox = m_hexGrid->boundingBox();
|
||||
|
||||
size_t lineCount = m_adjustedPolyline.size();
|
||||
for (size_t lIdx = 0; lIdx < lineCount - 1; ++lIdx)
|
||||
@ -996,7 +994,7 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
|
||||
sectionBBox.add(p2 - m_extrusionDirection*maxSectionHeight);
|
||||
|
||||
std::vector<size_t> columnCellCandidates;
|
||||
hexGrid->findIntersectingCells(sectionBBox, &columnCellCandidates);
|
||||
m_hexGrid->findIntersectingCells(sectionBBox, &columnCellCandidates);
|
||||
|
||||
cvf::Plane plane;
|
||||
plane.setFromPoints(p1, p2, p2 + m_extrusionDirection*maxSectionHeight);
|
||||
@ -1018,11 +1016,11 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
|
||||
{
|
||||
size_t globalCellIdx = columnCellCandidates[cccIdx];
|
||||
|
||||
if (!hexGrid->useCell(globalCellIdx)) continue;
|
||||
if (!m_hexGrid->useCell(globalCellIdx)) continue;
|
||||
|
||||
hexPlaneCutTriangleVxes.clear();
|
||||
hexGrid->cellCornerVertices(globalCellIdx, cellCorners);
|
||||
hexGrid->cellCornerIndices(globalCellIdx, cornerIndices);
|
||||
m_hexGrid->cellCornerVertices(globalCellIdx, cellCorners);
|
||||
m_hexGrid->cellCornerIndices(globalCellIdx, cornerIndices);
|
||||
|
||||
int triangleCount = planeHexIntersectionMC(plane,
|
||||
cellCorners,
|
||||
@ -1142,69 +1140,50 @@ cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::createMeshDrawable(
|
||||
return geo;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Calculates the texture coordinates in a "nearly" one dimentional texture.
|
||||
/// Undefined values are coded with a y-texturecoordinate value of 1.0 instead of the normal 0.5
|
||||
/// Remove the lines from the polyline that is nearly parallel to the extrusion direction
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionGeometryGenerator::textureCoordinates(cvf::Vec2fArray* textureCoords,
|
||||
const RigResultAccessor* resultAccessor,
|
||||
const cvf::ScalarMapper* mapper) const
|
||||
void RivCrossSectionGeometryGenerator::adjustPolyline(const std::vector<cvf::Vec3d>& polyLine,
|
||||
const cvf::Vec3d extrDir,
|
||||
std::vector<cvf::Vec3d>* adjustedPolyline)
|
||||
{
|
||||
if (!resultAccessor) return;
|
||||
size_t lineCount = polyLine.size();
|
||||
if (!polyLine.size()) return;
|
||||
|
||||
size_t numVertices = m_triangleVxes->size();
|
||||
|
||||
textureCoords->resize(numVertices);
|
||||
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
||||
|
||||
double cellScalarValue;
|
||||
cvf::Vec2f texCoord;
|
||||
|
||||
int triangleCount = static_cast<int>(m_triangleToCellIdxMap.size());
|
||||
|
||||
#pragma omp parallel for private(texCoord, cellScalarValue)
|
||||
for (int tIdx = 0; tIdx < triangleCount; tIdx++)
|
||||
{
|
||||
cellScalarValue = resultAccessor->cellScalarGlobIdx(m_triangleToCellIdxMap[tIdx]);
|
||||
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 RivCrossSectionGeometryGenerator::adjustPolyline()
|
||||
{
|
||||
size_t lineCount = m_polyLine.size();
|
||||
if (!m_polyLine.size()) return;
|
||||
|
||||
m_adjustedPolyline.push_back(m_polyLine[0]);
|
||||
cvf::Vec3d p1 = m_polyLine[0];
|
||||
adjustedPolyline->push_back(polyLine[0]);
|
||||
cvf::Vec3d p1 = polyLine[0];
|
||||
|
||||
for (size_t lIdx = 1; lIdx < lineCount; ++lIdx)
|
||||
{
|
||||
cvf::Vec3d p2 = m_polyLine[lIdx];
|
||||
cvf::Vec3d p2 = polyLine[lIdx];
|
||||
cvf::Vec3d p1p2 = p2 - p1;
|
||||
|
||||
if ((p1p2 - (p1p2 * m_extrusionDirection)*m_extrusionDirection).length() > 0.1 )
|
||||
if ((p1p2 - (p1p2 * extrDir)*extrDir).length() > 0.1 )
|
||||
{
|
||||
m_adjustedPolyline.push_back(p2);
|
||||
adjustedPolyline->push_back(p2);
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<size_t>& RivCrossSectionGeometryGenerator::triangleToCellIndex() const
|
||||
{
|
||||
CVF_ASSERT(m_triangleVxes->size());
|
||||
return m_triangleToCellIdxMap;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<RivVertexWeights>& RivCrossSectionGeometryGenerator::triangleVxToCellCornerInterpolationWeights() const
|
||||
{
|
||||
CVF_ASSERT(m_triangleVxes->size());
|
||||
return m_triVxToCellCornerWeights;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -1213,7 +1192,7 @@ void RivCrossSectionGeometryGenerator::adjustPolyline()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
EclipseCrossSectionGrid::EclipseCrossSectionGrid(const RigMainGrid * mainGrid) : m_mainGrid(mainGrid)
|
||||
RivEclipseCrossSectionGrid::RivEclipseCrossSectionGrid(const RigMainGrid * mainGrid) : m_mainGrid(mainGrid)
|
||||
{
|
||||
|
||||
}
|
||||
@ -1221,7 +1200,7 @@ EclipseCrossSectionGrid::EclipseCrossSectionGrid(const RigMainGrid * mainGrid) :
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d EclipseCrossSectionGrid::displayOffset() const
|
||||
cvf::Vec3d RivEclipseCrossSectionGrid::displayOffset() const
|
||||
{
|
||||
return m_mainGrid->displayModelOffset();
|
||||
}
|
||||
@ -1229,7 +1208,7 @@ cvf::Vec3d EclipseCrossSectionGrid::displayOffset() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::BoundingBox EclipseCrossSectionGrid::boundingBox() const
|
||||
cvf::BoundingBox RivEclipseCrossSectionGrid::boundingBox() const
|
||||
{
|
||||
return m_mainGrid->boundingBox();
|
||||
}
|
||||
@ -1237,7 +1216,7 @@ cvf::BoundingBox EclipseCrossSectionGrid::boundingBox() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void EclipseCrossSectionGrid::findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const
|
||||
void RivEclipseCrossSectionGrid::findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const
|
||||
{
|
||||
m_mainGrid->findIntersectingCells(intersectingBB, intersectedCells);
|
||||
}
|
||||
@ -1245,7 +1224,7 @@ void EclipseCrossSectionGrid::findIntersectingCells(const cvf::BoundingBox& inte
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool EclipseCrossSectionGrid::useCell(size_t cellIndex) const
|
||||
bool RivEclipseCrossSectionGrid::useCell(size_t cellIndex) const
|
||||
{
|
||||
const RigCell& cell = m_mainGrid->cells()[cellIndex];
|
||||
|
||||
@ -1255,7 +1234,7 @@ bool EclipseCrossSectionGrid::useCell(size_t cellIndex) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void EclipseCrossSectionGrid::cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const
|
||||
void RivEclipseCrossSectionGrid::cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const
|
||||
{
|
||||
m_mainGrid->cellCornerVertices(cellIndex, cellCorners);
|
||||
}
|
||||
@ -1263,7 +1242,7 @@ void EclipseCrossSectionGrid::cellCornerVertices(size_t cellIndex, cvf::Vec3d ce
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void EclipseCrossSectionGrid::cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const
|
||||
void RivEclipseCrossSectionGrid::cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const
|
||||
{
|
||||
const caf::SizeTArray8& cornerIndicesSource = m_mainGrid->cells()[cellIndex].cornerIndices();
|
||||
memcpy(cornerIndices, cornerIndicesSource.data(), 8);
|
||||
|
@ -35,25 +35,24 @@ namespace cvf
|
||||
}
|
||||
|
||||
#include "cvfBoundingBox.h"
|
||||
namespace cvf {
|
||||
|
||||
class CrossSectionHexGridIntf : public Object
|
||||
|
||||
class RivCrossSectionHexGridIntf : public cvf::Object
|
||||
{
|
||||
public:
|
||||
virtual Vec3d displayOffset() const = 0;
|
||||
virtual BoundingBox boundingBox() const = 0;
|
||||
virtual void findIntersectingCells(const BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const = 0;
|
||||
virtual cvf::Vec3d displayOffset() const = 0;
|
||||
virtual cvf::BoundingBox boundingBox() const = 0;
|
||||
virtual void findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const = 0;
|
||||
virtual bool useCell(size_t cellIndex) const = 0;
|
||||
virtual void cellCornerVertices(size_t cellIndex, Vec3d cellCorners[8]) const = 0;
|
||||
virtual void cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const = 0;
|
||||
virtual void cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class EclipseCrossSectionGrid : public cvf::CrossSectionHexGridIntf
|
||||
class RivEclipseCrossSectionGrid : public RivCrossSectionHexGridIntf
|
||||
{
|
||||
public:
|
||||
EclipseCrossSectionGrid(const RigMainGrid * mainGrid);
|
||||
RivEclipseCrossSectionGrid(const RigMainGrid * mainGrid);
|
||||
|
||||
virtual cvf::Vec3d displayOffset() const;
|
||||
virtual cvf::BoundingBox boundingBox() const;
|
||||
@ -109,40 +108,32 @@ class RivCrossSectionGeometryGenerator : public cvf::Object
|
||||
public:
|
||||
RivCrossSectionGeometryGenerator(const std::vector<cvf::Vec3d> &polyline,
|
||||
const cvf::Vec3d& extrusionDirection,
|
||||
const RigMainGrid* grid );
|
||||
const RivCrossSectionHexGridIntf* grid );
|
||||
|
||||
~RivCrossSectionGeometryGenerator();
|
||||
|
||||
|
||||
void textureCoordinates(cvf::Vec2fArray* textureCoords,
|
||||
const RigResultAccessor* resultAccessor,
|
||||
const cvf::ScalarMapper* mapper) const;
|
||||
|
||||
// Mapping between cells and geometry
|
||||
const std::vector<size_t>& triangleToCellIndex() const;
|
||||
const std::vector<RivVertexWeights>& triangleVxToCellCornerInterpolationWeights() const;
|
||||
|
||||
// Generated geometry
|
||||
|
||||
// Generate geometry
|
||||
cvf::ref<cvf::DrawableGeo> generateSurface();
|
||||
cvf::ref<cvf::DrawableGeo> createMeshDrawable();
|
||||
|
||||
// Mapping between cells and geometry
|
||||
const std::vector<size_t>& triangleToCellIndex() const;
|
||||
const std::vector<RivVertexWeights>& triangleVxToCellCornerInterpolationWeights() const;
|
||||
|
||||
private:
|
||||
void calculateArrays();
|
||||
static void adjustPolyline(const std::vector<cvf::Vec3d>& polyLine,
|
||||
const cvf::Vec3d extrDir,
|
||||
std::vector<cvf::Vec3d>* adjustedPolyline);
|
||||
|
||||
|
||||
|
||||
void adjustPolyline();
|
||||
|
||||
cvf::cref<RigMainGrid> m_mainGrid;
|
||||
cvf::cref<RivCrossSectionHexGridIntf> m_hexGrid;
|
||||
std::vector<cvf::Vec3d> m_polyLine;
|
||||
cvf::Vec3d m_extrusionDirection;
|
||||
std::vector<cvf::Vec3d> m_adjustedPolyline;
|
||||
|
||||
// Output arrays
|
||||
cvf::ref<cvf::Vec3fArray> m_triangleVxes;
|
||||
cvf::ref<cvf::Vec3fArray> m_cellBorderLineVxes;
|
||||
std::vector<size_t> m_triangleToCellIdxMap;
|
||||
|
||||
std::vector<RivVertexWeights> m_triVxToCellCornerWeights;
|
||||
};
|
||||
|
||||
|
@ -45,7 +45,6 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionPartMgr::RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection)
|
||||
: m_rimCrossSection(rimCrossSection),
|
||||
m_grid(NULL),
|
||||
m_defaultColor(cvf::Color3::WHITE)
|
||||
{
|
||||
CVF_ASSERT(m_rimCrossSection);
|
||||
@ -113,7 +112,10 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEcli
|
||||
timeStepIndex,
|
||||
cellResultColors->resultVariable());
|
||||
|
||||
m_nativeCrossSectionGenerator->textureCoordinates(m_nativeCrossSectionFacesTextureCoords.p(), resultAccessor.p() ,mapper);
|
||||
calculateEclipseTextureCoordinates(m_nativeCrossSectionFacesTextureCoords.p(),
|
||||
m_nativeCrossSectionGenerator->triangleToCellIndex(),
|
||||
resultAccessor.p(),
|
||||
mapper);
|
||||
|
||||
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(m_nativeCrossSectionFaces.p(),
|
||||
@ -127,6 +129,45 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex, RimEcli
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Calculates the texture coordinates in a "nearly" one dimentional texture.
|
||||
/// Undefined values are coded with a y-texturecoordinate value of 1.0 instead of the normal 0.5
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords,
|
||||
const std::vector<size_t>& triangleToCellIdxMap,
|
||||
const RigResultAccessor* resultAccessor,
|
||||
const cvf::ScalarMapper* mapper) const
|
||||
{
|
||||
if (!resultAccessor) return;
|
||||
|
||||
size_t numVertices = triangleToCellIdxMap.size()*3;
|
||||
|
||||
textureCoords->resize(numVertices);
|
||||
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
||||
|
||||
double cellScalarValue;
|
||||
cvf::Vec2f texCoord;
|
||||
|
||||
int triangleCount = static_cast<int>(triangleToCellIdxMap.size());
|
||||
|
||||
#pragma omp parallel for private(texCoord, cellScalarValue)
|
||||
for (int tIdx = 0; tIdx < triangleCount; tIdx++)
|
||||
{
|
||||
cellScalarValue = resultAccessor->cellScalarGlobIdx(triangleToCellIdxMap[tIdx]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int priCrossSectionGeo = 1;
|
||||
const int priNncGeo = 2;
|
||||
const int priMesh = 3;
|
||||
@ -265,14 +306,15 @@ void RivCrossSectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* mod
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::computeData()
|
||||
{
|
||||
m_grid = mainGrid();
|
||||
CVF_ASSERT(m_grid.notNull());
|
||||
RigMainGrid* m_grid = mainGrid();
|
||||
CVF_ASSERT(m_grid);
|
||||
|
||||
std::vector< std::vector <cvf::Vec3d> > polyLine = m_rimCrossSection->polyLines();
|
||||
if (polyLine.size() > 0)
|
||||
{
|
||||
cvf::Vec3d direction = extrusionDirection(polyLine[0]);
|
||||
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine[0], direction, m_grid.p());
|
||||
cvf::ref<RivEclipseCrossSectionGrid> eclHexGrid = new RivEclipseCrossSectionGrid(m_grid);
|
||||
m_nativeCrossSectionGenerator = new RivCrossSectionGeometryGenerator(polyLine[0], direction, eclHexGrid.p());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,10 +62,9 @@ private:
|
||||
|
||||
RigMainGrid* mainGrid();
|
||||
cvf::Vec3d extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const;
|
||||
|
||||
void calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, const std::vector<size_t>& triangleToCellIdxMap, const RigResultAccessor* resultAccessor, const cvf::ScalarMapper* mapper) const;
|
||||
private:
|
||||
|
||||
cvf::cref<RigMainGrid> m_grid;
|
||||
const RimCrossSection* m_rimCrossSection;
|
||||
|
||||
cvf::Color3f m_defaultColor;
|
||||
|
Loading…
Reference in New Issue
Block a user