Re: TView::WCtoNDC

From: Dmitri Litvintsev (litvinse@cdfsga.fnal.gov)
Date: Mon Sep 27 1999 - 23:28:43 MEST


Hi Valery, 

Thanx for explanation! I used this magic number 0.5*sqrt(3), and  all 
fell into place. 

I've attached header and implementation files for my class 'TEdView'. 
As you see I don't touch fTnorm and fTback. I presumed that 
fTnorm brings me from WC to normalized coordinates, that is the 
system where variables range from -1 to 1, so all I needed to do - 
expand and shift according to my Pad boundaries.  Well, anyway 
it works now ( after introduction of 0.5*sqrt(3)) like I 
intended it to work.

Dmitri Litvintsev

/----------------------------------------------------------\
| Tel:       (630) 840 3763                                |  
| FAX:       (630) 840 2968                                |      
| office:    164-O CDF Trailers                            |
| E-mail:    litvinse@fnal.gov                             |
\----------------------------------------------------------/




On Mon, 27 Sep 1999, Valeri Fine (Faine) wrote:

> 
>  Hello Dmitri,
> 
>   Could you supply the full text of your version of TView class
>   Especially I'd like to see how you fill :
> 
>       Float_t         fTnorm[12];        // Transformation matrix
>       Float_t         fTback[12];         // Back transformation matrix
> 
> >From my point of view to do what you want you should not touch
> WCtoNDC class rather introduce a special method to re-define fTnorm
> matrix
> 
> This matrix is defined by 
> 
> void TView::ResetView(Float_t longitude, Float_t latitude, Float_t psi, Int_t &irep)
> 
> method via "FindScope" as follows:
> {
>     irep = 0;
>     Float_t sqrt3 = 0.5*TMath::Sqrt(3.0);
>  
>     for (Int_t i = 0; i < 3; i++) {
>         if (fRmin[i] >= fRmax[i]) { irep = -1; return;}
>                 scale[i]  = sqrt3*(fRmax[i] - fRmin[i]);
>                 center[i] = 0.5*(fRmax[i] + fRmin[i]);
>     }
> }
> 
> >From the code above it is clear the SECOND transformation you introduced
> within your version of ONLY method of TView doesn't match the PRIMARY
> transfromation the rest methods of your class use.
> 
>  Apparently the factor:
> 
> root [3] 1.0/(0.5*sqrt(3)) 
> (double)1.15470053837925170e+000
> 
> I think sqrt3 was chosen to make sure all verteces of the cube
> (fRmax[i] - fRmin[i]) (in other words the cube diagonal) 
> are visible with either rotation angle.
> 
>  Myself see no reason for a new class.
> 
>   May be one should contribute  a new method (approach)
> 
>         TView::WCtoDC and avoid 
>         gPad->Range(-1, -1, 1, 1);
> 
> 
>   Hope this helps,
>                             Valery
> 

#include <math.h>
#include "TVirtualPad.h"
#include "TLego.h"


#include "RootEventDisplay/TEdView.hh"

ClassImp(TEdView)

//______________________________________________________________________________
TEdView::TEdView() : TView () {}

//______________________________________________________________________________
TEdView::~TEdView() {}

//______________________________________________________________________________
TEdView::TEdView(Int_t system) {
   Int_t irep;
   fSystem = system;
   fOutline = 0;
   fDefaultOutline = kFALSE;
   fAutoRange      = kFALSE;

   if (system == kCARTESIAN || system == kPOLAR) fPsi = 0;
   else fPsi = 90;

   if (gPad) {
     gPad->GetRange(fPadX1,fPadY1,fPadX2,fPadY2);

      for (Int_t i = 0; i < 3; fRmin[i] = 0, fRmax[i] = 1, i++);

      fLongitude = -90 - gPad->GetPhi();
      fLatitude  =  90 - gPad->GetTheta();
      ResetView(fLongitude, fLatitude, fPsi, irep);

      gPad->SetView(this);
   }
}

//______________________________________________________________________________
TEdView::TEdView(Float_t *rmin, Float_t *rmax, Int_t system) {
   Int_t irep;


   fSystem = system;
   fOutline = 0;
   fDefaultOutline = kFALSE;

   if (system == kCARTESIAN || system == kPOLAR) fPsi = 0;
   else fPsi = 90;

   //By default pad range in 3-D view is (-1,-1,1,1), so ...
   gPad->Range(rmin[0],rmin[1],rmax[0],rmax[1]);
   //   gPad->GetRange(xmin,ymin,xmax,ymax);

   fPadX1 = rmin[0];
   fPadY1 = rmin[1];
   fPadX2 = rmax[0];
   fPadY2 = rmax[1];

   for (Int_t i = 0; i < 3; fRmin[i] = rmin[i], fRmax[i] = rmax[i], i++);

        fLongitude = -90 - gPad->GetPhi();
        fLatitude  =  90 - gPad->GetTheta();
        ResetView(fLongitude, fLatitude, fPsi, irep);

   if (gPad)
                gPad->SetView(this);
}

//______________________________________________________________________________
void TEdView::WCtoNDC(Float_t *pw, Float_t *pn)
{
//*-*-*-*-*-*-*Transfer point from world to normalized coordinates*-*-*-*-*
//*-*          ===================================================        *
//*-*                                                                     *
//*-*    Input: PW(3) - point in world coordinate system                  *
//*-*           PN(3) - point in normalized coordinate system             *
//*-*                                                                     *
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  float dx = (fPadX2-fPadX1)*0.5*sqrt(3);
  float dy = (fPadY2-fPadY1)*0.5*sqrt(3);

  pn[0] = fTnorm[0]*pw[0] + fTnorm[1]*pw[1] + fTnorm[2]*pw[2]  + fTnorm[3];
  pn[1] = fTnorm[4]*pw[0] + fTnorm[5]*pw[1] + fTnorm[6]*pw[2]  + fTnorm[7];
  pn[2] = fTnorm[8]*pw[0] + fTnorm[9]*pw[1] + fTnorm[10]*pw[2] + fTnorm[11];

  pn[0] *= dx;
  pn[1] *= dy;

  pn[0] += 0.5*( fPadX2 + fPadX1 );  
  pn[1] += 0.5*( fPadY2 + fPadY1 );

}

//______________________________________________________________________________
void TEdView::NDCtoWC(Float_t* pn, Float_t* pw)
{
//*-*-*-*-*-*-*Transfer point from normalized to world coordinates*-*-*-*-*
//*-*          ===================================================        *
//*-*                                                                     *
//*-*    Input: PN(3) - point in world coordinate system                  *
//*-*           PW(3) - point in normalized coordinate system             *
//*-*                                                                     *
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  pw[0] = fTback[0]*pn[0] + fTback[1]*pn[1] + fTback[2]*pn[2]  + fTback[3];
  pw[1] = fTback[4]*pn[0] + fTback[5]*pn[1] + fTback[6]*pn[2]  + fTback[7];
  pw[2] = fTback[8]*pn[0] + fTback[9]*pn[1] + fTback[10]*pn[2] + fTback[11];
}



#ifndef TEdView_hh
#define TEdView_hh

#include "TView.h"

class TEdView : public TView { 

protected:
  Float_t         fPadX1;
  Float_t         fPadX2;
  Float_t         fPadY1;
  Float_t         fPadY2;
public:
  TEdView();
  TEdView(Int_t system);
  TEdView(Float_t *rmin, Float_t *rmax, Int_t system = 1);

  virtual         ~TEdView();
				// Overridden from the base class:
  virtual void  WCtoNDC(Float_t *pw, Float_t *pn);
  virtual void  NDCtoWC(Float_t *pn, Float_t *pw);

ClassDef(TEdView,0)
};

#endif



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:40 MET