Package bar :: Module base :: Class barTracedSlide
[hide private]
[frames] | no frames]

Class barTracedSlide


Class of objects representing CAF slides.

Nested Classes [hide private]
Instance Methods [hide private]
 
__init__(self, slideTemplate='\n<svg baseProfile="full" id="body"\nheight="900"\nwidth="120..., rendererConfiguration={'ReferenceHeight': 900, 'ReferenceWidth': 1200, 'imageSize': ..., tracingConfiguration={'CacheLevel': 5, 'DetectUnlabelled': True, 'DumpDirectory': '..., slideNumber=0)
Class requires providing following properties in order to work properly:
 
__setitem__(self, key, newStructure)
Add structure to the slide.
barGenericStructure
__getitem__(self, key)
Returns: requested structure
 
__delitem__(self, key)
Remove structure denoted by provided structure name.
[str, ...]
keys(self)
Returns: names of structures in the slide
[(str, barGenericStructure), ...]
items(self)
Returns: (structure name, structure representation) pairs for every slide structure
[barGenericStructure, ...]
values(self)
Returns: slide structures
int
__len__(self)
Returns: number of structures in the slide
barTracedSlide
__add__(self, op)
Add two slides.
bool
has_key(self, key)
Returns: True if the requested structure is present in the slide; False otherwise
 
__addPath(self, newPath)
Add a path to the slide.
 
addPath(self, newPathElement)
An alias of __addPath(newPathElement)
{str : barPath, ...}
__generatePathIndex(self)
Returns: path identifier to path representation mapping for all paths in the slide
 
_getPaths(self)
An alias for __generatePathIndex().values()
[barGenericStructure, ...]
_getStructures(self)
Returns: representations of all structures in the slide
 
addStructures(self, *args)
Add provided structures to the slide.
None
__validateBoundingBoxes(self)
Validate bounding boxes.
xml.dom.minidom.Document
getXMLelement(self)
Returns: XML representation of the slide
barTracedSlide
recolor(self, colorMapping)
Change colour of every slide structure according to the given colour mapping.
barTracedSlide
affineTransform(self, M)
Transform the location (in SVG coordinate system) of every label and path in the slide.
 
__affineTransform(self, M)
Transform the location (in SVG coordinate system) of every label and path in the slide.
{str : [barPath, ...], str : [barPath, ...]}
findDuplicatedRegions(self, Options=None, Apply=True)
Method for post processing of traced files.
 
__processDuplicates(self, Options, listOfChanges)
Process paths and labels in following way:
 
__setCrispEdges(self, boolValue)
Set 'crispEdges' attribute for every structure representation in the slide.
bool
__getCrispEdges(self)
Returns: True if every structure representation in the slide has the 'crispEdges' attribute equal True; False false.

Inherited from barSlideRenderer: renderSlide

Inherited from barVectorSlide: Show, addLabel, alignToRefMatrix, deleteLabelByCaption, deleteLabelByID, getCommentLabels, getLabelByName, getRegularLabels, getSpotLabels, renameLabelByCaption, retypeLabelByCaption, srs2svg, svg2srs, updateMetadata

Inherited from barObject: __str__, getElementById, writeXMLtoFile

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
cls
fromXML(cls, svgDocument, fixDrawing=False)
Create object representing given SVG slide.
None
_fromXML_LoadStructures(cls, slide, svgdom)
Part of XML parsing subroutine responsible for extracting 'structure' objects from provided XML element.
None
_fromXML_LoadLabels(cls, slide, svgdom)
Part of XML parsing subroutine responsible for extracting labels and markers from provided XML element.
Static Methods [hide private]

Inherited from barObject (private): _getAttributesDict

Instance Variables [hide private]

Inherited from barVectorSlide: slideNumber, slideTemplate

Inherited from barVectorSlide (private): _labels, _metadata

Properties [hide private]
[barPath, ...] paths
Representations of all paths in the slide.
{str : barPath, ...} pathIndex
Path identifier to path representation mapping for all paths in the slide.
[barGenericStructure, ...] structures
Representations of all structures in the slide.
xml.dom.minidom.Document svgDocument
XML representation of the slide.
bool crispEdges
The 'crispEdges' attribute of all contained structures.

Inherited from barSlideRenderer: bitmapSize, size

Inherited from barVectorSlide: labelIndex, labels, metadata

Inherited from object: __class__

Method Details [hide private]

__init__(self, slideTemplate='\n<svg baseProfile="full" id="body"\nheight="900"\nwidth="120..., rendererConfiguration={'ReferenceHeight': 900, 'ReferenceWidth': 1200, 'imageSize': ..., tracingConfiguration={'CacheLevel': 5, 'DetectUnlabelled': True, 'DumpDirectory': '..., slideNumber=0)
(Constructor)

 

Class requires providing following properties in order to work properly:

  • rendererConfiguration['ReferenceWidth']: (int) width of SVG drawing
  • rendererConfiguration['ReferenceHeight']: (int) height of SVG drawing
  • rendererConfiguration['imageSize'] : ((int, int)) size (width, height) of resulting bitmap image
Parameters:
  • slideTemplate (str) - SVG slide template
  • rendererConfiguration ({str : ?, ...}) - renderer configuration (see module description for details)
  • tracingConfiguration ({str : ?, ...}) - tracing configuration (see module description for details)
  • slideNumber (int) - slide number
Overrides: object.__init__

fromXML(cls, svgDocument, fixDrawing=False)
Class Method

 

Create object representing given SVG slide.

Parameters:
  • svgDocument (xml.dom.minidom.Document or str or file) - SVG slide (DOM XML or filename or file handler)
  • fixDrawing (bool) - indicates if path definitions has to be redefined with absolute coordinates
Returns: cls
created object

_fromXML_LoadStructures(cls, slide, svgdom)
Class Method

 

Part of XML parsing subroutine responsible for extracting 'structure' objects from provided XML element. This method may be overriden in subclasses if more features are required.

Parameters:
  • slide (barVectorSlide) - Slide to which structures extracted from svgdom will be assigned
  • svgdom (xml.dom.minidom.Document or str or file) - SVG slide (DOM XML or filename or file handler)
Returns: None
None

_fromXML_LoadLabels(cls, slide, svgdom)
Class Method

 

Part of XML parsing subroutine responsible for extracting labels and markers from provided XML element. This method can be overriden in subclasses if more features are required.

Parameters:
  • slide (barVectorSlide) - Slide to which labels extracted from svgdom will be assigned
  • svgdom (xml.dom.minidom.Document or str or file) - SVG slide (DOM XML or filename or file handler)
Returns: None
None

__setitem__(self, key, newStructure)
(Index assignment operator)

 

Add structure to the slide.

Parameters:
  • key (str) - name of the structure
  • newStructure (barGenericStructure) - structure to be added to the slide

__getitem__(self, key)
(Indexing operator)

 
Parameters:
  • key (str) - name of the requested structures
Returns: barGenericStructure
requested structure

__delitem__(self, key)
(Index deletion operator)

 

Remove structure denoted by provided structure name. All paths corresponding to the given structure are removed. Every path with identifier corresponding to the given structure is also removed.

Parameters:
  • key (str) - name of the structure to be removed

keys(self)

 
Returns: [str, ...]
names of structures in the slide

items(self)

 
Returns: [(str, barGenericStructure), ...]
(structure name, structure representation) pairs for every slide structure

values(self)

 

A stub of method. Raise NotImplementedError.

Returns: [barGenericStructure, ...]
slide structures
Overrides: barSlideRenderer.values

__len__(self)
(Length operator)

 
Returns: int
number of structures in the slide

__add__(self, op)
(Addition operator)

 

Add two slides.

Preconditions:

  • The transformation matrix of both slides has to be identical,
  • Slides has to have equal 'z' axis location,
  • Slides has to have identical slide templates,
  • Slides has to have identical slide number
  • Slides has to have the same reference rendering and tracing properties.

Definition of plus operator:

  • New slide is created with the template and properties taken from operands,
  • Slide is filled with the structures from the first operand and then from the second operand
  • If operands contains labels, they are copied in the same order as structures.

Resolving conflicts:

  • currently labels and paths with identical ids, prevent add operation.
Parameters:
  • op (barTracedSlide) - second term of the addition (the first is the object itself)
Returns: barTracedSlide
sum of the slides

has_key(self, key)

 
Parameters:
  • key (str) - name of the structure
Returns: bool
True if the requested structure is present in the slide; False otherwise

__addPath(self, newPath)

 

Add a path to the slide.

If structure corresponding to the added path exists, path is added to the structure. Otherwise new structure holding added path is created. This is possible as the path element holds name of the structure which it belongs to.

Parameters:
  • newPath (barPath) - path to be added to the slide

Note: Slide element does not contain barPath elements directly. Paths are holded in structure elements so paths are added to the structures not to the slide directly.

__generatePathIndex(self)

 
Returns: {str : barPath, ...}
path identifier to path representation mapping for all paths in the slide

_getStructures(self)

 
Returns: [barGenericStructure, ...]
representations of all structures in the slide

addStructures(self, *args)

 

Add provided structures to the slide. Existing structures are overwritten with new structures with the same name.

Parameters:

__validateBoundingBoxes(self)

 

Validate bounding boxes. For some datasets it may happen that bounding boxes are calculated incorrectly due to data corruption.

Returns: None

getXMLelement(self)

 

A stub of method. Raise NotImplementedError.

Returns: xml.dom.minidom.Document
XML representation of the slide
Overrides: barObject.getXMLelement

recolor(self, colorMapping)

 

Change colour of every slide structure according to the given colour mapping. Colours of structures not included in the mapping are preserved.

Parameters:
  • colorMapping ({str : str, ...}) - structure name to colour (in hexadecimal format) mapping
Returns: barTracedSlide
self

affineTransform(self, M)

 

Transform the location (in SVG coordinate system) of every label and path in the slide.

Parameters:
  • M (numpy 3x3 array) - transformation matrix
Returns: barTracedSlide
self
Overrides: barVectorSlide.affineTransform

__affineTransform(self, M)

 

Transform the location (in SVG coordinate system) of every label and path in the slide.

Parameters:
  • M (numpy 3x3 array) - transformation matrix

findDuplicatedRegions(self, Options=None, Apply=True)

 

Method for post processing of traced files. At this moment, has following capabilities:

  1. Find regions which are defined by the same path (the same path means that the definition of the path <d> attribute is the same for those paths). In other words find regions with the same <d> tags.
  2. Find corresponding labels for those regions.
  3. Remove all but one path.
    • Leave only one label (the first one) defining given region
    • Mark other labels as "spot labels" and make them red

Traced file may have all kinds of labels (normal, spot label, comment label). Effect it that there should be no overlapping areas in output file, no new unlabelled areas and some new spotlabels.

Parameters:
  • Options - dummy parameter - placeholder for further processing options
  • Apply (bool) - determine if slide is processed or not; when True, duplicated paths are removed and labels are changed; otherwise slide is not processed, only duplicated areas are found and returned
Returns: {str : [barPath, ...], str : [barPath, ...]}
mapping of keywords 'preserve' and 'remove' to representations of slide paths to be preserved and removed

To Do: Implement processing options

__processDuplicates(self, Options, listOfChanges)

 

Process paths and labels in following way:

  • Remove paths that should be removed
  • Change type of corresponding label to SpotLabel
Parameters:
  • listOfChanges ({str : [barPath, ...], ...}) - mapping of keyword 'remove' to representation of slide paths to be removed
  • Options - dummy parameter - placeholder for further processing options

__setCrispEdges(self, boolValue)

 

Set 'crispEdges' attribute for every structure representation in the slide.

Parameters:
  • boolValue (bool) - new value of the attribute

__getCrispEdges(self)

 
Returns: bool
True if every structure representation in the slide has the 'crispEdges' attribute equal True; False false.

Property Details [hide private]

paths

Representations of all paths in the slide.

Read-only property.

Get Method:
_getPaths(self) - An alias for __generatePathIndex().values()

pathIndex

Path identifier to path representation mapping for all paths in the slide.

Read-only property.

Get Method:
__generatePathIndex(self) - Returns: path identifier to path representation mapping for all paths in the slide
Type:
{str : barPath, ...}

structures

Representations of all structures in the slide.

Read-only property.

Get Method:
_getStructures(self) - Returns: representations of all structures in the slide
Type:
[barGenericStructure, ...]

svgDocument

XML representation of the slide.

Read-only property.

Get Method:
getXMLelement(self) - Returns: XML representation of the slide
Type:
xml.dom.minidom.Document

crispEdges

The 'crispEdges' attribute of all contained structures. When read True if the value of the attribute of every contained structure is 'crispEdges', False otherwise.

Get Method:
__getCrispEdges(self) - Returns: True if every structure representation in the slide has the 'crispEdges' attribute equal True; False false.
Set Method:
__setCrispEdges(self, boolValue) - Set 'crispEdges' attribute for every structure representation in the slide.
Type:
bool