Anda di halaman 1dari 4

Experience Programming Radiotherapy Applications in

Common Lisp
1
Ira J. Kalet, Ph.D. , Jonathan M. Unger, M.S. , Jonathan P. Jacky, Ph.D. ,
2 1
Mark H. Phillips, Ph.D.
1
1 Radiation Oncology Dept., University of Washington, Seattle, WA 98195
2 RSA, Inc., 22 Terry Ave., Burlington, MA 01803

We report on our experience using Common Lisp [1] as the user can bring up simultaneously any number of these or other
programming language for a new radiation treatment planning component-speci c panels during the Prism session.
(RTP) system, the Prism system [2]. The Prism system was
built to provide new features such as arti cial intelligence tools Design goals
and to take advantage of the most advanced computer graphic In addition to the speci c user requirements, we set out design
display and networking technologies. We decided to use Lisp goals. They include:
because of: its high level of expressive power, the existence
of a direct interface to the X window system for network-based  keeping the overall size of our programs small, so they
graphic display, its standardization and its wide availability. Al- will take less time to build and maintain,
though Lisp is one of the oldest programming languages, in the  ease of nding and xing problems,
past its use had been limited to arti cial intelligence research.  ease of adding new features and extending existing ones,
It was not widely available, and Lisp compilers of the time were
not able to generate highly ecient binary code. Modern Lisp  ability to add new kinds of objects,
systems have eliminated these obstacles, and added powerful  ability to add new kinds of control panels.
object oriented programming capabilities, along with standard- These items are examples of the need for software evolution,
ization, so that Common Lisp can be a powerful and practical a need that is dicult to satisfy, even using object-oriented de-
system implementation language for interactive graphic appli- sign and object-oriented programming languages.
cations like radiation treatment planning.
Architecture: objects and relationships
THE PRISM SYSTEM Our previous work [3] showed that RTP systems can be nat-
urally modeled as collections of interacting objects, radiation
Prism takes a very generalized approach to display and user ma- beams, organs, etc. In Prism too, we chose an object-oriented
nipulation of the system, extending ideas we incorporated into design. The patient, the treatment equipment, and all their
our previous work. The unique features of Prism are described parts are represented as objects in the Common Lisp Object
in another publication [2]. System.
The patient case is the overall \container" object in the
User interface requirements Prism system. The other objects are parts or components of
The Prism system user interface is distributed among several the patient case. We have modeled some RTP object classes
task-speci c windows we call panels, which act as a front end as subclasses. For example, there is a class, pstruct, that de-
for those components of the system which actually carry out nes a general three-dimensional anatomic object, and there
various functions related to radiotherapy planning. are subclasses for organs, tumors and targets. All have con-
The interface is designed to provide as little nesting of in- toured volumes, a display color, etc., but each subclass has ad-
teractions as possible, that is, we want almost all operations ditional attributes that represent special characteristics, e.g.,
to be available to the user at all times. On the other hand, organs may have a density, for use in the dose calculation.
presenting a display with visible controls for every adjustable We also make extensive use of the part-of relationship, in
parameter of every object would be impossible. So our com- which an attribute of an object may have as its value an in-
promise is to associate a type of control panel, or object editor, stance or collection of instances of another object class. For
with each type of object that the user can create or modify. A example, a radiation beam is modeled as an object that in-
control panel is a window on the screen that includes controls, cludes a collimator subsystem as a component attribute. There
e.g., dials for angles, sliders for adjustable numbers, text input are di erent classes of collimators, but only one class, beam for
boxes for typed text, etc. so that when the control panel for a radiation beam.
a particular object is displayed, the user can at any time alter As an example of how we implement these objects, the fol-
any of those attributes of the object. lowing shows the code that de nes the beam class.
A patient panel that manages administrative information
about the current patient case is always present in a given (defclass beam (generic-prism-object)
Prism session. Individual panels for plans, beams and other ((machine :type string
component objects control their respective domains, and view :documentation "The string naming the
windows display graphical renditions of patient anatomy and machine used for this beam, eg. Clinac 2500-6MV")
beam portals. A graphic editing panel provides for the delin- (new-machine :type event :initform (make-event))
eation and modi cation of patient anatomy, tumors and targets. (gantry-angle :type single-float)
The plan panel includes controls for the speci cation, compu- (new-gantry-angle :type event
tation and display of dosimetric information for a plan. The :initform (make-event))
(collimator :type collimator up to a point. Objects modeled as abstract data types (classes)
:documentation "An object, one of the can abstract and encapsulate attributes and operations on ob-
various types of collimators.") jects. But in a dynamic system, objects have actions that may
(collimator-angle :type single-float) a ect other objects. The internal code of object implementa-
(new-coll-angle :type event tions will then refer to other objects, and the result is that the
:initform (make-event)) objects are no longer independent and modular. Managing this
(monitor-units :type single-float) interdependence in writing a large program like an RTP system
...etc... )) is very dicult.
Sullivan and Notkin [4] argue that the generalization of ab-
The type declarations are not required but help the com- stract data types (ADT) to include action interfaces, or ab-
piler produce faster, more ecient code. Documentation strings stract behavioral types (ABT), provides improved correspon-
are parts of an object and can be accessed by a running pro- dence between speci cations and designs, improved abstraction
gram. They are data, not comments. We are considering us- and encapsulation, and behavioral composability of indepen-
ing this facility or something like it to incorporate context- dent types. This is particularly important in dynamic model-
dependent online help in the Prism system. The types string ing, where a software system must provide for the creation and
and single-float are the usual types you nd in most pro- destruction not only of objects but of relationships between
gramming languages, but an event is a type de ned in the them. The use of ABT provides a way to model such actions
Prism system, to provide connections between objects. An ob- while retaining encapsulation.
ject announces an event, and other objects can respond. The The potential of this approach to software design was suf-
responses depend on what is registered with the event while the ciently appealing that we decided to use it in designing and
program is running. implementing the Prism system. We expected that behavioral
The collimator type is also a class, with subclasses for abstraction would result in a simpler, more modular design
di erent types of collimators. Here are some of the collimator than the use of object-oriented design and programming alone.
subclasses. A separate report [5] describes how this approach worked out
in building the Prism system. In this report we address the
(defclass symmetric-jaw-coll (collimator) speci c choice of Lisp as our implementation language and its
((x :type single-float) contribution to the success of Prism.
(y :type single-float)
(new-coll-x :type event
:initform (make-event)
:documentation
WHY LISP?
"Announced when x is updated.")
In choosing a programming language for Prism, we considered
(new-coll-y ...))
several characteristics to be important. The language we use
(:default-initargs :x 10.0 :y 10.0))
must support:
 object-oriented programming,
This class de nition provides default values when a new
collimator is created, to insure that the attributes always have  the X window system, for graphic display and user inter-
valid values. action,
 a high level of abstraction,
(defclass portal-coll (collimator contour)
 building large systems, i.e., programs that are large and
()
(:default-initargs :z 0.0
complex, and that can handle very large amounts of data
:vertices '((-5 -5) (5 -5)
and numbers of objects,
(5 5) (-5 5)))  deployment in an application environment, i.e., routine
(:documentation "A collimator that has a portal, use in the clinic, not just an experimental lashup to be
defined by a contour. The contour is used only by physicists.
always at z = 0."))
Few languages meet all of these requirements. The obvious
The class portal-coll adds no new slots or attributes, but choice of most designers these days is C++ but it does not pro-
combines the properties of the collimator and the contour vide as good an object-oriented programming environment as
classes, since a portal collimator has a portal de ned by a con- Common Lisp, nor does it provide a very high level of abstrac-
tour. tion. We were not looking for \a better C". Before committing
to development in Common Lisp, we reviewed the limitations
(defclass electron-coll (portal-coll) we experienced with our earlier work, and did some prototyping
((cone-size :type single-float that helped determine the feasibility of using Lisp.
:documentation "An electron collimator
is a square cone with a Lisp in the light of previous work
metal cutout plate.") Our earlier work [3] used the Pascal programming language. It
...other slots...)) was dicult because there are no facilities in Pascal for de ning
abstract objects, i.e., classes, and for de ning generic functions
Adding a slot for specifying the cone in use allows for spe- for those objects. Although we created a workaround for our
cialized methods, e.g., for the user to select the cone size from RTP system, it was in exible (it was dicult to add new object
a menu, and for the dose computation to look up tables based classes), and hard to understand, because the implementation
on cone size. had much code devoted to object management and function dis-
Object-oriented design provides a way to make a close cor- patch. This obscured the actual application, the radiotherapy
respondence between the real world and the software system, objects and their operations.
We had some prior experience with Lisp, in writing an ex- programmer does not need to provide any code for formatted
pert system program for automating part of the radiation treat- or binary le reading. Prism takes advantage of this in storing
ment planning process [6]. That program did not have a graph- patient and plan data and retrieving it for reuse.
ical user interface and did not provide any of the complex data Prism objects contain many di erent types of data as values
management characteristic of RTP systems. Interlisp, the di- of their attributes. The data are all stored as ASCII text, us-
alect of Lisp that we rst used, was not a good candidate for an ing the Lisp write function. It formats the data automatically,
RTP system, as it did not have an ecient compiler (compiled without need for the programmer to do anything. The Prism
code ran slowly), it did not include support for the emerging function put-object executes the same code regardless of the
X window system, and although very large programs had been type or complexity of the object. It obtains the names of the
written using Interlisp, it was not well suited to writing pro- attributes of an object from its class de nition, and writes all
grams for routine use by non-programmers. the attributes without concern for order or type.
The emergence of Common Lisp as a standard and widely When data are read back into a Prism session, the corre-
supported commercial product was a radical change. Common sponding function get-object executes the same code regard-
Lisp implementations became available that had very ecient less of what is read. The le contains data identifying the type
compilers, support for X windows (there is a de facto stan- of the object and the get-object code calls the standard CLOS
dard Common Lisp binding to the X window system, CLX, function make-instance to make one. Then get-object reads
and a public domain implementation is available), facilities keywords naming the attributes, and then reads values whose
for application deployment, and an excellent standard object- type is automatically known to Lisp by the format of the data.
oriented programming system, the Common Lisp Object Sys- This alone represents a huge saving in code, where in our
tem (CLOS). Growing use of Lisp in serious applications has previous systems we had to write a lot of detailed code to han-
resulted in the formation of the Association of Lisp Users1 . dle the plan data le formats. It also makes it easy to add new
Lisp is used in the video game software industry, as well as in kinds of objects: the old les are not made obsolete, and no
software products such as AutoCAD and Interleaf, and as an new le reading and writing code needs to be written.
HTML server2 . An example of the use of multi-methods is the Prism draw
We wrote some prototype user interface code to experiment generic function. There are many places where an object needs
with the graphical performance of Common Lisp programs. to be drawn into a view. Neither the type of object nor the type
Satis ed with its performance, we discarded this code, and be- of view is xed, and at the same place in the program, but at
gan in earnest to design and write the Prism system. di erent times during a Prism session, this function may need to
draw di erent objects into various types of views. The function
Characteristics of Lisp call is (draw object view) where object is some Prism ob-
In deciding to write the Prism software in Lisp, we expected ject, a beam perhaps, and view is a view on the screen, maybe
to take advantage of the ability to create layered designs, in a transverse view. In general, in Prism, the types of the argu-
which the programmer constructs supplements to the language ments are not known at compile time, and may even vary as
as needed. In addition to meeting the criteria described above, the Prism session progresses.
Lisp has features and characteristics that make it radically Many object-oriented programming languages use method
di erent from all the more familiar programming languages. dispatch on the type of a single parameter, i.e., a method is a
These features are important in writing RTP software; they piece of code that implements a function for a particular class
are not just exotica that arti cial intelligence researchers play of object, and we say that the method \belongs" to that class.
with. In Prism the following features proved to be especially This is analogous to the idea of \sending a message to an ob-
useful: ject" in order to invoke a function. So there would be draw
methods for each of the di erent object classes. But what
 Run-time types: Lisp can determine the type of a piece about the di erent kinds of views? It is complicated. Per-
of data at run-time, and act accordingly. We take ad- haps there will be a multiway branch inside the code for each
vantage of this to make the storage and retrieval of RTP draw method. Then adding a new object means writing a big
plan data very simple. method, and adding a new kind of view means modifying a lot
 Multi-methods: In the Common Lisp Object System, of di erent modules.
methods for generic functions can be selected at run-time Instead, the Common Lisp Object System provides dispatch
based on the type of any number of arguments. on any number of parameters, so the draw function can have
 Lexical closures: Lisp code can create new functions while methods organized according to the types of both parameters,
the program is running. This may be very unfamiliar to i.e., there is a method for each combination. Here is an excerpt
most programmers, because it is impossible to do in most of a method for drawing an organ:
programming languages, but it is very powerful. It is ex-
plained in Graham's book [1, pages 1{2]. (defmethod draw ((org organ) (tv transverse-view))
(let ((prim (find org (foreground tv) ...))
Prism uses other unusual features of Lisp, too numerous to ...)
go into here. We refer the interested reader to some excellent (dolist (con (contours org))
books that explain Lisp programming in depth [1, 7]. (let ((pts (pixel-contour (vertices con)
scale x0 y0)))
Examples of advanced techniques (push (nconc pts (list (first pts) (second pts)))
We include here some examples of Prism code that uses special (points prim))))))
or advanced features of Lisp.
The Lisp function read can read text from a le and con- Drawing a di erent object, such as a beam, requires a di er-
struct the right type of object from the format of the le. The ent method for the draw function. The beam drawing method
1 refer to http://www.cs.rochester.edu/u/miller/ALU/home.html
2 in particular, for the White House Publications distribution system via the World Wide Web
uses a formula for projecting and transforming a portal contour from Pascal or C, and the extra e ort required to optimize the
in arbitrary orientation, and also has to render the other items performance of the system.
in the beam depiction, the isocenter, the central axis, and a Overall, the choice of Common Lisp was a good one and
wedge if present. Prism is successful, having been in clinical use for over two
years. The system continues to evolve and is easy to maintain.
(defmethod draw ((b beam) (v view)) In the future we hope to explore the possibility of devel-
(let ((solid-clr (display-color b)) oping a more high level implementation, something along the
... lines of the \Compiler TP" idea of Sterling [9], analogous to
(wdg (wedge b))) the CLOS Meta-Object Protocol [10]. Imagine an RTP sys-
...beam portal drawing code...)) tem with all the standard features, and a high level dynamic
RTP macro programming language built in, for adding features
The nal example we provide from Prism illustrates that without modifying any existing code, and being able to use any
in Lisp a program can write and execute programs as needed. existing components. That is our vision for the future of Prism.
The idea is that a function may be needed but what function
is needed may vary. It is possible in most programming lan-
guages to pass functions as parameters to other functions, but ACKNOWLEDGEMENTS
in Lisp, a program can make up functions depending on condi- This work was partially supported by NIH grant no. LM04174
tions in the program, something impossible to do in most other from the National Library of Medicine.
languages. The following code
(add-notify m (inserted os) References
#'(lambda (md obj-set obj)
1. Paul Graham. ANSI Common Lisp. Prentice-Hall, Engle-
(dolist (v (elements (view-set md)))
wood Cli s, New Jersey 07632, 1996.
(insert-element (funcall mediator-fn obj v)
(mediator-set md)) 2. Ira J. Kalet, Jonathan P. Jacky, Mary M. Austin-Seymour,
Sharon M. Hummel, Kevin J. Sullivan, and Jonathan M.
registers the function whose code begins with lambda so that it Unger. Prism: A new approach to radiotherapy planning
will be called when a new object is added (for example, a beam software. International Journal of Radiation Oncology, Bi-
to a plan) and the new object therefore has to appear in all the ology and Physics, 36(2):451{461, 1996.
views. This lambda function is a di erent function depending 3. Jonathan Jacky and Ira Kalet. An object-oriented pro-
on the type of object and the type of view, when it is added, gramming discipline for standard Pascal. Communications
i.e., the function that gets registered is created by this code, not of the ACM, 30(9):772{776, September 1987.
just selected. This is how Prism keeps all the objects and views 4. Kevin Sullivan and David Notkin. Reconciling environ-
coordinated, even though objects and views are being added ment integration and software evolution. ACM Transac-
and deleted all the time during a Prism session. tions on Software Engineering and Methods, 1(3):229{268,
July 1992.
RESULTS AND DISCUSSION 5. Kevin J. Sullivan, Ira J. Kalet, and David Notkin. Evalu-
ating the mediator method: Prism as a case study. IEEE
The Prism system consists of about 45,000 lines of Lisp source Transactions on Software Engineering, 22(8):563{579, Au-
code, making it similar in size to our two previous RTP systems, gust 1996.
written in the Pascal programming language. It is an order of
magnitude smaller than many other RTP systems, including 6. Ira J. Kalet and Witold Paluszynski. Knowledge-based
commercial products. However, the capabilities of Prism far computer systems for radiotherapy planning. American
exceed any previous system we built. We have described else- Journal of Clinical Oncology, 13(4):344{351, 1990.
where [2] some of the unique features of Prism, not found in 7. Paul Graham. On Lisp: Advanced Techniques for Common
any other RTP system of which we know. Lisp. Prentice-Hall, Englewood Cli s, New Jersey 07632,
The object oriented programming support in Common Lisp 1994.
enabled us to add facilities for modeling multileaf collimators 8. S. Sutlief, M. Phillips, I. Kalet, and P. Cho. Integration
and for stereotactic radiosurgery, after the initial system was and veri cation of intensity modulated radiation therapy
put into clinical use. We are also adding support for intensity into a computer treatment planning program (Prism). In
modulated radiotherapy using a computer controlled multileaf Dennis Leavitt and George Starkschall, editors, Proceedings
collimator [8, this volume]. of the Twelfth International Conference on Computers in
Other advantages of Lisp include: ease of incorporating ad- Radiotherapy(ICCR), Madison, WI, 1997. Medical Physics
vanced software engineering design ideas such as the \media- Publishing.
tor method" [5], ease of debugging, and simpli ed interactive
graphics programming, particularly the CLX package for X pro- 9. Theodor D. Sterling. Natural language compilers and in-
gramming. CLX is much less cluttered with low level details terpreters in radiation treatment planning or nous parlons
than the C binding for Xlib, even though it provides the same anglais better than jede andere sprache. In Ulf Rosenow,
and even more functionality. We nd Lisp programming to be editor, Proceedings of the Sixth International Conference
enjoyable and satisfying because with it we can express eas- on the Use of Computers in Radiation Therapy, pages 8{
ily our ideas and speci cations without becoming embroiled in 24, Gottingen, 1977.
arcane details unrelated to our application. 10. Gregor Kiczales, Jim des Rivieres, and Daniel G. Bobrow.
Some of the obstacles we had to work with include learn- The Art of the Metaobject Protocol. The MIT Press, Cam-
ing a new programming language whose style is very di erent bridge, Massachusetts, 1991.

Anda mungkin juga menyukai