[vtkusers] VTK6 migration and vtkImageData: "No scalar values found for texture input!" error in vtkOpenGLTexture

Sebastian Ordas sebastian.ordas at gmail.com
Tue Sep 30 17:02:22 EDT 2014


Hi Cory,

I set up an example code, but I could not reproduce the error :-(
The example is attached anyway, in case someone wants to have a look at it

I will keep searching the source of the error in my application and will 
come back to the list with any finding

thank you!
sebastian

On 29/09/2014 12:32 p.m., Cory Quammen wrote:
> Sebastian,
>
> Could you post a small, working example program that demonstrates the problem?
>
> Thank you,
> Cory
>
> On Mon, Sep 29, 2014 at 11:25 AM, Sebastian Ordas
> <sebastian.ordas at gmail.com> wrote:
>> Dear List,
>>
>> (I just realized I sent my message to ITK list instead of VTK!)
>>
>> I have started getting the error "No scalar values found for texture input!"
>> coming from vtkOpenGLTexture, while porting my code to VTK6
>>
>> More precisely, I have a vtkImageData, generated by
>> itkImageToVTKImageFilter, which is mapped through vtkImageResliceMapper
>>
>> I have tried adding the following to itkImageToVTKImageFilter:
>>
>>    m_Importer->UpdateInformation();
>>    vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
>>          m_Importer->GetOutputInformation(0 /*port number*/),
>>          0 /*piece*/,
>>          2 /*number of pieces*/,
>>          0 /*number of ghost levels*/);
>>    m_Importer->Update();
>>
>> .. but no luck!
>>
>> I have also tried:
>>
>> m_ImageData->GetPointData()->SetActiveAttribute (0, vtkPointData::SCALARS);
>>
>> didn´t work either...
>>
>> Any hint?
>>
>> thank you,
>> sebastian
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>

-------------- next part --------------
PROJECT (ImageReslice)

IF(NOT ITKWikiExamples_BINARY_DIR)
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
ENDIF(NOT ITKWikiExamples_BINARY_DIR)

#FIND_PACKAGE(VTK REQUIRED)
FIND_PACKAGE( VTK REQUIRED vtkRenderingImage vtkRenderingFreeType vtkRenderingFreeTypeOpenGL NO_MODULE)
INCLUDE(${VTK_USE_FILE})

#
# Build all .cxx files in the directory
FILE(GLOB ALL_FILES *.cxx)

include(${ITKWikiExamples_SOURCE_DIR}/CMake/RequiresVersion.cmake)
set(VERSION_MIN "4.0")
#Requires_Version(TransformFileWriter 4.0 ALL_FILES)

foreach(SOURCE_FILE ${ALL_FILES})
  STRING(REPLACE ".cxx" "" TMP ${SOURCE_FILE})
  STRING(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/ "" EXAMPLE ${TMP})
  ADD_EXECUTABLE(${EXAMPLE} MACOSX_BUNDLE ${EXAMPLE}.cxx)
  TARGET_LINK_LIBRARIES(${EXAMPLE} ${ItkVtkGlue} ${ITK_LIBRARIES} ${VTK_LIBRARIES})
endforeach(SOURCE_FILE)
-------------- next part --------------
#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageToVTKImageFilter.h"

#include <vtkSmartPointer.h>
#include <vtkImageProperty.h>
#include <vtkImageSlice.h>
#include <vtkImageInterpolator.h>
#include <vtkPlaneSource.h>
#include <vtkPlane.h>
#include <vtkImageResliceMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkCamera.h>

int main( int argc, char * argv[] )
{
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
    }

  typedef itk::Image< short, 3 >                 ImageType;
  typedef itk::ImageFileReader<ImageType>        ReaderType;
  typedef itk::ImageToVTKImageFilter<ImageType>  ConnectorType;

  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(argv[1]);
  
  // convert ITK image to VTK image
  ConnectorType::Pointer connector = ConnectorType::New();
  connector->SetInput( reader->GetOutput() );

  try
  {
    connector->Update();
  }
  catch( itk::ExceptionObject & err )
  {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
  }  

  vtkSmartPointer<vtkImageData> imageData = connector->GetOutput();
  
  // Setting of vtkImageInterpolator
  vtkSmartPointer<vtkImageInterpolator> imageInterpolator = vtkSmartPointer<vtkImageInterpolator>::New();
  imageInterpolator->SetInterpolationModeToLinear();

  vtkSmartPointer<vtkPlane> sliceplane = vtkSmartPointer<vtkPlane>::New();
  sliceplane->SetOrigin(imageData->GetCenter());
  sliceplane->SetNormal(1.0,0.0,0.0);

  // Setting of vtkImageResliceMapper
	vtkSmartPointer<vtkImageResliceMapper> imageResliceMapper = vtkSmartPointer<vtkImageResliceMapper>::New();
  imageResliceMapper->SetInputData(imageData);
  imageResliceMapper->SetSlicePlane(sliceplane);
  imageResliceMapper->SetInterpolator(imageInterpolator);
  imageResliceMapper->SetSliceFacesCamera(1);

  // Setting of vtkImageProperty
	vtkSmartPointer<vtkImageProperty> imageProperty = vtkSmartPointer<vtkImageProperty>::New();	
	imageProperty->SetAmbient(1.0);
  imageProperty->SetBacking(1.0);
  imageProperty->SetBackingColor(1.0,0.0,0.0);
	imageProperty->SetOpacity(1.0);
	imageProperty->SetInterpolationTypeToLinear();

  // Setting of vtkImageSlice
  vtkSmartPointer<vtkImageSlice> imageSlice = vtkSmartPointer<vtkImageSlice>::New();
	imageSlice->SetMapper(imageResliceMapper);
	imageSlice->SetProperty(imageProperty);

  double level;
  double window;
  
  double range[2];
  imageData->GetScalarRange(range);

  window = range[1] - range[0];
  level = 0.5*(range[0] + range[1]);
  
  if( fabs( window ) < 0.001 )
    {
    window = 0.001 * ( window < 0.0 ? -1 : 1 );
    }

  if( fabs( level ) < 0.001 )
    {
    level = 0.001 * ( level < 0.0 ? -1 : 1 );
    }

  imageProperty->SetColorWindow(window);
	imageProperty->SetColorLevel(level); 

  // Create renderers and add actors
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddViewProp(imageSlice);
  
  // Add renderer to renderwindow and render
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  renderWindow->SetSize(600, 600);
  
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);

  // Set the interactor style
  vtkSmartPointer<vtkInteractorStyleImage> style =
    vtkSmartPointer<vtkInteractorStyleImage>::New();
  
  interactor->SetInteractorStyle(style);

  renderer->SetBackground(.2, .3, .4);
 
  renderer->ResetCamera();
  renderWindow->Render();

  interactor->Start();
  
  return EXIT_SUCCESS;
 }


More information about the vtkusers mailing list