76 const Tag* file_id_tag )
85 std::vector< ReadSTL::Triangle > triangles;
87 bool is_ascii =
false, is_binary =
false;
90 if( is_ascii && is_binary )
92 MB_SET_ERR( MB_FAILURE,
"Conflicting options: BINARY ASCII" );
100 MB_SET_ERR( MB_FAILURE,
"Conflicting options: BIG_ENDIAN LITTLE_ENDIAN" );
120 std::map< Point, EntityHandle > vertex_map;
121 for( std::vector< Triangle >::iterator i = triangles.begin(); i != triangles.end(); ++i )
123 vertex_map[i->points[0]] = 0;
124 vertex_map[i->points[1]] = 0;
125 vertex_map[i->points[2]] = 0;
129 std::vector< double* > coord_arrays;
136 double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2];
137 for( std::map< Point, EntityHandle >::iterator i = vertex_map.begin(); i != vertex_map.end(); ++i )
139 i->second = vtx_handle;
141 *x = i->first.coords[0];
143 *y = i->first.coords[1];
145 *z = i->first.coords[2];
158 for( std::vector< Triangle >::iterator i = triangles.begin(); i != triangles.end(); ++i )
160 *connectivity = vertex_map[i->points[0]];
162 *connectivity = vertex_map[i->points[1]];
164 *connectivity = vertex_map[i->points[2]];
174 Range vertices( vtx_handle, vtx_handle + vertex_map.size() - 1 );
175 Range elements( elm_handle, elm_handle + triangles.size() - 1 );
186 FILE* file = fopen( name,
"r" );
193 if( !fgets( header,
sizeof( header ), file ) ||
194 strlen( header ) < 6 ||
195 header[strlen( header ) - 1] !=
'\n' ||
196 memcmp( header,
"solid", 5 ) ||
197 !isspace( header[5] ) )
214 const char*
const expected[] = {
"facet",
"endsolid", 0 };
232 for(
int i = 0; i < 3; i++ )
242 tris.push_back( tri );
267 std::vector< ReadSTL::Triangle >& tris )
269 FILE* file = fopen( name,
"rb" );
277 if( fread( &header, 84, 1, file ) != 1 )
286 bool swap_bytes = ( want_big_endian == am_big_endian );
302 unsigned long num_tri = header.
count;
309 if( ULONG_MAX / 50 - 84 < num_tri ||
310 84 + 50 * num_tri != (
unsigned long)
filesize )
314 uint32_t num_tri_tmp = header.
count;
316 unsigned long num_tri_swap = num_tri_tmp;
318 ULONG_MAX / 50 - 84 < num_tri_swap ||
319 84 + 50 * num_tri_swap != (
unsigned long)
filesize )
325 num_tri = num_tri_swap;
330 tris.resize( num_tri );
334 for( std::vector< Triangle >::iterator i = tris.begin(); i != tris.end(); ++i )
336 if( fread( &tri, 50, 1, file ) != 1 )
344 for(
unsigned j = 0; j < 9; ++j )
345 i->points[j / 3].coords[j % 3] = tri.
coords[j];