FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
antenna Namespace Reference

Classes

class  Antenna
 Abstract base class representing an antenna. More...
 
class  Gaussian
 Represents a Gaussian-shaped antenna gain pattern. More...
 
class  H5Antenna
 Represents an antenna whose gain pattern is loaded from a HDF5 file. More...
 
class  Isotropic
 Represents an isotropic antenna with uniform gain in all directions. More...
 
class  Parabolic
 Represents a parabolic reflector antenna. More...
 
class  Sinc
 Represents a sinc function-based antenna gain pattern. More...
 
class  SquareHorn
 Represents a square horn antenna. More...
 
class  XmlAntenna
 Represents an antenna whose gain pattern is defined by an XML file. More...
 

Functions

void to_json (nlohmann::json &j, const Antenna &a)
 
void from_json (const nlohmann::json &j, std::unique_ptr< Antenna > &ant)
 

Function Documentation

◆ from_json()

void antenna::from_json ( const nlohmann::json &  j,
std::unique_ptr< Antenna > &  ant 
)

Definition at line 866 of file json_serializer.cpp.

867 {
868 const auto name = j.at("name").get<std::string>();
869 const auto id = parse_json_id(j, "id", "Antenna");
870 const auto pattern = j.value("pattern", "isotropic");
871
872 if (pattern == "isotropic")
873 {
874 ant = std::make_unique<Isotropic>(name, id);
875 }
876 else if (pattern == "sinc")
877 {
878 ant = std::make_unique<Sinc>(name, j.at("alpha").get<RealType>(), j.at("beta").get<RealType>(),
879 j.at("gamma").get<RealType>(), id);
880 }
881 else if (pattern == "gaussian")
882 {
883 ant =
884 std::make_unique<Gaussian>(name, j.at("azscale").get<RealType>(), j.at("elscale").get<RealType>(), id);
885 }
886 else if (pattern == "squarehorn")
887 {
888 ant = std::make_unique<SquareHorn>(name, j.at("diameter").get<RealType>(), id);
889 }
890 else if (pattern == "parabolic")
891 {
892 ant = std::make_unique<Parabolic>(name, j.at("diameter").get<RealType>(), id);
893 }
894 else if (pattern == "xml")
895 {
896 const auto filename = j.value("filename", "");
897 if (filename.empty())
898 {
899 LOG(logging::Level::WARNING, "Skipping load of XML antenna '{}': filename is empty.", name);
900 return; // ant remains nullptr
901 }
902 ant = std::make_unique<XmlAntenna>(name, filename, id);
903 }
904 else if (pattern == "file")
905 {
906 const auto filename = j.value("filename", "");
907 if (filename.empty())
908 {
909 LOG(logging::Level::WARNING, "Skipping load of H5 antenna '{}': filename is empty.", name);
910 return; // ant remains nullptr
911 }
912 ant = std::make_unique<H5Antenna>(name, filename, id);
913 }
914 else
915 {
916 throw std::runtime_error("Unsupported antenna pattern in from_json: " + pattern);
917 }
918
919 ant->setEfficiencyFactor(j.value("efficiency", 1.0));
920 }
double RealType
Type for real numbers.
Definition config.h:27
#define LOG(level,...)
Definition logging.h:19
@ WARNING
Warning level for potentially harmful situations.
math::Vec3 max

References LOG, max, and logging::WARNING.

Referenced by serial::parse_antenna_from_json().

+ Here is the caller graph for this function:

◆ to_json()

void antenna::to_json ( nlohmann::json &  j,
const Antenna a 
)

Definition at line 823 of file json_serializer.cpp.

824 {
825 j = {{"id", sim_id_to_json(a.getId())}, {"name", a.getName()}, {"efficiency", a.getEfficiencyFactor()}};
826
827 if (const auto* sinc = dynamic_cast<const Sinc*>(&a))
828 {
829 j["pattern"] = "sinc";
830 j["alpha"] = sinc->getAlpha();
831 j["beta"] = sinc->getBeta();
832 j["gamma"] = sinc->getGamma();
833 }
834 else if (const auto* gaussian = dynamic_cast<const Gaussian*>(&a))
835 {
836 j["pattern"] = "gaussian";
837 j["azscale"] = gaussian->getAzimuthScale();
838 j["elscale"] = gaussian->getElevationScale();
839 }
840 else if (const auto* sh = dynamic_cast<const SquareHorn*>(&a))
841 {
842 j["pattern"] = "squarehorn";
843 j["diameter"] = sh->getDimension();
844 }
845 else if (const auto* parabolic = dynamic_cast<const Parabolic*>(&a))
846 {
847 j["pattern"] = "parabolic";
848 j["diameter"] = parabolic->getDiameter();
849 }
850 else if (const auto* xml = dynamic_cast<const XmlAntenna*>(&a))
851 {
852 j["pattern"] = "xml";
853 j["filename"] = xml->getFilename();
854 }
855 else if (const auto* h5 = dynamic_cast<const H5Antenna*>(&a))
856 {
857 j["pattern"] = "file";
858 j["filename"] = h5->getFilename();
859 }
860 else
861 {
862 j["pattern"] = "isotropic";
863 }
864 }
RealType a

References a, and max.