; docformat = 'rst' ; ; NAME: ; writeVer ; PURPOSE: ; Write a 3-D shape model in VER format ;+ ; :Description: ; Write a 3-D shape model in VER format ; ; :Categories: ; Disk I/O, Shape Models ; ; :Params: ; file: in, required, type=string ; A path to the file containing the 3-D shape model in VER format ; model: in, required, type=structure ; A structure containing the 3-D shape model. Fields are:: ; .VERTEX: A structure with Information on Vertex:: ; .N = Number of Vertex ; .XYZ= Cartesian coordinates of the vertex ; .FACET: A structure with Information on Facet:: ; .N = Number of Facets ; .CON = Connectivity array ([N_vertex, ID_vertex....]) ; ; :Examples: ; Write the shape model structure mymodel in the file myfile.ver ; IDL> writeVer, 'myfile.ver', mymodel ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in April 2014, B. Carry (OCA) ;- pro writeVer, file, model COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Input Syntax Verification ---------------------------------------------------- if n_params() lt 2 then begin message, /IOERROR, 'Syntax : writeVer, file, model' stop endif ;--I.2-- Check Input Model Structure -------------------------------------------- nTag = N_tags(model) tags = tag_names(model) ;print, nTag ;print, tags ; if not file_test(file,/READ) then begin ; message, 'ERROR: Cannot find the input file: '+strtrim(file,2) ; return, -2 ; endif ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Write the 3-D Shape Model File -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Open the File ---------------------------------------------------------- openw, idOut, file, /GET_LUN ;--II.2-- Number of Facets and Vertices ------------------------------------------ printf, idOut, strtrim(string(model.vertex.N,format='(I)'),2)+' '+$ strtrim(string(model.facet.N, format='(I)'),2) ;--II.3-- Write Vertex Cartesian Coordinates ------------------------------------- for kVert=0L, model.vertex.N-1L do begin printf, idOut, model.vertex.xyz[0,kVert], $ model.vertex.xyz[1,kVert], $ model.vertex.xyz[2,kVert], $ format='(F10.4,2x,F10.4,2x,F10.4)' endfor ;--II.3-- Write Facet = Vertex Connections --------------------------------------- for kFacet=0L, model.facet.N-1 do $ printf, idOut, model.facet.con[4*kFacet+1]+1L, $ model.facet.con[4*kFacet+2]+1L, $ model.facet.con[4*kFacet+3]+1L, $ format='(I5,2x,I5,2x,I5)' ;--II.4-- Close Shape Model File ------------------------------------------------- close, idOut free_lun, idOut end