a `e@sddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddZ d d d Z d d Z d dZd!ddZddZddZddZddZddZddZddZdS)"N)system)log) double_quote)datetimecCsdgiS)z' Create initial JSON for PDAL pipeline pipelinerrr/code/opendm/dem/pdal.py json_base/sr cCsXt}d||||dd}|durDd|d|d|d|d f|d <|d d ||S) zC Create initial JSON for PDAL pipeline containing a Writer element z writers.gdalfloat)type resolutionradiusfilename output_type data_typeNz([%s,%s],[%s,%s])minxmaxxminymaxyboundsrrr insert)rrrr rjsondrrrjson_gdal_base4s $rcCs t}|ddd|d|S)z/ Create initial JSON for writing to a LAS file rrz writers.lasr rr)foutrrrr json_las_baseIs  rcCs|ddd|d|S)z* Add decimation Filter element and return rrzfilters.decimation)r step)r)rrrrrjson_add_decimation_filterSs  r equalscCs6d|}|dkrd|}|ddd|d|S)z. Add classification Filter element and return zClassification[{0}:{0}]maxzClassification[:{0}]rrz filters.range)r limits)formatr)rZclassificationequalityr#rrrjson_add_classification_filter\s   r&cCstj|\}}|dkS)Nz.ply)ospathsplitextlower)r_extrrr is_ply_fileisr-cCs2d}t|rd}|dd|tj|d|S)z Add Reader Element and return z readers.lasz readers.plyrrr)r-rr'r(abspath)rrZ reader_typerrrjson_add_readerns  r/cCs8|D]}t||qt|dkr4|ddddi|S)zT Add merge Filter element and readers to a Writer element and return Filter element r rrr z filters.merge)r/lenr)r filenamesfrrrjson_add_readers{s   r3cCsbtjdd\}}t|t|dt|dddt|g}t d |t |dS) z& Run PDAL Pipeline with provided JSON z.json)suffixutf8pdalr-i %s N) tempfilemkstempr'writejsonlibdumpsencodecloserrrunjoinremove)rr2Zjsonfilecmdrrr run_pipelines  rDc CsBddd|d|dd|d|d|d |g }td |d S) z Run PDAL translate r6 translater7z-o %sZsmrfz--filters.smrf.scalar=%sz--filters.smrf.slope=%sz--filters.smrf.threshold=%sz--filters.smrf.window=%sr8Nrr@rA)finrscalarslope thresholdwindowrCrrrrun_pdaltranslate_smrfs rLcCsJt|dkrtddSdddtt||gg}td|dS)Nrz4Cannot merge point clouds, no point clouds to merge.r6merger8)r0r ODM_WARNINGrAmaprrr@)Z input_files output_filerCrrrmerge_point_cloudss  rQcCs(ddd|d|g}td|dS)Nr6rEz-i "%s"z-o "%s"r8rF)inputoutputrCrrrrEs rE)r N)r!)r'sysrr<r9opendmrr opendm.utilsrrr rrr r&r-r/r3rDrLrQrErrrr!s&