Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorViewer.cc
Go to the documentation of this file.
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#ifdef G4VIS_BUILD_OI_DRIVER
28
29// this :
31
32#include <Inventor/nodes/SoSelection.h>
33#include <Inventor/nodes/SoShape.h>
34#include <Inventor/nodes/SoOrthographicCamera.h>
35#include <Inventor/nodes/SoPerspectiveCamera.h>
36#include <Inventor/actions/SoCallbackAction.h>
37#include <Inventor/actions/SoWriteAction.h>
38#include <Inventor/sensors/SoNodeSensor.h>
39
44
45#include "G4OpenInventor.hh"
48#include "G4Scene.hh"
49#include "Geant4_SoPolyhedron.h"
50#include "G4AttValue.hh"
51#include "G4AttDef.hh"
52#include "G4AttCheck.hh"
53#include "G4AttHolder.hh"
54
55G4OpenInventorViewer::G4OpenInventorViewer(
56 G4OpenInventorSceneHandler& sceneHandler
57,const G4String& name)
58:G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
59,fG4OpenInventorSceneHandler(sceneHandler)
60,fInteractorManager(0)
61,fSoSelection(0)
62,fSoImageWriter(0)
63,fGL2PSAction(0) //To be set be suclass.
64,fGroupCameraSensor(0)
65,fCameraSensor(0)
66{
67 fVP.SetAutoRefresh(true);
68 fDefaultVP.SetAutoRefresh(true);
69 fVP.SetPicking(true);
70 fDefaultVP.SetPicking(true);
71
72 //FIXME : G.Barrand : not convinced that we have to rm culling.
73 // For viewing of all objects by default :
74 //fDefaultVP.SetCulling(false);
75 //fVP.SetCulling(false);
76
77 fInteractorManager =
78 ((G4OpenInventor*)fG4OpenInventorSceneHandler.GetGraphicsSystem())->
79 GetInteractorManager();
80
81 // Main user scene graph root sent to the viewers.
82 fSoSelection = new SoSelection;
83 fSoSelection->ref();
84 fSoSelection->addSelectionCallback(SelectionCB,this);
85 //fSoSelection->addDeselectionCallback(DeselectionCB,this);
86 fSoSelection->policy = SoSelection::SINGLE;
87
88 SoGroup* group = new SoGroup;
89 fSoSelection->addChild(group);
90
91 // Have a camera under fSoSelection in order
92 // that the below SceneGraphSensor be notifed
93 // when the viewer changes the camera type.
94 // But we put the camera under a SoGroup so that
95 // the SceneGraphSensor be not triggered at each change
96 // under the fG4OpenInventorSceneHandler.fRoot.
97 SoOrthographicCamera* camera = new SoOrthographicCamera;
98 camera->viewportMapping.setValue(SoCamera::ADJUST_CAMERA);
99 //camera->aspectRatio.setValue(10);
100 camera->position.setValue(0,0,10);
101 camera->orientation.setValue(SbRotation(SbVec3f(0,1,0),0));
102 camera->height.setValue(10);
103 camera->nearDistance.setValue(1);
104 camera->farDistance.setValue(100);
105 camera->focalDistance.setValue(10);
106 group->addChild(camera);
107
108 {SoInput soInput;
109 if(soInput.openFile("g4view.iv",TRUE)) {
110 SoSeparator* separator = SoDB::readAll(&soInput);
111 if(separator) fSoSelection->addChild(separator);
112 }}
113
114 fSoSelection->addChild(fG4OpenInventorSceneHandler.fRoot);
115
116 // SoImageWriter should be the last.
117 fSoImageWriter = new SoImageWriter();
118 fSoImageWriter->fileName.setValue("g4out.ps");
119 fSoSelection->addChild(fSoImageWriter);
120
121 // Sensors :
122 // To detect that the viewer had changed the camera type :
123 fGroupCameraSensor = new SoNodeSensor(GroupCameraSensorCB,this);
124 fGroupCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
125 fGroupCameraSensor->attach(group);
126
127 fCameraSensor = new SoNodeSensor(CameraSensorCB,this);
128 fCameraSensor->setPriority(0);//Needed in order to do getTriggerNode()
129}
130
131G4OpenInventorViewer::~G4OpenInventorViewer () {
132 fCameraSensor->detach();
133 delete fCameraSensor;
134 fGroupCameraSensor->detach();
135 delete fGroupCameraSensor;
136 fSoSelection->unref();
137}
138
139void G4OpenInventorViewer::KernelVisitDecision () {
140
141 // If there's a significant difference with the last view parameters
142 // of either the scene handler or this viewer, trigger a rebuild.
143
144 if (
145 //??fG4OpenInventorSceneHandler.fPODLList.size() == 0 ||
146 // We need a test for empty scene graph, such as
147 // staticRoot.size() or something?????????? See temporary fix
148 // in contructor. (John Allison Aug 2001)
149 CompareForKernelVisit(fLastVP)) {
150 NeedKernelVisit ();
151 }
152}
153
154G4bool G4OpenInventorViewer::CompareForKernelVisit(G4ViewParameters& vp) {
155
156 if (
157 (vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
158 (vp.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
159 (vp.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
160 (vp.IsCulling () != fVP.IsCulling ()) ||
161 (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
162 (vp.IsDensityCulling () != fVP.IsDensityCulling ()) ||
163 (vp.IsCullingCovered () != fVP.IsCullingCovered ()) ||
164 (vp.GetCBDAlgorithmNumber() !=
165 fVP.GetCBDAlgorithmNumber()) ||
166 (vp.IsSection () != fVP.IsSection ()) ||
167 (vp.IsCutaway () != fVP.IsCutaway ()) ||
168 // This assumes use of generic clipping (sectioning, slicing,
169 // DCUT, cutaway). If a decision is made to implement locally,
170 // this will need changing. See G4OpenGLViewer::SetView,
171 // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
172 // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
173 (vp.IsExplode () != fVP.IsExplode ()) ||
174 (vp.GetNoOfSides () != fVP.GetNoOfSides ()) ||
175 (vp.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
176 (vp.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
177 (vp.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
179 fVP.GetDefaultVisAttributes()->GetColour()) ||
181 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
182 (vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
183 (vp.IsPicking () != fVP.IsPicking ()) ||
184 // Scaling for Open Inventor is done by the scene handler so it
185 // needs a kernel visit. (In this respect, it differs from the
186 // OpenGL drivers, where it's done in SetView.)
187 (vp.GetScaleFactor () != fVP.GetScaleFactor ()) ||
188 // If G4OpenInventor ever introduces VAMs, the following might need
189 // changing to a complete comparison, i.e., remove ".size()". See
190 // G4OpenGLStoredViewer::CompareForKernelVisit.
191 (vp.GetVisAttributesModifiers().size() !=
192 fVP.GetVisAttributesModifiers().size())
193 )
194 return true;
195
196 if (vp.IsDensityCulling () &&
197 (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
198 return true;
199
200 if (vp.GetCBDAlgorithmNumber() > 0) {
201 if (vp.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
202 else if (vp.GetCBDParameters() != fVP.GetCBDParameters()) return true;
203 }
204
205 if (vp.IsSection () &&
206 (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
207 return true;
208
209 if (vp.IsCutaway ()) {
210 if (vp.GetCutawayPlanes ().size () !=
211 fVP.GetCutawayPlanes ().size ()) return true;
212 for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
213 if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
214 return true;
215 }
216
217 if (vp.IsExplode () &&
218 (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
219 return true;
220
221 return false;
222}
223
224void G4OpenInventorViewer::ClearView () {
225}
226
227void G4OpenInventorViewer::SetView () {
228
229 // Get G4 camera infos :
230 const G4Point3D target
231 = fSceneHandler.GetScene()->GetStandardTargetPoint()
232 + fVP.GetCurrentTargetPoint ();
233 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
234 if(radius<=0.) radius = 1.;
235 const G4double cameraDistance = fVP.GetCameraDistance (radius);
236 const G4Vector3D& direction = fVP.GetViewpointDirection().unit();
237 const G4Point3D cameraPosition = target + cameraDistance * direction;
238 //const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
239 //const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
240 const G4Normal3D& up = fVP.GetUpVector ();
241
242/*
243 printf("debug : target : %g %g %g\n",target.x(),
244 target.y(),
245 target.z());
246 printf("debug : dir : %g %g %g\n",direction.x(),
247 direction.y(),
248 direction.z());
249 printf("debug : pos : %g %g %g\n",cameraPosition.x(),
250 cameraPosition.y(),
251 cameraPosition.z());
252 //printf("debug : near %g far %g\n",pnear,pfar);
253*/
254
255 SoCamera* camera = GetCamera();
256 if(!camera) return;
257
258 // viewer camera setup :
259 camera->position.setValue((float)cameraPosition.x(),
260 (float)cameraPosition.y(),
261 (float)cameraPosition.z());
262
263 SbVec3f sbTarget((float)target.x(),
264 (float)target.y(),
265 (float)target.z());
266 SbVec3f sbUp((float)up.x(),
267 (float)up.y(),
268 (float)up.z());
269 sbUp.normalize();
270 // Need Coin's camera->pointAt(sbTarget,sbUp); not in the SGI API
271 // Stole Coin's code...
272 pointAt(camera,sbTarget,sbUp);
273
274 //camera->height.setValue(10);
275 //camera->nearDistance.setValue((float)pnear);
276 //camera->farDistance.setValue((float)pfar);
277 //camera->focalDistance.setValue((float)cameraDistance);
278
279 if(camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
280 if (fVP.GetFieldHalfAngle() == 0.) {
281 //FIXME : ((SoOrthographicCamera*)camera)->height.setValue();
282 //FIXME : (Don't think we have to do that.)
283 } else {
284 //FIXME : Have to set a perspective camera !
285 //FIXME : viewer->setCameraType(SoPerspectiveCamera::getClassTypeId())
286 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
287 //FIXME : (2.*fVP.GetFieldHalfAngle());
288 }
289 } else if(camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
290 if (fVP.GetFieldHalfAngle() == 0.) {
291 //FIXME : Have to set an orthographic camera !
292 //FIXME : viewer->setCameraType(SoOrthographicCamera::getClassTypeId())
293 } else {
294 //FIXME : ((SoPerspectiveCamera*)camera)->heightAngle.setValue
295 //FIXME : (2.*fVP.GetFieldHalfAngle());
296 }
297 }
298}
299
300//COIN_FUNCTION_EXTENSION
301void
302G4OpenInventorViewer::pointAt(SoCamera* camera,const SbVec3f & targetpoint, const SbVec3f & upvector)
303{
304 SbVec3f dir = targetpoint - camera->position.getValue();
305 if (dir.normalize() == 0.0f) return;
306 lookAt(camera,dir, upvector);
307}
308
309//COIN_FUNCTION
310// Private method that calculates a new orientation based on camera
311// direction and camera up vector. Vectors must be unit length.
312void
313G4OpenInventorViewer::lookAt(SoCamera* camera,const SbVec3f & dir, const SbVec3f & up)
314{
315 SbVec3f z = -dir;
316 SbVec3f y = up;
317 SbVec3f x = y.cross(z);
318
319 // recompute y to create a valid coordinate system
320 y = z.cross(x);
321
322 // normalize x and y to create an orthonormal coord system
323 y.normalize();
324 x.normalize();
325
326 // create a rotation matrix
327 SbMatrix rot = SbMatrix::identity();
328 rot[0][0] = x[0];
329 rot[0][1] = x[1];
330 rot[0][2] = x[2];
331
332 rot[1][0] = y[0];
333 rot[1][1] = y[1];
334 rot[1][2] = y[2];
335
336 rot[2][0] = z[0];
337 rot[2][1] = z[1];
338 rot[2][2] = z[2];
339
340 camera->orientation.setValue(SbRotation(rot));
341}
342
343void
344G4OpenInventorViewer::lookedAt(SoCamera* camera,SbVec3f & dir, SbVec3f & up)
345{
346 SbRotation rot = camera->orientation.getValue();
347 SbMatrix mrot; rot.getValue(mrot);
348
349 SbVec3f x, y, z;
350
351 // create a rotation matrix
352 x[0] = mrot[0][0];
353 x[1] = mrot[0][1];
354 x[2] = mrot[0][2];
355
356 y[0] = mrot[1][0];
357 y[1] = mrot[1][1];
358 y[2] = mrot[1][2];
359
360 z[0] = mrot[2][0];
361 z[1] = mrot[2][1];
362 z[2] = mrot[2][2];
363
364 dir = -z;
365 dir.normalize();
366 up = SbVec3f(0.f,1.f,0.f); // Choose y-axis if possible.
367 if (std::abs(up.dot(z)) > 1.e-6) {
368 up = y;
369 up.normalize();
370 }
371}
372
373void G4OpenInventorViewer::DrawView () {
374 //G4cout << "debug Iv::DrawViewer " <<G4endl;
375 if (!fNeedKernelVisit) KernelVisitDecision();
376 fLastVP= fVP;
377 ProcessView();
378 FinishView();
379}
380
381void G4OpenInventorViewer::ShowView () {
382 fInteractorManager -> SecondaryLoop ();
383}
384
385void G4OpenInventorViewer::GroupCameraSensorCB(void* aThis,SoSensor* aSensor){
386 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
387
388 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
389 //printf("debug : GroupCameraSensorCB %s\n",
390 //node->getTypeId().getName().getString());
391
392 if(node->isOfType(SoCamera::getClassTypeId())) {
393 // Viewer had changed the camera type,
394 // attach the fCameraSensor to the new camera.
395 SoCamera* camera = (SoCamera*)node;
396 This->fCameraSensor->detach();
397 This->fCameraSensor->attach(camera);
398 }
399
400}
401
402void G4OpenInventorViewer::CameraSensorCB(void* aThis,SoSensor* aSensor) {
403 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
404
405 //printf("debug : CameraSensorCB\n");
406
407 SoNode* node = ((SoNodeSensor*)aSensor)->getTriggerNode();
408
409 if(node->isOfType(SoCamera::getClassTypeId())) {
410 SoCamera* camera = (SoCamera*)node;
411
412 SbVec3f direction, up;
413 lookedAt(camera,direction, up);
414 This->fVP.SetViewpointDirection
415 (G4Vector3D(-direction[0],-direction[1],-direction[2]));
416 This->fVP.SetUpVector(G4Vector3D(up[0],up[1],up[2]));
417
418 SbVec3f pos = camera->position.getValue();
419 SbVec3f target = pos + direction * camera->focalDistance.getValue();
420
421 This->fVP.SetCurrentTargetPoint(G4Point3D(target[0],target[1],target[2]));
422 }
423}
424
425void G4OpenInventorViewer::SelectionCB(
426 void* aThis
427,SoPath* aPath
428)
429{
430 G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
431 SoNode* node = ((SoFullPath*)aPath)->getTail();
432 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
433 if(attHolder && attHolder->GetAttDefs().size()) {
434 for (size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
435 G4cout << G4AttCheck(attHolder->GetAttValues()[i],
436 attHolder->GetAttDefs()[i]);
437 }
438 } else {
439 G4String name((char*)node->getName().getString());
440 G4String cls((char*)node->getTypeId().getName().getString());
441 G4cout << "SoNode : " << node
442 << " SoType : " << cls
443 << " name : " << name
444 << G4endl;
445 G4cout << "No attributes attached." << G4endl;
446 }
447 /*FIXME : to explore (need different button - this is used for picking.
448 if(node->isOfType(Geant4_SoPolyhedron::getClassTypeId())) {
449 Geant4_SoPolyhedron* polyhedron = (Geant4_SoPolyhedron*)node;
450 if(polyhedron->solid.getValue()==FALSE)
451 polyhedron->solid.setValue(TRUE);
452 else
453 polyhedron->solid.setValue(FALSE);
454 }*/
455 This->fSoSelection->deselectAll();
456}
457/*
458void G4OpenInventorViewer::DeselectionCB(
459 void* aThis
460,SoPath* aPath
461)
462{
463 //G4OpenInventorViewer* This = (G4OpenInventorViewer*)aThis;
464 G4String name((char*)aPath->getTail()->getTypeId().getName().getString());
465 G4cout << "Deselect : " << name << G4endl;
466}
467*/
468
469void G4OpenInventorViewer::DrawDetector() {
470 /* Replace this... - JA
471 // DrawView does a ClearStore. Do not clear the transient store :
472 SoSeparator* tmp = fG4OpenInventorSceneHandler.fTransientRoot;
473 fG4OpenInventorSceneHandler.fTransientRoot = new SoSeparator;
474 if (!fNeedKernelVisit) KernelVisitDecision();
475 ProcessView();
476 fG4OpenInventorSceneHandler.fTransientRoot->unref();
477 fG4OpenInventorSceneHandler.fTransientRoot = tmp;
478 */
479 // ...by this... - JA
480 DrawView();
481}
482
483//////////////////////////////////////////////////////////////////////////////
484/// Menu items callbacks /////////////////////////////////////////////////////
485//////////////////////////////////////////////////////////////////////////////
486
487void G4OpenInventorViewer::Escape(){
488 G4cout << "Escape..." <<G4endl;
489 fInteractorManager->RequireExitSecondaryLoop (OIV_EXIT_CODE);
490}
491
492void G4OpenInventorViewer::WritePostScript(const G4String& aFile) {
493 if(!fGL2PSAction) return;
494 fGL2PSAction->setFileName(aFile.c_str());
495 fGL2PSAction->setExportImageFormat(GL2PS_EPS);
496 // Use gl2ps default buffer (2048*2048)
497 fGL2PSAction->setBufferSize(0);
498 G4cout << "Produce " << aFile << "..." << G4endl;
499 if (fGL2PSAction->enableFileWriting()) {
500 ViewerRender();
501 fGL2PSAction->disableFileWriting();
502 }
503 fGL2PSAction->resetBufferSizeParameters();
504}
505
506void G4OpenInventorViewer::WritePDF(const G4String& aFile) {
507 if(!fGL2PSAction) return;
508 fGL2PSAction->setFileName(aFile.c_str());
509 fGL2PSAction->setExportImageFormat(GL2PS_PDF);
510 // Use gl2ps default buffer (2048*2048)
511 fGL2PSAction->setBufferSize(0);
512 G4cout << "Produce " << aFile << "..." << G4endl;
513 if (fGL2PSAction->enableFileWriting()) {
514 ViewerRender();
515 fGL2PSAction->disableFileWriting();
516 }
517 fGL2PSAction->resetBufferSizeParameters();
518}
519
520void G4OpenInventorViewer::WritePixmapPostScript(const G4String& aFile) {
521 fSoImageWriter->fileName.setValue(aFile.c_str());
522 //imageWriter->format.setValue(SoImageWriter::POST_SCRIPT);
523 fSoImageWriter->enable();
524 ViewerRender();
525 fSoImageWriter->disable();
526 if(fSoImageWriter->getStatus()) {
527 G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
528 << " produced."
529 << G4endl;
530 } else {
531 G4cout << G4String(fSoImageWriter->fileName.getValue().getString())
532 << " not produced."
533 << G4endl;
534 }
535}
536
537void G4OpenInventorViewer::WriteInventor(const G4String& aFile) {
538 G4cout << "Produce " << aFile << "..." << G4endl;
539
540 SbBool genAlternateRep = TRUE;
541 //SbBool binary = FALSE;
542 SbBool binary = TRUE;
543 SoAlternateRepAction alternateRepAction;
544 if(genAlternateRep==TRUE) {
545 alternateRepAction.setGenerate(TRUE); //Clear alternate reps.
546 alternateRepAction.apply(fSoSelection);
547 }
548
549 SoWriteAction writeAction;
550 writeAction.getOutput()->openFile(aFile.c_str());
551 writeAction.getOutput()->setBinary(binary);
552 writeAction.apply(fSoSelection);
553 writeAction.getOutput()->closeFile();
554
555 if(genAlternateRep==TRUE) {
556 alternateRepAction.setGenerate(FALSE); //Clear alternate reps.
557 alternateRepAction.apply(fSoSelection);
558 }
559
560
561
562}
563
564struct Counter {
565 int fTriangles;
566 int fLineSegments;
567 int fPoints;
568};
569
570static void CountTrianglesCB(
571 void* userData
572,SoCallbackAction*
573,const SoPrimitiveVertex*
574,const SoPrimitiveVertex*,
575const SoPrimitiveVertex*)
576{
577 Counter* counter = (Counter*)userData;
578 counter->fTriangles++;
579}
580
581static void CountLineSegmentsCB(
582 void* userData
583,SoCallbackAction*
584,const SoPrimitiveVertex*
585,const SoPrimitiveVertex*)
586{
587 Counter* counter = (Counter*)userData;
588 counter->fLineSegments++;
589}
590
591static void CountPointsCB(
592 void* userData
593,SoCallbackAction*
594,const SoPrimitiveVertex*)
595{
596 Counter* counter = (Counter*)userData;
597 counter->fPoints++;
598}
599
600void G4OpenInventorViewer::SceneGraphStatistics() {
601 Counter counter;
602 counter.fTriangles = 0;
603 counter.fLineSegments = 0;
604 counter.fPoints = 0;
605
606 SoCallbackAction callbackAction;
607 callbackAction.addTriangleCallback
608 (SoShape::getClassTypeId(),CountTrianglesCB,(void*)&counter);
609 callbackAction.addLineSegmentCallback
610 (SoShape::getClassTypeId(),CountLineSegmentsCB,(void*)&counter);
611 callbackAction.addPointCallback
612 (SoShape::getClassTypeId(),CountPointsCB,(void*)&counter);
613 callbackAction.apply(fSoSelection);
614
615 SoCounterAction counterAction;
616 counterAction.apply(fSoSelection);
617 int nodes = counterAction.getCount();
618
619 counterAction.setLookFor(SoCounterAction::TYPE);
620 counterAction.setType(SoShape::getClassTypeId());
621 counterAction.apply(fSoSelection);
622 int shapes = counterAction.getCount();
623
624 G4cout << "Number of triangles : " << counter.fTriangles << G4endl;
625 G4cout << "Number of line segments : " << counter.fLineSegments << G4endl;
626 G4cout << "Number of points : " << counter.fPoints << G4endl;
627 G4cout << "Number of nodes : " << nodes << G4endl;
628 G4cout << "Number of shapes : " << shapes << G4endl;
629}
630
631void G4OpenInventorViewer::EraseDetector() {
632 fG4OpenInventorSceneHandler.fDetectorRoot->removeAllChildren();
633}
634void G4OpenInventorViewer::EraseEvent() {
635 fG4OpenInventorSceneHandler.fTransientRoot->removeAllChildren();
636}
637
638void G4OpenInventorViewer::SetPreviewAndFull() {
639 fG4OpenInventorSceneHandler.fPreviewAndFull = true;
640
641 NeedKernelVisit();
642 DrawDetector();
643}
644
645void G4OpenInventorViewer::SetPreview() {
646 fG4OpenInventorSceneHandler.fPreviewAndFull = false;
647
648 NeedKernelVisit();
649 DrawDetector();
650}
651
652// When ViewParameter <-> SoCamera mapping ready
653// uncomment the below
654//#define USE_SET_VIEW
655
656void G4OpenInventorViewer::SetSolid() {
657 G4ViewParameters vp = GetViewParameters();
659 //From G4VisCommandsViewerSet : /vis/viewer/set/style solid.
660 switch (existingStyle) {
663 break;
666 break;
668 break;
670 break;
673 break;
674 }
675 SetViewParameters(vp);
676 DrawDetector();
677}
678void G4OpenInventorViewer::SetWireFrame() {
679 G4ViewParameters vp = GetViewParameters();
681 switch (existingStyle) {
683 break;
685 break;
688 break;
691 break;
694 break;
695 }
696 SetViewParameters(vp);
697 DrawDetector();
698}
699
700
701void G4OpenInventorViewer::SetReducedWireFrame(bool aValue) {
702 G4ViewParameters vp = GetViewParameters();
703
704 // Set the wire frame kind :
705 vp.SetAuxEdgeVisible(!aValue);
706
707 // Set wire frame :
709 switch (existingStyle) {
711 break;
713 break;
716 break;
719 break;
722 break;
723 }
724 SetViewParameters(vp);
725 NeedKernelVisit(); // Just in case it was alread in wire framw.
726 DrawDetector();
727}
728
729void G4OpenInventorViewer::UpdateScene() {
730 /* Replace this... - JA
731 fG4OpenInventorSceneHandler.ClearStore();
732 ClearView();
733 if (!fNeedKernelVisit) KernelVisitDecision();
734 ProcessView();
735 ShowView();
736 */
737 // ...by this - JA
738 NeedKernelVisit();
739 DrawView();
740}
741G4String G4OpenInventorViewer::Help(const G4String& aTopic) {
742 if(aTopic=="controls") {
743 return G4String("\
744Controls on an Inventor examiner viewer are :\n\
745- in picking mode (cursor is the upper left arrow)\n\
746 Ctrl + pick a volume : see daughters.\n\
747 Shift + pick a volume : see mother.\n\
748- in viewing mode (cursor is the hand)\n\
749 Left-button + pointer move : rotate.\n\
750 Ctrl+Left-button + pointer move : pan.\n\
751 Ctrl+Shift+Left-button + pointer move : scale.\n\
752 Middle-button + pointer move : pan.\n\
753 Right-button : popup menu.\n");
754 } else {
755 return "";
756 }
757}
758
759#endif
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
#define OIV_EXIT_CODE
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:34
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
#define SoImageWriter
Definition: SoImageWriter.h:40
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
Definition: G4AttHolder.hh:59
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
Definition: G4AttHolder.hh:61
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:162
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
G4bool IsCutaway() const
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
const G4Colour & GetBackgroundColour() const
G4bool IsSection() const
G4bool IsPicking() const
G4bool IsCulling() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsExplode() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
const G4Planes & GetCutawayPlanes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
void SetAuxEdgeVisible(G4bool)
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
BasicVector3D< T > unit() const
void setGenerate(SbBool)
int getCount() const
void setLookFor(LookFor)
void setType(const SoType, SbBool=TRUE)
#define GL2PS_EPS
Definition: gl2ps.h:128
#define GL2PS_PDF
Definition: gl2ps.h:130
const char * name(G4int ptype)
#define userData
Definition: xmlparse.cc:572