G4XXXStoredViewer.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  7th March 2006
00031 // A template for a graphics driver with a store/database.
00032 //?? Lines beginning like this require specialisation for your driver.
00033 
00034 #include "G4XXXStoredViewer.hh"
00035 
00036 #include "G4VSceneHandler.hh"
00037 #include "G4XXXStoredSceneHandler.hh"
00038 
00039 #include <fstream>
00040 #include <sstream>
00041 
00042 G4XXXStoredViewer::G4XXXStoredViewer
00043 (G4VSceneHandler& sceneHandler, const G4String& name):
00044   G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
00045 {}
00046 
00047 G4XXXStoredViewer::~G4XXXStoredViewer() {}
00048 
00049 void G4XXXStoredViewer::SetView() {
00050 #ifdef G4XXXStoredDEBUG
00051   G4cout << "G4XXXStoredViewer::SetView() called." << G4endl;
00052 #endif
00053 }
00054 
00055 void G4XXXStoredViewer::ClearView() {
00056 #ifdef G4XXXStoredDEBUG
00057   G4cout << "G4XXXStoredViewer::ClearView() called." << G4endl;
00058 #endif
00059 }
00060 
00061 void G4XXXStoredViewer::DrawView() {
00062 #ifdef G4XXXStoredDEBUG
00063   G4cout << "G4XXXStoredViewer::DrawView() called." << G4endl;
00064 #endif
00065 
00066   // First, a view should decide when to re-visit the G4 kernel.
00067   // Sometimes it might not be necessary, e.g., if the scene is stored
00068   // in a graphical database (e.g., OpenGL's display lists) and only
00069   // the viewing angle has changed.  But graphics systems without a
00070   // graphical database will always need to visit the G4 kernel.
00071 
00072   // The fNeedKernelVisit flag might have been set by the user in
00073   // /vis/viewer/rebuild, but if not, make decision and set flag only
00074   // if necessary...
00075   if (!fNeedKernelVisit) KernelVisitDecision();
00076   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
00077 
00078   ProcessView ();  // Clears store and processes scene only if necessary.
00079 
00080   if (kernelVisitWasNeeded) {
00081     // Some systems, notably OpenGL, can draw while re-building, so
00082     // there might not be a need to draw from store again here.  But
00083     // in this case...
00084     DrawFromStore();
00085   } else {
00086     DrawFromStore();
00087   }
00088 
00089   // ...before finally...
00090   FinishView ();       // Flush streams and/or swap buffers.
00091 }
00092 
00093 void G4XXXStoredViewer::ShowView() {
00094 #ifdef G4XXXStoredDEBUG
00095   G4cout << "G4XXXStoredViewer::ShowView() called." << G4endl;
00096 #endif
00097 }
00098 
00099 void G4XXXStoredViewer::KernelVisitDecision () {
00100   
00101   // If there's a significant difference with the last view parameters
00102   // of either the scene handler or this viewer, trigger a rebuild.
00103 
00104   typedef std::list<G4String> Store;
00105   typedef std::list<G4String>::iterator StoreIterator;
00106   Store& store =
00107     static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
00108   if (store.empty() || CompareForKernelVisit(fLastVP)) {
00109     NeedKernelVisit ();  // Sets fNeedKernelVisit.
00110   }      
00111   fLastVP = fVP;
00112 }
00113 
00114 G4bool G4XXXStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
00115 {
00116   // Typical comparison.  Taken from OpenGL.
00117   if (
00118       (lastVP.GetDrawingStyle ()    != fVP.GetDrawingStyle ())    ||
00119       (lastVP.IsAuxEdgeVisible ()   != fVP.IsAuxEdgeVisible ())   ||
00120       (lastVP.GetRepStyle ()        != fVP.GetRepStyle ())        ||
00121       (lastVP.IsCulling ()          != fVP.IsCulling ())          ||
00122       (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
00123       (lastVP.IsDensityCulling ()   != fVP.IsDensityCulling ())   ||
00124       (lastVP.IsCullingCovered ()   != fVP.IsCullingCovered ())   ||
00125       // No need to visit kernel if section plane changes.
00126       // No need to visit kernel if cutaway planes change.
00127       (lastVP.IsExplode ()          != fVP.IsExplode ())          ||
00128       (lastVP.GetNoOfSides ()       != fVP.GetNoOfSides ())       ||
00129       (lastVP.IsMarkerNotHidden ()  != fVP.IsMarkerNotHidden ())  ||
00130       (lastVP.GetDefaultVisAttributes()->GetColour() !=
00131        fVP.GetDefaultVisAttributes()->GetColour())                ||
00132       (lastVP.GetDefaultTextVisAttributes()->GetColour() !=
00133        fVP.GetDefaultTextVisAttributes()->GetColour())            ||
00134       (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
00135       (lastVP.GetVisAttributesModifiers().size() !=
00136        fVP.GetVisAttributesModifiers().size())
00137       ) {
00138     return true;
00139   }
00140 
00141   if (lastVP.IsDensityCulling () &&
00142       (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
00143     return true;
00144 
00145   if (lastVP.IsExplode () &&
00146       (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
00147     return true;
00148 
00149   return false;
00150 }
00151 
00152 void G4XXXStoredViewer::DrawFromStore() {
00153   typedef std::list<G4String> Store;
00154   typedef std::list<G4String>::iterator StoreIterator;
00155   Store& store =
00156     static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
00157   // Write to a file for testing...
00158   static G4int iCount = 0;
00159   std::ostringstream oss;
00160   oss << fName << '.' << iCount++ << ".out";
00161   std::ofstream ofs(oss.str().c_str());
00162   for (StoreIterator i = store.begin(); i != store.end(); ++i) {
00163     ofs << *i;
00164   }
00165   ofs.close();
00166 }

Generated on Mon May 27 17:50:28 2013 for Geant4 by  doxygen 1.4.7