MCPcopy Create free account
hub / github.com/ImageEngine/cortex / referenceSplit

Method referenceSplit

test/IECoreScene/MeshAlgoSplitTest.py:145–254  ·  view source on GitHub ↗
( self, mesh, primVarName )

Source from the content-addressed store, hash-verified

143 # the algorithm to start with, it ensures that the results do not change, and that any optimizations which
144 # use indices do not affect the final result.
145 def referenceSplit( self, mesh, primVarName ):
146 faceCounts = []
147
148 remaps = {}
149 pvData = mesh[primVarName].expandedData()
150 for i in range( len( pvData ) ):
151 remaps.setdefault( str( pvData[i] ), (pvData[i], []) )[1].append( i )
152
153 # \todo Replace with itertools.accumulate once we're on Python 3
154 def accumulateInPython2( iterable ):
155 it = iter( iterable )
156 try:
157 total = next( it )
158 except StopIteration:
159 return
160 yield total
161 for element in it:
162 total += element
163 yield total
164
165 faceIndices = [0] + list( accumulateInPython2( mesh.verticesPerFace ) )[:-1]
166
167 result = []
168 for key, r in sorted( remaps.values() ):
169 reindex = {}
170 newVerticesPerFace = []
171 newVertIndices = []
172 mapFaceVert = []
173
174 usedIndices = set()
175 for i in r:
176 vpf = mesh.verticesPerFace[i]
177 newVerticesPerFace.append( vpf )
178 for j in range( vpf ):
179 origFaceVert = faceIndices[i] + j
180 origVert = mesh.vertexIds[ origFaceVert ]
181
182 usedIndices.add( origVert )
183
184 usedIndices = sorted( usedIndices )
185
186 for i in range( len( usedIndices ) ):
187 reindex[ usedIndices[i] ] = i
188
189 for i in r:
190 vpf = mesh.verticesPerFace[i]
191 for j in range( vpf ):
192 origFaceVert = faceIndices[i] + j
193 origVert = mesh.vertexIds[ origFaceVert ]
194
195 newIndex = usedIndices.index( origVert )
196 newVertIndices.append( newIndex )
197 mapFaceVert.append( origFaceVert )
198
199 rMesh = IECoreScene.MeshPrimitive(
200 IECore.IntVectorData( newVerticesPerFace ),
201 IECore.IntVectorData( newVertIndices ),
202 mesh.interpolation

Callers 2

Calls 15

setCornersMethod · 0.95
setCreasesMethod · 0.95
typeFunction · 0.85
expandedDataMethod · 0.80
appendMethod · 0.80
setdefaultMethod · 0.80
indexMethod · 0.80
cornerIdsMethod · 0.80
cornerSharpnessesMethod · 0.80
creaseLengthsMethod · 0.80
creaseSharpnessesMethod · 0.80
creaseIdsMethod · 0.80

Tested by

no test coverage detected