MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / simulateOne

Method simulateOne

source/MRMesh/MRPrecipitationSimulator.cpp:23–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23auto PrecipitationSimulator::simulateOne() -> SimulationStep
24{
25 SimulationStep res;
26 const auto [basin, amount] = heap_.top();
27 if ( amount == infAmount )
28 return res;
29 res.amount = amount;
30
31 auto& info = wg_.basinInfo( basin );
32 assert( !info.overflowVia );
33 info.lastUpdateAmount = amount;
34 info.accVolume = info.maxVolume;
35
36 for ( auto bd : wg_.graph().neighbours( basin ) )
37 {
38 const auto & bdInfo = wg_.bdInfo( bd );
39 if ( wg_.getHeightAt( bdInfo.lowestVert ) != info.lowestBdLevel )
40 continue;
41 const auto neiBasin = wg_.graph().ends( bd ).otherEnd( basin );
42 res.basin = basin;
43 res.neiBasin = neiBasin;
44 auto targetBasin = wg_.flowsFinallyTo( neiBasin );
45 if ( targetBasin == basin )
46 {
47 res.event = Event::Merge;
48 auto& neiInfo = wg_.basinInfo( neiBasin );
49 // all flow from nei was already in basin:
50 assert( info.area >= neiInfo.area );
51 neiInfo.area = 0;
52 wg_.merge( basin, neiBasin );
53 heap_.setSmallerValue( neiBasin, infAmount );
54 heap_.setSmallerValue( basin, amount + info.amountTillOverflow() );
55 return res;
56 }
57 auto v = neiBasin;
58 for (;;)
59 {
60 auto& vInfo = wg_.basinInfo( v );
61 if ( !vInfo.overflowVia )
62 vInfo.updateAccVolume( amount );
63 vInfo.area += info.area;
64 auto v2 = wg_.flowsTo( v );
65 if ( v2 == v )
66 {
67 if ( targetBasin != wg_.outsideId() )
68 heap_.setLargerValue( v, amount + vInfo.amountTillOverflow() );
69 break;
70 }
71 v = v2;
72 }
73 assert( v == targetBasin );
74 heap_.setSmallerValue( basin, infAmount );
75 info.overflowVia = bd;
76 res.event = Event::BasinFull;
77 return res;
78 }
79 assert( false );
80 heap_.setSmallerValue( basin, infAmount );

Callers

nothing calls this directly

Calls 10

getHeightAtMethod · 0.80
otherEndMethod · 0.80
flowsFinallyToMethod · 0.80
setSmallerValueMethod · 0.80
amountTillOverflowMethod · 0.80
updateAccVolumeMethod · 0.80
flowsToMethod · 0.80
outsideIdMethod · 0.80
setLargerValueMethod · 0.80
mergeMethod · 0.45

Tested by

no test coverage detected