[vtkusers] Size of labels in vtkScalarBarActor

Fernando Nellmeldin f.nellmeldin at open-engineering.com
Tue Oct 17 04:44:42 EDT 2017


Thank you for your help, after playing a lot with the configuration of this
class, I managed to achieve what I wanted. Thank you very much.
I include my code for future reference.
Thanks a lot!

// NOTE: m_configuration is a struct with the configuration to use for the
scalar bar
vtkSmartPointer<vtkContext2DScalarBarActor> m_scalarBarActor =
vtkSmartPointer<vtkContext2DScalarBarActor>::New();

m_scalarBarActor->SetHeight(0.75);
m_scalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
m_scalarBarActor->GetPositionCoordinate()->SetValue(0.02, 0.1, 0.0);

m_scalarBarActor->DrawColorBarOn();
m_scalarBarActor->SetFixedAnnotationLeaderLineColor(true);
m_scalarBarActor->SetMaximumWidthInPixels(80);
m_scalarBarActor->AutomaticAnnotationsOff();
m_scalarBarActor->AutomaticLabelFormatOff();
m_scalarBarActor->SetAddRangeAnnotations(0);
m_scalarBarActor->AnnotationTextScalingOn();
m_scalarBarActor->UnconstrainedFontSizeOff();
m_scalarBarActor->SetScalarBarLength(0.8);
m_scalarBarActor->SetScalarBarThickness(30);
m_scalarBarActor->SetOrientationToVertical();

m_scalarBarActor->ForceHorizontalTitleOn();
m_scalarBarActor->SetTitleJustification(VTK_TEXT_LEFT);
vtkTextProperty* titleTextProperty =
m_scalarBarActor->GetTitleTextProperty();
vtkTextProperty* labelTextProperty =
m_scalarBarActor->GetLabelTextProperty();
labelTextProperty->SetColor(0.0,0.0,0.0);
labelTextProperty->BoldOff();
labelTextProperty->ItalicOff();
labelTextProperty->ShadowOn();
titleTextProperty->SetFontFamily(m_configuration.fontToUse); // 0 for
arial, 1 for courier, 2 for times
titleTextProperty->SetFontSize(m_configuration.sizeTitle);
labelTextProperty->SetFontFamily(m_configuration.fontToUse); // 0 for
arial, 1 for courier, 2 for times
labelTextProperty->SetFontSize(m_configuration.sizeLabels);

m_scalarBarActor->SetLabelFormat(m_configuration.numberFormat.c_str());
m_scalarBarActor->SetRangeLabelFormat(m_scalarBarActor->GetLabelFormat());
m_scalarBarActor->SetMaximumNumberOfColors(m_configuration.numOfColors);
m_scalarBarActor->SetNumberOfLabels(m_configuration.numOfLabels);

double rangeForTable[2];

rangeForTable[0] =
m_configuration.currentRange[m_configuration.componentToUse*2];
rangeForTable[1] =
m_configuration.currentRange[m_configuration.componentToUse*2+1];

// This is the LookupTable for vtkContext2DScalarBarActor
vtkSmartPointer<vtkDiscretizableColorTransferFunction> tempLUT =
vtkSmartPointer<vtkDiscretizableColorTransferFunction>::New();
tempLUT->SetColorSpaceToHSV();
tempLUT->SetHSVWrap(0);
tempLUT->AddHSVPoint(rangeForTable[0], m_configuration.rangeHue[0],
m_configuration.rangeSaturation[0], m_configuration.rangeValue[0]);
tempLUT->AddHSVPoint(rangeForTable[1], m_configuration.rangeHue[1],
m_configuration.rangeSaturation[1], m_configuration.rangeValue[1]);
tempLUT->SetNumberOfValues(m_configuration.numOfColors);
tempLUT->SetIndexedLookup(0);
tempLUT->SetScaleToLinear();
tempLUT->Build();

// This is the LookupTable for vtkActor that shows the result in the model.
vtkSmartPointer<vtkLookupTable> m_scalarBarLUT =
vtkSmartPointer<vtkLookupTable>::New();
m_scalarBarLUT->SetRampToLinear();
m_scalarBarLUT->SetTableRange(rangeForTable);
m_scalarBarLUT->SetNumberOfTableValues(m_configuration.numOfColors);
m_scalarBarLUT->SetUseAboveRangeColor(1);
m_scalarBarLUT->SetUseBelowRangeColor(1);
m_scalarBarLUT->SetBelowRangeColor(m_configuration.belowRangeColor);
m_scalarBarLUT->SetAboveRangeColor(m_configuration.aboveRangeColor);
// Copy the values from one table to the other
double deltaColor = rangeForTable[1] - rangeForTable[0];
for (int i = 0; i < m_configuration.numOfColors; ++i)
{
double colorRGBA[4] = {1.0, 0.0, 0.0, 1.0};
double currentColorStep = (double(i)/m_configuration.numOfColors);
double v = rangeForTable[0] + deltaColor*currentColorStep;
tempLUT->GetColor(v, colorRGBA);
m_scalarBarLUT->SetTableValue(i, colorRGBA);
}
m_scalarBarLUT->Build();

m_scalarBarActor->SetLookupTable(tempLUT);

// Mapper is the mapper of the vtkActor, defined in another place
m_mapper->SetScalarRange(rangeForTable);
m_mapper->SetLookupTable(m_scalarBarLUT);


On 13 October 2017 at 15:05, Cory Quammen <cory.quammen at kitware.com> wrote:

> [snip]
>
>> Then, I tried to define the LookupTable as vtkDiscretizableColorTransferFunction,
>> but I can't find the way to make it work.
>> First of all, I would like to define the first and last value, and map
>> between them using a given number of values (see call
>> SetNumberOfTableValues). In vtkLookupTable I do this by setting the HSV
>> range. I guess I could do the same calling vtkDiscretizableColorTransferFunction::AddHSVPoint().
>> But the colors in between are not correct.
>>
>
>
> By default the vtkDiscretizableColorTransferFunction interpolates colors
> through the RGB color space. To replicate what the vtkLookupTable does, you
> will need to call
>
> tempLUT->SetColorSpaceToHSV();
>
>
>> Second thing is that the range is wrong and the method
>> vtkScalarsToColors::SetTableRange is not available in
>> vtkDiscretizableColorTransferFunction.
>>
>
> tempLUT->SetRange(min, max); should do the trick.
>
> HTH,
> Cory
>
>
>> See in the screenshot how the values go from 0 to 1 instead of from 293
>> to 630...
>>
>> Here's the code of how I do it with vtkLookupTable:
>> vtkSmartPointer<vtkLookupTable> tempLUT = vtkSmartPointer<vtkLookupTable
>> >::New();
>> tempLUT->SetRampToLinear();
>> tempLUT->SetTableRange (rangeForTable);
>> tempLUT->SetNumberOfTableValues(m_configuration.numOfColors);
>> tempLUT->SetHueRange (m_configuration.rangeHue[0],
>> m_configuration.rangeHue[1]);
>> tempLUT->SetSaturationRange (m_configuration.rangeSaturation[0],
>> m_configuration.rangeSaturation[1]);
>> tempLUT->SetValueRange (m_configuration.rangeValue[0],
>> m_configuration.rangeValue[1]);
>> tempLUT->Build();
>>
>> Here's my code with vtkDiscretizableColorTransferFunction, which doesn't
>> work (see screenshot):
>> vtkSmartPointer<vtkDiscretizableColorTransferFunction> tempLUT =
>> vtkSmartPointer<vtkDiscretizableColorTransferFunction>::New();
>> tempLUT->AddHSVPoint(0, m_configuration.rangeHue[0],
>> m_configuration.rangeSaturation[0], m_configuration.rangeValue[0]);
>> tempLUT->AddHSVPoint(1, m_configuration.rangeHue[1],
>> m_configuration.rangeSaturation[1], m_configuration.rangeValue[1]);
>> tempLUT->SetNumberOfValues(m_configuration.numOfColors);
>> tempLUT->SetIndexedLookup(0);
>> tempLUT->Build();
>>
>> I attach a screenshot of the difference I get.
>>
>> Thank you!
>>
>> On 12 October 2017 at 15:37, Cory Quammen <cory.quammen at kitware.com>
>> wrote:
>>
>>> Fernando,
>>>
>>> Because you are using a scalar bar actor from ParaView, I suggest using
>>> the vtkContext2DScalarBarActor. Font sizes are fixed in this scalar bar
>>> actor implementation.
>>>
>>> HTH,
>>> Cory
>>>
>>> On Thu, Oct 12, 2017 at 9:33 AM, Fernando Nellmeldin <
>>> f.nellmeldin at open-engineering.com> wrote:
>>>
>>>> Hello.
>>>>
>>>> I know that this issue was discussed many times before in this list,
>>>> but I can't find a way to do what I want. I'm using VTK 7.1.1 (under
>>>> Windows). So maybe there were some improvements.
>>>>
>>>> In fact, I'm using vtkPVScalarBarActor which includes some very well
>>>> welcomed improvements, but the discussion should apply also to the normal
>>>> vtkScalarBarActor.
>>>> https://www.paraview.org/ParaView/Doc/Nightly/www/cxx-doc/cl
>>>> assvtkPVScalarBarActor.html
>>>>
>>>> The issue is that the size of the labels for values depends on the
>>>> viewport. So when the viewport changes the size, the labels also change
>>>> their size. Is it possible to avoid this? I would like to set the size of
>>>> the labels as constant or at least to define a maximum/minimum size,
>>>> because sometimes it gets veeeeery small/big and it is not very pleaseant.
>>>>
>>>> Thank you!
>>>>
>>>> PS:
>>>> Here's my code to configure the vtkPVScalarBarActor, in case it's
>>>> useful... (I guess there are some calls that are useless):
>>>>
>>>> vtkSmartPointer<vtkPVScalarBarActor> scalarBarActor =
>>>> vtkSmartPointer<vtkPVScalarBarActor>::New();
>>>> scalarBarActor->GetPositionCoordinate()->SetCoordinateSystem
>>>> ToDisplay();
>>>> scalarBarActor->GetPositionCoordinate()->SetValue(20, 20, 0.0);
>>>>
>>>> scalarBarActor->SetAddRangeAnnotations(0);
>>>> scalarBarActor->DrawTickMarksOff();
>>>> scalarBarActor->UnconstrainedFontSizeOff();
>>>> scalarBarActor->AnnotationTextScalingOn();
>>>> scalarBarActor->SetFixedAnnotationLeaderLineColor(true);
>>>>
>>>> scalarBarActor->SetOrientationToVertical();
>>>> //scalarBarActor->SetWidth(0.1); // width in viewport coordinates
>>>> scalarBarActor->SetMaximumWidthInPixels(80);
>>>> scalarBarActor->GetLabelTextProperty()->BoldOff();
>>>> scalarBarActor->GetLabelTextProperty()->ItalicOff();
>>>> scalarBarActor->GetLabelTextProperty()->ShadowOn();
>>>> scalarBarActor->AutomaticLabelFormatOff();
>>>> scalarBarActor->SetLabelFormat("%.2f");
>>>> scalarBarActor->SetRangeLabelFormat(scalarBarActor->GetLabelFormat());
>>>> scalarBarActor->SetMaximumNumberOfColors(100);
>>>> scalarBarActor->SetNumberOfLabels(5);
>>>>
>>>> scalarBarActor->SetLookupTable(tempLUT); // defined elsewhere, doesn't
>>>> matter
>>>>
>>>> scalarBarActor->SetTitle("Displacements");
>>>> scalarBarActor->SetTitleJustification(VTK_TEXT_RIGHT);
>>>> scalarBarActor->GetTitleTextProperty()->SetFontSize(8);
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>
>>>>
>>>
>>>
>>> --
>>> Cory Quammen
>>> Staff R&D Engineer
>>> Kitware, Inc.
>>>
>>
>>
>>
>> --
>> *Fernando NELLMELDIN*
>> Software Engineer
>> *_______________________________________________________________*
>>
>> *Open Engineering s.a.*
>>
>> Rue Bois Saint-Jean 15
>> <https://maps.google.com/?q=Rue+Bois+Saint-Jean+15&entry=gmail&source=g>
>> /1
>> B-4102 Seraing (Belgium)
>> Tel: +32.4.353.30.34 <+32%204%20353%2030%2034>
>>
>> http://www.open-engineering.com
>> https://www.linkedin.com/company/open-engineering?trk=biz-companies-cym
>>
>>
>> *_________________________________________________________________________*
>>
>
>
>
> --
> Cory Quammen
> Staff R&D Engineer
> Kitware, Inc.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171017/d246a304/attachment.html>


More information about the vtkusers mailing list