vtkImageData: No scalar field has been specified-assuming 1 component

I am using vmtk to obtain cpr image. But vtkImageData reported a bug.

My code is:


curvedMPRImageFilter = vtkvmtk.vtkvmtkCurvedMPRImageFilter()
curvedMPRImageFilter.SetInputData(vtkImg)
curvedMPRImageFilter.SetCenterline(centerline)
curvedMPRImageFilter.SetParallelTransportNormalsArrayName('ParallelTransportNormals')
curvedMPRImageFilter.SetFrenetTangentArrayName('FSTangents')
curvedMPRImageFilter.SetInplaneOutputSpacing(1, 1)
curvedMPRImageFilter.SetInplaneOutputSize(300, 300)
curvedMPRImageFilter.SetReslicingBackgroundLevel(0)
curvedMPRImageFilter.Update()

A bug is reported for curvedMPRImageFilter.Update():

vtkImageData: No Scalar Field has been specified - assuming 1 component!

The vtkImg is converted from numpy data:

def numpyToVTK(data, multi_component=False, type='float'):

    flat_data_array = data.transpose(2,1,0).flatten()
    vtk_data = numpy_to_vtk(num_array=flat_data_array, deep=True, array_type=vtk.VTK_FLOAT)
    shape = data.shape

    img = vtk.vtkImageData()
    img.GetPointData().SetScalars(vtk_data)
    img.SetDimensions(shape[0], shape[1], shape[2])
    return img

I can not find a solution for this bug. Any suggestion is appreciated~~

Hello,

What is displayed when you run the following?

print(vtkImg.GetPointData())

The displayed information is:


Connected to pydev debugger (build 193.6911.25)
vtkPointData (0000026EFE343780)
  Debug: Off
  Modified Time: 2290
  Reference Count: 2
  Registered Events: 
    Registered Observers:
      vtkObserver (0000026E80B403E0)
        Event: 33
        EventName: ModifiedEvent
        Command: 0000026E80BC2CB0
        Priority: 0
        Tag: 1
  Number Of Arrays: 1
  Array 0 name = nullptr
  Number Of Components: 1
  Number Of Tuples: 52953088
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
  Scalars: 
    Debug: Off
    Modified Time: 2278
    Reference Count: 1
    Registered Events: (none)
    Name: (none)
    Data type: float
    Size: 52953088
    MaxId: 52953087
    NumberOfComponents: 1
    Information: 0000000000000000
    Name: (none)
    Number Of Components: 1
    Number Of Tuples: 52953088
    Size: 52953088
    MaxId: 52953087
    LookupTable: (none)
  Vectors: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
  EdgeFlag: (none)


Hello,

If you use the SetActiveScalars function in the numpyToVTK to set the active scalars, will it still solve the problem?

def numpyToVTK(data, multi_component=False, type='float'):

    flat_data_array = data.transpose(2,1,0).flatten()
    vtk_data = numpy_to_vtk(num_array=flat_data_array, deep=True, array_type=vtk.VTK_FLOAT)
    vtk_data.SetName('foo')
    shape = data.shape

    img = vtk.vtkImageData()
    img.GetPointData().SetScalars(vtk_data)
    img.GetPointData().SetActiveScalars('foo')
    img.SetDimensions(shape[0], shape[1], shape[2])
    return img

Sorry, but the bug is still reported. The complete code to reproduce this bug is:

import numpy as np
from vmtk import vtkvmtk
import vtk
from vtk.util.numpy_support import vtk_to_numpy, numpy_to_vtk

def numpyToVTKpoint(line):

    centerline = vtk.vtkPolyData()
    points = vtk.vtkPoints()
    lineCell = vtk.vtkCellArray()

    centerline.SetPoints(points)
    centerline.SetLines(lineCell)

    # centerline.GetPoints().SetNumberOfPoints(2)
    # centerline.GetLines().Reset()
    # ptIds = [0, 1]
    # centerline.GetLines().InsertNextCell(2, ptIds)

    ptIds = np.arange(line.shape[0]).tolist()
    centerline.GetPoints().SetNumberOfPoints(line.shape[0])
    centerline.GetLines().Reset()
    centerline.GetLines().InsertNextCell(len(ptIds), ptIds)
    for i in range(line.shape[0]):
        centerline.GetPoints().SetPoint(i, line[i, :])

    fsTangents = vtk.vtkDoubleArray()
    fsTangents.SetName('FSTangents')
    fsTangents.SetNumberOfTuples(1)
    fsTangents.InsertNextValue(1.0)
    fsTangents.InsertNextValue(1.0)
    fsTangents.InsertNextValue(1.0)
    centerline.GetPointData().AddArray(fsTangents)
    centerline.Modified()

    parallelTransportNormals = vtk.vtkDoubleArray()
    parallelTransportNormals.SetName("ParallelTransportNormals")
    parallelTransportNormals.SetNumberOfTuples(1)
    parallelTransportNormals.InsertNextValue(1.0)
    parallelTransportNormals.InsertNextValue(1.0)
    parallelTransportNormals.InsertNextValue(1.0)
    centerline.GetPointData().AddArray(parallelTransportNormals)
    centerline.Modified()

    return centerline

def numpyToVTK(data):

    flat_data_array = data.transpose(2,1,0).flatten()
    vtk_data = numpy_to_vtk(num_array=flat_data_array, deep=True, array_type=vtk.VTK_FLOAT)
    vtk_data.SetName('foo')
    shape = data.shape

    img = vtk.vtkImageData()
    img.GetPointData().SetScalars(vtk_data)
    img.GetPointData().SetActiveScalars('foo')
    img.SetDimensions(shape[0], shape[1], shape[2])
    return img

def vtkToNumpy(data):
    temp = vtk_to_numpy(data.GetPointData().GetScalars())
    dims = data.GetDimensions()

    numpy_data = temp.reshape(dims[2], dims[1], dims[0])
    numpy_data = numpy_data.transpose(2,1,0)

    return numpy_data

image = np.zeros([256, 256, 256])
image[64:192, 64:192, :] = 1

x = np.ones(shape=[128])*128
y = np.ones(shape=[128])*128
z = np.arange(0, 128)+64
point = np.array([x, y, z]).T

centerline = numpyToVTKpoint(point)
vtkImg = numpyToVTK(image)

curvedMPRImageFilter = vtkvmtk.vtkvmtkCurvedMPRImageFilter()
curvedMPRImageFilter.SetInputData(vtkImg)
curvedMPRImageFilter.SetCenterline(centerline)
curvedMPRImageFilter.SetParallelTransportNormalsArrayName('ParallelTransportNormals')
curvedMPRImageFilter.SetFrenetTangentArrayName('FSTangents')
curvedMPRImageFilter.SetInplaneOutputSpacing(1, 1)
curvedMPRImageFilter.SetInplaneOutputSize(300, 300)
curvedMPRImageFilter.SetReslicingBackgroundLevel(0)
curvedMPRImageFilter.Update()
cprImg = curvedMPRImageFilter.GetOutput()
cprImg = vtkToNumpy(cprImg)

Hello,

This appears to be a bug in vmtk that was fixed on November 13, 2018.

However, it is not reflected in the latest release version 1.4.0 (March 20, 2018).

Are you using version 1.4.0?

Yes, my vmtk version is 1.4.0. Because I can only download 1.4.0 vmtk. There is on other version unless I compile the vmtk from the source code.

Hello, may I ask if your problem has been resolved?

“ERROR: In …/Common/DataModel/vtkImageData.cxx, line 1324
vtkImageData (0x2110c60): No Scalar Field has been specified - assuming 1 component!”

I also encountered this error when performing surface reconstruction on coronary arteries, which has been bothering me for a long time. Looking forward to your reply. Thank you very much