casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Galaxy.h
Go to the documentation of this file.
00001 //# Galaxy.h: Simple classes for galaxies and stars
00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999
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_GALAXY_H
00029 #define TRIALDISPLAY_GALAXY_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Vector.h>
00033 #include <casa/Arrays/Matrix.h>
00034 #include <casa/Containers/List.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 class PixelCanvas;
00039 
00040 // <summary>
00041 // Simple class to represent a Galaxy as a collection of Stars.
00042 // </summary>
00043 
00044 class Galaxy {
00045 
00046  public:
00047   
00048   enum PLOT_MODE {
00049     POSITION,
00050     VELOCITY
00051   };
00052   
00053   // Constructor
00054   Galaxy(Vector<Double>& position, Vector<Double>& velocity, Double mass,
00055          Double size, uInt numStars, uInt numRings, Double inclination, 
00056          Double positionAngle, Int xSize, Int ySize);
00057 
00058   // Destructor
00059   ~Galaxy();
00060 
00061   // Compute a new position, applying the force of the Galaxies in the List
00062   // but do not update current position and velocity
00063   void computeStep(List<void *>& galaxyList, Double timeStep, 
00064                   Double dampingFactor = 1.0);
00065 
00066   // update position and velocity to new value
00067   void update();
00068   
00069   // Compute a new position for the Stars in this Galaxy
00070   void applyForceToStars(List<void *>& galaxyList, Double timeStep,
00071                          Double dampingFactor);
00072   
00073   // Rotate position and velocity
00074   void rotate(Matrix<Double>& rotMatrix);
00075 
00076   // Draw the Galaxy on the PixelCanvas
00077   void draw(PixelCanvas *pixelCanvas);
00078 
00079   // magnitude of the force for this galaxy
00080   Double force(Double distance);
00081   
00082   // Return the Mass of the Galaxy
00083   Double getMass();
00084 
00085   // Return the position of the Galaxy
00086   Vector<Double>& getPosition();
00087   
00088   // Return the Velocity of the Galaxy
00089   Vector<Double>& getVelocity();
00090 
00091   // Set the plot mode
00092   void setPlotMode(Galaxy::PLOT_MODE plotMode);
00093 
00094   void setScale(Int xSize, Int ySize)   ;
00095 
00096  private:
00097 
00098   // The mass of the Galaxy
00099   Double itsMass;  
00100 
00101   // its size
00102   Double itsSize;
00103 
00104   // The position of the Galaxy
00105   Vector<Double> itsPosition;
00106 
00107   // The velocity of the Galaxy
00108   Vector<Double> itsVelocity;
00109 
00110 
00111   // The new computed position of the Galaxy
00112   Vector<Double> newPosition;
00113 
00114   // The new computed velocity of the Galaxy
00115   Vector<Double> newVelocity;
00116 
00117   // The list of Stars in this Galaxy
00118   List<void *>   itsStarList;
00119   // and an iterator for this List
00120   
00121   ListIter<void *> *itsStarListIter;
00122   
00123   Vector<Int> oldPosition;
00124   // Last offset applied to itsPosition
00125   Vector<Int> itsOffset;
00126   // Last offset applied to itsPosition
00127   Vector<Int> itsPlotPosition;
00128 
00129   Int itsXSize;
00130   Int itsYSize;
00131   
00132   // Number of the draw list for the current PixelCanvas
00133   uInt           itsDrawList;
00134 
00135   PixelCanvas    *itsPixelCanvas;
00136 
00137   Galaxy::PLOT_MODE plotMode;
00138   
00139   Bool changedPlotMode;
00140 };
00141 
00142 // <summary>
00143 // Simple class which represents a star as a point mass.
00144 // </summary>
00145 
00146 class Star {
00147 
00148  public:
00149 
00150   // Constructor
00151   Star(Vector<Double>& position, Vector<Double>& velocity, 
00152        Int xSize, Int ySize);
00153 
00154   // Destructor
00155   ~Star();
00156 
00157   // Draw the current position on the PixelCanvas
00158   void draw(PixelCanvas *pixelCanvas);
00159 
00160   // Compute new position by applying the forces of the Galaxies in the List
00161   void applyForce(List<void *>& galaxyList, Double timeStep, 
00162                   Double dampingFactor);
00163 
00164   // Rotate position and velocity
00165   void rotate(Matrix<Double>& rotMatrix);
00166 
00167   // Set the plot mode
00168   void setPlotMode(Galaxy::PLOT_MODE newPlotMode);
00169   
00170   void setScale(Int xSize, Int ySize)   ;
00171 
00172  private:
00173 
00174   // Position of the Star
00175   Vector<Double> itsPosition;
00176   // The last drawn position of the Star 
00177   Vector<Int> oldPosition;
00178   // Last offset applied to itsPosition
00179   Vector<Int> itsOffset;
00180   // Last offset applied to itsPosition
00181   Vector<Int> itsPlotPosition;
00182 
00183   // Velocity of the Star
00184   Vector<Double> itsVelocity;
00185 
00186   Int itsXSize;
00187   Int itsYSize;
00188   
00189   // Number of the draw list for the current PixelCanvas
00190   uInt           itsDrawList;
00191 
00192   // Temp to check if we are drawing on a new PixelCanvas
00193   PixelCanvas    *itsPixelCanvas;
00194 
00195   Galaxy::PLOT_MODE plotMode;
00196   
00197   Bool changedPlotMode;
00198 };
00199 
00200 
00201 } //# NAMESPACE CASA - END
00202 
00203 #endif