Tube.h

00001 #ifndef __TUBE_H__
00002 #define __TUBE_H__
00003 
00004 #include <fstream>
00005 #include <assert.h>
00006 #include "../include/Curve.h"
00007 
00008 #ifdef RENDERMAN
00009 #warning libbiarc compiled with Pixie support!
00010 #include "ri.h"
00011 #endif
00012 
00013 template<class Vector>
00014 class Tube : public Curve
00015 // Doxygen doesn't like templates in heritage :(
00016 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00017 <Vector>
00018 #endif
00019 {
00020 
00021   // number of circle segments
00022   int _Segments;
00023 
00024   // tube radius
00025   float _Radius;
00026 
00027   // tube mesh \_Segments+1 columns and \_NoNodes+1 lines
00028   Vector *_MeshPoints;
00029 
00030   // Normals for Gouraud Shading
00031   Vector *_MeshNormals;
00032 
00033   // Extensions of the knot curve
00034   // Bottom left corner
00035   Vector _BBox_Min;
00036   // Upper right corner
00037   Vector _BBox_Max;
00038   // Center of mass
00039   Vector _Center;
00040 
00041   // this routine is called f.ex by makeMesh or scaleTubeRadius
00042   // to update the current bounging box and center value
00043   void computeBoundingBox();
00044 
00045  public:
00046 
00047   Tube();
00048   Tube(istream &in);
00049   Tube(const Curve<Vector> &curve);
00050   Tube(const Tube<Vector> &tube);
00051   Tube &operator= (const Tube<Vector> &t);
00052   ~Tube();
00053 
00054   void init();
00055   void clear_tube();
00056 
00057   Vector & meshPoint(int i);
00058   Vector & meshNormal(int i);
00059 
00060   int segments();
00061   float radius();
00062   void makeMesh(int N, int S, float R, float Tol = -1.0);
00063 
00064   void getBoundingBox(Vector & BBox_BL, Vector & BBox_UR);
00065   Vector & getCenter();
00066   void scaleTubeRadius(float NewRadius);
00067 
00068 #ifdef RENDERMAN
00069   RtInt NU; //  = knot->nodes()+1;
00070   RtInt NV; // = knot->segments()+1;
00071   RtPoint* MeshPoints; //[NV][NU];
00072   RtPoint* MeshNormals; //[NV][NU];
00073 
00074  public:
00075   void renderman_init();
00076   void renderman_draw();
00077   void exportRIBFile(char* filename, int W, int H,
00078                      const Vector &p, const Vector &a, float angle,
00079                      const Vector &light_dir);
00080 #endif
00081 
00082   /*
00083     TODO :
00084 
00085     scaleMesh, compute surface area and volume of the tube
00086     depending on coarsness of the mesh
00087   */
00088 
00089   // friend ostream &operator<<(ostream &out, Tube<Vector> &t);
00090 
00091 };
00092 
00093 template<class Vector>
00094 inline ostream &operator<<(ostream &out, Tube<Vector> &t) {
00095 
00096   /* FIXME : The templated class friend function doesn't work!!!!
00097   if (t._MeshPoints==NULL) {
00098     out << "-- Tube : Empty mesh --";
00099     return out;
00100   }
00101   */
00102   
00103   /* first and last circle point as well as
00104    * first and last point on curve are repeated !!
00105    * to keep connectivity of the mesh
00106    */
00107   if (t.isClosed())
00108     for (int i=0;i<=t.nodes();i++)
00109       for (int j=0;j<=t.segments();j++)
00110         out << t.meshPoint(i*(t.segments()+1)+j) << '\n';
00111   else
00112     for (int i=0;i<t.nodes();i++)
00113       for (int j=0;j<=t.segments();j++)
00114         out << t.meshPoint(i*(t.segments()+1)+j) << '\n';
00115 
00116   return out;
00117 }
00118 
00119 // Template thing
00120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00121 #include "../lib/Tube.cpp"
00122 #endif
00123 
00124 #endif // __TUBE_H__

Generated on Mon Feb 8 17:22:35 2010 for libbiarc by  doxygen 1.5.6