Skip to content

Commit 7b8c9dc

Browse files
committed
Added legacy tabulate mode
1 parent 89e57c9 commit 7b8c9dc

File tree

4 files changed

+43
-40
lines changed

4 files changed

+43
-40
lines changed

MLStructFP/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""
2-
MLSTRUCTFP
2+
MLSTRUCT-FP
33
4-
Machine learning structural floor plan dataset.
4+
Machine Learning STRUCTural Floor Plan dataset.
55
"""
66

77
# Basic information
88
__author__ = 'Pablo Pizarro R.'
99
__description__ = 'Machine learning structural floor plan dataset'
1010
__keywords__ = ['ml', 'ai', 'floor plan', 'architectural', 'dataset', 'cnn']
1111
__email__ = '[email protected]'
12-
__version__ = '0.6.5'
12+
__version__ = '0.6.6'
1313

1414
# URL
1515
__url__ = 'https://github.com/MLSTRUCT/MLSTRUCT-FP'

MLStructFP/db/_db_loader.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,23 @@ def set_filter(self, f_filter: Callable[['Floor'], bool]) -> None:
175175
self.__filter = f_filter
176176
self.__filtered_floors.clear()
177177

178-
def tabulate(self, limit: int = 0, show_project: bool = False,
178+
def tabulate(self, limit: int = 0, legacy: bool = False,
179179
f_filter: Optional[Callable[['Floor'], bool]] = None) -> None:
180180
"""
181181
Tabulates each floor, with their file and number of rects.
182182
183183
:param limit: Limits the number of items
184-
:param show_project: Show project data (if exists)
184+
:param legacy: Show legacy mode
185185
:param f_filter: Floor filter
186186
"""
187187
assert isinstance(limit, int) and limit >= 0, 'Limit must be an integer greater or equal than zero'
188188
theads = ['#']
189-
if show_project:
190-
theads.append('Project ID')
191-
theads.append('Project label')
192-
for t in ('Floor ID', 'Cat', 'Elev', 'Rects', 'Points', 'Slabs', 'Rooms', 'Items', 'Floor image path'):
189+
for t in (
190+
('Project ID', 'Project label', 'Floor ID', 'Cat', 'Elev',
191+
'Rects', 'Points', 'Slabs', 'Rooms', 'Items', 'Floor image path'
192+
) if not legacy else
193+
('Floor ID', 'Rects', 'Floor image path')
194+
):
193195
theads.append(t)
194196
table = [theads]
195197
floors = self.floors
@@ -198,12 +200,13 @@ def tabulate(self, limit: int = 0, show_project: bool = False,
198200
if f_filter is not None and not f_filter(f):
199201
continue
200202
table_data = [j]
201-
if show_project:
202-
table_data.append(f.project_id)
203-
table_data.append(f.project_label)
204-
for i in (f.id, f.category, 1 if f.elevation else 0,
205-
len(f.rect), len(f.point), len(f.slab), len(f.room), len(f.item), # Item count
206-
os.path.basename(f.image_path)):
203+
f_file: str = os.path.basename(f.image_path)
204+
for i in (
205+
(f.project_id, f.project_label, f.id, f.category, 1 if f.elevation else 0,
206+
len(f.rect), len(f.point), len(f.slab), len(f.room), len(f.item), f_file
207+
) if not legacy else
208+
(f.id, len(f.rect), f_file)
209+
):
207210
table_data.append(i)
208211
table.append(table_data)
209212
if 0 < limit - 1 <= j:

MLStructFP/db/_floor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class Floor(object):
4242
project_id: int
4343
project_label: str
4444

45-
def __init__(self, floor_id: int, image_path: str, image_scale: NumberType, project_id: int = -1,
45+
def __init__(self, floor_id: int, image_path: str, image_scale: NumberType, project_id: int,
4646
project_label: str = '', category: int = 0, category_name: str = '', elevation: bool = False) -> None:
4747
"""
4848
Constructor.
4949
5050
:param floor_id: Floor ID
5151
:param image_path: Image path
5252
:param image_scale: Image scale (px to units)
53-
:param project_id: Project ID (default: -1)
53+
:param project_id: Project ID
5454
:param project_label: Project label (default empty)
5555
:param category: Project category
5656
:param category_name: Project category name

README.rst

+23-23
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ MLSTRUCT-FP
2323
:target: https://opensource.org/licenses/MIT
2424
:alt: License MIT
2525

26-
Multi-unit floor plan dataset.
26+
**M**\ achine **L**\ earning **STRUCT**\ ural **F**\ loor **P**\ lan: A multi-unit floor plan dataset.
2727

2828

2929
Description
3030
-----------
3131

3232
This repo contains the base library to load and parse floor plans from the MLSTRUCT-FP dataset, which
3333
contains over 954 large-scale floor plan images, alongside annotations for their walls in JSON
34-
format. The database loader just loads in memory the Floor, Walls, and Slab objects, and also
34+
format. The database loader loads in memory the Floor, Walls, and Slab objects, and also
3535
offers methods to create custom images from floor plans by applying a crop, a rotation, and a custom
3636
scaling.
3737

38-
The images can be generated from the real rasterized plan, or by using the polygons stored in the
38+
The images can be generated from the real rasterized plan or by using the polygons stored in the
3939
JSON file. Both image and wall polygons are consistent in their placement.
4040

4141
See more information in our `published article <https://doi.org/10.1016/j.autcon.2023.105132>`_; also,
@@ -45,13 +45,13 @@ check out the `AI segmentation model <https://github.com/MLSTRUCT/MLSTRUCT-FP_be
4545
First steps
4646
-----------
4747

48-
In order to install the library, use the following python-pip commands:
48+
To install the library, use the following python-pip commands:
4949

5050
.. code-block:: bash
5151
5252
python -m pip install MLStructFP
5353
54-
To download the dataset (compressed in .zip), request a public download link by completing a
54+
To download the dataset (compressed in .zip), request a public download link by completing a
5555
`simple form <https://forms.gle/HigdGxngnTEvnNC37>`_.
5656

5757

@@ -61,7 +61,7 @@ Dataset details
6161
The dataset (uncompressed) has the following structure:
6262

6363
.. code-block:: bash
64-
64+
6565
dataset/
6666
0a0...736.png
6767
0a7...b41.png
@@ -77,7 +77,7 @@ whose labels (wall polygons, slabs) and metadata are stored within fp.json.
7777
The format of the fp.json file is characterized as follows:
7878

7979
.. code-block:: JSON
80-
80+
8181
{
8282
"rect": {
8383
"1000393": {
@@ -134,7 +134,7 @@ The format of the fp.json file is characterized as follows:
134134
}
135135
136136
Note the dataset comprises a list of "rect" representing the rectangles (wall segments),
137-
"slab" and "floor". Each item has a distinct ID for querying and grouping elements. In the example,
137+
"slab," and "floor." Each item has a distinct ID for querying and grouping elements. In the example,
138138
the rect ID ``1000393`` is within floor ID ``8970646``, with an angle of ``0`` degrees, a length
139139
of ``2.6 m``, and within the wall ID ``5969311``. Likewise, the slab ``1002588`` is within floor
140140
ID ``5980221``, whose its first point (x, y) is ``(-1.153, -22.622) m``. Finally, the floor ID
@@ -145,15 +145,15 @@ there are ``70873`` rects, ``954`` slabs and ``954`` floors.
145145
Object API
146146
----------
147147

148-
The basic usage of the API is illustrated on the
149-
`jupyter notebook <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/example.ipynb>`_. The most basic
148+
The primary usage of the API is illustrated on the
149+
`jupyter notebook <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/example.ipynb>`_. The most fundamental
150150
object is `DbLoader <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/MLStructFP/db/_db_loader.py>`_,
151151
which receives the path of the ``fp.json`` file.
152152

153153
.. code-block:: python
154-
154+
155155
class DbLoader(db: str)
156-
156+
157157
# Example
158158
db = DbLoader('test/data/fp.json')
159159
db.tabulate()
@@ -165,21 +165,21 @@ which receives the path of the ``fp.json`` file.
165165
DbLoader creates a dict of `Floor <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/MLStructFP/db/_floor.py>`_ object,
166166
which each contains a dict of `Rect <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/MLStructFP/db/_c_rect.py>`_ and
167167
`Slab <https://github.com/MLSTRUCT/MLSTRUCT-FP/blob/master/MLStructFP/db/_c_slab.py>`_ objects. Each item is associated
168-
using their respective ids. Floor objects also have many methods to retrieve their elements, plot, and apply
169-
transformations (aka mutations) such as scaling or rotation using ``mutate()`` method:
168+
with their respective IDs. Floor objects also have many methods to retrieve their elements, plot, and apply
169+
transformations (aka mutations) such as scaling or rotation using the ``mutate()`` method:
170170

171171
.. code-block:: python
172-
172+
173173
class Floor:
174174
...
175-
175+
176176
def mutate(self, angle: NumberType = 0, sx: NumberType = 1, sy: NumberType = 1,
177177
scale_first: bool = True) -> 'Floor':
178178
...
179-
179+
180180
# Example
181181
plot_floor = db.floor[302]
182-
plot_floor.mutate(30, 1, 1) # 30 degrees, scale 1 on the x-axis, 1 on the y-axis
182+
plot_floor.mutate(30, 1, 1) # 30 degrees, scale one on the x-axis, one on the y-axis
183183
plot_floor.plot_complex()
184184
185185
.. image:: docs/example-plot.png
@@ -193,19 +193,19 @@ main responsibilities are creating plan crops for machine learning model trainin
193193
and downsampling on any image size and scale factor. For both objects, the main methods are:
194194

195195
.. code-block:: python
196-
196+
197197
def make_rect(self, rect: 'Rect', crop_length: NumberType = 5) -> Tuple[int, 'np.ndarray']:
198-
198+
199199
def make_region(self, xmin: NumberType, xmax: NumberType, ymin: NumberType, ymax: NumberType,
200200
floor: 'Floor', rect: Optional['Rect'] = None) -> Tuple[int, 'np.ndarray']:
201201
202-
The first one creates a crop around the provided rect (using its position as the center, adding ``crop_length`` m
202+
The first creates a crop around the provided rect (using its position as the center, adding ``crop_length`` m
203203
for each axis). The second one creates a region on any arbitrary ``(xmin, ymin, xmax, ymax)`` region. Consider
204204
each position in meters.
205205

206206
From the provided notebook example, the following image shows two crops generated using a mutated floor plan
207-
with 30 30-degree angle rotation. Crops are ``256x256 px`` size and display a ``10x10 m`` region, for a selected
208-
rectangle as origin.
207+
with 30 30-degree angle rotation. Crops are 256x256 px`` in size and display a ``10x10 m`` region for a selected
208+
rectangle as the origin.
209209

210210
.. image:: docs/example-rects.png
211211
:width: 640

0 commit comments

Comments
 (0)