From b4c6277e72650b69b937288892680f4c56b5d66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 20 Oct 2016 16:09:27 +0200 Subject: [PATCH] #914 Transformed stress on intersection Box is working --- .../RivIntersectionBoxGeometryGenerator.cpp | 13 ++ .../RivIntersectionBoxGeometryGenerator.h | 1 + .../RivIntersectionBoxPartMgr.cpp | 128 +++++------------- .../Intersections/RivIntersectionBoxPartMgr.h | 12 -- .../RivIntersectionGeometryGenerator.cpp | 10 +- .../RivIntersectionGeometryGenerator.h | 5 +- .../Intersections/RivIntersectionPartMgr.cpp | 14 +- .../Intersections/RivIntersectionPartMgr.h | 16 ++- 8 files changed, 71 insertions(+), 128 deletions(-) diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.cpp index 09ffa11ddd..9ad58c9f3a 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.cpp @@ -113,6 +113,19 @@ const std::vector& RivIntersectionBoxGeometryGener return m_triVxToCellCornerWeights; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const cvf::Vec3fArray* RivIntersectionBoxGeometryGenerator::triangleVxes() const +{ + CVF_ASSERT(m_triangleVxes->size()); + + return m_triangleVxes.p(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- class Box { diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.h index 2acf755ca9..ec39ef767d 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxGeometryGenerator.h @@ -55,6 +55,7 @@ public: // Mapping between cells and geometry const std::vector& triangleToCellIndex() const; const std::vector& triangleVxToCellCornerInterpolationWeights() const; + const cvf::Vec3fArray* triangleVxes() const; const RimIntersectionBox* intersectionBox() const; diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.cpp index b42309df3a..147871d2e9 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.cpp @@ -49,6 +49,7 @@ #include "cvfRenderState_FF.h" #include "cvfRenderStateDepth.h" #include "cvfRenderStatePoint.h" +#include "RivIntersectionPartMgr.h" @@ -131,7 +132,7 @@ void RivIntersectionBoxPartMgr::updateCellResultColor(size_t timeStepIndex) cellResultColors); } - RivIntersectionBoxPartMgr::calculateEclipseTextureCoordinates(m_intersectionBoxFacesTextureCoords.p(), + RivIntersectionPartMgr::calculateEclipseTextureCoordinates(m_intersectionBoxFacesTextureCoords.p(), m_intersectionBoxGenerator->triangleToCellIndex(), resultAccessor.p(), mapper); @@ -159,21 +160,38 @@ void RivIntersectionBoxPartMgr::updateCellResultColor(size_t timeStepIndex) 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 &vertexWeights = m_intersectionBoxGenerator->triangleVxToCellCornerInterpolationWeights(); - const std::vector& 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(); + + if (!(resVarAddress.resultPosType == RIG_ELEMENT_NODAL_FACE) ) + { + // 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; - RivIntersectionBoxPartMgr::calculateGeoMechTextureCoords(m_intersectionBoxFacesTextureCoords.p(), - vertexWeights, - resultValues, - isElementNodalResult, - femPart, - mapper); + const std::vector& resultValues = caseData->femPartResults()->resultValues(resVarAddress, 0, (int)timeStepIndex); + RigFemPart* femPart = caseData->femParts()->part(0); + bool isElementNodalResult = !(resVarAddress.resultPosType == RIG_NODAL); + + RivIntersectionPartMgr::calculateGeoMechTextureCoords(m_intersectionBoxFacesTextureCoords.p(), + vertexWeights, + resultValues, + isElementNodalResult, + femPart, + mapper); + } + else + { + // Special direction sensitive result calculation + const cvf::Vec3fArray* triangelVxes = m_intersectionBoxGenerator->triangleVxes(); + + RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords(m_intersectionBoxFacesTextureCoords.p(), + triangelVxes, + vertexWeights, + caseData, + resVarAddress, + (int)timeStepIndex, + mapper); + } RivScalarMapperUtils::applyTextureResultsToPart(m_intersectionBoxFaces.p(), m_intersectionBoxFacesTextureCoords.p(), @@ -185,90 +203,6 @@ void RivIntersectionBoxPartMgr::updateCellResultColor(size_t timeStepIndex) } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RivIntersectionBoxPartMgr::calculateGeoMechTextureCoords(cvf::Vec2fArray* textureCoords, - const std::vector &vertexWeights, - const std::vector &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(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-texture coordinate value of 1.0 instead of the normal 0.5 -//-------------------------------------------------------------------------------------------------- -void RivIntersectionBoxPartMgr::calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, - const std::vector& 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(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; diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.h index cad7c71c27..1b8f0ebc63 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionBoxPartMgr.h @@ -57,18 +57,6 @@ private: void updatePartEffect(); void generatePartGeometry(); - static void calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, - const std::vector& triangleToCellIdxMap, - const RigResultAccessor* resultAccessor, - const cvf::ScalarMapper* mapper); - - static void calculateGeoMechTextureCoords(cvf::Vec2fArray* textureCoords, - const std::vector &vertexWeights, - const std::vector &resultValues, - bool isElementNodalResult, - const RigFemPart* femPart, - const cvf::ScalarMapper* mapper); - cvf::ref createHexGridInterface(); private: diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp index 2c7016174b..2b1cb70431 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp @@ -383,14 +383,10 @@ const std::vector& RivIntersectionGeometryGenerato //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::Mat3f RivIntersectionGeometryGenerator::calculateTriangleOrientation(int triangleIndex) +const cvf::Vec3fArray* RivIntersectionGeometryGenerator::triangleVxes() const { - int triVxStartIdx = triangleIndex*3; - cvf::Vec3f p0 = m_triangleVxes->get(triVxStartIdx); - cvf::Vec3f p1 = m_triangleVxes->get(triVxStartIdx + 1); - cvf::Vec3f p2 = m_triangleVxes->get(triVxStartIdx + 2); - - return cvf::GeometryTools::computePlaneHorizontalRotationMx(p1 - p0, p2 - p0); + CVF_ASSERT(m_triangleVxes->size()); + return m_triangleVxes.p(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h index 8e2333c6c0..dcc4db9104 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h @@ -66,10 +66,9 @@ public: // Mapping between cells and geometry - const std::vector& triangleToCellIndex() const; + const std::vector& triangleToCellIndex() const; const std::vector& triangleVxToCellCornerInterpolationWeights() const; - - cvf::Mat3f calculateTriangleOrientation(int triangleIndex); + const cvf::Vec3fArray* triangleVxes() const; const RimIntersection* crossSection() const; diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp index 7eb2248c33..0cb3978273 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp @@ -51,6 +51,7 @@ #include "cvfRenderStateDepth.h" #include "cvfRenderStatePoint.h" #include "cafTensor3.h" +#include "cvfGeometryTools.h" //-------------------------------------------------------------------------------------------------- @@ -184,8 +185,10 @@ void RivIntersectionPartMgr::updateCellResultColor(size_t timeStepIndex) else { // Special direction sensitive result calculation - // Normal, Horizontal, Semi Vertical, max shear + const cvf::Vec3fArray* triangelVxes = m_crossSectionGenerator->triangleVxes(); + RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords(m_crossSectionFacesTextureCoords.p(), + triangelVxes, vertexWeights, caseData, resVarAddress, @@ -255,6 +258,7 @@ void RivIntersectionPartMgr::calculateGeoMechTextureCoords(cvf::Vec2fArray* text /// //-------------------------------------------------------------------------------------------------- void RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords(cvf::Vec2fArray* textureCoords, + const cvf::Vec3fArray* triangelVertices, const std::vector &vertexWeights, RigGeoMechCaseData* caseData, const RigFemResultAddress& resVarAddress, @@ -296,11 +300,15 @@ void RivIntersectionPartMgr::calculateGeoMechTensorXfTextureCoords(cvf::Vec2fArr int vxCount = static_cast(vertexWeights.size()); int triCount = vxCount/3; -//#pragma omp parallel for schedule(dynamic) + #pragma omp parallel for schedule(dynamic) for (int triangleIdx = 0; triangleIdx < triCount; ++triangleIdx) { - cvf::Mat3f triangleXf = m_crossSectionGenerator->calculateTriangleOrientation(triangleIdx); int triangleVxStartIdx = triangleIdx*3; + cvf::Vec3f p0 = triangelVertices->get(triangleVxStartIdx); + cvf::Vec3f p1 = triangelVertices->get(triangleVxStartIdx + 1); + cvf::Vec3f p2 = triangelVertices->get(triangleVxStartIdx + 2); + + cvf::Mat3f triangleXf = cvf::GeometryTools::computePlaneHorizontalRotationMx(p1 - p0, p2 - p0); for(int triangleVxIdx = triangleVxStartIdx; triangleVxIdx < triangleVxStartIdx+3; ++triangleVxIdx) { diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h index 7fbb88a652..0da5083e0e 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h @@ -68,22 +68,26 @@ private: void computeData(); +public: static void calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, const std::vector& triangleToCellIdxMap, const RigResultAccessor* resultAccessor, const cvf::ScalarMapper* mapper); + static void calculateGeoMechTextureCoords(cvf::Vec2fArray* textureCoords, const std::vector &vertexWeights, const std::vector &resultValues, bool isElementNodalResult, const RigFemPart* femPart, const cvf::ScalarMapper* mapper); - void calculateGeoMechTensorXfTextureCoords(cvf::Vec2fArray* textureCoords, - const std::vector &vertexWeights, - RigGeoMechCaseData* caseData, - const RigFemResultAddress& resVarAddress, - int timeStepIdx, - const cvf::ScalarMapper* mapper); + + static void calculateGeoMechTensorXfTextureCoords(cvf::Vec2fArray* textureCoords, + const cvf::Vec3fArray* triangelVertices, + const std::vector &vertexWeights, + RigGeoMechCaseData* caseData, + const RigFemResultAddress& resVarAddress, + int timeStepIdx, + const cvf::ScalarMapper* mapper); cvf::ref createHexGridInterface(); private: