00001 #include "ObjFile_inserter.h"
00002 #include <ostream>
00003
00004 namespace MNI {
00005
00006
00007
00012 Object_file::Object_file( char* filename )
00013 {
00014 File_formats format;
00015
00016 if ( input_graphics_file( filename, &format,
00017 &objects_size, &objects_list ) != OK )
00018 {
00019 std::cerr << "MNI::Object_file::Object_file: "
00020 << "input_graphics_file(" << filename << ") failed."
00021 << std::endl;
00022 objects_size = -1;
00023 return;
00024 }
00025 }
00026
00027
00028 Object_file::~Object_file()
00029 {
00030 delete_object_list( objects_size, objects_list );
00031 }
00032
00033
00034 bool Object_file::is_valid() const
00035 {
00036 return objects_size > 0;
00037 }
00038
00039
00040
00041 int Object_file::size_of_objects() const
00042 {
00043 return objects_size;
00044 }
00045
00046
00049 object_struct* Object_file::object( int index ) const
00050 {
00051 CGAL_assertion( index >= 0 );
00052 CGAL_assertion( index < objects_size );
00053
00054 return objects_list[index];
00055 }
00056
00057
00060 bool Object_file::is_polygons( int index ) const
00061 {
00062 CGAL_assertion( index >= 0 );
00063 CGAL_assertion( index < objects_size );
00064
00065 return get_object_type( objects_list[index] ) == POLYGONS;
00066 }
00067
00068
00071 bool Object_file::is_quadmesh( int index ) const
00072 {
00073 CGAL_assertion( index >= 0 );
00074 CGAL_assertion( index < objects_size );
00075
00076 return get_object_type( objects_list[index] ) == QUADMESH;
00077 }
00078
00079
00086 void Object_file::insert( int index, bool split_quad, Polyhedron& poly )
00087 {
00088 object_struct* obj_ptr = object(index);
00089 CGAL::Modifier_base<HDS>* modifier;
00090
00091 if ( is_polygons(index) ) {
00092 modifier = new MNI::ObjFile_inserter::Polygons
00093 ( *(get_polygons_ptr(obj_ptr)) );
00094 } else if ( is_quadmesh(index) ) {
00095 modifier = new MNI::ObjFile_inserter::Quadmesh
00096 ( *(get_quadmesh_ptr(obj_ptr)), split_quad );
00097 } else {
00098 CGAL_assertion_msg( false, "Unable to handle object type" );
00099 return;
00100 }
00101
00102 poly.delegate( *modifier );
00103 delete modifier;
00104 }
00105
00106
00107 }