14 #ifndef __GEO_ParallelWiringUtil__
15 #define __GEO_ParallelWiringUtil__
26 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID
40 template<
typename INT_T>
41 class geo_SetTopoMappedParallel
45 const GA_Offset startfrom,
const INT_T *map)
46 : myTopology(topology)
48 , myStartFrom(startfrom)
52 template<
typename DEST_T>
64 GA_Offset to = myMap[off - myStartFrom] + myStartTo;
65 UT_ASSERT_P(
GAisValid(to) && to < myTopology->getDetail().getIndexMap(myTopology->getLinkOwner()).offsetSize());
66 topology.
set(off, DEST_T(to));
78 for (
GA_Offset off = start, to = (start - myStartFrom) + myStartTo; off <
end; ++off, ++to)
80 UT_ASSERT_P(
GAisValid(to) && to < myTopology->getDetail().getIndexMap(myTopology->getLinkOwner()).offsetSize());
81 topology.
set(off, DEST_T(to));
107 const INT_T *
const myMap;
118 template<
typename INT_T>
119 class geo_SetTopoRevMappedParallel
123 const GA_Offset startvtx,
const INT_T *vtx_to_pt_map)
125 : myPtToVtxTopology((
GA_PageArray<
void,1,true,true>&)(pt_to_vtx_topo->getData()))
127 , myStartVtx(startvtx)
128 , myVtxToPtMap(vtx_to_pt_map)
143 GA_Offset pt = myVtxToPtMap[off - myStartVtx] + myStartPt;
145 myPtToVtxTopology.set(pt,
int64(off));
155 const INT_T *
const myVtxToPtMap;
162 template<
typename INT_T>
163 class geo_TrivialArrayParallel
166 geo_TrivialArrayParallel(
UT_Array<INT_T> &array) : myArray(array.getArray()) {}
167 geo_TrivialArrayParallel(INT_T *array) : myArray(array) {}
171 for (
GA_Size i = r.begin(); i < r.end(); ++i)
176 INT_T *
const myArray;
183 template <
typename INT_T,
bool force_stable=true>
184 class geo_VerticesByPointCompare
187 geo_VerticesByPointCompare(
const INT_T *array) : myArray(array) {}
189 bool operator()(
const INT_T &
a,
const INT_T &
b)
const
197 return (myArray[a] < myArray[b])
198 || ((myArray[
a] == myArray[
b]) && (a < b));
200 return (myArray[a] < myArray[b]);
203 const INT_T *
const myArray;
211 template<
typename INT_T>
212 class geo_NextPrevParallel
215 geo_NextPrevParallel(
217 const exint order_size,
218 const INT_T *pointnumbers,
227 , myOrderSize(order_size)
228 , myPointNumbers(pointnumbers)
229 , myNextArray(nextarray)
230 , myPrevArray(prevarray)
231 , myStartVtx(startvtx)
235 , myUpdateExistingLock(lock)
246 INT_T pt = myPointNumbers[vtx];
251 for (; i < r.end(); ++i)
253 myPrevArray[vtx] = prev;
258 myNextArray[vtx] = next;
264 GA_Offset existingvtx = myPt2Vtx->getLink(pt + myStartPt);
274 myNextArray[vtx] = existingvtx - myStartVtx;
277 if (i+1 < myOrderSize)
280 vtx = myOrder[i + 1];
281 pt = myPointNumbers[vtx];
291 myPrevVtx->setLink(prevlinks(i).p0(), prevlinks(i).p1());
297 const exint myOrderSize;
298 const INT_T *
const myPointNumbers;
299 INT_T *
const myNextArray;
300 INT_T *
const myPrevArray;
313 template<
typename INT_T>
314 class geo_VertexVsPointCompare
317 geo_VertexVsPointCompare(
const INT_T *pointnumbers)
318 : myPointNumbers(pointnumbers)
321 bool operator()(
const INT_T &relativevtx,
const GA_Size &relativept)
const
322 {
return (myPointNumbers[relativevtx] < relativept); }
325 const INT_T *myPointNumbers;
330 template<
typename INT_T>
331 class geo_Pt2VtxTopoParallel
334 geo_Pt2VtxTopoParallel(
336 const INT_T *pointnumbers,
340 , myOrderSize(order_size)
341 , myPointNumbers(pointnumbers)
342 , myStartVtx(startvtx)
355 const INT_T *orderend = myOrder + myOrderSize;
357 if (myPointNumbers[orderend[-1]] <
GA_Size(start - myStartPt))
361 if (myPointNumbers[myOrder[0]] >=
GA_Size(end - myStartPt))
365 const INT_T *pvtx = std::lower_bound(myOrder, orderend,
GA_Size(start - myStartPt), geo_VertexVsPointCompare<INT_T>(myPointNumbers));
370 if (i == myPointNumbers[pvtx[0]] + myStartPt)
372 UT_ASSERT_P(
GAisValid(pvtx[0] + myStartVtx) && pvtx[0] + myStartVtx < myPt2Vtx->getDetail().getNumVertexOffsets());
373 myPt2Vtx->setLink(i, pvtx[0] + myStartVtx);
375 while (pvtx + 1 < orderend
376 && myPointNumbers[pvtx[0]] == myPointNumbers[pvtx[1]])
379 if (pvtx == orderend)
389 const exint myOrderSize;
390 const INT_T *
const myPointNumbers;
397 template<
typename INT_T>
398 class geo_LinkToposParallel
401 geo_LinkToposParallel(
403 const INT_T *nextarray,
404 const INT_T *prevarray,
408 , myNextArray(nextarray)
409 , myPrevArray(prevarray)
410 , myStartVtx(startvtx)
422 INT_T next = myNextArray[off - myStartVtx];
428 INT_T prev = myPrevArray[off - myStartVtx];
437 const INT_T *
const myNextArray;
438 const INT_T *
const myPrevArray;
446 class geo_UnlinkSingletonsParallel
457 UT_ASSERT(nextvtx && prevvtx && vtx2pt && pt2vtx);
460 geo_UnlinkSingletonsParallel(
const geo_UnlinkSingletonsParallel &that,
UT_Split)
461 : myNextVtx(that.myNextVtx)
462 , myPrevVtx(that.myPrevVtx)
463 , myVtx2Pt(that.myVtx2Pt)
464 , myPt2Vtx(that.myPt2Vtx)
481 GA_Offset ptoff = myVtx2Pt->getLink(off);
491 myNonSingletons.append(off);
497 void join(
const geo_UnlinkSingletonsParallel &that)
499 if (!that.myNonSingletons.entries())
501 if (!myNonSingletons.entries())
502 myNonSingletons = that.myNonSingletons;
504 myNonSingletons.append(that.myNonSingletons);
508 {
return myNonSingletons; }
521 class geo_PointRangeParallel
527 , myVertices(vertices)
534 geo_PointRangeParallel(
const geo_PointRangeParallel &that,
UT_Split)
535 : myVtx2Pt(that.myVtx2Pt)
536 , myVertices(that.myVertices)
548 GA_Offset minpoint = myVtx2Pt->getLink(myVertices(i));
550 for (++i; i < r.end(); ++i)
552 GA_Offset ptoff = myVtx2Pt->getLink(myVertices(i));
553 minpoint =
SYSmin(minpoint, ptoff);
554 maxpoint =
SYSmax(maxpoint, ptoff);
558 myMinPoint = minpoint;
559 myMaxPoint = maxpoint;
563 myMinPoint =
SYSmin(myMinPoint, minpoint);
564 myMaxPoint =
SYSmax(myMaxPoint, maxpoint);
568 void join(
const geo_PointRangeParallel &that)
572 myMinPoint = that.myMinPoint;
573 myMaxPoint = that.myMaxPoint;
577 myMinPoint =
SYSmin(myMinPoint, that.myMinPoint);
578 myMaxPoint =
SYSmax(myMaxPoint, that.myMaxPoint);
583 {
return myMinPoint; }
586 {
return myMaxPoint + 1; }
597 class geo_OffsetListToRelative
608 for (
GA_Size i = r.begin(); i < r.end(); ++i)
610 myOutput[i] =
int(
GA_Size(myInput(i) - myStart));
620 template<
typename INT_TYPE=
int>
621 class geo_QuadGridVertsParallel
624 geo_QuadGridVertsParallel(
GA_Size rows,
GA_Size cols, INT_TYPE *pointnums,
625 bool wrappedu=
false,
bool wrappedv=
false,
627 bool start_pole_row=
false,
bool end_pole_row=
false)
630 , myInterrupt(interrupt)
631 , myPointNums(pointnums)
632 , myStartPtNum(startptnum)
633 , myWrappedU(wrappedu)
634 , myWrappedV(wrappedv)
635 , myStartPole(start_pole_row)
636 , myEndPole(end_pole_row)
637 , myTriangularPoles(false)
641 void setupSphere(
bool triangular_poles)
const
647 myTriangularPoles = triangular_poles;
649 void setupTube()
const
656 void setupGrid()
const
663 void setupTorus()
const
677 GA_Size nquadcols = myCols - !myWrappedU;
679 int startrow;
int startcol;
680 SYSdivMod(r.begin(), nquadcols, startrow, startcol);
684 INT_TYPE pt = myStartPtNum;
685 if (myStartPole && startrow == 0)
688 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
690 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
696 myPointNums[i++] = pt;
697 if (!myTriangularPoles)
698 myPointNums[i++] = pt;
699 myPointNums[i++] = pt+1 + col + 1;
700 myPointNums[i++] = pt+1 + col;
702 if (myWrappedU && i < end)
704 myPointNums[i++] = pt;
705 if (!myTriangularPoles)
706 myPointNums[i++] = pt;
707 myPointNums[i++] = pt + 1;
708 myPointNums[i++] = pt + myCols;
716 pt += startrow*myCols + startcol;
721 if ((myWrappedV &&
row == myRows-1) || (!myWrappedV && myEndPole &&
row == myRows-2))
723 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
725 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
731 myPointNums[i++] = pt;
732 myPointNums[i++] = pt + 1;
733 myPointNums[i++] = pt + myCols + 1;
734 myPointNums[i++] = pt + myCols;
738 if (myWrappedU && i < end)
740 myPointNums[i++] = pt;
741 myPointNums[i++] = pt - myCols + 1;
742 myPointNums[i++] = pt + 1;
743 myPointNums[i++] = pt + myCols;
757 INT_TYPE endpolept = myWrappedV ? myStartPtNum : (pt+myCols);
758 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
760 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
763 myPointNums[i++] = pt;
764 myPointNums[i++] = pt + 1;
765 myPointNums[i++] = endpolept;
766 if (!myTriangularPoles)
767 myPointNums[i++] = endpolept;
771 if (myWrappedU && i < end)
773 myPointNums[i++] = pt;
774 myPointNums[i++] = pt - myCols + 1;
775 myPointNums[i++] = endpolept;
776 if (!myTriangularPoles)
777 myPointNums[i++] = endpolept;
783 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
785 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
788 myPointNums[i++] = pt;
789 myPointNums[i++] = pt + 1;
790 myPointNums[i++] = myStartPtNum + col + 1;
791 myPointNums[i++] = myStartPtNum + col;
795 if (myWrappedU && i < end)
797 myPointNums[i++] = pt;
798 myPointNums[i++] = pt - myCols + 1;
799 myPointNums[i++] = myStartPtNum;
800 myPointNums[i++] = myStartPtNum + myCols - 1;
808 INT_TYPE *
const myPointNums;
809 const INT_TYPE myStartPtNum;
810 const bool myWrappedU;
811 const bool myWrappedV;
812 const bool myStartPole;
813 const bool myEndPole;
814 const bool myTriangularPoles;
817 template<
typename INT_TYPE=
int>
818 class geo_TriGridVertsParallel
821 geo_TriGridVertsParallel(
823 bool wrappedu,
bool wrappedv,
826 bool start_pole_row=
false,
bool end_pole_row=
false)
829 , myPointNums(pointnums)
830 , myStartPtNum(startptnum)
832 , myWrappedU(wrappedu)
833 , myWrappedV(wrappedv)
834 , myInterrupt(interrupt)
835 , myStartPole(start_pole_row)
836 , myEndPole(end_pole_row)
837 , myTriangularPoles(false)
848 GA_Size nquadcols = myCols - !myWrappedU;
850 int startrow;
int startcol;
851 SYSdivMod(r.begin(), nquadcols, startrow, startcol);
854 INT_TYPE pt = myStartPtNum + startrow*myCols + startcol;
855 for (
int row = startrow; i <
end; ++
row)
857 if (myWrappedV && row == myRows-1)
859 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
861 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
868 bool switched = (rev || (alt && ((row^col)&1)));
870 myPointNums[i++] = pt;
871 myPointNums[i++] = pt + 1;
872 myPointNums[i++] = pt + myCols +
int(!switched);
874 myPointNums[i++] = pt +
int(switched);
875 myPointNums[i++] = pt + myCols + 1;
876 myPointNums[i++] = pt + myCols;
880 if (myWrappedU && i < end)
883 bool switched = (rev || (alt && ((row^(myCols-1))&1)));
885 myPointNums[i++] = pt;
886 myPointNums[i++] = pt - myCols + 1;
887 myPointNums[i++] = pt + (switched ? myCols : 1);
889 myPointNums[i++] = pt + (switched ? (-myCols + 1) : 0);
890 myPointNums[i++] = pt + 1;
891 myPointNums[i++] = pt + myCols;
903 for (
int col = startcol; col < myCols-1 && i <
end; ++col)
905 if (interrupt && !bcnt++ && interrupt->
opInterrupt())
909 bool switched = (rev || (alt && (((myRows-1)^col)&1)));
911 myPointNums[i++] = pt;
912 myPointNums[i++] = pt + 1;
913 myPointNums[i++] = myStartPtNum + col +
int(!switched);
915 myPointNums[i++] = pt +
int(switched);
916 myPointNums[i++] = myStartPtNum + col + 1;
917 myPointNums[i++] = myStartPtNum + col;
921 if (myWrappedU && i < end)
924 bool switched = (rev || (alt && (((myRows-1)^(myCols-1))&1)));
926 myPointNums[i++] = pt;
927 myPointNums[i++] = pt - myCols + 1;
928 myPointNums[i++] = myStartPtNum + (switched ? (myCols-1) : 0);
930 myPointNums[i++] = pt + (switched ? (-myCols + 1) : 0);
931 myPointNums[i++] = myStartPtNum + 0;
932 myPointNums[i++] = myStartPtNum + myCols-1;
940 INT_TYPE *
const myPointNums;
941 const INT_TYPE myStartPtNum;
943 const bool myWrappedU;
944 const bool myWrappedV;
945 const bool myStartPole;
946 const bool myEndPole;
947 const bool myTriangularPoles;
950 template<
typename INT_TYPE=
int>
951 class geo_CurveGridVertsParallel
954 geo_CurveGridVertsParallel(
GA_Size rows,
GA_Size cols, INT_TYPE *pointnums,
957 bool start_pole_row=
false,
bool end_pole_row=
false)
960 , myInterrupt(interrupt)
961 , myPointNums(pointnums)
962 , myStartPtNum(startptnum)
964 , myUnrollCurves(unrollcurves)
965 , myStartPole(start_pole_row)
966 , myEndPole(end_pole_row)
973 const bool unrollcurves = myUnrollCurves;
976 INT_TYPE *pointnums = myPointNums + r.begin();
980 GA_Size startrow = r.begin()/ncols;
981 const GA_Size startcol = r.begin()%ncols;
982 const GA_Size endrow = r.end()/ncols;
983 const GA_Size endcol = r.end()%ncols;
984 INT_TYPE
v = myStartPtNum + r.begin();
985 if (startrow == endrow)
987 for (
GA_Size col = startcol; col < endcol; ++col, ++
v, ++pointnums)
994 for (
GA_Size col = startcol; col < ncols; ++col, ++
v, ++pointnums)
999 *pointnums = v-ncols;
1005 for (
GA_Size row = startrow; row < endrow; ++
row)
1007 for (
GA_Size col = 0; col < ncols; ++col, ++
v, ++pointnums)
1012 *pointnums = v-ncols;
1017 for (
GA_Size col = 0; col < endcol; ++col, ++
v, ++pointnums)
1024 const GA_Size nmeshpoints = nrows*ncols;
1025 GA_Size startcol = r.begin()/nrows;
1026 const GA_Size startrow = r.begin()%nrows;
1027 const GA_Size endcol = r.end()/nrows;
1028 const GA_Size endrow = r.end()%nrows;
1031 INT_TYPE v = myStartPtNum + startrow*ncols + startcol;
1032 if (startcol == endcol)
1034 for (
GA_Size row = startrow; row < endrow; ++
row, v += ncols, ++pointnums)
1041 for (
GA_Size row = startrow; row < nrows; ++
row, v += ncols, ++pointnums)
1046 *pointnums = v-nmeshpoints;
1050 v -= (nmeshpoints-1);
1053 for (
GA_Size col = startcol; col < endcol; ++col, v -= (nmeshpoints-1))
1055 for (
GA_Size row = 0; row < nrows; ++
row, v += ncols, ++pointnums)
1060 *pointnums = v-nmeshpoints;
1065 for (
GA_Size row = 0; row < endrow; ++
row, v += ncols, ++pointnums)
1074 INT_TYPE *
const myPointNums;
1075 const INT_TYPE myStartPtNum;
1077 const bool myUnrollCurves;
1078 const bool myStartPole;
1079 const bool myEndPole;
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
Iteration over a range of elements.
bool blockAdvance(GA_Offset &start, GA_Offset &end)
GLboolean GLboolean GLboolean GLboolean a
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_EdgeT< GA_Offset, false > GA_Edge
SYS_FORCE_INLINE void set(GA_Offseti, SRC_DATA_T v)
component == 0 in this version
SYS_FORCE_INLINE bool GAisValid(GA_Size v)
exint GA_Size
Defines the bit width for index and offset types in GA.
#define GA_INVALID_OFFSET
A range of elements in an index-map.
GA_AttributeOwner getLinkOwner() const
int opInterrupt(int percent=-1)
GA_Iterator begin() const
GT_API const UT_StringHolder topology
GLdouble GLdouble GLint GLint order
GLboolean GLboolean GLboolean b
exint entries() const
Alias of size(). size() is preferred.
SYS_FORCE_INLINE GA_AttributeOwner getOwner() const
GLenum GLenum GLsizei void * row