| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | #include <limits>
|
|---|
| 4 | #include <algorithm>
|
|---|
| 5 | #include <list>
|
|---|
| 6 |
|
|---|
| 7 | #include "gwutil.h"
|
|---|
| 8 | #include "fluidyn.h"
|
|---|
| 9 | #include "geomorph.h"
|
|---|
| 10 | #include "synthsession.h"
|
|---|
| 11 | #include "gmregistry.h"
|
|---|
| 12 |
|
|---|
| 13 | namespace geoworld
|
|---|
| 14 | {
|
|---|
| 15 | namespace ofc
|
|---|
| 16 | {
|
|---|
| 17 | typedef mars::ParabolicFn<float, -1> EaseInFn; // Used for tapering the flow line
|
|---|
| 18 | typedef mars::ParabolicFn<float, -1> EaseOutFn; // Used for tapering the flow line
|
|---|
| 19 |
|
|---|
| 20 | const static EaseInFn EASE_IN_FN (1, 1.1f, -1.001f);
|
|---|
| 21 | const static EaseOutFn EASE_OUT_FN (1, 1.1f, -1.001f);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | class OutflowChannelGM : public HeightMapGeoMorph, public BoundedGeoMorph
|
|---|
| 25 | {
|
|---|
| 26 | private:
|
|---|
| 27 | class OutflowChannelData
|
|---|
| 28 | {
|
|---|
| 29 | public:
|
|---|
| 30 | GeoHeightMap::View & view;
|
|---|
| 31 | GeoHeightMap hmbb;
|
|---|
| 32 |
|
|---|
| 33 | OutflowChannelData (GeoHeightMap::View * pView)
|
|---|
| 34 | : view(*pView), hmbb(*pView) {}
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | class FluiDynQueryBridge : public fldyn::IQueryBridge <FluiDynQueryBridge, FieldReal, GeoHeightMap::Precision>
|
|---|
| 38 | {
|
|---|
| 39 | private:
|
|---|
| 40 | const IGeoWorldAccessor * _pAccessor;
|
|---|
| 41 | const GMScalarField * _pfsDensity;
|
|---|
| 42 | const GWSurfacePos _ptOffset;
|
|---|
| 43 |
|
|---|
| 44 | public:
|
|---|
| 45 | inline FluiDynQueryBridge (const IGeoWorldAccessor * pAccessor, const GWSurfacePos & ptOffset)
|
|---|
| 46 | : _pAccessor (pAccessor), _pfsDensity(pAccessor->queryField(FT_Density)), _ptOffset(ptOffset) {}
|
|---|
| 47 |
|
|---|
| 48 | inline DensityPrecision density (const GeoHeightMap::Precision x, const GeoHeightMap::Precision y, const GeoHeightMap::Precision z) const
|
|---|
| 49 | { return (*_pfsDensity) (x + _ptOffset.x, y + _ptOffset.y, z); }
|
|---|
| 50 | inline DensityPrecision density (const GeoHeightMap::Precision x, const GeoHeightMap::Precision y) const
|
|---|
| 51 | { return (*_pfsDensity) (x + _ptOffset.x, y + _ptOffset.y, (*_pAccessor)(x + _ptOffset.x, y + _ptOffset.y)); }
|
|---|
| 52 | inline GeoHeightMap::Precision elevation (const unsigned int x, const unsigned int y) const
|
|---|
| 53 | { return _pAccessor->mean(x + _ptOffset.x, y + _ptOffset.y); }
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | public:
|
|---|
| 57 | typedef mars::MidpointDisplacementGrid< typename GeoHeightMap::Precision > PerturbMapType;
|
|---|
| 58 | typedef mars::vector2D< float > PointType;
|
|---|
| 59 | typedef fldyn::ChannelSet <FluiDynQueryBridge, float, typename GeoHeightMap::Precision, OutflowChannelData> ChannelSetType;
|
|---|
| 60 | typedef fldyn::PathFinder <FluiDynQueryBridge, float, typename GeoHeightMap::Precision> ChannelFinderType;
|
|---|
| 61 | typedef ChannelFinderType::FlowLineType::Iterator<typename GeoHeightMap::Precision, ofc::EaseInFn, ofc::EaseOutFn> RasterIteratorType;
|
|---|
| 62 |
|
|---|
| 63 | private:
|
|---|
| 64 | class MyChannelSet : public ChannelSetType
|
|---|
| 65 | {
|
|---|
| 66 | private:
|
|---|
| 67 | class BevelFn : public mars::GaussianFn< float, -1 >
|
|---|
| 68 | {
|
|---|
| 69 | private:
|
|---|
| 70 | float _frDepth;
|
|---|
| 71 |
|
|---|
| 72 | public:
|
|---|
| 73 | BevelFn (const float frDepth)
|
|---|
| 74 | : GaussianFn(1.0f, frDepth, 1.0f / 3.0f, 0.0f), _frDepth(frDepth) {}
|
|---|
| 75 |
|
|---|
| 76 | BevelFn & operator = (const BevelFn & copy)
|
|---|
| 77 | {
|
|---|
| 78 | mars::GaussianFn< float, -1 >::operator = (copy);
|
|---|
| 79 | _frDepth = copy._frDepth;
|
|---|
| 80 | return *this;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | inline float getBevelDepth () const { return _frDepth; }
|
|---|
| 84 |
|
|---|
| 85 | inline const float rforce (const float t) const
|
|---|
| 86 | {
|
|---|
| 87 | return -f(t) / _frDepth;
|
|---|
| 88 | }
|
|---|
| 89 | inline const float bevel (const float t) const
|
|---|
| 90 | {
|
|---|
| 91 | return f(t) / _frDepth;
|
|---|
| 92 | }
|
|---|
| 93 | } _fnBevel;
|
|---|
| 94 |
|
|---|
| 95 | const ofc::EaseInFn _fnEaseIn;
|
|---|
| 96 | const ofc::EaseOutFn _fnEaseOut;
|
|---|
| 97 |
|
|---|
| 98 | PerturbMapType * _perturb;
|
|---|
| 99 | mars::RingBuffer< HMPrec > * _prbSediment;
|
|---|
| 100 |
|
|---|
| 101 | protected:
|
|---|
| 102 | virtual void applyFlowLine (const FlowLineType & fl, OutflowChannelData * pData) const;
|
|---|
| 103 |
|
|---|
| 104 | public:
|
|---|
| 105 | MyChannelSet ();
|
|---|
| 106 | MyChannelSet(
|
|---|
| 107 | const mars::RangeX< float > & mmfBendZenith,
|
|---|
| 108 | const unsigned int nBendZenithSteps,
|
|---|
| 109 | const unsigned int nCandidateSampleAmt,
|
|---|
| 110 | const mars::RangeX< float > & mmfSplineSeg,
|
|---|
| 111 | const float fGravitySlopeGrace,
|
|---|
| 112 | const float fCarveWeight,
|
|---|
| 113 | const float frSnapToGuide,
|
|---|
| 114 | const mars::RangeX< float > & mmfFlowLineWidth,
|
|---|
| 115 | const mars::RangeX< unsigned int > & mmnKidsPerLevel,
|
|---|
| 116 | const float fwStraightness,
|
|---|
| 117 | const float fwElevationInfluence,
|
|---|
| 118 | const float fwDensityInfluence,
|
|---|
| 119 | const float fwChaosInfluence,
|
|---|
| 120 | const unsigned int nSedimentHistorySize
|
|---|
| 121 | );
|
|---|
| 122 |
|
|---|
| 123 | void init ( const mars::ptr< FluiDynQueryBridge > & pQuery, const unsigned int nLevels, const mars::BBox< float > & bboxSearch );
|
|---|
| 124 | void run ( GeoHeightMap::View * pView ) const;
|
|---|
| 125 |
|
|---|
| 126 | mars::ObjectStream & operator >> (mars::ObjectStream & outs) const;
|
|---|
| 127 | mars::ObjectStream & operator << (mars::ObjectStream & ins);
|
|---|
| 128 |
|
|---|
| 129 | ~MyChannelSet();
|
|---|
| 130 | } _chans;
|
|---|
| 131 |
|
|---|
| 132 | GWSurfacePos _ptStart;
|
|---|
| 133 | mars::RangeX< float > _mmfFlowLineWidth, _mmfSourceDisplacement;
|
|---|
| 134 | mars::RangeX< unsigned int>
|
|---|
| 135 | _mmnLevels;
|
|---|
| 136 | mars::BBox< long > _bbox;
|
|---|
| 137 |
|
|---|
| 138 | float
|
|---|
| 139 | _fSourceSpread,
|
|---|
| 140 | _fGeneralDir;
|
|---|
| 141 | unsigned int _nSourcePoints;
|
|---|
| 142 |
|
|---|
| 143 | OutflowChannelGM();
|
|---|
| 144 |
|
|---|
| 145 | public:
|
|---|
| 146 | OutflowChannelGM(
|
|---|
| 147 | const GWSurfacePos & ptStart,
|
|---|
| 148 | const float fGeneralDir,
|
|---|
| 149 | const unsigned int nSourcePoints,
|
|---|
| 150 | const mars::RangeX< float > & mmfSourceDisplacement,
|
|---|
| 151 | const float fSourceSpread,
|
|---|
| 152 | const mars::RangeX< float > & mmfBendZenith,
|
|---|
| 153 | const unsigned int nBendZenithSteps,
|
|---|
| 154 | const unsigned int nCandidateSampleAmt,
|
|---|
| 155 | const mars::RangeX< float > & mmfSplineSeg,
|
|---|
| 156 | const float fGravitySlopeGrace,
|
|---|
| 157 | const float fCarveWeight,
|
|---|
| 158 | const float frSnapToGuide,
|
|---|
| 159 | const mars::RangeX< float > & mmfFlowLineWidth,
|
|---|
| 160 | const mars::RangeX< unsigned int > & mmnLevels,
|
|---|
| 161 | const mars::RangeX< unsigned int > & mmnKidsPerLevel,
|
|---|
| 162 | const float fwStraightness,
|
|---|
| 163 | const float fwElevationInfluence,
|
|---|
| 164 | const float fwDensityInfluence,
|
|---|
| 165 | const float fwChaosInfluence,
|
|---|
| 166 | const unsigned int nSedimentHistorySize
|
|---|
| 167 | );
|
|---|
| 168 | ~OutflowChannelGM();
|
|---|
| 169 |
|
|---|
| 170 | virtual void init (SynthesisSession & manager, const IGeoWorldAccessor & accessor, const unsigned short nMaxWidth, const unsigned short nMaxHeight);
|
|---|
| 171 | virtual mars::BBox< long > getBBox() const { return _bbox; }
|
|---|
| 172 | virtual void doMorph (LockedGWSection & section) const;
|
|---|
| 173 |
|
|---|
| 174 | static OutflowChannelGM * createInstance (mars::ObjectStream & ins);
|
|---|
| 175 | mars::ObjectStream & operator >> (mars::ObjectStream & outs) const;
|
|---|
| 176 | };
|
|---|
| 177 |
|
|---|
| 178 | inline mars::ObjectStream & operator << (OutflowChannelGM *& pGM, mars::ObjectStream & ins)
|
|---|
| 179 | {
|
|---|
| 180 | pGM = OutflowChannelGM::createInstance(ins);
|
|---|
| 181 | return ins;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | class OutflowChannelGMFactory : public GeoMorphFactory, public IPersistentGeoMorphFactory, public ISurfaceBoundedGeoMorphFactory
|
|---|
| 185 | {
|
|---|
| 186 | private:
|
|---|
| 187 | mars::RangeX< float >
|
|---|
| 188 | _mmfBendZenith,
|
|---|
| 189 | _mmfSplineSeg,
|
|---|
| 190 | _mmfFlowLineWidth,
|
|---|
| 191 | _mmfSourceSpread,
|
|---|
| 192 | _mmfSourceDisplacement;
|
|---|
| 193 |
|
|---|
| 194 | mars::RangeX< unsigned int>
|
|---|
| 195 | _mmnSourcePoints,
|
|---|
| 196 | _mmnLevels,
|
|---|
| 197 | _mmnKidsPerLevel;
|
|---|
| 198 |
|
|---|
| 199 | unsigned int
|
|---|
| 200 | _nBendZenithSteps,
|
|---|
| 201 | _nCandidateSampleAmount,
|
|---|
| 202 | _nSedimentHistorySize;
|
|---|
| 203 |
|
|---|
| 204 | float
|
|---|
| 205 | _fGravitySlopeGrace,
|
|---|
| 206 | _fCarveWeight,
|
|---|
| 207 | _frSnapToGuide,
|
|---|
| 208 | _fwStraightness,
|
|---|
| 209 | _fwElevationInfluence,
|
|---|
| 210 | _fwDensityInfluence,
|
|---|
| 211 | _fwChaosInfluence;
|
|---|
| 212 |
|
|---|
| 213 | public:
|
|---|
| 214 | virtual GeoMorph * createRandomInstance(const long x, const long y) const;
|
|---|
| 215 | virtual void configure( IConfigGMFactory * pFactoryConfig, const IConfigGMFactory::Settings & settings );
|
|---|
| 216 | virtual void save (const GeoMorph * pGM, mars::ObjectStream & outs) const;
|
|---|
| 217 | virtual const GeoMorph * restore (mars::ObjectStream & ins) const;
|
|---|
| 218 | };
|
|---|
| 219 | } |
|---|