forked from forefireAPI/forefire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurningMap.cpp
More file actions
134 lines (112 loc) · 3.54 KB
/
BurningMap.cpp
File metadata and controls
134 lines (112 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Copyright (C) 2012 ForeFire Team, SPE, UniversitŽ de Corse.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This program 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
*/
#include "BurningMap.h"
namespace libforefire {
BurningMap::BurningMap() {
FFPoint fakeOrigin = FFPoint();
double fakeRes = 123456789.;
SWCorner = fakeOrigin;
NECorner = fakeOrigin;
dx = fakeRes;
dy = fakeRes;
sizeX = 1;
sizeY = 1;
arrivalTimeMap = 0;
}
BurningMap::
BurningMap(const FFPoint& sw, const FFPoint& ne
, const size_t& nx, const size_t& ny) :
sizeX(nx), sizeY(ny), SWCorner(sw), NECorner(ne) {
try {
arrivalTimeMap = new FFArray<double>("ArrivalTime", numeric_limits<double>::infinity(), sizeX, sizeY);
dx = ( NECorner.getX()-SWCorner.getX() )/sizeX;
dy = ( NECorner.getY()-SWCorner.getY() )/sizeY;
} catch ( const std::bad_alloc & ) {
// the burning matrix is too refined, increasing the spatial resolution
cout << "Burning matrix too refined for spatial resolution: "
<< dx << ", " << dy << endl;
}
}
BurningMap::~BurningMap() {
delete arrivalTimeMap;
}
// Operators
double BurningMap::operator ()(size_t i, size_t j) const {
if ( i >= sizeX or j >= sizeY ){
cout << "Array subscript out of bounds when reading a value" << endl;
return (*arrivalTimeMap)(0,0);
}
return (*arrivalTimeMap)(i,j);
}
double& BurningMap::operator ()(size_t i, size_t j){
if ( i >= sizeX or j >= sizeY ){
cout << "Array subscript out of bounds when writing a value" << endl;
return (*arrivalTimeMap)(0,0);
}
return (*arrivalTimeMap)(i,j);
}
FFArray<double>* BurningMap::getMap(){
return arrivalTimeMap;
}
// Mutators
void BurningMap::setBurning(FFPoint& p, const double& time){
// finding the indices in the burning matrix
int kx = int((p.getX()-SWCorner.getX())/dx);
int ky = int((p.getY()-SWCorner.getY())/dy);
if ( (*arrivalTimeMap)(kx,ky) == 0. ){
// set the time of the end of burning in that cell
(*arrivalTimeMap)(kx,ky,time);
}
}
bool BurningMap::nothingBurning(const double& time){
// Assumption on the burning process
double burningTime = 30.;
for ( size_t i = 0; i < sizeX; i++ ) {
for ( size_t j = 0; j < sizeY; j++ ) {
if ( abs(time-(*arrivalTimeMap)(i,j)) < burningTime ) return false;
}
}
return true;
}
size_t BurningMap::getSizeX(){
return sizeX;
}
size_t BurningMap::getSizeY(){
return sizeY;
}
double BurningMap::getDx(){
return dx;
}
double BurningMap::getDy(){
return dy;
}
FFPoint BurningMap::getCenter(const size_t& i, const size_t& j){
return FFPoint(SWCorner.getX()+(i+0.5)*dx, SWCorner.getY()+(j+0.5)*dy);
}
string BurningMap::toString(const double& time){
ostringstream oss;
for (size_t i=0;i<sizeX;i++){
for (size_t j=0;j<sizeY;j++){
if ( (*arrivalTimeMap)(i,j)-time > 0. ) {
oss << 1 << " ";
} else {
oss << 0 << " ";
}
}
oss << endl;
}
return oss.str();
}
}