contrib/oxl/vrml/vrml_out.h
Go to the documentation of this file.
00001 // This is oxl/vrml/vrml_out.h
00002 #ifndef vrml_io_h_
00003 #define vrml_io_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author awf@robots.ox.ac.uk
00010 // \date   19 Mar 00
00011 
00012 #include <vcl_iosfwd.h>
00013 #include <vcl_vector.h>
00014 
00015 class vrml_out_vertex_to_texture;
00016 
00017 //: A class to write to a VRML 1.0 file.
00018 class vrml_out
00019 {
00020  public:
00021   // Constructors/Destructors--------------------------------------------------
00022 
00023   vrml_out();
00024   vrml_out(vcl_ostream& s);
00025   vrml_out(char const* filename);
00026   ~vrml_out();
00027 
00028   // Operations----------------------------------------------------------------
00029   void open(vcl_ostream& s);
00030   void close();
00031 
00032   void prologue();
00033   void write_points(vcl_vector<double> const& x, vcl_vector<double> const& y, vcl_vector<double> const& z);
00034   void display_pointset();
00035 #if 0 // NYI - TODO
00036   void write_vertices(vcl_vector<vgl_point_3d<double> > const&);
00037   void write_points(vcl_vector<vgl_point_3d<double> > const& l) { return write_vertices(l); }
00038   void write_edges(vcl_vector<vgl_line_segment_3d<double> > const&);
00039   void write_faces(vcl_list<vgl_polygon<float> > const& triangles);
00040   void write_faces_textured(vcl_list<v<float> gl_polygon> const& triangles, char const* imagefilename, int xsize, int ysize);
00041   void write_faces_textured(vcl_list<v<float> gl_polygon> const& triangles, char const* imagefilename, int xsize, int ysize,
00042                             vnl_matrix<double> const& Pmatrix);
00043   void write_faces_textured(vcl_list<v<float> gl_polygon> const& triangles, char const* imagefilename, int xsize, int ysize,
00044                             vcl_vector<vcl_pair<vgl_point_3d<double>, vgl_point_3d<double> > >&);
00045   void write_faces_textured(vcl_list<v<float> gl_polygon> const& triangles, char const* imagefilename,
00046                             vrml_out_vertex_to_texture const& textures);
00047   void write_block(Block* topology);
00048   void write_topology(TopologyObject* topology);
00049   void write_topology(vcl_list<TopologyObject*>& topology);
00050 #endif
00051   void comment(char const* msg);
00052   void verbatim(char const* msg);
00053   void epilogue();
00054 
00055   // Helpers-------------------------------------------------------------------
00056   void begin_separator();
00057   void end_separator();
00058 
00059   void begin_pointset();
00060   void point3d(double, double, double);
00061   void point3d(double, double, double, char const*);
00062 #if 0 // NYI - TODO
00063   void point3d(vgl_point_3d<double> const& p) { point3d(p.x(), p.y(), p.z()); }
00064   void point3d(vnl_vector_fixed<double,3> const& p) { point3d(p[0], p[1], p[2]); }
00065 #endif // 0
00066   void end_pointset();
00067 
00068   void begin_texture(char const* texture_filename);
00069   void texture2(double, double);
00070   void texture2_image_coords(double, double, int image_xsize, int image_ysize);
00071   void end_texture();
00072 
00073   void begin_lineset();
00074   void line(int i0, int i1);
00075   void end_lineset();
00076 
00077   void begin_faceset();
00078   void triangle(int, int, int);
00079   void quad(int, int, int, int);
00080   void face(const int* base, int n);
00081   void face_open();
00082   void face_index(int);
00083   void face_close();
00084   void end_faceset();
00085 
00086  protected:
00087   // Data Members--------------------------------------------------------------
00088   vcl_ostream* s_;
00089   bool own_ostream_;
00090 
00091  private:
00092   // private as don't want 2 people on same vcl_ostream
00093   vrml_out(const vrml_out& that);
00094   vrml_out& operator=(const vrml_out& that);
00095 };
00096 
00097 class vrml_out_vertex_to_texture
00098 {
00099  public:
00100   // Store image size for conversion from image to texture coordinates.
00101   int image_xsize;
00102   int image_ysize;
00103 
00104  public:
00105   vrml_out_vertex_to_texture(int xsize, int ysize): image_xsize(xsize), image_ysize(ysize) {}
00106   virtual ~vrml_out_vertex_to_texture() {}
00107 
00108   virtual void get_texture_coords(const void* vertex, double* u, double* v) const = 0;
00109 };
00110 
00111 #endif // vrml_io_h_