ROOT logo
// $Id: SMorph.cxx 2486 2011-06-25 04:07:48Z 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/.

#include "SMorph.h"
#include <Glasses/ZImage.h>
#include "SMorph.c7"

#include <Stones/TubeTvor.h>

#include <TMath.h>

ClassImp(SMorph);

void SMorph::_init(Float_t r)
{
  // Override settings from ZGlass
  bUseDispList = true;

  // Override settings from ZNode
  bUseScale = true;
  mSx = mSy = mSz = r;

  mTLevel = 2; mPLevel = 3;
  mTx = mCx = mRz = 0;

  mThetaMin = 0;   mThetaMax = 1;
  mPhiMean  = 0.5; mPhiRange = 1;
  bEquiSurf = false;

  mTexture = 0;
  mTexX0 = 0; mTexY0 =  1;
  mTexXC = 1; mTexYC = -1;
  mTexYOff = 0;

  pTuber = new TubeTvor;
  bTextured = false;
}

SMorph::~SMorph() { delete pTuber; }

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

void SMorph::Messofy(Float_t ct, Float_t st, Float_t phi)
{
  float R[3];
  Float_t twist = ct*mTx, conv = ct*mCx;
  Float_t x = ct, y = (1+conv)*st*cos(phi+twist), z = (1+conv)*st*sin(phi+twist);
  Float_t a = x*mRz, c=cos(a), s=sin(a);
  R[0] = x*c - y*s;
  R[1] = s*x + y*c;
  R[2] = z;

  if (bTextured)
  {
    float T[2];
    T[0] = mTexX0 + mTexXC * phi / (TMath::TwoPi());
    T[1] = mTexY0 + mTexYC * TMath::ACos(ct) / TMath::Pi();
    if (mTexYOff != 0) T[0] += Int_t(T[1])*mTexYOff;

    pTuber->NewVert(R, R, 0, T);
  }
  else
  {
    pTuber->NewVert(R, R);
  }
}

void SMorph::Triangulate()
{
  bTextured = (mTexture != 0);
  int tlevel = mTLevel + 1;
  pTuber->Init(0, tlevel, mPLevel, false, bTextured);

  float delta_t = TMath::Pi() * (mThetaMax - mThetaMin) / mTLevel;
  float t       = TMath::Pi() * mThetaMin;
  float last_ct = cos(t) + 2.0/mTLevel;
  for (int i=0; i<tlevel; i++)
  {
    float ct, st;
    if (bEquiSurf)
    {
      ct = last_ct - 2.0/mTLevel; if(ct < -1) ct = -1;
      st = sin(acos(ct));
    } else {
      ct = cos(t);
      st = sin(t);
      t += delta_t;
    }
    float phi  = TMath::TwoPi() * (mPhiMean - 0.5*mPhiRange);
    float step = TMath::TwoPi() * mPhiRange / (mPLevel);
    pTuber->NewRing(mPhiRange == 1 ? mPLevel : mPLevel - 1, true);
    for (int j=0; j<mPLevel; j++, phi+=step)
    {
      Messofy(ct, st, phi);
    }
    if (mPhiRange == 1)
      Messofy(ct, st, phi);
    last_ct = ct;
  }
}
 SMorph.cxx:1
 SMorph.cxx:2
 SMorph.cxx:3
 SMorph.cxx:4
 SMorph.cxx:5
 SMorph.cxx:6
 SMorph.cxx:7
 SMorph.cxx:8
 SMorph.cxx:9
 SMorph.cxx:10
 SMorph.cxx:11
 SMorph.cxx:12
 SMorph.cxx:13
 SMorph.cxx:14
 SMorph.cxx:15
 SMorph.cxx:16
 SMorph.cxx:17
 SMorph.cxx:18
 SMorph.cxx:19
 SMorph.cxx:20
 SMorph.cxx:21
 SMorph.cxx:22
 SMorph.cxx:23
 SMorph.cxx:24
 SMorph.cxx:25
 SMorph.cxx:26
 SMorph.cxx:27
 SMorph.cxx:28
 SMorph.cxx:29
 SMorph.cxx:30
 SMorph.cxx:31
 SMorph.cxx:32
 SMorph.cxx:33
 SMorph.cxx:34
 SMorph.cxx:35
 SMorph.cxx:36
 SMorph.cxx:37
 SMorph.cxx:38
 SMorph.cxx:39
 SMorph.cxx:40
 SMorph.cxx:41
 SMorph.cxx:42
 SMorph.cxx:43
 SMorph.cxx:44
 SMorph.cxx:45
 SMorph.cxx:46
 SMorph.cxx:47
 SMorph.cxx:48
 SMorph.cxx:49
 SMorph.cxx:50
 SMorph.cxx:51
 SMorph.cxx:52
 SMorph.cxx:53
 SMorph.cxx:54
 SMorph.cxx:55
 SMorph.cxx:56
 SMorph.cxx:57
 SMorph.cxx:58
 SMorph.cxx:59
 SMorph.cxx:60
 SMorph.cxx:61
 SMorph.cxx:62
 SMorph.cxx:63
 SMorph.cxx:64
 SMorph.cxx:65
 SMorph.cxx:66
 SMorph.cxx:67
 SMorph.cxx:68
 SMorph.cxx:69
 SMorph.cxx:70
 SMorph.cxx:71
 SMorph.cxx:72
 SMorph.cxx:73
 SMorph.cxx:74
 SMorph.cxx:75
 SMorph.cxx:76
 SMorph.cxx:77
 SMorph.cxx:78
 SMorph.cxx:79
 SMorph.cxx:80
 SMorph.cxx:81
 SMorph.cxx:82
 SMorph.cxx:83
 SMorph.cxx:84
 SMorph.cxx:85
 SMorph.cxx:86
 SMorph.cxx:87
 SMorph.cxx:88
 SMorph.cxx:89
 SMorph.cxx:90
 SMorph.cxx:91
 SMorph.cxx:92
 SMorph.cxx:93
 SMorph.cxx:94
 SMorph.cxx:95
 SMorph.cxx:96
 SMorph.cxx:97
 SMorph.cxx:98
 SMorph.cxx:99
 SMorph.cxx:100
 SMorph.cxx:101
 SMorph.cxx:102
 SMorph.cxx:103