casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
NBody.h
Go to the documentation of this file.
00001 //# NBody.h: class which provides brute force n-body simulation and display
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef TRIALDISPLAY_NBODY_H
00029 #define TRIALDISPLAY_NBODY_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Vector.h>
00033 #include <casa/Quanta/Quantum.h>
00034 #include <casa/Containers/Record.h>
00035 #include <display/DisplayEvents/WCPositionEvent.h>
00036 #include <display/DisplayEvents/WCPositionEH.h>
00037 #include <display/DisplayEvents/WCMotionEvent.h>
00038 #include <display/DisplayEvents/WCMotionEH.h>
00039 #include <display/DisplayDatas/DisplayData.h>
00040 #include <casa/Containers/List.h>
00041 
00042 namespace casa { //# NAMESPACE CASA - BEGIN
00043 
00044 class WorldCanvas;
00045 class WCResampleHandler;
00046 class WorldCanvasHolder;
00047 class AttributeBuffer;
00048 class Attribute;
00049 class Unit;
00050 class IPosition;
00051   
00052 // <summary> 
00053 // Simple class which provides brute force n-body simulation and display.
00054 // </summary>
00055 
00056 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00057 // </reviewed>
00058 
00059 // <synopsis> 
00060 
00061 // This class provides a simple object which can (by brute force)
00062 // calculated the internal gravitational forces acting on a
00063 // self-gravitating set of bodies.
00064 // </synopsis>
00065 
00066 class NBody : public DisplayData {
00067 
00068  public:   
00069 
00070   // Constructor.
00071   NBody();
00072     
00073   // Destructor.
00074   virtual ~NBody();
00075 
00076   // Coordinate transformations, called by the WorldCanvasHolder.
00077   // <group>
00078   virtual Bool linToWorld(Vector<Double>& world, const Vector<Double>& lin);
00079   virtual Bool worldToLin(Vector<Double>& lin, const Vector<Double>& world);
00080   // </group>
00081 
00082   // irrelevant in this part of the tree
00083   virtual void setActiveImage(uInt zindex) { return;};
00084 
00085   // Routines which yield information on the axis names and units, and
00086   // some miscellaneous information. 
00087   // <group>
00088   virtual Vector<String> worldAxisNames() const;
00089   virtual Vector<String> worldAxisUnits() const;
00090   virtual const Unit dataUnit() ;
00091   virtual const RecordInterface& miscInfo() ;
00092   // </group>
00093 
00094   // Return the number of elements in this DisplayData.
00095   virtual const uInt nelements(const WorldCanvasHolder& wcHolder) const;
00096   virtual const uInt nelements() const;
00097 
00098   // Add a restriction for item <src>itemNum</src> of this
00099   // DisplayData. 
00100   // <group>
00101   virtual void addElementRestrictions(const uInt itemNum, 
00102                                       AttributeBuffer& other);
00103   virtual void addElementRestriction(const uInt itemNum,
00104                                      Attribute& newRestriction, 
00105                                      Bool permanent);
00106   // </group>
00107 
00108   // Set a restriction for item <src>itemNum</src> of this
00109   // DisplayData. 
00110   // <group>
00111   virtual void setElementRestrictions(const uInt itemNum, 
00112                                       AttributeBuffer& other);
00113   virtual void setElementRestriction(const uInt itemNum, 
00114                                      Attribute& newRestriction);
00115   // </group>
00116 
00117   // Remove a restriction from item <src>itemNum</src>.
00118   virtual void removeElementRestriction(const uInt itemNum, 
00119                                         const String& name);
00120 
00121   // Clear all restrictions of item <src>itemNum</src> (except the
00122   // ones that are permanent of course).
00123   virtual void clearElementRestrictions(const uInt itemNum);
00124 
00125   // Check if a restriction for item <src>itemNum</src> with name
00126   // <src>name</src> exists.
00127   virtual Bool existElementRestriction(const uInt itemNum, 
00128                                        const String& name);  
00129 
00130   // Get a handle to the buffer of restrictions for item
00131   // <src>itemNum</src>.  Throws an exception of type AipsError if
00132   // <src>itemNum</src> is out of range.
00133   virtual AttributeBuffer *elementRestrictionBuffer(const uInt itemNum);
00134 
00135   // Report the minimum and maximum data values for this DisplayData.
00136   // <group>
00137   virtual Double getDataMin();
00138   virtual Double getDataMax();
00139   // </group>
00140 
00141   // sizeControlFunction, called by the WorldCanvasHolder.
00142   virtual Bool sizeControl(WorldCanvasHolder& wcHolder, 
00143                            AttributeBuffer& holderBuf);
00144 
00145   // Position event handler, called by the WorldCanvasHolder.
00146   virtual void positionEH(const WCPositionEvent& ev);
00147 
00148   // Motion event handler, called by the WorldCanvasHolder.
00149   virtual void motionEH(const WCMotionEvent& ev);
00150   
00151   // Refresh event handler, called by the WorldCanvasHolder.
00152   virtual void refreshEH(const WCRefreshEvent& ev); 
00153 
00154   // Clean up, ie. remove cached images etc.
00155   virtual void cleanup();
00156 
00157   // required functions with null implementations
00158   virtual String showPosition(const Vector<Double> &, const Bool &)
00159     { return String(""); }
00160   virtual String showValue(const Vector<Double> &) 
00161     { return String(""); }
00162   virtual Display::DisplayDataType classType()
00163     { return Display::Vector; }
00164   
00165  private:
00166 
00167   void setupStars();
00168   void cleanupStars();
00169   void drawImage(WorldCanvas& wCanvas);
00170   void setScale();
00171   
00172   // General restrictions  (already declared in DisplayData.h)
00173   //  AttributeBuffer restrictions;
00174   //True if nothing should be drawn by the NBody
00175   Bool turnedOff;
00176   
00177   // The min and max to use for drawing
00178   Double dataMin;
00179   Double dataMax;
00180   
00181   Double itsTimeStep;
00182   Double itsDampingFactor;
00183   Int itsNumSteps;
00184   Int itsXSize;
00185   Int itsYSize;
00186   
00187   // internal bookkeeping:
00188   // buffer for stroing sizecontrol done by this NBody
00189   AttributeBuffer sizeControlBuf;
00190   
00191 
00192   // Check if this NBody did the sizeControl
00193   Bool iDidSizeControl(WorldCanvas& wCanvas);
00194 
00195   void drawMovie(WorldCanvas& wCanvas, Int numSteps, Double timeStep, 
00196                  Double dampingFactor);
00197 
00198   Record miscInfoDummy;
00199 
00200   List<void *> itsGalaxyList;
00201   ListIter<void *> *itsGalaxyListIter;
00202   
00203 };
00204 
00205 
00206 } //# NAMESPACE CASA - END
00207 
00208 #endif