Re: Re: examples of complex TNode collections?

From: Stefano Bettelli (bettelli@tn.infn.it)
Date: Tue Sep 14 1999 - 11:34:36 MEST


Hi Mike, look at this macro (multi.C).
I think it does just what you were looking for:
=== macro begins =====================================
// This creates a copy of "original" node and stores it 
// under the "parent" node. It is possible to set also
// the associated rotation matrix.
void replicate (TNode *original, TNode *parent, float x, float y, float z) {
  TNode *copy = new TNode(*original);
  copy->SetParent(parent);
  copy->SetPosition(x, y, z);
  parent.GetListOfNodes()->Add(copy);
}

void multi (void) {
  // Create a new geometry and set it as default geometry
  TGeometry *g = new TGeometry("DETECTOR", "My detector");
  g->cd();
  // create a set of shapes
  TBRIK *brik = new TBRIK("BRIK", "A big brik","void", .5, .5, .5);
  TTUBE *tube = new TTUBE("TUBE", "A tube","void",.3,.4,.5);
  // create a dummy shape
  TBRIK *dummy = new TBRIK("DUMMY", "A dummy shape","void", 0., 0., 0.);
  // create the main node for our assembly and cd() to it
  TNode *assembly = new TNode("ASSEMBLY", "Node for the main assembly", dummy);
  assembly->cd();
  // create the first copy of an aggregate as a node associated to
  // a dummy shape and cd() to it
  TNode *aggregate = new TNode("AGGREGATE", "Node for various shapes", dummy);
  aggregate->cd();
  // add shapes to the node through other nodes
  TNode *brik_node = new TNode("BRIKNODE", "Node for the brik", brik);
  TNode *tube_node = new TNode("TTUBENODE", "Node for the tube", tube);
  // check the geometry status
  g->ls();
  // replicate the aggregate into the assembly in various positions
  replicate(aggregate, assembly, 3., 0., 0.);
  replicate(aggregate, assembly, 0., 3., 0.);
  replicate(aggregate, assembly, -3., 0., 0.);
  replicate(aggregate, assembly, 0., -3., 0.);
  replicate(aggregate, assembly, 3., 3., 0.);
  replicate(aggregate, assembly, -3., 3., 0.);
  replicate(aggregate, assembly, 3., -3., 0.);
  replicate(aggregate, assembly, -3., -3., 0.);
  // check the geometry status again
  g->ls();
  // draw the geometry
  g->Draw();
}
=== macro ends ======================================= 
----------------------------------------------------------
E-Mail: Stefano Bettelli <bettelli@tn.infn.it>
WWW   : http://meitner.tn.infn.it



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:39 MET