Go to the documentation of this file.00001
00002 #ifndef imesh_mesh_h_
00003 #define imesh_mesh_h_
00004
00005
00006
00007
00008
00009
00010 #include <vcl_vector.h>
00011 #include <vcl_memory.h>
00012 #include <vcl_cassert.h>
00013
00014 #include <imesh/imesh_vertex.h>
00015 #include <imesh/imesh_face.h>
00016 #include <imesh/imesh_half_edge.h>
00017
00018 #include <vgl/vgl_point_2d.h>
00019
00020
00021 #include <vbl/vbl_ref_count.h>
00022 #include <vbl/vbl_smart_ptr.h>
00023 #include <vsl/vsl_binary_io.h>
00024
00025
00026 class imesh_mesh : public vbl_ref_count
00027 {
00028 public:
00029
00030 imesh_mesh() : tex_coord_status_(TEX_COORD_NONE) {}
00031
00032
00033
00034 imesh_mesh(vcl_auto_ptr<imesh_vertex_array_base> verts, vcl_auto_ptr<imesh_face_array_base> faces)
00035 : verts_(verts), faces_(faces), tex_coord_status_(TEX_COORD_NONE) {}
00036
00037
00038 imesh_mesh(const imesh_mesh& other);
00039
00040
00041 imesh_mesh& operator=(imesh_mesh const& other);
00042
00043
00044 unsigned int num_verts() const {return verts_->size();}
00045
00046
00047 unsigned int num_faces() const {return faces_->size();}
00048
00049
00050 unsigned int num_edges() const {return half_edges_.size()/2;}
00051
00052
00053
00054 void merge(const imesh_mesh& other);
00055
00056
00057 bool is_init() const { return verts_.get() && faces_.get(); }
00058
00059
00060 const imesh_vertex_array_base& vertices() const { return *verts_; }
00061 imesh_vertex_array_base& vertices() { return *verts_; }
00062
00063
00064 template <unsigned int d>
00065 const imesh_vertex_array<d>& vertices() const
00066 {
00067 assert(dynamic_cast<imesh_vertex_array<d>*>(verts_.get()));
00068 return static_cast<const imesh_vertex_array<d>&>(*verts_);
00069 }
00070 template <unsigned int d>
00071 imesh_vertex_array<d>& vertices()
00072 {
00073 assert(dynamic_cast<imesh_vertex_array<d>*>(verts_.get()));
00074 return static_cast<imesh_vertex_array<d>&>(*verts_);
00075 }
00076
00077
00078 const imesh_face_array_base& faces() const { return *faces_; }
00079 imesh_face_array_base& faces() { return *faces_; }
00080
00081
00082 void set_vertices(vcl_auto_ptr<imesh_vertex_array_base> verts) { verts_ = verts; }
00083
00084
00085 void set_faces(vcl_auto_ptr<imesh_face_array_base> faces) { faces_ = faces; }
00086
00087
00088 bool has_half_edges() const { return half_edges_.size() > 0; }
00089
00090
00091 const imesh_half_edge_set& half_edges() const { return half_edges_; }
00092
00093
00094 void build_edge_graph();
00095
00096
00097 void remove_edge_graph() { half_edges_.clear(); }
00098
00099
00100 void compute_vertex_normals();
00101
00102
00103 void compute_vertex_normals_from_faces();
00104
00105
00106
00107 void compute_face_normals(bool norm = true);
00108
00109
00110
00111
00112 enum tex_coord_type { TEX_COORD_NONE = 0,
00113 TEX_COORD_ON_VERT = 1,
00114 TEX_COORD_ON_CORNER = 2 };
00115
00116
00117 tex_coord_type has_tex_coords() const { return tex_coord_status_; }
00118
00119
00120 const vcl_vector<vgl_point_2d<double> >& tex_coords() const { return tex_coords_; }
00121
00122
00123 void set_tex_coords(const vcl_vector<vgl_point_2d<double> >& tc);
00124
00125
00126 void set_tex_source(const vcl_string ts) { tex_source_ = ts; }
00127 const vcl_string& tex_source() const { return tex_source_; }
00128
00129
00130 const vcl_vector<bool>& valid_tex_faces() const { return valid_tex_faces_; }
00131
00132
00133 void set_valid_tex_faces(const vcl_vector<bool>& valid);
00134
00135
00136
00137 void label_ccw_tex_faces_valid();
00138
00139
00140 vgl_point_2d<double> texture_map(unsigned int tri,
00141 double u, double v) const;
00142
00143
00144 private:
00145 vcl_auto_ptr<imesh_vertex_array_base> verts_;
00146 vcl_auto_ptr<imesh_face_array_base> faces_;
00147 imesh_half_edge_set half_edges_;
00148
00149
00150 vcl_vector<vgl_point_2d<double> > tex_coords_;
00151
00152
00153 vcl_string tex_source_;
00154
00155
00156 vcl_vector<bool> valid_tex_faces_;
00157
00158 tex_coord_type tex_coord_status_;
00159 };
00160
00161
00162 typedef vbl_smart_ptr<imesh_mesh> imesh_mesh_sptr;
00163
00164
00165
00166 void vsl_b_write(vsl_b_ostream& os, imesh_mesh_sptr& sptr);
00167 void vsl_b_write(vsl_b_ostream& os, imesh_mesh_sptr const& sptr);
00168
00169
00170 void vsl_b_read(vsl_b_istream& is, imesh_mesh_sptr& sptr);
00171 void vsl_b_read(vsl_b_istream& is, imesh_mesh_sptr const& sptr);
00172
00173 #endif // imesh_mesh_h_