<< How to set G4VisAttributes >>
                            Jan, 1997

1) Solids of density less than G4SceneData::fVisibleDensity, currently
   defaulted to 0.01 * g / cm3), are not drawn except in wireframe mode.
   See code in 3) B) ii) above.

========================================================================
2) A class for visualization attributes:


class G4VisAttributes {

  friend ostream& operator << (ostream& os, const G4VisAttributes& a);

public:

  enum LineStyle {solid, dashed, dotted};

  G4VisAttributes ();
  G4VisAttributes (G4bool visibility);
  G4VisAttributes (const G4Colour& colour);
  G4VisAttributes (G4bool visibility, const G4Colour& colour);

  G4bool          IsVisible        () const;
  const G4Colour& GetColour        () const;
  const G4Color&  GetColor         () const;
  LineStyle       GetLineStyle     () const;
  G4double        GetLineWidth     () const;
  G4bool          IsForceWireframe () const;

  void SetVisibility     (G4bool v);
  void SetColour         (const G4Colour& colour);
  void SetColor          (const G4Color&  color);
  void SetColour         (G4double red, G4double green, G4double blue,
		          G4double alpha = 1.);
  void SetColor          (G4double red, G4double green, G4double blue,
		          G4double alpha = 1.);
  void SetLineStyle      (LineStyle style);
  void SetLineWidth      (G4double w);
  void SetForceWireframe (G4bool force);

private:

  G4bool      fVisible;     // Visibility flag
  G4Colour    fColour;
  LineStyle   fLineStyle;
  G4double    fLineWidth;       // Units of "normal" device linewidth, e.g.,
                                // pixels for screen, 0.1 mm for paper.
  G4bool      fForceWireframe;  // Overrides global surface request.
};


========================================================================
3) A base class for objects which need visualization attributes:

class G4Visible {
public:
  const G4VisAttributes* GetVisAttributes () const;
  void SetVisAttributes (const G4VisAttributes* pVA);
  ...

It has only a const G4VisAttributes* pointer.  A NULL POINTER MEANS NO
ATTRIBUTES.  The G4VisAttributes objects themselves must be managed
(at present) by the "user".

The following classes inherit G4Visible:
G4VVisPrim - and classes derived therefrom, such as G4Polyhedron.
(Note that G4VSolid - and classes derived therefrom, such as G4Box -
 do not have any information on G4VisAttributes.) 

========================================================================
4) How G4VisAttributes should be used.

A) By a user of the Visualization System.

As things stand, the G4VisAttributes object must be instantiated by
the user (e.g., in the code which is used to define the geometry) with
a long enough life to satisfy the object to which it is to be
attached.  This means it must be created with "new" in most cases.
For visualization, the instantiated G4VisAttributes can be set for
a logical volume. The following is a function to create and return 
a "red box":


G4VPhysicalVolume* BuildBox()
{
          //----- material
     G4double z = 13.;
     G4double a = 26.98*g/mole;
     G4double density = 2.7*g/cm3;
     G4Material myMaterial("Aluminium", z, a, density);
     
          //----- Vis Attributes
     G4VisAttributes* pVA  = new G4VisAttributes (G4Colour(1,0,0));

          //----- Solid
     G4Box *box = new G4Box ("Box", 1 ,4, 9 );

          //----- Logical Volume
     G4LogicalVolume *boxLog=new G4LogicalVolume( box, &myMaterial,
                                  "BoxLog",0,0,0);
     boxLog -> SetVisAttributes ( pVA );

          //----- physical volume
     G4PVPlacement *boxPhys=new G4PVPlacement( 0,G4ThreeVector(),
                                              "BoxPhys",
                                              boxLog,
                                              0,false,0);
     return boxPhys;

} // BuildBox


A created primitive can be visualized with the wireframe style forcibly.
It can be done by setting an attribute to G4VisAttributes.

    G4VisAttributes* pVA   = new G4VisAttributes (G4Colour(1,0,0));
    pVA->SetForceWireframe( true );

Another example (from G4UserSteppingAction) of using G4VisAttributes is
as follows.  This time, an automatic variable is OK:

  ... (decide colour - colR, etc.)
  G4VisAttributes va(G4Colour(colR,colG,colB));
  G4Polyline pl;
  pl.SetVisAttributes(&va);
  pl.append(fpSteppingManager->get_fpStep()->getPrePosition());
  pl.append(fpSteppingManager->get_fpStep()->getPostPosition());
  if(fpVVisManager) fpVVisManager->Draw(pl);

To "edit" the existing attributes of an object is not possible.  Instead:

  G4VisAttributes* pNewVisAttributes =
    new G4VisAttributes (*(LogicalVolumePointer->GetVisAttributes());
    // Uses default copy constructor.
  pNewVisAttributes->SetColour (newColour);
  VSolidPointer->SetVisAttributes (pNewVisAttributes);

B) By a Visualization System developer.

i) In AddPrimitives.  REMEMBER TO DEAL WITH NULL POINTER.  E.g.:

void G4OpenGLScene::AddPrimitive (const G4Polyline& line)
{
  G4int nPoints = line.entries ();
  const G4VisAttributes* pVA = line.GetVisAttributes ();
  if (pVA) {
    const G4Colour& c = pVA -> GetColour ();
    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
  }
  else {
    glColor3d (1., 1., 1.);
  }
  ...

ii) In AddThis.  The VisManager (actually
    G4VScene::VisitGeometryAndGetVisReps) chooses a G4VisAttributes:
  ...
  static const G4VisAttributes defaultAttributes;
  fpVisAttribs = pLV -> GetVisAttributes();
  if (!fpVisAttribs) fpVisAttribs = &defaultAttributes;
  // In future, this will be made to depend on material.

  // Initiate drawing if density OK or wireframe.
  G4double density = pLV -> GetMaterial() -> GetDensity();
  G4ViewParameters::DrawingStyle style =
    fpView -> GetViewParameters ().GetDrawingStyle ();
  if (density >= fSD.fVisibleDensity ||
      style == G4ViewParameters::wireframe) {
    pSol -> DescribeYourselfTo (*this);
  }
  ...

Thus there will always be a non-null G4VisAttributes* in
G4VScene::fpVisAttribs.  E.g.:

void G4FukuiRendererScene::AddThis( const G4Box& box )
{
  ...
        if(!SendVisAttributes( fpVisAttribs ) ) {
  ...

==================================================================
5) Other items
  i) In graphics_reps/, G4PointList has changed name to G4Point3DList
 ii) G4VGraphicsScene and G4VVisManager have become *pure* virtual
     abstract interfaces.  Non-visual programs link OK on HP and
     cernsp.  Let me know if you have problems linking.