25
The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

Embed Size (px)

Citation preview

Page 1: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

The Object Model to Construct the Mixed

“Open Inventor” / ROOT 3D scenes

by Valeri Fine, Jerome Lauret

STARBrookhaven National Laboratory

Page 2: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 2

IntroductionThe talk presents the ongoing effort to create the

powerful 3D visualization tool for STAR collaboration.

The man-power constrains have lead us to an introduction of the OO model and its implementation, allowing for the creation of OO definitions of complex 3D scenes based on Open Inventor and ROOT 3D object models simultaneously. Such approach allows us to create the unified visualization layer to fulfill the different, sometimes contradicting, requirements for Detector Simulation, Event Reconstruction and Online Monitoring that could not be otherwise satisfied with existing packages.

Page 3: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 3

Visualization tasks:Even so the various visualization tasks in HENP look

very similar, from the implementation stand point one still should distinguish:

• Online monitoring – Real time• Detector simulation – Full-fledged geometry ( hierarchy )

navigation, Selection. Comparison of the different versions.• Event reconstruction – Event representation. Event (flat or

simple hierarchy) Navigation and Selection on the top of the simplified detector geometry..

Why?

Page 4: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 4

3D “visual” attributes: one size fits all?Transparency: One and the same object (detector

component) can be seen as • transparent for the simulationsimulation, • solid for the reconstructionreconstruction and • invisible for the online monitoringonline monitoring. Does “invisible” == “100 % transparent”?Shape: Calorimeter tower shape:• Simulation – hardwired with the detector

(GEANT) description• Online line monitoring – the size and color are

required to reflect the energy deposit.The questions are experiment specific. Neither ROOT nor OpenGL nor any other “generic” software tool can address it alone.

Page 5: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 5

Abstraction layers

To satisfy the different requirements mentioned above several abstraction layers are needed to be designed and implemented

• Do not reinvent the wheel – use the proven ROOT design (re-use our Qt-layer approach ;-) .

• Re-use STAR framework components• Made it useful for ROOT community also

ROOT plug-in does allow allow to do this.

Page 6: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 6

ROOT + Qt + Coin3D

• The Coin3D-based (Coin3D is an “Open Source” implementation of the “Open Inventor” API) plug-in of the ROOT TVirtualViewer3d interface opened the possibility for STAR to use the existent OpenGL hardware within the STAR ROOT-based frameworks.

• It provided us the capabilities briefly mentioned on a few slides below those makes us free to think about our own applications rather about the technical details of the 3D object rendering.

Page 7: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 7

Coin3D implementation of ROOT 3D viewer interface

TVirtualViewer3D(ROOT > 4.01ROOT > 4.01)

TQtRootViewer3D

TQtGLViewer

TPad

TObject

GL list

Coin Node

model controller view

TQtCoinWidget

QWidget

SoQtFullViewer

SoNode

ROOT plug-in

ROOT plug-in

TQtCoinViewersignals:void ObjectSelected(TObject *, const QPoint&); void HandleSelected(ULong_t, const QPoint&);void ImageSaved(QString &fileName, . . . );

Page 8: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 8

1. Zebra - *.fz2. ROOT Macro - *.C3. ROOT file - *.root4. "Open Inventor" - *.iv, 5. VRML - *.wrl,

1. All common pixmap formats - *.gif,png,jpg,tiff …

2. Postscript and Encapsulated PostScript – *.ps, eps3. VRML - *.wrl, 4. "iv" - "Open Inventor2" - *.iv5. mpeg (movie) to create the primitive movie - *.mpeg

Input 3D geometry formats:

Coin3D implementation.Input /Output 3D geometry formats

The output formats:

Page 9: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 9

Coin3D implementation. API

1. ROOT API. The browser uses the standard ROOT plug-in mechanism. This means to use

it from within ROOT env to render the ROOT 3D class objects no special API is required. The TObject::Draw method will be served with the proper plug-in selected via ROOT resource file.

2. Open Inventor API: To control things programmatically and to render the non-ROOT class objects

one can use “Open Inventor” API See: " http://doc.coin3d.org/Coin/classes.html for details The ROOT and non-ROOT objects (including Coin3D animated objects) can be

mixed within one 3D scene. 3. Qt API. Thanks QtRoot and SoQt Coin3D-based widget classes do provide the Qt

signal / slot API. This allows using it to create the custom Qt-based GUI, for example for the "Control Room" and to create the animated interactive computer models of the STAR detector useful for students, teaching and public presentations.

The widget emits the Qt signal as soon as the user "picks" some object. The

signal provides a C++ pointer to the original ROOT object.

Page 10: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 10

To select object one has to

• Turn the Coin viewer “selection” tool on

• Use the left mouse button to point the image on the 3D view

The browser should:

1. Highlight the selected shape

2. Popup the label with the text provided by the selected object TObject::Info method

3. Find the object in the left tree pane of the Geometry Browser and select the found object there

4. The object selected in the “tree” list should be painted in the right upper TCanvas widget

1

2

43

5

Coin3D implementation. The Default Selection Slot

Page 11: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 11

The Browser provides another “selection” slot.

The SLOT is activated via the drop-down “Options” menu.

To select the object user should follow the previous slide. The only difference, instead of the label the browser will pop the ROOT “Context menu”

Coin3D implementation The “Menu” Selection Slot

Page 12: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 12

The STAR Geometry Browser provides the custom selection slot in addition to the two built-in slots described above

The SLOT is activated via the icon.

To select the object user should follow the previous slides. The only difference, in addition to the built-in action, the application is to popup the text edit window with the source code of the selected volume highlighted.

Coin3D implementation.The Custom Selection

Page 13: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 13

Coin3D implementationMultiply 3D widgets / attributes

The Qt-based ROOT 3D plug-ins do allow creating as many OpenGL widgets as your local video hardware can sustain and set the video attributes for each widget separately as the short animation on the right demonstrates:

Page 14: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 14

Approaches:• Change neither ROOT 3D object model no

3D virtual viewer model, change the “attributes visual implementation”

• Do not change ROOT object model, mix the ROOT and Coin object at the rendering time

• Enhance the ROOT object model to provide the new attributes to be treated by the dedicated viewer (but preserve the backward / forward compatibility)

Page 15: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 15

ROOT transparency attribute implementation.

Does “invisible” == “100 % transparent”?

There are several ways to see the transparency attributes for ROOT object.

1. Full 100 % transparent object – wired and “unpickable” image

2. 99% transparent object – wired and “pickable” image

3. > 99% - translucent solid image.4. Invisible – “invisible” means no image at

all.

Page 16: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 16

ROOT shapes.C example:

trap->SetLineColor(4);trap->SetFillStyle(4001);

tube->SetLineColor(6);tube->SetFillStyle(4000);

Page 17: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 17

STAR “Online Monitor” example:

trap->SetLineColor(4);trap->SetFillStyle(4001);

tpc->SetLineColor(kRed);tpc->SetFillStyle(4000);

ROOT I/O - ok

Page 18: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 18

“Rendering”-time mixture

Coin3D-based viewer

ROOT 3D objects Coin3d SoNode’s

Mix the ROOT and Coin3D objects at the rendering time within Coin3d viewer

Useful to decorate the original ROOT object with the scene-wide effects

“the decoration” is kept apart of the detector geometry with “iv” format

Page 19: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 19

Mixed OIV / ROOT model:TGeoTranslationC

TQtCoin3DNode TString fNodeDescriptor;TString fNodeName;

TQtCoin3DDefInterface(abstract interface)

TGeoTranslation

TGeoTranslation *replica1 =new TGeoTranslation(-150, -150, 0);

TGeoTranslationC *replica1 =new TGeoTranslationC(-150, -150, 0);replica1->SetFileName("replica1.iv");

replica1.iv:#Inventor V2.1 asciiRotor { rotation 0 1 0 0.1 speed 0.1 on TRUE}

rootgeom.c:

Page 20: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 20

Mixed ROOT / Coin3D 3D sceneIt is simple to create the ROOT objects

with the mixing ROOT 3D and Coin3D objects. For example the ROOT objects define the geometry (shapes, color and positions) and Coin3D define the animations, lighting, clipping, 3D labels etc. The mixed objects can be saved/ restored using the regular either ROOT (root file) or Coin3D (see slide 4) I/O

The rootgeom_coin.C ROOT macro creates such object and renders it with non-Coin3D TCanvas and Coin3D ROOT plug-in.

Both the “decoration” as well as ROOT 3d object attributes are kept within ROOT objects and ROOT I/O can be applied

Page 21: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 21

Detector simulationCompare two versions of the STAR

detector

Page 23: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 23

Event reconstruction(cont)

Page 24: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 24

Conclusions:• The object built upon this model can be saved and

retrieved using either ROOT (ROOT macro, ROOT files) or Open Inventor (“iv” or wrl” format files) I/O. The can be rendered with the built-in ROOT TVirtualViewer3D plug-in and with the Open Inventor-based implementation also. To reveal the “Open Inventor” components, a dedicated plug-in was developed.

• The model and its implimentation do allow STAR effectively combing the ROOT OO detector description and Coin3D sophisticated 3D scene visualization features.

• The plug-in is a part of the QtRoot project and it is available to download from QtRoot project Web sizte and CVS repository (see: http://root.bnl.gov )

(Windows binary do include Coin3D plug-in)

Page 25: The Object Model to Construct the Mixed “Open Inventor” / ROOT 3D scenes by Valeri Fine, Jerome Lauret STAR Brookhaven National Laboratory

4/24/[email protected]

Acat 2007 Workshop, NIKNEF 25

References• R.Brun et all. "ROOT OO model to render multi-level 3-

D geometric objects via an OpenGL" Proceedings of the VII International Workshop on Advanced Computing and Analysis Techniques in Physics Research, Chicago, October 16-20, 2000

• V.Fine "STAR Framework and Visualization" ROOT 2000 International Workshop, CERN, Geneva, February, 2000

• P.Nevski. "STAR Simulation". ROOT 2000 International Workshop, CERN, Geneva, February, 2000

• V.Fine. "Visualization of the ROOT 3D class objects with Open Inventor-like viewers" IX International Workshop on Advanced Computing and Analysis Techniques in Physics Research December 1-5, 2003