00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GEO_PrimVolume__
00020 #define __GEO_PrimVolume__
00021
00022 #include <UT/UT_VoxelArray.h>
00023
00024 #include "GEO_API.h"
00025 #include "GEO_Vertex.h"
00026 #include "GEO_Primitive.h"
00027
00028 enum GEO_VolumeBorder
00029 {
00030 GEO_VOLUMEBORDER_CONSTANT,
00031 GEO_VOLUMEBORDER_REPEAT,
00032 GEO_VOLUMEBORDER_STREAK,
00033 GEO_VOLUMEBORDER_SDF,
00034 NUM_GEO_VOLUMEBORDERS
00035 };
00036
00037 enum GEO_VolumeVis
00038 {
00039 GEO_VOLUMEVIS_SMOKE,
00040 GEO_VOLUMEVIS_RAINBOW,
00041 GEO_VOLUMEVIS_ISO,
00042 GEO_VOLUMEVIS_INVISIBLE,
00043 NUM_GEO_VOLUMEVIS
00044 };
00045
00046 class GEO_API GEO_PrimVolume : public GEO_Primitive
00047 {
00048 public:
00049 GEO_PrimVolume(GEO_Detail *d);
00050 virtual ~GEO_PrimVolume();
00051
00052
00053
00054 virtual unsigned getPrimitiveId() const;
00055 virtual int getBBox(UT_BoundingBox *bbox) const;
00056 virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
00057 virtual UT_Vector3 baryCenter() const;
00058 virtual UT_Vector3 computeNormal() const;
00059 virtual int save(ostream &os, int binary) const;
00060 virtual bool load(UT_IStream &is);
00061
00062 virtual bool evaluatePoint(GEO_Vertex &result,
00063 GEO_AttributeHandleList &hlist,
00064 fpreal u, fpreal v, uint du, uint dv) const;
00065
00066
00067
00068
00069
00070 virtual void transform(const UT_Matrix4 &mat);
00071
00072 virtual void untransform(void);
00073 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00074 virtual void copyPrimitive(const GEO_Primitive *src,
00075 GEO_Point **ptredirect);
00076 virtual void addPointRefToGroup(GB_PointGroup &grp) const;
00077
00078 void changePointRef(GB_Element *from, GB_Element *to);
00079 virtual int vertexApply(int (*a)(GB_Vertex &, void *), void *);
00080 virtual int vertexApply(int (*a)(const GB_Vertex &, void *),
00081 void *) const;
00082 virtual void reverse(void);
00083
00084 virtual unsigned getVertexCount() const;
00085 virtual const GEO_Vertex &getVertex(unsigned idx = 0) const;
00086 virtual GEO_Vertex &getVertex(unsigned idx = 0);
00087
00088
00089
00090
00091
00092
00093 virtual int detachPoints (GB_PointGroup &grp);
00094
00095 virtual int isDegenerate() const;
00096
00097
00098
00099 virtual void unitLengthToUnitPair(float ulength, float vlength,
00100 float &uparm, float &vparm)const;
00101
00102 virtual void unitToUnitLengthPair(float uparm, float vparm,
00103 float &ulength, float &vlength)
00104 const;
00105
00106 virtual float calcVolume(UT_Vector3 &refpt) const;
00107 virtual float calcArea() const;
00108
00109
00110
00111
00112 void setVertex(GEO_Point *ppt)
00113 {
00114 myVertex.setPt(ppt);
00115 }
00116
00117
00118 virtual void stashed(int onoff);
00119
00120 const UT_Matrix3 &getTransform(void) const { return myXform; }
00121 void setTransform(const UT_Matrix3 &m)
00122 { myXform = m;
00123 myInverseXform = m;
00124 myInverseXform.invert();
00125 }
00126
00127 void getTransform4( UT_Matrix4 &matx) const;
00128 void setTransform4(const UT_Matrix4 &matx);
00129
00130
00131 const UT_Matrix3 &getInverseTransform() const { return myInverseXform; }
00132 void getInverseTransform4(UT_Matrix4 &matx) const;
00133
00134
00135 UT_Vector3 toVoxelSpace(const UT_Vector3 &pos) const;
00136
00137 UT_Vector3 fromVoxelSpace(const UT_Vector3 &pos) const;
00138
00139
00140 void setVoxels(UT_VoxelArrayF *vox);
00141 void setVoxels(UT_VoxelArrayHandleF handle);
00142
00143
00144
00145 void stealVoxels(UT_VoxelArrayF *vox);
00146
00147
00148
00149
00150
00151
00152 UT_VoxelArrayHandleF getVoxelHandle() const;
00153
00154
00155 UT_VoxelArrayWriteHandleF getVoxelWriteHandle();
00156
00157
00158
00159 bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
00160
00161
00162
00163 bool posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
00164
00165
00166 fpreal getValue(const UT_Vector3 &pos) const;
00167 UT_Vector3 getGradient(const UT_Vector3 &pos) const;
00168
00169
00170
00171 fpreal getValue(const UT_Vector3 &pos, const UT_VoxelArrayReadHandleF &handle) const;
00172
00173
00174 fpreal getValueAtIndex(int ix, int iy, int iz) const;
00175
00176 void getRes(int &rx, int &ry, int &rz) const;
00177
00178
00179 fpreal getVoxelDiameter() const;
00180
00181
00182
00183 fpreal calcPositiveDensity() const;
00184
00185
00186 fpreal calcMinimum() const;
00187 fpreal calcMaximum() const;
00188 fpreal calcAverage() const;
00189
00190
00191
00192
00193 bool isSDF() const { return myIsSDF; }
00194
00195
00196 static const char *getBorderToken(GEO_VolumeBorder border);
00197 void setBorder(GEO_VolumeBorder border, fpreal val);
00198 GEO_VolumeBorder getBorder() const;
00199 fpreal getBorderValue() const;
00200
00201
00202 fpreal getCompressionTolerance() const;
00203 void setCompressionTolerance(fpreal tol);
00204 void recompress();
00205
00206
00207 static const char *getVisualizationToken(GEO_VolumeVis vis);
00208 void setVisualization(GEO_VolumeVis vis, fpreal iso, fpreal density);
00209 fpreal getVisIso() const { return myVisIso; }
00210 fpreal getVisDensity() const { return myVisDensity; }
00211 GEO_VolumeVis getVisualization() const { return myVisMode; }
00212
00213 protected:
00214
00215 virtual void copyOffsetPrimitive(const GEO_Primitive *src,
00216 int basept);
00217 virtual int savePrivate(ostream &os, int binary) const;
00218 virtual bool loadPrivate(UT_IStream &is);
00219 virtual int pointCanDelete(GB_Element *) const;
00220 virtual void pointDeleted(GB_Element *pt);
00221 virtual int isPointUsed(GB_Element *pt) const;
00222 virtual int isPointGroupUsed(const GB_PointGroup &grp) const;
00223
00224
00225 bool loadVoxelData(UT_IStream &is, UT_VoxelArrayWriteHandleF voxels, int version);
00226
00227 UT_VoxelArrayHandleF myVoxelHandle;
00228 private:
00229 GEO_Vertex myVertex;
00230 UT_Matrix3 myXform;
00231 UT_Matrix3 myInverseXform;
00232 bool myIsSDF : 1;
00233
00234 GEO_VolumeVis myVisMode;
00235 fpreal myVisIso;
00236 fpreal myVisDensity;
00237
00238 friend ostream &operator<<(ostream &os, const GEO_PrimVolume &d)
00239 {
00240 d.save(os, 0);
00241 return os;
00242 }
00243
00244
00245
00246 bool myStashedState : 1;
00247 };
00248
00249 #endif