Skip to content

Commit b1506fd

Browse files
committed
Formula: Add imageValue(image)
1 parent c924d75 commit b1506fd

File tree

3 files changed

+70
-25
lines changed

3 files changed

+70
-25
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.VNumberArray;
17+
import org.epics.vtype.VType;
18+
19+
/** A formula function for fetching VImage array data
20+
* @author Kay Kasemir
21+
*/
22+
public class ImageValueFunction implements FormulaFunction
23+
{
24+
@Override
25+
public String getCategory()
26+
{
27+
return "areaDetector";
28+
}
29+
30+
@Override
31+
public String getName()
32+
{
33+
return "imageValue";
34+
}
35+
36+
@Override
37+
public String getDescription()
38+
{
39+
return "Fetch array data of image";
40+
}
41+
42+
@Override
43+
public List<String> getArguments()
44+
{
45+
return List.of("image");
46+
}
47+
48+
/** Fetch info from image
49+
* @param image Image
50+
* @return VType to return from function
51+
*/
52+
protected VType getImageData(final VImage image)
53+
{
54+
return VNumberArray.of(image.getData(), image.getAlarm(), image.getTime(), Display.none());
55+
}
56+
57+
@Override
58+
public VType compute(final VType... args) throws Exception
59+
{
60+
if (args.length != 1 || ! (args[0] instanceof VImage))
61+
throw new Exception("Function " + getName() +
62+
" takes VImage but received " + Arrays.toString(args));
63+
return getImageData((VImage) args[0]);
64+
}
65+
}

core/formula/src/main/java/org/csstudio/apputil/formula/areadetector/ImageWidthFunction.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
******************************************************************************/
88
package org.csstudio.apputil.formula.areadetector;
99

10-
import java.util.Arrays;
11-
import java.util.List;
12-
13-
import org.csstudio.apputil.formula.spi.FormulaFunction;
1410
import org.epics.vtype.Display;
1511
import org.epics.vtype.VImage;
1612
import org.epics.vtype.VInt;
@@ -19,14 +15,8 @@
1915
/** A formula function for fetching width of VImage
2016
* @author Kay Kasemir
2117
*/
22-
public class ImageWidthFunction implements FormulaFunction
18+
public class ImageWidthFunction extends ImageValueFunction
2319
{
24-
@Override
25-
public String getCategory()
26-
{
27-
return "areaDetector";
28-
}
29-
3020
@Override
3121
public String getName()
3222
{
@@ -39,12 +29,6 @@ public String getDescription()
3929
return "Fetch width of image";
4030
}
4131

42-
@Override
43-
public List<String> getArguments()
44-
{
45-
return List.of("image");
46-
}
47-
4832
/** Fetch info (width, height, ...) from image
4933
*
5034
* Subclass can override
@@ -58,13 +42,8 @@ protected int getImageInfo(final VImage image)
5842
}
5943

6044
@Override
61-
public VType compute(final VType... args) throws Exception
45+
protected VType getImageData(final VImage image)
6246
{
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];
6847
return VInt.of(getImageInfo(image), image.getAlarm(), image.getTime(), Display.none());
6948
}
7049
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ 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
3130
org.csstudio.apputil.formula.areadetector.ImageHeightFunction
31+
org.csstudio.apputil.formula.areadetector.ImageValueFunction
32+
org.csstudio.apputil.formula.areadetector.ImageWidthFunction
3233
org.csstudio.apputil.formula.areadetector.ImageXOffsetFunction
33-
org.csstudio.apputil.formula.areadetector.ImageYOffsetFunction
3434
org.csstudio.apputil.formula.areadetector.ImageXReversedFunction
35+
org.csstudio.apputil.formula.areadetector.ImageYOffsetFunction
3536
org.csstudio.apputil.formula.areadetector.ImageYReversedFunction
3637

3738
# String

0 commit comments

Comments
 (0)