[80a6a52] | 1 | #include "crater.h"
|
---|
| 2 | #include "mars_ptr.h"
|
---|
| 3 | #include "geoworld.h"
|
---|
| 4 |
|
---|
| 5 | namespace geoworld
|
---|
| 6 | {
|
---|
| 7 | void CraterGM::init(SynthesisSession & manager, const IGeoWorldAccessor & accessor, const unsigned short nMaxWidth, const unsigned short nMaxHeight)
|
---|
| 8 | {
|
---|
| 9 | _gcOrigin = accessor.createCoords(_ptOrigin);
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | void CraterGM::doMorph (LockedGWSection & section) const
|
---|
| 13 | {
|
---|
| 14 | using namespace mars;
|
---|
| 15 | using namespace geoworld;
|
---|
| 16 |
|
---|
| 17 | const unsigned short nDim = static_cast <unsigned short> (_zones.puz.outside() * 2.0f);
|
---|
| 18 |
|
---|
| 19 | mars::ptr< NoiseGenerator< float >::NoiseMap > pMPField = _noise.compute(nDim, nDim);
|
---|
| 20 | for (PerimiterUpliftZone::UpsideDEMIterator <PerimiterUpliftZone> it = _zones.puz.walkUpside (_gcOrigin); it; ++it)
|
---|
| 21 | {
|
---|
| 22 | section.heightmap(it->x, it->y) =
|
---|
| 23 | blend(
|
---|
| 24 | section.heightmap(it->x, it->y),
|
---|
| 25 | it->z + (*pMPField)(it->x, it->y),
|
---|
| 26 | _zones.puz.outslope.taper.f (
|
---|
| 27 | static_cast< float > (it->x - _ptOrigin.x),
|
---|
| 28 | static_cast< float > (it->y - _ptOrigin.y)
|
---|
| 29 | )
|
---|
| 30 | );
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | // TODO: Why are we walking the downside? is this an inverted function?
|
---|
| 34 | for (CraterZone::DownsideDEMIterator <CraterZone> it = _zones.czone.walkDownside (_gcOrigin); it; ++it)
|
---|
| 35 | {
|
---|
| 36 | section.heightmap(it->x, it->y) = static_cast< GeoHeightMap::Precision > (mars::RNDi(it->z + pMPField->getw(it->x, it->y))); // TODO: Verify use of RNDi
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | for (CentralUpliftZone::UpsideDEMIterator <CentralUpliftZone> it = _zones.central.walkUpside (_gcOrigin); it; ++it)
|
---|
| 40 | {
|
---|
| 41 | section.heightmap(it->x, it->y) = static_cast< GeoHeightMap::Precision > (mars::RNDi(it->z + pMPField->getw(it->x, it->y))); // TODO: Verify use of RNDi
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | GMScalarField * CraterGM::queryField( const FieldType enft, const GeoHeightMap & hm )
|
---|
| 46 | {
|
---|
| 47 | switch (enft)
|
---|
| 48 | {
|
---|
| 49 | case FT_Density: return new DensityScalarField(_zones.density, _gcOrigin);
|
---|
| 50 | default: return NULL;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void CraterGM::releaseField( const GMScalarField * pField )
|
---|
| 55 | {
|
---|
| 56 | delete pField;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | mars::BBox< long > CraterGM::getBBox() const
|
---|
| 60 | {
|
---|
| 61 | return mars::BBox< long > (
|
---|
| 62 | _ptOrigin - static_cast< long > (floor (_zones.puz.outside())),
|
---|
| 63 | _ptOrigin + static_cast< long > (ceil (_zones.puz.outside()))
|
---|
| 64 | );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | mars::ptr< PersistentGeoMorph::State > CraterGM::createState() const
|
---|
| 68 | {
|
---|
| 69 | CraterGMState * pState = new CraterGMState();
|
---|
| 70 |
|
---|
| 71 | pState->fBowlDepth = -_zones.czone.bowl.depth;
|
---|
| 72 | pState->fCentralUpliftBroadnessScale = _fCentralUpliftBroadnessScale;
|
---|
| 73 | pState->fCentralUpliftDepthScale = _fCentralUpliftDepthScale;
|
---|
| 74 | pState->frBowlBroadness = _zones.czone.bowl.broadness;
|
---|
| 75 | pState->frNoise = _noise.noise;
|
---|
| 76 | pState->frScale = _zones.czone.bowl.scale;
|
---|
| 77 | pState->fSpallFalloffFactor = _zones.puz.outslope.falloff;
|
---|
| 78 | pState->gcOrigin = _gcOrigin;
|
---|
| 79 | pState->ptOrigin = _ptOrigin;
|
---|
| 80 |
|
---|
| 81 | return dynamic_cast< PersistentGeoMorph::State * > (pState);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | CraterGM::CraterGM( const VectorTag< GeoHeightMap::Precision >::V2 & ptOrigin, const float frSample, const float frScale, const float frBowlBroadness, const float fBowlDepth, const float fSpallFalloffFactor, const float frNoise, const float fCentralUpliftDepthScale, const float fCentralUpliftBroadnessScale )
|
---|
| 85 | :
|
---|
| 86 | _zones(
|
---|
| 87 | CraterZone(
|
---|
| 88 | BowlFn(
|
---|
| 89 | frScale,
|
---|
| 90 | frBowlBroadness,
|
---|
| 91 | -fBowlDepth
|
---|
| 92 | )
|
---|
| 93 | ),
|
---|
| 94 | PerimeterUpsideEq(
|
---|
| 95 | frScale,
|
---|
| 96 | frBowlBroadness,
|
---|
| 97 | 0.0f
|
---|
| 98 | ),
|
---|
| 99 | PerimeterDownsideEq(
|
---|
| 100 | frScale,
|
---|
| 101 | frBowlBroadness / 4.0f * mars::SQ(-fBowlDepth),
|
---|
| 102 | 0.0f
|
---|
| 103 | ),
|
---|
| 104 | CentralUpliftEq(
|
---|
| 105 | frScale,
|
---|
| 106 | 1.0f,
|
---|
| 107 | fCentralUpliftBroadnessScale * frBowlBroadness,
|
---|
| 108 | -fBowlDepth * fCentralUpliftDepthScale
|
---|
| 109 | ),
|
---|
| 110 | fSpallFalloffFactor
|
---|
| 111 | ),
|
---|
| 112 | _fCentralUpliftDepthScale(fCentralUpliftDepthScale),
|
---|
| 113 | _fCentralUpliftBroadnessScale(fCentralUpliftBroadnessScale),
|
---|
| 114 | _noise (0.4f, frNoise),
|
---|
| 115 | // TODO: Messy redundant EqSet instantiation to satisfy constructor member initialization limitations
|
---|
| 116 | _ptOrigin(ptOrigin)
|
---|
| 117 | {}
|
---|
| 118 |
|
---|
| 119 | CraterGM::CraterGM( const CraterGMState & state )
|
---|
| 120 | : _zones(
|
---|
| 121 | CraterZone(
|
---|
| 122 | BowlFn(
|
---|
| 123 | state.frScale,
|
---|
| 124 | state.frBowlBroadness,
|
---|
| 125 | -state.fBowlDepth
|
---|
| 126 | )
|
---|
| 127 | ),
|
---|
| 128 | PerimeterUpsideEq(
|
---|
| 129 | state.frScale,
|
---|
| 130 | state.frBowlBroadness,
|
---|
| 131 | 0.0f
|
---|
| 132 | ),
|
---|
| 133 | PerimeterDownsideEq(
|
---|
| 134 | state.frScale,
|
---|
| 135 | state.frBowlBroadness / 4.0f * mars::SQ(-state.fBowlDepth),
|
---|
| 136 | 0.0f
|
---|
| 137 | ),
|
---|
| 138 | CentralUpliftEq(
|
---|
| 139 | state.frScale,
|
---|
| 140 | 1.0f,
|
---|
| 141 | state.fCentralUpliftBroadnessScale * state.frBowlBroadness,
|
---|
| 142 | -state.fBowlDepth * state.fCentralUpliftDepthScale
|
---|
| 143 | ),
|
---|
| 144 | state.fSpallFalloffFactor
|
---|
| 145 | ),
|
---|
| 146 | _fCentralUpliftDepthScale(state.fCentralUpliftDepthScale),
|
---|
| 147 | _fCentralUpliftBroadnessScale(state.fCentralUpliftBroadnessScale),
|
---|
| 148 | _noise (0.4f, state.frNoise),
|
---|
| 149 | // TODO: Messy redundant EqSet instantiation to satisfy constructor member initialization limitations
|
---|
| 150 | _ptOrigin(state.ptOrigin),
|
---|
| 151 | _gcOrigin(state.gcOrigin)
|
---|
| 152 | {}
|
---|
| 153 |
|
---|
| 154 | CraterGM::DensityScalarField::ResultType CraterGM::DensityScalarField::operator () (const IndexType x, const IndexType y, const IndexType z) const
|
---|
| 155 | {
|
---|
| 156 | return std::max(1.0f, _zone.upside(static_cast< float > (x), static_cast< float > (y)));
|
---|
| 157 | }
|
---|
| 158 | CraterGM::DensityGradientField::ResultType CraterGM::DensityGradientField::operator () (const IndexType x, const IndexType y, const IndexType z) const
|
---|
| 159 | {
|
---|
| 160 | using namespace mars;
|
---|
| 161 |
|
---|
| 162 | const vector3Df dir (
|
---|
| 163 | static_cast< float > (_gcOrigin.x - x),
|
---|
| 164 | static_cast< float > (_gcOrigin.y - y),
|
---|
| 165 | static_cast< float > (_gcOrigin.z - z)
|
---|
| 166 | );
|
---|
| 167 |
|
---|
| 168 | const float fMag = MAG(dir);
|
---|
| 169 |
|
---|
| 170 | return fMag > _zone.outside() ? vector3Df() : -mars::U(dir) * _zone.upsideGrad(static_cast< float > (x), static_cast< float > (y));
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | CraterGMFactory::~CraterGMFactory() {}
|
---|
| 174 |
|
---|
| 175 | GeoMorph * CraterGMFactory::createRandomInstance( const long x, const long y ) const
|
---|
| 176 | {
|
---|
| 177 | return new CraterGM(
|
---|
| 178 | GWSurfacePos(x, y),
|
---|
| 179 | _rngfrSample.next(),
|
---|
| 180 | _rngfrScale.next(),
|
---|
| 181 | _rngfrBowlBroadness.next(),
|
---|
| 182 | _rngfBowlDepth.next(),
|
---|
| 183 | _fSpallFalloffFactor,
|
---|
| 184 | _frNoise,
|
---|
| 185 | _fCentralUpliftDepthScale,
|
---|
| 186 | _fCentralUpliftBroadnessScale
|
---|
| 187 | );
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | void CraterGMFactory::configure( IConfigGMFactory * pFactoryConfig, const IConfigGMFactory::Settings & settings )
|
---|
| 191 | {
|
---|
| 192 | const geoworld::IConfigSection & section = *pFactoryConfig->getSection();
|
---|
| 193 |
|
---|
| 194 | *section["sample"] >> _rngfrSample;
|
---|
| 195 | *section["scale"] >> _rngfrScale;
|
---|
| 196 | *section["broadness"] >> _rngfrBowlBroadness;
|
---|
| 197 | *section["depth"] >> _rngfBowlDepth;
|
---|
| 198 | *section["falloff"] >> _fSpallFalloffFactor;
|
---|
| 199 | *section["noise"] >> _frNoise;
|
---|
| 200 | *section["uplift_depth"] >> _fCentralUpliftDepthScale;
|
---|
| 201 | *section["uplift_broadness"] >> _fCentralUpliftBroadnessScale;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | void CraterGMFactory::save( const GeoMorph * pGM, mars::ObjectStream & outs ) const
|
---|
| 205 | {
|
---|
| 206 | const CraterGM * pCraterGM = dynamic_cast< const CraterGM * > (pGM);
|
---|
| 207 | assert(pCraterGM != NULL);
|
---|
| 208 | *(pCraterGM->createState()) >> outs;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | const GeoMorph * CraterGMFactory::restore( mars::ObjectStream & ins ) const
|
---|
| 212 | {
|
---|
| 213 | CraterGM::CraterGMState state;
|
---|
| 214 |
|
---|
| 215 | state << ins;
|
---|
| 216 | return new CraterGM(state);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | mars::ObjectStream & CraterGM::CraterGMState::operator >> ( mars::ObjectStream & outs ) const
|
---|
| 220 | {
|
---|
| 221 | outs << frScale << frBowlBroadness << fBowlDepth << fCentralUpliftBroadnessScale << fCentralUpliftDepthScale << fSpallFalloffFactor << frNoise << ptOrigin << gcOrigin;
|
---|
| 222 | return outs;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | mars::ObjectStream & CraterGM::CraterGMState::operator << ( mars::ObjectStream & ins )
|
---|
| 226 | {
|
---|
| 227 | ins >> frScale >> frBowlBroadness >> fBowlDepth >> fCentralUpliftBroadnessScale >> fCentralUpliftDepthScale >> fSpallFalloffFactor >> frNoise >> ptOrigin >> gcOrigin;
|
---|
| 228 | return ins;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | }
|
---|