diff --git a/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.cpp b/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.cpp index 72083bf04a..dba5542126 100644 --- a/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.cpp +++ b/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.cpp @@ -25,12 +25,14 @@ #include "RigWellPathGeometryTools.h" #include "cafDisplayCoordTransform.h" + #include "cvfObject.h" -#include "cvfDrawableGeo.h" #include "cvfPrimitiveSetIndexedUInt.h" - #include "cvfBoundingBox.h" +#include "cvfGeometryBuilderTriangles.h" +#include "cvfArrowGenerator.h" +#include #include //-------------------------------------------------------------------------------------------------- @@ -195,34 +197,38 @@ Riv3dWellLogGridGeometryGenerator::createGrid(const caf::DisplayCoordTransform* } std::vector vertices; + std::vector arrowVectors; vertices.reserve(interpolatedGridPoints.size()); + arrowVectors.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. + double shaftRelativeRadius = 0.0125f; + double arrowHeadRelativeRadius = shaftRelativeRadius * 3; + double arrowHeadRelativeLength = arrowHeadRelativeRadius * 3; + double totalArrowScaling = 1.0 / (1.0 - arrowHeadRelativeLength); + // Normal lines. Start from one to avoid drawing at surface edge. for (size_t i = 1; i < interpolatedGridCurveNormals.size(); i++) { vertices.push_back(cvf::Vec3f(interpolatedGridPoints[i] + interpolatedGridCurveNormals[i] * planeOffsetFromWellPathCenter)); - vertices.push_back(cvf::Vec3f(interpolatedGridPoints[i] + interpolatedGridCurveNormals[i] * (planeOffsetFromWellPathCenter + planeWidth))); - - indices.push_back(indexCounter++); - indices.push_back(indexCounter++); + arrowVectors.push_back(cvf::Vec3f(interpolatedGridCurveNormals[i] * planeWidth * totalArrowScaling)); } - 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()); + m_curveNormalVectors = new cvf::DrawableVectors(); cvf::ref vertexArray = new cvf::Vec3fArray(vertices); - normalLinesDrawable->setVertexArray(vertexArray.p()); + cvf::ref vectorArray = new cvf::Vec3fArray(arrowVectors); - m_curveNormalLines = normalLinesDrawable; + // Create the arrow glyph for the vector drawer + cvf::GeometryBuilderTriangles arrowBuilder; + cvf::ArrowGenerator gen; + gen.setShaftRelativeRadius(shaftRelativeRadius); + gen.setHeadRelativeRadius(arrowHeadRelativeRadius); + gen.setHeadRelativeLength(arrowHeadRelativeLength); + gen.setNumSlices(4); + gen.generate(&arrowBuilder); + + m_curveNormalVectors->setGlyph(arrowBuilder.trianglesUShort().p(), arrowBuilder.vertices().p()); + m_curveNormalVectors->setVectors(vertexArray.p(), vectorArray.p()); } return true; } @@ -237,9 +243,9 @@ cvf::ref Riv3dWellLogGridGeometryGenerator::border() return m_border; } -cvf::ref Riv3dWellLogGridGeometryGenerator::curveNormalLines() +cvf::ref Riv3dWellLogGridGeometryGenerator::curveNormalVectors() { - return m_curveNormalLines; + return m_curveNormalVectors; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.h b/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.h index a0363811e0..36e69aef76 100644 --- a/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.h +++ b/ApplicationCode/ModelVisualization/Riv3dWellLogGridGeomertyGenerator.h @@ -20,6 +20,7 @@ #include "cvfBase.h" #include "cvfDrawableGeo.h" +#include "cvfDrawableVectors.h" #include "cvfObject.h" #include "cafPdmPointer.h" @@ -53,13 +54,13 @@ public: cvf::ref background(); cvf::ref border(); - cvf::ref curveNormalLines(); + cvf::ref curveNormalVectors(); private: const RigWellPath* wellPathGeometry() const; private: - caf::PdmPointer m_wellPath; - cvf::ref m_background; - cvf::ref m_border; - cvf::ref m_curveNormalLines; + caf::PdmPointer m_wellPath; + cvf::ref m_background; + cvf::ref m_border; + cvf::ref m_curveNormalVectors; }; diff --git a/ApplicationCode/ModelVisualization/Riv3dWellLogPlanePartMgr.cpp b/ApplicationCode/ModelVisualization/Riv3dWellLogPlanePartMgr.cpp index c7ab52fda0..8cccfe30d7 100644 --- a/ApplicationCode/ModelVisualization/Riv3dWellLogPlanePartMgr.cpp +++ b/ApplicationCode/ModelVisualization/Riv3dWellLogPlanePartMgr.cpp @@ -18,8 +18,9 @@ #include "Riv3dWellLogPlanePartMgr.h" -#include "RiaColorTables.h" +#include "RiaApplication.h" +#include "RiuViewer.h" #include "Rim3dView.h" #include "Rim3dWellLogCurveCollection.h" #include "RimCase.h" @@ -36,7 +37,9 @@ #include "cvfColor3.h" #include "cvfDrawableGeo.h" #include "cvfModelBasicList.h" +#include "cvfOpenGLResourceManager.h" #include "cvfPart.h" +#include "cvfShaderProgram.h" #include @@ -225,9 +228,10 @@ void Riv3dWellLogPlanePartMgr::appendGridToModel(cvf::ModelBasicList* bool showGrid = curveCollection->isShowingGrid(); bool showBackground = curveCollection->isShowingBackground(); + cvf::Color3f gridColor(0.4f, 0.4f, 0.4f); caf::SurfaceEffectGenerator backgroundEffectGen(cvf::Color4f(1.0, 1.0, 1.0, 1.0), caf::PO_2); - caf::MeshEffectGenerator gridBorderEffectGen(cvf::Color3f(0.4f, 0.4f, 0.4f)); - caf::MeshEffectGenerator curveNormalsEffectGen(cvf::Color3f(0.4f, 0.4f, 0.4f)); + caf::MeshEffectGenerator gridBorderEffectGen(gridColor); + caf::VectorEffectGenerator curveNormalsEffectGen; backgroundEffectGen.enableLighting(false); bool gridCreated = m_3dWellLogGridGeometryGenerator->createGrid(displayCoordTransform, @@ -241,7 +245,7 @@ void Riv3dWellLogPlanePartMgr::appendGridToModel(cvf::ModelBasicList* cvf::ref backgroundEffect = backgroundEffectGen.generateCachedEffect(); cvf::ref borderEffect = gridBorderEffectGen.generateCachedEffect(); cvf::ref curveNormalsEffect = curveNormalsEffectGen.generateCachedEffect(); - + cvf::ref background = m_3dWellLogGridGeometryGenerator->background(); if (showBackground && background.notNull()) { @@ -263,9 +267,15 @@ void Riv3dWellLogPlanePartMgr::appendGridToModel(cvf::ModelBasicList* } } - cvf::ref normals = m_3dWellLogGridGeometryGenerator->curveNormalLines(); + cvf::ref normals = m_3dWellLogGridGeometryGenerator->curveNormalVectors(); if (normals.notNull()) { + normals->setSingleColor(gridColor); + if (RiaApplication::instance()->useShaders()) + { + normals->setUniformNames("u_transformationMatrix", "u_color"); + } + cvf::ref part = createPart(normals.p(), curveNormalsEffect.p()); if (part.notNull()) { diff --git a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp index 38d953b83f..813bf2e423 100644 --- a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp +++ b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp @@ -991,4 +991,58 @@ void TextEffectGenerator::updateForFixedFunctionRendering(cvf::Effect* effect) c } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +VectorEffectGenerator::VectorEffectGenerator() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool VectorEffectGenerator::isEqual(const EffectGenerator* other) const +{ + const VectorEffectGenerator* otherSurfaceEffect = dynamic_cast(other); + if (otherSurfaceEffect) + { + return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +EffectGenerator* VectorEffectGenerator::copy() const +{ + VectorEffectGenerator* effGen = new VectorEffectGenerator; + + return effGen; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void VectorEffectGenerator::updateForShaderBasedRendering(cvf::Effect* effect) const +{ + cvf::ShaderProgramGenerator gen("VectorDrawerShaderProgram", cvf::ShaderSourceProvider::instance()); + gen.addVertexCode(cvf::ShaderSourceRepository::vs_VectorDrawer); + gen.addFragmentCode(cvf::ShaderSourceRepository::fs_VectorDrawer); + + cvf::ref shaderProg = gen.generate(); + shaderProg->disableUniformTrackingForUniform("u_transformationMatrix"); + shaderProg->disableUniformTrackingForUniform("u_color"); + + cvf::ref eff = effect; + eff->setShaderProgram(shaderProg.p()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void VectorEffectGenerator::updateForFixedFunctionRendering(cvf::Effect* effect) const {} + } // End namespace caf diff --git a/Fwk/AppFwk/CommonCode/cafEffectGenerator.h b/Fwk/AppFwk/CommonCode/cafEffectGenerator.h index 48768cdefc..95875971b8 100644 --- a/Fwk/AppFwk/CommonCode/cafEffectGenerator.h +++ b/Fwk/AppFwk/CommonCode/cafEffectGenerator.h @@ -276,4 +276,21 @@ protected: }; +//================================================================================================== +// +// VectorEffectGenerator +// +//================================================================================================== +class VectorEffectGenerator : public EffectGenerator +{ +public: + VectorEffectGenerator(); + +protected: + virtual bool isEqual(const EffectGenerator* other) const; + virtual EffectGenerator* copy() const; + + virtual void updateForShaderBasedRendering(cvf::Effect* effect) const; + virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const; +}; } diff --git a/Fwk/VizFwk/LibRender/cvfDrawableVectors.cpp b/Fwk/VizFwk/LibRender/cvfDrawableVectors.cpp index d07c79291d..a7c191ac1f 100644 --- a/Fwk/VizFwk/LibRender/cvfDrawableVectors.cpp +++ b/Fwk/VizFwk/LibRender/cvfDrawableVectors.cpp @@ -125,6 +125,12 @@ void DrawableVectors::setSingleColor(Color3f color) } +void DrawableVectors::setUniformNames(String vectorMatrixUniformName, String colorUniformName) +{ + m_vectorMatrixUniformName = vectorMatrixUniformName; + m_colorUniformName = colorUniformName; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/VizFwk/LibRender/cvfDrawableVectors.h b/Fwk/VizFwk/LibRender/cvfDrawableVectors.h index 18798b1fce..bdf9f9c901 100644 --- a/Fwk/VizFwk/LibRender/cvfDrawableVectors.h +++ b/Fwk/VizFwk/LibRender/cvfDrawableVectors.h @@ -63,6 +63,7 @@ public: void setGlyph(UShortArray* triangles, Vec3fArray* vertices); void setSingleColor(Color3f color); + void setUniformNames(String vectorMatrixUniformName, String colorUniformName); void setVectors(Vec3fArray* vertexArray, Vec3fArray* vectorArray); void setColors(Color3fArray* vectorColorArray); size_t vectorCount() const;