#include "TVolumeViewIter.h"
#include "TObjArray.h"
#include "TVolumeView.h"
#include "TDataSetIter.h"
#include "TGeometry.h"
ClassImp(TVolumeViewIter)
TVolumeViewIter::TVolumeViewIter(TVolumeView *view, Int_t depth, Bool_t dir):
TDataSetIter(view,depth,dir),fPositions(0)
{
}
TVolumeViewIter::~TVolumeViewIter()
{
if (fPositions) { fPositions->Delete(); delete fPositions; }
}
const TVolumePosition *TVolumeViewIter::GetPosition(Int_t level) const
{
const TVolumePosition *pos = 0;
if (fPositions) {
Int_t thisLevel = level;
if (!thisLevel) thisLevel = fDepth;
pos=(TVolumePosition *)fPositions->At(thisLevel);
}
return pos;
}
TVolumePosition *TVolumeViewIter::operator[](Int_t level)
{
const TVolumePosition *pos = GetPosition(level);
if (pos) return new TVolumePosition(*pos);
else {
Error("operator[]"," GetPosition: %d %d %x", level,fDepth, fPositions);
return 0;
}
}
void TVolumeViewIter::Notify(TDataSet *set)
{
if (!set) return;
TVolumeView *view = (TVolumeView *) set;
TVolumePosition *position = 0;
position = view->GetPosition();
UpdateTempMatrix(position);
}
TVolumePosition *TVolumeViewIter::UpdateTempMatrix(TVolumePosition *curPosition)
{
TVolumePosition *newPosition = 0;
TVolume *curNode = 0;
UInt_t curPositionId = 0;
if (curPosition) {
curNode = curPosition->GetNode();
curPositionId = curPosition->GetId();
}
if (fDepth-1) {
TVolumePosition *oldPosition = 0;
const TRotMatrix *oldMatrix = 0;
oldPosition = fPositions ? (TVolumePosition *)fPositions->At(fDepth-1):0;
Double_t oldTranslation[] = { 0, 0, 0 };
if (oldPosition) {
oldMatrix = oldPosition->GetMatrix();
oldTranslation[0] = oldPosition->GetX();
oldTranslation[1] = oldPosition->GetY();
oldTranslation[2] = oldPosition->GetZ();
}
const TRotMatrix *curMatrix = curPosition->GetMatrix();
Double_t newTranslation[3];
Double_t newMatrix[9];
if(oldMatrix) {
TGeometry::UpdateTempMatrix(oldTranslation,((TRotMatrix *)oldMatrix)->GetMatrix()
,curPosition->GetX(),curPosition->GetY(),curPosition->GetZ()
,((TRotMatrix *)curMatrix)->GetMatrix()
,newTranslation,newMatrix);
Int_t num = gGeometry->GetListOfMatrices()->GetSize();
Char_t anum[100];
sprintf(anum,"%d",num+1);
newPosition = SetPositionAt(curNode
,newTranslation[0],newTranslation[1],newTranslation[2]
,new TRotMatrix(anum,"NodeView",newMatrix));
newPosition->SetMatrixOwner();
} else {
newTranslation[0] = oldTranslation[0] + curPosition->GetX();
newTranslation[1] = oldTranslation[1] + curPosition->GetY();
newTranslation[2] = oldTranslation[2] + curPosition->GetZ();
newPosition = SetPositionAt(curNode,newTranslation[0],newTranslation[1],newTranslation[2]);
}
} else if (curPosition) {
newPosition = SetPositionAt(*curPosition);
} else
Error("UpdateTempMatrix","No position has been defined");
if (newPosition) newPosition->SetId(curPositionId);
return newPosition;
}
void TVolumeViewIter::ResetPosition(Int_t level, TVolumePosition *newPosition)
{
Int_t thisLevel = level;
if (!thisLevel) thisLevel = fDepth;
TVolumePosition *thisPosition = (TVolumePosition *) GetPosition(level);
if (newPosition)
*thisPosition = *newPosition;
}
void TVolumeViewIter::Reset(TDataSet *l,Int_t depth)
{
TDataSetIter::Reset(l,depth);
}
TVolumePosition *TVolumeViewIter::SetPositionAt(TVolume *node,Double_t x, Double_t y, Double_t z, TRotMatrix *matrix)
{
if (!fPositions) fPositions = new TObjArray(100);
TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
if (position) position->Reset(node,x,y,z,matrix);
else {
position = new TVolumePosition(node,x,y,z,matrix);
fPositions->AddAtAndExpand(position,fDepth);
}
return position;
}
TVolumePosition *TVolumeViewIter::SetPositionAt(TVolumePosition &curPosition)
{
if (!fPositions) fPositions = new TObjArray(100);
TVolumePosition *position = (TVolumePosition *) fPositions->At(fDepth);
if (position) *position = curPosition;
else {
position = new TVolumePosition(curPosition);
fPositions->AddAtAndExpand(position,fDepth);
}
return position;
}
Last change: Wed Jun 25 08:55:05 2008
Last generated: 2008-06-25 08:55
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.