///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2018- Statoil ASA // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "Riv3dWellLogGridGeomertyGenerator.h" #include "RimWellPath.h" #include "RimWellPathCollection.h" #include "RigWellPath.h" #include "RigWellPathGeometryTools.h" #include "cafDisplayCoordTransform.h" #include "cvfObject.h" #include "cvfDrawableGeo.h" #include "cvfPrimitiveSetIndexedUInt.h" #include "cvfBoundingBox.h" #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Riv3dWellLogGridGeometryGenerator::Riv3dWellLogGridGeometryGenerator(RimWellPath* wellPath) : m_wellPath(wellPath) { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::map< Riv3dWellLogGridGeometryGenerator::DrawableId, cvf::ref > Riv3dWellLogGridGeometryGenerator::createGrid(const caf::DisplayCoordTransform* displayCoordTransform, const cvf::BoundingBox& wellPathClipBoundingBox, double planeAngle, double planeOffsetFromWellPathCenter, double planeWidth, double gridIntervalSize) const { CVF_ASSERT(gridIntervalSize > 0); if (!wellPathGeometry() || wellPathGeometry()->m_measuredDepths.empty()) { return std::map< DrawableId, cvf::ref >(); } if (!wellPathClipBoundingBox.isValid()) { return std::map< DrawableId, cvf::ref >(); } RimWellPathCollection* wellPathCollection = nullptr; m_wellPath->firstAncestorOrThisOfTypeAsserted(wellPathCollection); std::vector wellPathPoints = wellPathGeometry()->m_wellPathPoints; if (wellPathPoints.empty()) { return std::map< DrawableId, cvf::ref >(); } size_t originalWellPathSize = wellPathPoints.size(); if (wellPathCollection->wellPathClip) { double horizontalLengthAlongWellToClipPoint; double maxZClipHeight = wellPathClipBoundingBox.max().z() + wellPathCollection->wellPathClipZDistance; size_t indexToFirstVisibleSegment; wellPathPoints = RigWellPath::clipPolylineStartAboveZ( wellPathPoints, maxZClipHeight, &horizontalLengthAlongWellToClipPoint, &indexToFirstVisibleSegment); } if (wellPathPoints.empty()) { return std::map< DrawableId, cvf::ref >(); } std::map< DrawableId, cvf::ref > drawables; // calculateLineSegmentNormals returns normals for the whole well path. Erase the part which is clipped off std::vector wellPathSegmentNormals = RigWellPathGeometryTools::calculateLineSegmentNormals(wellPathGeometry(), planeAngle); wellPathSegmentNormals.erase(wellPathSegmentNormals.begin(), wellPathSegmentNormals.end() - wellPathPoints.size()); { std::vector vertices; vertices.reserve(wellPathPoints.size()); std::vector indices; indices.reserve(wellPathPoints.size()); cvf::uint indexCounter = 0; // Line along and close to well for (size_t i = 0; i < wellPathPoints.size(); i++) { vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord( wellPathPoints[i] + wellPathSegmentNormals[i] * planeOffsetFromWellPathCenter))); indices.push_back(indexCounter); indices.push_back(++indexCounter); } // Line along and far away from well in reverse order to create a closed surface. for (int64_t i = (int64_t) wellPathPoints.size()-1; i >= 0; i--) { vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord( wellPathPoints[i] + wellPathSegmentNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)))); indices.push_back(indexCounter); indices.push_back(++indexCounter); } indices.pop_back(); indices.push_back(0u); // Close surface cvf::ref indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINE_LOOP); cvf::ref indexArray = new cvf::UIntArray(indices); cvf::ref gridBorderDrawable = new cvf::DrawableGeo(); indexedUInt->setIndices(indexArray.p()); gridBorderDrawable->addPrimitiveSet(indexedUInt.p()); cvf::ref vertexArray = new cvf::Vec3fArray(vertices); gridBorderDrawable->setVertexArray(vertexArray.p()); drawables[GridBorder] = gridBorderDrawable; } { std::vector interpolatedGridPoints; std::vector interpolatedGridNormals; size_t newStartIndex = originalWellPathSize - wellPathPoints.size(); double firstMd = wellPathGeometry()->m_measuredDepths.at(newStartIndex); double lastMd = wellPathGeometry()->m_measuredDepths.back(); double md = lastMd; while (md >= firstMd) { cvf::Vec3d point = wellPathGeometry()->interpolatedPointAlongWellPath(md); cvf::Vec3d normal = wellPathGeometry()->interpolatedVectorAlongWellPath(wellPathSegmentNormals, md); interpolatedGridPoints.push_back(point); interpolatedGridNormals.push_back(normal.getNormalized()); md -= gridIntervalSize; } std::vector vertices; vertices.reserve(interpolatedGridPoints.size()); std::vector indices; indices.reserve(interpolatedGridPoints.size()); cvf::uint indexCounter = 0; // Normal lines. Start from one to avoid drawing at surface edge. for (size_t i = 1; i < interpolatedGridNormals.size(); i++) { vertices.push_back(cvf::Vec3f( displayCoordTransform->transformToDisplayCoord(interpolatedGridPoints[i] + interpolatedGridNormals[i] * planeOffsetFromWellPathCenter))); vertices.push_back(cvf::Vec3f(displayCoordTransform->transformToDisplayCoord( interpolatedGridPoints[i] + interpolatedGridNormals[i] * (planeOffsetFromWellPathCenter + planeWidth)))); indices.push_back(indexCounter++); indices.push_back(indexCounter++); } cvf::ref indexedUInt = new cvf::PrimitiveSetIndexedUInt(cvf::PrimitiveType::PT_LINES); cvf::ref indexArray = new cvf::UIntArray(indices); cvf::ref normalLinesDrawable = new cvf::DrawableGeo(); indexedUInt->setIndices(indexArray.p()); normalLinesDrawable->addPrimitiveSet(indexedUInt.p()); cvf::ref vertexArray = new cvf::Vec3fArray(vertices); normalLinesDrawable->setVertexArray(vertexArray.p()); drawables[NormalLines] = normalLinesDrawable; } return drawables; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const RigWellPath* Riv3dWellLogGridGeometryGenerator::wellPathGeometry() const { return m_wellPath->wellPathGeometry(); }