ROOT logo
// $Id: AEVMapViz.cxx 2824 2012-07-15 19:26:02Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

//__________________________________________________________________________
// AEVMapViz
//
//

#include "AEVMapViz.h"
#include <Glasses/ZImage.h>
#include "AEVSite.h"
#include "AEVMapViz.c7"
#include "AEVSiteViz.h"

#include <Glasses/AEVFlatSSpace.h>
#include <Glasses/AEVSite.h>
#include <Glasses/ZQueen.h>

ClassImp(AEVMapViz);

/**************************************************************************/

void AEVMapViz::_init()
{}

/**************************************************************************/

namespace {

  struct sub_map {
    const char* n;
    float x0, y0, dx, dy;
    // These are for placement only.
    float sx, sy;
    float ox, oy;
  };

  // Due to cosmic interferences this is scaled as (xs,ys) = (7,3.5).
  sub_map sub_map_list[] = {
    { "Europe",	 0.30,  0.95, 1.10, 0.70, 0,   0,   0,   0   },
    { "India",	 1.60,  0.35, 0.60, 0.50, 0.8, 0.8, 0,   0.5 },
    { "NE-USA",	-1.62,  0.82, 0.20, 0.20, 0.5, 1,   0.2, 0.2 },
    { "SE-USA",	-1.83,  0.60, 0.20, 0.20, 0.5, 1,   0.2, 0.2 },
    { "NW-USA",	-2.39,  0.73, 0.20, 0.20, 0.5, 1,   0.2, 0.2 },
    { 0 }
  };

}

void AEVMapViz::CutEarth_PDC04(ZImage* tex)
{
  // Creates chunks of Earth-map relevant for Alice PDC04.
  // Uses static (hardcoded) data to produce visually pleasing result.
  // Should be called at initialization time ... not MIR-safe, but
  // could easily be rewritten in this manner.

  const Float_t Sx = 7, Sy = 3.5;

  if(mNameSwitch == 0) {
    ZRlNodeMarkup* znm = new ZRlNodeMarkup;
    znm->SetTileCol(0, 0, 0.4, 0.4);
    mQueen->CheckIn(znm);
    SetNameSwitch(znm);
  }

  sub_map& o = sub_map_list[0];
  sub_map* smp = sub_map_list;
  while(smp->n) {
    sub_map &s = *smp;

    Float_t llx = s.x0 - s.dx/2, urx = s.x0 + s.dx/2;
    Float_t lly = s.y0 - s.dy/2, ury = s.y0 + s.dy/2;

    AEVFlatSSpace* fss = new
      AEVFlatSSpace(s.n, GForm("SSpace chunk representing %s", s.n));

    fss->SetRnrMod(*mNameSwitch);
    fss->SetModSelf(false);

    fss->SetTexture(tex);
    //fss->SetTexX0((llx+Sx/2)/Sx);  fss->SetTexY0(1 - (ury+Sy/2)/Sy);
    //fss->SetTexX1((urx+Sx/2)/Sx);  fss->SetTexY1(1 - (lly+Sy/2)/Sy);
    fss->SetTexX0((llx+Sx/2)/Sx);  fss->SetTexY0((lly+Sy/2)/Sy);
    fss->SetTexX1((urx+Sx/2)/Sx);  fss->SetTexY1((ury+Sy/2)/Sy);
    fss->SetUV(s.dx, s.dy);
    fss->SetPhi0(360*s.x0/Sx);   fss->SetDPhi(360*s.dx/Sx);
    fss->SetTheta0(180*s.y0/Sy); fss->SetDTheta(180*s.dy/Sy);

    if(smp != sub_map_list) {
      fss->SetPos((s.x0 - o.x0)*s.sx + s.ox, (s.y0 - o.y0)*s.sy + s.oy, 0);
    }

    // Here use ZQueen::IncarnateWAttach & suppress flare broadcast.
    mQueen->CheckIn(fss);
    Add(fss);

    ++smp;
  }
}

/**************************************************************************/

Bool_t AEVMapViz::ImportSite(AEVSite* site, Bool_t warn)
{
  static const Exc_t _eh("AEVMapViz::ImportSite ");

  GMutexHolder lstlck(mListMutex);
  Stepper<AEVSSpace_ABase> s(this);
  while(s.step()) {
    if(s->ImportSite(site, warn))
      return true;
  }
  return false;
}

void AEVMapViz::PopulateWSites(Bool_t warn)
{
  static const Exc_t _eh("AEVMapViz::PopulateWSites ");

  if(mSites == 0) {
    throw(_eh + "link Sites must be set.");
  }

  list<AEVSite*> sites;
  mSites->CopyListByGlass<AEVSite>(sites);

  GMutexHolder lstlck(mListMutex);
  Stepper<AEVSSpace_ABase> s(this);
  while(s.step()) {
    for(list<AEVSite*>::iterator i=sites.begin(); i!=sites.end(); ++i) {
      if(s->ImportSite(*i, warn)) {
	list<AEVSite*>::iterator j = i--;
	sites.erase(j);
      }
    }
  }
}

void AEVMapViz::ClearSiteVizes()
{
  list<AEVSSpace_ABase*> space_chunks;
  CopyListByClass<AEVSSpace_ABase>(space_chunks);
  for(list<AEVSSpace_ABase*>::iterator c=space_chunks.begin(); c!=space_chunks.end(); ++c) {
    (*c)->ClearSiteVizes();
  }
}

/**************************************************************************/

void AEVMapViz::RnrSiteNamesOn()
{
  if(mNameSwitch != 0)
    mNameSwitch->SetRnrNames(true);
}

void AEVMapViz::RnrSiteNamesOff()
{
  if(mNameSwitch != 0)
    mNameSwitch->SetRnrNames(false);
}

/**************************************************************************/

AEVSiteViz* AEVMapViz::FindSiteViz(const Text_t* name)
{
  list<ZList*> space_chunks;
  CopyListByGlass<ZList>(space_chunks);
  for(list<ZList*>::iterator c=space_chunks.begin(); c!=space_chunks.end(); ++c) {
    AEVSiteViz* sv = dynamic_cast<AEVSiteViz*>((*c)->GetElementByName(name));
    if(sv != 0) return sv;
  }
  return 0;
}
 AEVMapViz.cxx:1
 AEVMapViz.cxx:2
 AEVMapViz.cxx:3
 AEVMapViz.cxx:4
 AEVMapViz.cxx:5
 AEVMapViz.cxx:6
 AEVMapViz.cxx:7
 AEVMapViz.cxx:8
 AEVMapViz.cxx:9
 AEVMapViz.cxx:10
 AEVMapViz.cxx:11
 AEVMapViz.cxx:12
 AEVMapViz.cxx:13
 AEVMapViz.cxx:14
 AEVMapViz.cxx:15
 AEVMapViz.cxx:16
 AEVMapViz.cxx:17
 AEVMapViz.cxx:18
 AEVMapViz.cxx:19
 AEVMapViz.cxx:20
 AEVMapViz.cxx:21
 AEVMapViz.cxx:22
 AEVMapViz.cxx:23
 AEVMapViz.cxx:24
 AEVMapViz.cxx:25
 AEVMapViz.cxx:26
 AEVMapViz.cxx:27
 AEVMapViz.cxx:28
 AEVMapViz.cxx:29
 AEVMapViz.cxx:30
 AEVMapViz.cxx:31
 AEVMapViz.cxx:32
 AEVMapViz.cxx:33
 AEVMapViz.cxx:34
 AEVMapViz.cxx:35
 AEVMapViz.cxx:36
 AEVMapViz.cxx:37
 AEVMapViz.cxx:38
 AEVMapViz.cxx:39
 AEVMapViz.cxx:40
 AEVMapViz.cxx:41
 AEVMapViz.cxx:42
 AEVMapViz.cxx:43
 AEVMapViz.cxx:44
 AEVMapViz.cxx:45
 AEVMapViz.cxx:46
 AEVMapViz.cxx:47
 AEVMapViz.cxx:48
 AEVMapViz.cxx:49
 AEVMapViz.cxx:50
 AEVMapViz.cxx:51
 AEVMapViz.cxx:52
 AEVMapViz.cxx:53
 AEVMapViz.cxx:54
 AEVMapViz.cxx:55
 AEVMapViz.cxx:56
 AEVMapViz.cxx:57
 AEVMapViz.cxx:58
 AEVMapViz.cxx:59
 AEVMapViz.cxx:60
 AEVMapViz.cxx:61
 AEVMapViz.cxx:62
 AEVMapViz.cxx:63
 AEVMapViz.cxx:64
 AEVMapViz.cxx:65
 AEVMapViz.cxx:66
 AEVMapViz.cxx:67
 AEVMapViz.cxx:68
 AEVMapViz.cxx:69
 AEVMapViz.cxx:70
 AEVMapViz.cxx:71
 AEVMapViz.cxx:72
 AEVMapViz.cxx:73
 AEVMapViz.cxx:74
 AEVMapViz.cxx:75
 AEVMapViz.cxx:76
 AEVMapViz.cxx:77
 AEVMapViz.cxx:78
 AEVMapViz.cxx:79
 AEVMapViz.cxx:80
 AEVMapViz.cxx:81
 AEVMapViz.cxx:82
 AEVMapViz.cxx:83
 AEVMapViz.cxx:84
 AEVMapViz.cxx:85
 AEVMapViz.cxx:86
 AEVMapViz.cxx:87
 AEVMapViz.cxx:88
 AEVMapViz.cxx:89
 AEVMapViz.cxx:90
 AEVMapViz.cxx:91
 AEVMapViz.cxx:92
 AEVMapViz.cxx:93
 AEVMapViz.cxx:94
 AEVMapViz.cxx:95
 AEVMapViz.cxx:96
 AEVMapViz.cxx:97
 AEVMapViz.cxx:98
 AEVMapViz.cxx:99
 AEVMapViz.cxx:100
 AEVMapViz.cxx:101
 AEVMapViz.cxx:102
 AEVMapViz.cxx:103
 AEVMapViz.cxx:104
 AEVMapViz.cxx:105
 AEVMapViz.cxx:106
 AEVMapViz.cxx:107
 AEVMapViz.cxx:108
 AEVMapViz.cxx:109
 AEVMapViz.cxx:110
 AEVMapViz.cxx:111
 AEVMapViz.cxx:112
 AEVMapViz.cxx:113
 AEVMapViz.cxx:114
 AEVMapViz.cxx:115
 AEVMapViz.cxx:116
 AEVMapViz.cxx:117
 AEVMapViz.cxx:118
 AEVMapViz.cxx:119
 AEVMapViz.cxx:120
 AEVMapViz.cxx:121
 AEVMapViz.cxx:122
 AEVMapViz.cxx:123
 AEVMapViz.cxx:124
 AEVMapViz.cxx:125
 AEVMapViz.cxx:126
 AEVMapViz.cxx:127
 AEVMapViz.cxx:128
 AEVMapViz.cxx:129
 AEVMapViz.cxx:130
 AEVMapViz.cxx:131
 AEVMapViz.cxx:132
 AEVMapViz.cxx:133
 AEVMapViz.cxx:134
 AEVMapViz.cxx:135
 AEVMapViz.cxx:136
 AEVMapViz.cxx:137
 AEVMapViz.cxx:138
 AEVMapViz.cxx:139
 AEVMapViz.cxx:140
 AEVMapViz.cxx:141
 AEVMapViz.cxx:142
 AEVMapViz.cxx:143
 AEVMapViz.cxx:144
 AEVMapViz.cxx:145
 AEVMapViz.cxx:146
 AEVMapViz.cxx:147
 AEVMapViz.cxx:148
 AEVMapViz.cxx:149
 AEVMapViz.cxx:150
 AEVMapViz.cxx:151
 AEVMapViz.cxx:152
 AEVMapViz.cxx:153
 AEVMapViz.cxx:154
 AEVMapViz.cxx:155
 AEVMapViz.cxx:156
 AEVMapViz.cxx:157
 AEVMapViz.cxx:158
 AEVMapViz.cxx:159
 AEVMapViz.cxx:160
 AEVMapViz.cxx:161
 AEVMapViz.cxx:162
 AEVMapViz.cxx:163
 AEVMapViz.cxx:164
 AEVMapViz.cxx:165
 AEVMapViz.cxx:166
 AEVMapViz.cxx:167
 AEVMapViz.cxx:168
 AEVMapViz.cxx:169
 AEVMapViz.cxx:170
 AEVMapViz.cxx:171
 AEVMapViz.cxx:172
 AEVMapViz.cxx:173
 AEVMapViz.cxx:174
 AEVMapViz.cxx:175
 AEVMapViz.cxx:176