//*CMZ :  2.22/04 01/06/99  08.09.38  by  Valery Fine(fine@mail.cern.ch)
//*CMZ :  2.21/07 17/04/99  07.50.09  by  Valery Fine(fine@mail.cern.ch)
//*CMZ :  2.21/01 06/01/99  13.57.19  by  Rene Brun
//*CMZ :  2.21/00 03/01/99  23.34.38  by  Valery Fine(fine@mail.cern.ch)
//*CMZ :  2.20/05 13/12/98  17.45.30  by  Rene Brun
//*CMZ :  2.00/05 15/04/98  09.27.11  by  Rene Brun
//*CMZ :  1.03/08 18/11/97  15.52.24  by  Rene Brun
//*-- Author :    Nenad Buncic   17/09/95

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun, Fons Rademakers.                                  *
 * For list of contributors see $ROOTSYS/AA_CREDITS.                     *
 *                                                                       *
 * Permission to use, copy, modify and distribute this software and its  *
 * documentation for non-commercial purposes is hereby granted without   *
 * fee, provided that the above copyright notice appears in all copies   *
 * and that both the copyright notice and this permission notice appear  *
 * in the supporting documentation. The authors make no claims about the *
 * suitability of this software for any purpose. It is provided "as is"  *
 * without express or implied warranty.                                  *
 *************************************************************************/
//*KEND.

//*KEEP,TNode.
#include "TNode.h"
//*KEEP,TShape.
#include "TShape.h"
//*KEEP,TView.
#include "TView.h"
//*KEEP,TVirtualPad.
#include "TVirtualPad.h"
//*KEEP,TGeometry.
#include "TGeometry.h"
//*KEEP,TMaterial.
#include "TMaterial.h"
//*KEND.

ClassImp(TShape)

//______________________________________________________________________________
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*
//*-*  This is the base class for all geometry shapes.
//*-*  The list of shapes currently supported correspond to the shapes
//*-*  in Geant version 3:
//*-*    TBRIK,TCONE,TCONS,TGTRA,TPARA,TPCON,TPGON
//*-*   ,TTRAP,TTRD1,TTRD2,THYPE, TTUBE and TTUBS.
//*-*
//*-*  The figure below shows instances of all these shapes. This figure
//*-*  is generated by the ROOT 3-D viewer.
//
/*

*/
//
//
/*

*/
//
//*-*
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

//______________________________________________________________________________
 TShape::TShape()
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Shape default constructor-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      =========================

   fVisibility = 1;
   fMaterial   = 0;
}


//______________________________________________________________________________
 TShape::TShape(Text_t *name,Text_t *title, Text_t *materialname)
       : TNamed (name, title), TAttLine(), TAttFill()
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Shape normal constructor-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ========================

   fVisibility = 1;
   fMaterial   = gGeometry->GetMaterial(materialname);
   fNumber     = gGeometry->GetListOfShapes()->GetSize();
   gGeometry->GetListOfShapes()->Add(this);
#ifdef WIN32
//*-* The color "1" - default produces a very bad 3D image with OpenGL
   Color_t lcolor = 16;
   SetLineColor(lcolor);
#endif

}

//______________________________________________________________________________
 TShape::~TShape()
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Shape default destructor-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ========================

   gGeometry->GetListOfShapes()->Remove(this);

}

//______________________________________________________________________________
 Int_t TShape::ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
{
  Int_t dist = 9999;
  TView *view = gPad->GetView();
  if (!(numPoints && view)) return dist;

  Float_t *points =  new Float_t[3*numPoints];
  SetPoints(points);
  Float_t dpoint, dpoint2, x1, y1, xndc[3];
  for (Int_t i = 0; i < numPoints; i++) {
     gGeometry->Local2Master(&points[3*i],&points[3*i]);
     view->WCtoNDC(&points[3*i], xndc);
     x1     = gPad->XtoAbsPixel(xndc[0]);
     y1     = gPad->YtoAbsPixel(xndc[1]);
     dpoint2= (px-x1)*(px-x1) + (py-y1)*(py-y1);
     dpoint = TMath::Sqrt(dpoint2);
     if (dpoint < dist) dist = (Int_t)dpoint;
  }
  delete [] points;
  return dist;
}
//______________________________________________________________________________
 void TShape::Paint(Option_t *)
{
   // This method must be overridden by the real shape implementation.

   // AbstractMethod("Paint");
}

//______________________________________________________________________________
 void TShape::PaintShape(X3DBuffer *buff, Bool_t rangeView)
{
//*-*-*-*-*Paint 3-D shape in current pad with its current attributes*-*-*-*-*
//*-*      ==========================================================

// rangeView = kTRUE - means no real painting
//                     just estimate the tange
//                     of this shape only

    //*-* Paint in the pad
    //*-* Convert yo the master system

    if (!buff) return;

    Float_t *point = &(buff->points[0]);
    for (Int_t j = 0; j < buff->numPoints; j++)
           gGeometry->Local2Master(&point[3*j],&point[3*j]);

    Float_t points[6], x0, y0, z0, x1, y1, z1;
    const Int_t kExpandView = 2;
    int i0;

    x0 = y0 = z0 = x1 = y1 = z1 = buff->points[0];

    if (!rangeView) {
      TAttLine::Modify();  //Change line attributes only if necessary
      TAttFill::Modify();  //Change fill area attributes only if necessary
    }

    for (Int_t i = 0; i < buff->numSegs; i++) {
        i0 = 3*buff->segs[3*i+1];
        points[0] = buff->points[i0++];
        points[1] = buff->points[i0++];
        points[2] = buff->points[i0];

        i0 = 3*buff->segs[3*i+2];
        points[3] = buff->points[i0++];
        points[4] = buff->points[i0++];
        points[5] = buff->points[i0];

        x0 = points[0] < x0 ? points[0] : x0;
        y0 = points[1] < y0 ? points[1] : y0;
        z0 = points[2] < z0 ? points[2] : z0;
        x1 = points[0] > x1 ? points[0] : x1;
        y1 = points[1] > y1 ? points[1] : y1;
        z1 = points[2] > z1 ? points[2] : z1;

        Float_t *ptpoints_0 = &points[0];
        Float_t *ptpoints_3 = &points[3];

        if (!rangeView) gPad->PaintLine3D(ptpoints_0, ptpoints_3);
//        gPad->PaintLine3D(&points[0], &points[3]);
    }
    if (rangeView)
    {
      TView *view = gPad->GetView();
      if (view->GetAutoRange()) view->SetRange(x0,y0,z0,x1,y1,z1,kExpandView);
    }
}
//______________________________________________________________________________
 void TShape::SetPoints(Float_t *){
   AbstractMethod("SetPoints(Float_t *buffer)");
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.