OpenGL viewer and transparency

Hello ROOTers,

I want draw translucent objects with the OpenGL viewer. How can I change the opacity of an object inside my code? I’ve tried using TGeoMaterial::SetTransparency() and TGeoMaterial::SetFillStyle() but did not succeed.

Many thanks,
Oliver

PS. I’m using RooT version 5.02.00.

1 Like

Hi Oliver,

See this eaxmple:

{ TGeoManager::Import("alice.root"); gGeoManager->DefaultColors(); gGeoManager->GetVolume("IT56")->InvisibleAll(); gGeoManager->GetVolume("IT34")->InvisibleAll(); gGeoManager->GetVolume("IT12")->InvisibleAll(); gGeoManager->GetVolume("ICY2")->SetTransparency(50); gGeoManager->GetVolume("I215")->SetTransparency(50); gGeoManager->GetVolume("I212")->SetTransparency(50); gGeoManager->GetVolume("ITSD")->Draw("ogl"); new TBrowser; }

Rene

Hello
I am confused :frowning: about extra method to set the transparency for TGeoVolume’s.

root.cern.ch/root/htmldoc/TGeoVolume.html
class is derived from TAttFill and the methods
root.cern.ch/root/htmldoc/TAttFi … ransparent
and
root.cern.ch/root/htmldoc/TAttFi … tFillStyle
The later does allow to set the transparency
root.cern.ch/root/htmldoc/TAttFi … escription

4000 :the window is transparent. 4000 to 4100 the window is 100% transparent to 100% opaque
Does calling these methods affect the TGeoVolume appearance ?

Should the method SetFillStyle made private for TGeoVolume then?

Dear Valeri,

TGeoVolume::SetTransparency() is an inline for setting the fill style of the corresponding material which is used for painting. What the effect of the volume’s fill attributes are or if they even collide with the attributes of the material I don’t know. Anyway, it works and is looking very impressive!

Best regards,
Oliver

Hi Oliver,

Thanks for your comments. Yes, we can set the transparency
automatically per material and based on the material density.

I am collecting detector data bases for our tests. I would be
interested by your geometry. Could you send me the result of
gGeoManager->Export(“zeus.root”);

Rene

Hello René,

I’d like to do so, but unfortunately in the Zeus event display we’re still using the ‘old’ RooT geometry classes (mostly in a derived form). If you’re still interested I can send you a geomtery file together with the neccessary class defintions.

My question on the OpenGL viewer was merely a private one. I recently switched to the latest RooT version and was curious about new features. :slight_smile:

Best regards,
Oliver

[quote=“kind”]Dear Valeri,

TGeoVolume::SetTransparency() is an inline for setting the fill style of the corresponding material which is used for painting. What the effect of the volume’s fill attributes are or if they even collide with the attributes of the material I don’t know. Anyway, it works and is looking very impressive!

Best regards,
Oliver[/quote]

That is C++ and it does allow resolving the “Interface collision” smoothly

For example what is wrong to define things as follows:

[code]
void TGeoVolume::SetTransparency(Char_t transparency=0)
{
if (fMedium) fMedium->GetMaterial()->SetTransparency(transparency);
TAttFill::SetFillStyle(4100 - transparency);
} // MENU

virtual void TGeoVolume::SetFillStyle(Style_t fstyle) {
if (fstyle>4000) SetTransparency(4100-fstyle);
else TAttFill::SetFillStyle(fstyle);
}[/code]

I resume this topic because I’m trying to draw the layout of a drift chamber made of wires inside tubes and I encountered problems setting Fill attributes and Transparency of tubes: I’m not able to draw solid objects.
Although [color=#0000FF]TGeoVolume::GetFillStyle()[/color] give me [color=#0000FF]1001[/color] I used [color=#0000FF]TGeoVolume::SetFillStyle(1001)[/color] and [color=#0000FF]TGeoVolume::SetFillColor(17)[/color] without success.
So I tried with the same functions for [color=#0000FF]TGeoMaterial[/color]: nothing changed.
Then I attempted with [color=#0000FF]TGeoMaterial::SetTransparency(0)[/color] and [color=#0000FF]TGeoVolume::SetTransparency(0)[/color] but again only tubes lines were drawn.
The only way I found to draw solid tubes was [color=#0000FF]TGeoVolume::Raytrace()[/color] but this way I can’t set transparency so I can’t see wires inside tubes.
Someone can help me? I’m working on Scientific Linux and root version 5.18, I compile using [color=#0000FF].x lay_ch.C++[/color]. Below my code:

int numtubes = 5;
Float_t rintube[5] = {2.35, 2.35, 2.35, 2.35, 2.35};
Float_t d_wire[5] =  {0.01, 0.01, 0.01, 0.01, 0.01};
Float_t z_min[5] = {-40.,-40.,-40.,-40.,-40.};
Float_t z_max[5] = { 40., 40., 40., 40., 40.};
Float_t x_f0[5] = {0.,-40.,-20., 20., 40.};
Float_t ytubes[5] = {10.,0.,0.,20.,0.};

void lay_ch()
{	
	TGeoManager *manager = new TGeoManager("Chamber Layout", "Chamber Layout");
	TGeoMaterial *mat = new TGeoMaterial("Vacuum", 0.,0.,0.);
	TGeoMaterial *tmat = new TGeoMaterial("TubeMat", 26.98,13.,2.700);
	tmat->SetFillStyle(1001);
	tmat->SetFillColor(17);
	tmat->SetTransparency(0);
	TGeoMaterial *wmat = new TGeoMaterial("WireMat", 63.546,29.,8.920);
	TGeoMedium *med = new TGeoMedium("Vacuum", 0, mat);
	TGeoMedium *tmed = new TGeoMedium("TubeMed", 0, tmat);
	TGeoMedium *wmed = new TGeoMedium("WireMed", 0, wmat);
	
	TGeoVolume *top = manager->MakeBox("Top",med,150.,183.65,120.);
	manager->SetTopVolume(top);

	TGeoVolume *tube[numtubes];
	TGeoVolume *wire[numtubes];
	TGeoTranslation T;
	TGeoRotation R;
	TGeoCombiTrans *M[numtubes];
	char tname[30], wname[30];
	for (int i=0; i<numtubes; i++)
		{
		T.SetTranslation(x_f0[i], ytubes[i], 0.);
		R.SetAngles(0.,0.,0.);
		M[i]= new TGeoCombiTrans(T,R);
		
		sprintf(tname, "Tube[%i]",i);
		sprintf(wname, "wire[%i]",i);
		tube[i] = manager->MakeTube(tname,tmed,rintube[i],rintube[i]+0.15,z_max[i]-z_min[i]);
		wire[i] = manager->MakeTube(wname,wmed,0.,d_wire[i],z_max[i]-z_min[i]);
		
		tube[i]->SetLineColor(17);
		tube[i]->SetFillStyle(1001);
		tube[i]->SetFillColor(17);
		tube[i]->SetTransparency(0);
	
		wire[i]->SetLineColor(46);
		wire[i]->SetFillColor(46);
		tube[i]->AddNode(wire[i],1);
		top->AddNode(tube[i],1,M[i]);
		}

	top->SetVisContainers();
	manager->CloseGeometry();
	
	TCanvas *c3D = new TCanvas("c3D","Chamber Layout",1200,800);
	
	top->Draw("");

	return;
}

Hi,

Are you stuck with root-5.18? There are more flexible ways to show TGeo shapes in EVE but I don’t think it all worked in 5.18.

Matevz

Hi,

This is probably what you want:

int numtubes = 5;
Float_t rintube[5] = {2.35, 2.35, 2.35, 2.35, 2.35};
Float_t d_wire[5] =  {0.01, 0.01, 0.01, 0.01, 0.01};
Float_t z_min[5] = {-40.,-40.,-40.,-40.,-40.};
Float_t z_max[5] = { 40., 40., 40., 40., 40.};
Float_t x_f0[5] = {0.,-40.,-20., 20., 40.};
Float_t ytubes[5] = {10.,0.,0.,20.,0.};

void lay_ch()
{   
   TGeoManager *manager = new TGeoManager("Chamber Layout", "Chamber Layout");
   TGeoMaterial *mat = new TGeoMaterial("Vacuum", 0.,0.,0.);
   TGeoMaterial *tmat = new TGeoMaterial("TubeMat", 26.98,13.,2.700);
   tmat->SetTransparency(50);

   TGeoMaterial *wmat = new TGeoMaterial("WireMat", 63.546,29.,8.920);
   TGeoMedium *med = new TGeoMedium("Vacuum", 0, mat);
   TGeoMedium *tmed = new TGeoMedium("TubeMed", 0, tmat);
   TGeoMedium *wmed = new TGeoMedium("WireMed", 0, wmat);
   
   TGeoVolume *top = manager->MakeBox("Top",med,150.,183.65,120.);
   manager->SetTopVolume(top);

   TGeoVolume **tube = new TGeoVolume*[numtubes];
   TGeoVolume **wire = new TGeoVolume*[numtubes];
   TGeoTranslation T;
   TGeoRotation R;
   TGeoCombiTrans **M = new TGeoCombiTrans *[numtubes];
   char tname[30], wname[30];
   for (int i=0; i<numtubes; i++)
      {
      T.SetTranslation(x_f0[i], ytubes[i], 0.);
      R.SetAngles(0.,0.,0.);
      M[i]= new TGeoCombiTrans(T,R);
      
      sprintf(tname, "Tube[%i]",i);
      sprintf(wname, "wire[%i]",i);
      tube[i] = manager->MakeTube(tname,tmed,rintube[i],rintube[i]+0.15,z_max[i]-z_min[i]);
      wire[i] = manager->MakeTube(wname,wmed,0.,d_wire[i],z_max[i]-z_min[i]);
      
      tube[i]->SetLineColor(17);
   
      wire[i]->SetLineColor(46);
//      tube[i]->AddNode(wire[i],1);
      top->AddNode(tube[i],1,M[i]);
      top->AddNode(wire[i],1,M[i]);
      }

   manager->CloseGeometry();
   
   TCanvas *c3D = new TCanvas("c3D","Chamber Layout",1200,800);
   delete [] tube;
   delete [] wire;
   delete [] M;
   
   top->Draw("ogl");
}

Note that:

  • TGeo does not use SetFillColor/SetFillStyle - the line color is used also as fill color
  • you should not position a wire in the hole of a tube; any daughter volume should be contained inside the body of the mother volume. Rather position both with the same matrix in a common container.
  • to visualize in solid mode with transparency you have to use the OpenGL viewer and just use: TGeoMaterial::SetTransparency(0 to 100) or TGeoVolume::SetTransparency(). Note that a transparency>50 will make a volume invisible in the normal pad.
  • the changed macro above do produce transparent chambers - you see the wires only if you zoom (mouse wheel) since the wires are very thin.

Cheers,

1 Like