Ignore:
Timestamp:
Nov 9, 2007, 3:32:25 PM (17 years ago)
Author:
garnier
Message:

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc

    r529 r593  
    2525//
    2626//
    27 // $Id: G4OpenGLStoredSceneHandler.cc,v 1.31 2006/08/30 11:43:57 allison Exp $
    28 // GEANT4 tag $Name: geant4-08-02-patch-01 $
     27// $Id: G4OpenGLStoredSceneHandler.cc,v 1.34 2007/04/04 16:50:27 allison Exp $
     28// GEANT4 tag $Name: geant4-09-00-ref-01 $
    2929//
    3030//
     
    4646#include "G4PhysicalVolumeModel.hh"
    4747#include "G4VPhysicalVolume.hh"
     48#include "G4LogicalVolume.hh"
    4849#include "G4Polyline.hh"
    4950#include "G4Polymarker.hh"
     51#include "G4Text.hh"
    5052#include "G4Circle.hh"
    5153#include "G4Square.hh"
     54#include "G4Polyhedron.hh"
     55#include "G4AttHolder.hh"
    5256
    5357G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system,
     
    5660fMemoryForDisplayLists (true),
    5761fAddPrimitivePreambleNestingDepth (0),
    58 fTopPODL (0)
     62fTopPODL (0),
     63fProcessing2D (false)
    5964{}
    6065
     
    6974  if (fAddPrimitivePreambleNestingDepth > 1) return;
    7075
     76  // Because of our need to control colour of transients (display by
     77  // time fading), display lists may only cover a single primitive.
     78  // So display list setup is here.
     79
     80  if (fpViewer->GetViewParameters().IsPicking()) {
     81    fPickMap[++fPickName] = 0;
     82  }
     83
    7184  const G4Colour& c = GetColour (visible);
    72 
    73   if (fMemoryForDisplayLists && fReadyForTransients) {
    74 
    75     TO& to = fTOList.back();  // Transient object information.
    76 
    77     // Get vis attributes - pick up defaults if none.
    78     const G4VisAttributes* pVA =
    79       fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());
    80 
    81     // Get time information from vis attributes.
    82     to.fStartTime = pVA->GetStartTime();
    83     to.fEndTime = pVA->GetEndTime();
    84 
    85     // Keep colour out of (already started) display list so that it
    86     // can be applied independently.
    87     glEndList();
    88     glDeleteLists(fDisplayListId, 1);
    89     to.fColour = c;
    90     glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
    91     glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
    92      
    93   } else {
    94 
    95     // Make sure colour is set in other cases.
    96     glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
    97   }
    98 }
    99 
    100 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
    101 {
    102   fAddPrimitivePreambleNestingDepth--;
    103 }
    104 
    105 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)
    106 {
    107   AddPrimitivePreamble(polyline);
    108   G4OpenGLSceneHandler::AddPrimitive(polyline);
    109   AddPrimitivePostamble();
    110 }
    111 
    112 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)
    113 {
    114   AddPrimitivePreamble(circle);
    115   G4OpenGLSceneHandler::AddPrimitive(circle);
    116   AddPrimitivePostamble();
    117 }
    118 
    119 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)
    120 {
    121   AddPrimitivePreamble(square);
    122   G4OpenGLSceneHandler::AddPrimitive(square);
    123   AddPrimitivePostamble();
    124 }
    125 
    126 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
    127 {
    128   AddPrimitivePreamble(polymarker);
    129   G4OpenGLSceneHandler::AddPrimitive(polymarker);
    130   AddPrimitivePostamble();
    131 }
    132 
    133 void G4OpenGLStoredSceneHandler::BeginPrimitives
    134 (const G4Transform3D& objectTransformation) {
    135  
    136   G4VSceneHandler::BeginPrimitives (objectTransformation);
    13785
    13886  if (fMemoryForDisplayLists) {
    13987    fDisplayListId = glGenLists (1);
    14088    if (!fDisplayListId) {  // Could pre-allocate?
    141       G4cout << "********************* WARNING! ********************\n"
    142            <<"Unable to allocate any more display lists in OpenGL.\n "
    143            << "      Continuing drawing in IMMEDIATE MODE.\n"
    144            << "***************************************************" << G4endl;
     89      G4cout <<
     90        "********************* WARNING! ********************"
     91        "\nUnable to allocate any more display lists in OpenGL."
     92        "\n     Continuing drawing in IMMEDIATE MODE."
     93        "\n***************************************************"
     94             << G4endl;
    14595      fMemoryForDisplayLists = false;
    14696    }
     
    14898  if (fMemoryForDisplayLists) {
    14999    if (fReadyForTransients) {
    150       TO to(fDisplayListId, objectTransformation);
     100      TO to(fDisplayListId, *fpObjectTransformation);
     101      to.fPickName = fPickName;
     102      to.fColour = c;
     103      const G4VisAttributes* pVA =
     104        fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());
     105      to.fStartTime = pVA->GetStartTime();
     106      to.fEndTime = pVA->GetEndTime();
    151107      fTOList.push_back(to);
    152108      glDrawBuffer (GL_FRONT);
    153109      glPushMatrix();
    154       G4OpenGLTransform3D oglt (objectTransformation);
     110      G4OpenGLTransform3D oglt (*fpObjectTransformation);
    155111      glMultMatrixd (oglt.GetGLMatrix ());
     112      glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
    156113      glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
    157114    }
    158115    else {
    159       fPOList.push_back(PO(fDisplayListId, objectTransformation));
     116      PO po(fDisplayListId, *fpObjectTransformation);
     117      po.fPickName = fPickName;
     118      fPOList.push_back(po);
    160119      glNewList (fDisplayListId, GL_COMPILE);
     120      glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
    161121    }
    162122  } else {
    163123    glDrawBuffer (GL_FRONT);
    164124    glPushMatrix();
    165     G4OpenGLTransform3D oglt (objectTransformation);
     125    G4OpenGLTransform3D oglt (*fpObjectTransformation);
    166126    glMultMatrixd (oglt.GetGLMatrix ());
    167   }
    168 }
    169 
    170 void G4OpenGLStoredSceneHandler::EndPrimitives () {
     127    glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
     128  }
     129
     130  if (fProcessing2D) {
     131    // Push current 3D world matrices and load identity to define screen
     132    // coordinates...
     133    glMatrixMode (GL_PROJECTION);
     134    glPushMatrix();
     135    glLoadIdentity();
     136    glOrtho (-1., 1., -1., 1., -G4OPENGL_DBL_MAX, G4OPENGL_DBL_MAX);
     137    glMatrixMode (GL_MODELVIEW);
     138    glPushMatrix();
     139    glLoadIdentity();
     140  }
     141}
     142
     143void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
     144{
     145  if (fProcessing2D) {
     146    // Pop current 3D world matrices back again...
     147    glMatrixMode (GL_PROJECTION);
     148    glPopMatrix();
     149    glMatrixMode (GL_MODELVIEW);
     150    glPopMatrix();
     151  }
     152
    171153  if (fMemoryForDisplayLists) {
    172154    glEndList();
     
    177159    glDrawBuffer (GL_BACK);
    178160  }
    179   G4VSceneHandler::EndPrimitives ();
     161  fAddPrimitivePreambleNestingDepth--;
     162}
     163
     164void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)
     165{
     166  AddPrimitivePreamble(polyline);
     167  G4OpenGLSceneHandler::AddPrimitive(polyline);
     168  AddPrimitivePostamble();
     169}
     170
     171void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
     172{
     173  AddPrimitivePreamble(polymarker);
     174  G4OpenGLSceneHandler::AddPrimitive(polymarker);
     175  AddPrimitivePostamble();
     176}
     177
     178void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Text& text)
     179{
     180  // Note: colour is still handled in
     181  // G4OpenGLSceneHandler::AddPrimitive(const G4Text&), so it still
     182  // gets into the display list
     183  AddPrimitivePreamble(text);
     184  G4OpenGLSceneHandler::AddPrimitive(text);
     185  AddPrimitivePostamble();
     186}
     187
     188void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)
     189{
     190  AddPrimitivePreamble(circle);
     191  G4OpenGLSceneHandler::AddPrimitive(circle);
     192  AddPrimitivePostamble();
     193}
     194
     195void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)
     196{
     197  AddPrimitivePreamble(square);
     198  G4OpenGLSceneHandler::AddPrimitive(square);
     199  AddPrimitivePostamble();
     200}
     201
     202void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Scale& scale)
     203{
     204  // Let base class split into primitives.
     205  G4OpenGLSceneHandler::AddPrimitive(scale);
     206}
     207
     208void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron)
     209{
     210  // Note: colour is still handled in
     211  // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&), so it still
     212  // gets into the display list
     213  AddPrimitivePreamble(polyhedron);
     214  G4OpenGLSceneHandler::AddPrimitive(polyhedron);
     215  AddPrimitivePostamble();
     216}
     217
     218void G4OpenGLStoredSceneHandler::AddPrimitive (const G4NURBS& nurbs)
     219{
     220  // Note: colour is still handled in
     221  // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&), so it still
     222  // gets into the display list
     223  AddPrimitivePreamble(nurbs);
     224  G4OpenGLSceneHandler::AddPrimitive(nurbs);
     225  AddPrimitivePostamble();
     226}
     227
     228void G4OpenGLStoredSceneHandler::BeginPrimitives
     229(const G4Transform3D& objectTransformation)
     230
     231  G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
     232
     233  // Display list setup moved to AddPrimitivePreamble.  See notes there.
     234}
     235
     236void G4OpenGLStoredSceneHandler::EndPrimitives ()
     237{
     238  G4OpenGLSceneHandler::EndPrimitives ();
    180239}
    181240
    182241void G4OpenGLStoredSceneHandler::BeginPrimitives2D()
    183242{
    184   G4VSceneHandler::BeginPrimitives2D();
    185 
    186   if (fMemoryForDisplayLists) {
    187     fDisplayListId = glGenLists (1);
    188     if (!fDisplayListId) {  // Could pre-allocate?
    189       G4cout << "********************* WARNING! ********************\n"
    190            <<"Unable to allocate any more display lists in OpenGL.\n "
    191            << "      Continuing drawing in IMMEDIATE MODE.\n"
    192            << "***************************************************" << G4endl;
    193       fMemoryForDisplayLists = false;
    194     }
    195   }
    196   if (fMemoryForDisplayLists) {
    197     if (fReadyForTransients) {
    198       fTOList.push_back(TO(fDisplayListId));
    199       glDrawBuffer (GL_FRONT);
    200       glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
    201     }
    202     else {
    203       fPOList.push_back(PO(fDisplayListId));
    204       glNewList (fDisplayListId, GL_COMPILE);
    205     }
    206   } else {
    207     glDrawBuffer (GL_FRONT);
    208   }
    209   // Push current 3D world matrices and load identity to define screen
    210   // coordinates...
    211   glMatrixMode (GL_PROJECTION);
    212   glPushMatrix();
    213   glLoadIdentity();
    214   glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
    215   glMatrixMode (GL_MODELVIEW);
    216   glPushMatrix();
    217   glLoadIdentity();
     243  G4OpenGLSceneHandler::BeginPrimitives2D();
     244  fProcessing2D = true;
    218245}
    219246
    220247void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
    221248{
    222   // Pop current 3D world matrices back again...
    223   glMatrixMode (GL_PROJECTION);
    224   glPopMatrix();
    225   glMatrixMode (GL_MODELVIEW);
    226   glPopMatrix();
    227 
    228   if (fMemoryForDisplayLists) {
    229     glEndList();
    230   }
    231   if (fReadyForTransients || !fMemoryForDisplayLists) {
    232     glFlush ();
    233     glDrawBuffer (GL_BACK);
    234   }
    235   G4VSceneHandler::EndPrimitives2D ();
     249  fProcessing2D = false;
     250  G4OpenGLSceneHandler::EndPrimitives2D ();
    236251}
    237252
     
    253268      "  display List for fTopPODL - try OpenGL Immediated mode."
    254269           << G4endl;
    255   }
    256   else {
     270  } else {
    257271    glNewList (fTopPODL, GL_COMPILE_AND_EXECUTE); {
    258272      for (size_t i = 0; i < fPOList.size (); i++) {
     
    260274        G4OpenGLTransform3D oglt (fPOList[i].fTransform);
    261275        glMultMatrixd (oglt.GetGLMatrix ());
     276        if (fpViewer->GetViewParameters().IsPicking())
     277          glLoadName(fPOList[i].fPickName);
    262278        glCallList (fPOList[i].fDisplayListId);
    263279        glPopMatrix();
     
    288304  fPOList.clear ();
    289305  fSolidMap.clear ();
     306  ClearAndDestroyAtts();
    290307
    291308  // ...and clear transient store...
     
    375392        (fSolidMap.find (pSolid) != fSolidMap.end ())) {
    376393      fDisplayListId = fSolidMap [pSolid];
    377       fPOList.push_back(PO(fDisplayListId,*fpObjectTransformation));
     394      PO po(fDisplayListId,*fpObjectTransformation);
     395      if (fpViewer->GetViewParameters().IsPicking()) {
     396        G4AttHolder* holder = new G4AttHolder;
     397        // Load G4Atts from G4VisAttributes, if any...
     398        const G4VisAttributes* va = pPVModel->GetCurrentLV()->GetVisAttributes();
     399        if (va) {
     400          const std::map<G4String,G4AttDef>* vaDefs = va->GetAttDefs();
     401          if (vaDefs) holder->AddAtts(va->CreateAttValues(), vaDefs);
     402        }
     403        // Load G4Atts from G4PhysicalVolumeModel...
     404        const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs();
     405        if (defs) holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs);
     406        fPickMap[++fPickName] = holder;
     407        po.fPickName = fPickName;
     408      }
     409      fPOList.push_back(po);
    378410    }
    379411    else {
Note: See TracChangeset for help on using the changeset viewer.