Import Geant4 8.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 14:44:26 +02:00
parent 8a51e0bc40
commit 216a75eeb1
8717 changed files with 360418 additions and 141343 deletions
+22 -16
View File
@@ -1,32 +1,36 @@
//
// ********************************************************************
// * DISCLAIMER *
// * License and Disclaimer *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXX.cc,v 1.4 2005/06/02 17:00:11 allison Exp $
// GEANT4 tag $Name: geant4-08-00 $
// $Id: G4XXX.cc,v 1.6 2006/06/29 21:27:22 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 5th April 2001
// A graphics system to dump geometry hierarchy.
// A template for a simplest possible graphics driver.
//?? Lines or sections marked like this require specialisation for your driver.
#include "G4XXX.hh"
#include "G4XXXSceneHandler.hh"
@@ -35,8 +39,10 @@
G4XXX::G4XXX():
G4VGraphicsSystem("G4XXX",
"XXX",
"A template graphics driver",
G4VGraphicsSystem::noFunctionality) {}
"Simplest possible graphics driver",
G4VGraphicsSystem::noFunctionality //?? Your functionality
)
{}
G4XXX::~G4XXX() {}
+75
View File
@@ -0,0 +1,75 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXFile.cc,v 1.2 2006/06/29 21:27:24 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a file-writing graphics driver.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXFile.hh"
#include "G4XXXFileSceneHandler.hh"
#include "G4XXXFileViewer.hh"
G4XXXFile::G4XXXFile():
G4VGraphicsSystem("G4XXXFile",
"XXXFile",
"File-writing graphics driver",
G4VGraphicsSystem::threeD //?? Your functionality
)
{}
G4XXXFile::~G4XXXFile() {}
G4VSceneHandler* G4XXXFile::CreateSceneHandler(const G4String& name) {
G4VSceneHandler* pScene = new G4XXXFileSceneHandler(*this, name);
return pScene;
}
G4VViewer* G4XXXFile::CreateViewer(G4VSceneHandler& scene,
const G4String& name) {
G4VViewer* pView =
new G4XXXFileViewer((G4XXXFileSceneHandler&) scene, name);
if (pView) {
if (pView->GetViewId() < 0) {
G4cout <<
"G4XXXFile::CreateViewer: ERROR flagged by negative"
" view id in G4XXXFileViewer creation."
"\n Destroying view and returning null pointer."
<< G4endl;
delete pView;
pView = 0;
}
}
else {
G4cout <<
"G4XXXFile::CreateViewer: ERROR: null pointer on new G4XXXFileViewer."
<< G4endl;
}
return pView;
}
@@ -0,0 +1,284 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXFileSceneHandler.cc,v 1.4 2006/06/29 21:27:26 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a file-writing graphics driver.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXFileSceneHandler.hh"
#include "G4XXXFileViewer.hh"
#include "G4PhysicalVolumeModel.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4NURBS.hh"
#include "G4VTrajectory.hh"
#include "G4AttDef.hh"
#include "G4AttValue.hh"
#include "G4UnitsTable.hh"
#include <sstream>
G4int G4XXXFileSceneHandler::fSceneIdCount = 0;
// Counter for XXX scene handlers.
G4XXXFileSceneHandler::G4XXXFileSceneHandler(G4VGraphicsSystem& system,
const G4String& name):
G4VSceneHandler(system, fSceneIdCount++, name)
{}
G4XXXFileSceneHandler::~G4XXXFileSceneHandler() {}
#ifdef G4XXXFileDEBUG
// Useful function...
void G4XXXFileSceneHandler::PrintThings() {
G4cout <<
" with transformation "
<< (void*)fpObjectTransformation;
if (fpModel) {
G4cout << " from " << fpModel->GetCurrentDescription()
<< " (tag " << fpModel->GetCurrentTag()
<< ')';
} else {
G4cout << "(not from a model)";
}
G4PhysicalVolumeModel* pPVModel =
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) {
G4cout <<
"\n current physical volume: "
<< pPVModel->GetCurrentPV()->GetName() <<
"\n current logical volume: "
<< pPVModel->GetCurrentLV()->GetName() <<
"\n current depth of geometry tree: "
<< pPVModel->GetCurrentDepth();
}
G4cout << G4endl;
}
#endif
// Note: This function overrides G4VSceneHandler::AddSolid(const
// G4Box&). You may not want to do this, but this is how it's done if
// you do. Certain other specific solids may be treated this way -
// see G4VSceneHandler.hh. The simplest possible driver would *not*
// implement these polymorphic functions, with the effect that the
// default versions in G4VSceneHandler are used, which simply call
// G4VSceneHandler::RequestPrimitives to turn the solid into a
// G4Polyhedron usually.
void G4XXXFileSceneHandler::AddSolid(const G4Box& box) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddSolid(const G4Box& box) called for "
<< box.GetName()
<< G4endl;
#endif
//?? Process your box...
std::ostringstream oss;
oss << "G4Box(" <<
G4String
(G4BestUnit
(G4ThreeVector
(box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
"Length")).strip() << ')';
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
}
void G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
<< polyline
<< G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
//?? Process polyline.
std::ostringstream oss;
oss << polyline;
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
}
void G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4Text& text) called.\n"
<< text
<< G4endl;
#endif
// Get text colour - special method since default text colour is
// determined by the default text vis attributes, which may be
// specified independent of default vis attributes of other types of
// visible objects.
//const G4Colour& c = GetTextColour (text); // Picks up default if none.
//?? Process text.
std::ostringstream oss;
oss << text;
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
}
void G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4Circle& circle) called.\n "
<< circle
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (circle, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
//?? Process circle.
std::ostringstream oss;
oss << circle;
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
}
void G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4Square& square) called.\n"
<< square
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (square, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
//?? Process square.
std::ostringstream oss;
oss << square;
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
}
void G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n"
<< polyhedron
<< G4endl;
#endif
//?? Process polyhedron.
std::ostringstream oss;
oss << polyhedron;
dynamic_cast<G4XXXFileViewer*>(fpViewer)->
GetFileWriter().WriteItem(oss.str());
//?? Or... here are some ideas for decomposing into polygons...
//Assume all facets are convex quadrilaterals.
//Draw each G4Facet individually
//Get colour, etc..
if (polyhedron.GetNoFacets() == 0) return;
// Get vis attributes - pick up defaults if none.
const G4VisAttributes* pVA =
fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
// Get view parameters that the user can force through the vis
// attributes, thereby over-riding the current view parameter.
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
//G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
//Get colour, etc..
//const G4Colour& c = pVA -> GetColour ();
// Initial action depending on drawing style.
switch (drawing_style) {
case (G4ViewParameters::hsr):
{
break;
}
case (G4ViewParameters::hlr):
{
break;
}
case (G4ViewParameters::wireframe):
{
break;
}
default:
{
break;
}
}
// Loop through all the facets...
// Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
// for an example of how to get facets out of a G4Polyhedron,
// including how to cope with triangles if that's a problem.
}
void G4XXXFileSceneHandler::AddPrimitive(const G4NURBS&) {
#ifdef G4XXXFileDEBUG
G4cout <<
"G4XXXFileSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
<< G4endl;
#endif
//?? Don't bother implementing this. NURBS are not functional.
}
@@ -0,0 +1,90 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXFileViewer.cc,v 1.2 2006/06/29 21:27:28 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a file-writing graphics driver.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXFileViewer.hh"
#include "G4VSceneHandler.hh"
#include "G4XXXFileSceneHandler.hh"
G4XXXFileViewer::G4XXXFileViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name),
fFileWriter(name + ".out")
{}
G4XXXFileViewer::~G4XXXFileViewer() {}
void G4XXXFileViewer::SetView() {
#ifdef G4XXXFileDEBUG
G4cout << "G4XXXFileViewer::SetView() called." << G4endl;
#endif
}
void G4XXXFileViewer::ClearView() {
#ifdef G4XXXFileDEBUG
G4cout << "G4XXXFileViewer::ClearView() called." << G4endl;
#endif
fFileWriter.Rewind();
}
void G4XXXFileViewer::DrawView() {
#ifdef G4XXXFileDEBUG
G4cout << "G4XXXFileViewer::DrawView() called." << G4endl;
#endif
// First, a view should decide when to re-visit the G4 kernel.
// Sometimes it might not be necessary, e.g., if the scene is stored
// in a graphical database (e.g., OpenGL's display lists) and only
// the viewing angle has changed. But graphics systems without a
// graphical database will always need to visit the G4 kernel.
NeedKernelVisit (); // Default is - always visit G4 kernel.
// Note: this routine sets the fNeedKernelVisit flag of *all* the
// views of the scene.
ProcessView (); // The basic logic is here.
// Then a view may have more to do, e.g., display the graphical
// database. That code should come here...
// ...before finally...
FinishView (); // Flush streams and/or swap buffers.
}
void G4XXXFileViewer::ShowView() {
#ifdef G4XXXFileDEBUG
G4cout << "G4XXXFileViewer::ShowView() called." << G4endl;
#endif
fFileWriter.Close();
}
+77
View File
@@ -0,0 +1,77 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXSG.cc,v 1.2 2006/06/29 21:27:33 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 10th March 2005
// A template for a sophisticated graphics driver with a scene graph.
//?? Lines or sections marked like this require specialisation for your driver.
#ifdef G4VIS_BUILD_XXXSG_DRIVER
#include "G4XXXSG.hh"
#include "G4XXXSGSceneHandler.hh"
#include "G4XXXSGViewer.hh"
G4XXXSG::G4XXXSG():
G4VGraphicsSystem("G4XXXSG",
"XXXSG",
"Graphics driver with scene graph",
G4VGraphicsSystem::threeD) {} //?? Your functionality.
G4XXXSG::~G4XXXSG() {}
G4VSceneHandler* G4XXXSG::CreateSceneHandler(const G4String& name) {
G4VSceneHandler* pScene = new G4XXXSGSceneHandler(*this, name);
return pScene;
}
G4VViewer* G4XXXSG::CreateViewer(G4VSceneHandler& scene,
const G4String& name) {
G4VViewer* pView =
new G4XXXSGViewer((G4XXXSGSceneHandler&) scene, name);
if (pView) {
if (pView->GetViewId() < 0) {
G4cout <<
"G4XXXSG::CreateViewer: ERROR flagged by negative"
" view id in G4XXXSGViewer creation."
"\n Destroying view and returning null pointer."
<< G4endl;
delete pView;
pView = 0;
}
}
else {
G4cout <<
"G4XXXSG::CreateViewer: ERROR: null pointer on new G4XXXSGViewer."
<< G4endl;
}
return pView;
}
#endif
@@ -0,0 +1,423 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXSGSceneHandler.cc,v 1.3 2006/06/29 21:27:39 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 10th March 2006
// A template for a sophisticated graphics driver with a scene graph.
//?? Lines beginning like this require specialisation for your driver.
#ifdef G4VIS_BUILD_XXXSG_DRIVER
#include "G4XXXSGSceneHandler.hh"
#include "G4XXXSGViewer.hh"
#include "G4PhysicalVolumeModel.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4NURBS.hh"
#include "G4VTrajectory.hh"
#include "G4AttDef.hh"
#include "G4AttValue.hh"
#include "G4UnitsTable.hh"
#include <sstream>
G4int G4XXXSGSceneHandler::fSceneIdCount = 0;
// Counter for XXX scene handlers.
G4XXXSGSceneHandler::G4XXXSGSceneHandler(G4VGraphicsSystem& system,
const G4String& name):
G4VSceneHandler(system, fSceneIdCount++, name)
{
fRoot = fSceneGraph.setRoot("root");
fPermanentsRoot = fRoot.push_back("permanentsRoot");
fTransientsRoot = fRoot.push_back("transientsRoot");
}
G4XXXSGSceneHandler::~G4XXXSGSceneHandler() {}
#ifdef G4XXXSGDEBUG
// Useful function...
void G4XXXSGSceneHandler::PrintThings() {
G4cout <<
" with transformation "
<< (void*)fpObjectTransformation;
if (fpModel) {
G4cout << " from " << fpModel->GetCurrentDescription()
<< " (tag " << fpModel->GetCurrentTag()
<< ')';
} else {
G4cout << "(not from a model)";
}
G4PhysicalVolumeModel* pPVModel =
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) {
G4cout <<
"\n current physical volume: "
<< pPVModel->GetCurrentPV()->GetName() <<
"\n current logical volume: "
<< pPVModel->GetCurrentLV()->GetName() <<
"\n current depth of geometry tree: "
<< pPVModel->GetCurrentDepth();
}
G4cout << G4endl;
}
#endif
void G4XXXSGSceneHandler::CreateCurrentItem(const G4String& header) {
// Utility for PreAddSolid and BeginPrimitives.
G4PhysicalVolumeModel* pPVModel =
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) {
// This call comes from a G4PhysicalVolumeModel. drawnPVPath is
// the path of the current drawn (non-culled) volume in terms of
// drawn (non-culled) ancesters. Each node is identified by a
// PVNodeID object, which is a physical volume and copy number. It
// is a vector of PVNodeIDs corresponding to the geometry hierarchy
// actually selected, i.e., not culled.
typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
typedef std::vector<PVNodeID> PVPath;
const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath();
//G4int currentDepth = pPVModel->GetCurrentDepth();
//G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
//G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial();
// The simplest algorithm, used by the Open Inventor Driver
// developers, is to rely on the fact the G4PhysicalVolumeModel
// traverses the geometry hierarchy in an orderly manner. The last
// mother, if any, will be the node to which the volume should be
// added. So it is enough to keep a map of scene graph nodes keyed
// on the volume path ID. Actually, it is enough to use the logical
// volume as the key. (An alternative would be to keep the PVNodeID
// in the tree and match the PVPath from the root down.)
// Find mother. ri points to drawn mother, if any.
PVPath::const_reverse_iterator ri = ++drawnPVPath.rbegin();
if (ri != drawnPVPath.rend()) {
// This volume has a mother.
G4LogicalVolume* drawnMotherLV =
ri->GetPhysicalVolume()->GetLogicalVolume();
LVMapIterator mother = fLVMap.find(drawnMotherLV);
if (mother != fLVMap.end()) {
// This adds a child in Troy's tree...
fCurrentItem = mother->second.push_back(header);
} else {
// Mother not previously encountered. Shouldn't happen, since
// G4PhysicalVolumeModel sends volumes as it encounters them,
// i.e., mothers before daughters, in its descent of the
// geometry tree. Error!
G4cout << "ERROR: G4XXXSGSceneHandler::PreAddSolid: Mother "
<< ri->GetPhysicalVolume()->GetName()
<< ':' << ri->GetCopyNo()
<< " not previously encountered."
"\nShouldn't happen! Please report to visualization coordinator."
<< G4endl;
// Continue anyway. Add to root of scene graph tree...
fCurrentItem = fPermanentsRoot.push_back(header);
}
} else {
// This volume has no mother. Must be a top level un-culled
// volume. Add to root of scene graph tree...
fCurrentItem = fPermanentsRoot.push_back(header);
}
std::ostringstream oss;
oss << "Path of drawn PVs: ";
for (PVPath::const_iterator i = drawnPVPath.begin();
i != drawnPVPath.end(); ++i) {
oss << '/' << i->GetPhysicalVolume()->GetName()
<< ':' << i->GetCopyNo();
}
oss << std::endl;
*fCurrentItem += oss.str();
// Store for future searches. Overwrites previous entries for this
// LV, so entry is always the *last* LV.
fLVMap[pCurrentLV] = fCurrentItem;
} else { // Not from a G4PhysicalVolumeModel.
// Create a place for current solid in root...
if (fReadyForTransients) {
fCurrentItem = fTransientsRoot.push_back(header);
} else {
fCurrentItem = fPermanentsRoot.push_back(header);
}
}
}
void G4XXXSGSceneHandler::PreAddSolid
(const G4Transform3D& objectTransformation,
const G4VisAttributes& visAttribs)
{
G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs);
CreateCurrentItem(G4String("\nPreAddSolid:\n"));
}
void G4XXXSGSceneHandler::PostAddSolid()
{
*fCurrentItem += "EndSolid\n";
G4VSceneHandler::PostAddSolid();
}
void G4XXXSGSceneHandler::BeginPrimitives
(const G4Transform3D& objectTransformation)
{
G4VSceneHandler::BeginPrimitives(objectTransformation);
// If thread of control has already passed through PreAddSolid,
// avoid opening a graphical data base component again.
if (!fProcessingSolid) {
CreateCurrentItem(G4String("\nBeginPrimitives:\n"));
}
}
void G4XXXSGSceneHandler::EndPrimitives ()
{
if (!fProcessingSolid) { // Already done if so.
*fCurrentItem += "EndPrimitives\n";
}
G4VSceneHandler::EndPrimitives ();
}
// Note: This function overrides G4VSceneHandler::AddSolid(const
// G4Box&). You may not want to do this, but this is how it's done if
// you do. Certain other specific solids may be treated this way -
// see G4VSceneHandler.hh. The simplest possible driver would *not*
// implement these polymorphic functions, with the effect that the
// default versions in G4VSceneHandler are used, which simply call
// G4VSceneHandler::RequestPrimitives to turn the solid into a
// G4Polyhedron usually.
// Don't forget, solids can be transients too (e.g., representing a hit).
void G4XXXSGSceneHandler::AddSolid(const G4Box& box) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddSolid(const G4Box& box) called for "
<< box.GetName()
<< G4endl;
#endif
//?? Process your box...
std::ostringstream oss;
oss << "G4Box(" <<
G4String
(G4BestUnit
(G4ThreeVector
(box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
"Length")).strip() << ')' << std::endl;
*fCurrentItem += oss.str();
}
void G4XXXSGSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
<< polyline
<< G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
//?? Process polyline.
std::ostringstream oss;
oss << polyline << std::endl;
*fCurrentItem += oss.str();
}
void G4XXXSGSceneHandler::AddPrimitive(const G4Text& text) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4Text& text) called.\n"
<< text
<< G4endl;
#endif
// Get text colour - special method since default text colour is
// determined by the default text vis attributes, which may be
// specified independent of default vis attributes of other types of
// visible objects.
//const G4Colour& c = GetTextColour (text); // Picks up default if none.
//?? Process text.
std::ostringstream oss;
oss << text << std::endl;
*fCurrentItem += oss.str();
}
void G4XXXSGSceneHandler::AddPrimitive(const G4Circle& circle) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4Circle& circle) called.\n"
<< circle
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (circle, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
//?? Process circle.
std::ostringstream oss;
oss << circle << std::endl;
*fCurrentItem += oss.str();
}
void G4XXXSGSceneHandler::AddPrimitive(const G4Square& square) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4Square& square) called.\n"
<< square
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (square, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
//?? Process square.
std::ostringstream oss;
oss << square << std::endl;
*fCurrentItem += oss.str();
}
void G4XXXSGSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n"
<< polyhedron
<< G4endl;
#endif
//?? Process polyhedron.
std::ostringstream oss;
oss << polyhedron;
*fCurrentItem += oss.str();
//?? Or... here are some ideas for decomposing into polygons...
//Assume all facets are convex quadrilaterals.
//Draw each G4Facet individually
//Get colour, etc..
if (polyhedron.GetNoFacets() == 0) return;
// Get vis attributes - pick up defaults if none.
const G4VisAttributes* pVA =
fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
// Get view parameters that the user can force through the vis
// attributes, thereby over-riding the current view parameter.
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
//G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
//Get colour, etc..
//const G4Colour& c = pVA -> GetColour ();
// Initial action depending on drawing style.
switch (drawing_style) {
case (G4ViewParameters::hsr):
{
break;
}
case (G4ViewParameters::hlr):
{
break;
}
case (G4ViewParameters::wireframe):
{
break;
}
default:
{
break;
}
}
// Loop through all the facets...
// Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
// for an example of how to get facets out of a G4Polyhedron,
// including how to cope with triangles if that's a problem.
}
void G4XXXSGSceneHandler::AddPrimitive(const G4NURBS& nurbs) {
#ifdef G4XXXSGDEBUG
G4cout <<
"G4XXXSGSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
<< G4endl;
#endif
//?? Don't bother implementing this. NURBS are not functional.
}
void G4XXXSGSceneHandler::ClearStore () {
G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc.
fPermanentsRoot.clear();
fTransientsRoot.clear();
fLVMap.clear();
}
void G4XXXSGSceneHandler::ClearTransientStore () {
G4VSceneHandler::ClearTransientStore ();
fTransientsRoot.clear();
}
#endif
@@ -0,0 +1,175 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXSGViewer.cc,v 1.3 2006/06/29 21:27:42 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 10th March 2006
// A template for a sophisticated graphics driver with a scene graph.
//?? Lines beginning like this require specialisation for your driver.
#ifdef G4VIS_BUILD_XXXSG_DRIVER
#include "G4XXXSGViewer.hh"
#include "G4VSceneHandler.hh"
#include "G4XXXSGSceneHandler.hh"
#include <fstream>
G4XXXSGViewer::G4XXXSGViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
{}
G4XXXSGViewer::~G4XXXSGViewer() {}
void G4XXXSGViewer::SetView() {
//#ifdef G4XXXSGDEBUG
G4cout << "G4XXXSGViewer::SetView() called." << G4endl;
//#endif
}
void G4XXXSGViewer::ClearView() {
//#ifdef G4XXXSGDEBUG
G4cout << "G4XXXSGViewer::ClearView() called." << G4endl;
//#endif
}
void G4XXXSGViewer::DrawView() {
//#ifdef G4XXXSGDEBUG
G4cout << "G4XXXSGViewer::DrawView() called." << G4endl;
//#endif
// First, a view should decide when to re-visit the G4 kernel.
// Sometimes it might not be necessary, e.g., if the scene is stored
// in a graphical database (e.g., OpenGL's display lists) and only
// the viewing angle has changed. But graphics systems without a
// graphical database will always need to visit the G4 kernel.
// The fNeedKernelVisit flag might have been set by the user in
// /vis/viewer/rebuild, but if not, make decision and set flag only
// if necessary...
if (!fNeedKernelVisit) KernelVisitDecision();
G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
ProcessView (); // Clears store and processes scene only if necessary.
if (kernelVisitWasNeeded) {
// Some systems, notably OpenGL, can draw while re-building, so
// there might not be a need to draw from store again here. But
// in this case...
DrawFromStore("G4XXXSGViewer::DrawView");
} else {
DrawFromStore("G4XXXSGViewer::DrawView");
}
// ...before finally...
FinishView (); // Flush streams and/or swap buffers.
}
void G4XXXSGViewer::ShowView() {
//#ifdef G4XXXSGDEBUG
G4cout << "G4XXXSGViewer::ShowView() called." << G4endl;
//#endif
// This is what you should see...
DrawFromStore("G4XXXSGViewer::ShowView");
}
void G4XXXSGViewer::KernelVisitDecision () {
// If there's a significant difference with the last view parameters
// of either the scene handler or this viewer, trigger a rebuild.
typedef taj::tree<G4String> SceneGraph;
typedef taj::tree<G4String>::iterator SceneGraphIterator;
SceneGraph& sceneGraph =
static_cast<G4XXXSGSceneHandler&>(fSceneHandler).fSceneGraph;
if (sceneGraph.size() == 3 // I.e., only the root nodes.
|| CompareForKernelVisit(fLastVP)) {
NeedKernelVisit (); // Sets fNeedKernelVisit.
}
fLastVP = fVP;
}
G4bool G4XXXSGViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
{
// Typical comparison. Taken from OpenGL.
if (
(lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
(lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
(lastVP.IsCulling () != fVP.IsCulling ()) ||
(lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
(lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
(lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
(lastVP.IsSection () != fVP.IsSection ()) ||
// No need to visit kernel if section plane changes.
(lastVP.IsCutaway () != fVP.IsCutaway ()) ||
(lastVP.GetCutawayPlanes ().size () !=
fVP.GetCutawayPlanes ().size ()) ||
// No need to visit kernel if cutaway planes change.
(lastVP.IsExplode () != fVP.IsExplode ()) ||
(lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
(lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())
) {
return true;
}
if (lastVP.IsDensityCulling () &&
(lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
return true;
if (lastVP.IsExplode () &&
(lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
return true;
return false;
}
void G4XXXSGViewer::DrawFromStore(const G4String& source) {
typedef taj::tree<G4String> SceneGraph;
typedef taj::tree<G4String>::preorder_iterator SceneGraphPreIterator;
SceneGraph& sceneGraph =
static_cast<G4XXXSGSceneHandler&>(fSceneHandler).fSceneGraph;
// Write to a file for testing...
static G4int iCount = 0;
std::ostringstream oss;
oss << source << '.' << fName << '.' << iCount++ << ".out";
G4cout << "Writing " << oss.str() << G4endl;
std::ofstream ofs(oss.str().c_str());
for (SceneGraphPreIterator i = sceneGraph.beginPre();
i != sceneGraph.endPre(); ++i) {
G4int depth = 0;
SceneGraphPreIterator j = i;
while (j != sceneGraph.getRoot()) {j = j.parent(); ++depth;}
ofs << "\nDepth: " << depth;
ofs << *i;
}
ofs.close();
}
#endif
+72 -290
View File
@@ -1,59 +1,54 @@
//
// ********************************************************************
// * DISCLAIMER *
// * License and Disclaimer *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXSceneHandler.cc,v 1.25 2005/11/22 16:25:07 allison Exp $
// GEANT4 tag $Name: geant4-08-00 $
// $Id: G4XXXSceneHandler.cc,v 1.31 2006/06/29 21:27:44 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 5th April 2001
// A base class for a scene handler to dump geometry hierarchy.
// Based on a provisional G4XXXGraphicsScene (was in modeling).
// A template for a simplest possible graphics driver.
//?? Lines or sections marked like this require specialisation for your driver.
#include "G4XXXSceneHandler.hh"
#include "G4Box.hh"
#include "G4Cons.hh"
#include "G4Tubs.hh"
#include "G4Trd.hh"
#include "G4Trap.hh"
#include "G4Sphere.hh"
#include "G4Para.hh"
#include "G4Torus.hh"
#include "G4Polycone.hh"
#include "G4Polyhedra.hh"
#include "G4PhysicalVolumeModel.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4ModelingParameters.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
/*
#include "G4NURBS.hh"
#include "G4VTrajectory.hh"
#include "G4AttDef.hh"
#include "G4AttValue.hh"
*/
#include "G4UnitsTable.hh"
G4int G4XXXSceneHandler::fSceneIdCount = 0;
// Counter for XXX scene handlers.
@@ -69,269 +64,56 @@ G4XXXSceneHandler::~G4XXXSceneHandler() {}
void G4XXXSceneHandler::PrintThings() {
G4cout <<
" with transformation "
<< (void*)fpObjectTransformation
<< " from " << fpModel->GetCurrentDescription()
<< " (tag " << fpModel->GetCurrentTag()
<< ')';
if (fpCurrentPV) {
<< (void*)fpObjectTransformation;
if (fpModel) {
G4cout << " from " << fpModel->GetCurrentDescription()
<< " (tag " << fpModel->GetCurrentTag()
<< ')';
} else {
G4cout << "(not from a model)";
}
G4PhysicalVolumeModel* pPVModel =
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) {
G4cout <<
"\n current physical volume: "
<< fpCurrentPV->GetName() <<
<< pPVModel->GetCurrentPV()->GetName() <<
"\n current logical volume: "
<< fpCurrentLV->GetName() <<
<< pPVModel->GetCurrentLV()->GetName() <<
"\n current depth of geometry tree: "
<< fCurrentDepth;
<< pPVModel->GetCurrentDepth();
}
G4cout << G4endl;
}
#endif
#include <vector>
std::vector<std::pair<G4VPhysicalVolume*, G4int> > fPVPath;
typedef
std::vector<std::pair<G4VPhysicalVolume*, G4int> >::const_iterator
PVPath_const_iterator;
void G4XXXSceneHandler::PreAddSolid
(const G4Transform3D&, const G4VisAttributes&) {
using namespace std;
G4cout <<
"Current PV/LV/depth: "
<< fpCurrentPV->GetName() <<
"/"
<< fpCurrentLV->GetName() <<
"/"
<< fCurrentDepth
<< G4endl;
// How to establish a tree (even when some volumes have been
// culled)...
static G4int lastDepth = 0;
static G4LogicalVolume* lastMotherLV = 0;
G4int copyNo = fpCurrentPV->GetCopyNo();
if (fCurrentDepth > lastDepth) {
while (fCurrentDepth > lastDepth++) {
fPVPath.push_back(make_pair((G4VPhysicalVolume*)0,0));
}
fPVPath.back() = make_pair(fpCurrentPV,copyNo);
} else if (fCurrentDepth == lastDepth) {
fPVPath.back() = make_pair(fpCurrentPV,copyNo);
} else {
while (fCurrentDepth < lastDepth--) {
fPVPath.pop_back();
}
fPVPath.back() = make_pair(fpCurrentPV,copyNo);
}
lastDepth = fCurrentDepth;
lastMotherLV = fpCurrentPV->GetMotherLogical();
// Debug printing...
for (PVPath_const_iterator i = fPVPath.begin(); i != fPVPath.end(); ++i) {
if ((*i).first) {
G4cout << '/' << (*i).first->GetName();
} else {
G4cout << 0;
}
G4cout << ':' << (*i).second;
}
G4cout << G4endl;
/***********************************************
fLVSet.insert(fpCurrentLV);
G4LogicalVolume* motherLV = fpCurrentPV->GetMotherLogical();
if (motherLV) {
if (fLVSet.find(motherLV) == fLVSet.end()) {
// Mother not previously encountered - must have been culled.
G4cout << "Mother LV \"" << motherLV->GetName()
<< "\" not found." << G4endl;
// Search back up hierarchy...
do {
G4LogicalVolume* possibleMotherLV = 0;
G4LogicalVolumeStore* Store = G4LogicalVolumeStore::GetInstance();
for ( size_t LV=0; LV < Store->size(); LV++ ) {
G4LogicalVolume* aLogVol = (*Store)[LV];
if(aLogVol != this) { // Don't look for it inside itself!
for (G4int daughter=0; daughter < aLogVol->GetNoDaughters(); daughter++ ) {
if( aLogVol->GetDaughter(daughter)->GetLogicalVolume()==this )
{
// aLogVol is the mother !!!
//
motherLogVol = aLogVol;
break;
}
}
}
}
motherLV = motherLV->GetPhysicalVolume()->GetMotherLogical();
} while (motherLV && fLVSet.find(motherLV) == fLVSet.end());
G4cout << "Mother LV \"" << motherLV->GetName()
<< "\" found." << G4endl;
}
}
****************************************/
}
void G4XXXSceneHandler::AddSolid(const G4Box& box) {
void G4XXXSceneHandler::AddPrimitive(const G4Polyline&
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Box& box) called for "
<< box.GetName()
<< G4endl;
PrintThings();
polyline
#endif
G4VSceneHandler::AddSolid(box); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Cons& cons) {
) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Cons& cons) called for "
<< cons.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(cons); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Tubs& tubs) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Tubs& tubs) called for "
<< tubs.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(tubs); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Trd& trd) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Trd& trd) called for "
<< trd.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(trd); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Trap& trap) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Trap& trap) called for "
<< trap.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(trap); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Sphere& sphere) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Sphere& sphere) called for "
<< sphere.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(sphere); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Para& para) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Para& para) called for "
<< para.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(para); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Torus& torus) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Torus& torus) called for "
<< torus.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(torus); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Polycone& polycone) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Polycone& polycone) called for "
<< polycone.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(polycone); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4Polyhedra& polyhedra) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Polyhedra& polyhedra) called for "
<< polyhedra.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(polyhedra); // Invoke default action.
}
void G4XXXSceneHandler::AddSolid(const G4VSolid& solid) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddSolid(const G4Solid& solid) called for "
<< solid.GetName()
<< G4endl;
PrintThings();
#endif
G4VSceneHandler::AddSolid(solid); // Invoke default action.
}
void G4XXXSceneHandler::AddCompound(const G4VTrajectory& traj) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddCompound(const G4VTrajectory& traj) called."
<< G4endl;
#endif
G4VSceneHandler::AddCompound(traj); // Draw trajectory in good old way for now.
traj.ShowTrajectory();
G4cout << G4endl;
}
void G4XXXSceneHandler::AddCompound(const G4VHit& hit) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddCompound(const G4VHit& hit) called."
<< G4endl;
#endif
G4VSceneHandler::AddCompound(hit); // Invoke default action.
}
void G4XXXSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddPrimitive(const G4Polyline& polyline) called:"
"\n polyline: " << polyline
"G4XXXSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
<< polyline
<< G4endl;
PrintThings();
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
//?? Process polyline.
}
void G4XXXSceneHandler::AddPrimitive(const G4Text& text) {
void G4XXXSceneHandler::AddPrimitive(const G4Text&
#ifdef G4XXXDEBUG
text
#endif
) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddPrimitive(const G4Text& text) called:"
"\n text: " << text.GetText()
"G4XXXSceneHandler::AddPrimitive(const G4Text& text) called.\n"
<< text
<< G4endl;
PrintThings();
#endif
@@ -340,12 +122,19 @@ void G4XXXSceneHandler::AddPrimitive(const G4Text& text) {
// specified independent of default vis attributes of other types of
// visible objects.
//const G4Colour& c = GetTextColour (text); // Picks up default if none.
//?? Process text.
}
void G4XXXSceneHandler::AddPrimitive(const G4Circle& circle) {
void G4XXXSceneHandler::AddPrimitive(const G4Circle&
#ifdef G4XXXDEBUG
circle
#endif
) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddPrimitive(const G4Circle& circle) called:\n ";
"G4XXXSceneHandler::AddPrimitive(const G4Circle& circle) called.\n"
<< circle
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (circle, sizeType);
switch (sizeType) {
@@ -365,12 +154,19 @@ void G4XXXSceneHandler::AddPrimitive(const G4Circle& circle) {
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
//?? Process circle.
}
void G4XXXSceneHandler::AddPrimitive(const G4Square& square) {
void G4XXXSceneHandler::AddPrimitive(const G4Square&
#ifdef G4XXXDEBUG
square
#endif
) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddPrimitive(const G4Square& square) called:\n ";
"G4XXXSceneHandler::AddPrimitive(const G4Square& square) called.\n"
<< square
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (square, sizeType);
switch (sizeType) {
@@ -390,16 +186,18 @@ void G4XXXSceneHandler::AddPrimitive(const G4Square& square) {
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
//?? Process square.
}
void G4XXXSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
#ifdef G4XXXDEBUG
G4cout <<
"G4XXXSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called."
"G4XXXSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called.\n"
<< polyhedron
<< G4endl;
PrintThings();
#endif
//?? Process polyhedron. Here are some ideas...
//Assume all facets are convex quadrilaterals.
//Draw each G4Facet individually
@@ -438,12 +236,11 @@ void G4XXXSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
}
}
//Loop through all the facets...
// Loop through all the facets...
// Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
// for an example of how to get facets out of a G4Polyhedron,
// including how to cope with triangles if that's a problem.
}
void G4XXXSceneHandler::AddPrimitive(const G4NURBS&) {
@@ -453,20 +250,5 @@ void G4XXXSceneHandler::AddPrimitive(const G4NURBS&) {
<< G4endl;
PrintThings();
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (nurbs.GetVisAttributes ());
}
void G4XXXSceneHandler::ClearTransientStore () {
G4VSceneHandler::ClearTransientStore ();
// This is typically called after an update and before drawing hits
// of the next event. To simulate the clearing of "transients"
// (hits, etc.) in a system without a graphical database, the
// detector is redrawn...
if (fpViewer) {
fpViewer -> SetView ();
fpViewer -> ClearView ();
fpViewer -> DrawView ();
}
//?? Don't bother implementing this. NURBS are not functional.
}
@@ -0,0 +1,75 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXStored.cc,v 1.2 2006/06/29 21:27:46 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a graphics driver with a store/database.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXStored.hh"
#include "G4XXXStoredSceneHandler.hh"
#include "G4XXXStoredViewer.hh"
G4XXXStored::G4XXXStored():
G4VGraphicsSystem("G4XXXStored",
"XXXStored",
"Graphics driver with a store/database",
G4VGraphicsSystem::threeD //?? Your functionality
)
{}
G4XXXStored::~G4XXXStored() {}
G4VSceneHandler* G4XXXStored::CreateSceneHandler(const G4String& name) {
G4VSceneHandler* pScene = new G4XXXStoredSceneHandler(*this, name);
return pScene;
}
G4VViewer* G4XXXStored::CreateViewer(G4VSceneHandler& scene,
const G4String& name) {
G4VViewer* pView =
new G4XXXStoredViewer((G4XXXStoredSceneHandler&) scene, name);
if (pView) {
if (pView->GetViewId() < 0) {
G4cout <<
"G4XXXStored::CreateViewer: ERROR flagged by negative"
" view id in G4XXXStoredViewer creation."
"\n Destroying view and returning null pointer."
<< G4endl;
delete pView;
pView = 0;
}
}
else {
G4cout <<
"G4XXXStored::CreateViewer: ERROR: null pointer on new G4XXXStoredViewer."
<< G4endl;
}
return pView;
}
@@ -0,0 +1,357 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXStoredSceneHandler.cc,v 1.4 2006/06/29 21:27:48 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a graphics driver with a store/database.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXStoredSceneHandler.hh"
#include "G4XXXStoredViewer.hh"
#include "G4PhysicalVolumeModel.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Polyline.hh"
#include "G4Text.hh"
#include "G4Circle.hh"
#include "G4Square.hh"
#include "G4Polyhedron.hh"
#include "G4NURBS.hh"
#include "G4VTrajectory.hh"
#include "G4AttDef.hh"
#include "G4AttValue.hh"
#include "G4UnitsTable.hh"
#include <sstream>
G4int G4XXXStoredSceneHandler::fSceneIdCount = 0;
// Counter for XXX scene handlers.
G4XXXStoredSceneHandler::G4XXXStoredSceneHandler(G4VGraphicsSystem& system,
const G4String& name):
G4VSceneHandler(system, fSceneIdCount++, name)
{}
G4XXXStoredSceneHandler::~G4XXXStoredSceneHandler() {}
#ifdef G4XXXStoredDEBUG
// Useful function...
void G4XXXStoredSceneHandler::PrintThings() {
G4cout <<
" with transformation "
<< (void*)fpObjectTransformation;
if (fpModel) {
G4cout << " from " << fpModel->GetCurrentDescription()
<< " (tag " << fpModel->GetCurrentTag()
<< ')';
} else {
G4cout << "(not from a model)";
}
G4PhysicalVolumeModel* pPVModel =
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
if (pPVModel) {
G4cout <<
"\n current physical volume: "
<< pPVModel->GetCurrentPV()->GetName() <<
"\n current logical volume: "
<< pPVModel->GetCurrentLV()->GetName() <<
"\n current depth of geometry tree: "
<< pPVModel->GetCurrentDepth();
}
G4cout << G4endl;
}
#endif
void G4XXXStoredSceneHandler::PreAddSolid
(const G4Transform3D& objectTransformation,
const G4VisAttributes& visAttribs)
{
G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs);
// Create a place for current solid...
fCurrentItem = fStore.insert(fStore.end(), G4String("\nPreAddSolid:\n"));
if (fReadyForTransients) {
fTransients.push_back(fCurrentItem);
} else {
fPermanents.push_back(fCurrentItem);
}
}
void G4XXXStoredSceneHandler::PostAddSolid()
{
*fCurrentItem += "\nEndSolid\n";
G4VSceneHandler::PostAddSolid();
}
void G4XXXStoredSceneHandler::BeginPrimitives
(const G4Transform3D& objectTransformation)
{
G4VSceneHandler::BeginPrimitives(objectTransformation);
// If thread of control has already passed through PreAddSolid,
// avoid opening a graphical data base component again.
if (!fProcessingSolid) {
// Create a place for current primitive...
fCurrentItem = fStore.insert(fStore.end(),
G4String("\nBeginPrimitives:\n"));
if (fReadyForTransients) {
fTransients.push_back(fCurrentItem);
} else {
fPermanents.push_back(fCurrentItem);
}
}
}
void G4XXXStoredSceneHandler::EndPrimitives ()
{
if (!fProcessingSolid) { // Already done if so.
*fCurrentItem += "\nEndPrimitives\n";
}
G4VSceneHandler::EndPrimitives ();
}
// Note: This function overrides G4VSceneHandler::AddSolid(const
// G4Box&). You may not want to do this, but this is how it's done if
// you do. Certain other specific solids may be treated this way -
// see G4VSceneHandler.hh. The simplest possible driver would *not*
// implement these polymorphic functions, with the effect that the
// default versions in G4VSceneHandler are used, which simply call
// G4VSceneHandler::RequestPrimitives to turn the solid into a
// G4Polyhedron usually.
// Don't forget, solids can be transients too (e.g., representing a hit).
void G4XXXStoredSceneHandler::AddSolid(const G4Box& box) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddSolid(const G4Box& box) called for "
<< box.GetName()
<< G4endl;
#endif
//?? Process your box...
std::ostringstream oss;
oss << "G4Box(" <<
G4String
(G4BestUnit
(G4ThreeVector
(box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
"Length")).strip() << ')';
*fCurrentItem += oss.str();
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4Polyline& polyline) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
<< polyline
<< G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
//?? Process polyline.
std::ostringstream oss;
oss << polyline;
*fCurrentItem += oss.str();
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4Text& text) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4Text& text) called.|n"
<< text
<< G4endl;
#endif
// Get text colour - special method since default text colour is
// determined by the default text vis attributes, which may be
// specified independent of default vis attributes of other types of
// visible objects.
//const G4Colour& c = GetTextColour (text); // Picks up default if none.
//?? Process text.
std::ostringstream oss;
oss << text;
*fCurrentItem += oss.str();
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4Circle& circle) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4Circle& circle) called.\n"
<< circle
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (circle, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
//?? Process circle.
std::ostringstream oss;
oss << circle;
*fCurrentItem += oss.str();
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4Square& square) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4Square& square) called.\n"
<< square
<< G4endl;
MarkerSizeType sizeType;
G4double size = GetMarkerSize (square, sizeType);
switch (sizeType) {
default:
case screen:
// Draw in screen coordinates.
G4cout << "screen";
break;
case world:
// Draw in world coordinates.
G4cout << "world";
break;
}
G4cout << " size: " << size << G4endl;
#endif
// Get vis attributes - pick up defaults if none.
//const G4VisAttributes* pVA =
// fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
//?? Process square.
std::ostringstream oss;
oss << square;
*fCurrentItem += oss.str();
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4Polyhedron&) called.\n"
<< polyhedron
<< G4endl;
#endif
//?? Process polyhedron.
std::ostringstream oss;
oss << polyhedron;
*fCurrentItem += oss.str();
//?? Or... here are some ideas for decomposing into polygons...
//Assume all facets are convex quadrilaterals.
//Draw each G4Facet individually
//Get colour, etc..
if (polyhedron.GetNoFacets() == 0) return;
// Get vis attributes - pick up defaults if none.
const G4VisAttributes* pVA =
fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
// Get view parameters that the user can force through the vis
// attributes, thereby over-riding the current view parameter.
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
//G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
//Get colour, etc..
//const G4Colour& c = pVA -> GetColour ();
// Initial action depending on drawing style.
switch (drawing_style) {
case (G4ViewParameters::hsr):
{
break;
}
case (G4ViewParameters::hlr):
{
break;
}
case (G4ViewParameters::wireframe):
{
break;
}
default:
{
break;
}
}
// Loop through all the facets...
// Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
// for an example of how to get facets out of a G4Polyhedron,
// including how to cope with triangles if that's a problem.
}
void G4XXXStoredSceneHandler::AddPrimitive(const G4NURBS&) {
#ifdef G4XXXStoredDEBUG
G4cout <<
"G4XXXStoredSceneHandler::AddPrimitive(const G4NURBS& nurbs) called."
<< G4endl;
#endif
//?? Don't bother implementing this. NURBS are not functional.
}
void G4XXXStoredSceneHandler::ClearStore () {
G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc.
fStore.clear();
fPermanents.clear();
fTransients.clear();
}
void G4XXXStoredSceneHandler::ClearTransientStore () {
G4VSceneHandler::ClearTransientStore ();
typedef std::list<G4String> Store;
typedef std::list<G4String>::iterator StoreIterator;
typedef std::vector<StoreIterator>::iterator StoreIteratorIterator;
for (StoreIteratorIterator i = fTransients.begin();
i != fTransients.end(); ++i) {
fStore.erase(*i);
}
fTransients.clear();
// Make sure screen corresponds to graphical database...
if (fpViewer) {
fpViewer -> SetView ();
fpViewer -> ClearView ();
fpViewer -> DrawView ();
}
}
@@ -0,0 +1,163 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXStoredViewer.cc,v 1.4 2006/06/29 21:27:50 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 7th March 2006
// A template for a graphics driver with a store/database.
//?? Lines beginning like this require specialisation for your driver.
#include "G4XXXStoredViewer.hh"
#include "G4VSceneHandler.hh"
#include "G4XXXStoredSceneHandler.hh"
#include <fstream>
#include <sstream>
G4XXXStoredViewer::G4XXXStoredViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
{}
G4XXXStoredViewer::~G4XXXStoredViewer() {}
void G4XXXStoredViewer::SetView() {
#ifdef G4XXXStoredDEBUG
G4cout << "G4XXXStoredViewer::SetView() called." << G4endl;
#endif
}
void G4XXXStoredViewer::ClearView() {
#ifdef G4XXXStoredDEBUG
G4cout << "G4XXXStoredViewer::ClearView() called." << G4endl;
#endif
}
void G4XXXStoredViewer::DrawView() {
#ifdef G4XXXStoredDEBUG
G4cout << "G4XXXStoredViewer::DrawView() called." << G4endl;
#endif
// First, a view should decide when to re-visit the G4 kernel.
// Sometimes it might not be necessary, e.g., if the scene is stored
// in a graphical database (e.g., OpenGL's display lists) and only
// the viewing angle has changed. But graphics systems without a
// graphical database will always need to visit the G4 kernel.
// The fNeedKernelVisit flag might have been set by the user in
// /vis/viewer/rebuild, but if not, make decision and set flag only
// if necessary...
if (!fNeedKernelVisit) KernelVisitDecision();
G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
ProcessView (); // Clears store and processes scene only if necessary.
if (kernelVisitWasNeeded) {
// Some systems, notably OpenGL, can draw while re-building, so
// there might not be a need to draw from store again here. But
// in this case...
DrawFromStore();
} else {
DrawFromStore();
}
// ...before finally...
FinishView (); // Flush streams and/or swap buffers.
}
void G4XXXStoredViewer::ShowView() {
#ifdef G4XXXStoredDEBUG
G4cout << "G4XXXStoredViewer::ShowView() called." << G4endl;
#endif
}
void G4XXXStoredViewer::KernelVisitDecision () {
// If there's a significant difference with the last view parameters
// of either the scene handler or this viewer, trigger a rebuild.
typedef std::list<G4String> Store;
typedef std::list<G4String>::iterator StoreIterator;
Store& store =
static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
if (store.empty() || CompareForKernelVisit(fLastVP)) {
NeedKernelVisit (); // Sets fNeedKernelVisit.
}
fLastVP = fVP;
}
G4bool G4XXXStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
{
// Typical comparison. Taken from OpenGL.
if (
(lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
(lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
(lastVP.IsCulling () != fVP.IsCulling ()) ||
(lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
(lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
(lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
(lastVP.IsSection () != fVP.IsSection ()) ||
// No need to visit kernel if section plane changes.
(lastVP.IsCutaway () != fVP.IsCutaway ()) ||
(lastVP.GetCutawayPlanes ().size () !=
fVP.GetCutawayPlanes ().size ()) ||
// No need to visit kernel if cutaway planes change.
(lastVP.IsExplode () != fVP.IsExplode ()) ||
(lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
(lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())
) {
return true;
}
if (lastVP.IsDensityCulling () &&
(lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
return true;
if (lastVP.IsExplode () &&
(lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
return true;
return false;
}
void G4XXXStoredViewer::DrawFromStore() {
typedef std::list<G4String> Store;
typedef std::list<G4String>::iterator StoreIterator;
Store& store =
static_cast<G4XXXStoredSceneHandler&>(fSceneHandler).fStore;
// Write to a file for testing...
static G4int iCount = 0;
std::ostringstream oss;
oss << fName << '.' << iCount++ << ".out";
std::ofstream ofs(oss.str().c_str());
for (StoreIterator i = store.begin(); i != store.end(); ++i) {
ofs << *i;
}
ofs.close();
}
+31 -14
View File
@@ -1,32 +1,41 @@
//
// ********************************************************************
// * DISCLAIMER *
// * License and Disclaimer *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4XXXViewer.cc,v 1.7 2005/10/13 17:45:52 allison Exp $
// GEANT4 tag $Name: geant4-08-00 $
// $Id: G4XXXViewer.cc,v 1.9 2006/06/29 21:27:52 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 5th April 2001
// A template for a simplest possible graphics driver.
//?? Lines or sections marked like this require specialisation for your driver.
#include "G4XXXViewer.hh"
#include "G4VSceneHandler.hh"
#include "G4XXXSceneHandler.hh"
G4XXXViewer::G4XXXViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
@@ -64,7 +73,15 @@ void G4XXXViewer::DrawView() {
ProcessView (); // The basic logic is here.
// Then a view may have more to do, e.g., display the graphical
// database. That code should come here before finally...
// database. That code should come here...
// ...before finally...
FinishView (); // Flush streams and/or swap buffers.
}
void G4XXXViewer::ShowView() {
#ifdef G4XXXDEBUG
G4cout << "G4XXXViewer::ShowView() called." << G4endl;
static_cast<G4XXXSceneHandler&>(fSceneHandler).PrintStores();
#endif
}