function polygonal_surface_display ( node_file_name, triangle_file_name ) %% TRI_MESH_DISPLAY displays a 3D triangular mesh. % % Modified: % % 26 February 2007 % % Author: % % John Burkardt % % Parameters: % % Input, string NODE_FILE_NAME, the name of the node file. % % Input, string TRIANGLE_FILE_NAME, the name of the triangle file. % timestamp; fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY\n' ); fprintf ( 1, ' Read the nodes and triangles defining\n' ); fprintf ( 1, ' a triangulated 3D surface and display the object\n' ); fprintf ( 1, ' as a MATLAB shape.\n' ); % % If at least one command line argument, it's the node file name. % if ( nargin < 1 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY:\n' ); node_file_name = input ( 'Enter the name of the node file:' ); end % % If at least two command line arguments, it's the triangle file name. % if ( nargin < 2 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY:\n' ); triangle_file_name = input ( 'Enter the name of the triangle file:' ); end % % Read the node data. % [ dim_num, node_num ] = dtable_header_read ( node_file_name ); fprintf ( 1, '\n' ); fprintf ( 1, ' Spatial dimension of nodes = %d\n', dim_num ); fprintf ( 1, ' Number of nodes = %d\n', node_num ); if ( dim_num ~= 3 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY - Fatal error!\n' ); fprintf ( 1, ' The nodes do not have dimension 3.\n' ); error ( 'TRI_MESH_DISPLAY - Fatal error!\n' ); end node_xyz = dtable_data_read ( node_file_name, dim_num, node_num ); r8mat_transpose_print_some ( dim_num, node_num, node_xyz, ... 1, 1, dim_num, 5, ' First five nodes:' ); % % Read the triangle data. % [ triangle_order, triangle_num ] = itable_header_read ( triangle_file_name ); fprintf ( 1, '\n' ); fprintf ( 1, ' Order of triangles = %d\n', triangle_order ); fprintf ( 1, ' Number of triangles = %d\n', triangle_num ); if ( triangle_order ~= 3 ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY - Fatal error!\n' ); fprintf ( 1, ' The triangles do not have order 3.\n' ); error ( 'TRI_MESH_DISPLAY - Fatal error!\n' ); end triangle_node = itable_data_read ( triangle_file_name, triangle_order, ... triangle_num ); i4mat_transpose_print_some ( triangle_order, triangle_num, triangle_node, ... 1, 1, triangle_order, 5, ' First five triangles:' ); % % Display the image as a collection of polygons. % trisurf ( triangle_node', node_xyz(1,:), node_xyz(2,:), node_xyz(3,:) ) % colormap ( gray ) axis equal; grid on; xlabel ( '--X Axis--' ) ylabel ( '--Y Axis--' ) zlabel ( '--Z Axis--' ) % % The TITLE function will interpret underscores in the title. % We need to unescape such escape sequences! % title_string = s_escape_tex ( triangle_file_name ); title ( title_string ) fprintf ( 1, '\n' ); fprintf ( 1, 'TRI_MESH_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp;