00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TVolumeViewIter.h"
00013 #include "TObjArray.h"
00014 #include "TVolumeView.h"
00015 #include "TDataSetIter.h"
00016 #include "TGeometry.h"
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 ClassImp(TVolumeViewIter)
00034
00035 TVolumeViewIter::TVolumeViewIter(TVolumeView *view, Int_t depth, Bool_t dir):
00036 TDataSetIter(view,depth,dir),fPositions(0)
00037 {
00038
00039 }
00040
00041
00042 TVolumeViewIter::~TVolumeViewIter()
00043 {
00044
00045 if (fPositions) { fPositions->Delete(); delete fPositions; }
00046 }
00047
00048 const TVolumePosition *TVolumeViewIter::GetPosition(Int_t level) const
00049 {
00050
00051 const TVolumePosition *pos = 0;
00052 if (fPositions) {
00053 Int_t thisLevel = level;
00054 if (!thisLevel) thisLevel = fDepth;
00055 pos=(TVolumePosition *)fPositions->At(thisLevel);
00056 }
00057 return pos;
00058 }
00059
00060
00061 TVolumePosition *TVolumeViewIter::operator[](Int_t level)
00062 {
00063
00064 const TVolumePosition *pos = GetPosition(level);
00065 if (pos) return new TVolumePosition(*pos);
00066 else {
00067 Error("operator[]"," GetPosition: %d %d 0x%lx", level,fDepth, (Long_t)fPositions);
00068 return 0;
00069 }
00070 }
00071
00072
00073 void TVolumeViewIter::Notify(TDataSet *set)
00074 {
00075
00076 if (!set) return;
00077 TVolumeView *view = (TVolumeView *) set;
00078 TVolumePosition *position = 0;
00079 position = view->GetPosition();
00080 UpdateTempMatrix(position);
00081 }
00082
00083
00084 TVolumePosition *TVolumeViewIter::UpdateTempMatrix(TVolumePosition *curPosition)
00085 {
00086
00087 TVolumePosition *newPosition = 0;
00088 TVolume *curNode = 0;
00089 UInt_t curPositionId = 0;
00090 if (curPosition) {
00091 curNode = curPosition->GetNode();
00092 curPositionId = curPosition->GetId();
00093 } else {
00094 Error("UpdateTempMatrix","No position has been defined");
00095 return 0;
00096 }
00097 if (fDepth-1) {
00098 TVolumePosition *oldPosition = 0;
00099 const TRotMatrix *oldMatrix = 0;
00100 oldPosition = fPositions ? (TVolumePosition *)fPositions->At(fDepth-1):0;
00101 Double_t oldTranslation[] = { 0, 0, 0 };
00102 if (oldPosition) {
00103 oldMatrix = oldPosition->GetMatrix();
00104 oldTranslation[0] = oldPosition->GetX();
00105 oldTranslation[1] = oldPosition->GetY();
00106 oldTranslation[2] = oldPosition->GetZ();
00107 }
00108
00109
00110 const TRotMatrix *curMatrix = curPosition->GetMatrix();
00111
00112
00113 Double_t newTranslation[3];
00114 Double_t newMatrix[9];
00115
00116 if(oldMatrix) {
00117 TGeometry::UpdateTempMatrix(oldTranslation,((TRotMatrix *)oldMatrix)->GetMatrix()
00118 ,curPosition->GetX(),curPosition->GetY(),curPosition->GetZ()
00119 ,((TRotMatrix *)curMatrix)->GetMatrix()
00120 ,newTranslation,newMatrix);
00121 Int_t num = gGeometry->GetListOfMatrices()->GetSize();
00122 Char_t anum[100];
00123 snprintf(anum,100,"%d",num+1);
00124 newPosition = SetPositionAt(curNode
00125 ,newTranslation[0],newTranslation[1],newTranslation[2]
00126 ,new TRotMatrix(anum,"NodeView",newMatrix));
00127 newPosition->SetMatrixOwner();
00128 } else {
00129 newTranslation[0] = oldTranslation[0] + curPosition->GetX();
00130 newTranslation[1] = oldTranslation[1] + curPosition->GetY();
00131 newTranslation[2] = oldTranslation[2] + curPosition->GetZ();
00132 newPosition = SetPositionAt(curNode,newTranslation[0],newTranslation[1],newTranslation[2]);
00133 if (newPosition) {;}
00134 }
00135 }
00136 newPosition = SetPositionAt(*curPosition);
00137
00138 if (newPosition) newPosition->SetId(curPositionId);
00139 return newPosition;
00140 }
00141
00142
00143 void TVolumeViewIter::ResetPosition(Int_t level, TVolumePosition *newPosition)
00144 {
00145
00146 Int_t thisLevel = level;
00147 if (!thisLevel) thisLevel = fDepth;
00148 TVolumePosition *thisPosition = (TVolumePosition *) GetPosition(level);
00149 if (newPosition)
00150 *thisPosition = *newPosition;
00151 }
00152
00153
00154 void TVolumeViewIter::Reset(TDataSet *l,Int_t depth)
00155 {
00156
00157 TDataSetIter::Reset(l,depth);
00158 }
00159
00160
00161 TVolumePosition *TVolumeViewIter::SetPositionAt(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
00162 {
00163
00164 if (!fPositions) fPositions = new TObjArray(100);
00165 TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
00166 if (position) position->Reset(node,x,y,z,matrix);
00167 else {
00168 position = new TVolumePosition(node,x,y,z,matrix);
00169 fPositions->AddAtAndExpand(position,fDepth);
00170 }
00171 return position;
00172 }
00173
00174
00175 TVolumePosition *TVolumeViewIter::SetPositionAt(TVolumePosition &curPosition)
00176 {
00177
00178 if (!fPositions) fPositions = new TObjArray(100);
00179 TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
00180 if (position) *position = curPosition;
00181 else {
00182 position = new TVolumePosition(curPosition);
00183 fPositions->AddAtAndExpand(position,fDepth);
00184 }
00185 return position;
00186 }
00187
00188