Zai commited on
Commit
c2ea21f
·
1 Parent(s): b4ef065
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. House/__init__.py +0 -0
  2. House/__pycache__/__init__.cpython-311.pyc +0 -0
  3. House/__pycache__/__init__.cpython-37.pyc +0 -0
  4. House/__pycache__/settings.cpython-311.pyc +0 -0
  5. House/__pycache__/settings.cpython-37.pyc +0 -0
  6. House/__pycache__/urls.cpython-311.pyc +0 -0
  7. House/__pycache__/urls.cpython-37.pyc +0 -0
  8. House/__pycache__/wsgi.cpython-37.pyc +0 -0
  9. House/asgi.py +16 -0
  10. House/settings.py +127 -0
  11. House/urls.py +37 -0
  12. House/wsgi.py +16 -0
  13. Houseweb/__init__.py +0 -0
  14. Houseweb/__pycache__/__init__.cpython-311.pyc +0 -0
  15. Houseweb/__pycache__/__init__.cpython-37.pyc +0 -0
  16. Houseweb/__pycache__/create.cpython-37.pyc +0 -0
  17. Houseweb/__pycache__/floorplan2.cpython-37.pyc +0 -0
  18. Houseweb/__pycache__/network.cpython-37.pyc +0 -0
  19. Houseweb/__pycache__/utils.cpython-37.pyc +0 -0
  20. Houseweb/__pycache__/utils1.cpython-37.pyc +0 -0
  21. Houseweb/__pycache__/views.cpython-311.pyc +0 -0
  22. Houseweb/__pycache__/views.cpython-37.pyc +0 -0
  23. Houseweb/admin.py +3 -0
  24. Houseweb/apps.py +5 -0
  25. Houseweb/migrations/__init__.py +0 -0
  26. Houseweb/models.py +3 -0
  27. Houseweb/tests.py +3 -0
  28. Houseweb/views.py +757 -0
  29. Img/data.mat.png +0 -0
  30. Img/data_test_converted.png +0 -0
  31. Img/data_train_converted.png +0 -0
  32. Img/interface.jpg +0 -0
  33. Img/paper.png +0 -0
  34. align_fp/align_adjacent_room3.m +121 -0
  35. align_fp/align_fp.m +108 -0
  36. align_fp/align_neighbor.m +53 -0
  37. align_fp/align_with_boundary.m +29 -0
  38. align_fp/find_close_seg.m +74 -0
  39. align_fp/find_room_order.m +29 -0
  40. align_fp/get_entrance_space.m +14 -0
  41. align_fp/get_room_boundary.m +25 -0
  42. align_fp/regularize_fp.m +111 -0
  43. align_fp/shrink_box.m +61 -0
  44. db.sqlite3 +0 -0
  45. manage.py +21 -0
  46. model/__pycache__/_floorplan2.cpython-37.pyc +0 -0
  47. model/__pycache__/add_archs.cpython-37.pyc +0 -0
  48. model/__pycache__/box_utils.cpython-37.pyc +0 -0
  49. model/__pycache__/crn.cpython-37.pyc +0 -0
  50. model/__pycache__/floorplan.cpython-311.pyc +0 -0
House/__init__.py ADDED
File without changes
House/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (191 Bytes). View file
 
House/__pycache__/__init__.cpython-37.pyc ADDED
Binary file (157 Bytes). View file
 
House/__pycache__/settings.cpython-311.pyc ADDED
Binary file (3.1 kB). View file
 
House/__pycache__/settings.cpython-37.pyc ADDED
Binary file (2.38 kB). View file
 
House/__pycache__/urls.cpython-311.pyc ADDED
Binary file (1.92 kB). View file
 
House/__pycache__/urls.cpython-37.pyc ADDED
Binary file (1.4 kB). View file
 
House/__pycache__/wsgi.cpython-37.pyc ADDED
Binary file (536 Bytes). View file
 
House/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for House project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.asgi import get_asgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'House.settings')
15
+
16
+ application = get_asgi_application()
House/settings.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for House project.
3
+
4
+ Generated by 'django-admin startproject' using Django 3.0.2.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.0/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/3.0/ref/settings/
11
+ """
12
+
13
+ import os
14
+
15
+ # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17
+
18
+
19
+ # Quick-start development settings - unsuitable for production
20
+ # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
21
+
22
+ # SECURITY WARNING: keep the secret key used in production secret!
23
+ SECRET_KEY = 'y&ol628+upm0r&=8pilr@u_w_0ji!1afp!st*y#ympn3u@!3s%'
24
+
25
+ # SECURITY WARNING: don't run with debug turned on in production!
26
+ DEBUG = True
27
+
28
+ ALLOWED_HOSTS = []
29
+
30
+
31
+ # Application definition
32
+
33
+ INSTALLED_APPS = [
34
+ 'django.contrib.admin',
35
+ 'django.contrib.auth',
36
+ 'django.contrib.contenttypes',
37
+ 'django.contrib.sessions',
38
+ 'django.contrib.messages',
39
+ 'django.contrib.staticfiles',
40
+ ]
41
+
42
+ MIDDLEWARE = [
43
+ 'django.middleware.security.SecurityMiddleware',
44
+ 'django.contrib.sessions.middleware.SessionMiddleware',
45
+ 'django.middleware.common.CommonMiddleware',
46
+ 'django.middleware.csrf.CsrfViewMiddleware',
47
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
48
+ 'django.contrib.messages.middleware.MessageMiddleware',
49
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
50
+ ]
51
+
52
+ ROOT_URLCONF = 'House.urls'
53
+
54
+ TEMPLATES = [
55
+ {
56
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
57
+ 'DIRS': [os.path.join(BASE_DIR, 'templates')]
58
+ ,
59
+ 'APP_DIRS': True,
60
+ 'OPTIONS': {
61
+ 'context_processors': [
62
+ 'django.template.context_processors.debug',
63
+ 'django.template.context_processors.request',
64
+ 'django.contrib.auth.context_processors.auth',
65
+ 'django.contrib.messages.context_processors.messages',
66
+ ],
67
+ },
68
+ },
69
+ ]
70
+
71
+ WSGI_APPLICATION = 'House.wsgi.application'
72
+
73
+
74
+ # Database
75
+ # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
76
+
77
+ DATABASES = {
78
+ 'default': {
79
+ 'ENGINE': 'django.db.backends.sqlite3',
80
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81
+ }
82
+ }
83
+
84
+
85
+ # Password validation
86
+ # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
87
+
88
+ AUTH_PASSWORD_VALIDATORS = [
89
+ {
90
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91
+ },
92
+ {
93
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94
+ },
95
+ {
96
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97
+ },
98
+ {
99
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100
+ },
101
+ ]
102
+
103
+
104
+ # Internationalization
105
+ # https://docs.djangoproject.com/en/3.0/topics/i18n/
106
+
107
+ LANGUAGE_CODE = 'en-us'
108
+
109
+ TIME_ZONE = 'UTC'
110
+
111
+ USE_I18N = True
112
+
113
+ USE_L10N = True
114
+
115
+ USE_TZ = True
116
+
117
+
118
+ # Static files (CSS, JavaScript, Images)
119
+ # https://docs.djangoproject.com/en/3.0/howto/static-files/
120
+
121
+ STATIC_URL = '/static/'
122
+ HERE = os.path.dirname(os.path.abspath(__file__))
123
+ HERE = os.path.join(HERE, '../')
124
+ STATICFILES_DIRS = (
125
+ os.path.join(HERE, 'static/'),
126
+ )
127
+ ALLOWED_HOSTS = ['*']
House/urls.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """House URL Configuration
2
+
3
+ The `urlpatterns` list routes URLs to views. For more information please see:
4
+ https://docs.djangoproject.com/en/3.0/topics/http/urls/
5
+ Examples:
6
+ Function views
7
+ 1. Add an import: from my_app import views
8
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
9
+ Class-based views
10
+ 1. Add an import: from other_app.views import Home
11
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12
+ Including another URLconf
13
+ 1. Import the include() function: from django.urls import include, path
14
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15
+ """
16
+ from django.contrib import admin
17
+ from django.urls import path
18
+
19
+ from Houseweb import views
20
+
21
+ urlpatterns = [
22
+ # path('admin/', admin.site.urls),
23
+ path('index/LoadTestBoundary', views.LoadTestBoundary),
24
+ path('index/NumSearch/', views.NumSearch),
25
+ path(r'index/LoadTrainHouse/', views.LoadTrainHouse),
26
+ path(r'index/TransGraph/', views.TransGraph),
27
+ path(r'index/TransGraph_net/', views.TransGraph_net),
28
+ path(r'index/Init/', views.Init),
29
+ path(r'index/AdjustGraph/', views.AdjustGraph),
30
+ path(r'index/GraphSearch/', views.GraphSearch),
31
+ path(r'index/RelBox/', views.RelBox),
32
+ path(r'index/Save_Editbox/', views.Save_Editbox),
33
+
34
+ path('home', views.home),
35
+
36
+
37
+ ]
House/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for House project.
3
+
4
+ It exposes the WSGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
8
+ """
9
+
10
+ import os
11
+
12
+ from django.core.wsgi import get_wsgi_application
13
+
14
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'House.settings')
15
+
16
+ application = get_wsgi_application()
Houseweb/__init__.py ADDED
File without changes
Houseweb/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (194 Bytes). View file
 
Houseweb/__pycache__/__init__.cpython-37.pyc ADDED
Binary file (160 Bytes). View file
 
Houseweb/__pycache__/create.cpython-37.pyc ADDED
Binary file (3.27 kB). View file
 
Houseweb/__pycache__/floorplan2.cpython-37.pyc ADDED
Binary file (19.5 kB). View file
 
Houseweb/__pycache__/network.cpython-37.pyc ADDED
Binary file (3.89 kB). View file
 
Houseweb/__pycache__/utils.cpython-37.pyc ADDED
Binary file (9.39 kB). View file
 
Houseweb/__pycache__/utils1.cpython-37.pyc ADDED
Binary file (7.52 kB). View file
 
Houseweb/__pycache__/views.cpython-311.pyc ADDED
Binary file (54.4 kB). View file
 
Houseweb/__pycache__/views.cpython-37.pyc ADDED
Binary file (23.6 kB). View file
 
Houseweb/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
Houseweb/apps.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class HousewebConfig(AppConfig):
5
+ name = 'Houseweb'
Houseweb/migrations/__init__.py ADDED
File without changes
Houseweb/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
Houseweb/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
Houseweb/views.py ADDED
@@ -0,0 +1,757 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.shortcuts import render
2
+ from django.http import HttpResponse, JsonResponse
3
+ import json
4
+ import model.test as mltest
5
+ import model.utils as mdul
6
+ from model.floorplan import *
7
+ import retrieval.retrieval as rt
8
+ import time
9
+ import pickle
10
+ import scipy.io as sio
11
+ import numpy as np
12
+ from model.decorate import *
13
+ import math
14
+ import pandas as pd
15
+ import matlab.engine
16
+
17
+ global test_data, test_data_topk, testNameList, trainNameList
18
+ global train_data, trainNameList, trainTF, train_data_eNum, train_data_rNum
19
+ global engview, model
20
+ global tf_train, centroids, clusters
21
+
22
+
23
+ def home(request):
24
+ return render(request, "home.html", )
25
+
26
+
27
+ def Init(request):
28
+ start = time.clock()
29
+ getTestData()
30
+ getTrainData()
31
+ loadMatlabEng()
32
+ loadModel()
33
+ loadRetrieval()
34
+ end = time.clock()
35
+ print('Init(model+test+train+engine+retrieval) time: %s Seconds' % (end - start))
36
+
37
+ return HttpResponse(None)
38
+
39
+
40
+ def loadMatlabEng():
41
+ startengview = time.clock()
42
+ global engview
43
+ engview = matlab.engine.start_matlab()
44
+ engview.addpath(r'./align_fp/', nargout=0)
45
+ endengview = time.clock()
46
+ print(' matlab.engineview time: %s Seconds' % (endengview - startengview))
47
+
48
+
49
+ def loadRetrieval():
50
+ global tf_train, centroids, clusters
51
+ t1 = time.clock()
52
+ tf_train = np.load('./retrieval/tf_train.npy')
53
+ centroids = np.load('./retrieval/centroids_train.npy')
54
+ clusters = np.load('./retrieval/clusters_train.npy')
55
+ t2 = time.clock()
56
+ print('load tf/centroids/clusters', t2 - t1)
57
+
58
+
59
+ def getTestData():
60
+ start = time.clock()
61
+ global test_data, testNameList, trainNameList
62
+
63
+ test_data = pickle.load(open('./static/Data/data_test_converted.pkl', 'rb'))
64
+ test_data, testNameList, trainNameList = test_data['data'], list(test_data['testNameList']), list(
65
+ test_data['trainNameList'])
66
+ end = time.clock()
67
+ print('getTestData time: %s Seconds' % (end - start))
68
+
69
+
70
+ def getTrainData():
71
+ start = time.clock()
72
+ global train_data, trainNameList, trainTF, train_data_eNum, train_data_rNum
73
+
74
+ train_data = pickle.load(open('./static/Data/data_train_converted.pkl', 'rb'))
75
+ train_data, trainNameList, trainTF = train_data['data'], list(train_data['nameList']), list(train_data['trainTF'])
76
+
77
+ train_data_eNum = pickle.load(open('./static/Data/data_train_eNum.pkl', 'rb'))
78
+ train_data_eNum = train_data_eNum['eNum']
79
+ train_data_rNum = np.load('./static/Data/rNum_train.npy')
80
+
81
+ end = time.clock()
82
+ print('getTrainData time: %s Seconds' % (end - start))
83
+
84
+
85
+ def loadModel():
86
+ global model, train_data, trainNameList
87
+ start = time.clock()
88
+ model = mltest.load_model()
89
+ end = time.clock()
90
+ print('loadModel time: %s Seconds' % (end - start))
91
+ start = time.clock()
92
+ test = train_data[trainNameList.index("75119")]
93
+ mltest.test(model, FloorPlan(test, train=True))
94
+ end = time.clock()
95
+ print('test Model time: %s Seconds' % (end - start))
96
+
97
+
98
+ def LoadTestBoundary(request):
99
+ start = time.clock()
100
+ testName = request.GET.get('testName').split(".")[0]
101
+ test_index = testNameList.index(testName)
102
+ data = test_data[test_index]
103
+ data_js = {}
104
+ data_js["door"] = str(data.boundary[0][0]) + "," + str(data.boundary[0][1]) + "," + str(
105
+ data.boundary[1][0]) + "," + str(data.boundary[1][1])
106
+ ex = ""
107
+ for i in range(len(data.boundary)):
108
+ ex = ex + str(data.boundary[i][0]) + "," + str(data.boundary[i][1]) + " "
109
+ data_js['exterior'] = ex
110
+ end = time.clock()
111
+ print('LoadTestBoundary time: %s Seconds' % (end - start))
112
+ return HttpResponse(json.dumps(data_js), content_type="application/json")
113
+
114
+
115
+ def get_filter_func(mask, acc, num):
116
+ filters = [
117
+ None if not mask else (
118
+ np.equal if acc[i] else np.greater_equal
119
+ )
120
+ for i in range(len(mask))
121
+ ]
122
+
123
+ def filter_func(data):
124
+ for i in range(len(filters)):
125
+ if (filters[i] is not None) and (not filters[i](data[i], num[i])): return False
126
+ return True
127
+
128
+ return filter_func
129
+
130
+
131
+ def filter_graph(graph_):
132
+ filters = graph_
133
+
134
+ def filter_graphfunc(data):
135
+ sub = data - filters
136
+ return ((sub >= 0).all())
137
+
138
+ return filter_graphfunc
139
+
140
+
141
+ def NumSearch(request):
142
+ start = time.clock()
143
+ data_new = json.loads(request.GET.get("userInfo"))
144
+ testName = data_new[0].split(".")[0]
145
+ test_index = testNameList.index(testName)
146
+ topkList = []
147
+ topkList.clear()
148
+ data = test_data[test_index]
149
+
150
+
151
+ multi_clusters=False
152
+ test_data_topk = rt.retrieval(data, 1000,multi_clusters)
153
+
154
+ if len(data_new) > 1:
155
+ roomactarr = data_new[1]
156
+ roomexaarr = data_new[2]
157
+ roomnumarr = [int(x) for x in data_new[3]]
158
+
159
+ test_num = train_data_rNum[test_data_topk]
160
+ filter_func = get_filter_func(roomactarr, roomexaarr, roomnumarr)
161
+ indices = np.where(list(map(filter_func, test_num)))
162
+ indices = list(indices)
163
+ if len(indices[0]) < 20:
164
+ topk = len(indices[0])
165
+ else:
166
+ topk = 20
167
+ topkList.clear()
168
+ for i in range(topk):
169
+ topkList.append(str(trainNameList[int(test_data_topk[indices[0][i]])]) + ".png")
170
+ end = time.clock()
171
+ print('NumberSearch time: %s Seconds' % (end - start))
172
+ return HttpResponse(json.dumps(topkList), content_type="application/json")
173
+
174
+
175
+ def FindTraindata(trainname):
176
+ start = time.clock()
177
+ train_index = trainNameList.index(trainname)
178
+ data = train_data[train_index]
179
+ data_js = {}
180
+ data_js["hsname"] = trainname
181
+
182
+ data_js["door"] = str(data.boundary[0][0]) + "," + str(data.boundary[0][1]) + "," + str(
183
+ data.boundary[1][0]) + "," + str(data.boundary[1][1])
184
+ print("testboundary", data_js["door"])
185
+ ex = ""
186
+ for i in range(len(data.boundary)):
187
+ ex = ex + str(data.boundary[i][0]) + "," + str(data.boundary[i][1]) + " "
188
+ data_js['exterior'] = ex
189
+
190
+ data_js["hsedge"] = [[int(u), int(v)] for u, v in data.edge[:, [0, 1]]]
191
+
192
+ hsbox = [[[float(x1), float(y1), float(x2), float(y2)], [mdul.room_label[cate][1]]] for
193
+ x1, y1, x2, y2, cate in data.box[:]]
194
+ external = np.asarray(data.boundary)
195
+ xmin, xmax = np.min(external[:, 0]), np.max(external[:, 0])
196
+ ymin, ymax = np.min(external[:, 1]), np.max(external[:, 1])
197
+
198
+ area_ = (ymax - ymin) * (xmax - xmin)
199
+
200
+ data_js["rmsize"] = [
201
+ [[20 * math.sqrt((float(x2) - float(x1)) * (float(y2) - float(y1)) / float(area_))], [mdul.room_label[cate][1]]]
202
+ for
203
+ x1, y1, x2, y2, cate in data.box[:]]
204
+
205
+
206
+ box_order = data.order
207
+ data_js["hsbox"] = []
208
+ for i in range(len(box_order)):
209
+ data_js["hsbox"].append(hsbox[int(float(box_order[i])) - 1])
210
+
211
+ data_js["rmpos"] = [[int(cate), str(mdul.room_label[cate][1]), float((x1 + x2) / 2), float((y1 + y2) / 2)] for
212
+ x1, y1, x2, y2, cate in data.box[:]]
213
+ end = time.clock()
214
+ print('find train data time: %s Seconds' % (end - start))
215
+ return data_js
216
+
217
+
218
+ def LoadTrainHouse(request):
219
+ trainname = request.GET.get("roomID").split(".")[0]
220
+ data_js = FindTraindata(trainname)
221
+ return HttpResponse(json.dumps(data_js), content_type="application/json")
222
+
223
+
224
+ '''
225
+ transfer the graph of the training data into the graph of the test data
226
+ '''
227
+
228
+
229
+ def TransGraph(request):
230
+ start = time.clock()
231
+ userInfo = request.GET.get("userInfo")
232
+ testname = userInfo.split(',')[0]
233
+ trainname = request.GET.get("roomID")
234
+ mlresult = mltest.get_userinfo(testname, trainname)
235
+
236
+ fp_end = mlresult
237
+
238
+ sio.savemat("./static/" + userInfo.split(',')[0].split('.')[0] + ".mat", {"data": fp_end.data})
239
+
240
+ data_js = {}
241
+ # fp_end hsedge
242
+ data_js["hsedge"] = (fp_end.get_triples(tensor=False)[:, [0, 2, 1]]).astype(np.float).tolist()
243
+
244
+ # fp_rmsize
245
+ external = np.asarray(fp_end.data.boundary)
246
+ xmin, xmax = np.min(external[:, 0]), np.max(external[:, 0])
247
+ ymin, ymax = np.min(external[:, 1]), np.max(external[:, 1])
248
+ area_ = (ymax - ymin) * (xmax - xmin)
249
+ data_js["rmsize"] = [
250
+ [[20 * math.sqrt((float(x2) - float(x1)) * (float(y2) - float(y1)) / float(area_))], [mdul.room_label[cate][1]]]
251
+ for
252
+ x1, y1, x2, y2, cate in fp_end.data.box[:]]
253
+ # fp_end rmpos
254
+
255
+ rooms = fp_end.get_rooms(tensor=False)
256
+
257
+
258
+ center = [[(x1 + x2) / 2, (y1 + y2) / 2] for x1, y1, x2, y2 in fp_end.data.box[:, :4]]
259
+
260
+ # boxes_pred
261
+ data_js["rmpos"] = []
262
+ for k in range(len(center)):
263
+ node = float(rooms[k]), mdul.room_label[int(rooms[k])][1], center[k][0], center[k][1], float(k)
264
+ data_js["rmpos"].append(node)
265
+
266
+ test_index = testNameList.index(testname.split(".")[0])
267
+ data = test_data[test_index]
268
+ ex = ""
269
+ for i in range(len(data.boundary)):
270
+ ex = ex + str(data.boundary[i][0]) + "," + str(data.boundary[i][1]) + " "
271
+ data_js['exterior'] = ex
272
+ data_js["door"] = str(data.boundary[0][0]) + "," + str(data.boundary[0][1]) + "," + str(
273
+ data.boundary[1][0]) + "," + str(data.boundary[1][1])
274
+ end = time.clock()
275
+ print('TransGraph time: %s Seconds' % (end - start))
276
+ return HttpResponse(json.dumps(data_js), content_type="application/json")
277
+
278
+
279
+ def AdjustGraph(request):
280
+ start = time.clock()
281
+ # newNode index-typename-cx-cy
282
+ # oldNode index-typename-cx-cy
283
+ # newEdge u-v
284
+ NewGraph = json.loads(request.GET.get("NewGraph"))
285
+ testname = request.GET.get("userRoomID")
286
+ trainname = request.GET.get("adptRoomID")
287
+ s = time.clock()
288
+ mlresult = mltest.get_userinfo_adjust(testname, trainname, NewGraph)
289
+ e = time.clock()
290
+ print('get_userinfo_adjust: %s Seconds' % (e - s))
291
+ fp_end = mlresult[0]
292
+ global boxes_pred
293
+ boxes_pred = mlresult[1]
294
+
295
+ data_js = {}
296
+ data_js["hsedge"] = (fp_end.get_triples(tensor=False)[:, [0, 2, 1]]).astype(np.float).tolist()
297
+
298
+ rooms = fp_end.get_rooms(tensor=False)
299
+ center = [[(x1 + x2) / 2, (y1 + y2) / 2] for x1, y1, x2, y2 in fp_end.data.box[:, :4]]
300
+
301
+ box_order = mlresult[2]
302
+ '''
303
+ handle the information of the room boxes
304
+ boxes_pred: the prediction from net
305
+ box_order: The order in which boxes are drawn
306
+
307
+ '''
308
+ room = []
309
+ for o in range(len(box_order)):
310
+ room.append(float((rooms[int(float(box_order[o][0])) - 1])))
311
+ boxes_end = []
312
+ for i in range(len(box_order)):
313
+ tmp = []
314
+ for j in range(4):
315
+ tmp.append(float(boxes_pred[int(float(box_order[i][0])) - 1][j]))
316
+ boxes_end.append(tmp)
317
+
318
+ data_js['roomret'] = []
319
+ for k in range(len(room)):
320
+ data = boxes_end[k], [mdul.room_label[int(room[k])][1]], box_order[k][0] - 1
321
+ data_js['roomret'].append(data)
322
+
323
+ # change the box size
324
+ global relbox
325
+ relbox = data_js['roomret']
326
+ global reledge
327
+ reledge = data_js["hsedge"]
328
+
329
+ test_index = testNameList.index(testname.split(".")[0])
330
+ data = test_data[test_index]
331
+ ex = ""
332
+ for i in range(len(data.boundary)):
333
+ ex = ex + str(data.boundary[i][0]) + "," + str(data.boundary[i][1]) + " "
334
+ data_js['exterior'] = ex
335
+ data_js["door"] = str(data.boundary[0][0]) + "," + str(data.boundary[0][1]) + "," + str(
336
+ data.boundary[1][0]) + "," + str(data.boundary[1][1])
337
+
338
+ external = np.asarray(data.boundary)
339
+ xmin, xmax = np.min(external[:, 0]), np.max(external[:, 0])
340
+ ymin, ymax = np.min(external[:, 1]), np.max(external[:, 1])
341
+ area_ = (ymax - ymin) * (xmax - xmin)
342
+ data_js['rmsize'] = []
343
+ for i in range(len(data_js['roomret'])):
344
+ rmsize = 20 * math.sqrt((float(data_js['roomret'][i][0][2]) - float(data_js['roomret'][i][0][0])) * (
345
+ float(data_js['roomret'][i][0][3]) - float(data_js['roomret'][i][0][1])) / float(area_)), \
346
+ data_js["roomret"][i][1][0]
347
+ data_js["rmsize"].append(rmsize)
348
+
349
+ data_js["rmpos"] = []
350
+
351
+ newGraph = NewGraph[0]
352
+ for i in range(len(data_js['roomret'])):
353
+ for k in range(len(newGraph)):
354
+ if (data_js['roomret'][i][1][0] == newGraph[k][1]):
355
+ x_center = int((data_js['roomret'][i][0][0] + data_js['roomret'][i][0][2]) / 2)
356
+ y_center = int((data_js['roomret'][i][0][1] + data_js['roomret'][i][0][3]) / 2)
357
+ x_graph = newGraph[k][2]
358
+ y_graph = newGraph[k][3]
359
+ if ((int(x_graph - 30) < x_center < int(x_graph + 30))):
360
+ node = float(rooms[k]), newGraph[k][1], x_center, y_center, float(
361
+ newGraph[k][0])
362
+ data_js["rmpos"].append(node)
363
+ newGraph.pop(k)
364
+ break
365
+ if ((int(y_graph - 30) < y_center < int(y_graph + 30))):
366
+ node = float(rooms[k]), newGraph[k][1], x_center, y_center, float(
367
+ newGraph[k][0])
368
+ data_js["rmpos"].append(node)
369
+ newGraph.pop(k)
370
+
371
+ break
372
+
373
+ fp_end.data = add_dw_fp(fp_end.data)
374
+ data_js["indoor"] = []
375
+
376
+ boundary = data.boundary
377
+
378
+ isNew = boundary[:, 3]
379
+ frontDoor = boundary[[0, 1]]
380
+ frontDoor = frontDoor[:, [0, 1]]
381
+ frontsum = frontDoor.sum(axis=1).tolist()
382
+ idx = frontsum.index(min(frontsum))
383
+ wallThickness = 3
384
+ if idx == 1:
385
+ frontDoor = frontDoor[[1, 0], :]
386
+ orient = boundary[0][2]
387
+ if orient == 0 or orient == 2:
388
+ frontDoor[0][0] = frontDoor[0][0] + wallThickness / 4
389
+ frontDoor[1][0] = frontDoor[1][0] - wallThickness / 4
390
+ if orient == 1 or orient == 3:
391
+ frontDoor[0][1] = frontDoor[0][1] + wallThickness / 4
392
+ frontDoor[1][1] = frontDoor[1][1] - wallThickness / 4
393
+
394
+
395
+ data_js["windows"] = []
396
+ for indx, x, y, w, h, r in fp_end.data.windows:
397
+ if w != 0:
398
+ tmp = [x + 2, y - 2, w - 2, 4]
399
+ data_js["windows"].append(tmp)
400
+ if h != 0:
401
+ tmp = [x - 2, y, 4, h]
402
+ data_js["windows"].append(tmp)
403
+ data_js["windowsline"] = []
404
+ for indx, x, y, w, h, r in fp_end.data.windows:
405
+ if w != 0:
406
+ tmp = [x + 2, y, w + x, y]
407
+ data_js["windowsline"].append(tmp)
408
+ if h != 0:
409
+ tmp = [x, y, x, h + y]
410
+ data_js["windowsline"].append(tmp)
411
+
412
+ sio.savemat("./static/" + testname.split(',')[0].split('.')[0] + ".mat", {"data": fp_end.data})
413
+
414
+ end = time.clock()
415
+ print('AdjustGraph time: %s Seconds' % (end - start))
416
+ return HttpResponse(json.dumps(data_js), content_type="application/json")
417
+
418
+
419
+ def RelBox(request):
420
+ id = request.GET.get("selectRect")
421
+ print(id)
422
+ global relbox
423
+ global reledge
424
+ rdirgroup=get_dir(id,relbox,reledge)
425
+ return HttpResponse(json.dumps(rdirgroup), content_type="application/json")
426
+
427
+ def get_dir(id,relbox,reledge):
428
+ rel = []
429
+ selectindex = int(id.split("_")[1])
430
+ select = np.zeros(4).astype(int)
431
+ for i in range(len(relbox)):
432
+ a = math.ceil(relbox[i][0][0]), math.ceil(relbox[i][0][1]), math.ceil(relbox[i][0][2]), math.ceil(
433
+ relbox[i][0][3]), int(relbox[i][2])
434
+ rel.append(a)
435
+ if (selectindex == int(relbox[i][2])):
436
+ # select:x1,x0,y0,y1.relbox:x0,y0,x1,y1
437
+ select[0] = math.ceil(relbox[i][0][2])
438
+ select[1] = math.ceil(relbox[i][0][0])
439
+ select[2] = math.ceil(relbox[i][0][1])
440
+ select[3] = math.ceil(relbox[i][0][3])
441
+ rel = np.array(rel)
442
+ df = pd.DataFrame({'x0': rel[:, 0], 'y0': rel[:, 1], 'x1': rel[:, 2], 'y1': rel[:, 3], 'rindex': rel[:, 4]})
443
+ group_label = [(0, 'x1', "right"),
444
+ (1, 'x0', "left"),
445
+ (2, 'y0', "top"),
446
+ (3, 'y1', "down")]
447
+ dfgroup = []
448
+ for i in range(len(group_label)):
449
+ dfgroup.append(df.groupby(group_label[i][1], as_index=True).get_group(name=select[i]))
450
+ rdirgroup = []
451
+ for i in range(len(dfgroup)):
452
+ dir = dfgroup[i]
453
+ rdir = []
454
+ for k in range(len(dir)):
455
+ idx = (dir.loc[dir['rindex'] == (dir.iloc[[k]].values)[0][4]].index.values)[0]
456
+ rdir.append(relbox[idx][1][0].__str__() + "_" + (dir.iloc[[k]].values)[0][4].__str__())
457
+ rdirgroup.append(rdir)
458
+ reledge = np.array(reledge)
459
+ data1 = reledge[np.where((reledge[:, [0]] == selectindex))[0]]
460
+ data2 = reledge[np.where((reledge[:, [1]] == selectindex))[0]]
461
+ reledge1 = np.vstack((data1, data2))
462
+ return rdirgroup
463
+ def Save_Editbox(request):
464
+ global indxlist,boxes_pred
465
+ NewGraph = json.loads(request.GET.get("NewGraph"))
466
+ NewLay = json.loads(request.GET.get("NewLay"))
467
+ userRoomID = request.GET.get("userRoomID")
468
+ adptRoomID = request.GET.get("adptRoomID")
469
+
470
+ NewLay=np.array(NewLay)
471
+ NewLay=NewLay[np.argsort(NewLay[:, 1])][:,2:]
472
+ NewLay=NewLay.astype(float).tolist()
473
+
474
+ test_index = testNameList.index(userRoomID.split(".")[0])
475
+ test_ = test_data[test_index]
476
+
477
+ Boundary = test_.boundary
478
+ boundary=[[float(x),float(y),float(z),float(k)] for x,y,z,k in list(Boundary)]
479
+ test_fp =FloorPlan(test_)
480
+
481
+ train_index = trainNameList.index(adptRoomID.split(".")[0])
482
+ train_ =train_data[train_index]
483
+ train_fp =FloorPlan(train_,train=True)
484
+ fp_end = test_fp.adapt_graph(train_fp)
485
+ fp_end.adjust_graph()
486
+ newNode = NewGraph[0]
487
+ newEdge = NewGraph[1]
488
+ oldNode = NewGraph[2]
489
+ temp = []
490
+ for newindx, newrmname, newx, newy,scalesize in newNode:
491
+ for type, oldrmname, oldx, oldy, oldindx in oldNode:
492
+ if (int(newindx) == oldindx):
493
+ tmp=int(newindx), (newx - oldx), ( newy- oldy),float(scalesize)
494
+ temp.append(tmp)
495
+ newbox=[]
496
+ if mltest.adjust==True:
497
+ oldbox = []
498
+ for i in range(len(boxes_pred)):
499
+ indxtmp=[boxes_pred[i][0],boxes_pred[i][1],boxes_pred[i][2],boxes_pred[i][3],boxes_pred[i][0]]
500
+ oldbox.append(indxtmp)
501
+ if mltest.adjust==False:
502
+ indxlist=[]
503
+ oldbox=fp_end.data.box.tolist()
504
+ for i in range(len(oldbox)):
505
+ indxlist.append([oldbox[i][4]])
506
+ indxlist=np.array(indxlist)
507
+ adjust=True
508
+ oldbox=fp_end.data.box.tolist()
509
+ X=0
510
+ Y=0
511
+ for i in range(len(oldbox)):
512
+ X= X+(oldbox[i][2]-oldbox[i][0])
513
+ Y= Y+(oldbox[i][3]-oldbox[i][1])
514
+ x_ave=(X/len(oldbox))/2
515
+ y_ave=(Y/len(oldbox))/2
516
+
517
+ index_mapping = {}
518
+ # The room that already exists
519
+ # Move: Just by the distance
520
+ for newindx, tempx, tempy,scalesize in temp:
521
+ index_mapping[newindx] = len(newbox)
522
+ tmpbox=[]
523
+ scalesize = int(scalesize)
524
+ if scalesize<1:
525
+ scale = math.sqrt(scalesize)
526
+ scalex = (oldbox[newindx][2] - oldbox[newindx][0]) * (1 - scale) / 2
527
+ scaley = (oldbox[newindx][3] - oldbox[newindx][1]) * (1 - scale) / 2
528
+ tmpbox = [(oldbox[newindx][0] + tempx) + scalex, (oldbox[newindx][1] + tempy)+scaley,
529
+ (oldbox[newindx][2] + tempx) - scalex, (oldbox[newindx][3] + tempy) - scaley, oldbox[newindx][4]]
530
+ if scalesize == 1:
531
+ tmpbox = [(oldbox[newindx][0] + tempx) , (oldbox[newindx][1] + tempy) ,(oldbox[newindx][2] + tempx), (oldbox[newindx][3] + tempy), oldbox[newindx][4]]
532
+
533
+ if scalesize>1:
534
+ scale=math.sqrt(scalesize)
535
+ scalex = (oldbox[newindx][2] - oldbox[newindx][0]) * ( scale-1) / 2
536
+ scaley = (oldbox[newindx][3] - oldbox[newindx][1]) * (scale-1) / 2
537
+ tmpbox = [(oldbox[newindx][0] + tempx) - scalex, (oldbox[newindx][1] + tempy) - scaley,
538
+ (oldbox[newindx][2] + tempx) + scalex, (oldbox[newindx][3] + tempy) + scaley, oldbox[newindx][4]]
539
+
540
+ newbox.append(tmpbox)
541
+
542
+ # The room just added
543
+ # Move: The room node with the average size of the existing room
544
+ for newindx, newrmname, newx, newy,scalesize in newNode:
545
+ if int(newindx)>(len(oldbox)-1):
546
+ scalesize=int(scalesize)
547
+ index_mapping[int(newindx)] = (len(newbox))
548
+ tmpbox=[]
549
+ if scalesize < 1:
550
+ scale = math.sqrt(scalesize)
551
+ scalex = x_ave * (1 - scale) / 2
552
+ scaley = y_ave* (1 - scale) / 2
553
+ tmpbox = [(newx-x_ave) +scalex,(newy-y_ave) +scaley,(newx+x_ave)-scalex,(newy+y_ave)-scaley,vocab['object_name_to_idx'][newrmname]]
554
+
555
+ if scalesize == 1:
556
+ tmpbox = [(newx - x_ave), (newy - y_ave), (newx + x_ave), (newy + y_ave),vocab['object_name_to_idx'][newrmname]]
557
+ if scalesize > 1:
558
+ scale = math.sqrt(scalesize)
559
+ scalex = x_ave * (scale - 1) / 2
560
+ scaley = y_ave * (scale - 1) / 2
561
+ tmpbox = [(newx-x_ave) - scalex, (newy-y_ave) - scaley,(newx+x_ave) + scalex, (newy+y_ave) + scaley,vocab['object_name_to_idx'][newrmname]]
562
+ # tmpboxin = [(newx-x_ave) ,(newy-y_ave) ,(newx+x_ave) ,(newy+y_ave) ,vocab['object_name_to_idx'][newrmname]]
563
+ # print(tmpboxin)
564
+ # print(tmpbox)
565
+ # print(scalesize)
566
+ newbox.append(tmpbox)
567
+
568
+ fp_end.data.box=np.array(newbox)
569
+
570
+ adjust_Edge=[]
571
+ for u, v in newEdge:
572
+ tmp=[index_mapping[int(u)],index_mapping[int(v)], 0]
573
+ adjust_Edge.append(tmp)
574
+ fp_end.data.edge=np.array(adjust_Edge)
575
+ rType = fp_end.get_rooms(tensor=False)
576
+
577
+ rEdge = fp_end.get_triples(tensor=False)[:, [0, 2, 1]]
578
+ Edge = [[float(u), float(v), float(type2)] for u, v, type2 in rEdge]
579
+ Box=NewLay
580
+ boundary_mat = matlab.double(boundary)
581
+ rType_mat = matlab.double(rType.tolist())
582
+ Edge_mat = matlab.double(Edge)
583
+ Box_mat=matlab.double(Box)
584
+ fp_end.data.boundary =np.array(boundary)
585
+ fp_end.data.rType =np.array(rType).astype(int)
586
+ fp_end.data.refineBox=np.array(Box)
587
+ fp_end.data.rEdge=np.array(Edge)
588
+
589
+ box_refine = engview.align_fp(boundary_mat, Box_mat, rType_mat,Edge_mat ,18,False, nargout=3)
590
+ box_out=box_refine[0]
591
+ box_order=box_refine[1]
592
+ rBoundary=box_refine[2]
593
+ fp_end.data.newBox = np.array(box_out)
594
+ fp_end.data.order = np.array(box_order)
595
+ fp_end.data.rBoundary = [np.array(rb) for rb in rBoundary]
596
+ fp_end.data = add_dw_fp(fp_end.data)
597
+ sio.savemat("./static/" + userRoomID + ".mat", {"data": fp_end.data})
598
+ flag=1
599
+ return HttpResponse(json.dumps(flag), content_type="application/json")
600
+
601
+
602
+ def TransGraph_net(request):
603
+ userInfo = request.GET.get("userInfo")
604
+ testname = userInfo.split(',')[0]
605
+ trainname = request.GET.get("roomID")
606
+ mlresult = mltest.get_userinfo_net(testname, trainname)
607
+
608
+ fp_end = mlresult[0]
609
+ boxes_pred = mlresult[1]
610
+
611
+ data_js = {}
612
+ # fp_end hsedge
613
+ data_js["hsedge"] = (fp_end.get_triples(tensor=False)[:, [0, 2, 1]]).astype(np.float).tolist()
614
+
615
+ # fp_end rmpos
616
+ rooms = fp_end.get_rooms(tensor=False)
617
+ room = rooms
618
+ center = [[(x1 + x2) / 2, (y1 + y2) / 2] for x1, y1, x2, y2 in fp_end.data.box[:, :4]]
619
+
620
+
621
+
622
+ # boxes_pred
623
+ data_js["rmpos"] = []
624
+ for k in range(len(center)):
625
+ node = float(room[k]), mdul.room_label[int(room[k])][1], center[k][0], center[k][1]
626
+ data_js["rmpos"].append(node)
627
+ boxes_end = boxes_pred.tolist()
628
+ data_js['roomret'] = []
629
+ for k in range(len(room)):
630
+ data = boxes_end[k], [mdul.room_label[int(room[k])][1]]
631
+ data_js['roomret'].append(data)
632
+
633
+ test_index = testNameList.index(testname.split(".")[0])
634
+ data = test_data[test_index]
635
+ ex = ""
636
+ for i in range(len(data.boundary)):
637
+ ex = ex + str(data.boundary[i][0]) + "," + str(data.boundary[i][1]) + " "
638
+ data_js['exterior'] = ex
639
+ x0, x1 = np.min(data.boundary[:, 0]), np.max(data.boundary[:, 0])
640
+ y0, y1 = np.min(data.boundary[:, 1]), np.max(data.boundary[:, 1])
641
+ data_js['bbxarea'] = float((x1 - x0) * (y1 - y0))
642
+ return HttpResponse(json.dumps(data_js), content_type="application/json")
643
+
644
+
645
+ def GraphSearch(request):
646
+ s=time.clock()
647
+ # Graph
648
+ Searchtype = ["BedRoom", "Bathroom", "Kitchen", "Balcony", "Storage"]
649
+ BedRoomlist = ["MasterRoom", "SecondRoom", "GuestRoom", "ChildRoom", "StudyRoom"]
650
+ NewGraph = json.loads(request.GET.get("NewGraph"))
651
+
652
+ testname = request.GET.get("userRoomID")
653
+ newNode = NewGraph[0]
654
+ newEdge = NewGraph[1]
655
+ r_Num = np.zeros((1, 14)).tolist()
656
+ r_Mask = np.zeros((1, 14)).tolist()
657
+ r_Acc = np.zeros((1, 14)).tolist()
658
+ r_Num[0][0] = 1
659
+ r_Mask[0][0] = 1
660
+ r_Acc[0][0] = 1
661
+
662
+ for indx, rmname, x, y, scalesize in newNode:
663
+ r_Num[0][mdul.vocab['object_name_to_idx'][rmname]] = r_Num[0][mdul.vocab['object_name_to_idx'][rmname]] + 1
664
+ r_Mask[0][mdul.vocab['object_name_to_idx'][rmname]] = 1
665
+ if rmname in BedRoomlist:
666
+ r_Num[0][13] = r_Num[0][13] + 1
667
+ r_Mask[0][13] = 1
668
+
669
+ test_index = testNameList.index(testname.split(".")[0])
670
+ topkList = []
671
+ topkList.clear()
672
+ data = test_data[test_index]
673
+
674
+ Numrooms = json.loads(request.GET.get("Numrooms"))
675
+
676
+
677
+ roomactarr = Numrooms[0]
678
+ roomexaarr = Numrooms[1]
679
+ roomnumarr = [int(x) for x in Numrooms[2]]
680
+ test_data_topk=np.arange(0,74995)
681
+
682
+ if np.sum(roomactarr) != 1 or np.sum(roomexaarr) != 1 or np.sum(roomnumarr) != 1:
683
+ test_num = train_data_rNum[test_data_topk]
684
+ # Number filter
685
+
686
+ filter_func = get_filter_func(roomactarr, roomexaarr, roomnumarr)
687
+ indices = np.where(list(map(filter_func, test_num)))
688
+ # print("np.where(list(map(fil", test_num)
689
+ indices = list(indices)
690
+ test_data_topk = test_data_topk[indices[0]]
691
+
692
+ test_num = train_data_eNum[test_data_topk]
693
+ # Graph filter
694
+
695
+ edgematrix = np.zeros((5, 5))
696
+ for indx1, indx2 in newEdge:
697
+ tmp1 = ""
698
+ tmp2 = ""
699
+ for indx, rmname, x, y, scalesize in newNode:
700
+ if indx1 == indx:
701
+ if rmname in BedRoomlist:
702
+ tmp1 = "BedRoom"
703
+ else:
704
+ tmp1 = rmname
705
+ for indx, rmname, x, y, scalesize in newNode:
706
+ if indx2 == indx:
707
+ if rmname in BedRoomlist:
708
+ tmp2 = "BedRoom"
709
+ else:
710
+ tmp2 = rmname
711
+ if tmp1 != "" and tmp2 != "":
712
+ edgematrix[Searchtype.index(tmp1)][Searchtype.index(tmp2)] = edgematrix[Searchtype.index(tmp1)][
713
+ Searchtype.index(tmp2)] + 1
714
+ edgematrix[Searchtype.index(tmp2)][Searchtype.index(tmp1)] = edgematrix[Searchtype.index(tmp2)][
715
+ Searchtype.index(tmp1)] + 1
716
+ edge = edgematrix.reshape((1, 25))
717
+ filter_graphfunc = filter_graph(edge)
718
+ # rNum_list
719
+ eNumData = []
720
+
721
+ indices = np.where(list(map(filter_graphfunc, test_num)))
722
+
723
+ indices = list(indices)
724
+ tf_trainsub=tf_train[test_data_topk[indices[0]]]
725
+ re_data = train_data[test_data_topk[indices[0]]]
726
+ test_data_tftopk=retrieve_bf(tf_trainsub, data, k=20)
727
+ re_data=re_data[test_data_tftopk]
728
+ if len(re_data) < 20:
729
+ topk = len(re_data)
730
+ else:
731
+ topk = 20
732
+ topkList = []
733
+ for i in range(topk):
734
+ topkList.append(str(re_data[i].name) + ".png")
735
+
736
+ e=time.clock()
737
+ print('Graph Search time: %s Seconds' % (e - s))
738
+
739
+ print("topkList", topkList)
740
+ return HttpResponse(json.dumps(topkList), content_type="application/json")
741
+
742
+
743
+ def retrieve_bf(tf_trainsub, datum, k=20):
744
+ # compute tf for the data boundary
745
+ x, y = rt.compute_tf(datum.boundary)
746
+ y_sampled = rt.sample_tf(x, y, 1000)
747
+ dist = np.linalg.norm(y_sampled - tf_trainsub, axis=1)
748
+ if k > np.log2(len(tf_trainsub)):
749
+ index = np.argsort(dist)[:k]
750
+ else:
751
+ index = np.argpartition(dist, k)[:k]
752
+ index = index[np.argsort(dist[index])]
753
+ return index
754
+
755
+
756
+ if __name__ == "__main__":
757
+ pass
Img/data.mat.png ADDED
Img/data_test_converted.png ADDED
Img/data_train_converted.png ADDED
Img/interface.jpg ADDED
Img/paper.png ADDED
align_fp/align_adjacent_room3.m ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [newBox, constraint] = align_adjacent_room3(box, tempBox, updated, type, threshold)
2
+ % position of box1 relative to box2
3
+ % 0 left-above
4
+ % 1 left-below
5
+ % 2 left-of
6
+ % 3 above
7
+ % 4 inside
8
+ % 5 surrounding
9
+ % 6 below
10
+ % 7 right-of
11
+ % 8 right-above
12
+ % 9 right-below
13
+
14
+
15
+ newBox = box;
16
+ constraint = zeros(4, 2);
17
+ idx = 1;
18
+
19
+ if type == 0
20
+ alignV(true);
21
+ alignH(true);
22
+ elseif type == 1
23
+ alignV(true);
24
+ alignH(false);
25
+ elseif type == 2
26
+ align([2,1], [1,3], threshold);
27
+ align([2,2], [1,2], threshold/2);
28
+ align([2,4], [1,4], threshold/2);
29
+ elseif type == 3
30
+ align([2,2], [1,4], threshold);
31
+ align([2,1], [1,1], threshold/2);
32
+ align([2,3], [1,3], threshold/2);
33
+ elseif type == 4
34
+ align([2,1], [1,1], true);
35
+ align([2,2], [1,2], true);
36
+ align([2,3], [1,3], true);
37
+ align([2,4], [1,4], true);
38
+ elseif type == 5
39
+ align([1,1], [2,1], true);
40
+ align([1,2], [2,2], true);
41
+ align([1,3], [2,3], true);
42
+ align([1,4], [2,4], true);
43
+ elseif type == 6
44
+ align([2,4], [1,2], threshold);
45
+ align([2,1], [1,1], threshold/2);
46
+ align([2,3], [1,3], threshold/2);
47
+ elseif type == 7
48
+ align([2,3], [1,1], threshold);
49
+ align([2,2], [1,2], threshold/2);
50
+ align([2,4], [1,4], threshold/2);
51
+ elseif type == 8
52
+ alignV(false);
53
+ alignH(true);
54
+ elseif type == 9
55
+ alignV(false);
56
+ alignH(false);
57
+ end
58
+
59
+ constraint = constraint(1:idx-1, :);
60
+
61
+ function alignV(isLeft)
62
+ if isLeft
63
+ idx1 = 1;
64
+ idx2 = 3;
65
+ else
66
+ idx1 = 3;
67
+ idx2 = 1;
68
+ end
69
+
70
+ if abs(tempBox(2,idx1) - tempBox(1,idx2)) <= abs(tempBox(2,idx2) - tempBox(1,idx2))
71
+ align([2,idx1], [1,idx2], threshold/2)
72
+ else
73
+ align([2,idx2], [1,idx2], threshold/2)
74
+ end
75
+ end
76
+
77
+ function alignH(isAbove)
78
+ if isAbove
79
+ idx1 = 2;
80
+ idx2 = 4;
81
+ else
82
+ idx1 = 4;
83
+ idx2 = 2;
84
+ end
85
+
86
+ if abs(tempBox(2,idx1) - tempBox(1,idx2)) <= abs(tempBox(2,idx2) - tempBox(1,idx2))
87
+ align([2,idx1], [1,idx2], threshold/2)
88
+ else
89
+ align([2,idx2], [1,idx2], threshold/2)
90
+ end
91
+ end
92
+
93
+ function align(idx1, idx2, threshold, attach)
94
+ if nargin < 4
95
+ attach = false;
96
+ end
97
+ if abs(tempBox(idx1(1),idx1(2))- tempBox(idx2(1), idx2(2))) <= threshold
98
+ if updated(idx1(1), idx1(2)) && ~updated(idx2(1), idx2(2))
99
+ newBox(idx2(1), idx2(2)) = newBox(idx1(1),idx1(2));
100
+ elseif updated(idx2(1), idx2(2)) && ~updated(idx1(1), idx1(2))
101
+ newBox(idx1(1), idx1(2)) = newBox(idx2(1),idx2(2));
102
+ elseif ~updated(idx1(1), idx1(2)) && ~updated(idx2(1), idx2(2))
103
+ if attach
104
+ newBox(idx2(1), idx2(2)) = newBox(idx1(1),idx1(2));
105
+ else
106
+ y = (newBox(idx1(1),idx1(2)) + newBox(idx2(1), idx2(2)))/2;
107
+ newBox(idx1(1),idx1(2)) = y;
108
+ newBox(idx2(1), idx2(2)) = y;
109
+ end
110
+ end
111
+
112
+ if idx1(1) == 1
113
+ constraint(idx, :) = [idx1(2) idx2(2)];
114
+ else
115
+ constraint(idx, :) = [idx2(2) idx1(2)];
116
+ end
117
+ idx = idx + 1;
118
+ end
119
+ end
120
+
121
+ end
align_fp/align_fp.m ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [newBox, order, rBoundary] = align_fp(boundary, rBox, rType, rEdge, fp, threshold, drawResult)
2
+ % align the neighboring rooms first and then align with the boundary
3
+
4
+ if nargin < 7
5
+ drawResult =false;
6
+ end
7
+
8
+ % pre-processing:
9
+ % move the edge relation w.r.t. living room to the end
10
+ livingIdx = find(rType==0);
11
+ idx = rEdge(:,1) == livingIdx-1 | rEdge(:,2) == livingIdx-1;
12
+ % a = rEdge(~idx, :);
13
+ % b = rEdge(idx, :);
14
+ % rEdge = [a; b];
15
+ rEdge = rEdge(~idx, :);
16
+ entranceBox = get_entrance_space(boundary(1:2, 1:2), boundary(1,3), threshold);
17
+
18
+ if drawResult
19
+ clf
20
+ subplot(2,2,1)
21
+ plot_fp(rBox, boundary, rType, entranceBox);
22
+ title('original');
23
+ end
24
+
25
+ %% option #1: use greedy method: align with boundary first and then neighbor
26
+ % 1. align with boundary after the neighbors have been aligned
27
+ [~, newBox, updated] = align_with_boundary(rBox, boundary, threshold, rType);
28
+
29
+ if drawResult
30
+ subplot(2,2,2)
31
+ plot_fp(newBox, boundary, rType, entranceBox);
32
+ title('Align with boundary');
33
+ end
34
+
35
+
36
+ % 2. for each adjacent pair of room,
37
+ [~, newBox, ~] = align_neighbor(newBox, rEdge, updated, threshold+6);
38
+ if drawResult
39
+ subplot(2,2,3)
40
+ plot_fp(newBox, boundary, rType, entranceBox);
41
+ title('Align with neighbors');
42
+ end
43
+
44
+ % 3. regularize fp, include crop using boundary, gap filling
45
+ [newBox, order] = regularize_fp(newBox, boundary, rType);
46
+
47
+ % 4. generate the room polygons
48
+ [newBox, rBoundary] = get_room_boundary(newBox, boundary, order);
49
+
50
+ if drawResult
51
+ subplot(2,2,4)
52
+ plot_fp(newBox(order,:), boundary, rType(order), entranceBox);
53
+ title('Regularize fp');
54
+ end
55
+
56
+ % %% option #2: use optimization to align neighbors, and then align the boundary
57
+ % % 1. get the constraint from the adjacent rooms, and optimize
58
+ % %[constraint1, ~, ~] = align_with_boundary(rBox, boundary, threshold, rNode);
59
+ % [constraint2, ~, ~] = align_neighbor(rBox, rEdge, [], threshold+2);
60
+ % newBox = optimize_fp(rBox, [], constraint2);
61
+ % if drawResult
62
+ % subplot(3,4,6)
63
+ % plot_fp(newBox, boundary, rNode, entranceBox);
64
+ % title('Optimize the neighboring');
65
+ % end
66
+ %
67
+ % % 2. align with boundary after the neighbors have been aligned
68
+ % [constraint1, newBox2, ~] = align_with_boundary(newBox, boundary, threshold, rNode);
69
+ % if drawResult
70
+ % subplot(3,4,7)
71
+ % plot_fp(newBox2, boundary, rNode, entranceBox);
72
+ % title('Align with boundary w/o optimization');
73
+ % end
74
+ %
75
+ % % 3. regularize fp, include crop using boundary, gap filling
76
+ % [newBox2, order] = regularize_fp(newBox2, boundary, rNode);
77
+ % if drawResult
78
+ % subplot(3,4,8)
79
+ % plot_fp(newBox2(order,:), boundary, rNode(order,:), entranceBox);
80
+ % title('Regularize fp');
81
+ % end
82
+ %
83
+ %
84
+ %
85
+ % newBox = optimize_fp(newBox, constraint1, constraint2);
86
+ % if drawResult
87
+ % subplot(3,4,11)
88
+ % plot_fp(newBox, boundary, rNode, entranceBox);
89
+ % title('Align with boundary with optimization');
90
+ % end
91
+ %
92
+ % % 3. regularize fp, include crop using boundary, gap filling
93
+ % [newBox, order] = regularize_fp(newBox, boundary, rNode);
94
+ % if drawResult
95
+ % subplot(3,4,12)
96
+ % plot_fp(newBox(order,:), boundary, rNode(order,:), entranceBox);
97
+ % title('Regularize fp');
98
+ % if ~isempty(figName)
99
+ % saveas(gcf, figName);
100
+ % end
101
+ % end
102
+ %
103
+
104
+
105
+
106
+ %%
107
+ end
108
+
align_fp/align_neighbor.m ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [constraint, box, updated] = align_neighbor(box, rEdge, updated, threshold)
2
+
3
+ if isempty(updated)
4
+ updated = false(size(box));
5
+ end
6
+
7
+ tempBox = box;
8
+ constraint = zeros(size(rEdge, 1)*3, 2);
9
+ iBegin = 1;
10
+ checked = false(size(rEdge, 1), 1);
11
+ updatedCount = get_updated_count(updated, rEdge);
12
+ for i = 1:size(rEdge, 1)
13
+ I = find(~checked);
14
+ [~, t] = maxk(updatedCount(I), 1);
15
+ checked(I(t)) = true;
16
+ idx = rEdge(I(t),1:2)+1;
17
+ [b, c] = align_adjacent_room3(box(idx, :), tempBox(idx, :), updated(idx,:), rEdge(I(t),3), threshold);
18
+ for j = 1:length(idx)
19
+
20
+ updated(idx(j), c(:,j)) = true;
21
+
22
+ c(:, j) = (c(:,j)-1)*size(box,1) + double(idx(j));
23
+
24
+ if b(j, 1) == b(j, 3)
25
+ b(j, [1 3]) = box(idx(j), [1 3]);
26
+ updated(idx(j), c(:,j)) = false;
27
+ end
28
+ if b(j, 2) == b(j, 4)
29
+ b(j, [2 4]) = box(idx(j), [2 4]);
30
+ updated(idx(j), c(:,j)) = false;
31
+ end
32
+
33
+ end
34
+ box(idx, :) = b;
35
+
36
+
37
+ cNum = size(c, 1);
38
+
39
+ constraint(iBegin:iBegin+cNum-1, :) = c;
40
+ iBegin = iBegin+cNum;
41
+
42
+ updatedCount = get_updated_count(updated, rEdge);
43
+ end
44
+ constraint = constraint(1:iBegin-1, :);
45
+
46
+ function updatedCount = get_updated_count(updated, rEdge)
47
+ updatedCount = zeros(size(rEdge, 1), 1);
48
+ for k = 1:size(rEdge, 1)
49
+ index = rEdge(k,1:2)+1;
50
+ updatedCount(k) = sum(sum(updated(index,:)));
51
+ end
52
+ end
53
+ end
align_fp/align_with_boundary.m ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [constraint, box, updated] = align_with_boundary(box, boundary, threshold, rType)
2
+ tempBox = box;
3
+ updated = false(size(box));
4
+ closedSeg = zeros(size(box));
5
+ distSeg = zeros(size(box));
6
+ for i = 1:length(box)
7
+ [closedSeg(i,:), distSeg(i,:)] = find_close_seg(box(i,:), boundary);
8
+ end
9
+
10
+
11
+ box(distSeg <= threshold) = closedSeg(distSeg <= threshold);
12
+ updated(distSeg <= threshold) = true;
13
+ idx = find(distSeg <= threshold);
14
+ constraint = [idx closedSeg(idx)];
15
+
16
+
17
+ % check if any room box blocks the door
18
+ entranceBox = get_entrance_space(boundary(1:2, 1:2), boundary(1,3), threshold);
19
+ entrancePoly = polyshape(entranceBox([1 1 3 3]), entranceBox([2 4 4 2]));
20
+ for i = 1:length(box)
21
+ if rType(i) ~= 10 && rType(i) ~= 0
22
+ roomPoly = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
23
+ if overlaps(entrancePoly, roomPoly)
24
+ box(i,:) = shrink_box(roomPoly, entrancePoly, boundary(1,3));
25
+ updated(i, box(i,:)==tempBox(i,:)) = false;
26
+ updated(i, box(i,:)~=tempBox(i,:)) = true;
27
+ end
28
+ end
29
+ end
align_fp/find_close_seg.m ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [closedSeg, distSeg, idx] = find_close_seg(box, boundary)
2
+
3
+ % need to carefully select the closed wall seg for each box
4
+ % cannot introduce a hole inside the boundary
5
+
6
+ isNew = boundary(:,4);
7
+ boundary = double(boundary(~isNew, :));
8
+
9
+ % get the ordered horizontal and vertical segments on the boundary
10
+ bSeg = [boundary(:, 1:2), boundary([2:end 1], 1:2), boundary(:,3)];
11
+ vSeg = bSeg(mod(boundary(:,3), 2)==1, :);
12
+ vSeg(vSeg(:,5)==3, [2 4]) = vSeg(vSeg(:,5)==3, [4 2]);
13
+ [~, I] = sort(vSeg(:,1));
14
+ vSeg = vSeg(I,:);
15
+
16
+ hSeg = bSeg(mod(boundary(:,3), 2)==0, :);
17
+ hSeg(hSeg(:,5)==2, [1 3]) = hSeg(hSeg(:,5)==2, [3 1]);
18
+ [~, I] = sort(hSeg(:,2));
19
+ hSeg = hSeg(I,:);
20
+
21
+ closedSeg = ones(1,4)*256;
22
+ distSeg = ones(1,4)*256;
23
+ idx = zeros(1, 4);
24
+
25
+ % check vertial seg
26
+ for i = 1:size(vSeg,1)
27
+ seg = vSeg(i, :);
28
+ vdist = 0;
29
+ if seg(4) <= box(2)
30
+ vdist = box(2) - seg(4);
31
+ elseif seg(2) >= box(4)
32
+ vdist = seg(2) - box(4);
33
+ end
34
+
35
+ hdist = box([1 3]) - seg(1);
36
+ dist1 = norm(double([hdist(1), vdist]));
37
+ dist3 = norm(double([hdist(2), vdist]));
38
+
39
+ if dist1 < distSeg(1) && dist1 <= dist3 && hdist(1) > 0
40
+ distSeg(1) = dist1;
41
+ idx(1) = i;
42
+ closedSeg(1) = seg(1);
43
+ elseif dist3 < distSeg(3) && hdist(2) < 0
44
+ distSeg(3) = dist3;
45
+ idx(3) = i;
46
+ closedSeg(3) = seg(3);
47
+ end
48
+ end
49
+
50
+ % check horizontal seg
51
+ for i = 1:size(hSeg,1)
52
+
53
+ seg = hSeg(i, :);
54
+ hdist = 0;
55
+ if seg(3) <= box(1)
56
+ hdist = box(1) - seg(3);
57
+ elseif seg(1) >= box(3)
58
+ hdist = seg(1) - box(3);
59
+ end
60
+
61
+ vdist = box([2 4]) - seg(2);
62
+ dist2 = norm(double([vdist(1), hdist]));
63
+ dist4 = norm(double([vdist(2), hdist]));
64
+
65
+ if dist2 <= dist4 && dist2 < distSeg(2) && vdist(1) > 0
66
+ distSeg(2) = dist2;
67
+ idx(2) = i;
68
+ closedSeg(2) = seg(2);
69
+ elseif dist4 < distSeg(4) && vdist(2) < 0
70
+ distSeg(4) = dist4;
71
+ idx(4) = i;
72
+ closedSeg(4) = seg(4);
73
+ end
74
+ end
align_fp/find_room_order.m ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function order = find_room_order(M)
2
+
3
+ n = size(M,1);
4
+ G = digraph(M);
5
+ name = cell(n,1);
6
+ for i = 1:n
7
+ name{i} = num2str(i);
8
+ end
9
+ G.Nodes.Name = name;
10
+
11
+ order = zeros(n, 1);
12
+ i = 1;
13
+ while i <= n
14
+ D = indegree(G);
15
+ c = find(D==0);
16
+ if isempty(c)
17
+ idx = find(D==1);
18
+ c = setdiff(idx, order);
19
+ order(i) = str2double(G.Nodes.Name{c(1)});
20
+ G = rmnode(G, c(1));
21
+ i = i+1;
22
+ else
23
+ for j = 1:length(c)
24
+ order(i+j-1) = str2double(G.Nodes.Name{c(j)});
25
+ end
26
+ G = rmnode(G, c);
27
+ i = i + length(c);
28
+ end
29
+ end
align_fp/get_entrance_space.m ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ function doorBox = get_entrance_space(doorSeg, doorOri, threshold)
3
+
4
+ doorBox = [doorSeg(1,:) doorSeg(2,:)];
5
+ if doorOri == 0
6
+ doorBox(4) = doorBox(4) + threshold;
7
+ elseif doorOri == 1
8
+ doorBox(1) = doorBox(1) - threshold;
9
+ elseif doorOri == 2
10
+ doorBox(2) = doorBox(2) - threshold;
11
+ elseif doorOri == 3
12
+ doorBox(3) = doorBox(3) + threshold;
13
+ end
14
+
align_fp/get_room_boundary.m ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [newBox, rBoundary] = get_room_boundary(box, boundary, order)
2
+
3
+ isNew = boundary(:,4);
4
+ polyBoundary = polyshape(boundary(~isNew,1), boundary(~isNew,2));
5
+
6
+ poly = cell(size(box,1), 1);
7
+ for i = 1:size(box,1)
8
+ poly{i} = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
9
+ end
10
+
11
+ newBox = box;
12
+ rBoundary = cell(size(box,1), 1);
13
+ for i = 1:size(box,1)
14
+ idx = order(i);
15
+
16
+ rPoly = intersect(polyBoundary, poly{idx});
17
+ for j = i+1:size(box,1)
18
+ rPoly = subtract(rPoly, poly{order(j)});
19
+ end
20
+ rBoundary{idx} = rPoly.Vertices;
21
+ [xLimit, yLimit]= boundingbox(rPoly);
22
+ if ~isempty(xLimit)
23
+ newBox(idx,:) = [xLimit(1) yLimit(1) xLimit(2), yLimit(2)];
24
+ end
25
+ end
align_fp/regularize_fp.m ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [box, order] = regularize_fp(box, boundary, rType)
2
+
3
+ % 1. use the boundary to crop each room box
4
+ isNew = boundary(:,4);
5
+ polyBoundary = polyshape(boundary(~isNew,1), boundary(~isNew,2));
6
+ for i = 1:size(box, 1)
7
+ polyRoom = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
8
+ [xLimit, yLimit] = boundingbox(intersect(polyBoundary,polyRoom));
9
+ if isempty(xLimit)
10
+ disp('One room outside the building!');
11
+ else
12
+ box(i,:) = [xLimit(1) yLimit(1) xLimit(2), yLimit(2)];
13
+ end
14
+ end
15
+
16
+
17
+ % 2. check if there is any overlapped region to determine the layer of boxes
18
+ orderM = false(size(box,1), size(box,1));
19
+ for i = 1:size(box,1)
20
+ polyRoom1 = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
21
+ area1 = area(polyRoom1);
22
+ for j = i+1:size(box,1)
23
+ polyRoom2 = polyshape(box(j, [1 1 3 3]), box(j, [2 4 4 2]));
24
+ area2 = area(polyRoom2);
25
+ inter = intersect(polyRoom1, polyRoom2);
26
+ if inter.NumRegions >= 1
27
+ if area1 <= area2 % may need to add the FP into consideration
28
+ orderM(i,j) = true;
29
+ else
30
+ orderM(j,i) = true;
31
+ end
32
+ end
33
+ end
34
+ end
35
+ order = 1:size(box,1);
36
+ if any(orderM(:))
37
+ order = find_room_order(orderM);
38
+ end
39
+ order = order(end:-1:1);
40
+
41
+ % 3. check if there are more than one uncovered regions inside the building
42
+ livingIdx = find(rType==0);
43
+ for i = 1:size(box, 1)
44
+ if i ~= livingIdx
45
+ if box(i,1)==box(i,3) || box(i,2)==box(i,4)
46
+ disp('Empty box!!!');
47
+ else
48
+ polyRoom = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
49
+ polyBoundary = subtract(polyBoundary,polyRoom);
50
+ end
51
+
52
+ end
53
+ end
54
+ livingPoly = polyshape(box(livingIdx, [1 1 3 3]), box(livingIdx, [2 4 4 2]));
55
+
56
+ gap = polyBoundary;
57
+ if gap.NumRegions == 1
58
+ [xLimit, yLimit] = boundingbox(gap);
59
+ box(livingIdx,:) = [xLimit(1) yLimit(1) xLimit(2), yLimit(2)];
60
+ else
61
+ rIdx = find(isnan(gap.Vertices(:,1)));
62
+ rIdx = [rIdx; size(gap.Vertices,1)+1];
63
+
64
+ % for each region, check if it intersects with the living room,
65
+ % otherwise get the room label and find the room that should cover
66
+ % the region
67
+
68
+ region = cell(length(rIdx), 1);
69
+ overlapArea = zeros(length(rIdx), 1);
70
+ closeRoomIdx = zeros(length(rIdx), 1);
71
+ idx = 1;
72
+ for k = 1:length(rIdx)
73
+ regionV = gap.Vertices(idx:rIdx(k)-1, :);
74
+ idx = rIdx(k) + 1;
75
+ region{k} = polyshape(regionV);
76
+
77
+ if overlaps(region{k}, livingPoly)
78
+ iter = intersect(region{k}, livingPoly);
79
+ overlapArea(k) = area(iter);
80
+ end
81
+
82
+ [x, y] = centroid(region{k});
83
+ center = [x, y];
84
+
85
+ dist = 256;
86
+ bIdx = 0;
87
+ for i = 1:size(box, 1)
88
+ b = box(i, :);
89
+ bCenter = double([(b(:,1)+b(:,3))/2, (b(:,2)+b(:,4))/2]);
90
+ d = norm(bCenter-center);
91
+ if d<dist
92
+ dist = d;
93
+ bIdx = i;
94
+ end
95
+ end
96
+ closeRoomIdx(k) = bIdx;
97
+ end
98
+
99
+ [~, lIdx] = max(overlapArea);
100
+ for k = 1:length(closeRoomIdx)
101
+ if k == lIdx
102
+ [xLimit, yLimit] = boundingbox(region{k});
103
+ box(livingIdx,:) = [xLimit(1) yLimit(1) xLimit(2), yLimit(2)];
104
+ else
105
+ room = polyshape(box(closeRoomIdx(k), [1 1 3 3]), box(closeRoomIdx(k), [2 4 4 2]));
106
+ [xLimit, yLimit] = boundingbox(union(room, region{k}));
107
+ box(closeRoomIdx(k),:) = [xLimit(1) yLimit(1) xLimit(2), yLimit(2)];
108
+ end
109
+ end
110
+ end
111
+
align_fp/shrink_box.m ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function box = shrink_box(roomPoly, entrancePoly, doorOrient)
2
+
3
+ [PG, shapeId, ~] = subtract(roomPoly, entrancePoly);
4
+ idx1 = find(shapeId==1);
5
+ d = idx1(2:end) - idx1(1:end-1);
6
+ i = find(d~=1);
7
+ if ~isempty(i)
8
+ idx1 = idx1([i+1:end 1:i]);
9
+ end
10
+
11
+ idx2 = find(shapeId~=1);
12
+ d = idx2(2:end) - idx2(1:end-1);
13
+ i = find(d~=1);
14
+ if ~isempty(i)
15
+ idx2 = idx2([i+1:end 1:i]);
16
+ end
17
+
18
+ remainPoint = length(idx1);
19
+ if remainPoint == 2
20
+ box = [min(PG.Vertices) max(PG.Vertices)];
21
+ elseif remainPoint == 3
22
+ assert(length(idx2) == 3);
23
+ pointSet1 = PG.Vertices([idx1(1:2); idx2(2)], :);
24
+ pointSet2 = PG.Vertices([idx1(2:3); idx2(2)], :);
25
+ if mod(doorOrient, 2) == 0 % door grow vertically
26
+ if pointSet1(1,1) == pointSet1(2,1)
27
+ box = [min(pointSet1) max(pointSet1)];
28
+ else
29
+ box = [min(pointSet2) max(pointSet2)];
30
+ end
31
+ else
32
+ if pointSet1(1,2) == pointSet1(2,2)
33
+ box = [min(pointSet1) max(pointSet1)];
34
+ else
35
+ box = [min(pointSet2) max(pointSet2)];
36
+ end
37
+ end
38
+ elseif remainPoint == 4
39
+ % elseif remainPoint == 4 && length(idx2) == 4
40
+ % pointSet = PG.Vertices([idx1(2:3); idx2(2:3)], :);
41
+ % box = [min(pointSet) max(pointSet)];
42
+ % elseif remainPoint == 4 % door inside the box
43
+ [x1, y1] = centroid(roomPoly);
44
+ [x2, y2] = centroid(entrancePoly);
45
+ box = [min(roomPoly.Vertices) max(roomPoly.Vertices)];
46
+ if mod(doorOrient, 2) == 0 % door grow vertically
47
+ if x1 < x2
48
+ box(3) = min(entrancePoly.Vertices(:,1));
49
+ else
50
+ box(1) = max(entrancePoly.Vertices(:,1));
51
+ end
52
+ else
53
+ if y1 < y2
54
+ box(4) = min(entrancePoly.Vertices(:,2));
55
+ else
56
+ box(2) = max(entrancePoly.Vertices(:,2));
57
+ end
58
+ end
59
+ else
60
+ disp(['There are other cases with point number = ', num2str(length(shapeId))]);
61
+ end
db.sqlite3 ADDED
File without changes
manage.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+ import os
4
+ import sys
5
+
6
+
7
+ def main():
8
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'House.settings')
9
+ try:
10
+ from django.core.management import execute_from_command_line
11
+ except ImportError as exc:
12
+ raise ImportError(
13
+ "Couldn't import Django. Are you sure it's installed and "
14
+ "available on your PYTHONPATH environment variable? Did you "
15
+ "forget to activate a virtual environment?"
16
+ ) from exc
17
+ execute_from_command_line(sys.argv)
18
+
19
+
20
+ if __name__ == '__main__':
21
+ main()
model/__pycache__/_floorplan2.cpython-37.pyc ADDED
Binary file (2.67 kB). View file
 
model/__pycache__/add_archs.cpython-37.pyc ADDED
Binary file (13.3 kB). View file
 
model/__pycache__/box_utils.cpython-37.pyc ADDED
Binary file (4.07 kB). View file
 
model/__pycache__/crn.cpython-37.pyc ADDED
Binary file (3.06 kB). View file
 
model/__pycache__/floorplan.cpython-311.pyc ADDED
Binary file (17.6 kB). View file