vtkImageData rendering issue


Issue


Hi,

I want to display a 2D image on my 3d view.
So, I’m trying to use vtkImageData.
However, when I apply scalar data and render the image data, there is no display.
How could I fix this?

thanks.


Source


// Set Data Set //
vtkImageData* dataCoronal = vtkImageData::New();
dataCoronal->SetDimensions(cxCoronalImage, 1, cyCoronalImage);
dataCoronal->SetOrigin(sx, fPosY, sz);
dataCoronal->SetSpacing(dx, 1, dx);
dataCoronal->AllocateScalars(VTK_SHORT, 1);


// Associate Data with Data Set //
vtkShortArray* scalarsCoronal = vtkShortArray::New();
scalarsCoronal->Allocate(cxCoronalImage*cyCoronalImage);
short* pBufferCoronal = scalarsCoronal->WritePointer(0,cxCoronalImage*cyCoronalImage);
short* pTempCoronal = pBufferCoronal;

int i,j;
float zPat;
for(j = cyCoronalImage-1; j >= 0; j--)
{
	zPat = (sz-ez)*j/(float)(cyCoronalImage-1) + ez;
	
	ASSERT(zPat>=sz && zPat<=ez);

	for(i = 0; i < cxCoronalImage; i++)
	{
		*pTempCoronal = m_pFullVolume->GetZOnlyLinearInterpolValue_XYIndex(i,nPos,zPat);
		pTempCoronal++;
	}
}
dataCoronal->GetPointData()->SetScalars(scalarsCoronal);

// Apply LUT //
vtkImageMapToColors* colorsCoronal = vtkImageMapToColors::New();
colorsCoronal->SetInputData(dataCoronal);
colorsCoronal->SetLookupTable(m_lut);

// Set Actor Parameters //
m_actorPlaneCoronal->SetInputData(colorsCoronal->GetOutput());
    // m_actorPlaneCoronal->SetInputData(dataCoronal);
m_actorPlaneCoronal->SetDisplayExtent(0,cxCoronalImage-1, 0,0, 0,cyCoronalImage-1);

And some error like this occurred with my test code,


ERROR: In D:\Libraries\VTK\VTK 9.0.1\VTK-9.0.1\Common\ExecutionModel\vtkStreamingDemandDrivenPipeline.cxx, line 878
vtkStreamingDemandDrivenPipeline (19681EA0): The update extent specified in the information for output port 0 on algorithm vtkTrivialProducer(169041C0) is 0 9 0 9 0 0, which is outside the whole extent 0 -1 0 -1 0 -1.

ERROR: In D:\Libraries\VTK\VTK 9.0.1\VTK-9.0.1\Common\ExecutionModel\vtkTrivialProducer.cxx, line 241
vtkTrivialProducer (169041C0): This data object does not contain the requested extent.


Test Code


vtkImageData* testImage = vtkImageData::New();
testImage->SetExtent(0, 9, 0, 9, 0, 9);
testImage->SetOrigin(0, 0, 0);
testImage->SetSpacing(1, 1, 1);
testImage->AllocateScalars(VTK_SHORT, 1);

vtkDataArray* newScalars = testImage->GetPointData()->GetScalars();

double numPts = 10 * 10 * 10;
for (int i = 0; i < numPts; i++)
{
	newScalars->SetComponent(i, 0, 1);
}

//unsigned short* VolPtr = (unsigned short*)testImage->GetScalarPointer();
//for (int i = 0; i < 100 * 100 * 100; i++)
//{
//	*VolPtr = 1;
//	*VolPtr++;
//}

vtkNew<vtkImageActor> testActor;
testActor->SetInputData(testImage);
testActor->SetDisplayExtent(0,9,0,9,0,9);
m_ren->AddActor(testActor);

In my Test Project, It works fine.

However, in my original project, there is no rendered object!

And got this error
“vtkTrivialProducer (00F15A08) : This data object does not contain the requested extent.”

1 Like