00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GU_PrimVolumeCache__
00020 #define __GU_PrimVolumeCache__
00021
00022 #include "GU_API.h"
00023
00024 #include <UT/UT_Vector3.h>
00025 #include <UT/UT_Vector4.h>
00026 #include <UT/UT_RefArray.h>
00027 #include <UT/UT_VoxelArray.h>
00028 #include <UT/UT_EnvControl.h>
00029
00030 #include "GU_Detail.h"
00031 #include "GU_DisplayCache.h"
00032
00033 class GU_API GU_PrimVolumeCacheLight
00034 {
00035 public:
00036 bool operator==(const GU_PrimVolumeCacheLight &l) const
00037 {
00038
00039
00040 if (myIsInfinite &&
00041 myIsInfinite == l.myIsInfinite)
00042 return true;
00043 return (myOrg == l.myOrg) &&
00044 (myDir == l.myDir) &&
00045 (myCd == l.myCd) &&
00046 (myIsAmbient == l.myIsAmbient) &&
00047 (myIsInfinite == l.myIsInfinite);
00048 }
00049
00050 void setOrg(const UT_Vector3 &org) { myOrg = org; }
00051 void setDir(const UT_Vector3 &dir) { myDir = dir; }
00052 void setCd(const UT_Vector3 &cd) { myCd = cd; }
00053 void setIsAmbient(bool isamb) { myIsAmbient = isamb; }
00054 void setIsInfinite(bool isinfinite) { myIsInfinite = isinfinite; }
00055
00056 const UT_Vector3 &getOrg() const { return myOrg; }
00057 const UT_Vector3 &getDir() const { return myDir; }
00058 const UT_Vector3 &getCd() const { return myCd; }
00059
00060 bool isAmbient() const { return myIsAmbient; }
00061 bool isInfinite() const { return myIsInfinite; }
00062
00063 fpreal getDistance(const UT_Vector3 &pos) const;
00064
00065 protected:
00066 UT_Vector3 myOrg, myDir;
00067 UT_Vector3 myCd;
00068 bool myIsAmbient, myIsInfinite;
00069 };
00070
00071
00072 class GU_PrimVolumeCacheParms;
00073 class GU_PrimVolume;
00074
00075 class GU_API GU_PrimVolumeTexture
00076 {
00077 public:
00078 GU_PrimVolumeTexture() {}
00079 virtual ~GU_PrimVolumeTexture() {}
00080
00081 virtual void refresh(const UT_VoxelArray<UT_Vector4> *voxels) = 0;
00082 };
00083
00084 class GU_API GU_PrimVolumeCache : public GU_DisplayCache
00085 {
00086 public:
00087 GU_PrimVolumeCache(void);
00088 virtual ~GU_PrimVolumeCache(void);
00089
00090
00091 int refresh(GU_PrimVolumeCacheParms &parms);
00092
00093
00094 UT_VoxelArray<UT_Vector4> *getShadedVoxels() const { return myVoxels; }
00095 GU_PrimVolumeTexture *getTexture() const { return myTexture; }
00096 void setTexture(GU_PrimVolumeTexture *tex)
00097 { myTexture = tex; }
00098
00099 GU_Detail *getIsoSurface() const { return myIsoSurf; }
00100
00101 UT_Vector3 getIsoCd() const { return myIsoCd; }
00102
00103
00104 protected:
00105 void lightVoxelsFromLight(const UT_VoxelArrayF *density,
00106 const GU_PrimVolumeCacheLight &light,
00107 const UT_Vector3 &cd,
00108 fpreal shadowdensity);
00109
00110 void rainbowVoxels(const UT_VoxelArrayF *density);
00111
00112
00113
00114 int getMaxRes(int axis) const { return UT_EnvControl::getInt(ENV_HOUDINI_MAX_VOLUME_RES); }
00115
00116
00117
00118 bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
00119 bool posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
00120
00121 UT_VoxelArray<UT_Vector4> *myVoxels;
00122 UT_RefArray<GU_PrimVolumeCacheLight> myLightList;
00123 GU_PrimVolumeTexture *myTexture;
00124 GU_Detail *myIsoSurf;
00125 float myOldLOD;
00126 UT_Vector3 myIsoCd;
00127
00128 UT_Vector3 myCacheRes;
00129 UT_Matrix4 myCacheXform;
00130 UT_Matrix4 myCacheIXform;
00131 const UT_VoxelArrayF *myCacheDensity;
00132 };
00133
00134 class GU_API GU_PrimVolumeCacheParms : public GU_CacheParms
00135 {
00136 public:
00137 GU_PrimVolumeCacheParms(void) {}
00138 virtual ~GU_PrimVolumeCacheParms(void) {}
00139
00140 void setVolume(GU_PrimVolume *vol) { myVolume = vol; }
00141 GU_PrimVolume *getVolume() const { return myVolume; }
00142
00143 void setLights(UT_RefArray<GU_PrimVolumeCacheLight> &lightlist)
00144 { myLightList = lightlist; }
00145 const UT_RefArray<GU_PrimVolumeCacheLight> &getLights() const { return myLightList; }
00146
00147 private:
00148 UT_RefArray<GU_PrimVolumeCacheLight> myLightList;
00149 GU_PrimVolume *myVolume;
00150 };
00151
00152 #endif
00153