|
The tool module is designed to provide access to the Scorpion
Tool instances. This is a very powerful and provides the
following important features:
- Execute a tool any number of times
- Set all configuration parameters from script including ROIs
and threshold values
- Extract all tool results to define custom business
logic with Python
- Save and load tool configuration to file
The tool requires basic knowledge of the Scorpion SPB concept -
more information
The Tool class
Use the GetTool(toolname) to get a tool instance from Scorpion.
The GetTool may also be used to access tools above or below the
current level when working with toolboxes by using dot notation
Access Tools in other toolbox scopes
- GetTool('.tf3') accesses 'tf3' at the current level
- GetTool('..tf3') accesses 'tf3' at the above level
- GetTool('aaa.tf3') accesses 'tf3' in the toolbox 'aaa'
- GetTool(':Insp1.SETUP') accesses the 'SETUP' tool in the root
level toolbox 'Insp1'
- GetTool('.') returns the parent toolbox tool
- GetTool('..') returns the parent toolbox parent toolbox
tool
- GetTool(':DATA') accesses 'DATA' at root level from any
level
| Attribute |
Access |
Type |
Description |
| bound |
R |
bool |
verification of valid tool name,
GetTool(<name>).bound returns true/false due to valid name/existing
tool or
not |
| name |
R |
string |
the tool name |
| fullName |
R |
string |
the fully prefixed name for toolbox children |
| type |
R |
string |
the origin tool type
(Blob1, TemplateFinder3,BaseTool) |
| toolType |
R |
string |
fully qualified tool type, including template
and component name/version if assigned - applies to components
only |
| friendlyToolType |
R |
string |
fully qualified tool type, including template
and component short name/version if assigned |
| level |
R |
int |
level in toolbox hierarchi, 1 at root level, 2
in second toolbox... |
| index |
R |
int |
zero based index of tool (0..n-1) |
| active |
R/W |
int |
the active flag (0/1) |
| manual |
R/W |
int |
the manual execution flag (0/1) |
| threaded |
R |
int |
the threaded execution flag (0/1) |
| visible |
R/W |
int |
visible graphics (0/1), applies to specific tool
types |
| imageNo |
R/W |
int |
the associated image
number |
| colorPlane |
R/W |
int |
0=No Conversion, 1=Hue, 2=Saturation, 3=Intensity |
| state |
R/W |
int |
the execution state |
| refSys |
R |
tuple |
the input reference matrix ((3)(3)(3)) |
| childRefSys |
R/W |
tuple |
the output
child reference matrix ((3)(3)(3)) |
| pose |
R |
tuple |
the input pose matrix ((3)(3)(3)(3)) |
| childPose |
R/W |
tuple |
the output child pose matrix ((3)(3)(3)(3)) |
| configVariant |
R |
Tool |
returns the tools configuration variant tool, None if no
variant |
| configVariantName |
R |
string |
returns name
of configuration variant tool, "" if no
variant |
| template |
R |
string |
name template if attached, else empty |
| templateDir |
R |
string |
name of template directory is attached, else
empty |
| reference |
R |
Tool |
returns the tools reference tool, None if no
reference |
| referenceName |
R |
string |
returns the tools reference
name, "" if no
reference |
| resultReference |
R |
Tool |
returns the tools result reference tool |
| resultReferenceName |
R |
string |
returns the tools result reference
name, "" if no result reference |
| guard |
R |
string |
returns the tools guard, <None> if not
guarded |
| group |
R |
string |
returns tool group |
| calibTool |
R |
Tool |
returns the associated calibration tool |
| calibToolName |
R |
string |
returns the associated calibration toolname,
"" if no calibration |
| calib |
R |
pointer |
returns a pointer to the calibration structure,
normally an array tree |
| config |
R/W |
string |
the SPB-XML string for the tool |
| localConfig |
R/W |
string |
the SPB-XML
local configuration string for the tool, applies to tools
grouped in either HARDWARE,CALIBRATION or LOCAL only |
| result |
R/W |
dictionary |
all results as a python dictionary |
| hedit |
R |
int |
window handle of configuration dialog, 0 if
dialog not open |
| Component support |
| componentName |
R |
string |
applicable for tool components only |
| componentShortName |
R |
string |
applicable for tool components only |
| componentVersion |
R |
string |
applicable for tool components only |
| EK |
R |
string |
license ExecuteKey required to execute tool |
| Toolbox support |
| count |
R |
int |
returns number of contained tools for toolbox
tools |
| Method |
Returns |
Description |
getValue(name)getBoolValue(name)
getIntValue(name)
getFloatValue(name)
getStringValue(name)
getResultValue(name)
getPointValue(name)
getLineValue(name)
getCircleValue(name)
getPointValue3D(name)
getLineValue3D(name)
getPlaneValue3D(name)
getSphereValue3D(name)
|
value |
Tool result
methods
returns a single or tuple value from the tool results |
setValue(name,value)setBoolValue(name,value)
setIntValue(name,value)
setFloatValue(name,value)
setStringValue(name,value)
setResultValue(name,value)
setPointValue(name,value)
setLineValue(name,value)
setCircleValue(name,value)
setPointValue3D(name,value)
setLineValue3D(name,value)
setPlaneValue3D(name,value)
setSphereValue3D(name,value)
|
0/1 |
Tool result
methods
sets a single or tuple value in the tool results |
getValid(name)
getValidPoint(name)
getValidLine(name)
getValidCircle(name)
getValidPoint3D(name)getValidLine3D(name)
getValidPlane3D(name)getValidSphere3D(name) |
0/1 |
Tool result validation methods - returns true or false
for a tool result |
setValid(name,valid)
setValidPoint(name,valid)
setValidLine(name,valid)
setValidCircle(name,valid)
setValidPoint3D(name,valid)
setValidLine3D(name,valid)setValidPlane3D(name,valid)setValidSphere3D(name,valid)
|
0/1 |
Tool result validation methods - sets true or false of a
tool result |
| objToPix(point) |
(x,y) |
converts tool object coordinates to pixels,
single point or tuple of points |
| pixToObj(point) |
(x,y) |
converts pixel coordinates to tool object
coordinates, single point or tuple of points |
| childToPix(point) |
(x,y) |
converts tool child coordinates to pixels,
single point or tuple of points |
| pixToChild(point) |
(x,y) |
converts pixels to tool child coordinates,
single point or tuple of points |
| toObj(referenceName,point) |
(x,y)(x,y,z) |
transform 2D or 3D single point or tuple of points from
tool object coordinates
into the references result coordinates. |
| getConfigValue(tag,value) |
value |
returns the configuration value of a tool -
more |
| setConfigValue(tag,value[,reload=1]) |
0/1 |
sets the configuration value of a tool - more |
| load(filename [,section]) |
0/1 |
loads
configuration from spb configuration file. SPB section is given
by tool name. The optional
parameter section may be given if tool section is not located at
spb root level. |
| save(filename [,section]) |
0/1 |
saves configuration to spb configuration file.
SPB section is given by tool name. The optional parameter
section may be given if tool section is not located at spb root
level. |
| edit([tabindex,context]) |
0/1 |
opens the configuration dialog. Only one
configuration may be open at a time. Returns 0 if another dialog
is already open.
Optional tabindex and dialog context may be given to specify one
tab only |
| reset() |
0/1 |
resets all results and overlays |
| clearOverlay() |
0/1 |
clears overlays |
| execute([image]) |
0/1 |
executes the tool. The
optional matrix is an image matrix
as defined in the ArrLib library. When no parameter is given
the tool executes on the image given by the tools imageindex. By
supplying an image matrix, the tool can execute on another image
(the matrix is retrieved by the GetImageMatr(imagename)
function. |
| executeCmd(cmd [, param]) |
0/1 |
executes a tool specific command. See the actual
tool for available commands.
More
information. |
| Toolbox support |
| get(name) |
Tool |
returns contained tool for toolbox tools by name |
| tool(index) |
Tool |
returns contained tool for toolbox tools by
index |
Note: Modifying the result dictionary, the dictionary itself has to be
assigned to the tool.result attribute after modification is done,
see the two examples belowExample 1 - Set a tool result
t=GetTool('ExData')
t.setValue('Radius',12.0)
Example 2 - Run tools outside normal execution order t=GetTool('FindCircle')
t.execute()
t=GetTool('CircleFound')
if t.execute(None)==1:
print 'circle found'
else:
print 'circle not found'
im=GetImageMatr('Image2') #get the image matrix of Image2
t.execute(im) #execute on another image
Example 3 - Change tool
configuration using the SPB
import SPB
t=GetTool('FindReference')
spb=SPB.CreateSpb(t.config)
spb.setFloat('ROI.x',10)
spb.setFloat('ROI.y',15)
t.config=spb.xml
Example 4 - Access tools outside current toolbox (valid inside
toolbox scripts only)
t=GetTool('.') #returns owner toolbox tool
t=GetTool(':DATA') #returns the tool 'DATA' at root level from whatever scope
t=GetTool('Circle.SETUP') #returns the toolbox tool 'SETUP' in the toolbox 'Circle' at current level
Example 5 - Load and save tools
def LoadTool(name,fileName):
#precondition: tool and file exists with identical tool class
#postcondition: tool is loaded from file
return GetTool(name).load(fileName)
def SaveTool(name,fileName):
#precondition: tool exists
#postcondition: tool configuration is written to file
return GetTool(name).save(fileName)
|