Cleanleads program

Rob MacLeod

1 The Idea

The basic idea of this program was to perform certain corrections and alterations of the geometry files from needle experiments. The need arises for reasons such as electrodes being outside the myocardium, or needles slipping out of the heart over the course of the experiment. The user must select the operations, and the leads which need them, manually as part of routine quality control step. Once selected, the program should read these instructions and perform the corrections, creating a new geometry file from each original.

2 Running cleanleads

Cleanleads can be run directly as follows:

           cleanleads channel_list.clf inputfile.geom outputfile.geom

where the arguments are specified as

is a file containing a list of channels on which cleanleads should operate (see particulars of this file type below)
is an input file in the CVRTI .geom format
is an output file in the CVRTI .geom format

To facilitate running multiple files through cleanleads, shell scripts can also be used, or written for any particular situation. One example of such a script is, which requires input of the channels list and a list of files to be cleaned. It can be run as follows:

Case 1: specify geom filenames as a list or wildcard, for example,

        cleansomeleads channel_list.clf *.geom

would clean all the files with the .geom extension in the current directory.

Case 2: create a list of files to process in another file, for example

        cleansomeleads channel_list.clf `cat geomfile_list.flist`

would clean all the files found listed in the file geomfile_list.flist.

Case 3: create a file with the names of the channel_list file and the .geom files in it, for example

        cleansomeleads `cat geomfile_list.flist`

would clean all the files in the file geomfile_list.flist in the current directory, using the first filename in the geomfile_list.flist file as the channels_list file.

Note that the cleansomeleads script automatically saves the original .geom file under a new name, and then creates a new one under the original name. The format of the new name may vary but at the moment has ``-orig'' inserted between the filename and the extension (eg., filea.geom becomes filesa-orig.geom).

2.1 Channels list file format

This file contains all the information the cleanleads program needs to adjust the geometry files. It is a simple ASCII file with the following format:

Line number Column 1 Column 2 Comments
1 ncav_channels   Number of channels from leads that are in the cavity or otherwise outside the heart.
2 channnelnum   first channel number
3 channnelnum   second channel number
. . . .
. . . .
ncav_channels+1 cav_channel   last channel of cavity potentials
ncav_channels+2 nshift_needles nelecs_per_needle Number of needles to be shifted and the number of electrodes on each needle.
  nsteps channelnum Channel number at the end of the needle to be shifted and the number of electrode steps to be shift by.
  nsteps channelnum  
. . . .
. . . .
  nsteps last_channelnum Last needle to be shifted.


  1. Each channel number corresponds to the data channel of the lead. It seldom equals the node numbers for needle experiments. In map3d you can view channel numbers by making the appropriate choice in the lead marking menu.
  2. All channel numbers start at one and not zero.
  3. Needles are always shifted outwards, a direction defined by the order in which needles are labeled. We assume channel numbers run from the innermost needle electrodes outwards.
  4. At present, we require a constant number of electrodes per needle. If this changes, cleanleads also must change.
  5. Spacing between electrodes need not be constant for cleanleads to work properly.
  6. The .clf extension is not mandatory for channels list files, but is strongly recommended in order to identify files types in a directory listing.

3 What cleanleads does

The program first reads all surfaces from the geometry file, under the following assumptions:

  1. All .geom files with a single surface have nodes ordered along the needles.
  2. All .geom files with more than one surface, have nodes ordered by needles number across concentric shells. i.e., the first node of each surface belongs to needle 1, the second to needle 2, and so on.
  3. All .geom files have channels associated with the nodes. At present, cleanleads can only read the geometry from .geom files; .pts and .fac files must first be converted with gconvert.

Once the geometry read in and organized in groups according to the needles, cleanleads performs the following operations:

Doubled nodes:
Looks for doubled nodes in all triangles. These are degenerate triangles and can only serve to mess up other processing or display programs.
Shift needles:
Look for needles that need to be shifted and shift them according to the .clf file. At this point, the triangles are all intact, but nodes may have been moved in space.
Remove bad triangles:
Remove all triangles that conclude points whose channels have been marked as ``bad'', either in the cavity or outside the heart; this information comes from the .clf file.
Check isolated points:
Check for any nodes that have been isolated by the triangle removal, that is they contain valid data, but are not part of any triangles, and hence will not show up in map3d. For any that are found, cleanleads tries to make at least one new triangle from the isolated point and two nearby nodes that also contain valid data.
Output file:
Create a new .geom file to contain the altered version of things. The name of this file will be the one specified by the command line arguments and will be checked before it is overwritten.

4 Notes:

There always exists the risk that the program could mangle or destroy a file. It is best, especially at this early stage of things, to make copies of the .geom files and work with the copies.

If there are any problems or further additions/changes, and there are bound to be, then see Rob (ideally not before a bike ride and with checkbook in hand).

About this document ...

Cleanleads program

This document was generated using the LaTeX2HTML translator Version 99.2beta6 (1.42)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 3 -no_white -link 3 -no_navigation -no_math -html_version 3.2,math -show_section_numbers cleanleads

The translation was initiated by Rob MacLeod on 2001-08-05

Rob MacLeod 2001-08-05