I'm trying to add a colour to the LogicalVolume which has been renamed to TrackerLogical in Geant4. I get the error that fVisAttributes and visAttributes are undefined although I have defined them in the #include section as .hh files.
The primary framework I have used is that of exampleB1 and I am trying to add color using exampleB5 's approach by applying G4VisAttributes. I have referred to this as a guide: https://github.com/Geant4/geant4/blob/master/examples/basic/B5/src/B5DetectorConstruction.cc
I have included the necessary bits in the #include section as shown in example B5, and have included a line for fVisAttributes in the section B1DetectorConstruction::B1DetectorConstruction() but I get the error messages when I run -jN after adding the following section of code before the last line ( return physWorld) :
visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));
visAttributes->SetVisibility(false);
trackerLogical->SetVisAttributes(visAttributes);
fVisAttributes.push_back(visAttributes);
This is the error message I get:
home/neha/G4WORk/B1/src/B1DetectorConstruction.cc: In constructor ‘B1DetectorConstruction::B1DetectorConstruction()’:
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:53:3: error: class ‘B1DetectorConstruction’ does not have any field named ‘fVisAttributes’
53 | fVisAttributes()
| ^~~~~~~~~~~~~~
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc: In member function ‘virtual G4VPhysicalVolume* B1DetectorConstruction::Construct()’:
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:202:2: error: ‘visAttributes’ was not declared in this scope; did you mean ‘G4VisAttributes’?
202 | visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));
| ^~~~~~~~~~~~~
| G4VisAttributes
/home/neha/G4WORk/B1/src/B1DetectorConstruction.cc:205:2: error: ‘fVisAttributes’ was not declared in this scope; did you mean ‘G4VisAttributes’?
205 | fVisAttributes.push_back(visAttributes);
| ^~~~~~~~~~~~~~
| G4VisAttributes
make[2]: *** [CMakeFiles/exampleB1.dir/build.make:89: CMakeFiles/exampleB1.dir/src/B1DetectorConstruction.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/exampleB1.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
What is causing the issue and how can I resolve this? I am still a beginner with Geant4 and may need some fundamental explanations (in simple/layman's terms preferably). Thank you!
visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));toG4VisAttributes * visAttributes = new G4VisAttributes(G4Colour(0.9,0.9,0.9));, then the error on line 202 will go away. SimilarlyfVisAttributesis not a declared variable either. Line 53 is trickier, it may be that you forgot to put a semicolon or tried to use a variable as a function – Abdullah Ali Sivas Sep 05 '20 at 02:33MyClass(string inString) : myNum(5) { myString = inString;}. In your caseB1DetectorConstructiondoes not have any attribute namedfVisAttributes– Abdullah Ali Sivas Sep 07 '20 at 03:03