[vtkusers] a question about the vtkImageBlend and vtkImageMapToColors

zhang zhijun zjzhang at ee.cuhk.edu.hk
Thu May 30 12:59:43 EDT 2002


Dear All:
         I use the vtkGridSource to see the image deformation of every slice. I use the vtkImageMapToColors 
to change the vtkGridSource into the luminance and alpha image. but the output datatype of the vtkImageMapToColors
is VTK_UNSIGNED_CHAR, then there will be an mistake in the vtkImageBlend when I want to blend the grid 
with a vtkImageData which is with the VTK_SHORT type. When I run the program, there will be an error saying like 
this: ERROR: In d:\vtk4src\imaging\vtkimageblend.cxx, line 923
vtkImageBlend (02C5C4F0): Execute: input1 ScalarType (3), must match output ScalarType (4)
ERROR: In d:\vtk4src\imaging\vtkimageblend.cxx, line 923
vtkImageBlend (02C67D40): Execute: input1 ScalarType (3), must match output ScalarType (4)
ERROR: In d:\vtk4src\imaging\vtkimageblend.cxx, line 923
vtkImageBlend (02C6DF70): Execute: input1 ScalarType (3), must match output ScalarType (4)
I don't know whether there is solution for this? Here is the code segment I use:
// Add axial slice
 axialGrid=vtkImageGridSource::New();
 axialGrid->SetDataOrigin(-voxel_size_x*(width-1)/2,-voxel_size_y*(height-1)/2,-voxel_size_z*(depth-1)/2);
 axialGrid->SetGridSpacing(this->spacing,this->spacing,0);
 axialGrid->SetDataSpacing(voxel_size_x,voxel_size_y,voxel_size_z);
 axialGrid->SetDataExtent(0,width-1,0,height-1,0,depth-1);
 if (pDoc->rawData->GetScalarType()==VTK_SHORT)
     axialGrid->SetDataScalarTypeToShort();
 else if (pDoc->rawData->GetScalarType()==VTK_UNSIGNED_CHAR)
     axialGrid->SetDataScalarTypeToUnsignedChar();
 axialGrid->SetLineValue(1);
 vtkLookupTable *table1=vtkLookupTable::New();
 table1->SetTableRange(0,1);
 table1->SetAlphaRange(0.0,1.0);
 table1->Build();
 vtkImageMapToColors* alpha1=vtkImageMapToColors::New();
 alpha1->SetInput(axialGrid->GetOutput());
 alpha1->SetLookupTable(table1);
 alpha1->SetOutputFormatToLuminanceAlpha();
 axial_blend=vtkImageBlend::New();
 axial_blend->SetInput(0,pDoc->rawData);
 axial_blend->SetInput(1,alpha1->GetOutput());
 axial_blend->Update();
 axial_blend->SetOpacity(1,1.0);
 axial=vtkImageReslice::New();
 axial->SetInput(axial_blend->GetOutput());
 axial->SetResliceAxesOrigin(0,0,0);
 axial->SetOutputDimensionality(2);
 axial->SetOutputSpacing(1,1,voxel_size_z);
 axial->InterpolateOn();
 axial->SetResliceAxesDirectionCosines(1, 0, 0,0, 1, 0,0, 0, 1);
 vtkImageMapper *axial_mapper=vtkImageMapper::New();
 axial_mapper->SetInput(axial->GetOutput());
 if (pDoc->rawData->GetScalarType()==VTK_SHORT)
     axial_mapper->SetColorWindow(2000);
 else if (pDoc->rawData->GetScalarType()==VTK_UNSIGNED_CHAR)
     axial_mapper->SetColorWindow(255);
 axial_mapper->SetColorLevel(127.5);
 vtkActor2D *axial_actor=vtkActor2D::New();
 axial_actor->SetMapper(axial_mapper);
 axial_actor->SetPosition(interval,interval);
 this->Renderer->AddActor(axial_actor);



More information about the vtkusers mailing list