53 #define OBJ_AMBIGUOUS "AMBIGUOUS"
54 #define OBJ_UNDEFINED "UNDEFINED"
57 const char*
const geom_name[] = {
"Vertex\0",
"Curve\0",
"Surface\0",
"Volume\0" };
64 :
MBI( impl ), geom_tag( 0 ), id_tag( 0 ), name_tag( 0 ), category_tag( 0 ), faceting_tol_tag( 0 ),
65 geometry_resabs_tag( 0 ), obj_name_tag( 0 )
67 assert( NULL != impl );
114 std::vector< int >& ,
131 std::string object_name;
132 std::vector< EntityHandle > vertex_list;
133 int object_id = 0, group_id = 0;
147 std::cout <<
"Problems reading file = " << filename << std::endl;
161 if( line.length() == 0 )
continue;
164 std::vector< std::string > tokens;
169 if( tokens.size() < 2 )
continue;
176 object_name = tokens[1];
186 num_groups = tokens.size() - 1;
187 std::string group_name =
"Group";
188 for(
int i = 0; i < num_groups; i++ )
190 group_name = group_name +
'_' + tokens[i + 1];
205 vertex_list.push_back( new_vertex_eh );
209 "Failed to add vertex to global meshset." );
220 if( tokens.size() == 4 )
228 else if( tokens.size() == 5 )
240 std::cout <<
"Neither tri nor a quad: " << line << std::endl;
253 MB_SET_ERR( MB_FAILURE,
"Invalid/unrecognized line" );
260 if( object_id == 0 && group_id == 0 )
262 MB_SET_ERR( MB_FAILURE,
"This is not an obj file. " );
265 std::cout <<
"There were " << ignored <<
" ignored lines in this file." << std::endl;
275 void ReadOBJ::tokenize(
const std::string& str, std::vector< std::string >& tokens,
const char* delimiters2 )
279 std::string::size_type next_token_end, next_token_start = str.find_first_not_of( delimiters2, 0 );
281 while( std::string::npos != next_token_start )
283 next_token_end = str.find_first_of( delimiters2, next_token_start );
284 if( std::string::npos == next_token_end )
286 tokens.push_back( str.substr( next_token_start ) );
287 next_token_start = std::string::npos;
291 tokens.push_back( str.substr( next_token_start, next_token_end - next_token_start ) );
292 next_token_start = str.find_first_not_of( delimiters2, next_token_end );
299 std::map< std::string, keyword_type > keywords;
340 return keywords[
match( tokens[0], keywords )];
343 template <
typename T >
344 std::string
ReadOBJ::match(
const std::string& token, std::map< std::string, T >& tokenList )
350 for(
typename std::map< std::string, T >::iterator thisToken = tokenList.begin(); thisToken != tokenList.end();
354 if( token == ( *thisToken ).first )
377 "Failed to set mesh set name tag." );
380 "Failed to set mesh set ID tag." );
386 "Failed to set mesh set category tag." );
396 "Failed to add object mesh set as child of volume mesh set." );
403 "Failed to set mesh set name tag." );
413 "Failed to set mesh set category tag." );
416 "Failed to set surface sense." );
432 "Failed to set mesh set name tag." );
448 for(
int i = 1; i < 4; i++ )
449 next_vertex.
coord[i - 1] = atof( v_tokens[i].c_str() );
462 const std::vector< EntityHandle >& vertex_list,
467 for(
int i = 1; i < 4; i++ )
469 int vertex_id = atoi( f_tokens[i].c_str() );
473 std::size_t slash = f_tokens[i].find(
'/' );
474 if( slash != std::string::npos )
476 std::string
face = f_tokens[i].substr( 0, slash );
477 vertex_id = atoi(
face.c_str() );
480 next_face.
conn[i - 1] = vertex_list[vertex_id - 1];
490 std::vector< EntityHandle >& vertex_list,
493 std::vector< EntityHandle > quad_vert_eh;
496 for(
int i = 1; i < 5; i++ )
498 int vertex_id = atoi( f_tokens[i].c_str() );
499 std::size_t slash = f_tokens[i].find(
'/' );
500 if( slash != std::string::npos )
502 std::string
face = f_tokens[i].substr( 0, slash );
503 vertex_id = atoi(
face.c_str() );
506 quad_vert_eh.push_back( vertex_list[vertex_id - 1] );
522 connectivity[0] = quad_vert_eh[0];
523 connectivity[1] = quad_vert_eh[1];
524 connectivity[2] = quad_vert_eh[2];
526 face_eh.
insert( new_face );
528 connectivity[0] = quad_vert_eh[2];
529 connectivity[1] = quad_vert_eh[3];
530 connectivity[2] = quad_vert_eh[0];
532 face_eh.
insert( new_face );