Issue with geometry colors in TEve

Dear all,

I’m creating a geometry with ROOT and saving it in a root file. When I visualize the geometry directly with openGL I can see all the colors that I specified for each volume. However, when I open the same root geometry with TEve or even with TBrowser, the geometry loses all its colors, and actually adds some weird colors for some parts.

Here’s my code for TEve:

    TString projFile = "Geometry.root";

    auto gEve = TEveManager::Create();

    auto colorGLViewer = gEve->GetDefaultGLViewer();
    colorGLViewer->ColorSet().Background().SetColor(kBlack);
    colorGLViewer->SetGuideState(TGLUtil::kAxesOrigin, kTRUE, kFALSE, 0);
    colorGLViewer->RefreshPadEditor(colorGLViewer);

    auto gGeo = gEve->GetGeometry(projFile);

    auto tn = new TEveGeoTopNode(gGeo, gGeo->GetTopNode());
    tn->SetVisOption(1);
    tn->SetVisLevel(5);
    gEve->AddGlobalElement(tn);

    gEve->FullRedraw3D(kTRUE);

I’m adding screenshots for both cases, one directly with OGL, and the other with OGL inside TEve. Am I ignoring anything when calling the root geometry in TEve?

Many thanks in advance.


Hi Leonardo,

Thanks for the interesting post. This is not expected. @agheata do you have suggestions?

Cheers,
Danilo

1 Like

The only persistent format that currently loses the color properties for volumes is GDML. Saving directly in a root file a geometry with colors will preserve these upon reading back. Also, I’m not aware that:

alters in any way the colors, but this has to be checked. So please first check if the original colors are in your file, by doing:

TGeoManager::Import("Geometry.root");
gGeoManager->GetVolume("volume_name")->Draw(); // draws the volume with that name

If you still see the wrong colors, it might be that the root file was obtain by exporting the geometry after a previous GDML import.

1 Like

Thank you both @Danilo and @agheata.

So, I’m importing obj files by means of TGeoTessellated::ImportFromObjFormat(). There’s no GDML conversion beforehand.

I extracted only 1 part from my geometry to show that I have the same behaviour. It’s basically just a cylindrical shell, and I add a custom color. My code follows below.

I’m also attaching the applicable obj file, so you could re-check what happens here, if you have the time and willingness of course.
The obj file has a “.txt” added as extension, otherwise the forum doesn’t let me upload it. So it’s just a matter of renaming and deleting the “.txt”, and it should then run.

Basically the script shows me the volume with the correct color. After I export to .root and open again, it’s with a different color.
I’m using version 6.26, but I tried with the latest version and I get the same issue.

Thank you again!

void testGeom()
{
    gROOT->GetListOfCanvases()->Delete();
    if(gGeoManager)
        delete gGeoManager;
    
    new TGeoManager("", "testGeom");

    TGeoMaterial *Vac = new TGeoMaterial("vacuum", 0.0, 0.0, 0.0);
    TGeoMedium *Vacuum = new TGeoMedium("Vacuum", 1, Vac);

    TGeoMaterial *Al = new TGeoMaterial("Al", 26.98, 13, 2.7);
    TGeoMedium *Aluminium = new TGeoMedium("Aluminium", 1, Al);

    TGeoVolume *world = gGeoManager->MakeBox("World", Vacuum, 500, 500, 500);
    gGeoManager->SetTopVolume(world);

    // Specifying color
    Int_t colorIndex = TColor::GetFreeColorIndex();
    auto color = new TColor(colorIndex,0.806952, 0.287441, 0.0231534);

    // Import the obj file
    TString part = "kapton.obj";
    auto shape = TGeoTessellated::ImportFromObjFormat(part.Data(),
                                                      kFALSE);

    if (!shape) return;

    // Re-position the volume to the origin
    Double_t shapeX = shape->GetDX();
    Double_t shapeY = shape->GetDY();
    Double_t shapeZ = shape->GetDZ();
    Double_t maxDim = TMath::Max(TMath::Max(shapeX, shapeY), shapeZ);
    shape->ResizeCenter(maxDim);

    auto volume = new TGeoVolume("kapton", shape, Aluminium);
    volume->SetLineColor(colorIndex);
    volume->SetVisibility(kTRUE);

    world->AddNode(volume, 1);
    gGeoManager->CloseGeometry();

    gGeoManager->Export("kapton.root");

    world->Draw("ogl");    
}

kapton.obj.txt (24.4 KB)

I’m away this week, but will have a look asap.

1 Like

Dear @agheata ,

I’m sorry to ask, but have you had any time to look into this? So many thanks in advance.

Hi @lgi, yes I just did have a look. The problem is real: TGeoVolume stores the line properties (width, style and color) as TAttLine. So it is just the TColor index that gets stored, and then made persistent. So when reading back the volume in a separate root session, since the color with that index does not exist, you will get some gibberish color in the display. Of course if you recreated the same color with the same index you would get the right thing.

So AFAICT this points to a deeper problem, that TAttLine derived objects having a user-defined color cannot be made persistent. For you, the easy solution is to use one of the pre-defined base colors, but it would be useful to open a bug report, since the problem cannot be just addressed in geometry.

1 Like

@agheata thanks a lot.

I’ll open a bug report and use the standard basic colors in the meantime.

New colors are not stored in the root file by design. If you are creating your own colors, you will need to define them in your rootlogon.C file.

1 Like