Changeset 1540 in Sophya for trunk/SophyaPI/ProgPI


Ignore:
Timestamp:
Jun 18, 2001, 3:12:33 PM (24 years ago)
Author:
ansari
Message:

Fin (provisoire) commandes sortie PS + trace grille molleweide - Reza 18/6/2001

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/ProgPI/sopiamodule.cc

    r1481 r1540  
    2121#include "ctimer.h"
    2222
     23#include "pidrawer.h"
     24#include "nomgadapter.h"
     25
    2326extern "C" {
    2427void sopiamodule_init();
     
    3538};
    3639
     40//  Classe pour trace de grille en projection spherique Mollweide
     41class MollweideGridDrawer : public PIDrawer {
     42public:
     43                    MollweideGridDrawer(int np, int nm, int nx, int ny);
     44                    MollweideGridDrawer(int np, int nm, double x_larg=0., double x_0=0.,
     45                                        double y_larg=0., double y_0=0.);
     46  virtual           ~MollweideGridDrawer();
     47  virtual void      Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
     48  virtual void      UpdateLimits();
     49
     50protected:
     51  double xlarg, x0;
     52  double ylarg, y0;
     53  int nbparall, nbmerid;
     54  int nbpt;
     55  bool fgrevtheta;
     56};
     57
     58/* --Methode-- */
     59MollweideGridDrawer::MollweideGridDrawer(int np, int nm, int nx, int ny)
     60{
     61  x0 = (double)nx/2.;
     62  y0 = (double)ny/2.;
     63  xlarg = nx; 
     64  ylarg = ny;
     65  nbparall = np;
     66  nbmerid = nm;
     67  nbpt = ny/5;
     68  if ((nbpt % 20) == 0) nbpt++; 
     69  fgrevtheta = true;
     70}
     71
     72/* --Methode-- */
     73MollweideGridDrawer::MollweideGridDrawer(int np, int nm, double x_larg, double x_0,
     74                                         double y_larg, double y_0)
     75{
     76  if (x_larg > 0.) {
     77    xlarg = x_larg; x0 = x_0;
     78  }
     79  else {
     80    xlarg = M_PI*2.;  x0 = M_PI;
     81  }
     82  if (y_larg > 0.) {
     83    ylarg = y_larg; y0 = y_0;
     84  }
     85  else {
     86    ylarg = M_PI;  y0 = 0.;
     87  }
     88  nbparall = np;
     89  nbmerid = nm;
     90  nbpt = 101;
     91  fgrevtheta = false;
     92}
     93
     94/* --Methode-- */
     95MollweideGridDrawer::~MollweideGridDrawer()
     96{
     97}
     98
     99/* --Methode-- */
     100void MollweideGridDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
     101{
     102  PIGrCoord * xxl = new PIGrCoord[nbpt];
     103  PIGrCoord * xxr = new PIGrCoord[nbpt];
     104  PIGrCoord * yy = new PIGrCoord[nbpt];
     105
     106  char buff[64];
     107
     108  // Trace des paralleles
     109  g->DrawLine(xmin, y0, xmax, y0);
     110  g->DrawString(x0+xlarg/100, y0+ylarg/100, "0");
     111
     112  //  PIGrCoord asc, PIGrCoord desc;
     113  int i,k;
     114
     115  int nkp = (nbparall-1)/2;
     116  if (nkp > 0) {
     117    double dy = 0.5*ylarg/(double)(nkp+1);
     118    double dtd = 90./(double)(nkp+1);
     119    for(k=1; k<=nkp; k++) {
     120      double fx = sin(acos(2.*(double)k*dy/ylarg))*0.5;
     121      double yc = k*dy+y0;
     122      g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
     123      double ctd = (fgrevtheta) ? -dtd*k : dtd*k;
     124      sprintf(buff, "%5.1f", ctd);
     125      g->DrawString(x0, yc, buff);
     126      g->DrawString(x0-0.3*xlarg, yc, buff);
     127      g->DrawString(x0+0.25*xlarg, yc, buff);
     128      yc = -k*dy+y0;
     129      g->DrawLine(x0-fx*xlarg, yc, x0+fx*xlarg, yc);
     130      sprintf(buff, "%5.1f", -ctd);
     131      g->DrawString(x0, yc, buff);
     132      g->DrawString(x0-0.3*xlarg, yc, buff);
     133      g->DrawString(x0+0.25*xlarg, yc, buff);
     134    }
     135  }
     136
     137  // Trace des meridiennes
     138  g->DrawLine(x0, ymin, x0, ymax);
     139
     140  int nkm = (nbmerid-1)/2;
     141  if (nkm < 1)  nkm = 1;
     142  double dphi = M_PI/nkm;
     143  double dpd = 180./(double)(nkm);
     144  double dy = ylarg/(nbpt-1);
     145  for(k=0; k<nkm; k++) {
     146    double phi0 = k*dphi;
     147    double dphimil = fabs(phi0-M_PI);
     148    if (dphimil < 1.e-6)  continue;
     149    for(i=0; i<nbpt; i++) {
     150      double yc = (double)i*dy+y0-0.5*ylarg;
     151      double fx = (2.*fabs(yc-y0)/ylarg <= 1.) ?
     152        sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5 : 0.;
     153      yy[i] = yc;
     154      xxl[i] = x0-fx*xlarg;
     155      xxr[i] = x0+fx*xlarg;
     156    }
     157
     158    g->DrawPolygon(xxl, yy, nbpt, false);
     159    g->DrawPolygon(xxr, yy, nbpt, false);
     160
     161    if (k == 0)  continue;
     162    for(i=-1; i<=1; i++) {
     163      double yc = 0.20*i*ylarg+y0;
     164      double fx = sin(acos(2.*fabs(yc-y0)/ylarg)) * dphimil/M_PI * 0.5;
     165      double xc = x0-fx*xlarg;
     166      sprintf(buff, "%4.1f", dpd*k);
     167      g->DrawString(xc, yc, buff);
     168      xc = x0+fx*xlarg;
     169      sprintf(buff, "%4.1f", 360.-dpd*k);
     170      g->DrawString(xc, yc, buff);
     171    }
     172  }
     173
     174  delete [] xxl;
     175  delete [] xxr;
     176  delete [] yy;
     177}
     178
     179/* --Methode-- */
     180void MollweideGridDrawer::UpdateLimits()
     181{
     182  SetLimits(x0-xlarg/2., x0+xlarg/2., y0-ylarg/2., y0+ylarg/2.);
     183}
     184
    37185/* --Methode-- */
    38186sopiamoduleExecutor::sopiamoduleExecutor()
     
    47195string usage = "FFT on a vector -> Plots power spectrum ";
    48196usage += "\n Usage: fftp vecName vecFFT [graphic_att] ";
     197mpiac->RegisterCommand(kw, usage, this, hgrp);
     198kw = "mollgridsph";
     199usage = "Creates a spherical coordinate grid in Molleweide projection ";
     200usage += "\n Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att] ";
     201mpiac->RegisterCommand(kw, usage, this, hgrp);
     202kw = "mollgrid";
     203usage = "Creates a spherical coordinate grid in Molleweide projection ";
     204usage += "\n Usage: mollgrid [Nb_Parallel Nb_Meridien graphic_att] ";
    49205mpiac->RegisterCommand(kw, usage, this, hgrp);
    50206
     
    68224  SophyaFFT(tokens[0], tokens[1], tokens[2]);
    69225  }
     226 else if ( (kw == "mollgridsph") || (kw == "mollgrid") ) {
     227   NamedObjMgr omg;
     228   MollweideGridDrawer * mollgrid = NULL;
     229   string dopt="";
     230   if (kw == "mollgridsph") {
     231     if (tokens.size() < 1) {
     232       cout << "Usage: mollgridsph NameSphericalMap [Nb_Parallel Nb_Meridien graphic_att]"
     233            << endl;
     234       return(0);
     235     }
     236     int np = 5;
     237     int nm = 5;
     238     dopt = "same,thinline";
     239     if (tokens.size() > 1)  np = atoi(tokens[1].c_str());
     240     if (tokens.size() > 2)  nm = atoi(tokens[2].c_str());
     241     if (tokens.size() > 3)  dopt = tokens[3];
     242     NObjMgrAdapter* obja = omg.GetObjAdapter(tokens[0]);
     243     if (obja == NULL) {
     244       cout << "mollgridsph Error , No object with name " << tokens[0] << endl;
     245       return(0);
     246     }
     247     P2DArrayAdapter* arr = obja->Get2DArray(dopt);
     248     if (arr == NULL) {
     249       cout << "mollgridsph Error , object has non 2DArrayAdapter - Not a spherical map "
     250            << endl;
     251       return(0);       
     252     }
     253     int nx = arr->XSize();
     254     int ny = arr->YSize();
     255     delete arr;
     256     mollgrid = new MollweideGridDrawer(np, nm, nx, ny);
     257     cout << " mollgridsph: Creating MollweideGridDrawer() for object" << tokens[0] << endl;
     258   }
     259   else if (kw == "mollgrid") {
     260     int np = 5;
     261     int nm = 5;
     262     if (tokens.size() > 0)  np = atoi(tokens[0].c_str());
     263     if (tokens.size() > 1)  nm = atoi(tokens[1].c_str());
     264     if (tokens.size() > 2)  dopt = tokens[2];
     265     mollgrid = new MollweideGridDrawer(np, nm);
     266     cout << " mollgrid: Creating MollweideGridDrawer(" << np << "," << nm << ")" << endl;
     267   }
     268
     269   if (mollgrid == NULL) {
     270     cout << "mollgridsph Error/BUG !!! mollgrid = NULL "  << endl;
     271     return(0);
     272   }
     273
     274   int wrsid = 0;
     275   bool fgsr = true;
     276   int opt = omg.GetServiceObj()->DecodeDispOption(dopt, fgsr);
     277   
     278   string name = "mollgrid";
     279   wrsid = omg.GetImgApp()->DispScDrawer(mollgrid, name, opt);
     280   if (fgsr) omg.GetImgApp()->RestoreGraphicAtt();   
     281 }
    70282
    71283return(0);
Note: See TracChangeset for help on using the changeset viewer.