a `§»e¯ã@s ddlZddlmZdd„ZdS)éN)Úlogc Cs€t|ƒ*}tttj| ¡ d¡ƒƒ}Wdƒn1s80Yt|ƒdksj|ddksj|d ¡dkrvtd|ƒ‚t |d ƒ}g}|dd|…D]r}| d ¡^}} t j   |¡} t j   |¡} | | ¡} | durö| d t j  | | ¡d  | ¡f¡q–t d | |f¡q–|t|ƒkr$td |ƒ‚t|dƒ<}| dt|ƒ¡| d |¡¡| d¡Wdƒn1sr0YdS)a Create a new NVM file from an existing NVM file replacing the image references based on img_map where img_map is a dict { "old_image" --> "new_image" } (filename only). The function does not write the points information (they are discarded) Ú NérZNVM_V3éÚz'%s does not seem to be a valid NVM fileéÚ z%s %sz"Cannot find %s in image map for %sz6Cannot write %s, not all band images have been matchedÚwz NVM_V3 %s z 0 0 0)ÚopenÚlistÚmapÚstrÚstripÚreadÚsplitÚlenÚ ExceptionÚintÚosÚpathÚdirnameÚbasenameÚgetÚappendÚjoinrÚ ODM_WARNINGÚwrite) Z src_nvm_fileÚimg_mapZ dst_nvm_fileÚfÚlinesZ num_imagesÚentriesÚlÚ image_pathÚpZdir_nameÚ file_nameZ new_filename©r%ú/code/opendm/nvm.pyÚreplace_nvm_imagess( 8(     $  r')rÚopendmrr'r%r%r%r&Ús