00001 //------------------------------------------------------------------------ 00002 // 00003 // Joe Kniss 00004 // 6-20-03 00005 // ________ ____ ___ 00006 // | \ / | / / 00007 // +---+ \/ |/ / 00008 // +--+| |\ /| < 00009 // | || | \ / | |\ \ 00010 // | | \/ | | \ \ 00011 // \_____| |__| \__\ 00012 // Copyright 2003 00013 // Joe Michael Kniss 00014 // <<< jmk@cs.utah.edu >>> 00015 // "All Your Base are Belong to Us" 00016 //------------------------------------------------------------------------- 00017 00018 /// VolField.h 00019 00020 #ifndef __VOLUME_FIELD_DOT_H 00021 #define __VOLUME_FIELD_DOT_H 00022 00023 #include <simBase/simBase.h> 00024 #include <nrro/nrro.h> 00025 #include <texture/simTexture.h> 00026 #include <textureGlift.h> 00027 00028 /////////////////////////////////////////////////////////////////////////// 00029 /// VolField, a single field. 00030 /// An elaborate container for a simian data field. 00031 /// see VolFieldVec below for a description of a collection of fields 00032 /// TODO: needs major cleanup for handling Nrro images and not just 00033 /// 4D volumes... working on it, jeez! 00034 /////////////////////////////////////////////////////////////////////////// 00035 00036 class VolField : 00037 public NrroSPVec, /// is a Nrro Vector! 00038 public gutz::Counted, 00039 public SimBase 00040 { 00041 public: 00042 VolField(); 00043 VolField(Nrro *n); 00044 VolField(NrroSP n); 00045 00046 virtual ~VolField(){} 00047 00048 ////////////////////////////////////////////// 00049 /// Nrros: ----------------------------------- 00050 /// data is stored in Nrrd Objects, if there 00051 /// are more than 1 nrros then you probably have 00052 /// bricked data, but you should check. 00053 unsigned int numNrro() { return NrroSPVec::size(); } 00054 NrroSP getNrro(unsigned int n=0){return NrroSPVec::operator[](n);} 00055 void setNrro(NrroSP nrro, unsigned int n=0); 00056 00057 ////////////////////////////////////////////// 00058 /// is this field active for rendering ? 00059 bool isActive() {return _on;} 00060 void setActive(bool on_off) {_on = on_off;} 00061 00062 ////////////////////////////////////////////// 00063 /// Bricking: -------------------------------- 00064 /// if bricked the 0th nrro is the original data 00065 bool isBricked(){return _bricked;} 00066 /// set as bricked or not bricked 00067 void setBricked(bool bricked){_bricked = bricked;} 00068 /// get a Nrro brick 00069 NrroSP getBrick(unsigned int i); 00070 /// how many bricks? 00071 unsigned int numBricks(); 00072 /// create bricks no bigger than maxBrickDims (insures pow2) 00073 void brick(gutz::vec3i maxBrickDims); 00074 /// create a single brick 00075 NrroSP genBrick(gutz::vec3i pos, gutz::vec3i size, NrroSP nin); 00076 /// remove all bricks 00077 void nukeBricks(); 00078 00079 ////////////////////////////////////////////// 00080 /// a flag informing of changes to field 00081 bool getUpdate() {return _up;} 00082 void setUpdate(bool up) {_up = up;} 00083 virtual void update(); 00084 00085 ////////////////////////////////////////////// 00086 /// texture qualities, these are 00087 /// repeated from "simTexture.h", see for 00088 /// complete list of available qualities 00089 enum{ 00090 BEST = SIMT_BEST, /// best fit given the native field quality (default) 00091 BYTE = SIMT_8BIT, /// 8 bit fixed 00092 SHORT = SIMT_16FIXED, /// 16 bit fixed 00093 HALF = SIMT_16FLOAT, /// 16 bit float 00094 FLOAT = SIMT_32FLOAT, /// 32 bit float 00095 QUALITY_LAST 00096 }; 00097 int getTexQuality() {return _texquality;} 00098 void setTexQuality(int tq) {if(tq != _texquality) setUpdate(true); _texquality = tq;} 00099 00100 ////////////////////////////////////////////// 00101 /// Textures for rendering 00102 glift::SingleTexSP genTexture(unsigned int n=0); 00103 glift::SingleTexSP genBrickTexture(unsigned int n=0); 00104 void clearTex() {_tex = glift::SingleTexSPVec_empty;} 00105 00106 ////////////////////////////////////////////// 00107 /// validate the dimensions of this field 00108 /// against another field, are the data and all 00109 /// bricks the same dimension? 00110 bool checkDims(gutz::SmartPtr<VolField> f); 00111 00112 /////////////////////////////////////////////// 00113 /// texture unit to bind this field to, uses 00114 /// [0-N] range 00115 int getTexUnit() const { return _texUnit; } 00116 void setTexUnit(int tu) { _texUnit = tu; } 00117 00118 protected: 00119 00120 bool _on; 00121 bool _up; 00122 bool _bricked; 00123 glift::SingleTexSPVec _tex; 00124 int _texquality; 00125 int _texUnit; 00126 }; 00127 00128 typedef gutz::SmartPtr<VolField> VolFieldSP; 00129 00130 /////////////////////////////////////////////////////////////////////////// 00131 /////////////////////////////////////////////////////////////////////////// 00132 /////////////////////////////////////////////////////////////////////////// 00133 /// VolFieldVec, a collection of fields, with functionality of a std::vector 00134 /////////////////////////////////////////////////////////////////////////// 00135 /////////////////////////////////////////////////////////////////////////// 00136 /////////////////////////////////////////////////////////////////////////// 00137 00138 class VolFieldVec : 00139 public std::vector<VolFieldSP>, 00140 public SimBase { 00141 public: 00142 VolFieldVec():SimBase(){} 00143 virtual ~VolFieldVec(){} 00144 00145 int numFields(){return size();} 00146 00147 //////////////////////////////////////// 00148 /// Add Nrro, this is the correct way 00149 /// to add a new field to this array. 00150 void addNrro(NrroSP n); 00151 00152 //////////////////////////////////////// 00153 /// it's safer to use these accessors 00154 VolFieldSP getField(unsigned int i); 00155 void setField(unsigned int i, VolField *f); 00156 void delField(unsigned int i); 00157 00158 //////////////////////////////////////// 00159 /// check all fields 00160 virtual bool checkFields(); 00161 /// check a field and break it up if it has too many channels 00162 /// 4 is the limmit, 1,2,4 fields are optimal for hardware 00163 virtual bool checkField(unsigned int i); 00164 00165 //////////////////////////////////////// 00166 /// brick all fields if they are active 00167 /// specific maximum dimensions 00168 void brickData(gutz::vec3i maxBrickDims); 00169 00170 //////////////////////////////////////// 00171 /// update: 00172 /// check if any field changed 00173 virtual bool needUpdate(); 00174 /// update all fields 00175 virtual void update(); 00176 00177 protected: 00178 00179 }; 00180 00181 #endif 00182