44 using namespace HDK_Sample;
70 GAS_NetVDBSliceExchange::getDopDescription()
73 static PRM_Default theGeometryNameDefault(0,
"Geometry");
74 static PRM_Name theVDBName(
"vdbname",
"VDB Names");
82 static PRM_Name theThisSliceName(
"slice",
"Slice Number");
84 static PRM_Name theSliceRootName(
"sliceroot",
"Slice Data Root");
87 static PRM_Name theOverlapName(
"overlap",
"Slice Overlap");
88 static PRM_Name theOverlapVoxelName(
"overlapvoxel",
"Voxel Overlap");
108 "hdk_gasnetvdbsliceexchange",
109 "Gas Net VDB Slice Exchange",
115 return &theDopDescription;
143 GASreadDataFromPacket(openvdb::math::Vec3<float> &value,
UT_NetMessage *msg,
exint offset)
151 GASreadDataFromPacket(openvdb::math::Vec3<double> &value,
UT_NetMessage *msg,
exint offset)
159 GASreadDataFromPacket(openvdb::math::Vec3<int32> &value,
UT_NetMessage *msg,
exint offset)
162 value[1] = msg->
extractInt32(offset +
sizeof(value[0]));
163 value[2] = msg->
extractInt32(offset + 2*
sizeof(value[0]));
201 GASwriteDataToPacket(
UT_NetMessage *msg,
exint offset, openvdb::math::Vec3<float> value)
209 GASwriteDataToPacket(
UT_NetMessage *msg,
exint offset, openvdb::math::Vec3<double> value)
217 GASwriteDataToPacket(
UT_NetMessage *msg,
exint offset, openvdb::math::Vec3<int32> value)
234 template <
typename Gr
idType>
243 typename GridType::Accessor acc = grid.getAccessor();
252 for (
exint reply = 0; reply < numreply; reply++)
254 if (replyoff >= msg->
length())
256 std::cerr <<
"Malformed reply from " << srcpeer <<
", total replies " << numreply <<
" exhausted message packet sized " << msg->
length() << std::endl;
265 if (magictoken != 0x51DEEFC5)
269 std::cerr <<
"Malformed reply from " << srcpeer <<
", total replies " << numreply <<
" missing magic token on packet " << reply <<
" at offset " << replyoff << std::endl;
274 for (
int nm = 0; nm < 64; nm++)
281 for (
int x = 0;
x < 8;
x++)
283 for (
int y = 0;
y < 8;
y++)
286 for (
int z = 0;
z < 8;
z++)
288 if (nodemask[nodemaskpos] & flag)
293 GASreadDataFromPacket(v, msg, replyoff+nodeoff);
294 openvdb::Coord coord(minvxl.
x() +
x, minvxl.
y() +
y, minvxl.
z() +
z);
295 acc.setValueOn(coord, v);
296 nodeoff +=
sizeof(
v);
320 template <
typename Gr
idType>
329 typename GridType::Accessor acc = grid.getAccessor();
334 for (
int i = 0; i < numslice; i++)
344 msgs(i)->setWriteDataLength(8 + 8);
350 packetvoxeloffset.
setSize(numslice);
351 packetvoxelvalue.
setSize(numslice);
353 ValueType background = grid.background();
355 for (
auto it = grid.tree().beginLeaf(); it; ++it)
358 auto vdb_box = it->getNodeBoundingBox();
363 tstart.
assign(vdb_box.min().x()-0.5, vdb_box.min().y()-0.5, vdb_box.min().z()-0.5);
364 tend.
assign(vdb_box.max().x()+0.5, vdb_box.max().y()+0.5, vdb_box.max().z()+0.5);
369 tbbox_expand = tbbox;
385 for (
int i = vdb_box.min().x(); i <= vdb_box.max().x(); i++)
386 for (
int j = vdb_box.min().y();
j <= vdb_box.max().y();
j++)
387 for (
int k = vdb_box.min().z(); k <= vdb_box.max().z(); k++)
388 acc.setValueOff(openvdb::Coord(i,
j, k), background);
398 for (
int slice = 0; slice < numslice; slice++)
400 packetvoxeloffset(slice).
entries(0);
401 packetvoxelvalue(slice).
entries(0);
405 for (
int i = vdb_box.min().x(); i <= vdb_box.max().x(); i++)
406 for (
int j = vdb_box.min().y();
j <= vdb_box.max().y();
j++)
407 for (
int k = vdb_box.min().z(); k <= vdb_box.max().z(); k++)
416 acc.setValueOff(openvdb::Coord(i,
j, k), background);
422 for (
int slice = 0; slice < numslice; slice++)
425 if (slice == thisslice)
431 packetvoxeloffset(slice).
append( offset );
432 packetvoxelvalue(slice).
append( acc.getValue(openvdb::Coord(i,
j, k)) );
442 for (
int slice = 0; slice < numslice; slice++)
444 if (slice == thisslice)
447 if (packetvoxeloffset(slice).
entries() == 0)
450 auto && msg = msgs(slice);
452 exint msgoffset = msgoffsets(slice);
465 memset(nodemask, 0, 64);
466 for (
auto && offset : packetvoxeloffset(slice))
468 nodemask[offset >> 3] |= 1 << (offset & 7);
471 for (
int nm = 0; nm < 64; nm++)
476 for (
auto && value : packetvoxelvalue(slice))
478 GASwriteDataToPacket(msg, msgoffset, value);
479 msgoffset +=
sizeof(
value);
483 msgoffsets(slice) = msgoffset;
488 for (
int slice = 0; slice < numslice; slice++)
490 if (slice == thisslice)
493 msgs(slice)->overwriteInt32(8, msgpackets(slice));
510 overlap, thisslice, slicetable);
517 const char *tracker,
int port,
const char *jobname,
529 fpreal overlap = solver->getOverlap();
541 UT_NetExchange netxchg(tracker, port, thisslice, nslice, jobname);
551 thisslice, slicetable);
554 for (
int slice = 0; slice < nslice; slice++)
556 if (slice == thisslice)
559 netxchg.
sendData(slice, dispatchmsgs(slice));
567 for (
int i = 0; i < completed.
entries(); i++)
588 port = getTrackerPort();
589 getTrackerAddress(address);
600 exint slice = getSlice();
601 getSliceRoot(sliceroot);
639 exint msglen = 8 + 4;
641 for (
auto && prim : namedprims)
648 namelist.
append(
"unnamed");
650 namelist.
append(name_h.
get(prim->getMapOffset()));
667 exchangename.
sprintf(
"%s_verifyvdblist", (
const char *) jobname);
679 exint msgoff = 8 + 4;
681 for (
int i = 0; i < vdblist.
entries(); i++)
684 const char *
name = namelist(i);
694 msgoff +=
sizeof(
int32);
698 netxchg.sendData( 0, msg);
704 netxchg.receiveDataLoop(completed, (!slice ? (numslice-1) : 0) );
711 for (
int i = 0; i < completed.
entries(); i++)
721 if (numvdb != vdblist.
entries())
723 errormsg.
appendSprintf(
"Mismatch VDB count: Slice 0 has %d; but Slice %d has %d.\n", (
int) vdblist.
entries(), srcslice, numvdb);
728 exint msgoff = 8 + 4;
731 while (ok && curvdb < numvdb && msgoff < msg->
length())
735 while (msgoff < msg->
length())
743 msgoff +=
sizeof(
int32);
745 if (name.
strcmp(namelist(curvdb)))
749 errormsg.
appendSprintf(
"Mismatch VDB name. Vdb #%d has name %s in Slice 0 but %s in Slice %d.\n",
750 curvdb, (
const char *) namelist(curvdb),
753 if (type != typelist(curvdb))
756 errormsg.
appendSprintf(
"Mismatch VDB type. VDB #%d has type %d in Slice 0 but %d in Slice %d.\n",
757 curvdb, (
int) typelist(curvdb),
758 (
int) type, srcslice);
763 if (ok && (curvdb != numvdb))
766 errormsg.
appendSprintf(
"Malformed packet from slice %d; got %d vdbs but expected %d.\n", srcslice, curvdb, numvdb);
788 std::cerr <<
"Error: " << errormsg.
buffer() << std::endl;
792 exchangename.
sprintf(
"%s_reportvdblist", (
const char *) jobname);
797 for (
int dstslice = 1; dstslice < numslice; dstslice++)
806 const char *text = errormsg.
buffer();
815 netxchg.sendData(dstslice, msg);
822 netxchg.receiveDataLoop(completed, (slice ? 1 : 0) );
826 for (
int i = 0; i < completed.
entries(); i++)
833 while (msgoff < msg->
length())
860 for (
auto && vdb : vdblist)
862 exchangename.
sprintf(
"%s_%d", (
const char *) jobname, (
int)vdb->getMapIndex());
865 address, port, exchangename.
buffer(),
void filterConstSubData(SIM_ConstDataArray &dp, UT_StringArray *names, const SIM_DataFilter &filter, const char *startfrom, const SIM_DataFilter &recurseFilter) const
fpreal32 extractFloat32(exint offset)
SYS_FORCE_INLINE exint length() const
SYS_FORCE_INLINE UT_VDBType getStorageType() const
Get the storage type of the grid.
PRM_API const PRM_Type PRM_FLT
#define GAS_NAME_GEOMETRY
PRM_API const PRM_Type PRM_STRING
#define IMPLEMENT_DATAFACTORY(DataClass)
GridType
List of types that are currently supported by NanoVDB.
GT_API const UT_StringHolder time
static void setGasDescription(SIM_DopDescription &descr)
int32 extractInt32(exint offset)
GLsizei const GLfloat * value
SIM_GeometryCopy * getGeometryCopy(SIM_Object *obj, const char *name, bool silent=false)
GLdouble GLdouble GLdouble z
constexpr SYS_FORCE_INLINE T & z() noexcept
void overwriteInt32(exint offset, int32 val)
SYS_FORCE_INLINE bool isValid() const
SYS_FORCE_INLINE const HOLDER & get(GA_Offset off, int comp=0) const
Get the string at the given offset.
SYS_FORCE_INLINE const char * buffer() const
fpreal getVoxelDiameter() const
GLuint GLsizei GLsizei * length
void setWriteDataLength(exint bufsize)
static fpreal computeSliceDist(const SIM_SliceSearchList &list, const UT_Vector3 &pos)
fpreal64 extractFloat64(exint offset)
static bool doesIntersectSlice(const SIM_SliceSearchList &list, const UT_BoundingBox &bbox)
Returns true if the bounding box at all intersects the slice.
void overwriteInt8(exint offset, int8 val)
void overwriteFloat64(exint offset, fpreal64 val)
void GASnetvdbsliceexchangeApplyPacket(GU_PrimVDB *vdb, GAS_NetVDBSliceExchange *solver, SIM_Object *obj, UT_NetMessage *msg)
void setSize(exint newsize)
SYS_FORCE_INLINE void expandBounds(T relative, T absolute)
void initializeSIM(void *)
PRM_API const PRM_Type PRM_INT
#define UTvdbCallAllType(TYPE, FNAME, GRIDBASE,...)
int8 extractInt8(exint offset)
void GASnetvdbsliceexchangeBuildPacket(GU_PrimVDB *vdb, UT_Array< UT_NetMessage * > &msgs, GAS_NetVDBSliceExchange *solver, SIM_Object *obj, fpreal overlap, exint thisslice, const SIM_SliceSearchTable &slicetable)
bool receiveDataLoop(UT_Array< UT_NetMessage * > &completed, int expectedmessages, int timeoutms=100)
static PRM_SpareData unitsLength
#define GAS_NAME_TRACKERADDR
#define GAS_NAME_TRACKERPORT
void addError(const SIM_RootData *root, int errorcode, const char *errorparm, UT_ErrorSeverity severity) const
Adds an error to our SIM_Engine.
void overwriteInt64(exint offset, int64 val)
GLuint const GLchar * name
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
bool isInsideSlice(const UT_Vector3 &pos) const
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
exint entries() const
Alias of size(). size() is preferred.
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f)
Set the values of the vector components.
SYS_FORCE_INLINE int strcmp(const char *src) const
bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep) override
SYS_FORCE_INLINE bool isstring() const
void findAllPrimitivesByName(UT_Array< const GEO_Primitive * > &primlist, const char *nametomatch, const GA_PrimCompat::TypeMask &mask=GEO_PrimTypeCompat::GEOPRIMALL, const char *nameattrib="name") const
Like findPrimitiveByName, but adds all matching primitives to the list.
int int appendSprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
SYS_FORCE_INLINE void makeGridUnique()
If this primitive's grid's voxel data (i.e., its tree) is shared, replace the tree with a deep copy o...
This filter rejects all data.
void GASnetvdbsliceexchangeApplyPacketToVDB(GridType &grid, GAS_NetVDBSliceExchange *solver, SIM_Object *obj, UT_NetMessage *msg)
GEO_PrimVolumeXform getIndexSpaceTransform() const
void growWriteData(exint newlen)
SYS_FORCE_INLINE bool UTisstring(const char *s)
SYS_FORCE_INLINE void append(char character)
SYS_FORCE_INLINE void initBounds()
**But if you need a or simply need to know when the task has * completed
GAS_NetVDBSliceExchange(const SIM_DataFactory *factory)
void GASnetvdbsliceexchangeNetExchange(GAS_NetVDBSliceExchange *solver, SIM_Object *obj, GU_PrimVDB *vdb, const char *tracker, int port, const char *jobname, exint thisslice, const SIM_SliceSearchTable &slicetable)
~GAS_NetVDBSliceExchange() override
SYS_FORCE_INLINE void clear()
void buildSliceSearch(SIM_SliceSearchTable &table) const
SYS_FORCE_INLINE const openvdb::GridBase & getGrid() const
Return a reference to this primitive's grid.
int64 extractInt64(exint offset)
void GASnetvdbsliceexchangeBuildPacketGrid(GridType &grid, const GEO_PrimVolumeXform &indexxform, UT_Array< UT_NetMessage * > &msgs, GAS_NetVDBSliceExchange *solver, SIM_Object *obj, fpreal overlap, exint thisslice, const SIM_SliceSearchTable &slicetable)
constexpr SYS_FORCE_INLINE T & y() noexcept
PRM_API PRM_Default PRMzeroDefaults[]
void overwriteFloat32(exint offset, fpreal32 val)
void sendData(int destpeer, const char *data, exint len)
int16 extractInt16(exint offset)
constexpr SYS_FORCE_INLINE T & x() noexcept
This implements a SIM_Geometry that copies the source geometry.