Skip to content

Commit 00a3170

Browse files
committed
Image widget 'limits_from_pv'
1 parent ed63eb7 commit 00a3170

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/plots/ImageWidget.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2018 Oak Ridge National Laboratory.
2+
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
1313
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFile;
1414
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
1515
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propInteractive;
16+
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLimitsFromPV;
1617
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMaximum;
1718
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMinimum;
1819
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.runtimePropConfigure;
@@ -409,6 +410,7 @@ public boolean configureFromXML(final ModelReader model_reader, final Widget wid
409410
private volatile WidgetProperty<ColorMap> data_colormap;
410411
private volatile ColorBarProperty color_bar;
411412
private volatile AxisWidgetProperty x_axis, y_axis;
413+
private volatile WidgetProperty<Boolean> limits_from_pv;
412414
private volatile WidgetProperty<Integer> data_width, data_height;
413415
private volatile WidgetProperty<InterpolationType> data_interpolation;
414416
private volatile WidgetProperty<VImageType> data_color_mode;
@@ -440,6 +442,7 @@ protected void defineProperties(final List<WidgetProperty<?>> properties)
440442
properties.add(color_bar = new ColorBarProperty(this));
441443
properties.add(x_axis = new XAxisWidgetProperty(this));
442444
properties.add(y_axis = new YAxisWidgetProperty(this));
445+
properties.add(limits_from_pv = propLimitsFromPV.createProperty(this, false)); // 'true' would be preferred but breaks existing displays
443446
properties.add(data_width = propDataWidth.createProperty(this, 100));
444447
properties.add(data_height = propDataHeight.createProperty(this, 100));
445448
properties.add(data_interpolation = propInterpolationType.createProperty(this, InterpolationType.AUTOMATIC));
@@ -531,6 +534,12 @@ public AxisWidgetProperty propYAxis()
531534
return y_axis;
532535
}
533536

537+
/** @return 'limits_from_pv' property */
538+
public WidgetProperty<Boolean> propLimitsFromPV()
539+
{
540+
return limits_from_pv;
541+
}
542+
534543
/** @return 'data_width' property */
535544
public WidgetProperty<Integer> propDataWidth()
536545
{

app/display/model/src/main/resources/examples/plots_image.bob

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,33 +274,38 @@ the value range.</text>
274274
</rois>
275275
</widget>
276276
<widget type="label" version="2.0.0">
277-
<name>Label_8</name>
278-
<text>For PVAccess, a PV that serves an NTNDArray will provide
279-
both the image data and the width &amp; height information.
280-
(This is currently limited to byte[] data.
281-
For NTNDArray with short, int, etc., you need to read
282-
pva://that_pv/value to get just the data array,
283-
and configure the data width and height).
284-
285-
For PVAccess or Channel Access, the data can be a waveform
286-
that contains the pixels values starting with the top-left pixel,
287-
followed by the pixels of the top row, then the second row
288-
and so on.
277+
<class>SECTION</class>
278+
<text>PV, Data</text>
279+
<x>201</x>
280+
<y>891</y>
281+
<width>171</width>
282+
<font use_class="true">
283+
<font name="Default Bold" family="Liberation Sans" style="BOLD" size="14.0">
284+
</font>
285+
</font>
286+
<foreground_color use_class="true">
287+
<color name="Text" red="0" green="0" blue="0">
288+
</color>
289+
</foreground_color>
290+
<transparent use_class="true">true</transparent>
291+
</widget>
292+
<widget type="label" version="2.0.0">
293+
<text>The pixel data is an array that starts with the top-left pixel, followed by the pixels of the top row, then the second row and so on.
294+
295+
For PVAccess, a PV that serves an NTNDArray will provide not only the pixel data but also the width, height, signed/unsigned information and color mode.
289296

290-
The image data width and height need to be configured for
291-
waveform PVs.
292-
For NTNDArray PVs, the image size is provided by the PV.</text>
297+
For Channel Access, the waveform PV only provides pixels. The data width, height, signedness and color mode need to be configured via properties of the image widget.
298+
</text>
293299
<x>201</x>
294300
<y>921</y>
295301
<width>421</width>
296-
<height>279</height>
302+
<height>209</height>
297303
</widget>
298304
<widget type="label" version="2.0.0">
299-
<name>Label_9</name>
300305
<class>SECTION</class>
301-
<text>PV, Data</text>
306+
<text>Axes</text>
302307
<x>201</x>
303-
<y>891</y>
308+
<y>1130</y>
304309
<width>171</width>
305310
<font use_class="true">
306311
<font name="Default Bold" family="Liberation Sans" style="BOLD" size="14.0">
@@ -312,6 +317,17 @@ For NTNDArray PVs, the image size is provided by the PV.</text>
312317
</foreground_color>
313318
<transparent use_class="true">true</transparent>
314319
</widget>
320+
<widget type="label" version="2.0.0">
321+
<text>When the "Limits from PV" property of the widget is set, the X axis will range from 0 to the width of the image in pixels and the Y axis from 0 to the height. The origin will be placed in the top-left corner.
322+
323+
When "Limits from PV" is not set, the range of the X and Y axes can be configured independently from the image size. This allows for example a calibration of pixel positions in millimeters.
324+
The axis direction can be inverted by swapping the axis minimum and maximum limit.
325+
</text>
326+
<x>201</x>
327+
<y>1150</y>
328+
<width>421</width>
329+
<height>209</height>
330+
</widget>
315331
<widget type="label" version="2.0.0">
316332
<name>Label_10</name>
317333
<text>Region of Interest</text>

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/plots/ImageRepresentation.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -424,13 +424,19 @@ private void contentChanged(final WidgetProperty<?> property, final Object old_v
424424
{
425425
final VType value = model_widget.runtimePropValue().getValue();
426426
if (value instanceof VNumberArray)
427-
image_plot.setValue(model_widget.propDataWidth().getValue(),
428-
model_widget.propDataHeight().getValue(),
427+
{
428+
// Can't get size from PV, use data_width, .._height
429+
final int width = model_widget.propDataWidth().getValue();
430+
final int height = model_widget.propDataHeight().getValue();
431+
if (model_widget.propLimitsFromPV().getValue())
432+
image_plot.setAxisRange(0.0, width, height, 0.0);
433+
image_plot.setValue(width, height,
429434
((VNumberArray) value).getData(),
430435
model_widget.propDataUnsigned().getValue(),
431436
model_widget.propDataColorMode().getValue());
437+
}
432438
else if (value instanceof VImage)
433-
{
439+
{ // Use VImage metadata
434440
final VImage image = (VImage) value;
435441
boolean isUnsigned;
436442
switch (image.getDataType())
@@ -444,7 +450,12 @@ else if (value instanceof VImage)
444450
default:
445451
isUnsigned = false;
446452
}
447-
image_plot.setValue(image.getWidth(), image.getHeight(), image.getData(),
453+
454+
final int width = image.getWidth();
455+
final int height = image.getHeight();
456+
if (model_widget.propLimitsFromPV().getValue())
457+
image_plot.setAxisRange(0.0, width, height, 0.0);
458+
image_plot.setValue(width, height, image.getData(),
448459
isUnsigned, image.getVImageType());
449460
}
450461
else if (value != null)

0 commit comments

Comments
 (0)