TPolyLine3D and filled area

Dear rooters,

I am still working on the honeycomb histogram project I described here:
root.cern.ch/phpBB2/viewtopic.php?t=8661

In short: I have generated a 2D colored honeycomb structure using at first TPolyLine (now I used TCutG) and I would like now to move to 3D (or at least in a first step to give a 3D effect).

I thought that the easiest way will be to “convert” my TPolyLine to TPolyLine3D.
This works fine of course until I realized that I can not fill a TPolyLine3D area.
Can I ? If not can you suggest a workaround ? I tried to use “geometry” but I it is a bit overkill for what I want to achieve.

Best
Julien

Yes, You would need 3D polygons. Would triangles be enough ?

Dear Olivier,

Yes. I can work from triangles.

Cheers
Julien

Yes triangle are simple to pain in 3D because they are in a plane. There is no such 3D primitives right now. Also, can you take care of the hidden triangles ? (drawing order). If not, a better implementation using OpenGL would be needed.

May be you can send what you have right now using 3D polylines ?

Olivier,

I think I can, in fact I think it does not matter much for me since the polygons I want to draw are on the same plane.

Sure, it is still very primitive, but it works :

{

  gROOT->Reset();
  gSystem->Load("libMayaHisto.so");

  TMayaHisto *m0 = new TMayaHisto("histo","MAYA",32,32,5);
  
  TPolyLine3D *hex3D ;
  TH3I *blank = new TH3I("blank","",1,-1,35,1,-1,35,1,-1,35);

  TIter next(m0->GetArrayOfPADs());
  TObject *obj;
  TCutG *hexa ;
  blank->Draw();
  Double_t x[7],y[7] ;
  Double_t z[7] = {0.} ;
  while ((obj=next())) { // loop over all functions
    hexa = ((TCutG*)obj) ;
    for(int i=0;i<=7;i++){
      hexa->GetPoint(i%7,x[i],y[i]);
      if(hexa->GetFillColor()>1){
	cout << hexa->GetFillColor() << endl ;
      }
    }
    hex3D = new TPolyLine3D(7,x,y,z,"");

//        hex3D->SetFillColor(hexa->GetFillColor()); // this is the command I though will work !
        hex3D->Draw();
  }

}

TMayaHisto is the 2D honeycomb histogram made from hexagonal TCutG.
All these TCutG are held in TClonesArray. I attach the resulting picture. The PADs are the hexagonal (blue) structure at the bottom.

Cheers
Julien


Julien,
I am afraid I lost the libMayaHisto.so. Can you send me again ? (email to olivier.couet@cern.ch or in your public on afs).
Olivier

Olivier,

I just sent you the code.

Also: to illustrate what I would like to achieve I attach to the post a possible result.

Cheers
Julien




here is one way:

{
   gSystem->Load("libMayaHisto.so");
 
   TMayaHisto *m0 = new TMayaHisto("histo","MAYA",32,32,5);
 
   TH3I *blank = new TH3I("blank","",1,-1,35,1,-1,35,1,-1,35);
   blank->Draw();
   gPad->Update();
   TView *v = gPad->GetView();  
   if (!v) return;  

   TIter next(m0->GetArrayOfPADs());
   TObject *obj;
   TCutG *hexa ;

   TPolyLine3D *hex3D ;
   Double_t x[7],y[7] ;
   Double_t x2d[7],y2d[7] ;
   Double_t temp[3];
   Double_t xpad[6];

   Double_t z[7] = {0.} ;
   Int_t icol=0;
   while ((obj=next())) { // loop over all functions
      hexa = ((TCutG*)obj) ;
      for(int i=0;i<=7;i++){
         hexa->GetPoint(i%7,x[i],y[i]);
         if(hexa->GetFillColor()>1){
            cout << hexa->GetFillColor() << endl ;
         }
         temp[0] = x[i];
         temp[1] = y[i];
         temp[2] = z[i];
         v->WCtoNDC(temp, &xpad[0]);
         x2d[i] = xpad[0];
         y2d[i] = xpad[1];
      }
      TGraph *g=new TGraph(7,x2d,y2d);

      // define a color for the fill area
      icol++; if(icol==50)icol=1;
      g->SetFillColor(icol);

      g->Draw("F");
   }  
}

Dear Olivier,

Thank you for finding a solution. In fact I made an attempt using NCtoWDC but I think I did not understand how to use it (maybe because I used GetView3D() ).

It took me sometime to answer you back because I wanted to check if your solution works completely for me, which was not straightforward, but the attached picture can convince you that it does finally.

In the near future I will integrate this code to TMayaHisto, and it may solve a small issue I have now: I can not freely rotate (w/ the mouse) the whole scene (the TGraphs stay where they are).

I will certainly come back to this post if I go further in this direction.

Best
Julien


To have the rotation working properly, one should implement the proper Draw and Paint methods in the Maya class. Right now the 3D to 2D transformation is done once outside the class. So, when you rotate the cube, the new position is not recomputed like it is the TPolyLine3D case. To understand better what I mean by " proper Draw and Paint methods" have a look at:
root.cern.ch/drupal/content/graphics-pad