source: trunk/source/geometry/solids/test/fred/src/FredVoxelTest.cc@ 1350

Last change on this file since 1350 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 7.8 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// FredVoxelTest.cc
28//
29// Implementation of voxel solid tests
30//
31#include "FredVoxelTest.hh"
32#include "G4VSolid.hh"
33
34#include "G4VVisManager.hh"
35#include "G4Circle.hh"
36#include "G4Color.hh"
37#include "G4Polyline.hh"
38#include "G4VisAttributes.hh"
39
40//
41// Creator
42//
43FredVoxelTest::FredVoxelTest( )
44{
45 inverseTransform = transform.Inverse();
46
47 test.solid = 0;
48}
49
50//
51// Destructor
52//
53FredVoxelTest::~FredVoxelTest()
54{;}
55
56
57//
58// SetExtent
59//
60void FredVoxelTest::SetExtent( const EAxis axis, const G4double min, const G4double max )
61{
62 voxelLimits.AddLimit( axis, min, max );
63}
64
65
66//
67// SetOrigin
68//
69void FredVoxelTest::SetOrigin( const G4ThreeVector origin )
70{
71 transform.SetNetTranslation( origin );
72 inverseTransform = transform.Inverse();
73}
74
75
76//
77// Rotate
78//
79void FredVoxelTest::Rotate( const EAxis axis, const G4double value )
80{
81 switch(axis) {
82 case kXAxis: rotation = rotation.rotateX(value); break;
83 case kYAxis: rotation = rotation.rotateY(value); break;
84 case kZAxis: rotation = rotation.rotateZ(value); break;
85 default: break;
86 }
87 transform.SetNetRotation( rotation );
88 inverseTransform = transform.Inverse();
89}
90
91
92//
93// Reset rotation
94//
95void FredVoxelTest::ResetRotation()
96{
97 rotation = G4RotationMatrix();
98 transform.SetNetRotation( rotation );
99 inverseTransform = transform.Inverse();
100}
101
102
103//
104// Test
105//
106void FredVoxelTest::Test( const EAxis axis, const G4VSolid *solid )
107{
108 test.solid = solid;
109 test.axis = axis;
110
111 test.result = solid->CalculateExtent( axis, voxelLimits, transform, test.min, test.max );
112 if (test.result) {
113 G4cout << "Voxel intersects the solid" << G4endl;
114 }
115 else {
116 G4cout << "Voxel does not intersect the solid" << G4endl;
117 }
118}
119
120
121//
122// Draw
123//
124void FredVoxelTest::Draw( )
125{
126 static EAxis axes[3] = { kXAxis, kYAxis, kZAxis };
127 static G4ThreeVector cartAxes[3] = { G4ThreeVector(1,0,0),
128 G4ThreeVector(0,1,0),
129 G4ThreeVector(0,0,1) };
130
131 G4VVisManager *visManager = G4VVisManager::GetConcreteInstance();
132 if (!visManager) return;
133
134 G4ThreeVector origin(0,0,0);
135
136 inverseTransform.ApplyPointTransform( origin );
137 PlotMarker( origin, visManager );
138
139 G4int i;
140 for( i=0; i<3; i++ ) {
141 if (!voxelLimits.IsLimited(axes[i])) continue;
142
143 G4ThreeVector max(0,0,0);
144 max = max + cartAxes[i]*voxelLimits.GetMaxExtent(axes[i]);
145
146 inverseTransform.ApplyPointTransform( max );
147 PlotMarker( max, visManager );
148 PlotLine( origin, max, visManager );
149
150 G4ThreeVector min(0,0,0);
151 min = min + cartAxes[i]*voxelLimits.GetMinExtent(axes[i]);
152
153 inverseTransform.ApplyPointTransform( min );
154 PlotMarker( min, visManager );
155 PlotLine( origin, min, visManager );
156 }
157
158 if (test.solid && test.result) {
159 G4ThreeVector max, min, a, b, c, d;
160
161 if (test.max < voxelLimits.GetMaxExtent(test.axis)) {
162 max = cartAxes[test.axis]*test.max;
163 a = inverseTransform.TransformPoint( max );
164 PlotMarker( a, visManager, true );
165 PlotLine( origin, a, visManager, true );
166 }
167
168 if (test.min > voxelLimits.GetMinExtent(test.axis)) {
169 min = cartAxes[test.axis]*test.min;
170 a = inverseTransform.TransformPoint( min );
171 PlotMarker( a, visManager, true );
172 PlotLine( origin, a, visManager, true );
173 }
174
175 for( i=0; i<3; i++ ) {
176 if (axes[i]==test.axis) continue;
177
178 if (voxelLimits.IsLimited(axes[i])) {
179 G4ThreeVector aMax, bMax;
180
181 G4int j = (i + 1)%3;
182 if (axes[j]==test.axis) j = (j + 1)%3;
183
184 if (voxelLimits.IsLimited(axes[j])) {
185 c = voxelLimits.GetMaxExtent(axes[j])*cartAxes[j];
186 d = voxelLimits.GetMinExtent(axes[j])*cartAxes[j];
187 }
188 else {
189 c = +4*m*cartAxes[j];
190 d = -4*m*cartAxes[j];
191 }
192
193 if (test.max < voxelLimits.GetMaxExtent(test.axis)) {
194 aMax = max + voxelLimits.GetMaxExtent(axes[i])*cartAxes[i];
195 bMax = max + voxelLimits.GetMinExtent(axes[i])*cartAxes[i];
196
197 a = inverseTransform.TransformPoint( aMax );
198 b = inverseTransform.TransformPoint( bMax );
199 PlotLine( a, b, visManager, true );
200
201 a = inverseTransform.TransformPoint( aMax + c );
202 b = inverseTransform.TransformPoint( aMax + d );
203 PlotLine( a, b, visManager, true );
204 a = inverseTransform.TransformPoint( bMax + c );
205 b = inverseTransform.TransformPoint( bMax + d );
206 PlotLine( a, b, visManager, true );
207 }
208
209 if (test.min > voxelLimits.GetMinExtent(test.axis)) {
210 aMax = min + voxelLimits.GetMaxExtent(axes[i])*cartAxes[i];
211 bMax = min + voxelLimits.GetMinExtent(axes[i])*cartAxes[i];
212
213 a = inverseTransform.TransformPoint( aMax );
214 b = inverseTransform.TransformPoint( bMax );
215 PlotLine( a, b, visManager, true );
216
217 a = inverseTransform.TransformPoint( aMax + c );
218 b = inverseTransform.TransformPoint( aMax + d );
219 PlotLine( a, b, visManager, true );
220 a = inverseTransform.TransformPoint( bMax + c );
221 b = inverseTransform.TransformPoint( bMax + d );
222 PlotLine( a, b, visManager, true );
223 }
224 }
225 else {
226 G4ThreeVector aMax = max + 4*cartAxes[i],
227 bMax = max - 4*cartAxes[i];
228
229 if (test.max < voxelLimits.GetMaxExtent(test.axis)) {
230 a = inverseTransform.TransformPoint( max + 4*m*cartAxes[i] );
231 b = inverseTransform.TransformPoint( max - 4*m*cartAxes[i] );
232 PlotLine( a, b, visManager, true );
233 }
234
235 if (test.min > voxelLimits.GetMinExtent(test.axis)) {
236 a = inverseTransform.TransformPoint( min + 4*m*cartAxes[i] );
237 b = inverseTransform.TransformPoint( min - 4*m*cartAxes[i] );
238 PlotLine( a, b, visManager, true );
239 }
240 }
241 }
242 }
243}
244
245
246//
247// PlotMarker
248//
249void FredVoxelTest::PlotMarker( G4ThreeVector point,
250 G4VVisManager *visManager, G4bool isAtest )
251{
252 G4Circle circle( point );
253 circle.SetWorldSize( 5*cm );
254 G4Color color( isAtest ? 1.0 : 0.25, isAtest ? 1.0 : 0.25, 1.0 );
255 G4VisAttributes attribs( color );
256 circle.SetVisAttributes( attribs );
257
258 circle.SetFillStyle( G4Circle::filled );
259 visManager->Draw( circle );
260}
261
262
263//
264// PlotLine
265//
266void FredVoxelTest::PlotLine( G4ThreeVector start, G4ThreeVector end,
267 G4VVisManager *visManager, G4bool isAtest )
268{
269 G4Polyline line;
270
271 line.push_back( start );
272 line.push_back( end );
273
274 G4Color color( isAtest ? 1.0 : 0.25, isAtest ? 1.0 : 0.25, 1.0 );
275 G4VisAttributes attribs( color );
276 line.SetVisAttributes( attribs );
277
278 visManager->Draw( line );
279}
280
281
282
283
284
Note: See TracBrowser for help on using the repository browser.