G4VisFilterManager.hh

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 // $Id$
00027 //
00028 // Filter manager. Manages filter models, factories, messengers, 
00029 // command placement, filter mode etc
00030 //
00031 // Jane Tinslay, March 2006
00032 //
00033 #ifndef G4VISFILTERMANAGER_HH
00034 #define G4VISFILTERMANAGER_HH
00035 
00036 #include "G4String.hh"
00037 #include "G4UImessenger.hh"
00038 #include "G4VFilter.hh"
00039 #include "G4VModelFactory.hh"
00040 #include <vector>
00041 
00042 namespace FilterMode {
00043   enum Mode {Soft, Hard};
00044 }
00045 
00046 template <typename T>
00047 class G4VisFilterManager {
00048 
00049 public:
00050 
00051   // Construct with command placement
00052   G4VisFilterManager(const G4String&);
00053 
00054   virtual ~G4VisFilterManager();
00055 
00056   // Useful typedef's
00057   typedef G4VFilter<T> Filter;
00058   typedef G4VModelFactory<Filter> Factory;
00059 
00060   // Registration methods
00061   void Register(Filter*);
00062   void Register(Factory*); 
00063 
00064   // Do filtering
00065   bool Accept(const T&);
00066 
00067   // Command placement
00068   G4String Placement() const;
00069 
00070   // Filter mode operations
00071   void SetMode(const FilterMode::Mode&);
00072   void SetMode(const G4String&);
00073   FilterMode::Mode GetMode() const;
00074 
00075   // Print configuration
00076   void Print(std::ostream& ostr, const G4String& name="") const;
00077 
00078   // Accessors
00079   const std::vector<Filter*>& FilterList() const;
00080   const std::vector<Factory*>& FactoryList() const;
00081 
00082 private:
00083 
00084   // Data members
00085   G4String fPlacement; // Placement 
00086   FilterMode::Mode fMode;
00087   std::vector<Factory*> fFactoryList;
00088   std::vector<Filter*> fFilterList;
00089   std::vector<G4UImessenger*> fMessengerList;
00090 
00091 };
00092 
00093 template <typename T>
00094 G4VisFilterManager<T>::G4VisFilterManager(const G4String& placement)
00095   :fPlacement(placement)
00096 {
00097   fMode = FilterMode::Hard;
00098 }
00099 
00100 template <typename T>
00101 G4VisFilterManager<T>::~G4VisFilterManager() 
00102 {
00103   // Cleanup
00104   std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
00105   
00106   while (iterMsgr != fMessengerList.end()) {
00107     delete *iterMsgr;
00108     iterMsgr++;
00109   }
00110   
00111   typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
00112   
00113   while (iterFactory != fFactoryList.end()) {
00114     delete *iterFactory;       
00115     iterFactory++;
00116   }
00117 
00118   typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin();
00119   
00120   while (iterFilter != fFilterList.end()) {
00121     delete *iterFilter;       
00122     iterFilter++;
00123   }
00124 }
00125 
00126 template <typename T>
00127 void
00128 G4VisFilterManager<T>::Register(Filter* filter)
00129 {
00130   fFilterList.push_back(filter);
00131 }
00132 
00133 template <typename T>
00134 void
00135 G4VisFilterManager<T>::Register(Factory* factory)
00136 {
00137   fFactoryList.push_back(factory);
00138 
00139   fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
00140 }
00141 
00142 template <typename T>
00143 bool
00144 G4VisFilterManager<T>::Accept(const T& obj)
00145 {
00146   typename std::vector<Filter*>::const_iterator iter = fFilterList.begin();
00147   bool passed(true);
00148   
00149   while (passed && (iter != fFilterList.end())) {
00150     passed = (*iter)->Accept(obj);
00151     iter++;
00152   }
00153 
00154   return passed;
00155 }
00156 
00157 template <typename T>
00158 G4String
00159 G4VisFilterManager<T>::Placement() const
00160 {
00161   return fPlacement;
00162 }
00163 
00164 template <typename T>
00165 void
00166 G4VisFilterManager<T>::SetMode(const G4String& mode) 
00167 {
00168   bool result(false);
00169   
00170   G4String myMode(mode);
00171   myMode.toLower();
00172 
00173   if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
00174   else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
00175 
00176   if (!result) {
00177     G4ExceptionDescription ed;
00178     ed << "Invalid Filter mode: "<<mode;
00179     G4Exception
00180       ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
00181   }
00182 }
00183 
00184 template <typename T>
00185 void
00186 G4VisFilterManager<T>::SetMode(const FilterMode::Mode& mode) 
00187 {
00188   fMode = mode;
00189 }
00190 
00191 template <typename T>
00192 FilterMode::Mode
00193 G4VisFilterManager<T>::GetMode() const
00194 {
00195   return fMode;
00196 }
00197 
00198 template <typename T>
00199 void
00200 G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
00201 { 
00202   ostr<<"Registered filter factories:"<<std::endl;
00203   typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
00204 
00205   while (iterFactory != fFactoryList.end()) {
00206     (*iterFactory)->Print(ostr);
00207     iterFactory++;
00208   }
00209 
00210   if (0 == fFactoryList.size()) ostr<<"  None"<<std::endl;
00211 
00212   ostr<<std::endl;
00213   ostr<<"Registered filters:"<<std::endl;
00214 
00215   typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
00216 
00217   while (iterFilter != fFilterList.end()) {
00218     if (!name.isNull()) {
00219       if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
00220     }
00221     else {
00222       (*iterFilter)->PrintAll(ostr);
00223     }
00224     iterFilter++;
00225   }
00226 
00227   if (0 == fFilterList.size()) ostr<<"  None"<<std::endl;
00228 }
00229 
00230 template <typename T>
00231 const std::vector< G4VFilter<T>* >&
00232 G4VisFilterManager<T>::FilterList() const
00233 { 
00234   return fFilterList;
00235 }
00236 
00237 template <typename T>
00238 const std::vector< G4VModelFactory< G4VFilter<T> >* >&
00239 G4VisFilterManager<T>::FactoryList() const
00240 { 
00241   return fFactoryList;
00242 }
00243 
00244 #endif

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