Changeset 2013 in Sophya for trunk


Ignore:
Timestamp:
May 24, 2002, 4:54:53 PM (23 years ago)
Author:
lemeur
Message:

amelioration de la projection de localmap

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitslocalmap.cc

    r1371 r2013  
    55//    pout LocalMap
    66///////////////////////////////////////////////////////////
    7 
     7 
    88/*!
    99  \class SOPHYA::FITS_LocalMap
     
    9393    }
    9494  dobj_->ReSize(nSzX, nSzY);
    95   int_4 localMappingDone = dvl.GetI("LCMP");
    96   if (localMappingDone)
    97     {
     95  //  int_4 localMappingDone = dvl.GetI("LCMP");
     96  // if (localMappingDone)
     97  //  {
    9898      int_4 x0 = dvl.GetI("X0");
    9999      int_4 y0 = dvl.GetI("Y0");
     
    105105      double angleY = dvl.GetD("ANGLEY");
    106106      dobj_->SetSize(angleX, angleY);
    107     }
     107      //  }
    108108  // On lit les DataBlocks;
    109109  dobj_->DataBlock().ReSize(nPix);
     
    131131  dvl.SetComment("NPIX", "number of pixels in local map");
    132132
    133   if(dobj_->LocalMap_isDone())
    134     {
    135       dvl["LCMP"] = (int_4) 1;
    136       dvl.SetComment("LCMP", "local mapping 1= done, 0= not done");
     133  // if(dobj_->LocalMap_isDone())
     134  // {
     135  //   dvl["LCMP"] = (int_4) 1;
     136  //   dvl.SetComment("LCMP", "local mapping 1= done, 0= not done");
    137137      int_4 x0 = 0;
    138138      int_4 y0 = 0;
     
    159159      dvl["ANGLEY"] = angleY;
    160160      dvl.SetComment("ANGLEY", "sphere angle covered by map y-extension ");
    161     }
    162   else
    163     {
    164       dvl["LCMP"] = (int_4) 0;
    165     }
     161      // }
     162  // else
     163  //  {
     164  //    dvl["LCMP"] = (int_4) 0;
     165  //  }
    166166  dvl["Content"]= "LocalMap";
    167167  dvl.SetComment("Content", "name of SOPHYA object");
  • trunk/SophyaLib/SkyMap/fiolocalmap.cc

    r1967 r2013  
    22
    33#include "fiolocalmap.h"
     4#include "fioarr.h"
    45#include "pexceptions.h"
    56#include "fiondblock.h"
     
    115116  //  dobj->setSize_y(nSzY);
    116117
    117   int_4 nPix;
    118   is.GetI4(nPix);
     118  // int_4 nPix;
     119  // is.GetI4(nPix);
    119120  //  dobj->setNbPixels(nPix);
    120121  dobj->ReSize(nSzX, nSzY);
    121   string ss("local mapping is done");
    122   string sso;
    123   is.GetStr(sso);
    124   if(sso == ss)
    125     {
    126       cout<<" ReadSelf:: local mapping"<<endl;
    127       int_4 x0, y0;
    128       double theta, phi, angle;
    129       is.GetI4(x0);
    130       is.GetI4(y0);
    131       is.GetR8(theta);
    132       is.GetR8(phi);
    133       is.GetR8(angle);
    134       dobj->SetOrigin(theta, phi, x0, y0, angle);
     122  //  string ss("local mapping is done");
     123  // string sso;
     124  // is.GetStr(sso);
     125  // if(sso == ss)
     126  //  {
     127  //   cout<<" ReadSelf:: local mapping"<<endl;
    135128
    136129      double angleX, angleY;
     
    138131      is.GetR8(angleY);
    139132      dobj->SetSize(angleX, angleY);
    140     }
     133
     134
     135      int_4 x0, y0;
     136      double theta, phi, angle;
     137      is.GetR8(theta);
     138      is.GetR8(phi);
     139      is.GetI4(x0);
     140      is.GetI4(y0);
     141      is.GetR8(angle);
     142      dobj->SetOrigin(theta, phi, x0, y0, angle);
     143
     144      //  }
    141145
    142146// On lit le DataBlock;
    143   FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
     147      //  FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
     148// On lit la matrice;
     149  FIO_TArray<T> fio_nd(&dobj->Matrix());
    144150  fio_nd.Read(is);
    145151}
     
    176182  os.PutI4(nSzX);
    177183  os.PutI4(nSzY);
    178   os.PutI4(nPix);
    179 
    180   if(dobj->LocalMap_isDone())
    181     {
    182       string ss("local mapping is done");
    183       os.PutStr(ss);
    184       int_4 x0, y0;
    185       double theta, phi, angle;
    186       dobj->Origin(theta, phi, x0, y0, angle);
    187       os.PutI4(x0);
    188       os.PutI4(y0);
    189       os.PutR8(theta);
    190       os.PutR8(phi);
    191       os.PutR8(angle);
     184  //  os.PutI4(nPix);
     185
     186  // if(dobj->LocalMap_isDone())
     187  // {
     188  //   string ss("local mapping is done");
     189  //    os.PutStr(ss);
    192190
    193191      double angleX, angleY;
     
    195193      os.PutR8(angleX);
    196194      os.PutR8(angleY);
    197     }
    198   else
    199     {
    200       string ss("no local mapping");
    201       os.PutStr(ss);
    202     }
     195
     196
     197      int_4 x0, y0;
     198      double theta, phi, angle;
     199      dobj->Origin(theta, phi, x0, y0, angle);
     200      os.PutR8(theta);
     201      os.PutR8(phi);
     202      os.PutI4(x0);
     203      os.PutI4(y0);
     204      os.PutR8(angle);
     205
     206      // }
     207// else
     208//  {
     209//   string ss("no local mapping");
     210//   os.PutStr(ss);
     211//  }
    203212
    204213// On ecrit le dataBlock
    205   FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
     214      //  FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
     215// On ecrit la matrice
     216  FIO_TArray<T> fio_nd(&dobj->Matrix());
    206217  fio_nd.Write(os);
    207218}
  • trunk/SophyaLib/SkyMap/localmap.cc

    r1624 r2013  
    77#include <string.h>
    88#include <iostream.h>
     9#include "timing.h"
    910
    1011
    1112/*!
    1213  \class SOPHYA::LocalMap
    13 
    14   A local map has an origin in (theta0, phi0), mapped to pixel(x0, y0)
    15    (x0, y0 might be outside of this local map)
     14  A local map is a 2 dimensional matrix, with ny rows and nx columns.
     15  The local map has an origin in (theta0, phi0), mapped to pixel(x0, y0)
    1616 default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2)
    17     A local map is a 2 dimensional array, with i as column index and j
    18     as row index. The map is supposed to lie on a plan tangent to the
    19     celestial sphere in a point whose coordinates are (x0,y0) on the local
    20    map and (theta0, phi0) on the sphere. The range of the map is defined
    21     by two values of angles covered respectively by all the pixels in
    22     x direction and all the pixels in y direction (SetSize()).
    23 
    24     A "reference plane" is considered : this plane is tangent to the
    25     celestial sphere in a point with angles theta=Pi/2 and phi=0. This
    26     point is the origine of coordinates is of the reference plane. The
    27     x-axis is the tangent parallel to the equatorial line and oriented
    28     toward the increasing phi's ; the y-axis is parallel to the meridian
    29     line and oriented toward the north pole.
     17 Each pixel(ip, it) is defined by its "phi-like" index ip (column
     18 index in the matrix) and its "theta-like" index it (row index in
     19 the matrix). Index ip is associated with x-axis in a map-coordinate
     20 system ; index it is associated with y-axis in the same map-coordinate system.
     21 
     22    The map is supposed to lie on a plan tangent to the celestial sphere
     23    at a point, with spherical coordinates (theta0, phi0), whose pixel
     24    numbers  are (x0,y0) in the local map. The aperture of the map is defined
     25    by two values of angles, angleX and angleY, covered respectively by all
     26    the pixels in x direction and all the pixels in y direction.
     27
     28    Each pixel has angleX/nx and angleY/ny, as angle extensions. So, in
     29    map-coordinate system the pixel (i,j) has following coordinates :
     30
     31    x = (i-x0)*angleX/nx
     32 
     33    y = (j-y0)*angleY/ny
    3034   
    31     Internally, a map is first defined within this reference plane and
    32     tranported until the point (theta0, phi0) in such a way that both
    33     axes are kept parallel to meridian and parallel lines of the sphere.
    34     The user can define its own map with axes rotated with respect to
    35     reference axes (this rotation is characterized by angle between
    36     the local parallel line and the wanted x-axis-- see method
    37     SetOrigin(...))
     35    (angles in radians)
     36
     37    The projection (method : ProjectionToSphere() )of the map onto a
     38    sphere is made by the following procedure :
     39
     40    the sphere is supposed to have radius=1. The map is
     41    considered to be tangent to the sphere, on a point with (theta0, phi0)
     42    spherical coodinates. A reference coordinate system (plane-coordinate
     43    system) , is chosen in the plane of the map  with reference axes :
     44
     45    x-axis : vector tengent to a parallel in (theta0, phi0) on the sphere
     46    (components in "3-dim cartesian system : -sin(phi0) ; cos(phi0) ; 0)
     47
     48    z-axis : vector-radius with 3-dim cartesian cordinates :
     49             sin(theta0)*cos(phi0) ; sin(theta0*sin(phi0) ; cos(theta0)
     50
     51    y-axis = z-axis^x-axis : tangent to the meridian at (theta0, phi0)
     52
     53    note that the map-coordinate system may be rotated with respect to
     54    plane-coordinate system (parameter "angle" below).
     55   
     56    the projection of a map pixel is defined as the intersection of
     57    the vector-radius, from sphere center to the pixel defined by
     58    his coordinates  in the plane-coordinate system (computed from x,y
     59    above, with eventual rotation), with the sphere.
    3860*/
    3961template<class T>
     
    4365}
    4466
    45 template<class T>
    46 LocalMap<T>::LocalMap(int_4 nx, int_4 ny) : nSzX_(nx), nSzY_(ny)
    47 {
    48   InitNul();
    49   nPix_= nx*ny;
    50   pixels_.ReSize(nPix_);
    51   pixels_.Reset();
    52 }
    53 
    54 template<class T>
    55 LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
    56   : pixels_(lm.pixels_, share)
    57 {
    58 
    59   if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
    60   recopierVariablesSimples(lm);
    61 }
    62 
    63 template<class T>
    64 LocalMap<T>::LocalMap(const LocalMap<T>& lm)
    65   : pixels_(lm.pixels_)
    66 
    67 {
    68 
    69   if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
    70   recopierVariablesSimples(lm);
    71 }
    72 
    73 template<class T>
    74 LocalMap<T>::~LocalMap()
    75 {
    76   InitNul();
    77 }
    78 
    79 
    80 
    81 /*!  \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny)
    82 
    83   Resize storage area for pixels
    84 */
    85 template<class T>
    86 void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
     67//! full constructor of the local map
     68/*!
     69  \param nx : number of pixels in x direction
     70  \param ny : number of pixels in y direction
     71  \param angleX : total angle aperture in x direction (degrees)
     72  \param angleY : total angle aperture in y direction (degrees)
     73  \param theta0,phi0 : spherical coordinates of reference point at which
     74                       the map is considered to be tangent to the sphere
     75  \param x0, y0 : coodinates (in pixels) of the reference point just defined
     76  \param angle : angle (degrees) of the rotation between x-axis of
     77                 map-coordinate system) and the tangent to parallel on
     78                 the sphere (default : 0.).
     79 */
     80template<class T>
     81LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle) 
    8782{
    8883  InitNul();
     
    9085  nSzY_ = ny;
    9186  nPix_= nx*ny;
    92   pixels_.ReSize(nPix_);
    93   pixels_.Reset();
     87  pixels_.ReSize(ny,nx);
     88  SetSize(angleX, angleY);
     89  SetOrigin(theta0, phi0, x0, y0, angle);
     90}
     91
     92
     93//! standard constructor of the local map
     94/*!
     95  \param nx : number of pixels in x direction
     96  \param ny : number of pixels in y direction
     97  \param angleX : total angle aperture in x direction (degrees)
     98  \param angleY : total angle aperture in y direction (degrees)
     99  \param theta0,phi0 : spherical coordinates of reference point at which
     100                       the map is considered to be tangent to the sphere
     101  \param angle : angle (degrees) of the rotation between x-axis of
     102                 map-coordinate system) and the tangent to parallel on
     103                 the sphere (default : 0.).
     104 */
     105template<class T>
     106LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
     107{
     108  InitNul();
     109  nSzX_ = nx;
     110  nSzY_ = ny;
     111  nPix_= nx*ny;
     112  pixels_.ReSize(ny,nx);
     113  cout << " tableau pixels initialise " << endl;
     114  SetSize(angleX, angleY);
     115  cout << " fin du setsize " << endl;
     116  SetOrigin(theta0, phi0, angle);
     117  cout << " fin du set oorigine " << endl;
     118}
     119
     120//! copy constructor
     121/*!
     122  \param share : if true, share data. If false copy data
     123 */
     124template<class T>
     125LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
     126  : pixels_(lm.pixels_, share)
     127{
     128
     129  if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
     130  recopierVariablesSimples(lm);
     131}
     132
     133//! copy constructor
     134/*!
     135  \warning datas are \b SHARED with \b lm.
     136  \sa TMatrix::TMatrix(const TMatrix<T>&)
     137*/
     138template<class T>
     139LocalMap<T>::LocalMap(const LocalMap<T>& lm)
     140  : pixels_(lm.pixels_)
     141
     142{
     143
     144  if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
     145  recopierVariablesSimples(lm);
     146}
     147
     148template<class T>
     149LocalMap<T>::~LocalMap() {;}
     150
     151
     152
     153/*!  \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny)
     154
     155  Resize storage area for pixels
     156*/
     157template<class T>
     158void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
     159{
     160    // angles par pixel,  en radians
     161  deltaPhi_   *=  nSzX_/nx;   
     162  deltaTheta_ *=  nSzY_/ny;
     163
     164  nSzX_ = nx;
     165  nSzY_ = ny;
     166  nPix_= nx*ny;
     167  pixels_.ReSize(ny,nx);
    94168}
    95169
     
    122196      recopierVariablesSimples(a);     
    123197  int k;
    124   for (k=0; k< nPix_; k++) pixels_(k) = a.pixels_(k);
     198  pixels_ = a.pixels_;
    125199  return(*this);
    126200
     
    163237  if((k < 0) || (k >= nPix_))
    164238    {
    165       cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
    166       THROW(rangeCheckErr);
    167     }
    168   return(pixels_(k));
     239    throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
     240    }
     241  //
     242  int_4 i,j;
     243  Getij(k,i,j);
     244  return(pixels_(j,i));
     245
     246  //
    169247}
    170248
     
    177255  if((k < 0) || (k >= nPix_))
    178256    {
    179       cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
    180       throw "LocalMap::PIxVal Pixel index out of range";
     257    throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
    181258    }
    182   return *(pixels_.Data()+k);
     259  //
     260  int_4 i,j;
     261  Getij(k,i,j);
     262  return(pixels_(j,i));
    183263}
    184264
     
    197277/*!  \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const
    198278
     279   angles in radians
    199280  \return index of the pixel with spherical coordinates (theta,phi)
    200281*/
     
    203284{
    204285  int_4 i,j;
    205   if(!(originFlag_) || !(extensFlag_))
    206     {
    207       cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
    208       exit(0);
    209     }
    210 
    211   // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference)
    212   double theta_aux= theta;
    213   double phi_aux  = phi;
    214   UserToReference(theta_aux, phi_aux);
    215 
    216   // coordonnees dans le plan local en unites de pixels
    217   double x,y;
    218   AngleProjToPix(theta_aux,phi_aux, x, y);
     286
     287  double csTheta = cos(theta);
     288  double snTheta = sin(theta);
     289  double csPhi   = cos(phi);
     290  double snPhi   = sin(phi);
     291  double csPhiMPhiC = cos (phi - phiC_);
     292  double snPhiMPhiC = sin (phi - phiC_);
     293  // le point sur la sphere est note M.
     294  // intersection P de OM avec le plan de la carte (tangent en C)
     295  double denom = snTheta*snthC_*csPhiMPhiC + csTheta*csthC_;
     296  if ( denom == 0.)
     297    {
     298      throw PException("LocalMap::PixIndexSph : vector radius parallel to map plane ");
     299    }
     300  double lambda = 1./denom;
     301  // coordonnes du point d'intersection P dans le repere lie au plan
     302
     303  double XP = lambda*snTheta*snPhiMPhiC;
     304  double YP = lambda*snTheta*csthC_*csPhiMPhiC;
     305
     306  // coordonnees dans le repere lie a la carte (eventuellement tourne par
     307  // rapport au precedent.
     308
     309  double X = XP*cosAngle_ + YP*sinAngle_;
     310  double Y = -XP*sinAngle_ + YP*cosAngle_;
     311
     312  // en unites de pixels
     313
     314  X /= deltaPhi_;
     315  Y /= deltaTheta_;
     316
    219317
    220318  double xmin= -x0_-0.5;
    221319  double xmax= xmin+nSzX_;
    222   if((x > xmax) || (x < xmin)) return(-1);
     320  if((X > xmax) || (X < xmin)) return(-1);
    223321  double xcurrent= xmin;
    224322  for(i = 0; i < nSzX_; i++ )
    225323    {
    226324      xcurrent += 1.;
    227       if( x < xcurrent ) break;
     325      if( X < xcurrent ) break;
    228326    }
    229327  double ymin= -y0_-0.5;
    230328  double ymax= ymin+nSzY_;
    231   if((y >  ymax) || (y < ymin)) return(-1);
     329  if((Y >  ymax) || (Y < ymin)) return(-1);
    232330  double ycurrent= ymin;
    233331  for(j = 0; j < nSzY_; j++ )
    234332    {
    235333      ycurrent += 1.;
    236       if( y < ycurrent ) break;
     334      if( Y < ycurrent ) break;
    237335    }
    238336  return (j*nSzX_+i);
     
    243341   \return (theta, phi) coordinates of pixel with index k
    244342*/
     343
     344
    245345template<class T>
    246346void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
    247347{
    248   if(!(originFlag_) || !(extensFlag_))
    249     {
    250       cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
    251       exit(0);
    252     }
    253348
    254349  int_4 i,j;
    255350  Getij(k,i,j);
    256351
    257   double X= double(i-x0_);
    258   double Y= double(j-y0_);
    259   // situation de ce pixel dans le plan de reference
    260   double x= X*cos_angle_-Y*sin_angle_;
    261   double y= X*sin_angle_+Y* cos_angle_;
    262   // projection sur la sphere
    263   PixProjToAngle(x, y, theta, phi);
    264   // retour au plan utilisateur
    265   ReferenceToUser(theta, phi);
    266 }
     352  PixThetaPhi(i,j, theta, phi);
     353
     354}
     355
     356/*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
     357
     358
     359   \return (theta, phi) coordinates of pixel of map with indices (ip,it) corresponding to x and y directions
     360
     361 \param ip : phi-like index
     362 \param it : theta-like index
     363*/
     364
     365template<class T>
     366void LocalMap<T>::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
     367{
     368  double XP, YP, ZP;
     369  PixToSphereC(ip,it,XP,YP,ZP);
     370
     371  theta = acos(ZP);
     372  phi = atan2(YP, XP);
     373  while (phi < 0.)  phi += 2.*Pi;
     374
     375}
     376
     377
     378
    267379
    268380/*! \fn T SOPHYA::LocalMap::SetPixels(T v)
     
    273385T LocalMap<T>::SetPixels(T v)
    274386{
    275 pixels_.Reset(v);
     387pixels_ = v;
    276388return(v);
    277389}
     
    281393   Pixel Solid angle  (steradians)
    282394
    283     All the pixels have not necessarly the same size in (theta, phi)
    284     because of the projection scheme which is not yet fixed.
     395   All the pixels are considered to have  the same size in (theta, phi).
     396     
    285397*/ 
    286398template<class T>
    287399double LocalMap<T>::PixSolAngle(int_4 k) const
    288400{
     401  double XP, YP, ZP;
    289402  int_4 i,j;
    290403  Getij(k,i,j);
    291   double X= double(i-x0_);
    292   double Y= double(j-y0_);
    293   double XR= X+double(i)*0.5;
    294   double XL= X-double(i)*0.5;
    295   double YU= Y+double(j)*0.5;
    296   double YL= Y-double(j)*0.5;
    297 
    298   // situation  dans le plan de reference
    299   double x0= XL*cos_angle_-YL*sin_angle_;
    300   double y0= XL*sin_angle_+YL*cos_angle_;
    301   double xa= XR*cos_angle_-YL*sin_angle_;
    302   double ya= XR*sin_angle_+YL*cos_angle_;
    303   double xb= XL*cos_angle_-YU*sin_angle_;
    304   double yb= XL*sin_angle_+YU*cos_angle_;
    305 
    306   // projection sur la sphere
    307   double thet0,phi0,theta,phia,thetb,phib;
    308   PixProjToAngle(x0, y0, thet0, phi0);
    309   PixProjToAngle(xa, ya, theta, phia);
    310   PixProjToAngle(xb, yb, thetb, phib);
     404  PixToSphereC(i,j,XP,YP,ZP);
     405
     406  double theta = acos(ZP);
     407
     408 
    311409
    312410  // angle solide
    313   double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0));
     411
     412  double sol= 2.* deltaPhi_*sin(theta)*sin(0.5*deltaTheta_);
    314413  return sol;
    315414}
    316415
     416/*! \fn void SOPHYA::LocalMap::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP)
     417
     418projection of a pixel of map, onto the unity sphere ; result in cartesian coordinates.
     419*/
     420
     421template<class T>
     422void LocalMap<T>::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
     423{
     424  double X= double(ip-x0_)* deltaPhi_;
     425  double Y= double(it-y0_)*deltaTheta_;
     426
     427    // situation dans le plan de reference tangent
     428  double dx= X*cosAngle_-Y*sinAngle_;
     429  double dy= X*sinAngle_+Y*cosAngle_;
     430
     431  XP = XC_ - dx*snphC_ - dy*csthC_*csphC_;
     432  YP = YC_ + dx*csphC_ - dy*csthC_*snphC_;
     433  ZP = ZC_ + dy*snthC_;
     434
     435  // on renormalise pour eviter les probleme de precision lors
     436  // de la prise ulterieure de lignes trigonometriques
     437  double norme = sqrt(XP*XP + YP*YP + ZP*ZP);
     438  XP /= norme;
     439  YP /= norme;
     440  ZP /= norme;
     441}
     442
    317443/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle)
    318444
     
    324450void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
    325451{
    326   theta0_= theta0;
    327   phi0_  = phi0;
    328   angle_ = angle;
    329   x0_= nSzX_/2;
    330   y0_= nSzY_/2;
    331   cos_angle_= cos(angle*Pi/180.);
    332   sin_angle_= sin(angle*Pi/180.);
    333   originFlag_= true;
    334   cout << " LocalMap:: set origin 1 done" << endl;
     452  SetOrigin(theta0, phi0,  nSzX_/2,  nSzY_/2, angle);
    335453}
    336454 
     
    342460void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
    343461{
    344   theta0_= theta0;
    345   phi0_  = phi0;
    346   angle_ = angle;
     462  // if (originFlag_)
     463  //   {
     464  //     throw PException("LocalMap::SetOrigin : redefining origin is not allowed at the moment ");
     465  //  }
     466
     467  if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.)
     468    {
     469      throw "LocalMap::SetOrigin  angle out of range";
     470    }
     471  SetCoorC(theta0,phi0);
     472  angleDegres_ = angle;
     473  // en radians
     474  angle_ = angle*Pi/180.;
    347475  x0_= x0;
    348476  y0_= y0;
    349   cos_angle_= cos(angle*Pi/180.);
    350   sin_angle_= sin(angle*Pi/180.);
    351   originFlag_= true;
    352   cout << " LocalMap:: set origin 2 done" << endl;
     477  cosAngle_= cos(angle_);
     478  sinAngle_= sin(angle_);
    353479}
    354480
     481template<class T>
     482void LocalMap<T>::SetCoorC(double theta0, double phi0)
     483{
     484
     485  thetaDegresC_ = theta0;
     486  phiDegresC_ = phi0;
     487
     488  // passage en radians
     489  thetaC_= theta0*Pi/180.;
     490  phiC_  = phi0*Pi/180.;
     491  csthC_ = cos(thetaC_);
     492  snthC_ = sin(thetaC_);
     493  csphC_ = cos(phiC_);
     494  snphC_ = sin(phiC_);
     495  XC_ = snthC_*csphC_;
     496  YC_ = snthC_*snphC_;
     497  ZC_ = csthC_;
     498}
     499
     500
     501// angles en RADIANS
     502template<class T>
     503TMatrix<double> LocalMap<T>::CalculMatricePassage()
     504{
     505  cout << " calcul matrice de passage " << endl;
     506  TMatrix<double> passage(3,3);
     507  double cos_th_axeZ;
     508  double sin_th_axeZ;
     509  double cos_phi_axeZ;
     510  double sin_phi_axeZ;
     511
     512  double cth,sth, cdeltaPhi, phi, cphi, sphi;
     513
     514  if ( snthC_ <= 0.) // carte centree au pole
     515    {
     516      cos_th_axeZ = 1.;
     517      sin_th_axeZ = 0.;
     518      cos_phi_axeZ = 1.;
     519      sin_phi_axeZ = 0.;
     520     
     521    }
     522  else
     523    {
     524      cth = cosAngle_*snthC_;
     525      double arg = 1.-cth*cth;
     526      if (arg <= 0. ) // carte centree sur l'equateur, sans rotation
     527        {
     528          cos_th_axeZ = 1.;
     529          sin_th_axeZ = 0.;
     530          cos_phi_axeZ = csphC_;
     531          sin_phi_axeZ = snphC_;
     532        }
     533      else
     534        {
     535          sth = sqrt(arg);
     536          cdeltaPhi = -csthC_*cth/(snthC_*sth);
     537          if (cdeltaPhi < -1. ) cdeltaPhi = -1.;
     538          if (cdeltaPhi > 1. ) cdeltaPhi = 1.;
     539          phi = phiC_ + acos( cdeltaPhi );
     540
     541          cos_th_axeZ = cth;
     542          sin_th_axeZ = sth;
     543          cos_phi_axeZ = cos(phi);
     544          sin_phi_axeZ = sin(phi);
     545        }
     546    }
     547  passage(0,0) = snthC_*csphC_;
     548  passage(1,0) = snthC_*snphC_;
     549  passage(2,0) = csthC_;
     550
     551  passage(0,2) = sin_th_axeZ*cos_phi_axeZ;
     552  passage(1,2) = sin_th_axeZ*sin_phi_axeZ;
     553  passage(2,2) = cos_th_axeZ;
     554
     555  passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0);
     556  passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0);
     557  passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0);
     558
     559  //  passage.Print(cout);
     560  // cout << " fin calcul passage " << endl;
     561
     562  return passage;
     563
     564
     565}
     566
    355567/*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY)
    356568
     
    360572void LocalMap<T>::SetSize(double angleX,double angleY)
    361573{
    362   angleX_= angleX;
    363   angleY_= angleY;
    364 
    365   // tangente de la moitie de l'ouverture angulaire totale
    366   tgAngleX_= tan(0.5*angleX_*Pi/180.);
    367   tgAngleY_= tan(0.5*angleY_*Pi/180.);
    368 
    369   extensFlag_= true;
    370   cout << " LocalMap:: set extension done" << endl;
    371 }
    372 
    373 /*! \fn void SOPHYA::LocalMap::Project(SphericalMap<T>& sphere) const
     574  if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.)
     575    {
     576      throw "LocalMap::SetSize extension angle out of range";
     577    }
     578
     579  angleDegresX_ = angleX;
     580  angleDegresY_ = angleY;
     581  // angles par pixel,  en radians
     582  cout << " taille x " << nSzX_ <<"  taille y " << nSzY_ << endl;
     583  deltaPhi_   = angleX*Pi/(180.*nSzX_);
     584  deltaTheta_ = angleY*Pi/(180.*nSzY_);
     585
     586
     587}
     588
     589
     590
     591/*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const
    374592
    375593Projection to a spherical map
    376594*/
    377595template<class T>
    378 void LocalMap<T>::Project(SphericalMap<T>& sphere) const
    379 {
    380   for(int m = 0; m < nPix_; m++)
    381     {
    382       double theta,phi;
    383       PixThetaPhi(m,theta,phi);
    384       sphere(theta,phi)= pixels_(m);
    385       // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl;
    386     }
    387 }
     596void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const
     597{
     598   double theta, phi;
     599  int it, ip;
     600   for (it = 0; it < nSzY_; it++)
     601    {
     602      for (ip = 0; ip < nSzX_; ip++)
     603        {
     604          PixThetaPhi(ip,it, theta, phi);
     605          sphere(theta,phi)= pixels_(it, ip);
     606        }
     607    }
     608}
     609
     610
     611
    388612// Titre        Private Methods
    389613//++
     
    391615void LocalMap<T>::InitNul()
    392616//
    393 //    set some attributes to zero
     617//    set attributes to zero
    394618//--
    395619{
    396   originFlag_= false;
    397   extensFlag_= false;
    398   cos_angle_= 1.0;
    399   sin_angle_= 0.0;
    400 //  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
     620  nSzX_ = 0;
     621  nSzY_ = 0;
     622  angleDegresX_ = 0.;
     623  angleDegresY_ = 0.;
     624  thetaDegresC_ = 0.;
     625  phiDegresC_   = 0.;
     626  x0_ = 0;
     627  y0_ = 0;
     628  angleDegres_ = 0.;
     629
     630
     631  nPix_ = 0;
     632
     633  thetaC_ = 0.;
     634  phiC_   = 0.;
     635  csthC_  = 1.;
     636  snthC_  = 0.;
     637  csphC_  = 1.;
     638  snphC_  = 0.;
     639  XC_     = 0.;
     640  YC_     = 0.;
     641  ZC_     = 1.;
     642
     643  angle_      = 0.;
     644  cosAngle_   = 1.;
     645  sinAngle_   = 0.;
     646  deltaPhi_   = 0.;
     647  deltaTheta_ =0.;
    401648}
    402649
     
    414661}
    415662
    416 /*! \fn void  SOPHYA::LocalMap::ReferenceToUser(double& theta,double& phi) const
    417 
    418    Transform a pair of coordinates (theta, phi) given in
    419     reference coordinates into map coordinates
    420 */
    421 template<class T>
    422 void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const
    423 {
    424   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
    425     {
    426       throw "LocalMap::ReferenceToUser (theta,phi) out of range";
    427     }
    428 
    429   theta= theta0_*Pi/180.+theta-Pi*0.5;
    430   if(theta < 0.)
    431     {
    432       theta= -theta;
    433       phi += Pi;
    434     }
    435   else
    436     {
    437       if(theta > Pi)
    438         {
    439           theta= 2.*Pi-theta;
    440           phi += Pi;
    441         }
    442     }
    443 
    444   phi= phi0_*Pi/180.+phi;
    445   while(phi >= 2.*Pi) phi-= 2.*Pi;
    446 
    447   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
    448     {
    449       cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl;
    450       cout << " theta= " << theta << " phi= " << phi << endl;
    451       exit(0);
    452     }
    453 }
    454 
    455 /*!  \fn void  SOPHYA::LocalMap::UserToReference(double& theta,double& phi) const
    456 
    457   Transform a pair of coordinates (theta, phi) given in
    458    map coordinates into reference coordinates
    459 */
    460 template<class T>
    461 void  LocalMap<T>::UserToReference(double& theta,double& phi) const
    462 {
    463   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
    464     {
    465       cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl;
    466       // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
    467       throw "LocalMap::UserToReference (theta,phi) out of range";
    468     }
    469 
    470   double phi1= phi-phi0_*Pi/180.;
    471   if(phi1 < 0.) phi1+= 2.*Pi;
    472 
    473   double theta1= theta-theta0_*Pi/180.+Pi*0.5;
    474   if(theta1 < 0.)
    475     {
    476       theta= -theta1;
    477       phi1+= Pi;
    478     }
    479   else
    480     {
    481       if(theta1 > Pi)
    482         {
    483           theta= 2.*Pi-theta1;
    484           phi1+= Pi;
    485         }
    486     }
    487 
    488   while(phi1 >= 2.*Pi) phi1-= 2.*Pi;
    489   phi= phi1;
    490   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
    491     {
    492       cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl;
    493       cout << " theta= " << theta << " phi= " << phi << endl;
    494       exit(0);
    495     }
    496 }
    497 
    498 /*! \fn void SOPHYA::LocalMap::PixProjToAngle(double x,double y,double& theta,double& phi) const
    499 
    500   Given coordinates in pixel units in the REFERENCE PLANE, return
    501     (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.   
    502 */
    503 template<class T>
    504 void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const
    505 {
    506   theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_);
    507   phi= atan2(2.*x*tgAngleX_,(double)nSzX_);
    508   if(phi < 0.) phi += DeuxPi;
    509 }
    510 
    511 /*! \fn void SOPHYA::LocalMap::AngleProjToPix(double theta,double phi,double& x,double& y) const
    512 
    513    Given coordinates  (theta, phi) in "absolute" referential
    514     theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE.
    515 */
    516 template<class T>
    517 void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const
    518 {
    519   if(phi >= Pi) phi-= DeuxPi;
    520   //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$
    521   y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ? 
    522   x= 0.5*nSzX_*tan(phi)/tgAngleX_;
    523 }
     663
     664
     665
     666
    524667
    525668template<class T>
     
    527670{
    528671  os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
    529   if(LocalMap_isDone())
    530     {
    531       os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl;
     672      os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl;
    532673      os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
    533       os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl;
    534       os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl;
    535       os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl;
    536     }
     674      os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl;
     675      os<<"  deltaPhi_= "<<  deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl;
     676      os <<endl;
    537677
    538678  os << " contenu de pixels : ";
     
    540680    {
    541681      if(i%5 == 0) os << endl;
    542       os <<  pixels_(i) <<", ";
     682  int_4 ik,jk;
     683  Getij(i,ik,jk);
     684      os <<  pixels_(jk,ik) <<", ";
    543685    }
    544686  os << endl;
     
    549691void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
    550692{
    551   nSzX_= lm.nSzX_;
    552   nSzY_= lm.nSzY_;
    553   nPix_= lm.nPix_;
    554   originFlag_= lm.originFlag_;
    555   extensFlag_= lm.extensFlag_;
    556   x0_= lm.x0_;
    557   y0_= lm.y0_;
    558   theta0_= lm.theta0_;
    559   phi0_= lm.phi0_;
     693
     694  nSzX_ = lm.nSzX_;
     695  nSzY_ = lm.nSzY_;
     696  nPix_ = lm.nPix_;
     697  x0_   = lm.x0_;
     698  y0_   = lm.y0_;
     699
     700  thetaC_ = lm.thetaC_;
     701  phiC_   = lm.phiC_;
     702  csthC_  = lm.csthC_;
     703  snthC_  = lm.snthC_;
     704  csphC_  = lm.csphC_;
     705  snphC_  = lm.snphC_;
     706  XC_     = lm.XC_;
     707  YC_     = lm.YC_;
     708  ZC_     = lm.ZC_;
     709
    560710  angle_= lm.angle_;
    561   cos_angle_= lm.cos_angle_;
    562   sin_angle_= lm.sin_angle_;
    563   angleX_= lm.angleX_;
    564   angleY_= lm.angleY_;
    565   tgAngleX_= lm.tgAngleX_;
    566   tgAngleY_= lm.tgAngleY_;
     711  cosAngle_  = lm.cosAngle_;
     712  sinAngle_  = lm.sinAngle_;
     713  deltaPhi_  = lm. deltaPhi_;
     714  deltaTheta_ = lm.deltaTheta_;
    567715}
    568716
     
    654802    throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ;
    655803    }
    656   pixels_ *= a.pixels_;
     804  //  pixels_ *= a.pixels_;
     805  pixels_.DataBlock() *= a.pixels_.DataBlock();
    657806  return (*this);
    658807}
     
    666815    throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ;
    667816    }
    668   pixels_ /= a.pixels_;
     817  //  pixels_ /= a.pixels_;
     818  pixels_.DataBlock() /= a.pixels_.DataBlock();
    669819  return (*this);
    670820}
     
    673823
    674824
    675 
    676 //++
    677 // Titre        class FIO_LocalMap
    678 //    Delegated objects for persitance management
    679 //--
    680825
    681826
  • trunk/SophyaLib/SkyMap/localmap.h

    r1624 r2013  
    1919
    2020
     21template <class T>
     22class FIO_LocalMap;
     23
     24template<class T>
     25class FITS_LocalMap;
     26
    2127/* Class LocalMap */
    2228
     
    2632{
    2733
     34 // friend declaration for classes which handle persistence and FITS IO
     35  friend class FIO_LocalMap<T>;
     36  friend class FITS_LocalMap<T>;
     37
    2838public:
    2939
    3040LocalMap();
    31 LocalMap(int_4 nx, int_4 ny);
     41LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle=0.);
     42LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle=0.);
    3243LocalMap(const LocalMap<T>& lm, bool share);
    3344LocalMap(const LocalMap<T>& lm);
     
    6980inline virtual char* TypeOfMap() const {return "LOCAL";};
    7081 
    71 virtual void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
    72 virtual void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.);
    73 
    74 virtual void SetSize(double angleX,double angleY);
    7582
    7683/*! Check to see if the local mapping is done */
    77 inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
    78 
    79 virtual void Project(SphericalMap<T>& sphere) const;
     84  //inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
     85
     86void PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const;
     87
     88
     89void ProjectionToSphere(SphericalMap<T>&) const;
    8090 
    8191/* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
     
    92102inline int_4 SizeY() const {return nSzY_;}
    93103
    94 inline void Origin(double& theta,double& phi,int_4& x0,int_4& y0,double& angle) const {theta= theta0_; phi= phi0_; x0= x0_; y0= y0_;angle= angle_;}
    95 
    96 inline void Aperture(double& anglex,double& angley) const {anglex= angleX_; angley= angleY_;}
     104inline void Origin(double& theta,double& phi,int_4& x0,int_4& y0,double& angle) const {theta= thetaDegresC_; phi= phiDegresC_; x0= x0_; y0= y0_;angle= angleDegres_;}
     105
     106/*! total aperture in theta and phi, in degrees ( from SetSize() ) */
     107inline void Aperture(double& anglex,double& angley) const {anglex= angleDegresX_; angley= angleDegresY_;}
    97108
    98109
    99110/*  Acces to the DataBlock  */
    100 inline       NDataBlock<T>& DataBlock()       {return pixels_;}
    101 inline const NDataBlock<T>& DataBlock() const {return pixels_;}
     111inline       NDataBlock<T>& DataBlock()       {return pixels_.DataBlock();}
     112inline const NDataBlock<T>& DataBlock() const {return pixels_.DataBlock();}
     113
     114/*  Acces to the matrix  */
     115//! access to matrix
     116/*!
     117  \warning : a pixel is defined by the pair of a phi-like index
     118   (x-axis) and a theta-like index (y-axis). The phi-like index denotes
     119   the column number in the matrix ; the theta-like index denotes the
     120   row number.
     121*/
     122inline       TMatrix<T>& Matrix()       {return pixels_;}
     123inline const TMatrix<T>& Matrix() const {return pixels_;}
    102124
    103125/* impression */
     
    156178
    157179void InitNul();
     180void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
     181void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.);
     182void SetSize(double angleX,double angleY);
     183void SetCoorC(double theta0, double phi0);
     184TMatrix<double> CalculMatricePassage();
    158185void Getij(int_4 k,int_4& i,int_4& j) const;
    159 void ReferenceToUser(double& theta,double& phi) const;
    160 void UserToReference(double& theta,double& phi) const;
    161 void PixProjToAngle(double x,double y,double& theta,double& phi) const;
    162 void AngleProjToPix(double theta,double phi,double& x,double& y) const;
     186  void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const;
    163187
    164188void recopierVariablesSimples(const LocalMap<T>& lm);
     
    167191// ---------- Variables internes ----------------------------
    168192
    169 int_4 nSzX_;
    170 int_4 nSzY_;
    171 int_4 nPix_;
    172 bool originFlag_;
    173 bool extensFlag_;
    174 int_4 x0_;
    175 int_4 y0_;
    176 double theta0_;
    177 double phi0_;
    178 double angle_;
    179 double cos_angle_;
    180 double sin_angle_;
    181 double angleX_;
    182 double angleY_;
    183 double tgAngleX_;
    184 double tgAngleY_;
    185 NDataBlock<T> pixels_;
     193
     194  // variables suffisantes pour reconstruire l'objet
     195
     196  int_4 nSzX_;
     197  int_4 nSzY_;
     198  double angleDegresX_;
     199  double angleDegresY_;
     200  double thetaDegresC_;
     201  double phiDegresC_;
     202  int_4 x0_;
     203  int_4 y0_;
     204  double angleDegres_;
     205
     206  //  NDataBlock<T> pixels_;
     207  TMatrix<T> pixels_;
     208
     209
     210  // variables derivees (redondantes, precalculees pour ameliorer
     211  // les performances)
     212
     213  int_4 nPix_;
     214
     215
     216  double thetaC_;
     217  double phiC_;
     218  double csthC_;
     219  double snthC_;
     220  double csphC_;
     221  double snphC_;
     222  double XC_;
     223  double YC_;
     224  double ZC_;
     225
     226
     227  double angle_;
     228  double cosAngle_;
     229  double sinAngle_;
     230  double deltaPhi_;
     231  double deltaTheta_;
     232
     233
     234
    186235};
    187236
Note: See TracChangeset for help on using the changeset viewer.