""" Services implemented: GMS/PointCloud/calls/potreeConverte POST: PotreeConverter generates an octree LOD structure for streaming and real-time rendering of massive point clouds. """ from monitorT.task import Task from tools.layer import Layer, OutLayer import os import shutil import random import string import zipfile class TaskCustom(Task): CONTROL = False def post(task, user=None, input_layer: Layer = None, output_layer: OutLayer = None, title=None, description=None, material=None, output_attributes=None, output_format=None, intensity_range=None, color_range=None, page_name=None, projection=None, skybox=None, incremental=None, overwrite=True): """ Servicio PotreeConverter genera una estructura LOD octtree para transmisiĆ³n y representaciĆ³n en tiempo real de nubes de puntos masivas. Parameters ---------- user: str User ID input_layer: Layer Input Layer output_layer: OutLayer Output Layer title: str Potree title description: str Potree description material: str RGB, ELEVATION, INTENSITY, INTENSITY_GRADIENT, RETURN_NUMBER, SOURCE, LEVEL_OF_DETAIL output_attributes: str Can be any combination of RGB, INTENSITY and CLASSIFICATION. Default is RGB. output_format: str Output format can be BINARY, LAS or LAZ. Default is BINARY intensity_range: str Intensity range (0-255) color_range: str Color range (0-255) incremental: bool Add new points to existing conversion page_name: str Generates a ready to use web page with the given name. projection: str Projection in proj4 format. skybox: bool Possibles enviroment overwrite: bool Overwrite the last potree Returns ------- Examples >>> input_layer: World Layer >>> output_layer: Output Layer >>> title: Potree title >>> description: Potree description >>> material: RGB, ELEVATION >>> output_attributes: RGB, INTENSITY >>> output_format: LAS >>> intensity_range: 0 255 >>> color_range: 0 255 >>> incremental: False >>> page_name: SRM >>> projection: "+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs" >>> skybox: False >>> overwrite: False """ if title is None: title_potree = '' else: title_potree = """ --title "{}" """.format(title) if description is None: descrip_potree = '' else: descrip_potree = """ --description "{}" """.format(description) # valid_output_attributes = ['RGB','INTENSITY','CLASSIFICATION'] # if not output_attributes in valid_output_attributes: # raise NameError('Modo no soportado') valid_output_attributes = ['RGB', 'INTENSITY', 'CLASSIFICATION'] if isinstance(output_attributes, str): output_attributes_check = output_attributes.split(",") if not set(output_attributes_check).issubset(set(valid_output_attributes)): # if not i in valid_output_attributes: raise NameError('Modo no soportado') output_attributes = output_attributes.replace(",", " ") # valid_output_format = ['BINARY','LAS','LAZ'] # if not output_format in valid_output_format: # raise NameError('Modo no soportado') valid_output_format = ['BINARY', 'LAS', 'LAZ'] if not output_format in valid_output_format: # if not i in valid_output_attributes: raise NameError('Modo no soportado') valid_material = ['RGB', 'ELEVATION', 'INTENSITY', 'INTENSITY_GRADIENT', 'RETURN_NUMBER', 'SOURCE', 'LEVEL_OF_DETAIL'] if type(material) == str: material_check = material.split(",") if not set(material_check).issubset(set(valid_material)): # if not i in valid_output_attributes: raise NameError('Modo no soportado') material = material.replace(",", " ") if color_range is True or color_range == 'true': color_range = '--color-range' else: color_range = '' if intensity_range is True or intensity_range == 'true': intensity_range = '--intensity-range' else: intensity_range = '' # if page_name == True or page_name == 'true': # page_name = '- p' # else: # page_name = '' if projection is None: projection1 = '' else: projection1 = """ --projection "{}" """.format(projection) if skybox is True or skybox == 'true': skybox = '--show-skybox' else: skybox = '' if overwrite is True: overwrite = '--overwrite' else: overwrite = '' if incremental is True: incremental = '--incremental' overwrite = '' else: incremental = '' letters_and_digits = string.ascii_letters + string.digits rnd = ''.join((random.choice(letters_and_digits) for i in range(8))) url_tmp = './tmp/potreeConverter/' + user + '_' + rnd shutil.rmtree(url_tmp, ignore_errors=True) if not os.path.exists(url_tmp): os.makedirs(url_tmp) input_layer.protocol.download(input_layer['source'], url_tmp+'/'+rnd+'_input') variable1 = url_tmp+'/'+rnd+'_input' variable2 = url_tmp+'/'+rnd command = """ PotreeConverter {input} -o {output} -p "{page_name}" {color_range} {intensity_range} --output-format {output_format} -a {output_attributes} {overwrite} {incremental} {projection} {title} {description} {skybox}--material {material} """.format(input=variable1, output=variable2, page_name=page_name, color_range=color_range, intensity_range=intensity_range, output_format=output_format, output_attributes=output_attributes, overwrite=overwrite, projection=projection1, title=title_potree, description=descrip_potree, skybox=skybox, material=material, incremental=incremental) os.system(command) zipf = zipfile.ZipFile(url_tmp+'/'+rnd+'.zip', 'w', url_tmp+'/'+rnd) zipf.close() output_layer.attach_sources((url_tmp+'/'+rnd+'.zip', )) output_layer.residual_sources.append(url_tmp) return output_layer