source: trunk/source/geometry/solids/test/SBT/src/SBTvoxelMessenger.cc@ 1330

Last change on this file since 1330 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: 12.3 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// SBTvoxelMessenger.cc
28//
29// Implementation of the messenger for the voxel test
30//
31
32#include "SBTvoxelMessenger.hh"
33#include "SBTvoxel.hh"
34#include "SBTVisManager.hh"
35#include "G4SolidQuery.hh"
36
37#include "G4VoxelLimits.hh"
38#include "G4AffineTransform.hh"
39
40#include "G4ios.hh"
41#include "G4UIdirectory.hh"
42#include "G4UIcommand.hh"
43#include "G4UIcmdWith3VectorAndUnit.hh"
44#include "G4UIcmdWithAnInteger.hh"
45#include "G4UIcmdWithAString.hh"
46#include "G4UIcmdWithoutParameter.hh"
47#include "G4UIcmdWith3Vector.hh"
48
49#include "G4UIcmdWithPargs.hh"
50#include "G4UIcmdPargDouble.hh"
51#include "G4UIcmdPargInteger.hh"
52
53#include <fstream>
54
55//
56// Constructor
57//
58SBTvoxelMessenger::SBTvoxelMessenger( const G4String prefix,
59 const G4SolidQuery *theSolidQuery, SBTVisManager *theVisManager )
60 : tester(), errorFile("sbtvoxel.log")
61{
62 //
63 // Initialize
64 //
65 visManager = theVisManager;
66 translate = new G4ThreeVector;
67 rotate = new G4RotationMatrix;
68 voxel = 0;
69 point = 0;
70 limits[0] = +1000.0;
71 limits[1] = -1000.0;
72 axis = kXAxis;
73
74 //
75 // Store solid query
76 //
77 solidQuery = theSolidQuery;
78
79 //
80 // Declare directory
81 //
82 voxelDirectory = new G4UIdirectory( prefix );
83 voxelDirectory->SetGuidance( "Controls for CSG batch voxel tester" );
84
85 //
86 // Target command
87 //
88 G4String com = prefix+"target";
89 targetCmd = new G4UIcmdWith3VectorAndUnit( com, this );
90 targetCmd->SetGuidance( "Center of distribution of random points" );
91 targetCmd->SetParameterName( "X", "Y", "Z", true, true );
92
93 //
94 // Widths command
95 //
96 com = prefix+"widths";
97 widthsCmd = new G4UIcmdWith3VectorAndUnit( com, this );
98 widthsCmd->SetGuidance( "Widths of distribution of random points" );
99 widthsCmd->SetParameterName( "Dx", "Dy", "Dz", true, true );
100
101 //
102 // Max Voxels command
103 //
104 com = prefix+"maxVoxels";
105 maxVoxelsCmd = new G4UIcmdWithAnInteger( com, this );
106 maxVoxelsCmd->SetGuidance( "Maximum number of Voxels before test ends" );
107
108 //
109 // Max Errors command
110 //
111 com = prefix+"maxErrors";
112 maxErrorsCmd = new G4UIcmdWithAnInteger( com, this );
113 maxErrorsCmd->SetGuidance( "Maximum number of errors before test ends" );
114
115 //
116 // Error filename command
117 //
118 com = prefix+"errorFileName";
119 errorFileCmd = new G4UIcmdWithAString( com, this );
120 errorFileCmd->SetGuidance( "Filename in which to send error listings" );
121
122 //
123 // Run command
124 //
125 com = prefix+"run";
126 runCmd = new G4UIcmdWithoutParameter( com, this );
127 runCmd->SetGuidance( "Execute voxel test" );
128
129 //
130 // Picture directory
131 //
132 com = prefix+"picture/";
133 pictDirectory = new G4UIdirectory( com );
134 pictDirectory->SetGuidance( "Controls for drawing CSG voxel tests" );
135
136 //
137 // picture/voxel command
138 //
139 pictVoxelArgs[0] = new G4UIcmdPargDouble( "xmin", 1.0, mm );
140 pictVoxelArgs[1] = new G4UIcmdPargDouble( "xmax", 1.0, mm );
141 pictVoxelArgs[2] = new G4UIcmdPargDouble( "ymin", 1.0, mm );
142 pictVoxelArgs[3] = new G4UIcmdPargDouble( "ymax", 1.0, mm );
143 pictVoxelArgs[4] = new G4UIcmdPargDouble( "zmin", 1.0, mm );
144 pictVoxelArgs[5] = new G4UIcmdPargDouble( "zmax", 1.0, mm );
145 com = prefix+"picture/voxel";
146 pictVoxelCmd = new G4UIcmdWithPargs( com, this, pictVoxelArgs, 6 );
147 pictVoxelCmd->SetGuidance( "Specifies the voxel to draw" );
148
149 //
150 // picture/translate command
151 //
152 com = prefix+"picture/translate";
153 pictTranCmd = new G4UIcmdWith3Vector( com, this );
154 pictTranCmd->SetGuidance( "Specifies the voxel translation" );
155
156 //
157 // picture/rotate command
158 //
159 pictRotArgs[0] = new G4UIcmdPargDouble( "xaxis", 1.0, 1 );
160 pictRotArgs[1] = new G4UIcmdPargDouble( "yaxis", 1.0, 1 );
161 pictRotArgs[2] = new G4UIcmdPargDouble( "zaxis", 1.0, 1 );
162 pictRotArgs[3] = new G4UIcmdPargDouble( "amount", 1.0, 1 );
163 com = prefix+"picture/rotate";
164 pictRotCmd = new G4UIcmdWithPargs( com, this, pictRotArgs, 4 );
165 pictRotCmd->SetGuidance( "Specifies rotation matrix" );
166
167 //
168 // picture/point command
169 //
170 com = prefix+"picture/point";
171 pictPointCmd = new G4UIcmdWith3Vector( com, this );
172 pictPointCmd->SetGuidance( "Specifies one point to include in the picture" );
173
174 //
175 // picture/limit command
176 //
177 pictLimitArgs[0] = new G4UIcmdPargInteger( "axis", 1 );
178 pictLimitArgs[1] = new G4UIcmdPargDouble( "min", 1.0, mm );
179 pictLimitArgs[2] = new G4UIcmdPargDouble( "max", 1.0, mm );
180 com = prefix+"picture/limit";
181 pictLimitCmd = new G4UIcmdWithPargs( com, this, pictLimitArgs, 3 );
182 pictLimitCmd->SetGuidance( "Specifies voxel limits" );
183
184 //
185 // picture/draw command
186 //
187 com = prefix+"picture/draw";
188 pictDrawCmd = new G4UIcmdWithoutParameter( com, this );
189 pictDrawCmd->SetGuidance( "Draw the picture" );
190
191 //
192 // picture/debug command
193 //
194 com = prefix+"picture/debug";
195 pictDebugCmd = new G4UIcmdWithoutParameter( com, this );
196 pictDebugCmd->SetGuidance( "Call CalculateExtent for the picture" );
197}
198
199
200
201//
202// Destructor
203//
204SBTvoxelMessenger::~SBTvoxelMessenger()
205{
206 if (voxel) delete voxel;
207 if (point) delete point;
208
209// delete targetCmd;
210// delete widthsCmd;
211// delete maxVoxelsCmd;
212// delete maxVoxelsCmd;
213// delete errorFileCmd;
214 delete voxelDirectory;
215
216 delete pictDirectory;
217}
218
219
220//
221// InvokeTest
222//
223// Run the test
224//
225void SBTvoxelMessenger::InvokeTest()
226{
227 //
228 // Is there a Solid to test?
229 //
230 G4VSolid *testSolid = solidQuery->GetSolid();
231 if (testSolid == 0) {
232 G4cerr << "Please initialize geometry before running test" << G4endl;
233 G4cerr << "Test ABORTED" << G4endl;
234 return;
235 }
236
237 //
238 // Open output file
239 //
240 std::ofstream logFile( errorFile );
241
242 //
243 // Run the test
244 //
245 tester.RunTest( testSolid, logFile );
246}
247
248
249void SBTvoxelMessenger::Draw()
250{
251 if (!visManager)
252 G4cerr << "Visualization is not available in this executable" << G4endl;
253
254 //
255 // Is there a Solid to test?
256 //
257 G4VSolid *testSolid = solidQuery->GetSolid();
258 if (testSolid == 0) {
259 G4cerr << "Please initialize geometry before running test" << G4endl;
260 return;
261 }
262
263 //
264 // Is there a voxel to test?
265 //
266 if (voxel == 0) {
267 G4cerr << "Please specify a voxel to draw using /pict/voxel command" << G4endl;
268 return;
269 }
270
271 //
272 // Go do it
273 //
274 visManager->BuildFakeWorld();
275
276 G4AffineTransform transform( *rotate, *translate );
277
278 tester.Draw( testSolid, *voxel, transform, point, point ? 1 : 0, axis, limits, visManager );
279}
280
281
282void SBTvoxelMessenger::Debug()
283{
284 //
285 // Is there a Solid to test?
286 //
287 G4VSolid *testSolid = solidQuery->GetSolid();
288 if (testSolid == 0) {
289 G4cerr << "Please initialize geometry before running test" << G4endl;
290 return;
291 }
292
293 //
294 // Is there a voxel to test?
295 //
296 if (voxel == 0) {
297 G4cerr << "Please specify a voxel to debug using /pict/voxel command" << G4endl;
298 return;
299 }
300
301 //
302 // Go do it
303 //
304 G4AffineTransform transform( *rotate, *translate );
305
306 tester.Debug( testSolid, axis, *voxel, transform, point );
307}
308
309
310//
311// SetNewValue
312//
313// Call by the UI when user requests a change
314//
315void SBTvoxelMessenger::SetNewValue( G4UIcommand *command, G4String newValues )
316{
317 if (command == targetCmd) {
318 tester.SetTarget( targetCmd->GetNew3VectorValue( newValues ) );
319 }
320 else if (command == widthsCmd) {
321 tester.SetWidths( widthsCmd->GetNew3VectorValue( newValues ) );
322 }
323 else if (command == maxVoxelsCmd) {
324 tester.SetMaxVoxels( maxVoxelsCmd->GetNewIntValue( newValues ) );
325 }
326 else if (command == maxErrorsCmd) {
327 tester.SetMaxErrors( maxErrorsCmd->GetNewIntValue( newValues ) );
328 }
329 else if (command == errorFileCmd) {
330 errorFile = newValues;
331 }
332 else if (command == runCmd) {
333 InvokeTest();
334 }
335 else if (command == pictVoxelCmd) {
336 if (pictVoxelCmd->GetArguments( newValues )) {
337 G4UIcmdPargDouble *minX = (G4UIcmdPargDouble *)pictVoxelArgs[0],
338 *maxX = (G4UIcmdPargDouble *)pictVoxelArgs[1],
339 *minY = (G4UIcmdPargDouble *)pictVoxelArgs[2],
340 *maxY = (G4UIcmdPargDouble *)pictVoxelArgs[3],
341 *minZ = (G4UIcmdPargDouble *)pictVoxelArgs[4],
342 *maxZ = (G4UIcmdPargDouble *)pictVoxelArgs[5];
343
344 if (voxel) delete voxel;
345
346 voxel = new G4VoxelLimits;
347
348 if (minX->GetValue() < maxX->GetValue())
349 voxel->AddLimit( kXAxis, minX->GetValue(), maxX->GetValue() );
350 if (minY->GetValue() < maxY->GetValue())
351 voxel->AddLimit( kYAxis, minY->GetValue(), maxY->GetValue() );
352 if (minZ->GetValue() < maxZ->GetValue())
353 voxel->AddLimit( kZAxis, minZ->GetValue(), maxZ->GetValue() );
354 }
355 else
356 G4cerr << "Syntax error" << G4endl;
357 }
358 else if (command == pictTranCmd) {
359 *translate = pictTranCmd->GetNew3VectorValue( newValues );
360 }
361 else if (command == pictRotCmd) {
362 if (pictRotCmd->GetArguments( newValues )) {
363 G4UIcmdPargDouble *rotX = (G4UIcmdPargDouble *)pictRotArgs[0],
364 *rotY = (G4UIcmdPargDouble *)pictRotArgs[1],
365 *rotZ = (G4UIcmdPargDouble *)pictRotArgs[2],
366 *amount = (G4UIcmdPargDouble *)pictRotArgs[3];
367
368 G4ThreeVector rotAxis( rotX->GetValue(), rotY->GetValue(), rotZ->GetValue() );
369
370 delete rotate;
371 rotate = new G4RotationMatrix();
372 rotate->rotate( amount->GetValue(), &rotAxis );
373 }
374 else
375 G4cerr << "Syntax error" << G4endl;
376 }
377 else if (command == pictPointCmd) {
378 if (point) delete point;
379 point = new G4ThreeVector();
380 *point = pictPointCmd->GetNew3VectorValue( newValues );
381 }
382 else if (command == pictLimitCmd) {
383 if (pictLimitCmd->GetArguments( newValues )) {
384 static const EAxis axes[3] = { kXAxis, kYAxis, kZAxis };
385
386 G4UIcmdPargInteger *axisArg = (G4UIcmdPargInteger *)pictLimitArgs[0];
387 G4UIcmdPargDouble *min = (G4UIcmdPargDouble *)pictLimitArgs[1],
388 *max = (G4UIcmdPargDouble *)pictLimitArgs[2];
389
390 G4int axisIndex = axisArg->GetValue();
391 if (axisIndex < 0 || axisIndex > 2) {
392 G4cerr << "Axis value must be from 0 to 2" << G4endl;
393 }
394 else {
395 axis = axes[axisIndex];
396 limits[0] = min->GetValue();
397 limits[1] = max->GetValue();
398 }
399 }
400 else
401 G4cerr << "Syntax error" << G4endl;
402 }
403 else if (command == pictDrawCmd) {
404 Draw();
405 }
406 else if (command == pictDebugCmd) {
407 Debug();
408 }
409 else {
410 G4Exception( "Unrecognized command" );
411 }
412}
413
414
415
416//
417// GetCurrentValue
418//
419G4String SBTvoxelMessenger::GetCurrentValue( G4UIcommand *command )
420{
421 if (command == targetCmd) {
422 return targetCmd->ConvertToString( tester.GetTarget(), "m" );
423 }
424 else if (command == widthsCmd) {
425 return widthsCmd->ConvertToString( tester.GetWidths(), "m" );
426 }
427 else if (command == maxVoxelsCmd) {
428 return maxVoxelsCmd->ConvertToString( tester.GetMaxVoxels() );
429 }
430 else if (command == maxErrorsCmd) {
431 return maxErrorsCmd->ConvertToString( tester.GetMaxErrors() );
432 }
433 else if (command == errorFileCmd) {
434 return errorFile;
435 }
436 else if (command == runCmd) {
437 return "";
438 }
439 else if (command == pictVoxelCmd) {
440 return "";
441 }
442 else if (command == pictTranCmd) {
443 return "";
444 }
445 else if (command == pictRotCmd) {
446 return "";
447 }
448 else if (command == pictPointCmd) {
449 return "";
450 }
451 else if (command == pictLimitCmd) {
452 return "";
453 }
454 else if (command == pictDebugCmd) {
455 return "";
456 }
457 else if (command == pictDrawCmd) {
458 return "";
459 }
460
461 G4Exception( "Unrecognized command" );
462 return "foo!";
463}
Note: See TracBrowser for help on using the repository browser.