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 );
108 std::vector< int >& ,
126 std::string object_name;
127 std::vector< EntityHandle > vertex_list;
128 int object_id = 0, group_id = 0;
142 std::cout <<
"Problems reading file = " << filename << std::endl;
156 if( line.length() == 0 )
continue;
159 std::vector< std::string > tokens;
164 if( tokens.size() < 2 )
continue;
171 object_name = tokens[1];
181 num_groups = tokens.size() - 1;
182 std::string group_name =
"Group";
183 for(
int i = 0; i < num_groups; i++ )
185 group_name = group_name +
'_' + tokens[i + 1];
200 vertex_list.push_back( new_vertex_eh );
214 if( tokens.size() == 4 )
225 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 )
445 for(
int i = 1; i < 4; i++ )
446 next_vertex.
coord[i - 1] = atof( v_tokens[i].c_str() );
459 const std::vector< EntityHandle >& vertex_list,
465 for(
int i = 1; i < 4; i++ )
467 int vertex_id = atoi( f_tokens[i].c_str() );
471 std::size_t slash = f_tokens[i].find(
'/' );
472 if( slash != std::string::npos )
474 std::string
face = f_tokens[i].substr( 0, slash );
475 vertex_id = atoi(
face.c_str() );
478 next_face.
conn[i - 1] = vertex_list[vertex_id - 1];
488 std::vector< EntityHandle >& vertex_list,
492 std::vector< EntityHandle > quad_vert_eh;
495 for(
int i = 1; i < 5; i++ )
497 int vertex_id = atoi( f_tokens[i].c_str() );
498 std::size_t slash = f_tokens[i].find(
'/' );
499 if( slash != std::string::npos )
501 std::string
face = f_tokens[i].substr( 0, slash );
502 vertex_id = atoi(
face.c_str() );
505 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 );