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
00016 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00017 <Vector>
00018 #endif
00019 {
00020
00021
00022 int _Segments;
00023
00024
00025 float _Radius;
00026
00027
00028 Vector *_MeshPoints;
00029
00030
00031 Vector *_MeshNormals;
00032
00033
00034
00035 Vector _BBox_Min;
00036
00037 Vector _BBox_Max;
00038
00039 Vector _Center;
00040
00041
00042
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;
00070 RtInt NV;
00071 RtPoint* MeshPoints;
00072 RtPoint* MeshNormals;
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
00084
00085
00086
00087
00088
00089
00090
00091 };
00092
00093 template<class Vector>
00094 inline ostream &operator<<(ostream &out, Tube<Vector> &t) {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
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
00120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00121 #include "../lib/Tube.cpp"
00122 #endif
00123
00124 #endif // __TUBE_H__