1657 {
1658
1661
1663 if (!pScene) {
1665 G4warn <<
"ERROR: No current scene. Please create one." <<
G4endl;
1666 }
1667 return;
1668 } else {
1672 << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
1674 }
1675 return;
1676 }
1677 }
1678
1680 if (!pViewer) {
1683 "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1684 "\n Auto direction needs a viewer."
1686 }
1687 return;
1688 }
1689
1690 G4double userHeight, red, green, blue, xmid, ymid, zmid;
1691 G4String userHeightUnit, direction, placement, positionUnit;
1692 std::istringstream is (newValue);
1693 is >> userHeight >> userHeightUnit >> direction
1694 >> red >> green >> blue
1695 >> placement
1696 >> xmid >> ymid >> zmid >> positionUnit;
1697
1699 const G4VisExtent& sceneExtent = pScene->
GetExtent();
1700 if (userHeightUnit == "auto") {
1702 } else {
1704 }
1705
1707 xmid *= unit; ymid *= unit; zmid *= unit;
1708
1709 Direction logoDirection = X;
1710 if (direction == "auto") {
1711
1714 if (vp.
x() > vp.
y() && vp.
x() > vp.
z()) logoDirection = X;
1715 else if (vp.
x() < vp.
y() && vp.
x() < vp.
z()) logoDirection = minusX;
1716 else if (vp.
y() > vp.
x() && vp.
y() > vp.
z()) logoDirection = Y;
1717 else if (vp.
y() < vp.
x() && vp.
y() < vp.
z()) logoDirection = minusY;
1718 else if (vp.
z() > vp.
x() && vp.
z() > vp.
y()) logoDirection = Z;
1719 else if (vp.
z() < vp.
x() && vp.
z() < vp.
y()) logoDirection = minusZ;
1720 }
1721 else if (direction[0] == 'x') logoDirection = X;
1722 else if (direction[0] == 'y') logoDirection = Y;
1723 else if (direction[0] == 'z') logoDirection = Z;
1724 else if (direction[0] == '-') {
1725 if (direction[1] == 'x') logoDirection = minusX;
1726 else if (direction[1] == 'y') logoDirection = minusY;
1727 else if (direction[1] == 'z') logoDirection = minusZ;
1728 } else {
1730 G4warn <<
"ERROR: Unrecogniseed direction: \""
1731 << direction <<
"\"." <<
G4endl;
1732 return;
1733 }
1734 }
1735
1736 G4bool autoPlacing =
false;
if (placement ==
"auto") autoPlacing =
true;
1737
1738
1739
1746
1747
1750 worried = true;
1753 "WARNING: Existing scene does not yet have any extent."
1754 "\n Maybe you have not yet added any geometrical object."
1756 }
1757 }
1758
1759
1760 const G4double halfHeight(height / 2.);
1762 const G4double freeHeightFraction (1. + 2. * comfort);
1763
1764
1766 switch (logoDirection) {
1767 case X:
1768 case minusX:
1769 if (freeHeightFraction * (xmax - xmin) < height) room = false;
1770 break;
1771 case Y:
1772 case minusY:
1773 if (freeHeightFraction * (ymax - ymin) < height) room = false;
1774 break;
1775 case Z:
1776 case minusZ:
1777 if (freeHeightFraction * (zmax - zmin) < height) room = false;
1778 break;
1779 }
1780 if (!room) {
1781 worried = true;
1784 "WARNING: Not enough room in existing scene. Maybe logo is too large."
1786 }
1787 }
1788 if (worried) {
1791 "WARNING: The logo you have asked for is bigger than the existing"
1792 "\n scene. Maybe you have added it too soon. It is recommended that"
1793 "\n you add the logo last so that it can be correctly auto-positioned"
1794 "\n so as not to be obscured by any existing object and so that the"
1795 "\n view parameters can be correctly recalculated."
1797 }
1798 }
1799
1800 G4double sxmid(xmid), symid(ymid), szmid(zmid);
1801 if (autoPlacing) {
1802
1803
1804 const G4double xComfort = comfort * (xmax - xmin);
1805 const G4double yComfort = comfort * (ymax - ymin);
1806 const G4double zComfort = comfort * (zmax - zmin);
1807 switch (logoDirection) {
1808 case X:
1809 sxmid = xmax + halfHeight + xComfort;
1810 symid = ymin - yComfort;
1811 szmid = zmin - zComfort;
1812 break;
1813 case minusX:
1814 sxmid = xmin - halfHeight - xComfort;
1815 symid = ymin - yComfort;
1816 szmid = zmax + zComfort;
1817 break;
1818 case Y:
1819 sxmid = xmin - xComfort;
1820 symid = ymax + halfHeight + yComfort;
1821 szmid = zmin - zComfort;
1822 break;
1823 case minusY:
1824 sxmid = xmax + xComfort;
1825 symid = ymin - halfHeight - yComfort;
1826 szmid = zmin - zComfort;
1827 break;
1828 case Z:
1829 sxmid = xmax + xComfort;
1830 symid = ymin - yComfort;
1831 szmid = zmax + halfHeight + zComfort;
1832 break;
1833 case minusZ:
1834 sxmid = xmin - xComfort;
1835 symid = ymin - yComfort;
1836 szmid = zmin - halfHeight - zComfort;
1837 break;
1838 }
1839 }
1840
1842 switch (logoDirection) {
1843 case X:
1845 break;
1846 case minusX:
1848 break;
1849 case Y:
1851 break;
1852 case minusY:
1854 break;
1855 case Z:
1856
1857 break;
1858 case minusZ:
1860 break;
1861 }
1863
1864 G4VisAttributes visAtts(G4Colour(red, green, blue));
1865 visAtts.SetForceSolid(true);
1866
1867 G4Logo* logo = new G4Logo(height,visAtts,transform);
1868 G4VModel* model =
1869 new G4CallbackModel<G4VisCommandSceneAddLogo::G4Logo>(logo);
1875 G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1876 model->
SetExtent(extent.Transform(transform));
1877
1878
1879 const G4String& currentSceneName = pScene -> GetName ();
1880 G4bool successful = pScene -> AddRunDurationModel (model, warn);
1881 if (successful) {
1883 G4cout <<
"G4 Logo of height " << userHeight <<
' ' << userHeightUnit
1884 << ", " << direction << "-direction, added to scene \""
1885 << currentSceneName << "\"";
1887 G4cout <<
"\n with extent " << extent
1890 }
1892 }
1893 }
1895
1897}
HepGeom::Vector3D< G4double > G4Vector3D
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
void SetType(const G4String &)
void SetGlobalDescription(const G4String &)
void SetGlobalTag(const G4String &)
void SetExtent(const G4VisExtent &)
const G4ViewParameters & GetViewParameters() const
void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
void CheckSceneAndNotifyHandlers(G4Scene *=nullptr)
static G4VisManager * fpVisManager
const G4Vector3D & GetViewpointDirection() const
G4double GetExtentRadius() const