<commit_before>// @(#)root/g3d:$Name:  $:$Id: TShape.cxx,v 1.15 2006/05/24 15:31:40 brun Exp $
// Author: <NAME>   17/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TNode.h"
#include "TShape.h"
#include "TView.h"
#include "TVirtualPad.h"
#include "TGeometry.h"
#include "TMaterial.h"
#include "TFile.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualViewer3D.h"
#include "TClass.h"
#include "TMath.h"

#include <assert.h>

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.
//Begin_Html
/*
<img src="gif/tshape_classtree.gif">
*/
//End_Html
//Begin_Html
/*
<img src="gif/shapes.gif">
*/
//End_Html
//


//______________________________________________________________________________
TShape::TShape()
{
   // Shape default constructor

   fVisibility = 1;
   fMaterial   = 0;
}


//______________________________________________________________________________
TShape::TShape(const char *name,const char *title, const char *materialname)
       : TNamed (name, title), TAttLine(), TAttFill()
{
   // Shape normal constructor

   fVisibility = 1;
   if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
   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(const TShape& ts) : 
  TNamed(ts), 
  TAttLine(ts),
  TAttFill(ts),
  TAtt3D(ts),
  fNumber(ts.fNumber),
  fVisibility(ts.fVisibility),
  fMaterial(ts.fMaterial) 
{ 
   //copy constructor
}

//______________________________________________________________________________
TShape& TShape::operator=(const TShape& ts) 
{ 
   //assignement operator
   if (this!=&ts) {
      TNamed::operator=(ts);
      TAttLine::operator=(ts);
      TAttFill::operator=(ts);
      TAtt3D::operator=(ts);
      fNumber=ts.fNumber;
      fVisibility=ts.fVisibility;
      fMaterial=ts.fMaterial;
   } 
   return *this;
}

//______________________________________________________________________________
TShape::~TShape()
{
   // Shape default destructor

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


//______________________________________________________________________________
Int_t TShape::ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
{
   // Distance to primitive.

   Int_t dist = 9999;

   TView *view = gPad->GetView();
   if (!(numPoints && view)) return dist;

   Double_t *points =  new Double_t[3*numPoints];
   SetPoints(points);
   Double_t dpoint2, x1, y1, xndc[3];
   for (Int_t i = 0; i < numPoints; i++) {
      if (gGeometry) 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);
      if (dpoint2 < dist) dist = (Int_t)dpoint2;
   }
   delete [] points;
   return Int_t(TMath::Sqrt(Float_t(dist)));
}


//______________________________________________________________________________
void TShape::Paint(Option_t *)
{
   // This method is used only when a shape is painted outside a TNode.

   TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
   if (viewer3D) {
      const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
      viewer3D->AddObject(buffer);
   }
}

//______________________________________________________________________________
void TShape::SetPoints(Double_t *) const 
{
   // Set points.

   AbstractMethod("SetPoints(Double_t *buffer) const");
}


//______________________________________________________________________________
void TShape::Streamer(TBuffer &R__b)
{
   // Stream an object of class TShape.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 1) {
         TShape::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      TNamed::Streamer(R__b);
      TAttLine::Streamer(R__b);
      TAttFill::Streamer(R__b);
      TFile *file = (TFile*)R__b.GetParent();
      if (file) {
         if (file->GetVersion() > 22300) TAtt3D::Streamer(R__b);
      } else {
         TAtt3D::Streamer(R__b);
      }
      R__b >> fNumber;
      R__b >> fVisibility;
      R__b >> fMaterial;
      R__b.CheckByteCount(R__s, R__c, TShape::IsA());
      //====end of old versions
      
   } else {
      TShape::Class()->WriteBuffer(R__b,this);
   }
}<commit_msg>Remove dependency from TFile (thanks to new function TBuffer::GetVersionOwner) This changes removes all dependencies on the I/O system from directory g3d.<commit_after>// @(#)root/g3d:$Name:  $:$Id: TShape.cxx,v 1.16 2007/01/12 16:03:15 brun Exp $
// Author: <NAME>   17/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TNode.h"
#include "TShape.h"
#include "TView.h"
#include "TVirtualPad.h"
#include "TGeometry.h"
#include "TMaterial.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualViewer3D.h"
#include "TClass.h"
#include "TMath.h"

#include <assert.h>

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.
//Begin_Html
/*
<img src="gif/tshape_classtree.gif">
*/
//End_Html
//Begin_Html
/*
<img src="gif/shapes.gif">
*/
//End_Html
//


//______________________________________________________________________________
TShape::TShape()
{
   // Shape default constructor

   fVisibility = 1;
   fMaterial   = 0;
}


//______________________________________________________________________________
TShape::TShape(const char *name,const char *title, const char *materialname)
       : TNamed (name, title), TAttLine(), TAttFill()
{
   // Shape normal constructor

   fVisibility = 1;
   if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
   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(const TShape& ts) : 
  TNamed(ts), 
  TAttLine(ts),
  TAttFill(ts),
  TAtt3D(ts),
  fNumber(ts.fNumber),
  fVisibility(ts.fVisibility),
  fMaterial(ts.fMaterial) 
{ 
   //copy constructor
}

//______________________________________________________________________________
TShape& TShape::operator=(const TShape& ts) 
{ 
   //assignement operator
   if (this!=&ts) {
      TNamed::operator=(ts);
      TAttLine::operator=(ts);
      TAttFill::operator=(ts);
      TAtt3D::operator=(ts);
      fNumber=ts.fNumber;
      fVisibility=ts.fVisibility;
      fMaterial=ts.fMaterial;
   } 
   return *this;
}

//______________________________________________________________________________
TShape::~TShape()
{
   // Shape default destructor

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


//______________________________________________________________________________
Int_t TShape::ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
{
   // Distance to primitive.

   Int_t dist = 9999;

   TView *view = gPad->GetView();
   if (!(numPoints && view)) return dist;

   Double_t *points =  new Double_t[3*numPoints];
   SetPoints(points);
   Double_t dpoint2, x1, y1, xndc[3];
   for (Int_t i = 0; i < numPoints; i++) {
      if (gGeometry) 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);
      if (dpoint2 < dist) dist = (Int_t)dpoint2;
   }
   delete [] points;
   return Int_t(TMath::Sqrt(Float_t(dist)));
}


//______________________________________________________________________________
void TShape::Paint(Option_t *)
{
   // This method is used only when a shape is painted outside a TNode.

   TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
   if (viewer3D) {
      const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
      viewer3D->AddObject(buffer);
   }
}

//______________________________________________________________________________
void TShape::SetPoints(Double_t *) const 
{
   // Set points.

   AbstractMethod("SetPoints(Double_t *buffer) const");
}


//______________________________________________________________________________
void TShape::Streamer(TBuffer &R__b)
{
   // Stream an object of class TShape.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 1) {
         TShape::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      TNamed::Streamer(R__b);
      TAttLine::Streamer(R__b);
      TAttFill::Streamer(R__b);
      if (R__b.GetVersionOwner() > 22300) {
         TAtt3D::Streamer(R__b);
      } else {
         TAtt3D::Streamer(R__b);
      }
      R__b >> fNumber;
      R__b >> fVisibility;
      R__b >> fMaterial;
      R__b.CheckByteCount(R__s, R__c, TShape::IsA());
      //====end of old versions
      
   } else {
      TShape::Class()->WriteBuffer(R__b,this);
   }
}
{'fraction_non_alphanumeric': 0.15150976909413855, 'fraction_numerical': 0.01625222024866785, 'mean_word_length': 3.4668782229274098, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3053561', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3449, 'n_words': 737}