Skip to content

Commit

Permalink
Merge pull request #751 from ngageoint/fix-txrx-pol-conversion
Browse files Browse the repository at this point in the history
Fix txrx pol conversion
  • Loading branch information
adam-beauchamp authored Sep 23, 2024
2 parents ac30d2b + 3f8e31b commit c155714
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 27 deletions.
1 change: 1 addition & 0 deletions six/modules/c++/six.sidd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ coda_add_tests(
test_geometric_chip.cpp
test_read_sidd_legend.cpp
test_valid_sixsidd.cpp
test_dual_polarization_type_conversions.cpp
unittest_sidd_byte_provider.cpp)

# Install the schemas
Expand Down
228 changes: 202 additions & 26 deletions six/modules/c++/six.sidd/source/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,47 +414,223 @@ void Utilities::setCollectionValues(Vector3 arpVel,
six::PolarizationSequenceType _convertDualPolarization(six::DualPolarizationType pol,
bool useFirst)
{
if (pol == six::DualPolarizationType::UNKNOWN)
{
throw except::Exception(Ctxt("DualPolarizationType::UNKNOWN has no "
"corresponding PolarizationType"));
}

if (useFirst)
{
switch (pol)
{
case six::DualPolarizationType::OTHER:
case six::DualPolarizationType::OTHER_V:
case six::DualPolarizationType::OTHER_H:
case six::DualPolarizationType::OTHER_X:
case six::DualPolarizationType::OTHER_Y:
case six::DualPolarizationType::OTHER_S:
case six::DualPolarizationType::OTHER_E:
case six::DualPolarizationType::OTHER_RHC:
case six::DualPolarizationType::OTHER_LHC:
case six::DualPolarizationType::OTHER_OTHER:
return six::PolarizationSequenceType::OTHER;

case six::DualPolarizationType::V_V:
case six::DualPolarizationType::V_H:
case six::DualPolarizationType::V_X:
case six::DualPolarizationType::V_Y:
case six::DualPolarizationType::V_S:
case six::DualPolarizationType::V_E:
case six::DualPolarizationType::V_RHC:
case six::DualPolarizationType::V_LHC:
case six::DualPolarizationType::V_OTHER:
return six::PolarizationSequenceType::V;

case six::DualPolarizationType::H_V:
case six::DualPolarizationType::H_H:
case six::DualPolarizationType::H_X:
case six::DualPolarizationType::H_Y:
case six::DualPolarizationType::H_S:
case six::DualPolarizationType::H_E:
case six::DualPolarizationType::H_RHC:
case six::DualPolarizationType::H_LHC:
case six::DualPolarizationType::H_OTHER:
return six::PolarizationSequenceType::H;

case six::DualPolarizationType::X_V:
case six::DualPolarizationType::X_H:
case six::DualPolarizationType::X_X:
case six::DualPolarizationType::X_Y:
case six::DualPolarizationType::X_S:
case six::DualPolarizationType::X_E:
case six::DualPolarizationType::X_RHC:
case six::DualPolarizationType::X_LHC:
case six::DualPolarizationType::X_OTHER:
return six::PolarizationSequenceType::X;

case six::DualPolarizationType::Y_V:
case six::DualPolarizationType::Y_H:
case six::DualPolarizationType::Y_X:
case six::DualPolarizationType::Y_Y:
case six::DualPolarizationType::Y_S:
case six::DualPolarizationType::Y_E:
case six::DualPolarizationType::Y_RHC:
case six::DualPolarizationType::Y_LHC:
case six::DualPolarizationType::Y_OTHER:
return six::PolarizationSequenceType::Y;

case six::DualPolarizationType::S_V:
case six::DualPolarizationType::S_H:
case six::DualPolarizationType::S_X:
case six::DualPolarizationType::S_Y:
case six::DualPolarizationType::S_S:
case six::DualPolarizationType::S_E:
case six::DualPolarizationType::S_RHC:
case six::DualPolarizationType::S_LHC:
case six::DualPolarizationType::S_OTHER:
return six::PolarizationSequenceType::S;

case six::DualPolarizationType::E_V:
case six::DualPolarizationType::E_H:
case six::DualPolarizationType::E_X:
case six::DualPolarizationType::E_Y:
case six::DualPolarizationType::E_S:
case six::DualPolarizationType::E_E:
case six::DualPolarizationType::E_RHC:
case six::DualPolarizationType::E_LHC:
case six::DualPolarizationType::E_OTHER:
return six::PolarizationSequenceType::E;

case six::DualPolarizationType::RHC_V:
case six::DualPolarizationType::RHC_H:
case six::DualPolarizationType::RHC_X:
case six::DualPolarizationType::RHC_Y:
case six::DualPolarizationType::RHC_S:
case six::DualPolarizationType::RHC_E:
case six::DualPolarizationType::RHC_RHC:
case six::DualPolarizationType::RHC_LHC:
case six::DualPolarizationType::RHC_OTHER:
return six::PolarizationSequenceType::RHC;

case six::DualPolarizationType::LHC_V:
case six::DualPolarizationType::LHC_H:
case six::DualPolarizationType::LHC_X:
case six::DualPolarizationType::LHC_Y:
case six::DualPolarizationType::LHC_S:
case six::DualPolarizationType::LHC_E:
case six::DualPolarizationType::LHC_RHC:
case six::DualPolarizationType::LHC_LHC:
case six::DualPolarizationType::LHC_OTHER:
return six::PolarizationSequenceType::LHC;

default:
return six::PolarizationSequenceType::NOT_SET;
}
}

switch (pol)
{
case six::DualPolarizationType::OTHER:
case six::DualPolarizationType::OTHER_OTHER:
case six::DualPolarizationType::V_OTHER:
case six::DualPolarizationType::H_OTHER:
case six::DualPolarizationType::X_OTHER:
case six::DualPolarizationType::Y_OTHER:
case six::DualPolarizationType::S_OTHER:
case six::DualPolarizationType::E_OTHER:
case six::DualPolarizationType::RHC_OTHER:
case six::DualPolarizationType::LHC_OTHER:
return six::PolarizationSequenceType::OTHER;

case six::DualPolarizationType::OTHER_V:
case six::DualPolarizationType::V_V:
case six::DualPolarizationType::H_V:
case six::DualPolarizationType::X_V:
case six::DualPolarizationType::Y_V:
case six::DualPolarizationType::S_V:
case six::DualPolarizationType::E_V:
case six::DualPolarizationType::RHC_V:
case six::DualPolarizationType::LHC_V:
return six::PolarizationSequenceType::V;

case six::DualPolarizationType::OTHER_H:
case six::DualPolarizationType::V_H:
return useFirst ? six::PolarizationSequenceType::V : six::PolarizationSequenceType::H;
case six::DualPolarizationType::V_RHC:
return useFirst ? six::PolarizationSequenceType::V : six::PolarizationSequenceType::RHC;
case six::DualPolarizationType::V_LHC:
return useFirst ? six::PolarizationSequenceType::V : six::PolarizationSequenceType::LHC;
case six::DualPolarizationType::H_V:
return useFirst ? six::PolarizationSequenceType::H : six::PolarizationSequenceType::V;
case six::DualPolarizationType::H_H:
case six::DualPolarizationType::X_H:
case six::DualPolarizationType::Y_H:
case six::DualPolarizationType::S_H:
case six::DualPolarizationType::E_H:
case six::DualPolarizationType::RHC_H:
case six::DualPolarizationType::LHC_H:
return six::PolarizationSequenceType::H;

case six::DualPolarizationType::OTHER_X:
case six::DualPolarizationType::V_X:
case six::DualPolarizationType::H_X:
case six::DualPolarizationType::X_X:
case six::DualPolarizationType::Y_X:
case six::DualPolarizationType::S_X:
case six::DualPolarizationType::E_X:
case six::DualPolarizationType::RHC_X:
case six::DualPolarizationType::LHC_X:
return six::PolarizationSequenceType::X;

case six::DualPolarizationType::OTHER_Y:
case six::DualPolarizationType::V_Y:
case six::DualPolarizationType::H_Y:
case six::DualPolarizationType::X_Y:
case six::DualPolarizationType::Y_Y:
case six::DualPolarizationType::S_Y:
case six::DualPolarizationType::E_Y:
case six::DualPolarizationType::RHC_Y:
case six::DualPolarizationType::LHC_Y:
return six::PolarizationSequenceType::Y;

case six::DualPolarizationType::OTHER_S:
case six::DualPolarizationType::V_S:
case six::DualPolarizationType::H_S:
case six::DualPolarizationType::X_S:
case six::DualPolarizationType::Y_S:
case six::DualPolarizationType::S_S:
case six::DualPolarizationType::E_S:
case six::DualPolarizationType::RHC_S:
case six::DualPolarizationType::LHC_S:
return six::PolarizationSequenceType::S;

case six::DualPolarizationType::OTHER_E:
case six::DualPolarizationType::V_E:
case six::DualPolarizationType::H_E:
case six::DualPolarizationType::X_E:
case six::DualPolarizationType::Y_E:
case six::DualPolarizationType::S_E:
case six::DualPolarizationType::E_E:
case six::DualPolarizationType::RHC_E:
case six::DualPolarizationType::LHC_E:
return six::PolarizationSequenceType::E;

case six::DualPolarizationType::OTHER_RHC:
case six::DualPolarizationType::V_RHC:
case six::DualPolarizationType::H_RHC:
return useFirst ? six::PolarizationSequenceType::H : six::PolarizationSequenceType::RHC;
case six::DualPolarizationType::H_LHC:
return useFirst ? six::PolarizationSequenceType::H : six::PolarizationSequenceType::LHC;
case six::DualPolarizationType::X_RHC:
case six::DualPolarizationType::Y_RHC:
case six::DualPolarizationType::S_RHC:
case six::DualPolarizationType::E_RHC:
case six::DualPolarizationType::RHC_RHC:
case six::DualPolarizationType::LHC_RHC:
return six::PolarizationSequenceType::RHC;

case six::DualPolarizationType::OTHER_LHC:
case six::DualPolarizationType::V_LHC:
case six::DualPolarizationType::H_LHC:
case six::DualPolarizationType::X_LHC:
case six::DualPolarizationType::Y_LHC:
case six::DualPolarizationType::S_LHC:
case six::DualPolarizationType::E_LHC:
case six::DualPolarizationType::RHC_LHC:
return useFirst ? six::PolarizationSequenceType::RHC
: six::PolarizationSequenceType::LHC;
case six::DualPolarizationType::RHC_V:
return useFirst ? six::PolarizationSequenceType::RHC : six::PolarizationSequenceType::V;
case six::DualPolarizationType::RHC_H:
return useFirst ? six::PolarizationSequenceType::RHC : six::PolarizationSequenceType::H;
case six::DualPolarizationType::LHC_RHC:
return useFirst ? six::PolarizationSequenceType::LHC
: six::PolarizationSequenceType::RHC;
case six::DualPolarizationType::LHC_LHC:
return six::PolarizationSequenceType::LHC;
case six::DualPolarizationType::LHC_V:
return useFirst ? six::PolarizationSequenceType::LHC : six::PolarizationSequenceType::V;
case six::DualPolarizationType::LHC_H:
return useFirst ? six::PolarizationSequenceType::LHC : six::PolarizationSequenceType::H;
case six::DualPolarizationType::UNKNOWN:
throw except::Exception(Ctxt("DualPolarizationType::UNKNOWN has no "
"corresponding PolarizationType"));

default:
return six::PolarizationSequenceType::NOT_SET;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* =========================================================================
* This file is part of six.sidd-c++
* =========================================================================
*
* (C) Copyright 2004 - 2016, MDA Information Systems LLC
*
* six-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#include <vector>

#include <import/str.h>

#include "TestCase.h"
#include <six/Enums.h>
#include <six/sidd/Utilities.h>

TEST_CASE(DualPolarization)
{
auto&& map = six::PolarizationType::string_to_value_();
for (auto&& tx : map)
{
const auto txType = six::PolarizationType::toType(tx.first);
TEST_ASSERT_EQ(tx.second, txType);
if ((txType == six::PolarizationType::NOT_SET) || (txType == six::PolarizationType::UNKNOWN))
{
continue;
}
for (auto&& rcv : map)
{
const auto rcvType = six::PolarizationType::toType(rcv.first);
TEST_ASSERT_EQ(rcv.second, rcvType);
if ((rcvType == six::PolarizationType::NOT_SET) || (rcvType == six::PolarizationType::UNKNOWN))
{
continue;
}
auto strType = txType.toString() + "_" + rcvType.toString();

auto fromToType = six::DualPolarizationType::toType(strType);

auto asPair = six::sidd::Utilities::convertDualPolarization(fromToType);
TEST_ASSERT_EQ(asPair.first.toString(), txType.toString());
TEST_ASSERT_EQ(asPair.second.toString(), rcvType.toString());
}
}
}

TEST_MAIN(
TEST_CHECK(DualPolarization);
)
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TEST_CASE(ToType)
test_toType<six::PolarizationType>(testName, 12);

test_toType_<six::PolarizationSequenceType>(testName, "X", six::PolarizationSequenceType::X); // SICD 1.3
test_toType_<six::PolarizationSequenceType>(testName, "SEQUENCE", six::PolarizationSequenceType::SEQUENCE);
test_toType_<six::PolarizationSequenceType>(testName, "SEQUENCE", six::PolarizationSequenceType::SEQUENCE);
test_toType<six::PolarizationSequenceType>(testName, 13);
}

Expand Down

0 comments on commit c155714

Please sign in to comment.