[vtkusers] VTK6.0 label size problem of vtkScalarBarActor
chasank
chasank at gmail.com
Tue Jun 25 15:56:11 EDT 2013
It's not small enough but it will illustrate the problem;
int main(int argc, char **argv)
{
vtkSmartPointer< vtkImageData > imageData = vtkSmartPointer <
vtkImageData > :: New();
itk::Image< signed short, 3 > ImageType3D;
try
{
itk::ImageFileReader< ImageType3D >::Pointer reader =
itk::ImageFileReader< ImageType3D >::New();
itk::NiftiImageIO::Pointer niftiIO = itk::NiftiImageIO::New();
reader->SetFileName("C:\\niftis\\ch2better.nii.gz");
reader->SetImageIO(niftiIO);
reader->UpdateLargestPossibleRegion();
reader->Update();
itk::ImageToVTKImageFilter< ImageType3D >::Pointer connector =
itk::ImageToVTKImageFilter< ImageType3D >::New();
connector->SetInput(reader->GetOutput());
connector->Update();
imageData->DeepCopy(connector->GetOutput());
}
catch ( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
}
vtkSmartPointer< vtkLookupTable > table = vtkSmartPointer<
vtkLookupTable >::New();
table->SetNumberOfTableValues(256);
table->SetTableRange(range[0], range[1]);
table->SetRampToLinear();
table->SetScaleToLinear();
table->GlobalWarningDisplayOff();
table->Build();
LookupTableReader *lutReader = new
LookupTableReader("..\\luts\\grayscale");
unsigned char *r = lutReader->GetRed();
unsigned char *g = lutReader->GetGreen();
unsigned char *b = lutReader->GetBlue();
for (int i = 0; i <= 255; i++)
{
if ( i < 5 )
{
table->SetTableValue(i, *(r + i)/255.0, *(g + i)/255.0, *(b +
i)/255.0, 0.0);
}
else if ( i > 250)
{
table->SetTableValue(i, *(r + i)/255.0, *(g + i)/255.0, *(b +
i)/255.0, 1.0);
}
else
{
table->SetTableValue(i, *(r + i)/255.0, *(g + i)/255.0, *(b +
i)/255.0, i/255.0);
}
}
vtkSmartPointer< vtkScalarBarActor > colorBar = vtkSmartPointer<
vtkScalarBarActor >::New();
colorBar->SetMaximumNumberOfColors(256);
colorBar->SetLookupTable(table);
colorBar->SetHeight(0.12);
colorBar->SetWidth(0.90);
colorBar->SetPosition(0.04, 0.02);
colorBar->SetPosition2(0.90, 0.20);
colorBar->SetOrientationToHorizontal();
colorBar->SetNumberOfLabels(3);
colorBar->SetLabelFormat("%.4g");
colorBar->VisibilityOn();
vtkSmartPointer< vtkRenderer > renderer = vtkSmartPointer< vtkRenderer
>::New();
vtkSmartPointer< vtkRenderWindow > renderWindow = vtkSmartPointer<
vtkRenderWindow >::New();
vtkSmartPointer< vtkRenderWindowInteractor > iren = vtkSmartPointer<
vtkRenderWindowInteractor >::New();
vtkSmartPointer< vtkInteractorStyleImage > interactorStyle =
vtkSmartPointer< vtkInteractorStyleImage >::New();
double xViewRightVector[3] = {0, 1, 0};
double xViewUpVector[3] = {0, 0, 1};
double yViewRightVector[3] = {1, 0, 0};
double yViewUpVector[3] = {0, 0, 1};
double zViewRightVector[3] = { 1, 0, 0 };
double ZViewUpVector[3] = {0, 1, 0};
vtkSmartPointer< CallBack > callBack = vtkSmartPointer< CallBack
>::New();
interactorStyle->AddObserver(vtkCommand::MouseWheelForwardEvent,
callBack);
interactorStyle->AddObserver(vtkCommand::MouseWheelBackwardEvent,
callBack);
interactorStyle->AddObserver(vtkCommand::StartWindowLevelEvent,
callBack);
interactorStyle->AddObserver(vtkCommand::WindowLevelEvent, callBack);
interactorStyle->AddObserver(vtkCommand::ResetWindowLevelEvent,
callBack);
interactorStyle->SetInteractionModeToImage3D();
interactorStyle->SetXViewRightVector(xViewRightVector);
interactorStyle->SetXViewUpVector(xViewUpVector);
interactorStyle->SetYViewRightVector(yViewRightVector);
interactorStyle->SetYViewUpVector(yViewUpVector);
interactorStyle->SetZViewRightVector(zViewRightVector);
interactorStyle->SetZViewUpVector(ZViewUpVector);
interactorStyle->SetImageOrientation(xViewRightVector, xViewUpVector);
renderWindow->AddRenderer(renderer);
iren->SetInteractorStyle(interactorStyle);
iren->SetRenderWindow(renderWindow);
vtkSmartPointer< vtkImageResliceMapper > mapper = vtkSmartPointer<
vtkImageResliceMapper >::New();
mapper->SetInputDataObject(imageData);
mapper->SliceFacesCameraOn();
mapper->SliceAtFocalPointOn();
mapper->SetImageSampleFactor(2);
mapper->BorderOn();
double level = 0.5 * (range[0] + range[1]);
double window = range[1] - range[0];
vtkSmartPointer< vtkImageProperty > property = vtkSmartPointer<
vtkImageProperty >::New();
property->SetColorLevel(level);
property->SetColorWindow(window);
property->SetInterpolationTypeToLinear();
property->SetLookupTable(table);
property->SetAmbient(1.0);
property->SetDiffuse(1.0);
property->SetOpacity(1.0);
double *center = imageData->GetCenter();
vtkSmartPointer< vtkMatrix4x4 > matrix = vtkSmartPointer< vtkMatrix4x4
>::New();
matrix->Identity();
matrix->SetElement(0, 3, center[0]);
matrix->SetElement(1, 3, center[1]);
matrix->SetElement(2, 3, center[2]);
matrix->Modified();
vtkSmartPointer< vtkImageSlice > slice = vtkSmartPointer< vtkImageSlice
>::New();
slice->SetMapper(mapper);
slice->SetProperty(property);
slice->SetUserMatrix(matrix);
renderer->AddViewProp(slice);
renderer->AddActor2D(colorBar);
vtkSmartPointer< vtkCamera > camera = renderer->GetActiveCamera();
camera->ParallelProjectionOn();
camera->SetFocalPoint(0.0, 0.0, 0.0);
camera->SetPosition(1.0, 0.0, 0.0);
camera->SetViewUp(0.0, 0.0, 1.0);
renderer->ResetCamera();
iren->Initialize();
iren->Start();
renderWindow->Render();
return 0;
}
Sample output is below;
<http://vtk.1045678.n5.nabble.com/file/n5721597/colorBar_problem.png>
--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK6-0-label-size-problem-of-vtkScalarBarActor-tp5721585p5721597.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list