70 #ifndef __GU_Insetter_h__
71 #define __GU_Insetter_h__
85 #define INSET_COPLANARITY_TOL 0.866
104 fpreal CoplanarityTolerance = 0.866;
158 bool two_sided =
true,
159 OffsetConversion off_conv = IDENTITY,
161 bool merge_branches =
true,
162 bool common_limit =
false);
167 int *is_limit =
nullptr);
169 int *is_limit =
nullptr);
181 fpreal getLimit(
bool positive =
true);
210 fpreal min_coplanar_nml_diff_cos
212 bool *is_folded_joint =
nullptr);
224 fpreal min_coplanar_nml_diff_cos,
243 OffsetConversion off_conv = IDENTITY,
245 bool merge_branches =
true,
246 bool common_limit =
true);
249 int *is_limit =
nullptr);
252 int *is_limit =
nullptr);
254 fpreal getMaxStopTime() {
return myLimitTime; }
260 explicit Edge() : mySrcIdx(-1), myDstIdx(-1) {}
261 explicit Edge(
int sidx,
int didx = -1) :
262 mySrcIdx(sidx), myDstIdx(didx) {}
268 {
return (mySrcIdx >= 0 && myDstIdx >= 0); }
271 {
return mySrcIdx == other.mySrcIdx &&
272 myDstIdx == other.myDstIdx; }
274 {
return mySrcIdx != other.mySrcIdx ||
275 myDstIdx != other.myDstIdx; }
282 static Edge InvalidEdge;
287 Edge right_edge = InvalidEdge) :
288 myLeftEdge(left_edge),
289 myRightEdge(right_edge),
317 int myIndex, myParentIdx;
318 Edge myLeftEdge, myRightEdge;
320 fpreal myStartTime, myStopTime;
328 explicit Node() : myIndex(-1) {}
330 int idx()
const {
return myIndex; }
332 {
return myIndex == other.myIndex; }
352 myType(RAY), myNode0(-1), myNode1(-1), myTime(-1)
356 myType(RAY), myNode0(n), myNode1(n), myTime(
t) {}
359 myType(type), myNode0(n0), myNode1(n1), myTime(t) {}
368 Node myNode0, myNode1;
392 void buildChain(
int chain_num);
395 bool is_leaf =
false);
397 Node newChainNode(
int chain,
Edge left_edge,
398 Edge right_edge,
bool is_leaf =
false);
400 bool hasParent(
Node n)
401 {
return (
myNodes(n.idx()).getParentIdx() >= 0); }
410 {
return dstJointPos(e) - srcJointPos(e); }
413 {
return myEdgeVel[e.srcIdx()]; }
416 {
return myNodes(n.idx()).leftEdge(); }
419 {
return myNodes(n.idx()).rightEdge(); }
422 {
return myJointLeaf(e.srcIdx()); }
425 {
return myJointLeaf(e.dstIdx()); }
429 {
return myNodes(n.idx()).getVelocity(); }
432 {
myNodes(n.idx()).setVelocity(v); }
436 {
return myNodes(n.idx()).getStartPos(); }
439 {
myNodes(n.idx()).setStartPos(p); }
443 {
return myNodes(n.idx()).getPosAtTime(t); }
446 {
return myNodes(n.idx()).getStartTime(); }
449 {
myNodes(n.idx()).setStartTime(t); }
452 {
return myNodes(n.idx()).getStopTime(); }
455 {
myNodes(n.idx()).setStopTime(t); }
458 {
return myNodes(n.idx()).getChainLimitTime(); }
460 inline void setChainLimitTime(
Node n,
fpreal t)
461 {
myNodes(n.idx()).setChainLimitTime(t); }
463 inline void setParent(
Node child,
Node parent)
464 {
myNodes(child.idx()).setParentIdx(parent.idx()); }
468 switch (myOffsetConv)
471 return myJointOffsets[idx];
472 case VERTEX_TO_POINT:
473 return myGdp->vertexPoint(myJointOffsets[idx]);
474 case VERTEX_TO_PRIMITIVE:
475 return myGdp->vertexPrimitive(myJointOffsets[idx]);
477 return myJointOffsets[idx];
482 inline int chainSize(
int i)
483 {
return myChainStarts(i + 1) - myChainStarts(i); }
485 inline bool isChainClosed(
int i)
486 {
return !myClosedFlags || myClosedFlags[i]; }
488 inline int jointIndex(
int chain_num,
int i);
493 {
return myPosHandle.get(jointOffset(e.srcIdx())); }
497 {
return myPosHandle.get(jointOffset(e.dstIdx())); }
504 inline Node srcLeaf(
int idx)
505 {
return myJointLeaf(idx); }
507 inline Node dstLeaf(
int idx)
508 {
return myJointLeaf(idx); }
523 NodeArray myJointLeaf;
532 OffsetConversion myOffsetConv;
536 bool myMergeBranches;
549 GU_Insetter::Tree::jointIndex(
int chain_num,
int i)
551 int n = chainSize(chain_num);
553 if (isChainClosed(chain_num))
554 return myChainStarts(chain_num) + ((i +
n) % n);
557 if (i < 0 || i > n - 1)
560 return myChainStarts(chain_num) + i;
567 fpreal min_coplanar_nml_diff_cos,
581 return dot(nn0, nn1) < min_coplanar_nml_diff_cos;
588 fpreal min_coplanar_nml_diff_cos,
589 bool *is_folded_joint)
607 if (
isFoldedJoint(v0, v1, b0, b1, min_coplanar_nml_diff_cos, &n0, &n1))
611 *is_folded_joint =
true;
618 vel = 0.5 * (b0 + b1);
626 fpreal denum = intersectLines<fpreal>(b0, m0, b1, m1, u0,
u1);
631 vel = 0.5 * (b0 + b1);
637 *is_folded_joint =
false;
656 edge_vect.
cross(prim_nml);
constexpr SYS_FORCE_INLINE T length2() const noexcept
NodeInfo(int idx=-1, Edge left_edge=InvalidEdge, Edge right_edge=InvalidEdge)
void setStartPos(UT_Vector3 s)
bool operator==(const Node &other)
bool operator==(const Edge &other)
Event(EventType type, Node n0, Node n1, fpreal t)
UT_Vector3 GUweightedBisector(const UT_Vector3 &v0, const UT_Vector3 &v1, fpreal w0, fpreal w1, const UT_Vector3 &cn)
bool operator()(Event e1, Event e2) const
bool operator!=(const Edge &other)
void setVelocity(UT_Vector3 e)
UT_Vector3 getStartPos() const
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
Edge(int sidx, int didx=-1)
GA_API const UT_StringHolder scale
constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T< T > &v) noexcept
UT_Vector3 getVelocity() const
Event(Node n, fpreal t=0.0)
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
void setParentIdx(int idx)
static bool isFoldedJoint(UT_Vector3 v0, UT_Vector3 v1, UT_Vector3 b0, UT_Vector3 b1, fpreal min_coplanar_nml_diff_cos, UT_Vector3 *n0=nullptr, UT_Vector3 *n1=nullptr)
fpreal getChainLimitTime() const
void setChainLimitTime(fpreal t)
static UT_Vector3 jointVelocity(UT_Vector3 v0, UT_Vector3 v1, UT_Vector3 b0, UT_Vector3 b1, fpreal min_coplanar_nml_diff_cos=INSET_COPLANARITY_TOL, bool *is_folded_joint=nullptr)
fpreal getStartTime() const
bool SYSequalZero(const UT_Vector3T< T > &v)
static UT_Vector3 edgeVelocity(UT_Vector3 edge_vect, UT_Vector3 prim_nml)
Helper methods for setting up an insetter:
void setStopTime(fpreal m)
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
#define INSET_COPLANARITY_TOL
Container class for all geometry.
fpreal getStopTime() const
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
void setStartTime(fpreal m)
fpreal GUweightedBisectingAngle(fpreal angle_sum, fpreal wt0, fpreal wt1)
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)