Problem 1995 - Cannot draw twisted solids with negative twist angle
Summary: Cannot draw twisted solids with negative twist angle
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: visualization (show other problems)
Version: 10.3
Hardware: PC Linux
: P4 minor
Assignee: John.Allison
URL:
Depends on:
Blocks:
 
Reported: 2017-08-14 17:48 CEST by suhl
Modified: 2017-08-20 14:01 CEST (History)
0 users

See Also:


Attachments
minimal example (1.20 KB, text/x-c++src)
2017-08-14 17:48 CEST, suhl
Details

Note You need to log in before you can comment on or make changes to this problem.
Description suhl 2017-08-14 17:48:09 CEST
Created attachment 467 [details]
minimal example

Using Geant4 10.3p1 (I did not try other versions) I cannot draw twisted solids with a negative twist angle.

The attachment contains a minimal example trying to draw a G4TwistedBox with a negative twist angle. It can be compiled with the command:

g++ test.cc -o test `geant4-config --cflags --libs`

The example crashes with the message

[...]
Polyhedron::SetReferences: different edge visibility 1/1/56 and 1/0/-1541871320
Polyhedron::SetReferences: different edge visibility 1/3/56 and 1/2/-1541871320
Segmentation fault (core dumped)

If in line 15 the twist angle is made positive, the example runs without an issue.

I also could not draw G4TwistedTubs and G4TwistedTrap with a negative twist angle, in these cases the test just crashes without any message.
Comment 1 John.Allison 2017-08-16 19:22:41 CEST
Thanks for reporting this. I can see the problem. We will look into it.
Comment 2 John.Allison 2017-08-20 14:01:53 CEST
A fix has been found and will be part of the next release. The problem only affected visualisation. Tracking is and was OK (tested with RayTracer). It is a relatively small fix - see below - which you may apply yourself if you have the ability to rebuild Geant4.

Index: src/G4TwistedTubs.cc
===================================================================
--- src/G4TwistedTubs.cc        (.../geom-specific-V10-03-12)   (revision 105798)
+++ src/G4TwistedTubs.cc        (.../geom-specific-V10-03-13)   (revision 105798)
@@ -906,11 +906,12 @@
 {
   // number of meshes
   //
-  G4double dA = std::max(fDPhi,fPhiTwist);
+  G4double absPhiTwist = std::abs(fPhiTwist);
+  G4double dA = std::max(fDPhi,absPhiTwist);
   const G4int k =
     G4int(G4Polyhedron::GetNumberOfRotationSteps() * dA / twopi) + 2;
   const G4int n =
-    G4int(G4Polyhedron::GetNumberOfRotationSteps() * fPhiTwist / twopi) + 2;
+    G4int(G4Polyhedron::GetNumberOfRotationSteps() * absPhiTwist / twopi) + 2;
 
   const G4int nnodes = 4*(k-1)*(n-2) + 2*k*k ;
   const G4int nfaces = 4*(k-1)*(n-1) + 2*(k-1)*(k-1) ;
Index: src/G4VTwistedFaceted.cc
===================================================================
--- src/G4VTwistedFaceted.cc    (.../geom-specific-V10-03-12)   (revision 105798)
+++ src/G4VTwistedFaceted.cc    (.../geom-specific-V10-03-13)   (revision 105798)
@@ -1152,7 +1152,8 @@
 {
   // number of meshes
   const G4int k =
-    G4int(G4Polyhedron::GetNumberOfRotationSteps() * fPhiTwist / twopi) + 2;
+  G4int(G4Polyhedron::GetNumberOfRotationSteps() *
+        std::abs(fPhiTwist) / twopi) + 2;
   const G4int n = k;
 
   const G4int nnodes = 4*(k-1)*(n-2) + 2*k*k ;