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 778 of file json_serializer.cpp.

779 {
780 const auto name = j.at("name").get<std::string>();
781 const auto id = parse_json_id(j, "id", "Antenna");
782 const auto pattern = j.value("pattern", "isotropic");
783
784 if (pattern == "isotropic")
785 {
786 ant = std::make_unique<Isotropic>(name, id);
787 }
788 else if (pattern == "sinc")
789 {
790 ant = std::make_unique<Sinc>(name, j.at("alpha").get<RealType>(), j.at("beta").get<RealType>(),
791 j.at("gamma").get<RealType>(), id);
792 }
793 else if (pattern == "gaussian")
794 {
795 ant =
796 std::make_unique<Gaussian>(name, j.at("azscale").get<RealType>(), j.at("elscale").get<RealType>(), id);
797 }
798 else if (pattern == "squarehorn")
799 {
800 ant = std::make_unique<SquareHorn>(name, j.at("diameter").get<RealType>(), id);
801 }
802 else if (pattern == "parabolic")
803 {
804 ant = std::make_unique<Parabolic>(name, j.at("diameter").get<RealType>(), id);
805 }
806 else if (pattern == "xml")
807 {
808 const auto filename = j.value("filename", "");
809 if (filename.empty())
810 {
811 LOG(logging::Level::WARNING, "Skipping load of XML antenna '{}': filename is empty.", name);
812 return; // ant remains nullptr
813 }
814 ant = std::make_unique<XmlAntenna>(name, filename, id);
815 }
816 else if (pattern == "file")
817 {
818 const auto filename = j.value("filename", "");
819 if (filename.empty())
820 {
821 LOG(logging::Level::WARNING, "Skipping load of H5 antenna '{}': filename is empty.", name);
822 return; // ant remains nullptr
823 }
824 ant = std::make_unique<H5Antenna>(name, filename, id);
825 }
826 else
827 {
828 throw std::runtime_error("Unsupported antenna pattern in from_json: " + pattern);
829 }
830
831 ant->setEfficiencyFactor(j.value("efficiency", 1.0));
832 }
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 735 of file json_serializer.cpp.

736 {
737 j = {{"id", sim_id_to_json(a.getId())}, {"name", a.getName()}, {"efficiency", a.getEfficiencyFactor()}};
738
739 if (const auto* sinc = dynamic_cast<const Sinc*>(&a))
740 {
741 j["pattern"] = "sinc";
742 j["alpha"] = sinc->getAlpha();
743 j["beta"] = sinc->getBeta();
744 j["gamma"] = sinc->getGamma();
745 }
746 else if (const auto* gaussian = dynamic_cast<const Gaussian*>(&a))
747 {
748 j["pattern"] = "gaussian";
749 j["azscale"] = gaussian->getAzimuthScale();
750 j["elscale"] = gaussian->getElevationScale();
751 }
752 else if (const auto* sh = dynamic_cast<const SquareHorn*>(&a))
753 {
754 j["pattern"] = "squarehorn";
755 j["diameter"] = sh->getDimension();
756 }
757 else if (const auto* parabolic = dynamic_cast<const Parabolic*>(&a))
758 {
759 j["pattern"] = "parabolic";
760 j["diameter"] = parabolic->getDiameter();
761 }
762 else if (const auto* xml = dynamic_cast<const XmlAntenna*>(&a))
763 {
764 j["pattern"] = "xml";
765 j["filename"] = xml->getFilename();
766 }
767 else if (const auto* h5 = dynamic_cast<const H5Antenna*>(&a))
768 {
769 j["pattern"] = "file";
770 j["filename"] = h5->getFilename();
771 }
772 else
773 {
774 j["pattern"] = "isotropic";
775 }
776 }
RealType a

References a, and max.