Changeset 1168 for trunk


Ignore:
Timestamp:
Nov 16, 2009, 3:49:55 PM (15 years ago)
Author:
garnier
Message:

Fix a delete problem

Location:
trunk/source/visualization/management
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/visualization/management/History

    r1140 r1168  
    1 $Id: History,v 1.127 2009/10/30 16:05:30 allison Exp $
     1$Id: History,v 1.133 2009/11/16 13:51:08 lgarnier Exp $
    22
    33-------------------------------------------------------------------
     
    2626History file for visualization management sub-category
    2727------------------------------------------------------
     28
     2916th November 2009  Laurent Garnier
     30-G4VSceneHandler.cc: Bug fix: Deleting G4VSceneHandler null pointer exception fix.
     31
     3214th November 2009  John Allison
     33- G4VSceneHandler.cc: Bug fix: Should be const_cast, not static_cast, for hits.
     34  (Introduced in visman-V09-02-05 and geant4-09-02-ref-10.)
     35
     366th November 2009  John Allison
     37- G4VSceneHandler::AddCompound (const G4THitsMap<G4double>&):
     38  o For scoring maps, call DrawMesh with G4DefaultLinearColorMap as default.
     39  o Write message about other options:
     40    - /vis/open/gMocrenFile
     41    - /score/draw.. commands.
     42  o For hits that are not scoring maps, call DrawAllHits.
     43
     445th November 2009  John Allison
     45- G4VSceneHandler.cc:
     46  o ProcessScene: Added DrawEndOfRunModels().
     47  o AddCompound (const G4THitsMap<G4double>&): Call DrawMesh.
     48
     494th November 2009  John Allison
     50- G4Scene: Added EndOfRunModelList.
     51- G4VSceneHandler:
     52  o Added DrawEndOfRunModels.
     53  o AddCompound(const G4THitsMap<G4double>&): Prototype implementation
     54    using G4ScoringManager.  Still does nothing for scoring maps but
     55    otherwise calls DrawAllHits.
     56- G4VisManager.cc: Call fpSceneHandler->DrawEndOfRunModels at end of run.
     57- G4VisCommandsSceneAdd: Added optional parameter:
     58  o /vis/scene/add/psHits [scoring map name]
    2859
    296030th October 2009  John Allison  (visman-V09-02-06 coworks greps-V09-02-03)
  • trunk/source/visualization/management/src/G4VSceneHandler.cc

    r1140 r1168  
    2525//
    2626//
    27 // $Id: G4VSceneHandler.cc,v 1.86 2009/10/23 07:58:36 allison Exp $
     27// $Id: G4VSceneHandler.cc,v 1.91 2009/11/16 13:51:08 lgarnier Exp $
    2828// GEANT4 tag $Name:  $
    2929//
     
    7474#include "G4HitsModel.hh"
    7575#include "G4VHit.hh"
     76#include "G4ScoringManager.hh"
     77#include "G4DefaultLinearColorMap.hh"
    7678#include "Randomize.hh"
    7779#include "G4StateManager.hh"
     
    116118
    117119G4VSceneHandler::~G4VSceneHandler () {
    118   G4ViewerListIterator i;
    119   for (i = fViewerList.begin(); i != fViewerList.end(); ++i) {
    120     delete *i;
     120//   G4ViewerListIterator i;
     121//   for (i = fViewerList.begin(); i != fViewerList.end(); ++i) {
     122//      delete *i;
     123//    }
     124  G4VViewer* last;
     125  while( ! fViewerList.empty() ) {
     126    last = fViewerList.back();
     127    fViewerList.pop_back();
     128    delete last;
    121129  }
    122130}
     
    262270
    263271void G4VSceneHandler::AddCompound (const G4VHit& hit) {
    264   static_cast<G4VHit>(hit).Draw(); // Cast because Draw is non-const!!!!
     272  // Cast away const because Draw is non-const!!!!
     273  const_cast<G4VHit&>(hit).Draw();
    265274}
    266275
    267276void G4VSceneHandler::AddCompound (const G4THitsMap<G4double>& hits) {
    268   // Cast because DrawAllHits is non-const!!!!
    269   static_cast<G4THitsMap<G4double> >(hits).DrawAllHits();
     277  //G4cout << "AddCompound: hits: " << &hits << G4endl;
     278  G4bool scoreMapHits = false;
     279  G4ScoringManager* scoringManager = G4ScoringManager::GetScoringManagerIfExist();
     280  if (scoringManager) {
     281    size_t nMeshes = scoringManager->GetNumberOfMesh();
     282    for (size_t i = 0; i < nMeshes; ++i) {
     283      G4VScoringMesh* mesh = scoringManager->GetMesh(i);
     284      if (mesh && mesh->IsActive()) {
     285        MeshScoreMap scoreMap = mesh->GetScoreMap();
     286        for(MeshScoreMap::const_iterator i = scoreMap.begin();
     287            i != scoreMap.end(); ++i) {
     288          const G4String& scoreMapName = i->first;
     289          const G4THitsMap<G4double>* foundHits = i->second;
     290          if (foundHits == &hits) {
     291            G4DefaultLinearColorMap colorMap("G4VSceneHandlerColorMap");
     292            scoreMapHits = true;
     293            mesh->DrawMesh(scoreMapName, &colorMap);
     294          }
     295        }
     296      }
     297    }
     298  }
     299  if (scoreMapHits) {
     300    static G4bool first = true;
     301    if (first) {
     302      first = false;
     303      G4cout <<
     304        "Scoring map drawn with default parameters."
     305        "\n  To get gMocren file for gMocren browser:"
     306        "\n    /vis/open gMocrenFile"
     307        "\n    /vis/viewer/flush"
     308        "\n  Many other options available with /score/draw... commands."
     309        "\n  You might want to \"/vis/viewer/set/autoRefresh false\"."
     310             << G4endl;
     311    }
     312  } else {  // Not score map hits.  Just call DrawAllHits.
     313    // Cast away const because DrawAllHits is non-const!!!!
     314    const_cast<G4THitsMap<G4double>&>(hits).DrawAllHits();
     315  }
    270316}
    271317
     
    456502    if (pPolyhedron) {
    457503      pPolyhedron -> SetVisAttributes (fpVisAttribs);
    458 #ifdef G4DEBUG_VIS_MANAGEMENT
    459       printf("G4VSceneHandler::RequestPrimitives VSolid: %d\n",pPolyhedron);
    460 #endif
    461       G4cout <<
    462         "G4VSceneHandler::RequestPrimitives VSolid " << solid.GetName () <<G4endl;
    463504      AddPrimitive (*pPolyhedron);
    464505    }
     
    481522void G4VSceneHandler::ProcessScene (G4VViewer&) {
    482523
    483 #ifdef G4DEBUG_VIS_MANAGEMENT
    484   printf("G4VSceneHandler::ProcessScene : BEGIN\n");
    485 #endif
    486 
    487524  if (!fpScene) return;
    488525
    489 #ifdef G4DEBUG_VIS_MANAGEMENT
    490   printf("G4VSceneHandler::ProcessScene : 2\n");
    491 #endif
    492526  G4VisManager* visManager = G4VisManager::GetInstance();
    493527
    494 #ifdef G4DEBUG_VIS_MANAGEMENT
    495   printf("G4VSceneHandler::ProcessScene : 3\n");
    496 #endif
    497528  if (!visManager->GetConcreteInstance()) return;
    498529
    499 #ifdef G4DEBUG_VIS_MANAGEMENT
    500   printf("G4VSceneHandler::ProcessScene : 4\n");
    501 #endif
    502530  G4VisManager::Verbosity verbosity = visManager->GetVerbosity();
    503531
    504532  fReadyForTransients = false;
    505533
    506 #ifdef G4DEBUG_VIS_MANAGEMENT
    507   printf("G4VSceneHandler::ProcessScene : Before clear store \n");
    508 #endif
    509534  // Clear stored scene, if any, i.e., display lists, scene graphs.
    510535  ClearStore ();
    511536
    512 #ifdef G4DEBUG_VIS_MANAGEMENT
    513   printf("G4VSceneHandler::ProcessScene : 5\n");
    514 #endif
    515537  // Reset fMarkForClearingTransientStore.  No need to clear transient
    516538  // store since it has just been cleared above.  (Leaving
     
    526548
    527549  if (runDurationModelList.size ()) {
    528 #ifdef G4DEBUG_VIS_MANAGEMENT
    529   printf("G4VSceneHandler::ProcessScene : 6\n");
    530 #endif
    531550    if (verbosity >= G4VisManager::confirmations) {
    532551      G4cout << "Traversing scene data..." << G4endl;
    533552    }
    534553
    535 #ifdef G4DEBUG_VIS_MANAGEMENT
    536     printf("G4VSceneHandler::ProcessScene : begin model\n");
    537 #endif
    538554    BeginModeling ();
    539555
     
    542558
    543559    for (size_t i = 0; i < runDurationModelList.size (); i++) {
    544 #ifdef G4DEBUG_VIS_MANAGEMENT
    545   printf("G4VSceneHandler::ProcessScene : 7\n");
    546 #endif
    547560      G4VModel* pModel = runDurationModelList[i];
    548561      // Note: this is not the place to take action on
     
    558571    // Repeat if required...
    559572    if (fSecondPassRequested) {
    560 #ifdef G4DEBUG_VIS_MANAGEMENT
    561   printf("G4VSceneHandler::ProcessScene : 8\n");
    562 #endif
    563573      fSecondPass = true;
    564574      for (size_t i = 0; i < runDurationModelList.size (); i++) {
    565 #ifdef G4DEBUG_VIS_MANAGEMENT
    566   printf("G4VSceneHandler::ProcessScene : 9\n");
    567 #endif
    568575        G4VModel* pModel = runDurationModelList[i];
    569576        pModel -> SetModelingParameters (pMP);
     
    585592  fReadyForTransients = true;
    586593
    587 #ifdef G4DEBUG_VIS_MANAGEMENT
    588   printf("G4VSceneHandler::ProcessScene : Idle ?\n");
    589 #endif
    590594  // Refresh event from end-of-event model list.
    591595  // Allow only in Idle or GeomClosed state...
     
    593597  G4ApplicationState state = stateManager->GetCurrentState();
    594598  if (state == G4State_Idle || state == G4State_GeomClosed) {
    595 #ifdef G4DEBUG_VIS_MANAGEMENT
    596     printf("G4VSceneHandler::ProcessScene : IDLE\n");
    597 #endif
    598599
    599600    visManager->SetEventRefreshing(true);
    600601
    601602    if (visManager->GetRequestedEvent()) {
    602 #ifdef G4DEBUG_VIS_MANAGEMENT
    603       printf("G4VSceneHandler::ProcessScene : DrawEvent\n");
    604 #endif
    605603      DrawEvent(visManager->GetRequestedEvent());
    606604
    607605    } else {
    608606
    609 #ifdef G4DEBUG_VIS_MANAGEMENT
    610       printf("G4VSceneHandler::ProcessScene : no event\n");
    611 #endif
    612607      G4RunManager* runManager = G4RunManager::GetRunManager();
    613608      if (runManager) {
    614 #ifdef G4DEBUG_VIS_MANAGEMENT
    615         printf("G4VSceneHandler::ProcessScene : runManager\n");
    616 #endif
    617609        const G4Run* run = runManager->GetCurrentRun();
    618610        const std::vector<const G4Event*>* events =
     
    622614        if (nKeptEvents) {
    623615
    624 #ifdef G4DEBUG_VIS_MANAGEMENT
    625         printf("G4VSceneHandler::ProcessScene : 1\n");
    626 #endif
    627616          if (fpScene->GetRefreshAtEndOfEvent()) {
    628 #ifdef G4DEBUG_VIS_MANAGEMENT
    629         printf("G4VSceneHandler::ProcessScene : 2\n");
    630 #endif
    631617
    632618            if (verbosity >= G4VisManager::confirmations) {
     
    638624
    639625          } else {  // Accumulating events.
    640 #ifdef G4DEBUG_VIS_MANAGEMENT
    641         printf("G4VSceneHandler::ProcessScene : 3\n");
    642 #endif
    643626
    644627            if (verbosity >= G4VisManager::confirmations) {
     
    646629            }
    647630            for (size_t i = 0; i < nKeptEvents; ++i) {
    648 #ifdef G4DEBUG_VIS_MANAGEMENT
    649         printf("G4VSceneHandler::ProcessScene : 4\n");
    650 #endif
    651631              const G4Event* event = (*events)[i];
    652632              if (event) DrawEvent(event);
     
    654634
    655635            if (!fpScene->GetRefreshAtEndOfRun()) {
    656 #ifdef G4DEBUG_VIS_MANAGEMENT
    657         printf("G4VSceneHandler::ProcessScene : 5\n");
    658 #endif
    659636              if (verbosity >= G4VisManager::warnings) {
    660637                G4cout <<
     
    671648  }
    672649
     650  // Refresh end-of-run model list.
     651  // Allow only in Idle or GeomClosed state...
     652  if (state == G4State_Idle || state == G4State_GeomClosed) {
     653    DrawEndOfRunModels();
     654  }
     655
    673656  fMarkForClearingTransientStore = tmpMarkForClearingTransientStore;
    674657}
     
    684667    for (size_t i = 0; i < nModels; i++) {
    685668      G4VModel* pModel = EOEModelList [i];
     669      pModel -> SetModelingParameters(pMP);
     670      SetModel (pModel);
     671      pModel -> DescribeYourselfTo (*this);
     672      pModel -> SetModelingParameters(0);
     673    }
     674    delete pMP;
     675    SetModel (0);
     676  }
     677}
     678
     679void G4VSceneHandler::DrawEndOfRunModels()
     680{
     681  const std::vector<G4VModel*>& EORModelList =
     682    fpScene -> GetEndOfRunModelList ();
     683  size_t nModels = EORModelList.size();
     684  if (nModels) {
     685    G4ModelingParameters* pMP = CreateModelingParameters();
     686    pMP->SetEvent(0);
     687    for (size_t i = 0; i < nModels; i++) {
     688      G4VModel* pModel = EORModelList [i];
    686689      pModel -> SetModelingParameters(pMP);
    687690      SetModel (pModel);
Note: See TracChangeset for help on using the changeset viewer.