int main(int argc, char **argv) { const char *value; p_ply iply, oply; iply = ply_open("input.ply", NULL); if (!iply) return 1; if (!ply_read_header(iply)) return 1; oply = ply_create("output.ply", PLY_LITTLE_ENDIAN, NULL); if (!oply) return 1; if (!setup_callbacks(iply, oply)) return 1; /* pass comments and obj_infos from input to output */ value = NULL; while ((value = ply_get_next_comment(iply, value))) if (!ply_add_comment(oply, value)) return 1; value = NULL; while ((value = ply_get_next_obj_info(iply, value))) if (!ply_add_obj_info(oply, value)) return 1;; /* write output header */ if (!ply_write_header(oply)) return 1; /* read input file generating callbacks that pass data to output file */ if (!ply_read(iply)) return 1; /* close up, we are done */ if (!ply_close(iply)) return 1; if (!ply_close(oply)) return 1; return 0; }
/* given a format mode, an input file name and an output file name, * convert input file to output in given format mode */ int main(int argc, char **argv) { const char *value = NULL; e_ply_storage_mode storage_mode = PLY_LITTLE_ENDIAN; const char *iname = NULL, *oname = NULL; p_ply iply = NULL, oply = NULL; /* parse command line arguments */ parse_arguments(argc, argv, &storage_mode, &iname, &oname); /* open input file and make sure we parsed its header */ iply = ply_open(iname, NULL, 0, NULL); if (!iply) error("Unable to open file '%s'", iname); if (!ply_read_header(iply)) error("Failed reading '%s' header", iname); /* create output file */ oply = ply_create(oname, storage_mode, NULL, 0, NULL); if (!oply) error("Unable to create file '%s'", oname); /* create elements and properties in output file and * setup callbacks for them in input file */ setup_callbacks(iply, oply); /* pass comments and obj_infos from input to output */ value = NULL; while ((value = ply_get_next_comment(iply, value))) if (!ply_add_comment(oply, value)) error("Failed adding comments"); value = NULL; while ((value = ply_get_next_obj_info(iply, value))) if (!ply_add_obj_info(oply, value)) error("Failed adding comments"); /* write output header */ if (!ply_write_header(oply)) error("Failed writing '%s' header", oname); /* read input file generating callbacks that pass data to output file */ if (!ply_read(iply)) error("Conversion failed"); /* close up, we are done */ if (!ply_close(iply)) error("Error closing file '%s'", iname); if (!ply_close(oply)) error("Error closing file '%s'", oname); return 0; }
/******************************************************************************* * Name: main * Description: ******************************************************************************/ int main( void ) { int i; /* Create new PLY file. */ p_ply oply = ply_create( "new.ply", PLY_ASCII, NULL, 0, NULL ); if ( !oply ) { fprintf( stderr, "ERROR: Could not create »new.ply«\n" ); return EXIT_FAILURE; } /* Add object information to PLY. */ if ( !ply_add_obj_info( oply, "This is just a test." ) ) { fprintf( stderr, "ERROR: Could not add object info.\n" ); return EXIT_FAILURE; } /* Add a comment, too. */ if ( !ply_add_comment( oply, "Just some comment…" ) ) { fprintf( stderr, "ERROR: Could not add comment.\n" ); return EXIT_FAILURE; } /* Add vertex element. We want to add 9999 vertices. */ if ( !ply_add_element( oply, "vertex", 99999 ) ) { fprintf( stderr, "ERROR: Could not add element.\n" ); return EXIT_FAILURE; } /* Add vertex properties: x, y, z, r, g, b */ if ( !ply_add_property( oply, "x", PLY_FLOAT, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } if ( !ply_add_property( oply, "y", PLY_FLOAT, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } if ( !ply_add_property( oply, "z", PLY_FLOAT, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } if ( !ply_add_property( oply, "red", PLY_UCHAR, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } if ( !ply_add_property( oply, "green", PLY_UCHAR, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } if ( !ply_add_property( oply, "blue", PLY_UCHAR, 0, 0 ) ) { fprintf( stderr, "ERROR: Could not add property x.\n" ); return EXIT_FAILURE; } /* Write header to file */ if ( !ply_write_header( oply ) ) { fprintf( stderr, "ERROR: Could not write header.\n" ); return EXIT_FAILURE; } /* Now we generate random data to add to the file: */ srand ( time( NULL ) ); for ( i = 0; i < 99999; i++ ) { ply_write( oply, (double) ( rand() % 10000 ) / 10.0 ); /* x */ ply_write( oply, (double) ( rand() % 10000 ) / 10.0 ); /* y */ ply_write( oply, (double) ( rand() % 10000 ) / 10.0 ); /* z */ ply_write( oply, rand() % 256 ); /* red */ ply_write( oply, rand() % 256 ); /* blue */ ply_write( oply, rand() % 256 ); /* green */ } if ( !ply_close( oply ) ) { fprintf( stderr, "ERROR: Could not close file.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; }