[vtkusers] Size of labels in vtkScalarBarActor

Fernando Nellmeldin f.nellmeldin at open-engineering.com
Fri Oct 13 04:21:20 EDT 2017


Hello, thank you for your answer.
I tried what you said but I'm having difficulties implementing it. I'm
setting the values of the actor using vtkLookupTable but the scalar bar is
not displayed.
I followed the code and it fails
in vtkContext2DScalarBarActor::PaintColorBar because it fails the casting
of the LookupTable from vtkLookupTable to
vtkDiscretizableColorTransferFunction (and it is normal, as they are in
different parts of the inheritance tree).

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.
Second thing is that the range is wrong and the method
vtkScalarsToColors::SetTableRange is not available in
vtkDiscretizableColorTransferFunction. 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/
>> classvtkPVScalarBarActor.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()->SetCoordinateSystemToDisplay();
>> 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/1
B-4102 Seraing (Belgium)
Tel: +32.4.353.30.34

http://www.open-engineering.com
https://www.linkedin.com/company/open-engineering?trk=biz-companies-cym

*_________________________________________________________________________*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171013/27b4a487/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: differences_scalarbars.png
Type: image/png
Size: 17987 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171013/27b4a487/attachment.png>


More information about the vtkusers mailing list