31 #include <sys/types.h>
41 #if defined( _MSC_VER ) || defined( __MINGW32__ )
44 typedef unsigned __int32 uint32_t;
48 #define _S_IREAD ( S_IRUSR | S_IRGRP | S_IROTH )
49 #define _S_IWRITE ( S_IWUSR | S_IWGRP | S_IWOTH )
74 const std::vector< std::string >& qa_list,
83 if( tag_list && num_tags )
94 if( triangles.
empty() )
99 bool is_ascii =
false, is_binary =
false;
102 if( is_ascii && is_binary )
104 MB_SET_ERR( MB_FAILURE,
"Conflicting options: BINARY ASCII" );
112 MB_SET_ERR( MB_FAILURE,
"Conflicting options: BIG_ENDIAN LITTLE_ENDIAN" );
116 FILE* file =
open_file( file_name, overwrite, is_binary );
137 int flags = O_WRONLY | O_CREAT;
149 if( binary ) flags |= O_BINARY;
161 int fd = open( name, flags, creat_mode );
166 FILE* result = fdopen( fd, binary ?
"wb" :
"w" );
167 if( !result ) close( fd );
174 memset( header, 0, 81 );
177 for( std::vector< std::string >::const_iterator i = qa_list.begin(); i != qa_list.end(); ++i )
183 size_t len = result.size();
184 if( len > 80 ) len = 80;
185 memcpy( header, result.c_str(), len );
196 for( ; iter != end; ++iter )
201 triangles.
merge( r );
227 n = ( v2 - v1 ) * ( v3 - v1 );
236 const char solid_name[] =
"MOAB";
238 char myheader[81] =
"solid ";
239 strcat( myheader, solid_name );
240 strncat( myheader, header, 80 );
242 if( EOF == fputs( myheader, file ) || EOF == fputs(
"\n", file ) )
return MB_FILE_WRITE_ERROR;
254 if( num_vtx != 3 )
return MB_FAILURE;
262 fprintf( file,
"facet normal %e %e %e\n", n[0], n[1], n[2] );
263 fprintf( file,
"outer loop\n" );
264 fprintf( file,
"vertex %.*e %.*e %.*e\n", prec, (
float)v1[0], prec, (
float)v1[1], prec, (
float)v1[2] );
265 fprintf( file,
"vertex %.*e %.*e %.*e\n", prec, (
float)v2[0], prec, (
float)v2[1], prec, (
float)v2[2] );
266 fprintf( file,
"vertex %.*e %.*e %.*e\n", prec, (
float)v3[0], prec, (
float)v3[1], prec, (
float)v3[2] );
267 fprintf( file,
"endloop\n" );
268 fprintf( file,
"endfacet\n" );
271 fprintf( file,
"endsolid %s\n", solid_name );
285 const char header[81],
287 const Range& triangles )
295 const bool swap_bytes = ( want_big_endian == am_big_endian );
297 if( triangles.
size() > INT_MAX )
300 uint32_t count = (uint32_t)triangles.
size();
306 tri.
pad[0] = tri.
pad[1] =
'\0';
314 if( num_vtx != 3 )
return MB_FAILURE;