00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TNode.h"
00013 #include "TShape.h"
00014 #include "TView.h"
00015 #include "TVirtualPad.h"
00016 #include "TGeometry.h"
00017 #include "TMaterial.h"
00018 #include "TBuffer3D.h"
00019 #include "TBuffer3DTypes.h"
00020 #include "TVirtualViewer3D.h"
00021 #include "TClass.h"
00022 #include "TMath.h"
00023
00024 #include <assert.h>
00025
00026 ClassImp(TShape)
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 TShape::TShape()
00054 {
00055
00056
00057 fVisibility = 1;
00058 fMaterial = 0;
00059 fNumber = 0;
00060 }
00061
00062
00063
00064 TShape::TShape(const char *name,const char *title, const char *materialname)
00065 : TNamed (name, title), TAttLine(), TAttFill()
00066 {
00067
00068
00069 fVisibility = 1;
00070 if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
00071 fMaterial = gGeometry->GetMaterial(materialname);
00072 fNumber = gGeometry->GetListOfShapes()->GetSize();
00073 gGeometry->GetListOfShapes()->Add(this);
00074 #ifdef WIN32
00075
00076 Color_t lcolor = 16;
00077 SetLineColor(lcolor);
00078 #endif
00079 }
00080
00081
00082 TShape::TShape(const TShape& ts) :
00083 TNamed(ts),
00084 TAttLine(ts),
00085 TAttFill(ts),
00086 TAtt3D(ts),
00087 fNumber(ts.fNumber),
00088 fVisibility(ts.fVisibility),
00089 fMaterial(ts.fMaterial)
00090 {
00091
00092 }
00093
00094
00095 TShape& TShape::operator=(const TShape& ts)
00096 {
00097
00098 if (this!=&ts) {
00099 TNamed::operator=(ts);
00100 TAttLine::operator=(ts);
00101 TAttFill::operator=(ts);
00102 TAtt3D::operator=(ts);
00103 fNumber=ts.fNumber;
00104 fVisibility=ts.fVisibility;
00105 fMaterial=ts.fMaterial;
00106 }
00107 return *this;
00108 }
00109
00110
00111 TShape::~TShape()
00112 {
00113
00114
00115 if (gGeometry) gGeometry->GetListOfShapes()->Remove(this);
00116 }
00117
00118
00119
00120 Int_t TShape::ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
00121 {
00122
00123
00124 Int_t dist = 9999;
00125
00126 TView *view = gPad->GetView();
00127 if (!(numPoints && view)) return dist;
00128
00129 Double_t *points = new Double_t[3*numPoints];
00130 SetPoints(points);
00131 Double_t dpoint2, x1, y1, xndc[3];
00132 for (Int_t i = 0; i < numPoints; i++) {
00133 if (gGeometry) gGeometry->Local2Master(&points[3*i],&points[3*i]);
00134 view->WCtoNDC(&points[3*i], xndc);
00135 x1 = gPad->XtoAbsPixel(xndc[0]);
00136 y1 = gPad->YtoAbsPixel(xndc[1]);
00137 dpoint2= (px-x1)*(px-x1) + (py-y1)*(py-y1);
00138 if (dpoint2 < dist) dist = (Int_t)dpoint2;
00139 }
00140 delete [] points;
00141 return Int_t(TMath::Sqrt(Float_t(dist)));
00142 }
00143
00144
00145
00146 void TShape::Paint(Option_t *)
00147 {
00148
00149
00150 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
00151 if (viewer3D) {
00152 const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
00153 viewer3D->AddObject(buffer);
00154 }
00155 }
00156
00157
00158 void TShape::SetPoints(Double_t *) const
00159 {
00160
00161
00162 AbstractMethod("SetPoints(Double_t *buffer) const");
00163 }
00164
00165
00166
00167 void TShape::Streamer(TBuffer &R__b)
00168 {
00169
00170
00171 if (R__b.IsReading()) {
00172 UInt_t R__s, R__c;
00173 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00174 if (R__v > 1) {
00175 R__b.ReadClassBuffer(TShape::Class(), this, R__v, R__s, R__c);
00176 return;
00177 }
00178
00179 TNamed::Streamer(R__b);
00180 TAttLine::Streamer(R__b);
00181 TAttFill::Streamer(R__b);
00182 TAtt3D::Streamer(R__b);
00183 R__b >> fNumber;
00184 R__b >> fVisibility;
00185 R__b >> fMaterial;
00186 R__b.CheckByteCount(R__s, R__c, TShape::IsA());
00187
00188
00189 } else {
00190 R__b.WriteClassBuffer(TShape::Class(),this);
00191 }
00192 }
00193
00194
00195
00196 void TShape::TransformPoints(Double_t *points, UInt_t NbPnts) const
00197 {
00198
00199
00200 if (gGeometry && points) {
00201 Double_t dlocal[3];
00202 Double_t dmaster[3];
00203 for (UInt_t j=0; j<NbPnts; j++) {
00204 dlocal[0] = points[3*j];
00205 dlocal[1] = points[3*j+1];
00206 dlocal[2] = points[3*j+2];
00207 gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
00208 points[3*j] = dmaster[0];
00209 points[3*j+1] = dmaster[1];
00210 points[3*j+2] = dmaster[2];
00211 }
00212 }
00213 }
00214
00215
00216
00217 void TShape::FillBuffer3D(TBuffer3D & buffer, Int_t reqSections) const
00218 {
00219
00220
00221
00222 if (reqSections & TBuffer3D::kRaw)
00223 {
00224 if (!(reqSections & TBuffer3D::kRawSizes) && !buffer.SectionsValid(TBuffer3D::kRawSizes))
00225 {
00226 assert(kFALSE);
00227 }
00228 }
00229
00230 if (reqSections & TBuffer3D::kCore) {
00231 buffer.ClearSectionsValid();
00232
00233
00234
00235
00236 buffer.fID = gNode;
00237 buffer.fColor = GetLineColor();
00238 buffer.fTransparency = 0;
00239 buffer.fLocalFrame = kFALSE;
00240 buffer.fReflection = kFALSE;
00241
00242 buffer.SetLocalMasterIdentity();
00243 buffer.SetSectionsValid(TBuffer3D::kCore);
00244 }
00245 }
00246
00247
00248
00249 Int_t TShape::GetBasicColor() const
00250 {
00251
00252
00253 Int_t basicColor = ((GetLineColor() %8) -1) * 4;
00254 if (basicColor < 0) basicColor = 0;
00255
00256 return basicColor;
00257 }
00258
00259
00260
00261 const TBuffer3D &TShape::GetBuffer3D(Int_t ) const
00262 {
00263
00264
00265 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
00266 Warning("GetBuffer3D", "this must be implemented for shapes in a TNode::Paint hierarchy. This will become a pure virtual fn eventually.");
00267 return buffer;
00268 }