@@ -33,6 +33,7 @@ class DbLoader(object):
33
33
__filter : Optional [Callable [['Floor' ], bool ]]
34
34
__filtered_floors : List ['Floor' ]
35
35
__floor : Dict [int , 'Floor' ]
36
+ __floor_categories : Dict [int , str ]
36
37
__path : str
37
38
38
39
def __init__ (self , db : str , floor_only : bool = False ) -> None :
@@ -45,17 +46,17 @@ def __init__(self, db: str, floor_only: bool = False) -> None:
45
46
assert os .path .isfile (db ), f'Dataset file { db } not found'
46
47
self .__filter = None
47
48
self .__filtered_floors = []
48
- self .__path = str (Path (os .path .realpath (db )).parent )
49
49
self .__floor = {}
50
+ self .__floor_categories : Dict [int , str ] = {}
51
+ self .__path = str (Path (os .path .realpath (db )).parent )
50
52
51
53
with open (db , 'r' , encoding = 'utf8' ) as dbfile :
52
54
data : dict = json .load (dbfile )
53
55
meta : dict = data ['meta' ] if 'meta' in data else {}
54
56
55
57
# Load metadata
56
- floor_categories : Dict [int , str ] = {}
57
58
for cat in (meta ['floor_categories' ] if 'floor_categories' in meta else {}):
58
- floor_categories [meta ['floor_categories' ][cat ]] = cat
59
+ self . __floor_categories [meta ['floor_categories' ][cat ]] = cat
59
60
item_types : Dict [int , Tuple [str , str ]] = {}
60
61
for cat in (meta ['item_types' ] if 'item_types' in meta else {}):
61
62
ic = meta ['item_types' ][cat ]
@@ -83,7 +84,7 @@ def __init__(self, db: str, floor_only: bool = False) -> None:
83
84
project_id = project_id ,
84
85
project_label = project_label [project_id ] if project_id in project_label else '' ,
85
86
category = f_cat ,
86
- category_name = floor_categories .get (f_cat , '' ),
87
+ category_name = self . __floor_categories .get (f_cat , '' ),
87
88
elevation = f_data ['elevation' ] if 'elevation' in f_data else False
88
89
)
89
90
if floor_only :
@@ -153,6 +154,31 @@ def __init__(self, db: str, floor_only: bool = False) -> None:
153
154
def __getitem__ (self , item : int ) -> 'Floor' :
154
155
return self .__floor [item ]
155
156
157
+ def add_floor (self , floor_image : str , scale : float , category : int , elevation : bool ) -> 'Floor' :
158
+ """
159
+ Adds a floor to the dataset. No project.
160
+
161
+ :param floor_image: Floor image file
162
+ :param scale: Image scale
163
+ :param category: Floor category
164
+ :param elevation: Floor is elevation
165
+ :return: Added floor object
166
+ """
167
+ assert os .path .isfile (floor_image )
168
+ f_id : int = len (self .__floor ) + 1
169
+ f = Floor (
170
+ floor_id = int (f_id ),
171
+ image_path = floor_image ,
172
+ image_scale = scale ,
173
+ project_id = - 1 ,
174
+ project_label = '' ,
175
+ category = category ,
176
+ category_name = self .__floor_categories .get (category , '' ),
177
+ elevation = elevation
178
+ )
179
+ self .__floor [f_id ] = f
180
+ return f
181
+
156
182
@property
157
183
def floors (self ) -> Tuple ['Floor' , ...]:
158
184
if len (self .__filtered_floors ) == 0 :
0 commit comments