Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r542 - branches/itanium2/Readers/DoubleEagle
- Date: Mon, 12 Sep 2005 18:53:20 -0600 (MDT)
Author: abe
Date: Mon Sep 12 18:53:19 2005
New Revision: 542
Modified:
branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
Log:
Added the ability to convert from Hughes Hoppe .m file format to .v3c1.
M vn2v3c1.cc
Modified: branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc
==============================================================================
--- branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc (original)
+++ branches/itanium2/Readers/DoubleEagle/vn2v3c1.cc Mon Sep 12 18:53:19
2005
@@ -31,6 +31,11 @@
// Obj file format.
void process_obj_file( const char *file_name );
+// Hughes Hoppe M file format.
+void process_m_file( const char *file_name );
+float default_color[3] = { 1.0f, 1.0f, 1.0f };
+
+
// v3c1 format.
void v3c1_info( const char *file_name );
void v3c1_clip( const char *file_name, const Point &plane_point, const
Vector &plane_normal );
@@ -83,7 +88,11 @@
vector<nv3_face> in_buffer;
vector<v3c1_face> out_buffer;
-enum CommandType { NONE, CONVERT_VN, CONVERT_OBJ, INFO, CUT };
+struct m_vertex {
+ float v[3];
+};
+
+enum CommandType { NONE, CONVERT_VN, CONVERT_OBJ, CONVERT_M, INFO, CUT };
int main( int argc, char **argv ) {
@@ -111,6 +120,14 @@
else if (arg == "-obj") {
command = CONVERT_OBJ;
}
+ else if (arg == "-m") {
+ command = CONVERT_M;
+ }
+ else if (arg == "-color") {
+ default_color[0] = atof(argv[++i]);
+ default_color[1] = atof(argv[++i]);
+ default_color[2] = atof(argv[++i]);
+ }
else if (arg == "-out") {
output_file_name = argv[++i];
}
@@ -148,7 +165,8 @@
// Check that both were found.
if ((command == NONE) || (file_list_begin == 0)) {
printf( "Usage: v2v3c1 -vn3 -in <tanker paths...> -out
<outfile.v3c1>\n"
- " v2v3c1 -obj -in
<file1.obj ...> [-out <outfile.v3c1>]\n -- Outfile optional uses group names
otherwise.\n"
+ " v2v3c1 -obj -in
<file1.obj ...> [-out <outfile.v3c1>]\n -- Outfile optional uses group names
otherwise.\n"
+ " v2v3c1 -m -in <file1.m ...> -color <r> <g> <b> [-out
<outfile.v3c1>]\n -- Hughes Hoppe .m file format conversion.\n"
" v2v3c1 -info <infile.v3c1 ...> -- Computes
bounds and number of triangles.\n"
" v2v3c1 -clip <px>
<py> <pz> <nx> <ny> <nz> -- Apply a clipping plane to the input files. \n");
return 1;
@@ -199,9 +217,31 @@
// Output the bounds.
std::cout << "Bounds: " << bounds[0] << " " << bounds[1] <<
std::endl;
-
break;
- case INFO:
+ case CONVERT_M:
+
+ // Check to see if more then one output file should be used.
+ if (output_file_name) {
+ // Open the output file.
+ if ((out_file = fopen( output_file_name, "w" )) == 0)
{
+ perror( "Could not open output file." );
+ return 1;
+ }
+ }
+
+ for (int i=file_list_begin;i<file_list_end;++i) {
+ process_m_file( argv[i] );
+ }
+
+ // Close the output file.
+ if (out_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] );
@@ -434,6 +474,95 @@
group = group->next;
}
}
+
+void process_m_file( const char *file_name ) {
+
+ int group_num = 0;
+ v3c1_face out_face;
+
+ // Open the data file.
+ FILE *in_file = fopen( file_name, "r" );
+ if (!in_file) {
+ perror( "Could not open data file." );
+ return;
+ }
+
+
/////////////////////////////////////////////////////////////////////////////
+ // First pass.
+ char line[128];
+ int total_vertices = 0;
+
+ while (fscanf(in_file,"%s",line) != EOF) {
+
+ // Check if this line is a face or a vertex.
+ if (strstr(line,"Vertex")) {
+ ++total_vertices;
+ }
+
+ // Skip the rest of the line.
+ fgets(line, sizeof(line), in_file);
+ }
+
+ fseek( in_file, 0, SEEK_SET );
+
+
/////////////////////////////////////////////////////////////////////////////
+ // Second pass.
+ m_vertex *vertex_list = new m_vertex[total_vertices];
+ int index;
+
+ while (fscanf(in_file,"%s",line) != EOF) {
+
+ // Check if this line is a face or a vertex.
+ if (strstr(line,"Vertex")) {
+
+ float v[3];
+
+ // Read in what follows "Vertex"
+ fgets(line, sizeof(line), in_file);
+
+ sscanf(line, "%d %f %f %f",
+ &index, &v[0], &v[1], &v[2] );
+
+ // Copy the coordinates to the vertex list.
+ vertex_list[index-1].v[0] = v[0];
+ vertex_list[index-1].v[1] = v[1];
+ vertex_list[index-1].v[2] = v[2];
+
+ bounds.extendByPoint( Point( v[0], v[1], v[2] ) );
+ }
+ else if (strstr(line,"Face")) {
+
+ int face[3];
+
+
+ // Read in the vertex indices.
+ fgets(line, sizeof(line), in_file);
+
+ sscanf(line, "%d %d %d %d",
+ &index, &face[0], &face[1], &face[2] );
+
+ for (int f=0;f<3;++f) {
+ for (int i=0;i<3;++i) {
+ out_face.vertex(f)[i] = vertex_list[face[f]-1].v[i];
+ }
+ }
+
+ for (int i=0;i<3;++i) {
+ out_face.color[i] = default_color[i];
+ }
+
+ // Output the face.
+ fwrite( &out_face, sizeof( v3c1_face ), 1, out_file );
+
+ total_faces++;
+ }
+ }
+
+ printf( "Faces: %d\n", total_faces );
+
+ fclose( in_file );
+}
+
void v3c1_info( const char *file_name ) {
- [MANTA] r542 - branches/itanium2/Readers/DoubleEagle, abe, 09/12/2005
Archive powered by MHonArc 2.6.16.