From c784deae25d32485b52ee78290d75710563c66f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Tue, 10 Apr 2018 15:35:10 +0200 Subject: [PATCH] #2437 Add fault-labels to 2d Intersection view --- .../RivIntersectionGeometryGenerator.cpp | 117 +++++++++++------- .../RivIntersectionGeometryGenerator.h | 5 + .../Intersections/RivIntersectionPartMgr.cpp | 93 ++++++++++++++ .../Intersections/RivIntersectionPartMgr.h | 9 +- 4 files changed, 177 insertions(+), 47 deletions(-) diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp index e73e491060..b1ed7216d2 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.cpp @@ -144,6 +144,60 @@ void RivIntersectionGeometryGenerator::calculateFlattenedOrOffsetedPolyline() } } + +class MeshLinesAccumulator +{ +public: + MeshLinesAccumulator(const RivIntersectionHexGridInterface* hexGrid) + : m_hexGrid(hexGrid) + {} + + std::vector cellBorderLineVxes; + std::vector faultCellBorderLineVxes; + std::map faultToHighestFaultMeshVxMap; + + void accumulateMeshLines(const std::vector& cellFaceForEachClippedTriangleEdge, + uint triVxIdx, + size_t globalCellIdx, + const cvf::Vec3d& p0, + const cvf::Vec3d& p1) + { + #define isFace( faceEnum ) (0 <= faceEnum && faceEnum <= 5 ) + using FaceType = cvf::StructGridInterface::FaceType; + + if ( isFace(cellFaceForEachClippedTriangleEdge[triVxIdx]) ) + { + const RigFault * fault = m_hexGrid->findFaultFromCellIndexAndCellFace(globalCellIdx, + (FaceType)cellFaceForEachClippedTriangleEdge[triVxIdx]); + if ( fault ) + { + cvf::Vec3d highestVx = p0.z() > p1.z() ? p0 : p1; + + auto itIsInsertedPair = faultToHighestFaultMeshVxMap.insert({fault, highestVx}); + if (!itIsInsertedPair.second) + { + if (itIsInsertedPair.first->second.z() < highestVx.z()) + { + itIsInsertedPair.first->second = highestVx; + } + } + + faultCellBorderLineVxes.emplace_back(p0); + faultCellBorderLineVxes.emplace_back(p1); + } + else + { + cellBorderLineVxes.emplace_back(p0); + cellBorderLineVxes.emplace_back(p1); + } + } + } + +private: + cvf::cref m_hexGrid; +}; + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -153,8 +207,9 @@ void RivIntersectionGeometryGenerator::calculateArrays() m_extrusionDirection.normalize(); std::vector triangleVertices; - std::vector cellBorderLineVxes; - std::vector faultCellBorderLineVxes; + + MeshLinesAccumulator meshAcc(m_hexGrid.p()); + cvf::Vec3d displayOffset = m_hexGrid->displayOffset(); cvf::BoundingBox gridBBox = m_hexGrid->boundingBox(); @@ -303,6 +358,7 @@ void RivIntersectionGeometryGenerator::calculateArrays() uint triVxIdx = tIdx*3; // Accumulate triangle vertices + cvf::Vec3d p0(clippedTriangleVxes[triVxIdx+0].vx); cvf::Vec3d p1(clippedTriangleVxes[triVxIdx+1].vx); cvf::Vec3d p2(clippedTriangleVxes[triVxIdx+2].vx); @@ -317,49 +373,12 @@ void RivIntersectionGeometryGenerator::calculateArrays() // Accumulate mesh lines - #define isFace( faceEnum ) (0 <= faceEnum && faceEnum <= 5 ) - using FaceType = cvf::StructGridInterface::FaceType; - - if ( isFace(cellFaceForEachClippedTriangleEdge[triVxIdx]) ) - { - if ( m_hexGrid->findFaultFromCellIndexAndCellFace(globalCellIdx, (FaceType)cellFaceForEachClippedTriangleEdge[triVxIdx]) ) - { - faultCellBorderLineVxes.emplace_back(p0); - faultCellBorderLineVxes.emplace_back(p1); - } - else - { - cellBorderLineVxes.emplace_back(p0); - cellBorderLineVxes.emplace_back(p1); - } - } - if ( isFace(cellFaceForEachClippedTriangleEdge[triVxIdx+1]) ) - { - if ( m_hexGrid->findFaultFromCellIndexAndCellFace(globalCellIdx, (FaceType)cellFaceForEachClippedTriangleEdge[triVxIdx+1]) ) - { - faultCellBorderLineVxes.emplace_back(p1); - faultCellBorderLineVxes.emplace_back(p2); - } - else - { - cellBorderLineVxes.emplace_back(p1); - cellBorderLineVxes.emplace_back(p2); - } - } - if ( isFace(cellFaceForEachClippedTriangleEdge[triVxIdx+2]) ) - { - if ( m_hexGrid->findFaultFromCellIndexAndCellFace(globalCellIdx, (FaceType)cellFaceForEachClippedTriangleEdge[triVxIdx+2]) ) - { - faultCellBorderLineVxes.emplace_back(p2); - faultCellBorderLineVxes.emplace_back(p0); - } - else - { - cellBorderLineVxes.emplace_back(p2); - cellBorderLineVxes.emplace_back(p0); - } - } + meshAcc.accumulateMeshLines(cellFaceForEachClippedTriangleEdge, triVxIdx + 0, globalCellIdx, p0, p1); + meshAcc.accumulateMeshLines(cellFaceForEachClippedTriangleEdge, triVxIdx + 1, globalCellIdx, p1, p2); + meshAcc.accumulateMeshLines(cellFaceForEachClippedTriangleEdge, triVxIdx + 2, globalCellIdx, p2, p0); + + // Mapping to cell index m_triangleToCellIdxMap.push_back(globalCellIdx); @@ -389,9 +408,15 @@ void RivIntersectionGeometryGenerator::calculateArrays() lIdx = idxToNextP; } } + m_triangleVxes->assign(triangleVertices); - m_cellBorderLineVxes->assign(cellBorderLineVxes); - m_faultCellBorderLineVxes->assign(faultCellBorderLineVxes); + m_cellBorderLineVxes->assign(meshAcc.cellBorderLineVxes); + m_faultCellBorderLineVxes->assign(meshAcc.faultCellBorderLineVxes); + + for (const auto& it : meshAcc.faultToHighestFaultMeshVxMap) + { + m_faultMeshLabelAndAnchorPositions.push_back( { it.first->name(), it.second } ); + } } diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h index 6bc7363ce8..5c8a08fcea 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionGeometryGenerator.h @@ -29,6 +29,8 @@ #include +#include + class RigMainGrid; class RigActiveCellInfo; class RigResultAccessor; @@ -68,6 +70,8 @@ public: cvf::ref createPointsFromExtrusionLineDrawable(const std::vector& extrusionLine); const std::vector >& flattenedOrOffsettedPolyLines() { return m_flattenedOrOffsettedPolyLines; } + const std::vector > & faultMeshLabelAndAnchorPositions() { return m_faultMeshLabelAndAnchorPositions; } + // Mapping between cells and geometry const std::vector& triangleToCellIndex() const; @@ -106,5 +110,6 @@ private: std::vector > m_flattenedOrOffsettedPolyLines; std::vector > m_segementTransformPrLinePoint; + std::vector > m_faultMeshLabelAndAnchorPositions; }; diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp index 0b4e2307bd..d49e7fe5d6 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.cpp @@ -59,9 +59,11 @@ #include "cafTensor3.h" #include "cvfDrawableGeo.h" +#include "cvfDrawableText.h" #include "cvfGeometryTools.h" #include "cvfModelBasicList.h" #include "cvfPart.h" +#include "cvfqtUtils.h" #include "cvfPrimitiveSetDirect.h" #include "cvfRenderState_FF.h" #include "cvfRenderStateDepth.h" @@ -582,9 +584,87 @@ void RivIntersectionPartMgr::generatePartGeometry() createExtrusionDirParts(useBufferObjects); + if (m_isFlattened) createFaultLabelParts(m_crossSectionGenerator->faultMeshLabelAndAnchorPositions()); + applySingleColorEffect(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RivIntersectionPartMgr::createFaultLabelParts(const std::vector >& labelAndAnchors) +{ + cvf::Font* font = RiaApplication::instance()->customFont(); + + std::vector lineVertices; + + cvf::ref drawableText = new cvf::DrawableText; + { + drawableText->setFont(font); + drawableText->setCheckPosVisible(false); + drawableText->setDrawBorder(false); + drawableText->setDrawBackground(false); + drawableText->setVerticalAlignment(cvf::TextDrawer::BASELINE); + cvf::Color3f defWellLabelColor = RiaApplication::instance()->preferences()->defaultWellLabelColor(); + drawableText->setTextColor(defWellLabelColor); + } + + cvf::BoundingBox bb = m_crossSectionFaces->boundingBox(); + double labelZOffset = bb.extent().z() / 10; + + for (const auto& labelAndAnchorPair : labelAndAnchors) + { + cvf::String cvfString = cvfqt::Utils::toString(labelAndAnchorPair.first); + cvf::Vec3f textCoord(labelAndAnchorPair.second); + + textCoord.z() += labelZOffset; + drawableText->addText(cvfString, textCoord); + + lineVertices.push_back(cvf::Vec3f(labelAndAnchorPair.second)); + lineVertices.push_back(textCoord); + } + + // Labels part + { + cvf::ref part = new cvf::Part; + part->setName("Fault mesh label : text "); + part->setDrawable(drawableText.p()); + + cvf::ref eff = new cvf::Effect; + + part->setEffect(eff.p()); + part->setPriority(RivPartPriority::PartType::Text); + part->updateBoundingBox(); + + m_faultMeshLabels = part; + } + + // Lines to labels part + { + cvf::ref vertices = new cvf::Vec3fArray; + vertices->assign(lineVertices); + cvf::ref geo = new cvf::DrawableGeo; + geo->setVertexArray(vertices.p()); + + cvf::ref primSet = new cvf::PrimitiveSetDirect(cvf::PT_LINES); + primSet->setStartIndex(0); + primSet->setIndexCount(vertices->size()); + geo->addPrimitiveSet(primSet.p()); + + cvf::ref part = new cvf::Part; + part->setName("Anchor lines for fault mesh labels"); + part->setDrawable(geo.p()); + + part->updateBoundingBox(); + + caf::MeshEffectGenerator gen(RiaApplication::instance()->preferences()->defaultFaultGridLineColors()); + cvf::ref eff = gen.generateCachedEffect(); + + part->setEffect(eff.p()); + m_faultMeshLabelLines = part; + } + +} //-------------------------------------------------------------------------------------------------- /// @@ -834,6 +914,19 @@ void RivIntersectionPartMgr::appendMeshLinePartsToModel(cvf::ModelBasicList* mod m_crossSectionFaultGridLines->setTransform(scaleTransform); model->addPart(m_crossSectionFaultGridLines.p()); } + + if (m_faultMeshLabelLines.notNull()) + { + m_faultMeshLabelLines->setTransform(scaleTransform); + model->addPart(m_faultMeshLabelLines.p()); + } + + if (m_faultMeshLabels.notNull()) + { + m_faultMeshLabels->setTransform(scaleTransform); + model->addPart(m_faultMeshLabels.p()); + } + } diff --git a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h index 4410ec3f6b..1e422ec737 100644 --- a/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h +++ b/ApplicationCode/ModelVisualization/Intersections/RivIntersectionPartMgr.h @@ -28,7 +28,10 @@ #include "cafPdmPointer.h" +#include + #include +#include namespace cvf { @@ -110,6 +113,7 @@ public: const cvf::ScalarMapper* mapper); private: void generatePartGeometry(); + void createFaultLabelParts(const std::vector >& labelAndAnchors); void createPolyLineParts(bool useBufferObjects); void createExtrusionDirParts(bool useBufferObjects); @@ -122,7 +126,10 @@ private: cvf::ref m_crossSectionFaces; cvf::ref m_crossSectionGridLines; cvf::ref m_crossSectionFaultGridLines; - + cvf::ref m_faultMeshLabels; + cvf::ref m_faultMeshLabelLines; + + cvf::ref m_crossSectionFacesTextureCoords; cvf::ref m_highlightLineAlongPolyline;