11 #ifndef __GEO_PrimVolume__
12 #define __GEO_PrimVolume__
40 pos *= myInverseXform;
45 fpreal zscale = (1 - pos.
z()) * 0.5
f;
46 fpreal taperx = 1 + (-1 + myTaperX) * zscale;
47 fpreal tapery = 1 + (-1 + myTaperY) * zscale;
81 fpreal zscale = (1 - pos.
z()) * 0.5
f;
82 fpreal taperx = 1 + (-1 + myTaperX) * zscale;
83 fpreal tapery = 1 + (-1 + myTaperY) * zscale;
106 return myInverseXform*0.5;
109 pos *= myInverseXform;
111 float zscale = (1 - pos.
z()) * 0.5
f;
112 float taperx = 1 + (-1 + myTaperX) * zscale;
113 float tapery = 1 + (-1 + myTaperY) * zscale;
122 0.5f * (myTaperX - 1.f) * pos.
x() / (taperx * taperx),
123 0.5
f * (myTaperY - 1.
f) * pos.
y() / (tapery * tapery),
126 return myInverseXform*tapergrad*0.5;
147 float zscale = (1 - pos.
z()) * 0.5
f;
148 float taperx = 1 + (-1 + myTaperX) * zscale;
149 float tapery = 1 + (-1 + myTaperY) * zscale;
158 0.5f * (1.f - myTaperX) * pos.
x(),
159 0.5f * (1.f - myTaperY) * pos.
y(),
162 return 2.f*tapergrad*myXform;
169 myXform.multiply3(xform);
170 myInverseXform = myXform;
178 myInverseXform = myXform;
179 myInverseXform.invert();
197 for (i = 0; i < 8; i++)
218 for (i = 0; i < 8; i++)
256 SamplingType sampling_type,
290 void save(std::ostream &os,
bool binary =
false)
const;
296 myCenter.assign(0, 0, 0);
298 myInverseXform.identity();
347 float u,
float v=0,
float w=0)
const override;
376 std::ostream &os,
bool binary,
392 bool loadStorageType(
const char *storagename);
408 static const int theSharedVoxelMagic=(
'V'<<24)|(
'o'<<16)|(
'x'<<8)|(
'l');
418 allocateSharedDataLoader();
468 bool dry_run=
false)
override;
470 bool dry_run=
false)
override;
477 float ulength,
float vlength,
478 float &uparm,
float &vparm)
const override;
480 float ulength,
float vlength,
481 float &uparm,
float &vparm,
482 float tolerance)
const override;
485 float uparm,
float vparm,
486 float &ulength,
float &vlength)
const override;
494 #if GA_PRIMITIVE_VERTEXLIST
509 void assignVertex(
GA_Offset new_vtx,
bool update_topology);
512 void stashed(
bool beingstashed,
518 void setTupleSize(
int comps);
524 void setStoresIntegers(
bool ints);
529 StorageType getStorageType()
const;
532 void setStorageType(StorageType store);
536 {
return getTupleSize() == 1 && getStoresIntegers() ==
false; }
555 void getInverseTransform4(
UT_Matrix4 &matx)
const;
568 bool isWorldAxisAligned()
const;
580 template <
typename T>
621 return getVoxelHandle();
628 template <
typename BASE>
631 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
632 return getVoxelHandleV4();
633 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
634 return getVoxelHandleV3();
635 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
636 return getVoxelHandleV2();
637 if constexpr (SYS_IsSame_v<float, BASE>)
638 return getVoxelHandleF();
639 if constexpr (SYS_IsSame_v<int64, BASE>)
640 return getVoxelHandleI();
643 template <
typename BASE>
646 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
647 return getVoxelWriteHandleV4();
648 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
649 return getVoxelWriteHandleV3();
650 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
651 return getVoxelWriteHandleV2();
652 if constexpr (SYS_IsSame_v<float, BASE>)
653 return getVoxelWriteHandleF();
654 if constexpr (SYS_IsSame_v<int64, BASE>)
655 return getVoxelWriteHandleI();
662 template <
typename BASE =
float>
665 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
666 return myVoxelHandleP;
667 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
668 return myVoxelHandleV;
669 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
670 return myVoxelHandleU;
671 if constexpr (SYS_IsSame_v<float, BASE>)
672 return myVoxelHandleF;
673 if constexpr (SYS_IsSame_v<int64, BASE>)
674 return myVoxelHandleI;
681 return getVoxelWriteHandle();
693 template <
typename OP>
694 void dispatchToReadHandle(OP& op)
const;
703 template <
typename OP>
704 void dispatchToWriteHandle(OP& op,
bool force_load);
706 template <
typename OP>
708 { dispatch(getStorageType(), op); }
710 template <
typename OP>
715 case VOLUME_TYPE_FLOAT: op((
float) 0);
break;
716 case VOLUME_TYPE_VECTOR2: op(
UT_Vector2(0,0));
break;
717 case VOLUME_TYPE_VECTOR3: op(
UT_Vector3(0,0,0));
break;
718 case VOLUME_TYPE_VECTOR4: op(
UT_Vector4(0,0,0,0));
break;
719 case VOLUME_TYPE_INTEGER: op((
int64) 0);
break;
740 template <
typename T>
745 bool isIndexInside(
int x,
int y,
int z)
const;
747 template <
typename T>
748 bool isIndexInside(
int x,
int y,
int z,
753 bool posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
778 template <
typename TYPE>
781 return getValueByType<TYPE>(pos, getVoxelHandleByType<TYPE>());
783 template <
typename TYPE>
786 if constexpr (SYSisSame<TYPE, float>())
793 localpos = toVoxelSpace(pos);
796 return (*vox)(localpos);
801 fpreal getValueAtIndex(
int ix,
int iy,
int iz)
const;
802 void getValuesAtIndices(
float *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
803 void getValuesAtIndices(
int *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
804 void getValuesAtIndices(
double *
f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
807 void getRes(
int &rx,
int &ry,
int &rz)
const;
811 fpreal getVoxelDiameter()
const;
818 fpreal calcPositiveDensity()
const;
821 fpreal calcMinimum()
const;
822 fpreal calcMaximum()
const;
823 fpreal calcAverage()
const;
828 bool isSDF()
const {
return myIsSDF; }
832 bool computeHeightFieldProperties(
int &a1,
int &a2,
int &axis,
fpreal &
scale)
const;
841 fpreal getBorderValue(
int component = 0)
const;
845 fpreal getCompressionTolerance()
const;
846 void setCompressionTolerance(
fpreal tol);
869 template <
typename T>
880 if (index >= 0 && index < myEntries)
882 exint tuple = index % myTupleSize;
884 index /= myTupleSize;
887 index = (index -
x) / myXres;
889 index = (index -
y) / myYres;
906 bool atEnd()
const {
return myCurr >= myEntries; }
918 : myVoxels(prim.getVoxelHandleByType<
T>())
921 prim.
getRes(myXres, myYres, myZres);
924 myEntries = myXres*myYres*myZres * myTupleSize;
929 exint myCurr = 0, myEntries = 0;
930 int myXres = 0, myYres = 0, myZres = 0;
937 template <
typename T>
999 #if !GA_PRIMITIVE_VERTEXLIST
1003 #if !GA_PRIMITIVE_VERTEXLIST
1062 float u,
float v = 0,
1063 unsigned du=0,
unsigned dv=0)
const override
1081 #if !GA_PRIMITIVE_VERTEXLIST
1093 fpreal myTaperX, myTaperY;
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
virtual void flushCECaches()
serialize getSerialize() const
bool myIMXLayerAuthorative
Definition of a geometry attribute.
GEO_VolumeVis getVisualization() const
GLenum GLuint GLenum GLsizei const GLchar * buf
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
GLenum GLuint GLsizei bufsize
virtual UT_Vector3 baryCenter() const
UT_SharedPtr< IMX_Layer > getIMXLayer(bool read, bool write) const
UT_COWHandle< UT_VoxelArray< BASE > > getHandleToVoxelsWithoutLoading() const
virtual void copyPrimitive(const GEO_Primitive *src)=0
virtual void clearForDeletion()
Used to pass options and map offset values during saving.
bool loadVoxelDataH9(UT_IStream &is, UT_VoxelArrayWriteHandleF voxels, int version)
bool isFullyLoaded() const
UT_Vector2T< float > UT_Vector2
UT_VoxelArrayHandleV4 myVoxelHandleP
TYPE getValueByType(const UT_Vector3 &pos, const UT_VoxelArrayReadHandle< TYPE > &vox) const
virtual UT_Vector3D computeNormalD() const =0
getFileOption("OpenEXR:storage") storage
UT_VoxelArrayHandleV2 & getMyVoxelHandleV2() const
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
GLsizei const GLfloat * value
void setVisOptions(const GEO_VolumeOptions &vis)
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *p) const override
static void dispatch(StorageType storage, const OP &op)
int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const override
const GLuint GLenum const void * binary
fpreal calcVolume(const UT_Vector3 &) const override
UT_Vector3T< float > UT_Vector3
GLdouble GLdouble GLdouble z
SYS_FORCE_INLINE UT_Vector3 getPos3() const
virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &save, GA_GeometryIndex *geo_index) const
constexpr SYS_FORCE_INLINE T & z() noexcept
fpreal getVisDensity() const
void resetAndAllocateHandles()
const GEO_VolumeOptions & getVisOptions() const
static GA_PrimitiveFamilyMask buildFamilyMask()
void reverse() override
Reverse the order of vertices.
GA_Offset vertexPoint() const
GA_SharedDataHandlePtr mySharedVoxelData
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
JSON reader class which handles parsing of JSON or bJSON files.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Class which writes ASCII or binary JSON streams.
Abstract base class for a range membership query object.
GEO_API const char * GEOgetVolumeStorageTypeToken(GEO_PrimVolume::StorageType type)
Returns string token from the StorageType enum value.
virtual bool savePrivateH9(std::ostream &os, bool binary) const
int getTupleSize() const
Returns the number of components (or the tuple size) for this volume.
fpreal calcArea() const override
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
UT_VoxelArrayHandleV4 & getMyVoxelHandleV4() const
virtual void swapVertexOffsets(const GA_Defragment &defrag)
virtual void unitToUnitLengthPair(float uparm, float vparm, float &ulength, float &vlength) const
void wireVertex(GA_Offset vertex, GA_Offset point)
virtual bool loadH9(UT_IStream &is, const UT_Array< GA_AttribLoadDataH9 > &prim_attribs, const UT_Array< GA_AttribLoadDataH9 > &vtx_attribs)
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
UT_VoxelArrayHandleV3 myVoxelHandleV
#define GA_INVALID_OFFSET
serializeT & operator++()
__hostdev__ float getValue(uint32_t i) const
UT_VoxelArrayWriteHandleF getVoxelWriteHandleF()
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimVolume &d)
virtual bool isDegenerate() const =0
Is the primitive degenerate.
fpreal getVisTiles() const
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
const UT_Matrix3 & getTransform() const
GA_API const UT_StringHolder scale
UT_VoxelArrayHandleV3 & getMyVoxelHandleV3() const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
UT_VoxelArrayHandleF & getMyVoxelHandleF() const
Gets the handle to our voxels.
UT_Vector4T< float > UT_Vector4
TYPE getValueByType(const UT_Vector3 &pos) const
Class to load shared data.
serializeT< float > serialize
virtual int evaluateInteriorPointV4(UT_Vector4 &pos, fpreal u, fpreal v, fpreal w=0) const
bool hasBorrowedIMXLayer() const
GEO_VolumeTypeInfo getTypeInfo() const
void setTransform(const UT_Matrix3 &m)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
bool hasBorrowedCEGrid() const
const UT_Matrix3 & getInverseTransform() const
Converts from world space to local space.
GLint GLint GLsizei GLint GLenum format
virtual const GA_PrimitiveJSON * getJSON() const =0
GLsizei GLsizei GLchar * source
Provide a JSON interface to a primitive.
GLint GLenum GLboolean GLsizei stride
UT_COWWriteHandle< UT_VoxelArray< BASE > > getVoxelWriteHandleByType()
void setBorrowedCEGrid(CE_Grid *grid)
A handle to simplify manipulation of multiple attributes.
Defragmentation of IndexMaps.
bool getStoresIntegers() const
Returns true if this volume stores integers.
GLboolean GLboolean GLboolean b
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
serializeT< T > getSerializeByType() const
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
fpreal getBorderValue(int component=0) const
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos)
bool mySharedDataHandleLoaded
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
UT_COWHandle< UT_VoxelArray< BASE > > getVoxelHandleByType() const
UT_VoxelArrayHandleF getVoxelHandleF() const
virtual void unitLengthToUnitPair(float ulength, float vlength, float &uparm, float &vparm) const
GT_API const UT_StringHolder version
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
virtual bool evaluateInteriorPointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v, fpreal w=0) const
CE_Grid * getCEGrid(bool read, bool write) const
virtual void transform(const UT_Matrix4 &)
virtual void enlargePointBounds(UT_BoundingBox &box) const
virtual void getLocalTransform(UT_Matrix3D &matrix) const
#define SCALAR(T)
Simplify checking for scalar types.
virtual bool loadPrivateH9(UT_IStream &is)
UT_VoxelArrayHandleF myVoxelHandleF
void setVertexPoint(GA_Offset pt)
virtual int detachPoints(GA_PointGroup &grp)=0
GLint GLint GLsizei GLint border
fpreal getVoxel(exint index) const
Random access of a voxel value.
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
UT_SharedPtr< IMX_Layer > myIMXLayer
virtual bool getBBox(UT_BoundingBox *bbox) const =0
SYS_FORCE_INLINE void initBounds()
virtual int evaluateNormalVector(UT_Vector3 &nml, float u, float v=0, float w=0) const
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
virtual void stealCEBuffers(const GA_Primitive *src)
Steal the underlying CE buffer from the source.
Class to store JSON objects as C++ objects.
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
void setVisTiles(fpreal tiles)
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
void setTypeInfo(GEO_VolumeTypeInfo info)
SYS_FORCE_INLINE GA_Offset getPointOffset() const
GLubyte GLubyte GLubyte GLubyte w
void setBorrowedIMXLayer(const UT_SharedPtr< IMX_Layer > &l)
UT_VoxelArrayHandleV2 myVoxelHandleU
constexpr SYS_FORCE_INLINE T & y() noexcept
UT_VoxelArrayHandleI myVoxelHandleI
virtual bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item)
UT_VoxelArrayHandleI & getMyVoxelHandleI() const
void getRes(int &rx, int &ry, int &rz) const
Returns the resolution of the voxel array.
GEO_API GEO_PrimVolume::StorageType GEOgetVolumeStorageTypeEnum(const char *token, GEO_PrimVolume::StorageType def)
void dispatch(const OP &op) const
bool isScalarVolume() const
True if this is a traditional scalar volume.
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
UT_Matrix3T< fpreal64 > UT_Matrix3D
constexpr SYS_FORCE_INLINE T & x() noexcept