mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#815 Moved files to Intersections folder
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
# Use this workaround until we're on 2.8.3 on all platforms and can use CMAKE_CURRENT_LIST_DIR directly
|
||||
if (${CMAKE_VERSION} VERSION_GREATER "2.8.2")
|
||||
set(CEE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}/)
|
||||
endif()
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionGeometryGenerator.h
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionPartMgr.h
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionSourceInfo.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionGeometryGenerator.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionPartMgr.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RivCrossSectionSourceInfo.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
source_group( "ModelVisualization\\Intersections" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CEE_CURRENT_LIST_DIR}CMakeLists_files.cmake )
|
||||
@@ -0,0 +1,545 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RivCrossSectionGeometryGenerator.h"
|
||||
|
||||
#include "RigMainGrid.h"
|
||||
#include "RigResultAccessor.h"
|
||||
|
||||
#include "RimCrossSection.h"
|
||||
|
||||
#include "cafHexGridIntersectionTools/cafHexGridIntersectionTools.h"
|
||||
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfPrimitiveSetDirect.h"
|
||||
#include "cvfPrimitiveSetIndexedUInt.h"
|
||||
#include "cvfScalarMapper.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionGeometryGenerator::RivCrossSectionGeometryGenerator(const RimCrossSection* crossSection,
|
||||
std::vector<std::vector<cvf::Vec3d> > &polylines,
|
||||
const cvf::Vec3d& extrusionDirection,
|
||||
const RivCrossSectionHexGridIntf* grid)
|
||||
: m_crossSection(crossSection),
|
||||
m_polyLines(polylines),
|
||||
m_extrusionDirection(extrusionDirection),
|
||||
m_hexGrid(grid)
|
||||
{
|
||||
m_triangleVxes = new cvf::Vec3fArray;
|
||||
m_cellBorderLineVxes = new cvf::Vec3fArray;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionGeometryGenerator::~RivCrossSectionGeometryGenerator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionGeometryGenerator::calculateArrays()
|
||||
{
|
||||
if (m_triangleVxes->size()) return;
|
||||
|
||||
m_extrusionDirection.normalize();
|
||||
std::vector<cvf::Vec3f> triangleVertices;
|
||||
std::vector<cvf::Vec3f> cellBorderLineVxes;
|
||||
cvf::Vec3d displayOffset = m_hexGrid->displayOffset();
|
||||
cvf::BoundingBox gridBBox = m_hexGrid->boundingBox();
|
||||
|
||||
for (size_t pLineIdx = 0; pLineIdx < m_polyLines.size(); ++pLineIdx)
|
||||
{
|
||||
const std::vector<cvf::Vec3d>& m_polyLine = m_polyLines[pLineIdx];
|
||||
|
||||
if (m_polyLine.size() < 2) continue;
|
||||
|
||||
std::vector<cvf::Vec3d> m_adjustedPolyline;
|
||||
adjustPolyline(m_polyLine, m_extrusionDirection, &m_adjustedPolyline);
|
||||
|
||||
size_t lineCount = m_adjustedPolyline.size();
|
||||
for (size_t lIdx = 0; lIdx < lineCount - 1; ++lIdx)
|
||||
{
|
||||
cvf::Vec3d p1 = m_adjustedPolyline[lIdx];
|
||||
cvf::Vec3d p2 = m_adjustedPolyline[lIdx+1];
|
||||
|
||||
cvf::BoundingBox sectionBBox;
|
||||
sectionBBox.add(p1);
|
||||
sectionBBox.add(p2);
|
||||
double maxSectionHeight = gridBBox.radius();
|
||||
sectionBBox.add(p1 + m_extrusionDirection*maxSectionHeight);
|
||||
sectionBBox.add(p1 - m_extrusionDirection*maxSectionHeight);
|
||||
sectionBBox.add(p2 + m_extrusionDirection*maxSectionHeight);
|
||||
sectionBBox.add(p2 - m_extrusionDirection*maxSectionHeight);
|
||||
|
||||
std::vector<size_t> columnCellCandidates;
|
||||
m_hexGrid->findIntersectingCells(sectionBBox, &columnCellCandidates);
|
||||
|
||||
cvf::Plane plane;
|
||||
plane.setFromPoints(p1, p2, p2 + m_extrusionDirection*maxSectionHeight);
|
||||
|
||||
cvf::Plane p1Plane;
|
||||
p1Plane.setFromPoints(p1, p1 + m_extrusionDirection*maxSectionHeight, p1 + plane.normal());
|
||||
cvf::Plane p2Plane;
|
||||
p2Plane.setFromPoints(p2, p2 + m_extrusionDirection*maxSectionHeight, p2 - plane.normal());
|
||||
|
||||
|
||||
std::vector<caf::HexGridIntersectionTools::ClipVx> hexPlaneCutTriangleVxes;
|
||||
hexPlaneCutTriangleVxes.reserve(5*3);
|
||||
std::vector<bool> isTriangleEdgeCellContour;
|
||||
isTriangleEdgeCellContour.reserve(5*3);
|
||||
cvf::Vec3d cellCorners[8];
|
||||
size_t cornerIndices[8];
|
||||
|
||||
for (size_t cccIdx = 0; cccIdx < columnCellCandidates.size(); ++cccIdx)
|
||||
{
|
||||
size_t globalCellIdx = columnCellCandidates[cccIdx];
|
||||
|
||||
if (!m_hexGrid->useCell(globalCellIdx)) continue;
|
||||
|
||||
hexPlaneCutTriangleVxes.clear();
|
||||
m_hexGrid->cellCornerVertices(globalCellIdx, cellCorners);
|
||||
m_hexGrid->cellCornerIndices(globalCellIdx, cornerIndices);
|
||||
|
||||
caf::HexGridIntersectionTools::planeHexIntersectionMC(plane,
|
||||
cellCorners,
|
||||
cornerIndices,
|
||||
&hexPlaneCutTriangleVxes,
|
||||
&isTriangleEdgeCellContour);
|
||||
|
||||
std::vector<caf::HexGridIntersectionTools::ClipVx> clippedTriangleVxes;
|
||||
std::vector<bool> isClippedTriEdgeCellContour;
|
||||
|
||||
caf::HexGridIntersectionTools::clipTrianglesBetweenTwoParallelPlanes(hexPlaneCutTriangleVxes, isTriangleEdgeCellContour, p1Plane, p2Plane,
|
||||
&clippedTriangleVxes, &isClippedTriEdgeCellContour);
|
||||
|
||||
size_t clippedTriangleCount = clippedTriangleVxes.size()/3;
|
||||
|
||||
for (uint tIdx = 0; tIdx < clippedTriangleCount; ++tIdx)
|
||||
{
|
||||
uint triVxIdx = tIdx*3;
|
||||
|
||||
// Accumulate triangle vertices
|
||||
|
||||
cvf::Vec3f p0(clippedTriangleVxes[triVxIdx+0].vx - displayOffset);
|
||||
cvf::Vec3f p1(clippedTriangleVxes[triVxIdx+1].vx - displayOffset);
|
||||
cvf::Vec3f p2(clippedTriangleVxes[triVxIdx+2].vx - displayOffset);
|
||||
|
||||
triangleVertices.push_back(p0);
|
||||
triangleVertices.push_back(p1);
|
||||
triangleVertices.push_back(p2);
|
||||
|
||||
|
||||
// Accumulate mesh lines
|
||||
|
||||
if (isClippedTriEdgeCellContour[triVxIdx])
|
||||
{
|
||||
cellBorderLineVxes.push_back(p0);
|
||||
cellBorderLineVxes.push_back(p1);
|
||||
}
|
||||
if (isClippedTriEdgeCellContour[triVxIdx+1])
|
||||
{
|
||||
cellBorderLineVxes.push_back(p1);
|
||||
cellBorderLineVxes.push_back(p2);
|
||||
}
|
||||
if (isClippedTriEdgeCellContour[triVxIdx+2])
|
||||
{
|
||||
cellBorderLineVxes.push_back(p2);
|
||||
cellBorderLineVxes.push_back(p0);
|
||||
}
|
||||
|
||||
// Mapping to cell index
|
||||
|
||||
m_triangleToCellIdxMap.push_back(globalCellIdx);
|
||||
|
||||
// Interpolation from nodes
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
caf::HexGridIntersectionTools::ClipVx cvx = clippedTriangleVxes[triVxIdx + i];
|
||||
if (cvx.isVxIdsNative)
|
||||
{
|
||||
m_triVxToCellCornerWeights.push_back(
|
||||
RivVertexWeights(cvx.clippedEdgeVx1Id, cvx.clippedEdgeVx2Id, cvx.normDistFromEdgeVx1));
|
||||
}
|
||||
else
|
||||
{
|
||||
caf::HexGridIntersectionTools::ClipVx cvx1 = hexPlaneCutTriangleVxes[cvx.clippedEdgeVx1Id];
|
||||
caf::HexGridIntersectionTools::ClipVx cvx2 = hexPlaneCutTriangleVxes[cvx.clippedEdgeVx2Id];
|
||||
|
||||
m_triVxToCellCornerWeights.push_back(
|
||||
RivVertexWeights(cvx1.clippedEdgeVx1Id, cvx1.clippedEdgeVx2Id, cvx1.normDistFromEdgeVx1,
|
||||
cvx2.clippedEdgeVx1Id, cvx2.clippedEdgeVx2Id, cvx2.normDistFromEdgeVx1,
|
||||
cvx.normDistFromEdgeVx1));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_triangleVxes->assign(triangleVertices);
|
||||
m_cellBorderLineVxes->assign(cellBorderLineVxes);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Generate surface drawable geo from the specified region
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::generateSurface()
|
||||
{
|
||||
calculateArrays();
|
||||
|
||||
CVF_ASSERT(m_triangleVxes.notNull());
|
||||
|
||||
if (m_triangleVxes->size() == 0) return NULL;
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
geo->setFromTriangleVertexArray(m_triangleVxes.p());
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::createMeshDrawable()
|
||||
{
|
||||
if (!(m_cellBorderLineVxes.notNull() && m_cellBorderLineVxes->size() != 0)) return NULL;
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
geo->setVertexArray(m_cellBorderLineVxes.p());
|
||||
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetDirect> prim = new cvf::PrimitiveSetDirect(cvf::PT_LINES);
|
||||
prim->setIndexCount(m_cellBorderLineVxes->size());
|
||||
|
||||
geo->addPrimitiveSet(prim.p());
|
||||
return geo;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::createLineAlongPolylineDrawable()
|
||||
{
|
||||
std::vector<cvf::uint> lineIndices;
|
||||
std::vector<cvf::Vec3f> vertices;
|
||||
|
||||
cvf::Vec3d displayOffset = m_hexGrid->displayOffset();
|
||||
|
||||
for (size_t pLineIdx = 0; pLineIdx < m_polyLines.size(); ++pLineIdx)
|
||||
{
|
||||
const std::vector<cvf::Vec3d>& m_polyLine = m_polyLines[pLineIdx];
|
||||
if (m_polyLine.size() < 2) continue;
|
||||
|
||||
for (size_t i = 0; i < m_polyLine.size(); ++i)
|
||||
{
|
||||
vertices.push_back(cvf::Vec3f(m_polyLine[i] - displayOffset));
|
||||
if (i < m_polyLine.size() - 1)
|
||||
{
|
||||
lineIndices.push_back(static_cast<cvf::uint>(i));
|
||||
lineIndices.push_back(static_cast<cvf::uint>(i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vertices.size() == 0) return NULL;
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> vx = new cvf::Vec3fArray;
|
||||
vx->assign(vertices);
|
||||
cvf::ref<cvf::UIntArray> idxes = new cvf::UIntArray;
|
||||
idxes->assign(lineIndices);
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetIndexedUInt> prim = new cvf::PrimitiveSetIndexedUInt(cvf::PT_LINES);
|
||||
prim->setIndices(idxes.p());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> polylineGeo = new cvf::DrawableGeo;
|
||||
polylineGeo->setVertexArray(vx.p());
|
||||
polylineGeo->addPrimitiveSet(prim.p());
|
||||
|
||||
return polylineGeo;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RivCrossSectionGeometryGenerator::createPointsFromPolylineDrawable()
|
||||
{
|
||||
std::vector<cvf::Vec3f> vertices;
|
||||
|
||||
cvf::Vec3d displayOffset = m_hexGrid->displayOffset();
|
||||
|
||||
for (size_t pLineIdx = 0; pLineIdx < m_polyLines.size(); ++pLineIdx)
|
||||
{
|
||||
const std::vector<cvf::Vec3d>& m_polyLine = m_polyLines[pLineIdx];
|
||||
for (size_t i = 0; i < m_polyLine.size(); ++i)
|
||||
{
|
||||
vertices.push_back(cvf::Vec3f(m_polyLine[i] - displayOffset));
|
||||
}
|
||||
}
|
||||
|
||||
if (vertices.size() == 0) return NULL;
|
||||
|
||||
cvf::ref<cvf::PrimitiveSetDirect> primSet = new cvf::PrimitiveSetDirect(cvf::PT_POINTS);
|
||||
primSet->setStartIndex(0);
|
||||
primSet->setIndexCount(vertices.size());
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geo = new cvf::DrawableGeo;
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> vx = new cvf::Vec3fArray(vertices);
|
||||
geo->setVertexArray(vx.p());
|
||||
geo->addPrimitiveSet(primSet.p());
|
||||
|
||||
return geo;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Remove the lines from the polyline that is nearly parallel to the extrusion direction
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionGeometryGenerator::adjustPolyline(const std::vector<cvf::Vec3d>& polyLine,
|
||||
const cvf::Vec3d extrDir,
|
||||
std::vector<cvf::Vec3d>* adjustedPolyline)
|
||||
{
|
||||
size_t lineCount = polyLine.size();
|
||||
if (!polyLine.size()) return;
|
||||
|
||||
adjustedPolyline->push_back(polyLine[0]);
|
||||
cvf::Vec3d p1 = polyLine[0];
|
||||
|
||||
for (size_t lIdx = 1; lIdx < lineCount; ++lIdx)
|
||||
{
|
||||
cvf::Vec3d p2 = polyLine[lIdx];
|
||||
cvf::Vec3d p1p2 = p2 - p1;
|
||||
|
||||
if ((p1p2 - (p1p2 * extrDir)*extrDir).length() > 0.1 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RimCrossSection* RivCrossSectionGeometryGenerator::crossSection() const
|
||||
{
|
||||
return m_crossSection;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RivCrossSectionGeometryGenerator::isAnyGeometryPresent() const
|
||||
{
|
||||
if (m_triangleVxes->size() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "RigActiveCellInfo.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivEclipseCrossSectionGrid::RivEclipseCrossSectionGrid(const RigMainGrid * mainGrid,
|
||||
const RigActiveCellInfo* activeCellInfo,
|
||||
bool showInactiveCells)
|
||||
: m_mainGrid(mainGrid),
|
||||
m_activeCellInfo(activeCellInfo),
|
||||
m_showInactiveCells(showInactiveCells)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RivEclipseCrossSectionGrid::displayOffset() const
|
||||
{
|
||||
return m_mainGrid->displayModelOffset();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::BoundingBox RivEclipseCrossSectionGrid::boundingBox() const
|
||||
{
|
||||
return m_mainGrid->boundingBox();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivEclipseCrossSectionGrid::findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const
|
||||
{
|
||||
m_mainGrid->findIntersectingCells(intersectingBB, intersectedCells);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RivEclipseCrossSectionGrid::useCell(size_t cellIndex) const
|
||||
{
|
||||
const RigCell& cell = m_mainGrid->globalCellArray()[cellIndex];
|
||||
if (m_showInactiveCells)
|
||||
return !(cell.isInvalid() || (cell.subGrid() != NULL));
|
||||
else
|
||||
return m_activeCellInfo->isActive(cellIndex) && (cell.subGrid() == NULL);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivEclipseCrossSectionGrid::cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const
|
||||
{
|
||||
m_mainGrid->cellCornerVertices(cellIndex, cellCorners);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivEclipseCrossSectionGrid::cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const
|
||||
{
|
||||
const caf::SizeTArray8& cornerIndicesSource = m_mainGrid->globalCellArray()[cellIndex].cornerIndices();
|
||||
memcpy(cornerIndices, cornerIndicesSource.data(), 8);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "RigFemPart.h"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivFemCrossSectionGrid::RivFemCrossSectionGrid(const RigFemPart * femPart): m_femPart(femPart)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RivFemCrossSectionGrid::displayOffset() const
|
||||
{
|
||||
return cvf::Vec3d::ZERO;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::BoundingBox RivFemCrossSectionGrid::boundingBox() const
|
||||
{
|
||||
return m_femPart->boundingBox();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivFemCrossSectionGrid::findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const
|
||||
{
|
||||
m_femPart->findIntersectingCells(intersectingBB, intersectedCells);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RivFemCrossSectionGrid::useCell(size_t cellIndex) const
|
||||
{
|
||||
RigElementType elmType = m_femPart->elementType(cellIndex);
|
||||
|
||||
if (!(elmType == HEX8 || elmType == HEX8P)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivFemCrossSectionGrid::cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const
|
||||
{
|
||||
RigElementType elmType = m_femPart->elementType(cellIndex);
|
||||
if (!(elmType == HEX8 || elmType == HEX8P)) return ;
|
||||
|
||||
const std::vector<cvf::Vec3f>& nodeCoords = m_femPart->nodes().coordinates;
|
||||
const int* cornerIndices = m_femPart->connectivities(cellIndex);
|
||||
|
||||
cellCorners[0] = cvf::Vec3d(nodeCoords[cornerIndices[0]]);
|
||||
cellCorners[1] = cvf::Vec3d(nodeCoords[cornerIndices[1]]);
|
||||
cellCorners[2] = cvf::Vec3d(nodeCoords[cornerIndices[2]]);
|
||||
cellCorners[3] = cvf::Vec3d(nodeCoords[cornerIndices[3]]);
|
||||
cellCorners[4] = cvf::Vec3d(nodeCoords[cornerIndices[4]]);
|
||||
cellCorners[5] = cvf::Vec3d(nodeCoords[cornerIndices[5]]);
|
||||
cellCorners[6] = cvf::Vec3d(nodeCoords[cornerIndices[6]]);
|
||||
cellCorners[7] = cvf::Vec3d(nodeCoords[cornerIndices[7]]);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivFemCrossSectionGrid::cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const
|
||||
{
|
||||
RigElementType elmType = m_femPart->elementType(cellIndex);
|
||||
if (!(elmType == HEX8 || elmType == HEX8P)) return ;
|
||||
int elmIdx = static_cast<int>(cellIndex);
|
||||
cornerIndices[0] = m_femPart->elementNodeResultIdx(elmIdx, 0);
|
||||
cornerIndices[1] = m_femPart->elementNodeResultIdx(elmIdx, 1);
|
||||
cornerIndices[2] = m_femPart->elementNodeResultIdx(elmIdx, 2);
|
||||
cornerIndices[3] = m_femPart->elementNodeResultIdx(elmIdx, 3);
|
||||
cornerIndices[4] = m_femPart->elementNodeResultIdx(elmIdx, 4);
|
||||
cornerIndices[5] = m_femPart->elementNodeResultIdx(elmIdx, 5);
|
||||
cornerIndices[6] = m_femPart->elementNodeResultIdx(elmIdx, 6);
|
||||
cornerIndices[7] = m_femPart->elementNodeResultIdx(elmIdx, 7);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include "cvfArray.h"
|
||||
#include "cvfBase.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RigMainGrid;
|
||||
class RigActiveCellInfo;
|
||||
class RigResultAccessor;
|
||||
class RimCrossSection;
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ScalarMapper;
|
||||
class DrawableGeo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class RivCrossSectionHexGridIntf : public cvf::Object
|
||||
{
|
||||
public:
|
||||
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, cvf::Vec3d cellCorners[8]) const = 0;
|
||||
virtual void cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const = 0;
|
||||
};
|
||||
|
||||
|
||||
class RivEclipseCrossSectionGrid : public RivCrossSectionHexGridIntf
|
||||
{
|
||||
public:
|
||||
RivEclipseCrossSectionGrid(const RigMainGrid * mainGrid, const RigActiveCellInfo* activeCellInfo, bool showInactiveCells);
|
||||
|
||||
virtual cvf::Vec3d displayOffset() const;
|
||||
virtual cvf::BoundingBox boundingBox() const;
|
||||
virtual void findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const;
|
||||
virtual bool useCell(size_t cellIndex) const;
|
||||
virtual void cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const;
|
||||
virtual void cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const;
|
||||
|
||||
private:
|
||||
cvf::cref<RigMainGrid> m_mainGrid;
|
||||
cvf::cref<RigActiveCellInfo> m_activeCellInfo;
|
||||
bool m_showInactiveCells;
|
||||
};
|
||||
|
||||
class RigFemPart;
|
||||
|
||||
class RivFemCrossSectionGrid : public RivCrossSectionHexGridIntf
|
||||
{
|
||||
public:
|
||||
RivFemCrossSectionGrid(const RigFemPart * femPart);
|
||||
|
||||
virtual cvf::Vec3d displayOffset() const;
|
||||
virtual cvf::BoundingBox boundingBox() const;
|
||||
virtual void findIntersectingCells(const cvf::BoundingBox& intersectingBB, std::vector<size_t>* intersectedCells) const;
|
||||
virtual bool useCell(size_t cellIndex) const;
|
||||
virtual void cellCornerVertices(size_t cellIndex, cvf::Vec3d cellCorners[8]) const;
|
||||
virtual void cellCornerIndices(size_t cellIndex, size_t cornerIndices[8]) const;
|
||||
|
||||
private:
|
||||
cvf::cref<RigFemPart> m_femPart;
|
||||
};
|
||||
|
||||
class RivVertexWeights
|
||||
{
|
||||
public:
|
||||
explicit RivVertexWeights(size_t edge1Vx1, size_t edge1Vx2, double normDistFromE1V1,
|
||||
size_t edge2Vx1, size_t edge2Vx2, double normDistFromE2V1,
|
||||
double normDistFromE1Cut) : m_count(4)
|
||||
{
|
||||
m_vxIds[0] = (edge1Vx1);
|
||||
m_vxIds[1] = (edge1Vx2);
|
||||
m_vxIds[2] = (edge2Vx1);
|
||||
m_vxIds[3] = (edge2Vx2);
|
||||
|
||||
m_weights[0] = ((float)(1.0 - normDistFromE1V1 - normDistFromE1Cut + normDistFromE1V1*normDistFromE1Cut));
|
||||
m_weights[1] = ((float)(normDistFromE1V1 - normDistFromE1V1*normDistFromE1Cut));
|
||||
m_weights[2] = ((float)(normDistFromE1Cut - normDistFromE2V1*normDistFromE1Cut));
|
||||
m_weights[3] = ((float)(normDistFromE2V1*normDistFromE1Cut));
|
||||
}
|
||||
|
||||
explicit RivVertexWeights(size_t edge1Vx1, size_t edge1Vx2, double normDistFromE1V1) : m_count(2)
|
||||
{
|
||||
m_vxIds[0] = (edge1Vx1);
|
||||
m_vxIds[1] = (edge1Vx2);
|
||||
|
||||
m_weights[0] = ((float)(1.0 - normDistFromE1V1));
|
||||
m_weights[1] = ((float)(normDistFromE1V1));
|
||||
}
|
||||
|
||||
int size() const { return m_count;}
|
||||
size_t vxId(int idx) const { return m_vxIds[idx];}
|
||||
float weight(int idx)const { return m_weights[idx];}
|
||||
|
||||
private:
|
||||
|
||||
size_t m_vxIds[4];
|
||||
float m_weights[4];
|
||||
int m_count;
|
||||
};
|
||||
|
||||
class RivCrossSectionGeometryGenerator : public cvf::Object
|
||||
{
|
||||
public:
|
||||
RivCrossSectionGeometryGenerator(const RimCrossSection* crossSection,
|
||||
std::vector<std::vector<cvf::Vec3d> > &polylines,
|
||||
const cvf::Vec3d& extrusionDirection,
|
||||
const RivCrossSectionHexGridIntf* grid );
|
||||
|
||||
~RivCrossSectionGeometryGenerator();
|
||||
|
||||
bool isAnyGeometryPresent() const;
|
||||
|
||||
// Generate geometry
|
||||
cvf::ref<cvf::DrawableGeo> generateSurface();
|
||||
cvf::ref<cvf::DrawableGeo> createMeshDrawable();
|
||||
cvf::ref<cvf::DrawableGeo> createLineAlongPolylineDrawable();
|
||||
cvf::ref<cvf::DrawableGeo> createPointsFromPolylineDrawable();
|
||||
|
||||
// Mapping between cells and geometry
|
||||
const std::vector<size_t>& triangleToCellIndex() const;
|
||||
const std::vector<RivVertexWeights>& triangleVxToCellCornerInterpolationWeights() const;
|
||||
|
||||
const RimCrossSection* crossSection() const;
|
||||
|
||||
private:
|
||||
void calculateArrays();
|
||||
static void adjustPolyline(const std::vector<cvf::Vec3d>& polyLine,
|
||||
const cvf::Vec3d extrDir,
|
||||
std::vector<cvf::Vec3d>* adjustedPolyline);
|
||||
|
||||
cvf::cref<RivCrossSectionHexGridIntf> m_hexGrid;
|
||||
const std::vector<std::vector<cvf::Vec3d> > m_polyLines;
|
||||
cvf::Vec3d m_extrusionDirection;
|
||||
|
||||
// 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;
|
||||
|
||||
const RimCrossSection* m_crossSection;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,562 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RivCrossSectionPartMgr.h"
|
||||
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigCaseData.h"
|
||||
#include "RigFemPartCollection.h"
|
||||
#include "RigFemPartResultsCollection.h"
|
||||
#include "RigGeoMechCaseData.h"
|
||||
#include "RigResultAccessor.h"
|
||||
#include "RigResultAccessorFactory.h"
|
||||
|
||||
#include "RimCrossSection.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimGeoMechCase.h"
|
||||
#include "RimGeoMechCellColors.h"
|
||||
#include "RimGeoMechView.h"
|
||||
#include "RimLegendConfig.h"
|
||||
#include "RimTernaryLegendConfig.h"
|
||||
|
||||
#include "RivCrossSectionSourceInfo.h"
|
||||
#include "RivResultToTextureMapper.h"
|
||||
#include "RivScalarMapperUtils.h"
|
||||
#include "RivTernaryScalarMapper.h"
|
||||
#include "RivTernaryTextureCoordsCreator.h"
|
||||
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfPrimitiveSetDirect.h"
|
||||
#include "cvfRenderState_FF.h"
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStatePoint.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionPartMgr::RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection)
|
||||
: m_rimCrossSection(rimCrossSection),
|
||||
m_defaultColor(cvf::Color3::WHITE)
|
||||
{
|
||||
CVF_ASSERT(m_rimCrossSection);
|
||||
|
||||
m_crossSectionFacesTextureCoords = new cvf::Vec2fArray;
|
||||
|
||||
computeData();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::applySingleColorEffect()
|
||||
{
|
||||
if (m_crossSectionGenerator.isNull()) return;
|
||||
|
||||
m_defaultColor = cvf::Color3f::OLIVE;//m_rimCrossSection->CrossSectionColor();
|
||||
this->updatePartEffect();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex)
|
||||
{
|
||||
if (m_crossSectionGenerator.isNull()) return;
|
||||
|
||||
if (!m_crossSectionGenerator->isAnyGeometryPresent()) return;
|
||||
|
||||
RimEclipseView* eclipseView;
|
||||
m_rimCrossSection->firstAnchestorOrThisOfType(eclipseView);
|
||||
|
||||
if (eclipseView)
|
||||
{
|
||||
RimEclipseCellColors* cellResultColors = eclipseView->cellResult();
|
||||
CVF_ASSERT(cellResultColors);
|
||||
|
||||
RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(cellResultColors->porosityModel());
|
||||
RigCaseData* eclipseCase = eclipseView->eclipseCase()->reservoirData();
|
||||
|
||||
// CrossSections
|
||||
if (m_crossSectionFaces.notNull())
|
||||
{
|
||||
if (cellResultColors->isTernarySaturationSelected())
|
||||
{
|
||||
RivTernaryTextureCoordsCreator texturer(cellResultColors, cellResultColors->ternaryLegendConfig(), timeStepIndex);
|
||||
|
||||
texturer.createTextureCoords(m_crossSectionFacesTextureCoords.p(), m_crossSectionGenerator->triangleToCellIndex());
|
||||
|
||||
const RivTernaryScalarMapper* mapper = cellResultColors->ternaryLegendConfig()->scalarMapper();
|
||||
RivScalarMapperUtils::applyTernaryTextureResultsToPart(m_crossSectionFaces.p(),
|
||||
m_crossSectionFacesTextureCoords.p(),
|
||||
mapper,
|
||||
1.0,
|
||||
caf::FC_NONE,
|
||||
eclipseView->isLightingDisabled());
|
||||
}
|
||||
else
|
||||
{
|
||||
CVF_ASSERT(m_crossSectionGenerator.notNull());
|
||||
|
||||
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
|
||||
cvf::ref<RigResultAccessor> resultAccessor;
|
||||
|
||||
if (RimDefines::isPerCellFaceResult(cellResultColors->resultVariable()))
|
||||
{
|
||||
resultAccessor = new RigHugeValResultAccessor;
|
||||
}
|
||||
else
|
||||
{
|
||||
resultAccessor = RigResultAccessorFactory::createResultAccessor(cellResultColors->reservoirView()->eclipseCase()->reservoirData(),
|
||||
0,
|
||||
timeStepIndex,
|
||||
cellResultColors);
|
||||
}
|
||||
|
||||
RivCrossSectionPartMgr::calculateEclipseTextureCoordinates(m_crossSectionFacesTextureCoords.p(),
|
||||
m_crossSectionGenerator->triangleToCellIndex(),
|
||||
resultAccessor.p(),
|
||||
mapper);
|
||||
|
||||
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(m_crossSectionFaces.p(),
|
||||
m_crossSectionFacesTextureCoords.p(),
|
||||
mapper,
|
||||
1.0,
|
||||
caf::FC_NONE,
|
||||
eclipseView->isLightingDisabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RimGeoMechView* geoView;
|
||||
m_rimCrossSection->firstAnchestorOrThisOfType(geoView);
|
||||
|
||||
if (geoView)
|
||||
{
|
||||
RimGeoMechCellColors* cellResultColors = geoView->cellResult();
|
||||
RigGeoMechCaseData* caseData = cellResultColors->ownerCaseData();
|
||||
|
||||
if (!caseData) return;
|
||||
|
||||
RigFemResultAddress resVarAddress = cellResultColors->resultAddress();
|
||||
|
||||
// Do a "Hack" to show elm nodal and not nodal POR results
|
||||
if (resVarAddress.resultPosType == RIG_NODAL && resVarAddress.fieldName == "POR-Bar") resVarAddress.resultPosType = RIG_ELEMENT_NODAL;
|
||||
|
||||
const std::vector<RivVertexWeights> &vertexWeights = m_crossSectionGenerator->triangleVxToCellCornerInterpolationWeights();
|
||||
const std::vector<float>& resultValues = caseData->femPartResults()->resultValues(resVarAddress, 0, (int)timeStepIndex);
|
||||
bool isElementNodalResult = !(resVarAddress.resultPosType == RIG_NODAL);
|
||||
RigFemPart* femPart = caseData->femParts()->part(0);
|
||||
const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper();
|
||||
|
||||
RivCrossSectionPartMgr::calculateGeoMechTextureCoords(m_crossSectionFacesTextureCoords.p(),
|
||||
vertexWeights,
|
||||
resultValues,
|
||||
isElementNodalResult,
|
||||
femPart,
|
||||
mapper);
|
||||
|
||||
RivScalarMapperUtils::applyTextureResultsToPart(m_crossSectionFaces.p(),
|
||||
m_crossSectionFacesTextureCoords.p(),
|
||||
mapper,
|
||||
1.0,
|
||||
caf::FC_NONE,
|
||||
geoView->isLightingDisabled());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::calculateGeoMechTextureCoords(cvf::Vec2fArray* textureCoords,
|
||||
const std::vector<RivVertexWeights> &vertexWeights,
|
||||
const std::vector<float> &resultValues,
|
||||
bool isElementNodalResult,
|
||||
const RigFemPart* femPart,
|
||||
const cvf::ScalarMapper* mapper)
|
||||
{
|
||||
textureCoords->resize(vertexWeights.size());
|
||||
|
||||
if (resultValues.size() == 0)
|
||||
{
|
||||
textureCoords->setAll(cvf::Vec2f(0.0, 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
||||
|
||||
int vxCount = static_cast<int>(vertexWeights.size());
|
||||
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int triangleVxIdx = 0; triangleVxIdx < vxCount; ++triangleVxIdx)
|
||||
{
|
||||
float resValue = 0;
|
||||
int weightCount = vertexWeights[triangleVxIdx].size();
|
||||
for (int wIdx = 0; wIdx < weightCount; ++wIdx)
|
||||
{
|
||||
size_t resIdx = isElementNodalResult ? vertexWeights[triangleVxIdx].vxId(wIdx) :
|
||||
femPart->nodeIdxFromElementNodeResultIdx(vertexWeights[triangleVxIdx].vxId(wIdx));
|
||||
resValue += resultValues[resIdx] * vertexWeights[triangleVxIdx].weight(wIdx);
|
||||
}
|
||||
|
||||
if (resValue == HUGE_VAL || resValue != resValue) // a != a is true for NAN's
|
||||
{
|
||||
rawPtr[triangleVxIdx][1] = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawPtr[triangleVxIdx] = mapper->mapToTextureCoord(resValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Calculates the texture coordinates in a "nearly" one dimensional 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)
|
||||
{
|
||||
if (!resultAccessor) return;
|
||||
|
||||
size_t numVertices = triangleToCellIdxMap.size()*3;
|
||||
|
||||
textureCoords->resize(numVertices);
|
||||
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
||||
|
||||
int triangleCount = static_cast<int>(triangleToCellIdxMap.size());
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int tIdx = 0; tIdx < triangleCount; tIdx++)
|
||||
{
|
||||
double cellScalarValue = resultAccessor->cellScalarGlobIdx(triangleToCellIdxMap[tIdx]);
|
||||
cvf::Vec2f 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;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::generatePartGeometry()
|
||||
{
|
||||
if (m_crossSectionGenerator.isNull()) return;
|
||||
|
||||
bool useBufferObjects = true;
|
||||
// Surface geometry
|
||||
{
|
||||
cvf::ref<cvf::DrawableGeo> geo = m_crossSectionGenerator->generateSurface();
|
||||
if (geo.notNull())
|
||||
{
|
||||
geo->computeNormals();
|
||||
|
||||
if (useBufferObjects)
|
||||
{
|
||||
geo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section");
|
||||
part->setDrawable(geo.p());
|
||||
|
||||
// Set mapping from triangle face index to cell index
|
||||
cvf::ref<RivCrossSectionSourceInfo> si = new RivCrossSectionSourceInfo(m_crossSectionGenerator.p());
|
||||
part->setSourceInfo(si.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
part->setEnableMask(faultBit);
|
||||
part->setPriority(priCrossSectionGeo);
|
||||
|
||||
m_crossSectionFaces = part;
|
||||
}
|
||||
}
|
||||
|
||||
// Mesh geometry
|
||||
{
|
||||
cvf::ref<cvf::DrawableGeo> geoMesh = m_crossSectionGenerator->createMeshDrawable();
|
||||
if (geoMesh.notNull())
|
||||
{
|
||||
if (useBufferObjects)
|
||||
{
|
||||
geoMesh->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section mesh");
|
||||
part->setDrawable(geoMesh.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
part->setEnableMask(meshFaultBit);
|
||||
part->setPriority(priMesh);
|
||||
|
||||
m_crossSectionGridLines = part;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight line
|
||||
|
||||
m_highlightLineAlongPolyline = NULL;
|
||||
m_highlightPointsForPolyline = NULL;
|
||||
|
||||
if (m_rimCrossSection->type == RimCrossSection::CS_POLYLINE)
|
||||
{
|
||||
{
|
||||
cvf::ref<cvf::DrawableGeo> polylineGeo = m_crossSectionGenerator->createLineAlongPolylineDrawable();
|
||||
if (polylineGeo.notNull())
|
||||
{
|
||||
if (useBufferObjects)
|
||||
{
|
||||
polylineGeo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section Polyline");
|
||||
part->setDrawable(polylineGeo.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
part->setPriority(10000);
|
||||
|
||||
// Always show this part, also when mesh is turned off
|
||||
//part->setEnableMask(meshFaultBit);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator lineEffGen(cvf::Color3::MAGENTA);
|
||||
eff = lineEffGen.generateUnCachedEffect();
|
||||
|
||||
cvf::ref<cvf::RenderStateDepth> depth = new cvf::RenderStateDepth;
|
||||
depth->enableDepthTest(false);
|
||||
eff->setRenderState(depth.p());
|
||||
|
||||
part->setEffect(eff.p());
|
||||
|
||||
m_highlightLineAlongPolyline = part;
|
||||
}
|
||||
}
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> polylinePointsGeo = m_crossSectionGenerator->createPointsFromPolylineDrawable();
|
||||
if (polylinePointsGeo.notNull())
|
||||
{
|
||||
if (useBufferObjects)
|
||||
{
|
||||
polylinePointsGeo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section Polyline");
|
||||
part->setDrawable(polylinePointsGeo.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
part->setPriority(10000);
|
||||
|
||||
// Always show this part, also when mesh is turned off
|
||||
//part->setEnableMask(meshFaultBit);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator lineEffGen(cvf::Color3::MAGENTA);
|
||||
eff = lineEffGen.generateUnCachedEffect();
|
||||
|
||||
cvf::ref<cvf::RenderStateDepth> depth = new cvf::RenderStateDepth;
|
||||
depth->enableDepthTest(false);
|
||||
eff->setRenderState(depth.p());
|
||||
|
||||
cvf::ref<cvf::RenderStatePoint> pointRendState = new cvf::RenderStatePoint(cvf::RenderStatePoint::FIXED_SIZE);
|
||||
pointRendState->setSize(5.0f);
|
||||
eff->setRenderState(pointRendState.p());
|
||||
|
||||
part->setEffect(eff.p());
|
||||
|
||||
m_highlightPointsForPolyline = part;
|
||||
}
|
||||
}
|
||||
|
||||
updatePartEffect();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::updatePartEffect()
|
||||
{
|
||||
if (m_crossSectionGenerator.isNull()) return;
|
||||
|
||||
// Set deCrossSection effect
|
||||
caf::SurfaceEffectGenerator geometryEffgen(m_defaultColor, caf::PO_1);
|
||||
|
||||
cvf::ref<cvf::Effect> geometryOnlyEffect = geometryEffgen.generateCachedEffect();
|
||||
|
||||
if (m_crossSectionFaces.notNull())
|
||||
{
|
||||
m_crossSectionFaces->setEffect(geometryOnlyEffect.p());
|
||||
}
|
||||
|
||||
// Update mesh colors as well, in case of change
|
||||
//RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator CrossSectionEffGen(cvf::Color3::WHITE);//prefs->defaultCrossSectionGridLineColors());
|
||||
eff = CrossSectionEffGen.generateCachedEffect();
|
||||
|
||||
if (m_crossSectionGridLines.notNull())
|
||||
{
|
||||
m_crossSectionGridLines->setEffect(eff.p());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
|
||||
{
|
||||
if (m_crossSectionFaces.isNull())
|
||||
{
|
||||
generatePartGeometry();
|
||||
}
|
||||
|
||||
if (m_crossSectionFaces.notNull())
|
||||
{
|
||||
m_crossSectionFaces->setTransform(scaleTransform);
|
||||
model->addPart(m_crossSectionFaces.p());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
|
||||
{
|
||||
if (m_crossSectionGridLines.isNull())
|
||||
{
|
||||
generatePartGeometry();
|
||||
}
|
||||
|
||||
if (m_crossSectionGridLines.notNull())
|
||||
{
|
||||
m_crossSectionGridLines->setTransform(scaleTransform);
|
||||
model->addPart(m_crossSectionGridLines.p());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::appendPolylinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform)
|
||||
{
|
||||
if (m_highlightLineAlongPolyline.notNull())
|
||||
{
|
||||
m_highlightLineAlongPolyline->setTransform(scaleTransform);
|
||||
model->addPart(m_highlightLineAlongPolyline.p());
|
||||
}
|
||||
if (m_highlightPointsForPolyline.notNull())
|
||||
{
|
||||
m_highlightPointsForPolyline->setTransform(scaleTransform);
|
||||
model->addPart(m_highlightPointsForPolyline.p());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RivCrossSectionPartMgr::computeData()
|
||||
{
|
||||
std::vector< std::vector <cvf::Vec3d> > polyLines = m_rimCrossSection->polyLines();
|
||||
if (polyLines.size() > 0)
|
||||
{
|
||||
cvf::Vec3d direction = extrusionDirection(polyLines[0]);
|
||||
cvf::ref<RivCrossSectionHexGridIntf> hexGrid = createHexGridInterface();
|
||||
m_crossSectionGenerator = new RivCrossSectionGeometryGenerator(m_rimCrossSection, polyLines, direction, hexGrid.p());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<RivCrossSectionHexGridIntf> RivCrossSectionPartMgr::createHexGridInterface()
|
||||
{
|
||||
|
||||
RimEclipseView* eclipseView;
|
||||
m_rimCrossSection->firstAnchestorOrThisOfType(eclipseView);
|
||||
if (eclipseView)
|
||||
{
|
||||
RigMainGrid* grid = NULL;
|
||||
grid = eclipseView->eclipseCase()->reservoirData()->mainGrid();
|
||||
return new RivEclipseCrossSectionGrid(grid, eclipseView->currentActiveCellInfo(), m_rimCrossSection->showInactiveCells());
|
||||
}
|
||||
|
||||
RimGeoMechView* geoView;
|
||||
m_rimCrossSection->firstAnchestorOrThisOfType(geoView);
|
||||
if (geoView)
|
||||
{
|
||||
RigFemPart* femPart = geoView->geoMechCase()->geoMechData()->femParts()->part(0);
|
||||
return new RivFemCrossSectionGrid(femPart);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RivCrossSectionPartMgr::extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const
|
||||
{
|
||||
CVF_ASSERT(m_rimCrossSection);
|
||||
|
||||
cvf::Vec3d dir = cvf::Vec3d::Z_AXIS;
|
||||
|
||||
if (m_rimCrossSection->direction == RimCrossSection::CS_HORIZONTAL &&
|
||||
polyline.size() > 1)
|
||||
{
|
||||
// Use first and last point of polyline to approximate orientation of polyline
|
||||
// Then cross with Z axis to find extrusion direction
|
||||
|
||||
cvf::Vec3d polyLineDir = polyline[polyline.size() - 1] - polyline[0];
|
||||
cvf::Vec3d up = cvf::Vec3d::Z_AXIS;
|
||||
dir = polyLineDir ^ up;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RivCrossSectionGeometryGenerator.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfColor4.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ModelBasicList;
|
||||
class Transform;
|
||||
class Part;
|
||||
}
|
||||
|
||||
class RigMainGrid;
|
||||
class RimEclipseCellColors;
|
||||
class RimCellEdgeColors;
|
||||
class RimCrossSection;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
class RivCrossSectionPartMgr : public cvf::Object
|
||||
{
|
||||
public:
|
||||
RivCrossSectionPartMgr(const RimCrossSection* rimCrossSection);
|
||||
|
||||
void applySingleColorEffect();
|
||||
void updateCellResultColor(size_t timeStepIndex);
|
||||
|
||||
|
||||
void appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform);
|
||||
void appendMeshLinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform);
|
||||
void appendPolylinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform);
|
||||
|
||||
private:
|
||||
void updatePartEffect();
|
||||
void generatePartGeometry();
|
||||
void computeData();
|
||||
|
||||
cvf::Vec3d extrusionDirection(const std::vector<cvf::Vec3d>& polyline) const;
|
||||
static void calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords,
|
||||
const std::vector<size_t>& triangleToCellIdxMap,
|
||||
const RigResultAccessor* resultAccessor,
|
||||
const cvf::ScalarMapper* mapper);
|
||||
static void calculateGeoMechTextureCoords(cvf::Vec2fArray* textureCoords,
|
||||
const std::vector<RivVertexWeights> &vertexWeights,
|
||||
const std::vector<float> &resultValues,
|
||||
bool isElementNodalResult,
|
||||
const RigFemPart* femPart,
|
||||
const cvf::ScalarMapper* mapper);
|
||||
cvf::ref<RivCrossSectionHexGridIntf> createHexGridInterface();
|
||||
private:
|
||||
|
||||
const RimCrossSection* m_rimCrossSection;
|
||||
|
||||
cvf::Color3f m_defaultColor;
|
||||
|
||||
cvf::ref<RivCrossSectionGeometryGenerator> m_crossSectionGenerator;
|
||||
cvf::ref<cvf::Part> m_crossSectionFaces;
|
||||
cvf::ref<cvf::Part> m_crossSectionGridLines;
|
||||
cvf::ref<cvf::Vec2fArray> m_crossSectionFacesTextureCoords;
|
||||
|
||||
cvf::ref<cvf::Part> m_highlightLineAlongPolyline;
|
||||
cvf::ref<cvf::Part> m_highlightPointsForPolyline;
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RivCrossSectionSourceInfo.h"
|
||||
|
||||
#include "RivCrossSectionGeometryGenerator.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RivCrossSectionSourceInfo::RivCrossSectionSourceInfo(RivCrossSectionGeometryGenerator* geometryGenerator)
|
||||
: m_crossSectionGeometryGenerator(geometryGenerator)
|
||||
{
|
||||
CVF_ASSERT(m_crossSectionGeometryGenerator.notNull());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<size_t>& RivCrossSectionSourceInfo::triangleToCellIndex() const
|
||||
{
|
||||
CVF_ASSERT(m_crossSectionGeometryGenerator.notNull());
|
||||
|
||||
return m_crossSectionGeometryGenerator->triangleToCellIndex();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const RimCrossSection* RivCrossSectionSourceInfo::crossSection() const
|
||||
{
|
||||
return m_crossSectionGeometryGenerator->crossSection();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Statoil ASA
|
||||
// Copyright (C) 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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfArray.h"
|
||||
|
||||
class RivCrossSectionGeometryGenerator;
|
||||
class RimCrossSection;
|
||||
|
||||
class RivCrossSectionSourceInfo : public cvf::Object
|
||||
{
|
||||
public:
|
||||
RivCrossSectionSourceInfo(RivCrossSectionGeometryGenerator* geometryGenerator);
|
||||
|
||||
const std::vector<size_t>& triangleToCellIndex() const;
|
||||
|
||||
const RimCrossSection* crossSection() const;
|
||||
|
||||
private:
|
||||
cvf::cref<RivCrossSectionGeometryGenerator> m_crossSectionGeometryGenerator;
|
||||
};
|
||||
Reference in New Issue
Block a user