Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r433 - branches/itanium2/Readers/DoubleEagle
- Date: Fri, 15 Jul 2005 01:30:45 -0600 (MDT)
Author: abe
Date: Fri Jul 15 01:30:44 2005
New Revision: 433
Added:
branches/itanium2/Readers/DoubleEagle/
branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
Log:
Added DoubleEagle reader directory
Added: branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc Fri Jul 15 01:30:44
2005
@@ -0,0 +1,329 @@
+#include <sys/types.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include <MantaTypes.h>
+#include <Core/Color/ColorDB.h>
+#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/BBox.h>
+
+using namespace std;
+using namespace Manta;
+
+// This program loads data files from the Double Eagle tanker and produces
+// one v3c1 file with per face color information.
+// The program takes the input path (and recursively examines all
subdirectories)
+// as well as the output file name.
+
+void search_directory ( const char *directory_name, unsigned char
current_color[3] );
+void process_data_file( const char *file_name, unsigned char
current_color[3] );
+void v3c1_info( const char *file_name );
+
+FILE *out_file = 0;
+int total_faces = 0;
+
+BBox bounds;
+
+struct nv3_face {
+ float normal0[3];
+ float vertex0[3];
+ float normal1[3];
+ float vertex1[3];
+ float normal2[3];
+ float vertex2[3];
+};
+
+struct v3c1_face {
+ float vertex0[3];
+ float vertex1[3];
+ float vertex2[3];
+ float color[3];
+
+ v3c1_face() { };
+ v3c1_face( const nv3_face &nv_, unsigned char new_color[3] ) {
+
+ memcpy( vertex0, nv_.vertex0, 3*sizeof(float) );
+ memcpy( vertex1, nv_.vertex1, 3*sizeof(float) );
+ memcpy( vertex2, nv_.vertex2, 3*sizeof(float) );
+
+ color[0] = 0.003921f * (float)new_color[0];
+ color[1] = 0.003921f * (float)new_color[1];
+ color[2] = 0.003921f * (float)new_color[2];
+
+ }
+};
+
+vector<nv3_face> in_buffer;
+vector<v3c1_face> out_buffer;
+
+enum CommandType { NONE, CONVERT, INFO };
+
+
+int main( int argc, char **argv ) {
+
+ int file_list_begin = 0;
+ int file_list_end = 0;
+ char *output_file_name = 0;
+
+ CommandType command = NONE;
+
+ // Check the command line args.
+ for (int i=1;i<argc;++i) {
+ string arg = argv[i];
+
+ if (arg == "-path") {
+ command = CONVERT;
+
+ file_list_begin = ++i;
+ file_list_end = file_list_begin+1;
+
+ while ((file_list_end < argc) &&
(argv[file_list_end][0] != '-')) {
+ ++file_list_end;
+ }
+ }
+ else if (arg == "-file") {
+ output_file_name = argv[++i];
+ }
+ else if (arg == "-info") {
+ command = INFO;
+
+ file_list_begin = ++i;
+ file_list_end = file_list_begin+1;
+
+ while ((file_list_end < argc) &&
(argv[file_list_end][0] != '-')) {
+ ++file_list_end;
+ }
+ }
+ }
+
+ // Check that both were found.
+ if ((command == NONE) || (file_list_begin == 0)) {
+ printf( "Usage: v2v3c1 -path <tanker path> -file
<outfile.v3c1>\n"
+ " v2v3v1 -info <infile.v3c1 ...> -- Computes
bounds and number of triangles." );
+ return 1;
+ }
+
+
+ unsigned char default_color[3] = { 179, 179, 179 };
+
+ // Switch on the command.
+ switch (command) {
+ case CONVERT:
+
+ // Open the output file.
+ if ((out_file = fopen( output_file_name, "w" )) == 0) {
+ perror( "Could not open output file." );
+ return 1;
+ }
+
+ // Recursively search out new directories and data files.
+ for (int i=file_list_begin;i<file_list_end;++i) {
+ search_directory( argv[i], default_color );
+ }
+
+ // Close the output file.
+ fclose( out_file );
+
+ // Output the bounds.
+ std::cout << "Bounds: " << bounds[0] << " " << bounds[1] <<
std::endl;
+
+ break;
+ case INFO:
+ // Output info for each file.
+ for (int i=file_list_begin;i<file_list_end;++i) {
+ v3c1_info( argv[i] );
+ }
+
+ // Output the bounds.
+ std::cout << "All: faces: " << total_faces << " "<<
bounds[0] << " " << bounds[1] << std::endl;
+ break;
+ };
+}
+
+void search_directory( const char *directory_name, unsigned char
current_color[3] ) {
+
+ printf( "Entering directory %s\n", directory_name );
+
+ // Open the directory.
+ DIR *dir;
+ if ((dir = opendir( directory_name )) == 0) {
+ perror( "Could not open directory." );
+ return;
+ }
+
+ // Read each entry.
+ dirent *entry;
+ while ((entry = readdir( dir ))) {
+
+ // Examine the directory entry name.
+ string entry_name = entry->d_name;
+
+ if ((entry->d_type != DT_DIR) && (entry_name.find(".bin") >
0)) {
+
+ // printf( "\tFound data file: %s\n",
entry_name.c_str() );
+
+ // Concat the file name on the current directory.
+ char next_file[NAME_MAX+1];
+
+ // Append the entry name to the current directory.
+ sprintf( next_file, "%s/%s", directory_name,
entry->d_name );
+
+ // process the .bin file.
+ process_data_file( next_file, current_color );
+ }
+ else {
+ // Check to see if the name is a directory.
+ if ((entry->d_type == DT_DIR) &&
+ (entry_name != ".") &&
+ (entry_name != "..") &&
+ (entry_name != "bigsla")) {
+
+ unsigned char next_color[3];
+
+ // Check to see if the new entry matches a
color.
+ if (ColorDB::getNamedColor( next_color,
entry_name )) {
+ printf( "\nFound new color: %s\n",
entry->d_name );
+ current_color = next_color;
+ }
+
+ // Process the subdirectory.
+ char next_directory[NAME_MAX+1];
+
+ // Append the entry name to the current
directory.
+ sprintf( next_directory, "%s/%s",
directory_name, entry->d_name );
+
+ search_directory( next_directory,
current_color );
+ }
+ }
+ }
+
+ // Output total number of faces.
+ printf( "Total faces so far: %d\n", total_faces );
+
+ // Close the directory.
+ closedir( dir );
+}
+
+void process_data_file( const char *file_name, unsigned char
current_color[3] ) {
+
+ // Open the data file.
+ FILE *in_file = fopen( file_name, "r" );
+ if (!in_file) {
+ perror( "Could not open data file." );
+ return;
+ }
+
+ // Determine the file size.
+ fseek( in_file, 0, SEEK_END );
+ long file_size = ftell( in_file );
+ fseek( in_file, 0, SEEK_SET );
+
+ // Determine the total number of faces in this file.
+ long file_faces = file_size / (sizeof(nv3_face));
+
+ // printf( "\t\tDatafile: %s total faces: %d\n", file_name,
(int)file_faces );
+
+ // Resize buffers to hold the faces.
+ in_buffer.resize ( file_faces );
+ out_buffer.resize( file_faces );
+
+ // Read in the faces.
+ fread( &in_buffer[0], sizeof( nv3_face ), file_faces, in_file );
+ fclose( in_file );
+
+ // Copy the faces into the output buffer.
+ for (int i=0;i<file_faces;++i) {
+
+ out_buffer[i] = v3c1_face( in_buffer[i], current_color );
+
+ // Check to make sure none of the vertex coords are too large.
+ bool bad_triangle = false;
+ for (int j=0;j<3;++j) {
+ if (fabs(out_buffer[i].vertex0[j]) > 1000.0f) {
+ bad_triangle = true;
+ }
+ if (fabs(out_buffer[i].vertex1[j]) > 1000.0f) {
+ bad_triangle = true;
+ }
+ if (fabs(out_buffer[i].vertex2[j]) > 1000.0f) {
+ bad_triangle = true;
+ }
+ }
+
+ if (bad_triangle) {
+ printf( "Bad triangle: File: %s Face: %d Skipping
rest of file.\n", file_name, i );
+ file_faces = i;
+ break;
+ }
+
+ // Compute the bounds of the face.
+ bounds.extendByPoint( Point( out_buffer[i].vertex0[0],
out_buffer[i].vertex0[1], out_buffer[i].vertex0[2] ) );
+ bounds.extendByPoint( Point( out_buffer[i].vertex1[0],
out_buffer[i].vertex1[1], out_buffer[i].vertex1[2] ) );
+ bounds.extendByPoint( Point( out_buffer[i].vertex2[0],
out_buffer[i].vertex2[1], out_buffer[i].vertex2[2] ) );
+ }
+
+ // Write to the output file.
+ fwrite( &out_buffer[0], sizeof( v3c1_face ), file_faces, out_file );
+
+ total_faces += file_faces;
+}
+
+void v3c1_info( const char *file_name ) {
+
+ // Open the data file.
+ FILE *in_file = fopen( file_name, "r" );
+ if (!in_file) {
+ perror( "Could not open data file." );
+ return;
+ }
+
+ // Determine the file size.
+ fseek( in_file, 0, SEEK_END );
+ long file_size = ftell( in_file );
+ fseek( in_file, 0, SEEK_SET );
+
+ // Determine the total number of faces in this file.
+ long file_faces = file_size / (sizeof(v3c1_face));
+
+ // Output number of faces.
+ if ((file_size % sizeof(v3c1_face)) != 0) {
+ printf( "%s size %d is not a multiple of sizeof(v3c1_face)
(%d) ",
+ file_name, (int)file_size,
(int)sizeof(v3c1_face) );
+ }
+ else {
+ printf( "%s faces: %d ", file_name, (int)file_faces );
+ }
+
+ // Read in the data.
+ out_buffer.resize( file_faces );
+ fread( &out_buffer[0], sizeof(v3c1_face), file_faces, in_file );
+
+ // Compute the bounds of this file.
+ BBox file_bounds;
+
+ // Copy the faces into the output buffer.
+ for (int i=0;i<file_faces;++i) {
+
+ // Compute the bounds of the face.
+ file_bounds.extendByPoint( Point( out_buffer[i].vertex0[0],
out_buffer[i].vertex0[1], out_buffer[i].vertex0[2] ) );
+ file_bounds.extendByPoint( Point( out_buffer[i].vertex1[0],
out_buffer[i].vertex1[1], out_buffer[i].vertex1[2] ) );
+ file_bounds.extendByPoint( Point( out_buffer[i].vertex2[0],
out_buffer[i].vertex2[1], out_buffer[i].vertex2[2] ) );
+ }
+
+ // Output the bounds.
+ std::cout << " " << file_bounds[0][0] << " " << file_bounds[0][1] <<"
" << file_bounds[0][2]
+ << " " << file_bounds[1][0] << " " <<
file_bounds[1][1] <<" " << file_bounds[1][2]
+ << std::endl;
+
+ // Add this file's bounds to the bounds of all the files.
+ bounds.extendByBox( file_bounds );
+
+ total_faces += file_faces;
+};
+
+
- [MANTA] r433 - branches/itanium2/Readers/DoubleEagle, abe, 07/15/2005
Archive powered by MHonArc 2.6.16.