00001 //------------------------------------------------------------------------ 00002 // 00003 // Joe Kniss 00004 // 9-17-02 00005 // ________ ____ ___ 00006 // | \ / | / / 00007 // +---+ \/ |/ / 00008 // +--+| |\ /| < 00009 // | || | \ / | |\ \ 00010 // | | \/ | | \ \ 00011 // \_____| |__| \__\ 00012 // Copyright 2002 00013 // Joe Michael Kniss 00014 // <<< jmk@cs.utah.edu >>> 00015 // "All Your Base are Belong to Us" 00016 //------------------------------------------------------------------------- 00017 00018 //volrenbase.h 00019 00020 /// the base interface for rendering volume data. Also implements 00021 /// a simple slice based volume renderer 00022 00023 00024 #ifndef __VOLREN_BASE_DOT_H 00025 #define __VOLREN_BASE_DOT_H 00026 00027 #include <renderable/Renderable.h> 00028 #include <simBase/simBase.h> 00029 #include <mathGutz.h> 00030 #include <volume/Volume.h> 00031 #include <volume/VolSamples.h> 00032 #include <graphicsGutz.h> 00033 #include <volrenalg/VolRenAlgBase.h> 00034 #include <volren/VolSlicer.h> 00035 00036 ///Forward Decl 00037 //class VolRenAlgBase; 00038 00039 class VolRenBase : 00040 public Renderable, 00041 public SimBase 00042 { 00043 public: 00044 VolRenBase(); 00045 virtual ~VolRenBase(); 00046 00047 ///////////////////////////////////////////////////////////// 00048 /// Init, to be called after Graphic context is valid 00049 virtual void init(); 00050 00051 ///////////////////////////////////////////////////////////// 00052 /// Slice polytopes and render 00053 void draw(const gutz::RenderEvent &re) 00054 { if(re.picking()) return; drawDef(re);} 00055 00056 ///////////////////////////////////////////////////////////// 00057 /// Get the center of the volume rendered, given a 00058 /// specific camera. 00059 gutz::vec3f getCenter(const gutz::CameraEvent &ce) const; 00060 00061 ///////////////////////////////////////////////////////////// 00062 /// Update sliced volume 00063 /// virtual void update(renderstate &rs){} 00064 00065 ///////////////////////////////////////////////////////////// 00066 ///@name Algorithm 00067 /// Set/Get the rendering algorithm, client strategy 00068 ///@{ 00069 virtual void setAlg(VolRenAlgBase *vrab); 00070 virtual VolRenAlgBaseSP getAlg() { return _currentAlg; } 00071 ///@} 00072 00073 //////////////////////////////////////////////////////////// 00074 ///@name Slicer 00075 /// Set/Get the currrent Slicer, client strategy 00076 ///@{ 00077 virtual void setSlicer(VolSlicer *vslice); 00078 virtual VolSlicerSP getSlicer() { return _currentSlicer; } 00079 ///@} 00080 ////////////////////////////////////////////////////////////// 00081 00082 ///////////////////////////////////////////////////////////// 00083 ///@name Set/Get sample spacing. 00084 /// This is in volume model space, 00085 /// which is not the same as texture space. 00086 ///@{ 00087 virtual void setSampleSpace(float sampleSpace) 00088 { _currentSlicer->setSampleSpace(sampleSpace); } 00089 virtual float getSampleSpace() 00090 { return _currentSlicer->getSampleSpace();} 00091 ///@} 00092 ////////////////////////////////////////////////////////////// 00093 00094 ////////////////////////////////////////////////////////////// 00095 ///@name Serialize/un... 00096 ///@{ 00097 00098 /// serialize 00099 virtual std::ostream &saveSelf(std::ostream &os) { return os;} 00100 /// unserialize 00101 virtual std::istream &readSelf(std::istream &is) { return is;} 00102 00103 ///@} 00104 ////////////////////////////////////////////////////////////// 00105 00106 ////////////////////////////////////////////////////////////// 00107 /// Light management, TODO: need a light class, yo 00108 ///////////////////////////////////////////////////////////// 00109 void addLight(gutz::Light *lt) {_ltv.push_back(lt);} 00110 gutz::Light *getLight(int i) {return _ltv[i];} 00111 gutz::LightVec getLightVec() {return _ltv;} 00112 void setLightVec(gutz::LightVec <v){_ltv = ltv;} 00113 unsigned int getNumLights() {return _ltv.size();} 00114 /// Lighting on/off 00115 void enableLight(bool on) {_lightOn = on;} 00116 /// Light transport using half angle on/off 00117 void enableLTHA(bool on) {_lthaOn = on;} 00118 00119 VolumeSP getVolume() const {return _v;} 00120 void setVolume(Volume *v) { _v = v;} 00121 00122 protected: 00123 00124 virtual void drawDef(const gutz::RenderEvent &re); 00125 00126 ///////////////////////////////////////////////////////////// 00127 /// Slicing related functions 00128 ///////////////////////////////////////////////////////////// 00129 00130 ///////////////////////////////////////////////////////////// 00131 /// get the slice axis 00132 virtual gutz::vec3f 00133 genSliceAxis(unsigned int light, gutz::vec3f volCtr){return gutz::vec3f_z;} 00134 00135 /////////////////////////////////////////////////////////////// 00136 /// a couple of no-ops for sub-classes 00137 virtual void preSlice(const gutz::RenderEvent &re) {} 00138 00139 virtual void postSlice(const gutz::RenderEvent &re) {} 00140 00141 ///////////////////////////////////////////////////////////// 00142 /// Rotate sample buffers, tripple buffered 00143 virtual void rotateSampBuffs() { _vsBuff = _vsBuff == 0 ? 1 : (_vsBuff == 1 ? 2 : 0); } 00144 00145 ///////////////////////////////////////////////////////////// 00146 /// Stratagies 00147 ///////////////////////////////////////////////////////////// 00148 VolRenAlgBaseSP _currentAlg; //defaults to new VolRenAlgBase() 00149 VolSlicerSP _currentSlicer; //defaults to new VolSlicer() 00150 00151 ///////////////////////////////////////////////////////////// 00152 /// Member data 00153 ///////////////////////////////////////////////////////////// 00154 00155 VolumeSP _v; //Current volume being rendered 00156 00157 VolytopeSP _vt; //Current volytope being rendered 00158 00159 VolSamplesVec _vsv; //VolSamples Vector 00160 int _vsBuff; /// which sample buffer are we about to render from? 00161 00162 gutz::LightVec _ltv; //Light Vector 00163 00164 gutz::vec3f _sliceDir; //Current slice direction, should be normalized. 00165 00166 bool _lightOn, _lthaOn; //Is lighting on?? 00167 00168 void err(char *when, float v = 0.0f, char *where=0); 00169 00170 private: 00171 00172 }; 00173 00174 typedef gutz::SmartPtr<VolRenBase> VolRenBaseSP; 00175 00176 00177 //========== NOTES =========================================== 00178 // Standard brick vertex ordering: 00179 // 00180 // (011) (111) 00181 // 6 +---------+ 7 Where 1's are the size of the brick 00182 // /| /| allong that axis 00183 // / | / | 00184 // (001)/ |(101) / | 00185 // 4 +---------+ 5 | 00186 // | | | |(110) z axis 00187 // | 2 +-----+---+ 3 ^ 00188 // | /(010) | / | y axis 00189 // | / | / | / 00190 // |/ |/ |/ 00191 // 0 +---------+ 1 +-------> x axis 00192 // (000) (100) 00193 // 00194 00195 #endif 00196