forked from s_ranjbar/city_retrofit
obj export to ground reference
This commit is contained in:
parent
f98a341ea2
commit
8f36b88571
|
@ -6,7 +6,7 @@
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv2" />
|
<excludeFolder url="file://$MODULE_DIR$/venv2" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv38" />
|
<excludeFolder url="file://$MODULE_DIR$/venv38" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.8 (libs) (2)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.7 (venv)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PackageRequirementsSettings">
|
<component name="PackageRequirementsSettings">
|
||||||
|
|
|
@ -7,6 +7,7 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
|
||||||
from exports.formats.stl import Stl
|
from exports.formats.stl import Stl
|
||||||
from exports.formats.obj import Obj
|
from exports.formats.obj import Obj
|
||||||
|
|
||||||
|
|
||||||
class ExportsFactory:
|
class ExportsFactory:
|
||||||
"""
|
"""
|
||||||
Exports factory class
|
Exports factory class
|
||||||
|
@ -38,7 +39,7 @@ class ExportsFactory:
|
||||||
Export the city geometry to obj
|
Export the city geometry to obj
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
return Obj(self._city, self._path)
|
return Obj(self._city, self._path).to_ground_points()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _idf(self):
|
def _idf(self):
|
||||||
|
|
|
@ -1,5 +1,25 @@
|
||||||
from exports.formats.triangular import Triangular
|
from exports.formats.triangular import Triangular
|
||||||
|
from pathlib import Path
|
||||||
|
from imports.geometry_factory import GeometryFactory
|
||||||
|
import trimesh.exchange.obj
|
||||||
|
from trimesh import Trimesh
|
||||||
|
|
||||||
|
|
||||||
class Obj(Triangular):
|
class Obj(Triangular):
|
||||||
def __init__(self, city, path):
|
def __init__(self, city, path):
|
||||||
super().__init__(city, path, 'obj')
|
super().__init__(city, path, 'obj')
|
||||||
|
|
||||||
|
def to_ground_points(self):
|
||||||
|
reference_coordinates = self._city.lower_corner
|
||||||
|
file_name_in = self._city.name + '.' + self._triangular_format
|
||||||
|
file_name_out = self._city.name + '_ground.' + self._triangular_format
|
||||||
|
file_path_in = (Path(self._path).resolve() / file_name_in).resolve()
|
||||||
|
file_path_out = (Path(self._path).resolve() / file_name_out).resolve()
|
||||||
|
scene_dic = GeometryFactory('obj', file_path_in).scene
|
||||||
|
for vertex in scene_dic['vertices']:
|
||||||
|
for i in range(0, 3):
|
||||||
|
vertex[i] -= reference_coordinates[i]
|
||||||
|
scene = Trimesh(vertices=scene_dic['vertices'], faces=scene_dic['faces'])
|
||||||
|
obj_file = trimesh.exchange.obj.export_obj(scene)
|
||||||
|
with open(file_path_out, 'w') as file:
|
||||||
|
file.write(obj_file)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from exports.formats.triangular import Triangular
|
from exports.formats.triangular import Triangular
|
||||||
|
|
||||||
|
|
||||||
class Stl(Triangular):
|
class Stl(Triangular):
|
||||||
def __init__(self, city, path):
|
def __init__(self, city, path):
|
||||||
super().__init__(city, path, 'stl')
|
super().__init__(city, path, 'stl')
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from trimesh import Trimesh
|
from trimesh import Trimesh
|
||||||
|
|
||||||
|
|
||||||
class Triangular:
|
class Triangular:
|
||||||
def __init__(self, city, path, triangular_format):
|
def __init__(self, city, path, triangular_format):
|
||||||
self._city = city
|
self._city = city
|
||||||
|
|
|
@ -7,6 +7,7 @@ from city_model_structure.city import City
|
||||||
from city_model_structure.city_object import CityObject
|
from city_model_structure.city_object import CityObject
|
||||||
from imports.geometry_feeders.city_gml import CityGml
|
from imports.geometry_feeders.city_gml import CityGml
|
||||||
from imports.geometry_feeders.osm_subway import OsmSubway
|
from imports.geometry_feeders.osm_subway import OsmSubway
|
||||||
|
from imports.geometry_feeders.obj import Obj
|
||||||
|
|
||||||
|
|
||||||
class GeometryFactory:
|
class GeometryFactory:
|
||||||
|
@ -25,6 +26,10 @@ class GeometryFactory:
|
||||||
def _stl(self):
|
def _stl(self):
|
||||||
raise Exception('Not implemented')
|
raise Exception('Not implemented')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _obj(self):
|
||||||
|
return Obj(self._path).scene
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _geojson(self):
|
def _geojson(self):
|
||||||
raise Exception('Not implemented')
|
raise Exception('Not implemented')
|
||||||
|
@ -41,6 +46,14 @@ class GeometryFactory:
|
||||||
"""
|
"""
|
||||||
return getattr(self, self._file_type, lambda: None)
|
return getattr(self, self._file_type, lambda: None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scene(self):
|
||||||
|
"""
|
||||||
|
Load the city model structure from a geometry source
|
||||||
|
:return: Trimesh
|
||||||
|
"""
|
||||||
|
return getattr(self, self._file_type, lambda: None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _city_debug(self):
|
def _city_debug(self):
|
||||||
return CityGml(self._path).city
|
return CityGml(self._path).city
|
||||||
|
|
21
imports/geometry_feeders/obj.py
Normal file
21
imports/geometry_feeders/obj.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
"""
|
||||||
|
Obj module parses obj files and import the geometry into the city model structure
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2020 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
|
"""
|
||||||
|
import trimesh.exchange.obj
|
||||||
|
|
||||||
|
|
||||||
|
class Obj:
|
||||||
|
"""
|
||||||
|
Obj class
|
||||||
|
"""
|
||||||
|
def __init__(self, path):
|
||||||
|
self._city = None
|
||||||
|
with open(path, 'r') as file:
|
||||||
|
self._scene = trimesh.exchange.obj.load_obj(file)
|
||||||
|
# todo: review class trimesh.exchange.load that returns Trimesh or Trimesh.scene
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scene(self) -> dict:
|
||||||
|
return self._scene
|
|
@ -1,10 +1,11 @@
|
||||||
xmltodict~=0.12.0
|
xmltodict~=0.12.0
|
||||||
numpy~=1.20.1
|
numpy~=1.20.1
|
||||||
trimesh~=3.9.8
|
trimesh~=3.9.9
|
||||||
pyproj~=3.0.1
|
pyproj~=3.0.1
|
||||||
pandas~=1.2.3
|
pandas~=1.2.3
|
||||||
requests~=2.25.1
|
requests~=2.25.1
|
||||||
esoreader~=1.2.3
|
esoreader~=1.2.3
|
||||||
geomeppy~=0.11.8
|
geomeppy~=0.11.8
|
||||||
open3d~=0.12.0
|
open3d~=0.12.0
|
||||||
pathlib~=1.0.1
|
pathlib~=1.0.1
|
||||||
|
PyWavefront~=1.3.3
|
|
@ -9,6 +9,7 @@ from unittest import TestCase
|
||||||
from imports.geometry_factory import GeometryFactory
|
from imports.geometry_factory import GeometryFactory
|
||||||
from exports.exports_factory import ExportsFactory
|
from exports.exports_factory import ExportsFactory
|
||||||
|
|
||||||
|
|
||||||
class TestExports(TestCase):
|
class TestExports(TestCase):
|
||||||
"""
|
"""
|
||||||
TestGeometryFactory TestCase 1
|
TestGeometryFactory TestCase 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user