TVolumePosition.cxx

Go to the documentation of this file.
00001 // @(#)root/table:$Id: TVolumePosition.cxx 36323 2010-10-13 07:23:05Z brun $
00002 // Author: Valery Fine(fine@bnl.gov)   25/12/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #include "Riostream.h"
00014 
00015 #include "TCernLib.h"
00016 #include "TVolumePosition.h"
00017 #include "TVolume.h"
00018 
00019 #include "TROOT.h"
00020 #include "TClass.h"
00021 #include "TVirtualPad.h"
00022 #include "TGeometry.h"
00023 #include "TRotMatrix.h"
00024 #include "TBrowser.h"
00025 #include "X3DBuffer.h"
00026 
00027 #include "TTablePadView3D.h"
00028 
00029 //R__EXTERN  Size3D gSize3D;
00030 
00031 ClassImp(TVolumePosition)
00032 
00033 //______________________________________________________________________________
00034 //*-*-*-*-*-*-*-*-* S T N O D E P O S I T I O N   description *-*-*-*-*-*-*-*-*-
00035 //*-*               ===========================
00036 //*-*
00037 //*-*    A TVolumePosition object is used to build the geometry hierarchy (see TGeometry).
00038 //*-*    A node may contain other nodes.
00039 //*-*
00040 //*-*    A geometry node has attributes:
00041 //*-*      - name and title
00042 //*-*      - pointer to the referenced shape (see TShape).
00043 //*-*      - x,y,z offset with respect to the mother node.
00044 //*-*      - pointer to the rotation matrix (see TRotMatrix).
00045 //*-*
00046 //*-*    A node can be drawn.
00047 //*-*
00048 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00049 
00050 
00051 //______________________________________________________________________________
00052 TVolumePosition::TVolumePosition(TVolume *node,Double_t x, Double_t y, Double_t z, const char *matrixname)
00053 : fMatrix(0),fNode(node),fId(0)
00054 {
00055 //*-*-*-*-*-*-*-*-*-*-*Node normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00056 //*-*                  ======================
00057 //*-*
00058 //*-*    name    is the name of the node
00059 //*-*    title   is title
00060 //*-*    x,y,z   are the offsets of the volume with respect to his mother
00061 //*-*    matrixname  is the name of the rotation matrix
00062 //*-*
00063 //*-*    This new node is added into the list of sons of the current node
00064 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00065    SetMatrixOwner(kFALSE);
00066    fX[0] = x; fX[1] =y; fX[2] = z;
00067    if (!node) return;
00068    static Int_t counter = 0;
00069    counter++;
00070    if(!(counter%1000))cout<<"TVolumePosition count="<<counter<<" name="<<node->GetName()<<endl;
00071 
00072    if (!gGeometry) new TGeometry;
00073    if (matrixname && strlen(matrixname)) fMatrix = gGeometry->GetRotMatrix(matrixname);
00074    if (!fMatrix) fMatrix = TVolume::GetIdentity();
00075 }
00076 
00077 
00078 //______________________________________________________________________________
00079 TVolumePosition::TVolumePosition(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
00080                : fMatrix(matrix),fNode(node),fId(0)
00081 {
00082 //*-*-*-*-*-*-*-*-*-*-*Node normal constructor*-*-*-*-*-*-*-*-*-*-*
00083 //*-*                  ================================
00084 //*-*
00085 //*-*    name    is the name of the node
00086 //*-*    title   is title
00087 //*-*    x,y,z   are the offsets of the volume with respect to his mother
00088 //*-*    matrix  is the pointer to the rotation matrix
00089 //*-*
00090 //*-*    This new node is added into the list of sons of the current node
00091 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00092    SetMatrixOwner(kFALSE);
00093    if (!gGeometry) new TGeometry;
00094    fX[0] = x; fX[1] = y; fX[2] = z;
00095    if (!fMatrix) fMatrix = TVolume::GetIdentity();
00096 }
00097 //______________________________________________________________________________
00098 TVolumePosition::TVolumePosition(const TVolumePosition* oldPosition, const TVolumePosition* curPosition){
00099    // Pick the "old" position by pieces
00100    fMatrix = 0;
00101    SetMatrixOwner(kFALSE);
00102    TVolume *curNode = 0;
00103    UInt_t curPositionId    = 0;
00104    TRotMatrix *curMatrix = 0;
00105    if (curPosition) {
00106       curNode       = curPosition->GetNode();
00107       curPositionId = curPosition->GetId();
00108       curMatrix     = (TRotMatrix *) curPosition->GetMatrix();
00109    }
00110    TRotMatrix *oldMatrix = 0;
00111    fX[0] = 0; fX[1] = 0; fX[2] = 0;
00112    Double_t oldTranslation[] = { 0, 0, 0 };
00113    if (oldPosition) {
00114       oldMatrix         = (TRotMatrix *) oldPosition->GetMatrix();
00115       oldTranslation[0] = oldPosition->GetX();
00116       oldTranslation[1] = oldPosition->GetY();
00117       oldTranslation[2] = oldPosition->GetZ();
00118    }
00119 
00120    // Pick the "current" position by pieces
00121 
00122    // Create a new position
00123    Double_t newMatrix[9];
00124 
00125    if(oldMatrix && curMatrix && curPosition)  {
00126       TGeometry::UpdateTempMatrix(oldTranslation,oldMatrix->GetMatrix(),
00127                                  curPosition->GetX(),curPosition->GetY(),curPosition->GetZ(),
00128                                  curMatrix->GetMatrix(),
00129                                  fX,newMatrix);
00130       Int_t num = gGeometry->GetListOfMatrices()->GetSize();
00131       Char_t anum[100];
00132       snprintf(anum,100,"%d",num+1);
00133       fMatrix = new TRotMatrix(anum,"NodeView",newMatrix);
00134       SetMatrixOwner(kTRUE);
00135    } else {
00136       if (curPosition) {
00137          fX[0] = oldTranslation[0] + curPosition->GetX();
00138          fX[1] = oldTranslation[1] + curPosition->GetY();
00139          fX[2] = oldTranslation[2] + curPosition->GetZ();
00140          fMatrix = curMatrix;
00141       }
00142    }
00143    fId = curPositionId;
00144    fNode = curNode;
00145 }
00146 //______________________________________________________________________________
00147 //______________________________________________________________________________
00148 TVolumePosition::TVolumePosition(const TVolumePosition&pos): TObject()
00149       , fMatrix(((TVolumePosition &)pos).GetMatrix()),fNode(pos.GetNode()),fId(pos.GetId())
00150 {
00151    //to be documented
00152    for (int i=0;i<3;i++) fX[i] = pos.GetX(i);
00153    // Transferring the ownership.
00154    // The last created object owns the matrix if any.
00155    // The source object gives up its ownership in favour of the destination object
00156 
00157    SetMatrixOwner(pos.IsMatrixOwner());
00158    // !!! We have to break the "const'ness" at this point to take the ownerships
00159    ((TVolumePosition &)pos).SetMatrixOwner(kFALSE);
00160 }
00161 
00162 //______________________________________________________________________________
00163 TVolumePosition::~TVolumePosition()
00164 {
00165    //to be documented
00166    DeleteOwnMatrix();
00167 }
00168 //______________________________________________________________________________
00169 void TVolumePosition::Browse(TBrowser *b)
00170 {
00171    //to be documented
00172    if (GetNode()) {
00173       TShape *shape = GetNode()->GetShape();
00174       b->Add(GetNode(),shape?shape->GetName():GetNode()->GetName());
00175    } else {
00176       Draw();
00177       gPad->Update();
00178    }
00179 }
00180 
00181 //______________________________________________________________________________
00182 Int_t TVolumePosition::DistancetoPrimitive(Int_t, Int_t)
00183 {
00184 //*-*-*-*-*-*-*-*-*-*-*Compute distance from point px,py to a Node*-*-*-*-*-*
00185 //*-*                  ===========================================
00186 //*-*  Compute the closest distance of approach from point px,py to this node.
00187 //*-*  The distance is computed in pixels units.
00188 //*-*
00189 //*-*
00190 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00191    return 99999;
00192 }
00193 
00194 //______________________________________________________________________________
00195 void TVolumePosition::Draw(Option_t *option)
00196 {
00197 //*-*-*-*-*-*-*-*-*-*-*-*Draw Referenced node with current parameters*-*-*-*
00198 //*-*                   =============================================
00199    TVolume *node = GetNode();
00200    if (node) node->Draw(option);
00201 }
00202 
00203 
00204 //______________________________________________________________________________
00205 void TVolumePosition::ExecuteEvent(Int_t, Int_t, Int_t)
00206 {
00207 //*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
00208 //*-*                  =========================================
00209 //*-*  This member function must be implemented to realize the action
00210 //*-*  corresponding to the mouse click on the object in the window
00211 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00212 
00213 //   if (gPad->GetView())
00214 //             gPad->GetView()->ExecuteRotateView(event, px, py);
00215 
00216 //   if (!gPad->GetListOfPrimitives()->FindObject(this)) gPad->SetCursor(kCross);
00217    gPad->SetCursor(kHand);
00218 }
00219 
00220 //______________________________________________________________________________
00221 const Char_t *TVolumePosition::GetName() const
00222 {
00223    //return VolumePosition name
00224    return GetNode()?GetNode()->GetName():IsA()->GetName();
00225 }
00226 
00227 //______________________________________________________________________________
00228 char *TVolumePosition::GetObjectInfo(Int_t, Int_t) const
00229 {
00230    //to be documented
00231    if (!gPad) return 0;
00232    if (!GetNode()) return 0;
00233    static char info[64];
00234    snprintf(info,64,"%s/%s, shape=%s/%s",GetNode()->GetName(),GetNode()->GetTitle(),GetNode()->GetShape()->GetName(),GetNode()->GetShape()->ClassName());
00235    return info;
00236 }
00237 
00238 //______________________________________________________________________________
00239 Double_t *TVolumePosition::Errmx2Master(const Double_t *localError, Double_t *masterError) const
00240 {
00241    //to be documented
00242    Double_t error[6];
00243    TCL::vzero(&error[1],4);
00244    error[0] = localError[0]; error[2] = localError[1]; error[5] = localError[2];
00245    return Cormx2Master(error, masterError);
00246 }
00247 
00248 //______________________________________________________________________________
00249 Float_t *TVolumePosition::Errmx2Master(const Float_t *localError, Float_t *masterError) const
00250 {
00251    //to be documented
00252    Float_t error[6];
00253    TCL::vzero(&error[1],4);
00254    error[0] = localError[0]; error[2] = localError[1]; error[5] = localError[2];
00255    return Cormx2Master(error, masterError);
00256 }
00257 
00258 //______________________________________________________________________________
00259 Double_t *TVolumePosition::Cormx2Master(const Double_t *localCorr, Double_t *masterCorr)const
00260 {
00261    //to be documented
00262    Double_t *res = 0;
00263    const TRotMatrix *rm = GetMatrix();
00264    double *m = 0;
00265    if (rm && ( m = ((TRotMatrix *)rm)->GetMatrix()) )
00266       res = TCL::trasat(m,(Double_t *)localCorr,masterCorr,3,3);
00267    else
00268       res = TCL::ucopy(localCorr,masterCorr,6);
00269    return res;
00270 }
00271 
00272 //______________________________________________________________________________
00273 Float_t *TVolumePosition::Cormx2Master(const Float_t *localCorr, Float_t *masterCorr) const
00274 {
00275    //to be documented
00276    Float_t *res = 0;
00277    const TRotMatrix *rm = GetMatrix();
00278    Double_t *m = 0;
00279    if (rm && (m = ((TRotMatrix *)rm)->GetMatrix()) ) {
00280       double corLocal[6], corGlobal[6];
00281       TCL::ucopy(localCorr,corLocal,6);
00282       TCL::trasat(m,corLocal,corGlobal,3,3);
00283       res =  TCL::ucopy(corGlobal,masterCorr,6);
00284    } else
00285       res =  TCL::ucopy(localCorr,masterCorr,6);
00286    return res;
00287 }
00288 //______________________________________________________________________________
00289 Double_t *TVolumePosition::Errmx2Local(const Double_t *masterError, Double_t *localError) const
00290 {
00291    //to be documented
00292    Double_t error[6];
00293    TCL::vzero(&error[1],4);
00294    error[0] = masterError[0]; error[2] = masterError[1]; error[5] = masterError[2];
00295    return Cormx2Local(error, localError);
00296 }
00297 //______________________________________________________________________________
00298 Float_t *TVolumePosition::Errmx2Local(const Float_t *masterError, Float_t *localError) const
00299 {
00300    //to be documented
00301    Float_t error[6];
00302    TCL::vzero(&error[1],4);
00303    error[0] = masterError[0]; error[2] = masterError[1]; error[5] = masterError[2];
00304    return Cormx2Local(error, localError);
00305 }
00306 //______________________________________________________________________________
00307 Double_t *TVolumePosition::Cormx2Local(const Double_t *localCorr, Double_t *masterCorr) const
00308 {
00309    //to be documented
00310    Double_t *res = 0;
00311    TRotMatrix *rm = (TRotMatrix *) GetMatrix();
00312    double *m = 0;
00313    if (rm && ( m = rm->GetMatrix()) )
00314       res = TCL::tratsa(m,(Double_t *)localCorr,masterCorr,3,3);
00315    else
00316       res = TCL::ucopy(localCorr,masterCorr,6);
00317    return res;
00318 }
00319 
00320 //______________________________________________________________________________
00321 Float_t *TVolumePosition::Cormx2Local(const Float_t *localCorr, Float_t *masterCorr) const
00322 {
00323    //to be documented
00324    Float_t *res = 0;
00325    TRotMatrix *rm = (TRotMatrix *) GetMatrix();
00326    Double_t *m = 0;
00327    if (rm && (m = rm->GetMatrix()) ) {
00328       double corLocal[6], corGlobal[6];
00329       TCL::ucopy(localCorr,corLocal,6);
00330       TCL::tratsa(m,corLocal,corGlobal,3,3);
00331       res =  TCL::ucopy(corGlobal,masterCorr,6);
00332    }
00333    else
00334       res =  TCL::ucopy(localCorr,masterCorr,6);
00335    return res;
00336 }
00337 
00338 //______________________________________________________________________________
00339 Double_t *TVolumePosition::Local2Master(const Double_t *local, Double_t *master, Int_t nPoints) const
00340 {
00341 //*-*-*-*-*Convert one point from local system to master reference system*-*-*
00342 //*-*      ==============================================================
00343 //
00344 //  Note that before invoking this function, the global rotation matrix
00345 //  and translation vector for this node must have been computed.
00346 //  This is automatically done by the Paint functions.
00347 //  Otherwise TVolumePosition::UpdateMatrix should be called before.
00348    Double_t *matrix = 0;
00349    Double_t *trans = 0;
00350    if (!fMatrix ||  fMatrix == TVolume::GetIdentity() || !(matrix = ((TRotMatrix *)fMatrix)->GetMatrix()) )  {
00351       trans = master;
00352       for (int i =0; i < nPoints; i++,local += 3, master += 3) TCL::vadd(local,fX,master,3);
00353    } else {
00354       trans = master;
00355       for (int i =0; i < nPoints; i++, local += 3, master += 3) {
00356          TCL::mxmpy2(matrix,local,master,3,3,1);
00357          TCL::vadd(master,fX,master,3);
00358       }
00359    }
00360    return trans;
00361 }
00362 
00363 //______________________________________________________________________________
00364 Float_t *TVolumePosition::Local2Master(const Float_t *local, Float_t *master, Int_t nPoints) const
00365 {
00366    //*-*-*-*Convert nPoints points from local system to master reference system*-*-*
00367    //*-*      ==============================================================
00368    //
00369    //  Note that before invoking this function, the global rotation matrix
00370    //  and translation vector for this node must have been computed.
00371    //  This is automatically done by the Paint functions.
00372    //  Otherwise TVolumePosition::UpdateMatrix should be called before.
00373    //
00374    Double_t *matrix = 0;
00375    Float_t *trans = 0;
00376    if (!fMatrix ||  fMatrix == TVolume::GetIdentity() || !(matrix = ((TRotMatrix *)fMatrix)->GetMatrix()) )
00377    {
00378       trans = master;
00379       for (int i =0; i < nPoints; i++,local += 3, master += 3) TCL::vadd(local,fX,master,3);
00380    } else {
00381       trans = master;
00382       for (int i =0; i < nPoints; i++, local += 3, master += 3) {
00383          Double_t dlocal[3];   Double_t dmaster[3];
00384          TCL::ucopy(local,dlocal,3);
00385          TCL::mxmpy2(matrix,dlocal,dmaster,3,3,1);
00386          TCL::vadd(dmaster,fX,dmaster,3);
00387          TCL::ucopy(dmaster,master,3);
00388       }
00389    }
00390    return trans;
00391 }
00392 //______________________________________________________________________________
00393 Double_t *TVolumePosition::Master2Local(const Double_t *master, Double_t *local, Int_t nPoints) const
00394 {
00395    //*-*-*-*-*Convert one point from master system to local reference system*-*-*
00396    //*-*      ==============================================================
00397    //
00398    //  Note that before invoking this function, the global rotation matrix
00399    //  and translation vector for this node must have been computed.
00400    //  This is automatically done by the Paint functions.
00401    //  Otherwise TVolumePosition::UpdateMatrix should be called before.
00402    Double_t *matrix = 0;
00403    Double_t *trans = 0;
00404    if (!fMatrix ||  fMatrix == TVolume::GetIdentity() || !(matrix = ((TRotMatrix *)fMatrix)->GetMatrix()) ){
00405       trans = local;
00406       for (int i =0; i < nPoints; i++,master += 3, local += 3) TCL::vsub(master,fX,local,3);
00407    } else {
00408       trans = local;
00409       for (int i =0; i < nPoints; i++, master += 3, local += 3) {
00410          Double_t dlocal[3];
00411          TCL::vsub(master,fX,dlocal,3);
00412          TCL::mxmpy(matrix,dlocal,local,3,3,1);
00413       }
00414    }
00415    return trans;
00416 }
00417 
00418 //______________________________________________________________________________
00419 Float_t *TVolumePosition::Master2Local(const Float_t *master, Float_t *local, Int_t nPoints) const
00420 {
00421    //*-*-*-*Convert nPoints points from master system to local reference system*-*-*
00422    //*-*      ==============================================================
00423    //
00424    //  Note that before invoking this function, the global rotation matrix
00425    //  and translation vector for this node must have been computed.
00426    //  This is automatically done by the Paint functions.
00427    //  Otherwise TVolumePosition::UpdateMatrix should be called before.
00428    //
00429    Double_t *matrix = 0;
00430    Float_t *trans = 0;
00431    if (!fMatrix ||  fMatrix == TVolume::GetIdentity() || !(matrix = ((TRotMatrix *)fMatrix)->GetMatrix()) ){
00432       trans = local;
00433       for (int i =0; i < nPoints; i++,master += 3, local += 3) TCL::vsub(master,fX,local,3);
00434    } else {
00435       trans = local;
00436       for (int i =0; i < nPoints; i++, master += 3, local += 3) {
00437          Double_t dmaster[3];   Double_t dlocal[3];
00438          TCL::ucopy(master,dmaster,3);
00439          TCL::vsub(dmaster,fX,dmaster,3);
00440          TCL::mxmpy(matrix,dmaster,dlocal,3,3,1);
00441          TCL::ucopy(dlocal,local,3);
00442       }
00443    }
00444    return trans;
00445 }
00446 //______________________________________________________________________________
00447 void TVolumePosition::Paint(Option_t *)
00448 {
00449 //*-*-*-*-*-*-*-*-*-*-*-*Paint Referenced node with current parameters*-*-*-*
00450 //*-*                   ==============================================
00451 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00452    Error("Paint","Position can not be painted");
00453 }
00454 
00455 //_______________________________________________________________________
00456 void TVolumePosition::Print(Option_t *) const
00457 {
00458    //to be documented
00459    cout << *this << endl;
00460 }
00461 
00462 //______________________________________________________________________________
00463 TVolumePosition *TVolumePosition::Reset(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
00464 {
00465 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Reset this position *-*-*-*-*-*-*-*-*-*-*
00466 //*-*                           ===================
00467 //*-*    x,y,z   are the offsets of the volume with respect to his mother
00468 //*-*    matrix  is the pointer to the rotation matrix
00469 //*-*
00470 //*-*    This method is to re-use the memory this object without delete/create steps
00471 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00472 
00473 // This method has to be protected since it doesn't set properly kIsOwn bit.
00474 
00475    fNode = node;
00476    SetPosition(x,y,z);
00477    SetMatrix(matrix);
00478    if (!fMatrix) fMatrix = TVolume::GetIdentity();
00479    return this;
00480 }
00481 
00482 //_______________________________________________________________________
00483 void TVolumePosition::SavePrimitive(ostream &, Option_t * /*= ""*/)
00484 {
00485    //to be documented
00486 #if 0
00487    out << "TVolumePosition *CreatePosition() { " << endl;
00488    out << "  TVolumePosition *myPosition = 0;    " << endl;
00489    Double_t x = GetX();
00490    Double_t y = GetY();
00491    Double_t z = GetZ();
00492    TRotMatrix *matrix =
00493    myPosition =  new TVolumePosition(TVolume *node,Double_t x, Double_t y, Double_t z, const char *matrixname)
00494    : fNode(node),fX(x),fY(y),fZ(z),fMatrix(0)
00495 {
00496 /
00497    out << "  return myPosition; "                << endl;
00498    out << "} "                                   << endl;
00499 #endif
00500 
00501 }
00502 //______________________________________________________________________________
00503 void   TVolumePosition::SetLineAttributes()
00504 {
00505    //to be documented
00506    TVolume *thisNode = GetNode();
00507    if (thisNode) thisNode->SetLineAttributes();
00508 }
00509 //_______________________________________________________________________
00510 void TVolumePosition::SetMatrix(TRotMatrix *matrix)
00511 {
00512    //to be documented
00513    if (matrix != fMatrix) {
00514       DeleteOwnMatrix();
00515       fMatrix = matrix;
00516    }
00517 }
00518 //_______________________________________________________________________
00519 void TVolumePosition::UpdatePosition(Option_t *)
00520 {
00521    //to be documented
00522    TTablePadView3D *view3D=(TTablePadView3D *)gPad->GetView3D();
00523 //*-*- Update translation vector and rotation matrix for new level
00524    if (gGeometry->GeomLevel() && fMatrix) {
00525       gGeometry->UpdateTempMatrix(fX[0],fX[1],fX[2]
00526                                 ,((TRotMatrix *)fMatrix)->GetMatrix()
00527                                 ,fMatrix->IsReflection());
00528       if (view3D)
00529          view3D->UpdatePosition(fX[0],fX[1],fX[2],((TRotMatrix *)fMatrix));
00530    }
00531 }
00532 
00533 //______________________________________________________________________________
00534 void TVolumePosition::SetVisibility(Int_t vis)
00535 {
00536    //to be documented
00537    TVolume *node = GetNode();
00538    if (node) node->SetVisibility(TVolume::ENodeSEEN(vis));
00539 }
00540 //______________________________________________________________________________
00541 TVolumePosition &TVolumePosition::Mult(const TVolumePosition &curPosition) {
00542 
00543    // This method mupltiply the position of this object to the position of the
00544    // curPosition object.
00545    // It doesn't change Id of either object involved.
00546 
00547 
00548    // Pick the "old" position by pieces
00549    TVolume *curNode = 0;
00550  //  UInt_t curPositionId    = 0;
00551    curNode       = curPosition.GetNode();
00552  //     curPositionId = curPosition.GetId();
00553    const TRotMatrix *oldMatrix = 0;
00554    Double_t oldTranslation[] = { 0, 0, 0 };
00555    oldMatrix         = GetMatrix();
00556    oldTranslation[0] = GetX();
00557    oldTranslation[1] = GetY();
00558    oldTranslation[2] = GetZ();
00559 
00560    // Pick the "current" position by pieces
00561    const TRotMatrix *curMatrix        = curPosition.GetMatrix();
00562 
00563    // Create a new position
00564    Double_t newTranslation[3];
00565    Double_t newMatrix[9];
00566    if(oldMatrix){
00567       TGeometry::UpdateTempMatrix(oldTranslation,((TRotMatrix *)oldMatrix)->GetMatrix()
00568                        ,curPosition.GetX(),curPosition.GetY(),curPosition.GetZ(),
00569                        ((TRotMatrix *)curMatrix)->GetMatrix()
00570                        ,newTranslation,newMatrix);
00571       Int_t num = gGeometry->GetListOfMatrices()->GetSize();
00572       Char_t anum[100];
00573       snprintf(anum,100,"%d",num+1);
00574       SetMatrixOwner();
00575       Reset(curNode
00576                            ,newTranslation[0],newTranslation[1],newTranslation[2]
00577                            ,new TRotMatrix(anum,"NodeView",newMatrix));
00578       SetMatrixOwner(kTRUE);
00579    } else {
00580       newTranslation[0] = oldTranslation[0] + curPosition.GetX();
00581       newTranslation[1] = oldTranslation[1] + curPosition.GetY();
00582       newTranslation[2] = oldTranslation[2] + curPosition.GetZ();
00583       Reset(curNode,newTranslation[0],newTranslation[1],newTranslation[2]);
00584    }
00585 //    SetId(curPositionId);
00586    return *this;
00587 }
00588 
00589 //______________________________________________________________________________
00590 void TVolumePosition::SetXYZ(Double_t *xyz)
00591 {
00592    //to be documented
00593    if (xyz)  memcpy(fX,xyz,sizeof(fX));
00594    else      memset(fX,0,sizeof(fX));
00595 }
00596 
00597 //______________________________________________________________________________
00598 void TVolumePosition::Streamer(TBuffer &R__b)
00599 {
00600    // Stream an object of class TVolumePosition.
00601    TRotMatrix     *save = fMatrix;
00602    if (R__b.IsReading()) {
00603       fMatrix = 0;
00604       R__b.ReadClassBuffer(TVolumePosition::Class(), this);
00605       if (!fMatrix) fMatrix = save;
00606    } else {
00607       if (save == TVolume::GetIdentity() ) fMatrix = 0;
00608       R__b.WriteClassBuffer(TVolumePosition::Class(), this);
00609       fMatrix = save;
00610    }
00611 }
00612 //______________________________________________________________________________
00613 ostream& operator<<(ostream& s,const TVolumePosition &target)
00614 {
00615    //to be documented
00616    s << " Node: ";
00617    if (target.GetNode()) s <<  target.GetNode()->GetName() << endl;
00618    else                  s << "NILL" << endl;
00619    s << Form(" Position: x=%10.5f : y=%10.5f : z=%10.5f\n", target.GetX(), target.GetY(), target.GetZ());
00620    TRotMatrix *rot = (TRotMatrix *) target.GetMatrix();
00621    if (rot){
00622       s << rot->IsA()->GetName() << "\t" << rot->GetName() << "\t" << rot->GetTitle() << endl;
00623       Double_t *matrix = rot->GetMatrix();
00624       Int_t i = 0;
00625       for (i=0;i<3;i++) {
00626          for (Int_t j=0;j<3;j++) s << Form("%10.5f:", *matrix++);
00627          s << endl;
00628       }
00629    }
00630    return s;
00631 }

Generated on Tue Jul 5 14:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1