From 40821a05a680515af9cfb5cdf27419ed1657aaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 23 Nov 2015 13:23:25 +0100 Subject: [PATCH] (#166) Refactored to improve readability of geomech Intersection texture generation --- .../RivCrossSectionPartMgr.cpp | 116 ++++++++++-------- .../RivCrossSectionPartMgr.h | 12 +- 2 files changed, 76 insertions(+), 52 deletions(-) diff --git a/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.cpp b/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.cpp index 0afe4c9391..2fbe4c72dc 100644 --- a/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.cpp @@ -123,10 +123,10 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex) timeStepIndex, cellResultColors->resultVariable()); - calculateEclipseTextureCoordinates(m_crossSectionFacesTextureCoords.p(), - m_crossSectionGenerator->triangleToCellIndex(), - resultAccessor.p(), - mapper); + RivCrossSectionPartMgr::calculateEclipseTextureCoordinates(m_crossSectionFacesTextureCoords.p(), + m_crossSectionGenerator->triangleToCellIndex(), + resultAccessor.p(), + mapper); RivScalarMapperUtils::applyTextureResultsToPart(m_crossSectionFaces.p(), @@ -149,58 +149,23 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex) if (!caseData) return; - const cvf::ScalarMapper* mapper = cellResultColors->legendConfig()->scalarMapper(); 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& resultValues = caseData->femPartResults()->resultValues(resVarAddress, 0, (int)timeStepIndex); - const std::vector &vertexWeights = m_crossSectionGenerator->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(); - bool isElementNodalResult = true; - RigFemPart* femPart = NULL; - if (resVarAddress.resultPosType == RIG_NODAL) - { - isElementNodalResult = false; - femPart = caseData->femParts()->part(0); - } - - m_crossSectionFacesTextureCoords->resize(vertexWeights.size()); - - if (resultValues.size() == 0) - { - m_crossSectionFacesTextureCoords->setAll(cvf::Vec2f(0.0, 1.0f)); - } - else - { - cvf::Vec2f* rawPtr = m_crossSectionFacesTextureCoords->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); - } - } - } + RivCrossSectionPartMgr::calculateGeoMechTextureCoords(m_crossSectionFacesTextureCoords.p(), + vertexWeights, + resultValues, + isElementNodalResult, + femPart, + mapper); RivScalarMapperUtils::applyTextureResultsToPart(m_crossSectionFaces.p(), m_crossSectionFacesTextureCoords.p(), @@ -211,14 +176,63 @@ void RivCrossSectionPartMgr::updateCellResultColor(size_t timeStepIndex) } } + //-------------------------------------------------------------------------------------------------- -/// Calculates the texture coordinates in a "nearly" one dimentional texture. +/// +//-------------------------------------------------------------------------------------------------- +void RivCrossSectionPartMgr::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-texturecoordinate value of 1.0 instead of the normal 0.5 //-------------------------------------------------------------------------------------------------- void RivCrossSectionPartMgr::calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, const std::vector& triangleToCellIdxMap, const RigResultAccessor* resultAccessor, - const cvf::ScalarMapper* mapper) const + const cvf::ScalarMapper* mapper) { if (!resultAccessor) return; diff --git a/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.h b/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.h index 62c084756d..28f1332ab7 100644 --- a/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivCrossSectionPartMgr.h @@ -52,6 +52,7 @@ public: void applySingleColorEffect(); void updateCellResultColor(size_t timeStepIndex); + void appendNativeCrossSectionFacesToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform); void appendMeshLinePartsToModel(cvf::ModelBasicList* model, cvf::Transform* scaleTransform); @@ -61,7 +62,16 @@ private: void computeData(); cvf::Vec3d extrusionDirection(const std::vector& polyline) const; - void calculateEclipseTextureCoordinates(cvf::Vec2fArray* textureCoords, const std::vector& triangleToCellIdxMap, const RigResultAccessor* resultAccessor, const cvf::ScalarMapper* mapper) const; + 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: