Skip to content

Commit 36cea4a

Browse files
committed
'imageWidth' and '..Height' formula functions
1 parent 00a3170 commit 36cea4a

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<display version="2.0.0">
33
<name>Image Widget</name>
4-
<width>1100</width>
5-
<height>1200</height>
4+
<width>1090</width>
5+
<height>1430</height>
66
<widget type="label" version="2.0.0">
77
<name>Label</name>
88
<class>TITLE</class>
@@ -322,11 +322,13 @@ For Channel Access, the waveform PV only provides pixels. The data width, height
322322

323323
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.
324324
The axis direction can be inverted by swapping the axis minimum and maximum limit.
325+
326+
To set an axis limit relative to the image pixel size, one can use rules or scripts that take inputs from formula PVs '=imageWidth(`pva://...Image`)' or '=imageHeight(`pva://...Image`)' and then write for example the 'x_axis.maximum' or 'y_axis.minimum' property of the widget.
325327
</text>
326-
<x>201</x>
328+
<x>200</x>
327329
<y>1150</y>
328-
<width>421</width>
329-
<height>209</height>
330+
<width>422</width>
331+
<height>280</height>
330332
</widget>
331333
<widget type="label" version="2.0.0">
332334
<name>Label_10</name>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Oak Ridge National Laboratory.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
******************************************************************************/
8+
package org.csstudio.apputil.formula.areadetector;
9+
10+
import org.epics.vtype.VImage;
11+
12+
/** A formula function for fetching height of VImage
13+
* @author Kay Kasemir
14+
*/
15+
public class ImageHeightFunction extends ImageWidthFunction
16+
{
17+
@Override
18+
public String getName()
19+
{
20+
return "imageHeight";
21+
}
22+
23+
@Override
24+
public String getDescription()
25+
{
26+
return "Fetch height of image";
27+
}
28+
29+
@Override
30+
protected int getImageInfo(final VImage image)
31+
{
32+
return image.getHeight();
33+
}
34+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Oak Ridge National Laboratory.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
******************************************************************************/
8+
package org.csstudio.apputil.formula.areadetector;
9+
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
import org.csstudio.apputil.formula.spi.FormulaFunction;
14+
import org.epics.vtype.Display;
15+
import org.epics.vtype.VImage;
16+
import org.epics.vtype.VInt;
17+
import org.epics.vtype.VType;
18+
19+
/** A formula function for fetching width of VImage
20+
* @author Kay Kasemir
21+
*/
22+
public class ImageWidthFunction implements FormulaFunction
23+
{
24+
@Override
25+
public String getCategory()
26+
{
27+
return "areaDetector";
28+
}
29+
30+
@Override
31+
public String getName()
32+
{
33+
return "imageWidth";
34+
}
35+
36+
@Override
37+
public String getDescription()
38+
{
39+
return "Fetch width of image";
40+
}
41+
42+
@Override
43+
public List<String> getArguments()
44+
{
45+
return List.of("image");
46+
}
47+
48+
/** Fetch info (width, height, ...) from image
49+
*
50+
* Subclass can override
51+
*
52+
* @param image Image
53+
* @return info
54+
*/
55+
protected int getImageInfo(final VImage image)
56+
{
57+
return image.getWidth();
58+
}
59+
60+
@Override
61+
public VType compute(final VType... args) throws Exception
62+
{
63+
if (args.length != 1 || ! (args[0] instanceof VImage))
64+
throw new Exception("Function " + getName() +
65+
" takes VImage but received " + Arrays.toString(args));
66+
67+
final VImage image = (VImage) args[0];
68+
return VInt.of(getImageInfo(image), image.getAlarm(), image.getTime(), Display.none());
69+
}
70+
}

core/formula/src/main/resources/META-INF/services/org.csstudio.apputil.formula.spi.FormulaFunction

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ org.csstudio.apputil.formula.math.Pow
2727
# Other functions
2828
org.csstudio.apputil.formula.demo.Factorial
2929
org.csstudio.apputil.formula.areadetector.ADDataTypeMappingFunction
30+
org.csstudio.apputil.formula.areadetector.ImageWidthFunction
31+
org.csstudio.apputil.formula.areadetector.ImageHeightFunction
3032

3133
# String
3234
org.csstudio.apputil.formula.string.StringFunction

0 commit comments

Comments
 (0)