///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2020- Equinor 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. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include "RiaDefines.h" #include "cvfObject.h" #include "cafPdmPointer.h" #include "cafSignal.h" #include "cvfCollection.h" #include "cvfPart.h" #include "cvfVector3.h" #include namespace cvf { class ModelBasicList; class ScalarMapper; class ScalarMapperDiscreteLinear; } // namespace cvf class RimEclipseView; class RimStreamlineInViewCollection; class Rim3dView; class RivStreamlinesPartMgr : public cvf::Object, public caf::SignalObserver { public: RivStreamlinesPartMgr( RimEclipseView* reservoirView ); ~RivStreamlinesPartMgr() override; void appendDynamicGeometryPartsToModel( cvf::ModelBasicList* model, size_t timeStepIndex ); void updateAnimation(); private: struct StreamlineSegment { /* x_ij(t) = a_ij + b_ij * t + c_ij * t^2 + d_ij * t^3 */ StreamlineSegment(){}; StreamlineSegment( cvf::Vec3d startPoint, cvf::Vec3d endPoint, cvf::Vec3d startDirection, cvf::Vec3d endDirection, double startVelocity, double endVelocity ) : startPoint( startPoint ) , endPoint( endPoint ) , startDirection( startDirection ) , endDirection( endDirection ) , startVelocity( startVelocity ) , endVelocity( endVelocity ) { computeSegments(); }; void computeSegments(); cvf::Vec3d getPointAt( double localT ) const; cvf::Vec3d getDirectionAt( double localT ) const; double getVelocityAt( double localT ) const; double getChordLength() const; cvf::Vec3d startPoint; cvf::Vec3d endPoint; cvf::Vec3d startDirection; cvf::Vec3d endDirection; double globalTStart; double globalTEnd; double startVelocity; double endVelocity; private: cvf::Vec3d a; cvf::Vec3d b; cvf::Vec3d c; cvf::Vec3d d; }; struct StreamlineVisualization { StreamlineVisualization() { areTValuesComputed = false; currentAnimationGlobalT = 0.0; }; void computeTValues(); void appendSegment( StreamlineSegment segment ); void prependSegment( StreamlineSegment segment ); void appendPart( cvf::ref part, double globalT ); size_t segmentsSize() const; std::list getSegments(); void clear(); void updateAnimationGlobalT( double timeMs ); double getApproximatedTotalLength(); cvf::Vec3d getPointAt( double globalT ) const; cvf::Vec3d getDirectionAt( double globalT ) const; double getVelocityAt( double globalT ) const; cvf::Collection getParts(); cvf::ref getPartAtGlobalT( double globalT ) const; double currentAnimationGlobalT; private: bool areTValuesComputed; double approximatedTotalLength; std::list segments; cvf::Collection parts; std::vector partTValues; }; struct Streamline { Streamline() { animIndex = 0; }; void appendTracerPoint( cvf::Vec3d point ); void appendAbsVelocity( double velocity ); void appendDirection( cvf::Vec3d direction ); void appendPhase( RiaDefines::PhaseType phase ); void clear(); cvf::ref getPart(); cvf::Vec3d getTracerPoint( size_t index ) const; double getAbsVelocity( size_t index ) const; cvf::Vec3d getDirection( size_t index ) const; RiaDefines::PhaseType getPhase( size_t index ) const; size_t countTracerPoints() const; void setPart( cvf::ref part ); size_t getAnimationIndex() const; void incrementAnimationIndex( size_t increment = 1.0 ); void setAnimationIndex( size_t index ); private: std::vector tracerPoints; std::vector absVelocities; std::vector directions; std::vector dominantPhases; cvf::ref part; size_t animIndex; }; private: cvf::ref createPart( const RimStreamlineInViewCollection& streamlineCollection, Streamline& streamlineVisualization ); void createResultColorTextureCoords( cvf::Vec2fArray* textureCoords, const Streamline& streamline, const cvf::ScalarMapper* mapper ); cvf::ref createVectorPart( const RimStreamlineInViewCollection& streamlineCollection, Streamline& segment ); std::array createArrowVertices( const cvf::Vec3f anchorPoint, const cvf::Vec3f direction ) const; std::array createArrowShaftIndices( uint startIndex ) const; std::array createArrowHeadIndices( uint startIndex ) const; void setAlpha( cvf::ref part, float alpha ); private: std::list m_streamlines; caf::PdmPointer m_rimReservoirView; uint m_count; size_t m_currentT; bool m_showAsVectors; };