11 #ifndef __GEO_PrimVolume__
12 #define __GEO_PrimVolume__
39 pos *= myInverseXform;
44 fpreal zscale = (1 - pos.
z()) * 0.5
f;
45 fpreal taperx = 1 + (-1 + myTaperX) * zscale;
46 fpreal tapery = 1 + (-1 + myTaperY) * zscale;
80 fpreal zscale = (1 - pos.
z()) * 0.5
f;
81 fpreal taperx = 1 + (-1 + myTaperX) * zscale;
82 fpreal tapery = 1 + (-1 + myTaperY) * zscale;
105 return myInverseXform*0.5;
108 pos *= myInverseXform;
110 float zscale = (1 - pos.
z()) * 0.5
f;
111 float taperx = 1 + (-1 + myTaperX) * zscale;
112 float tapery = 1 + (-1 + myTaperY) * zscale;
121 0.5f * (myTaperX - 1.f) * pos.
x() / (taperx * taperx),
122 0.5
f * (myTaperY - 1.
f) * pos.
y() / (tapery * tapery),
125 return myInverseXform*tapergrad*0.5;
146 float zscale = (1 - pos.
z()) * 0.5
f;
147 float taperx = 1 + (-1 + myTaperX) * zscale;
148 float tapery = 1 + (-1 + myTaperY) * zscale;
157 0.5f * (1.f - myTaperX) * pos.
x(),
158 0.5f * (1.f - myTaperY) * pos.
y(),
161 return 2.f*tapergrad*myXform;
168 myXform.multiply3(xform);
169 myInverseXform = myXform;
177 myInverseXform = myXform;
178 myInverseXform.invert();
196 for (i = 0; i < 8; i++)
217 for (i = 0; i < 8; i++)
255 SamplingType sampling_type,
289 void save(std::ostream &os,
bool binary =
false)
const;
295 myCenter.assign(0, 0, 0);
297 myInverseXform.identity();
346 float u,
float v=0,
float w=0)
const override;
375 std::ostream &os,
bool binary,
406 static const int theSharedVoxelMagic=(
'V'<<24)|(
'o'<<16)|(
'x'<<8)|(
'l');
416 allocateSharedDataLoader();
466 bool dry_run=
false)
override;
468 bool dry_run=
false)
override;
475 float ulength,
float vlength,
476 float &uparm,
float &vparm)
const override;
478 float ulength,
float vlength,
479 float &uparm,
float &vparm,
480 float tolerance)
const override;
483 float uparm,
float vparm,
484 float &ulength,
float &vlength)
const override;
492 #if GA_PRIMITIVE_VERTEXLIST
507 void assignVertex(
GA_Offset new_vtx,
bool update_topology);
510 void stashed(
bool beingstashed,
516 void setTupleSize(
int comps);
522 void setStoresIntegers(
bool ints);
527 StorageType getStorageType()
const;
530 void setStorageType(StorageType store);
549 void getInverseTransform4(
UT_Matrix4 &matx)
const;
562 bool isWorldAxisAligned()
const;
574 template <
typename T>
615 return getVoxelHandle();
622 template <
typename BASE>
625 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
626 return getVoxelHandleV4();
627 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
628 return getVoxelHandleV3();
629 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
630 return getVoxelHandleV2();
631 if constexpr (SYS_IsSame_v<float, BASE>)
632 return getVoxelHandleF();
633 if constexpr (SYS_IsSame_v<int64, BASE>)
634 return getVoxelHandleI();
637 template <
typename BASE>
640 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
641 return getVoxelWriteHandleV4();
642 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
643 return getVoxelWriteHandleV3();
644 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
645 return getVoxelWriteHandleV2();
646 if constexpr (SYS_IsSame_v<float, BASE>)
647 return getVoxelWriteHandleF();
648 if constexpr (SYS_IsSame_v<int64, BASE>)
649 return getVoxelWriteHandleI();
656 template <
typename BASE =
float>
659 if constexpr (SYS_IsSame_v<UT_Vector4, BASE>)
660 return myVoxelHandleP;
661 if constexpr (SYS_IsSame_v<UT_Vector3, BASE>)
662 return myVoxelHandleV;
663 if constexpr (SYS_IsSame_v<UT_Vector2, BASE>)
664 return myVoxelHandleU;
665 if constexpr (SYS_IsSame_v<float, BASE>)
666 return myVoxelHandleF;
667 if constexpr (SYS_IsSame_v<int64, BASE>)
668 return myVoxelHandleI;
675 return getVoxelWriteHandle();
687 template <
typename OP>
688 void dispatchToReadHandle(OP& op)
const;
697 template <
typename OP>
698 void dispatchToWriteHandle(OP& op,
bool force_load);
700 template <
typename OP>
702 { dispatch(getStorageType(), op); }
704 template <
typename OP>
709 case VOLUME_TYPE_FLOAT: op((
float) 0);
break;
710 case VOLUME_TYPE_VECTOR2: op(
UT_Vector2(0,0));
break;
711 case VOLUME_TYPE_VECTOR3: op(
UT_Vector3(0,0,0));
break;
712 case VOLUME_TYPE_VECTOR4: op(
UT_Vector4(0,0,0,0));
break;
713 case VOLUME_TYPE_INTEGER: op((
int64) 0);
break;
734 template <
typename T>
739 bool isIndexInside(
int x,
int y,
int z)
const;
741 template <
typename T>
742 bool isIndexInside(
int x,
int y,
int z,
747 bool posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
772 template <
typename TYPE>
775 return getValueByType<TYPE>(pos, getVoxelHandleByType<TYPE>());
777 template <
typename TYPE>
780 if constexpr (SYSisSame<TYPE, float>())
782 return getValue(pos, vox);
787 localpos = toVoxelSpace(pos);
790 return (*vox)(localpos);
795 fpreal getValueAtIndex(
int ix,
int iy,
int iz)
const;
796 void getValuesAtIndices(
float *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
797 void getValuesAtIndices(
int *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
798 void getValuesAtIndices(
double *
f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
801 void getRes(
int &rx,
int &ry,
int &rz)
const;
805 fpreal getVoxelDiameter()
const;
812 fpreal calcPositiveDensity()
const;
815 fpreal calcMinimum()
const;
816 fpreal calcMaximum()
const;
817 fpreal calcAverage()
const;
822 bool isSDF()
const {
return myIsSDF; }
826 bool computeHeightFieldProperties(
int &a1,
int &a2,
int &axis,
fpreal &
scale)
const;
835 fpreal getBorderValue(
int component = 0)
const;
839 fpreal getCompressionTolerance()
const;
840 void setCompressionTolerance(
fpreal tol);
859 template <
typename T>
870 if (index >= 0 && index < myEntries)
872 exint tuple = index % myTupleSize;
874 index /= myTupleSize;
877 index = (index -
x) / myXres;
879 index = (index -
y) / myYres;
896 bool atEnd()
const {
return myCurr >= myEntries; }
908 : myVoxels(prim.getVoxelHandleByType<
T>())
911 prim.
getRes(myXres, myYres, myZres);
914 myEntries = myXres*myYres*myZres * myTupleSize;
919 exint myCurr = 0, myEntries = 0;
920 int myXres = 0, myYres = 0, myZres = 0;
927 template <
typename T>
988 #if !GA_PRIMITIVE_VERTEXLIST
992 #if !GA_PRIMITIVE_VERTEXLIST
1051 float u,
float v = 0,
1052 unsigned du=0,
unsigned dv=0)
const override
1070 #if !GA_PRIMITIVE_VERTEXLIST
1082 fpreal myTaperX, myTaperY;
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
virtual void flushCECaches()
serialize getSerialize() const
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_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
bool hasBorrowedCEImage() 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)
GLenum GLenum GLsizei void * image
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
void read(T &in, bool &v)
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++()
UT_VoxelArrayWriteHandleF getVoxelWriteHandleF()
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimVolume &d)
virtual bool isDegenerate() const =0
Is the primitive degenerate.
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
void setTransform(const UT_Matrix3 &m)
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
CE_Image * getCEImage(bool read, bool write) const
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.
void setBorrowedCEImage(CE_Image *image)
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().
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
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
SYS_FORCE_INLINE GA_Offset getPointOffset() const
GLubyte GLubyte GLubyte GLubyte w
bool myCEImageAuthorative
UT_VoxelArrayHandleV2 myVoxelHandleU
constexpr SYS_FORCE_INLINE T & y() noexcept
void write(T &out, bool v)
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
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