How to deal with multitexture coordinates and OSPRay in ParaView 5.5


(Dave DeMarle) #1

Howdy,

In ParaView 5.5.0, the OSPRay interface doesn’t know what to do with the disparate texture coordinate arrays that the OBJ reader can produce. One trick to deal with this for the time being is to collapse all the texture coordinates into one.

A python programmable filter with the folllowing Script will do the collapsing, and in the process remove the original texture coordinate arrays.

pdi = self.GetInput()
pdo = self.GetOutput()
pdo.ShallowCopy(pdi)

arraynames = []
arrays = {}
for a in range(0,pdi.GetPointData().GetNumberOfArrays()):
  array = pdi.GetPointData().GetArray(a)
  if array.GetNumberOfComponents() != 2:
    # the assumption here is that all 2 component arrays are texture coordinates
    continue
  arrname = array.GetName()
  pdo.GetPointData().RemoveArray(arrname)
  arraynames.append(arrname)
  arrays[arrname] = array

tcoords = vtk.vtkFloatArray()
tcoords.SetName("TCoords")
tcoords.SetNumberOfComponents(2)
pdo.GetPointData().SetTCoords(tcoords)
# todo numpy this to make it 100x faster
for p in range(0, pdi.GetNumberOfPoints()):
  tcoord = [0,0]
  for arrname in arrays:
    candidate = arrays[arrname].GetTuple2(p)
    if candidate[0] == -1 and candidate[1] == -1:
      continue
    tcoord = candidate
  tcoords.InsertNextTuple2(tcoord[0],tcoord[1])

hth