<commit_before>// Copyright (c) 2019 Chris Ohk, Youngjoong Kim, SeungHyun Jeon

// We are making my contributions/submissions to this project solely in our
// personal capacity and are not conveying any rights to any intellectual
// property of any third parties.

#include "gtest/gtest.h"

#include <Rosetta/Cards/Cards.hpp>
#include <Rosetta/Enums/CardEnums.hpp>

using namespace RosettaStone;

TEST(Cards, GetAllCards)
{
    const std::vector<Card> cards1 = Cards::GetInstance().GetAllCards();

    ASSERT_FALSE(cards1.empty());
    EXPECT_EQ(cards1.size(), 6086u);
}

TEST(Cards, FindCardByID)
{
    const Card card1 = Cards::GetInstance().FindCardByID("AT_001");
    const Card card2 = Cards::GetInstance().FindCardByID("");

    EXPECT_EQ(card1.id, "AT_001");
    EXPECT_EQ(card2.id, "");
}

TEST(Cards, FindCardByRarity)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByRarity(Rarity::COMMON);
    std::vector<Card> cards2 = instance.FindCardByRarity(Rarity::RARE);
    std::vector<Card> cards3 = instance.FindCardByRarity(Rarity::EPIC);
    std::vector<Card> cards4 = instance.FindCardByRarity(Rarity::LEGENDARY);
    std::vector<Card> cards5 = instance.FindCardByRarity(Rarity::FREE);
    std::vector<Card> cards6 = instance.FindCardByRarity(Rarity::INVALID);
    std::vector<Card> cards7 = instance.FindCardByRarity(Rarity::UNKNOWN_6);

    EXPECT_EQ(Rarity::COMMON, cards1.front().GetRarity());
    EXPECT_EQ(Rarity::RARE, cards2.front().GetRarity());
    EXPECT_EQ(Rarity::EPIC, cards3.front().GetRarity());
    EXPECT_EQ(Rarity::LEGENDARY, cards4.front().GetRarity());
    EXPECT_EQ(Rarity::FREE, cards5.front().GetRarity());
    EXPECT_EQ(Rarity::INVALID, cards6.front().GetRarity());
    EXPECT_TRUE(cards7.empty());
}

TEST(Cards, FindCardByClass)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByClass(CardClass::DEATHKNIGHT);
    std::vector<Card> cards2 = instance.FindCardByClass(CardClass::DREAM);
    std::vector<Card> cards3 = instance.FindCardByClass(CardClass::DRUID);
    std::vector<Card> cards4 = instance.FindCardByClass(CardClass::HUNTER);
    std::vector<Card> cards5 = instance.FindCardByClass(CardClass::MAGE);
    std::vector<Card> cards6 = instance.FindCardByClass(CardClass::NEUTRAL);
    std::vector<Card> cards7 = instance.FindCardByClass(CardClass::PALADIN);
    std::vector<Card> cards8 = instance.FindCardByClass(CardClass::PRIEST);
    std::vector<Card> cards9 = instance.FindCardByClass(CardClass::INVALID);

    EXPECT_EQ(CardClass::DEATHKNIGHT, cards1.front().GetCardClass());
    EXPECT_EQ(CardClass::DREAM, cards2.front().GetCardClass());
    EXPECT_EQ(CardClass::DRUID, cards3.front().GetCardClass());
    EXPECT_EQ(CardClass::HUNTER, cards4.front().GetCardClass());
    EXPECT_EQ(CardClass::MAGE, cards5.front().GetCardClass());
    EXPECT_EQ(CardClass::NEUTRAL, cards6.front().GetCardClass());
    EXPECT_EQ(CardClass::PALADIN, cards7.front().GetCardClass());
    EXPECT_EQ(CardClass::PRIEST, cards8.front().GetCardClass());
    EXPECT_EQ(CardClass::INVALID, cards9.front().GetCardClass());
}

TEST(Cards, FindCardBySet)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardBySet(CardSet::CORE);
    std::vector<Card> cards2 = instance.FindCardBySet(CardSet::EXPERT1);
    std::vector<Card> cards3 = instance.FindCardBySet(CardSet::HOF);
    std::vector<Card> cards4 = instance.FindCardBySet(CardSet::NAXX);
    std::vector<Card> cards5 = instance.FindCardBySet(CardSet::GVG);
    std::vector<Card> cards6 = instance.FindCardBySet(CardSet::BRM);
    std::vector<Card> cards7 = instance.FindCardBySet(CardSet::TGT);
    std::vector<Card> cards8 = instance.FindCardBySet(CardSet::LOE);
    std::vector<Card> cards9 = instance.FindCardBySet(CardSet::OG);
    std::vector<Card> cards10 = instance.FindCardBySet(CardSet::KARA);
    std::vector<Card> cards11 = instance.FindCardBySet(CardSet::GANGS);
    std::vector<Card> cards12 = instance.FindCardBySet(CardSet::UNGORO);
    std::vector<Card> cards13 = instance.FindCardBySet(CardSet::ICECROWN);
    std::vector<Card> cards14 = instance.FindCardBySet(CardSet::LOOTAPALOOZA);
    std::vector<Card> cards15 = instance.FindCardBySet(CardSet::GILNEAS);
    std::vector<Card> cards16 = instance.FindCardBySet(CardSet::BOOMSDAY);
    std::vector<Card> cards17 = instance.FindCardBySet(CardSet::INVALID);

    EXPECT_EQ(CardSet::CORE, cards1.front().GetCardSet());
    EXPECT_EQ(CardSet::EXPERT1, cards2.front().GetCardSet());
    EXPECT_EQ(CardSet::HOF, cards3.front().GetCardSet());
    EXPECT_EQ(CardSet::NAXX, cards4.front().GetCardSet());
    EXPECT_EQ(CardSet::GVG, cards5.front().GetCardSet());
    EXPECT_EQ(CardSet::BRM, cards6.front().GetCardSet());
    EXPECT_EQ(CardSet::TGT, cards7.front().GetCardSet());
    EXPECT_EQ(CardSet::LOE, cards8.front().GetCardSet());
    EXPECT_EQ(CardSet::OG, cards9.front().GetCardSet());
    EXPECT_EQ(CardSet::KARA, cards10.front().GetCardSet());
    EXPECT_EQ(CardSet::GANGS, cards11.front().GetCardSet());
    EXPECT_EQ(CardSet::UNGORO, cards12.front().GetCardSet());
    EXPECT_EQ(CardSet::ICECROWN, cards13.front().GetCardSet());
    EXPECT_EQ(CardSet::LOOTAPALOOZA, cards14.front().GetCardSet());
    EXPECT_EQ(CardSet::GILNEAS, cards15.front().GetCardSet());
    EXPECT_EQ(CardSet::BOOMSDAY, cards16.front().GetCardSet());
    EXPECT_TRUE(cards17.empty());
}

TEST(Cards, FindCardByType)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByType(CardType::WEAPON);
    std::vector<Card> cards2 = instance.FindCardByType(CardType::GAME);
    std::vector<Card> cards3 = instance.FindCardByType(CardType::HERO);
    std::vector<Card> cards4 = instance.FindCardByType(CardType::HERO_POWER);
    std::vector<Card> cards5 = instance.FindCardByType(CardType::ENCHANTMENT);
    std::vector<Card> cards6 = instance.FindCardByType(CardType::ITEM);
    std::vector<Card> cards7 = instance.FindCardByType(CardType::MINION);
    std::vector<Card> cards8 = instance.FindCardByType(CardType::PLAYER);
    std::vector<Card> cards9 = instance.FindCardByType(CardType::SPELL);
    std::vector<Card> cards10 = instance.FindCardByType(CardType::TOKEN);
    std::vector<Card> cards11 = instance.FindCardByType(CardType::INVALID);

    EXPECT_EQ(CardType::WEAPON, cards1.front().GetCardType());
    EXPECT_EQ(CardType::HERO, cards3.front().GetCardType());
    EXPECT_EQ(CardType::HERO_POWER, cards4.front().GetCardType());
    EXPECT_EQ(CardType::ENCHANTMENT, cards5.front().GetCardType());
    EXPECT_EQ(CardType::MINION, cards7.front().GetCardType());
    EXPECT_EQ(CardType::SPELL, cards9.front().GetCardType());
    EXPECT_TRUE(cards2.empty());
    EXPECT_TRUE(cards6.empty());
    EXPECT_TRUE(cards8.empty());
    EXPECT_TRUE(cards10.empty());
    EXPECT_TRUE(cards11.empty());
}

TEST(Cards, FindCardByRace)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards = instance.FindCardByRace(Race::INVALID);

    EXPECT_FALSE(cards.empty());
    EXPECT_NO_THROW(instance.FindCardByRace(Race::ALL));
}

TEST(Cards, FindCardByName)
{
    Cards& instance = Cards::GetInstance();

    const Card card = instance.FindCardByName("Flame Lance");

    EXPECT_EQ("Flame Lance", card.name);
}

TEST(Cards, FindCardByCost)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByCost(0, 1);
    std::vector<Card> cards2 = instance.FindCardByCost(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByAttack)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByAttack(0, 1);
    std::vector<Card> cards2 = instance.FindCardByAttack(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByHealth)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByHealth(0, 1);
    std::vector<Card> cards2 = instance.FindCardByHealth(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByGameTag)
{
    Cards& instance = Cards::GetInstance();

    std::vector<GameTag> tags1;
    const std::vector<GameTag> tags2;
    tags1.emplace_back(GameTag::CANT_ATTACK);

    std::vector<Card> cards1 = instance.FindCardByGameTag(tags1);
    std::vector<Card> cards2 = instance.FindCardByGameTag(tags2);
    auto gameTags = cards1.front().gameTags;

    EXPECT_TRUE(gameTags.find(GameTag::CANT_ATTACK) != gameTags.end());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, GetHeroCard)
{
    Cards& instance = Cards::GetInstance();

    EXPECT_EQ(instance.FindCardByID("HERO_06").id,
              instance.GetHeroCard(CardClass::DRUID).id);
    EXPECT_EQ(instance.FindCardByID("HERO_05").id,
              instance.GetHeroCard(CardClass::HUNTER).id);
    EXPECT_EQ(instance.FindCardByID("HERO_08").id,
              instance.GetHeroCard(CardClass::MAGE).id);
    EXPECT_EQ(instance.FindCardByID("HERO_04").id,
              instance.GetHeroCard(CardClass::PALADIN).id);
    EXPECT_EQ(instance.FindCardByID("HERO_09").id,
              instance.GetHeroCard(CardClass::PRIEST).id);
    EXPECT_EQ(instance.FindCardByID("HERO_03").id,
              instance.GetHeroCard(CardClass::ROGUE).id);
    EXPECT_EQ(instance.FindCardByID("HERO_02").id,
              instance.GetHeroCard(CardClass::SHAMAN).id);
    EXPECT_EQ(instance.FindCardByID("HERO_07").id,
              instance.GetHeroCard(CardClass::WARLOCK).id);
    EXPECT_EQ(instance.FindCardByID("HERO_01").id,
              instance.GetHeroCard(CardClass::WARRIOR).id);
    EXPECT_EQ(instance.GetHeroCard(CardClass::DEATHKNIGHT).id, "");
}

TEST(Cards, GetDefaultHeroPower)
{
    Cards& instance = Cards::GetInstance();

    EXPECT_EQ(instance.FindCardByID("CS2_017").id,
              instance.GetDefaultHeroPower(CardClass::DRUID).id);
    EXPECT_EQ(instance.FindCardByID("DS1h_292").id,
              instance.GetDefaultHeroPower(CardClass::HUNTER).id);
    EXPECT_EQ(instance.FindCardByID("CS2_034").id,
              instance.GetDefaultHeroPower(CardClass::MAGE).id);
    EXPECT_EQ(instance.FindCardByID("CS2_101").id,
              instance.GetDefaultHeroPower(CardClass::PALADIN).id);
    EXPECT_EQ(instance.FindCardByID("CS1h_001").id,
              instance.GetDefaultHeroPower(CardClass::PRIEST).id);
    EXPECT_EQ(instance.FindCardByID("CS2_083b").id,
              instance.GetDefaultHeroPower(CardClass::ROGUE).id);
    EXPECT_EQ(instance.FindCardByID("CS2_049").id,
              instance.GetDefaultHeroPower(CardClass::SHAMAN).id);
    EXPECT_EQ(instance.FindCardByID("CS2_056").id,
              instance.GetDefaultHeroPower(CardClass::WARLOCK).id);
    EXPECT_EQ(instance.FindCardByID("CS2_102").id,
              instance.GetDefaultHeroPower(CardClass::WARRIOR).id);
    EXPECT_EQ(instance.GetDefaultHeroPower(CardClass::DEATHKNIGHT).id, "");
}

TEST(Cards, FindCardBySpellDamage)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardBySpellPower(1, 1);
    std::vector<Card> cards2 = instance.FindCardBySpellPower(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}
<commit_msg>test: Update the size of all cards<commit_after>// Copyright (c) 2019 Chris Ohk, Youngjoong Kim, SeungHyun Jeon

// We are making my contributions/submissions to this project solely in our
// personal capacity and are not conveying any rights to any intellectual
// property of any third parties.

#include "gtest/gtest.h"

#include <Rosetta/Cards/Cards.hpp>
#include <Rosetta/Enums/CardEnums.hpp>

using namespace RosettaStone;

TEST(Cards, GetAllCards)
{
    const std::vector<Card> cards = Cards::GetInstance().GetAllCards();

    ASSERT_FALSE(cards.empty());
    EXPECT_EQ(cards.size(), 6717u);
}

TEST(Cards, FindCardByID)
{
    const Card card1 = Cards::GetInstance().FindCardByID("AT_001");
    const Card card2 = Cards::GetInstance().FindCardByID("");

    EXPECT_EQ(card1.id, "AT_001");
    EXPECT_EQ(card2.id, "");
}

TEST(Cards, FindCardByRarity)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByRarity(Rarity::COMMON);
    std::vector<Card> cards2 = instance.FindCardByRarity(Rarity::RARE);
    std::vector<Card> cards3 = instance.FindCardByRarity(Rarity::EPIC);
    std::vector<Card> cards4 = instance.FindCardByRarity(Rarity::LEGENDARY);
    std::vector<Card> cards5 = instance.FindCardByRarity(Rarity::FREE);
    std::vector<Card> cards6 = instance.FindCardByRarity(Rarity::INVALID);
    std::vector<Card> cards7 = instance.FindCardByRarity(Rarity::UNKNOWN_6);

    EXPECT_EQ(Rarity::COMMON, cards1.front().GetRarity());
    EXPECT_EQ(Rarity::RARE, cards2.front().GetRarity());
    EXPECT_EQ(Rarity::EPIC, cards3.front().GetRarity());
    EXPECT_EQ(Rarity::LEGENDARY, cards4.front().GetRarity());
    EXPECT_EQ(Rarity::FREE, cards5.front().GetRarity());
    EXPECT_EQ(Rarity::INVALID, cards6.front().GetRarity());
    EXPECT_TRUE(cards7.empty());
}

TEST(Cards, FindCardByClass)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByClass(CardClass::DEATHKNIGHT);
    std::vector<Card> cards2 = instance.FindCardByClass(CardClass::DREAM);
    std::vector<Card> cards3 = instance.FindCardByClass(CardClass::DRUID);
    std::vector<Card> cards4 = instance.FindCardByClass(CardClass::HUNTER);
    std::vector<Card> cards5 = instance.FindCardByClass(CardClass::MAGE);
    std::vector<Card> cards6 = instance.FindCardByClass(CardClass::NEUTRAL);
    std::vector<Card> cards7 = instance.FindCardByClass(CardClass::PALADIN);
    std::vector<Card> cards8 = instance.FindCardByClass(CardClass::PRIEST);
    std::vector<Card> cards9 = instance.FindCardByClass(CardClass::INVALID);

    EXPECT_EQ(CardClass::DEATHKNIGHT, cards1.front().GetCardClass());
    EXPECT_EQ(CardClass::DREAM, cards2.front().GetCardClass());
    EXPECT_EQ(CardClass::DRUID, cards3.front().GetCardClass());
    EXPECT_EQ(CardClass::HUNTER, cards4.front().GetCardClass());
    EXPECT_EQ(CardClass::MAGE, cards5.front().GetCardClass());
    EXPECT_EQ(CardClass::NEUTRAL, cards6.front().GetCardClass());
    EXPECT_EQ(CardClass::PALADIN, cards7.front().GetCardClass());
    EXPECT_EQ(CardClass::PRIEST, cards8.front().GetCardClass());
    EXPECT_EQ(CardClass::INVALID, cards9.front().GetCardClass());
}

TEST(Cards, FindCardBySet)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardBySet(CardSet::CORE);
    std::vector<Card> cards2 = instance.FindCardBySet(CardSet::EXPERT1);
    std::vector<Card> cards3 = instance.FindCardBySet(CardSet::HOF);
    std::vector<Card> cards4 = instance.FindCardBySet(CardSet::NAXX);
    std::vector<Card> cards5 = instance.FindCardBySet(CardSet::GVG);
    std::vector<Card> cards6 = instance.FindCardBySet(CardSet::BRM);
    std::vector<Card> cards7 = instance.FindCardBySet(CardSet::TGT);
    std::vector<Card> cards8 = instance.FindCardBySet(CardSet::LOE);
    std::vector<Card> cards9 = instance.FindCardBySet(CardSet::OG);
    std::vector<Card> cards10 = instance.FindCardBySet(CardSet::KARA);
    std::vector<Card> cards11 = instance.FindCardBySet(CardSet::GANGS);
    std::vector<Card> cards12 = instance.FindCardBySet(CardSet::UNGORO);
    std::vector<Card> cards13 = instance.FindCardBySet(CardSet::ICECROWN);
    std::vector<Card> cards14 = instance.FindCardBySet(CardSet::LOOTAPALOOZA);
    std::vector<Card> cards15 = instance.FindCardBySet(CardSet::GILNEAS);
    std::vector<Card> cards16 = instance.FindCardBySet(CardSet::BOOMSDAY);
    std::vector<Card> cards17 = instance.FindCardBySet(CardSet::INVALID);

    EXPECT_EQ(CardSet::CORE, cards1.front().GetCardSet());
    EXPECT_EQ(CardSet::EXPERT1, cards2.front().GetCardSet());
    EXPECT_EQ(CardSet::HOF, cards3.front().GetCardSet());
    EXPECT_EQ(CardSet::NAXX, cards4.front().GetCardSet());
    EXPECT_EQ(CardSet::GVG, cards5.front().GetCardSet());
    EXPECT_EQ(CardSet::BRM, cards6.front().GetCardSet());
    EXPECT_EQ(CardSet::TGT, cards7.front().GetCardSet());
    EXPECT_EQ(CardSet::LOE, cards8.front().GetCardSet());
    EXPECT_EQ(CardSet::OG, cards9.front().GetCardSet());
    EXPECT_EQ(CardSet::KARA, cards10.front().GetCardSet());
    EXPECT_EQ(CardSet::GANGS, cards11.front().GetCardSet());
    EXPECT_EQ(CardSet::UNGORO, cards12.front().GetCardSet());
    EXPECT_EQ(CardSet::ICECROWN, cards13.front().GetCardSet());
    EXPECT_EQ(CardSet::LOOTAPALOOZA, cards14.front().GetCardSet());
    EXPECT_EQ(CardSet::GILNEAS, cards15.front().GetCardSet());
    EXPECT_EQ(CardSet::BOOMSDAY, cards16.front().GetCardSet());
    EXPECT_TRUE(cards17.empty());
}

TEST(Cards, FindCardByType)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByType(CardType::WEAPON);
    std::vector<Card> cards2 = instance.FindCardByType(CardType::GAME);
    std::vector<Card> cards3 = instance.FindCardByType(CardType::HERO);
    std::vector<Card> cards4 = instance.FindCardByType(CardType::HERO_POWER);
    std::vector<Card> cards5 = instance.FindCardByType(CardType::ENCHANTMENT);
    std::vector<Card> cards6 = instance.FindCardByType(CardType::ITEM);
    std::vector<Card> cards7 = instance.FindCardByType(CardType::MINION);
    std::vector<Card> cards8 = instance.FindCardByType(CardType::PLAYER);
    std::vector<Card> cards9 = instance.FindCardByType(CardType::SPELL);
    std::vector<Card> cards10 = instance.FindCardByType(CardType::TOKEN);
    std::vector<Card> cards11 = instance.FindCardByType(CardType::INVALID);

    EXPECT_EQ(CardType::WEAPON, cards1.front().GetCardType());
    EXPECT_EQ(CardType::HERO, cards3.front().GetCardType());
    EXPECT_EQ(CardType::HERO_POWER, cards4.front().GetCardType());
    EXPECT_EQ(CardType::ENCHANTMENT, cards5.front().GetCardType());
    EXPECT_EQ(CardType::MINION, cards7.front().GetCardType());
    EXPECT_EQ(CardType::SPELL, cards9.front().GetCardType());
    EXPECT_TRUE(cards2.empty());
    EXPECT_TRUE(cards6.empty());
    EXPECT_TRUE(cards8.empty());
    EXPECT_TRUE(cards10.empty());
    EXPECT_TRUE(cards11.empty());
}

TEST(Cards, FindCardByRace)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards = instance.FindCardByRace(Race::INVALID);

    EXPECT_FALSE(cards.empty());
    EXPECT_NO_THROW(instance.FindCardByRace(Race::ALL));
}

TEST(Cards, FindCardByName)
{
    Cards& instance = Cards::GetInstance();

    const Card card = instance.FindCardByName("Flame Lance");

    EXPECT_EQ("Flame Lance", card.name);
}

TEST(Cards, FindCardByCost)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByCost(0, 1);
    std::vector<Card> cards2 = instance.FindCardByCost(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByAttack)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByAttack(0, 1);
    std::vector<Card> cards2 = instance.FindCardByAttack(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByHealth)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardByHealth(0, 1);
    std::vector<Card> cards2 = instance.FindCardByHealth(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, FindCardByGameTag)
{
    Cards& instance = Cards::GetInstance();

    std::vector<GameTag> tags1;
    const std::vector<GameTag> tags2;
    tags1.emplace_back(GameTag::CANT_ATTACK);

    std::vector<Card> cards1 = instance.FindCardByGameTag(tags1);
    std::vector<Card> cards2 = instance.FindCardByGameTag(tags2);
    auto gameTags = cards1.front().gameTags;

    EXPECT_TRUE(gameTags.find(GameTag::CANT_ATTACK) != gameTags.end());
    EXPECT_TRUE(cards2.empty());
}

TEST(Cards, GetHeroCard)
{
    Cards& instance = Cards::GetInstance();

    EXPECT_EQ(instance.FindCardByID("HERO_06").id,
              instance.GetHeroCard(CardClass::DRUID).id);
    EXPECT_EQ(instance.FindCardByID("HERO_05").id,
              instance.GetHeroCard(CardClass::HUNTER).id);
    EXPECT_EQ(instance.FindCardByID("HERO_08").id,
              instance.GetHeroCard(CardClass::MAGE).id);
    EXPECT_EQ(instance.FindCardByID("HERO_04").id,
              instance.GetHeroCard(CardClass::PALADIN).id);
    EXPECT_EQ(instance.FindCardByID("HERO_09").id,
              instance.GetHeroCard(CardClass::PRIEST).id);
    EXPECT_EQ(instance.FindCardByID("HERO_03").id,
              instance.GetHeroCard(CardClass::ROGUE).id);
    EXPECT_EQ(instance.FindCardByID("HERO_02").id,
              instance.GetHeroCard(CardClass::SHAMAN).id);
    EXPECT_EQ(instance.FindCardByID("HERO_07").id,
              instance.GetHeroCard(CardClass::WARLOCK).id);
    EXPECT_EQ(instance.FindCardByID("HERO_01").id,
              instance.GetHeroCard(CardClass::WARRIOR).id);
    EXPECT_EQ(instance.GetHeroCard(CardClass::DEATHKNIGHT).id, "");
}

TEST(Cards, GetDefaultHeroPower)
{
    Cards& instance = Cards::GetInstance();

    EXPECT_EQ(instance.FindCardByID("CS2_017").id,
              instance.GetDefaultHeroPower(CardClass::DRUID).id);
    EXPECT_EQ(instance.FindCardByID("DS1h_292").id,
              instance.GetDefaultHeroPower(CardClass::HUNTER).id);
    EXPECT_EQ(instance.FindCardByID("CS2_034").id,
              instance.GetDefaultHeroPower(CardClass::MAGE).id);
    EXPECT_EQ(instance.FindCardByID("CS2_101").id,
              instance.GetDefaultHeroPower(CardClass::PALADIN).id);
    EXPECT_EQ(instance.FindCardByID("CS1h_001").id,
              instance.GetDefaultHeroPower(CardClass::PRIEST).id);
    EXPECT_EQ(instance.FindCardByID("CS2_083b").id,
              instance.GetDefaultHeroPower(CardClass::ROGUE).id);
    EXPECT_EQ(instance.FindCardByID("CS2_049").id,
              instance.GetDefaultHeroPower(CardClass::SHAMAN).id);
    EXPECT_EQ(instance.FindCardByID("CS2_056").id,
              instance.GetDefaultHeroPower(CardClass::WARLOCK).id);
    EXPECT_EQ(instance.FindCardByID("CS2_102").id,
              instance.GetDefaultHeroPower(CardClass::WARRIOR).id);
    EXPECT_EQ(instance.GetDefaultHeroPower(CardClass::DEATHKNIGHT).id, "");
}

TEST(Cards, FindCardBySpellDamage)
{
    Cards& instance = Cards::GetInstance();

    std::vector<Card> cards1 = instance.FindCardBySpellPower(1, 1);
    std::vector<Card> cards2 = instance.FindCardBySpellPower(2, 1);

    EXPECT_FALSE(cards1.empty());
    EXPECT_TRUE(cards2.empty());
}
<|endoftext|>


<commit_before>#include <iostream>
#include <stdexcept>
#include <string>

#include <boost/tr1/memory.hpp>

#include <boost/iterator/filter_iterator.hpp>
#include <boost/scoped_ptr.hpp>

extern "C" {
#include <libxslt/xslt.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libexslt/exslt.h>
}

#include <AlpinoCorpus/CorpusReader.hh>
#include <AlpinoCorpus/Error.hh>

#include <util/textfile.hh>

#include <EqualsPrevious.hh>
#include <ProgramOptions.hh>
#include <Stylesheet.hh>
#include <util.hh>

using alpinocorpus::CorpusReader;

namespace tr1 = std::tr1;

typedef boost::filter_iterator<NotEqualsPrevious<std::string>, CorpusReader::EntryIterator>
    UniqueFilterIter;

void transformCorpus(tr1::shared_ptr<CorpusReader> reader,
  tr1::shared_ptr<std::string const> query, tr1::shared_ptr<Stylesheet> stylesheet)
{
  std::list<CorpusReader::MarkerQuery> markerQueries;
  if (query) {
     // Markers
    CorpusReader::MarkerQuery activeMarker(*query, "active", "1");
    markerQueries.push_back(activeMarker);
  }

  CorpusReader::EntryIterator i, end(reader->end());

  if (query)
    i = reader->query(CorpusReader::XPATH, *query);
  else
    i = reader->begin();

  NotEqualsPrevious<std::string> pred;

  for (UniqueFilterIter iter(pred, i, end); iter != UniqueFilterIter(pred, end, end);
      ++iter)
    try {
      std::cout << stylesheet->transform(reader->readMarkQueries(*iter, markerQueries));
    } catch (std::runtime_error &e) {
      std::cerr << "Could not apply stylesheet to: " << *iter << std::endl;
    }
}

void transformEntry(tr1::shared_ptr<CorpusReader> reader,
  tr1::shared_ptr<std::string const> query, tr1::shared_ptr<Stylesheet> stylesheet,
  std::string const &entry)
{
  std::list<CorpusReader::MarkerQuery> markerQueries;
  if (query) {
     // Markers
    CorpusReader::MarkerQuery activeMarker(*query, "active", "1");
    markerQueries.push_back(activeMarker);
  }
  std::cout << stylesheet->transform(reader->readMarkQueries(entry, markerQueries));
}

void usage(std::string const &programName)
{
    std::cerr << "Usage: " << programName << " [OPTION] stylesheet treebanks" <<
      std::endl << std::endl <<
      "  -g entry\tApply the stylesheet to a single entry" << std::endl <<
      "  -q query\tFilter the treebank using the given query" << std::endl <<
      "  -r\t\tProcess a directory of corpora recursively" << std::endl << std::endl;
}

int main (int argc, char *argv[])
{
    xmlInitMemory();
    xmlInitParser();

    // EXSLT extensions
    exsltRegisterAll();

    // XPath
    xmlXPathInit();

  boost::scoped_ptr<ProgramOptions> opts;
  try {
    opts.reset(new ProgramOptions(argc, const_cast<char const **>(argv),
      "g:q:r"));
  } catch (std::exception &e) {
    std::cerr << e.what() << std::endl;
    return 1;
  }

  if (opts->arguments().size() < 2)
  {
    usage(opts->programName());
    return 1;
  }

  tr1::shared_ptr<Stylesheet> stylesheet;
  try {
    std::string stylesheetData = alpinocorpus::util::readFile(opts->arguments().at(0));
    stylesheet.reset(new Stylesheet(stylesheetData));
  } catch (std::runtime_error &e) {
    std::cerr << "Could not parse stylesheet: " << e.what() << std::endl;
    return 1;
  }

  tr1::shared_ptr<CorpusReader> reader;
  try {
    if (opts->arguments().size() == 2)
      reader = tr1::shared_ptr<CorpusReader>(
        openCorpus(opts->arguments().at(1), opts->option('r')));
    else
      reader = tr1::shared_ptr<CorpusReader>(
        openCorpora(opts->arguments().begin() + 1,
            opts->arguments().end(), opts->option('r')));
  } catch (std::runtime_error &e) {
    std::cerr << "Could not open corpus: " << e.what() << std::endl;
    return 1;
  }

  tr1::shared_ptr<std::string> query;
  if (opts->option('q')) {
    query.reset(new std::string(opts->optionValue('q')));

    if (!reader->isValidQuery(CorpusReader::XPATH, false, *query)) {
      std::cerr << "Invalid (or unwanted) query: " << *query << std::endl;
      return 1;
    }
  }

  try {
    if (opts->option('g'))
      transformEntry(reader, query, stylesheet, opts->optionValue('g'));
    else
      transformCorpus(reader, query, stylesheet);
  } catch (std::runtime_error &e) {
    std::cerr << "Error while transforming corpus: " << e.what() << std::endl;
  }
}
<commit_msg>ac-xslt: update for new overloaded read() method.<commit_after>#include <iostream>
#include <stdexcept>
#include <string>

#include <boost/tr1/memory.hpp>

#include <boost/iterator/filter_iterator.hpp>
#include <boost/scoped_ptr.hpp>

extern "C" {
#include <libxslt/xslt.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libexslt/exslt.h>
}

#include <AlpinoCorpus/CorpusReader.hh>
#include <AlpinoCorpus/Error.hh>

#include <util/textfile.hh>

#include <EqualsPrevious.hh>
#include <ProgramOptions.hh>
#include <Stylesheet.hh>
#include <util.hh>

using alpinocorpus::CorpusReader;

namespace tr1 = std::tr1;

typedef boost::filter_iterator<NotEqualsPrevious<std::string>, CorpusReader::EntryIterator>
    UniqueFilterIter;

void transformCorpus(tr1::shared_ptr<CorpusReader> reader,
  tr1::shared_ptr<std::string const> query, std::string const &stylesheet)
{
  std::list<CorpusReader::MarkerQuery> markerQueries;
  if (query) {
     // Markers
    CorpusReader::MarkerQuery activeMarker(*query, "active", "1");
    markerQueries.push_back(activeMarker);
  }

  CorpusReader::EntryIterator i, end(reader->end());

  if (query)
    i = reader->queryWithStylesheet(CorpusReader::XPATH, *query,
      stylesheet, markerQueries);
  else
    i = reader->beginWithStylesheet(stylesheet);

  NotEqualsPrevious<std::string> pred;

  for (UniqueFilterIter iter(pred, i, end); iter != UniqueFilterIter(pred, end, end);
      ++iter)
    try {
      std::cout << i.contents(*reader);
    } catch (std::runtime_error &e) {
      std::cerr << "Could not apply stylesheet to: " << *iter << std::endl;
    }
}

void transformEntry(tr1::shared_ptr<CorpusReader> reader,
  tr1::shared_ptr<std::string const> query, std::string stylesheet,
  std::string const &entry)
{
  Stylesheet compiledStylesheet(stylesheet);

  std::list<CorpusReader::MarkerQuery> markerQueries;
  if (query) {
     // Markers
    CorpusReader::MarkerQuery activeMarker(*query, "active", "1");
    markerQueries.push_back(activeMarker);
  }
  std::cout << compiledStylesheet.transform(reader->read(entry, markerQueries));
}

void usage(std::string const &programName)
{
    std::cerr << "Usage: " << programName << " [OPTION] stylesheet treebanks" <<
      std::endl << std::endl <<
      "  -g entry\tApply the stylesheet to a single entry" << std::endl <<
      "  -q query\tFilter the treebank using the given query" << std::endl <<
      "  -r\t\tProcess a directory of corpora recursively" << std::endl << std::endl;
}

int main (int argc, char *argv[])
{
    xmlInitMemory();
    xmlInitParser();

    // EXSLT extensions
    exsltRegisterAll();

    // XPath
    xmlXPathInit();

  boost::scoped_ptr<ProgramOptions> opts;
  try {
    opts.reset(new ProgramOptions(argc, const_cast<char const **>(argv),
      "g:q:r"));
  } catch (std::exception &e) {
    std::cerr << e.what() << std::endl;
    return 1;
  }

  if (opts->arguments().size() < 2)
  {
    usage(opts->programName());
    return 1;
  }

  std::string stylesheet;
  try {
    stylesheet = alpinocorpus::util::readFile(opts->arguments().at(0));
  } catch (std::runtime_error &e) {
    std::cerr << "Could not read stylesheet: " << e.what() << std::endl;
    return 1;
  }

  tr1::shared_ptr<CorpusReader> reader;
  try {
    if (opts->arguments().size() == 2)
      reader = tr1::shared_ptr<CorpusReader>(
        openCorpus(opts->arguments().at(1), opts->option('r')));
    else
      reader = tr1::shared_ptr<CorpusReader>(
        openCorpora(opts->arguments().begin() + 1,
            opts->arguments().end(), opts->option('r')));
  } catch (std::runtime_error &e) {
    std::cerr << "Could not open corpus: " << e.what() << std::endl;
    return 1;
  }

  tr1::shared_ptr<std::string> query;
  if (opts->option('q')) {
    query.reset(new std::string(opts->optionValue('q')));

    if (!reader->isValidQuery(CorpusReader::XPATH, false, *query)) {
      std::cerr << "Invalid (or unwanted) query: " << *query << std::endl;
      return 1;
    }
  }

  try {
    if (opts->option('g'))
      transformEntry(reader, query, stylesheet, opts->optionValue('g'));
    else
      transformCorpus(reader, query, stylesheet);
  } catch (std::runtime_error &e) {
    std::cerr << "Error while transforming corpus: " << e.what() << std::endl;
  }
}
<|endoftext|>


<commit_before>//Copyright (c) 2020 Ultimaker B.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#include <cassert>

#include "LimitedBeadingStrategy.h"

namespace cura
{

LimitedBeadingStrategy::Beading LimitedBeadingStrategy::compute(coord_t thickness, coord_t bead_count) const
{
    if (bead_count <= max_bead_count)
    {
        return parent->compute(thickness, bead_count);
    }
    assert(bead_count == max_bead_count + 1);

    coord_t optimal_thickness = parent->getOptimalThickness(max_bead_count);
    Beading ret = parent->compute(optimal_thickness, max_bead_count);
    ret.left_over += thickness - ret.total_thickness;
    ret.total_thickness = thickness;

    // Enforce symmetry
    if (bead_count % 2 == 1)
    {
        ret.toolpath_locations[bead_count / 2] = thickness / 2;
        ret.bead_widths[bead_count / 2] = thickness - optimal_thickness;
    }
    for (coord_t bead_idx = 0; bead_idx < (bead_count + 1) / 2; bead_idx++)
    {
        ret.toolpath_locations[bead_count - 1 - bead_idx] = thickness - ret.toolpath_locations[bead_idx];
    }

    //Create a "fake" inner wall with 0 width to indicate the edge of the walled area.
    //This wall can then be used by other structures to e.g. fill the infill area adjacent to the variable-width walls.
    coord_t innermost_toolpath_location = ret.toolpath_locations[max_bead_count / 2 - 1];
    coord_t innermost_toolpath_width = ret.bead_widths[max_bead_count / 2 - 1];
    ret.toolpath_locations.insert(ret.toolpath_locations.begin() + max_bead_count / 2, innermost_toolpath_location + innermost_toolpath_width / 2);
    ret.bead_widths.insert(ret.bead_widths.begin() + max_bead_count / 2, 0);

    //Symmetry on both sides. Symmetry is guaranteed since this code is stopped early if the bead_count <= max_bead_count, and never reaches this point then.
    innermost_toolpath_location = ret.toolpath_locations[bead_count - (max_bead_count / 2 - 1)];
    innermost_toolpath_width = ret.bead_widths[bead_count - (max_bead_count / 2 - 1)];
    ret.toolpath_locations.insert(ret.toolpath_locations.begin() + bead_count - (max_bead_count / 2 - 1), innermost_toolpath_location - innermost_toolpath_width / 2);
    ret.bead_widths.insert(ret.bead_widths.begin() + bead_count - (max_bead_count / 2 - 1), 0);

    return ret;
}

coord_t LimitedBeadingStrategy::getOptimalThickness(coord_t bead_count) const
{
    if (bead_count <= max_bead_count)
    {
        return parent->getOptimalThickness(bead_count);
    }
    return 10000000; // 10 meter
}

coord_t LimitedBeadingStrategy::getTransitionThickness(coord_t lower_bead_count) const
{
    if (lower_bead_count < max_bead_count)
    {
        return parent->getTransitionThickness(lower_bead_count);
    }
    if (lower_bead_count == max_bead_count)
    {
        return parent->getOptimalThickness(lower_bead_count + 1) - 10;
    }
    return 9000000; // 9 meter
}

coord_t LimitedBeadingStrategy::getOptimalBeadCount(coord_t thickness) const
{
    coord_t parent_bead_count = parent->getOptimalBeadCount(thickness);
    if (parent_bead_count <= max_bead_count)
    {
        return parent->getOptimalBeadCount(thickness);
    }
    else if (parent_bead_count == max_bead_count + 1)
    {
        if (thickness < parent->getOptimalThickness(max_bead_count + 1) - 10)
            return max_bead_count;
        else
            return max_bead_count + 1;
    }
    else return max_bead_count + 1;
}

} // namespace cura
<commit_msg>Workaround: add a 0-width wall in locations where there are maximum walls<commit_after>//Copyright (c) 2020 Ultimaker B.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#include <cassert>

#include "LimitedBeadingStrategy.h"

namespace cura
{

LimitedBeadingStrategy::Beading LimitedBeadingStrategy::compute(coord_t thickness, coord_t bead_count) const
{
    if (bead_count <= max_bead_count)
    {
        Beading ret = parent->compute(thickness, bead_count);

        if (bead_count % 2 == 0 && bead_count == max_bead_count)
        {
            const coord_t innermost_toolpath_location = ret.toolpath_locations[max_bead_count / 2 - 1];
            const coord_t innermost_toolpath_width = ret.bead_widths[max_bead_count / 2 - 1];
            ret.toolpath_locations.insert(ret.toolpath_locations.begin() + max_bead_count / 2, innermost_toolpath_location + innermost_toolpath_width / 2);
            ret.bead_widths.insert(ret.bead_widths.begin() + max_bead_count / 2, 0);
        }
        return ret;
    }
    assert(bead_count == max_bead_count + 1);

    coord_t optimal_thickness = parent->getOptimalThickness(max_bead_count);
    Beading ret = parent->compute(optimal_thickness, max_bead_count);
    ret.left_over += thickness - ret.total_thickness;
    ret.total_thickness = thickness;

    // Enforce symmetry
    if (bead_count % 2 == 1)
    {
        ret.toolpath_locations[bead_count / 2] = thickness / 2;
        ret.bead_widths[bead_count / 2] = thickness - optimal_thickness;
    }
    for (coord_t bead_idx = 0; bead_idx < (bead_count + 1) / 2; bead_idx++)
    {
        ret.toolpath_locations[bead_count - 1 - bead_idx] = thickness - ret.toolpath_locations[bead_idx];
    }

    //Create a "fake" inner wall with 0 width to indicate the edge of the walled area.
    //This wall can then be used by other structures to e.g. fill the infill area adjacent to the variable-width walls.
    coord_t innermost_toolpath_location = ret.toolpath_locations[max_bead_count / 2 - 1];
    coord_t innermost_toolpath_width = ret.bead_widths[max_bead_count / 2 - 1];
    ret.toolpath_locations.insert(ret.toolpath_locations.begin() + max_bead_count / 2, innermost_toolpath_location + innermost_toolpath_width / 2);
    ret.bead_widths.insert(ret.bead_widths.begin() + max_bead_count / 2, 0);

    //Symmetry on both sides. Symmetry is guaranteed since this code is stopped early if the bead_count <= max_bead_count, and never reaches this point then.
    innermost_toolpath_location = ret.toolpath_locations[bead_count - (max_bead_count / 2 - 1)];
    innermost_toolpath_width = ret.bead_widths[bead_count - (max_bead_count / 2 - 1)];
    ret.toolpath_locations.insert(ret.toolpath_locations.begin() + bead_count - (max_bead_count / 2 - 1), innermost_toolpath_location - innermost_toolpath_width / 2);
    ret.bead_widths.insert(ret.bead_widths.begin() + bead_count - (max_bead_count / 2 - 1), 0);

    return ret;
}

coord_t LimitedBeadingStrategy::getOptimalThickness(coord_t bead_count) const
{
    if (bead_count <= max_bead_count)
    {
        return parent->getOptimalThickness(bead_count);
    }
    return 10000000; // 10 meter
}

coord_t LimitedBeadingStrategy::getTransitionThickness(coord_t lower_bead_count) const
{
    if (lower_bead_count < max_bead_count)
    {
        return parent->getTransitionThickness(lower_bead_count);
    }
    if (lower_bead_count == max_bead_count)
    {
        return parent->getOptimalThickness(lower_bead_count + 1) - 10;
    }
    return 9000000; // 9 meter
}

coord_t LimitedBeadingStrategy::getOptimalBeadCount(coord_t thickness) const
{
    coord_t parent_bead_count = parent->getOptimalBeadCount(thickness);
    if (parent_bead_count <= max_bead_count)
    {
        return parent->getOptimalBeadCount(thickness);
    }
    else if (parent_bead_count == max_bead_count + 1)
    {
        if (thickness < parent->getOptimalThickness(max_bead_count + 1) - 10)
            return max_bead_count;
        else
            return max_bead_count + 1;
    }
    else return max_bead_count + 1;
}

} // namespace cura
<|endoftext|>


<commit_before>
#include "coring.hpp"

#include "logger.hpp"
#include "tools.hpp"

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

#include <boost/program_options.hpp>
#include <omp.h>

WTDMap
compute_wtd(std::list<std::size_t> streaks) {
  WTDMap wtd;
  if (streaks.size() > 0) {
    streaks.sort(std::greater<std::size_t>());
    std::size_t max_streak = streaks.front();
    for (std::size_t i=0; i <= max_streak; ++i) {
      float n_steps = 0.0f;
      for (auto s: streaks) {
        if (i > s) {
          break;
        }
        n_steps += 1.0f;
      }
      wtd[i] = n_steps / ((float) streaks.size());
    }
  }
  return wtd;
}

int main(int argc, char* argv[]) {
  using namespace Clustering::Tools;
  namespace b_po = boost::program_options;
  b_po::variables_map args;
  b_po::options_description desc (std::string(argv[0]).append(
    "\n\n"
    "compute boundary corrections for clustering results."
    "\n"
    "options"));
  desc.add_options()
    ("help,h", b_po::bool_switch()->default_value(false),
        "show this help.")
    // optional
    ("states,s", b_po::value<std::string>()->required(),
        "(required): file with state information (i.e. clustered trajectory")
    ("windows,w", b_po::value<std::string>()->required(),
        "(required): file with window sizes."
        "format is space-separated lines of\n\n"
        "STATE_ID WINDOW_SIZE\n\n"
        "use * as STATE_ID to match all (other) states.\n"
        "e.g.:\n\n"
        "* 20\n"
        "3 40\n"
        "4 60\n\n"
        "matches 40 frames to state 3, 60 frames to state 4 and 20 frames to all the other states")
    ("output,o", b_po::value<std::string>(),
        "(optional): cored trajectory")
    ("distribution,d", b_po::value<std::string>(),
        "(optional): write waiting time distributions to file.")
    ("cores,c", b_po::value<std::string>(),
        "(optional): write core information to file, i.e. trajectory with state name if in core region or -1 if not in core region")
    // defaults
    ("verbose,v", b_po::bool_switch()->default_value(false),
        "verbose mode: print runtime information to STDOUT.")
  ;
  // parse cmd arguments
  try {
    b_po::store(b_po::command_line_parser(argc, argv).options(desc).run(), args);
    b_po::notify(args);
  } catch (b_po::error& e) {
    if ( ! args["help"].as<bool>()) {
      std::cerr << "\n" << e.what() << "\n\n" << std::endl;
    }
    std::cerr << desc << std::endl;
    return EXIT_FAILURE;
  }
  if (args["help"].as<bool>()) {
    std::cout << desc << std::endl;
    return EXIT_SUCCESS;
  }
  // setup general flags / options
  Clustering::verbose = args["verbose"].as<bool>();
  // load states
  std::vector<std::size_t> states = Clustering::Tools::read_clustered_trajectory(args["states"].as<std::string>());
  std::set<std::size_t> state_names(states.begin(), states.end());
  std::size_t n_frames = states.size();
  if (args.count("output") || args.count("distribution") || args.count("cores")) {
    // load window size information
    std::map<std::size_t, std::size_t> coring_windows;
    {
      std::ifstream ifs(args["windows"].as<std::string>());
      std::string buf1, buf2;
      std::size_t size_for_all = 1;
      while (ifs.good()) {
        ifs >> buf1;
        ifs >> buf2;
        if (ifs.good()) {
          if (buf1 == "*") {
            size_for_all = string_to_num<std::size_t>(buf2);
          } else {
            coring_windows[string_to_num<std::size_t>(buf1)] = string_to_num<std::size_t>(buf2);
          }
        }
      }
      // fill remaining, not explicitly defined states with common window size
      for (std::size_t name: state_names) {
        if ( ! coring_windows.count(name)){
          coring_windows[name] = size_for_all;
        }
      }
    }
    // core trajectory
    std::vector<std::size_t> cored_traj(n_frames);
    std::size_t current_core = states[0];
    std::vector<long> cores(n_frames);
    for (std::size_t i=0; i < states.size(); ++i) {
      std::size_t w = coring_windows[states[i]];
      bool is_in_core = true;
      for (std::size_t j=i+1; j < i+w; ++j) {
        if (states[j] != states[i]) {
          is_in_core = false;
          break;
        }
      }
      if (is_in_core) {
        current_core = states[i];
        cores[i] = current_core;
      } else {
        cores[i] = -1;
      }
      cored_traj[i] = current_core;
    }
    // write cored trajectory to file
    if (args.count("output")) {
      Clustering::Tools::write_clustered_trajectory(args["output"].as<std::string>(), cored_traj);
    }
    // write core information to file
    if (args.count("cores")) {
      Clustering::Tools::write_single_column<long>(args["cores"].as<std::string>(), cores, false);
    }
    // compute/save escape time distributions
    if (args.count("distribution")) {
      std::map<std::size_t, std::list<std::size_t>> streaks;
      std::size_t current_state = cored_traj[0];
      long n_counts = 0;
      for (std::size_t state: cored_traj) {
        if (state == current_state) {
          ++n_counts;
        } else {
          streaks[current_state].push_back(n_counts);
          current_state = state;
          n_counts = 1;
        }
      }
      streaks[current_state].push_back(n_counts);

      std::map<std::size_t, WTDMap> etds;
      for (std::size_t state: state_names) {
        etds[state] = compute_wtd(streaks[state]);
      }
      // write WTDs to file
      for (auto state_etd: etds) {
        std::string fname = Clustering::Tools::stringprintf(args["distribution"].as<std::string>() + "_%d", state_etd.first);
        Clustering::Tools::write_map<std::size_t, float>(fname, state_etd.second);
      }
    }
  } else {
    std::cerr << "\n" << "nothing to do! please define '--output', '--distribution' or both!" << "\n\n";
    std::cerr << desc << std::endl;
  }
  return EXIT_SUCCESS;
}

<commit_msg>support concatenated trajectories in coring (unfinished)<commit_after>
#include "coring.hpp"

#include "logger.hpp"
#include "tools.hpp"

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

#include <boost/program_options.hpp>
#include <omp.h>

WTDMap
compute_wtd(std::list<std::size_t> streaks) {
  WTDMap wtd;
  if (streaks.size() > 0) {
    streaks.sort(std::greater<std::size_t>());
    std::size_t max_streak = streaks.front();
    for (std::size_t i=0; i <= max_streak; ++i) {
      float n_steps = 0.0f;
      for (auto s: streaks) {
        if (i > s) {
          break;
        }
        n_steps += 1.0f;
      }
      wtd[i] = n_steps / ((float) streaks.size());
    }
  }
  return wtd;
}

int main(int argc, char* argv[]) {
  using namespace Clustering::Tools;
  namespace b_po = boost::program_options;
  b_po::variables_map args;
  b_po::options_description desc (std::string(argv[0]).append(
    "\n\n"
    "compute boundary corrections for clustering results."
    "\n"
    "options"));
  desc.add_options()
    ("help,h", b_po::bool_switch()->default_value(false),
        "show this help.")
    // optional
    ("states,s", b_po::value<std::string>()->required(),
        "(required): file with state information (i.e. clustered trajectory")
    ("windows,w", b_po::value<std::string>()->required(),
        "(required): file with window sizes."
        "format is space-separated lines of\n\n"
        "STATE_ID WINDOW_SIZE\n\n"
        "use * as STATE_ID to match all (other) states.\n"
        "e.g.:\n\n"
        "* 20\n"
        "3 40\n"
        "4 60\n\n"
        "matches 40 frames to state 3, 60 frames to state 4 and 20 frames to all the other states")
    ("output,o", b_po::value<std::string>(),
        "(optional): cored trajectory")
    ("distribution,d", b_po::value<std::string>(),
        "(optional): write waiting time distributions to file.")
    ("cores,c", b_po::value<std::string>(),
        "(optional): write core information to file, i.e. trajectory with state name if in core region or -1 if not in core region")
    ("concat-nframes", b_po::value<std::size_t>(),
      "input (optional parameter): no. of frames per (equally sized) sub-trajectory for concatenated trajectory files.")
    ("concat-limits", b_po::value<std::string>(),
      "input (optional, file): file with frame ids (base 0) of first frames per (not equally sized) sub-trajectory for concatenated trajectory files.")
    // defaults
    ("verbose,v", b_po::bool_switch()->default_value(false),
        "verbose mode: print runtime information to STDOUT.")
  ;
  // parse cmd arguments
  try {
    b_po::store(b_po::command_line_parser(argc, argv).options(desc).run(), args);
    b_po::notify(args);
  } catch (b_po::error& e) {
    if ( ! args["help"].as<bool>()) {
      std::cerr << "\n" << e.what() << "\n\n" << std::endl;
    }
    std::cerr << desc << std::endl;
    return EXIT_FAILURE;
  }
  if (args["help"].as<bool>()) {
    std::cout << desc << std::endl;
    return EXIT_SUCCESS;
  }
  // setup general flags / options
  Clustering::verbose = args["verbose"].as<bool>();
  // load states
  std::vector<std::size_t> states = Clustering::Tools::read_clustered_trajectory(args["states"].as<std::string>());
  std::set<std::size_t> state_names(states.begin(), states.end());
  std::size_t n_frames = states.size();
  if (args.count("output") || args.count("distribution") || args.count("cores")) {
    // load concatenation limits to treat concatenated trajectories correctly
    // when performing dynamical corrections
    std::vector<std::size_t> concat_limits;
    if (args.count("concat-limits")) {
      concat_limits = Clustering::Tools::read_single_column<std::size_t>(args["concat-limits"].as<std::string>());
    } else if (args.count("concat-nframes")) {
      std::size_t n_frames_per_subtraj = args["concat-nframes"].as<std::size_t>();
      for (std::size_t i=n_frames_per_subtraj; i < traj.size(); i += n_frames_per_subtraj) {
        concat_limits.push_back(i);
      }
    }

//TODO use concat limits

    // load window size information
    std::map<std::size_t, std::size_t> coring_windows;
    {
      std::ifstream ifs(args["windows"].as<std::string>());
      std::string buf1, buf2;
      std::size_t size_for_all = 1;
      while (ifs.good()) {
        ifs >> buf1;
        ifs >> buf2;
        if (ifs.good()) {
          if (buf1 == "*") {
            size_for_all = string_to_num<std::size_t>(buf2);
          } else {
            coring_windows[string_to_num<std::size_t>(buf1)] = string_to_num<std::size_t>(buf2);
          }
        }
      }
      // fill remaining, not explicitly defined states with common window size
      for (std::size_t name: state_names) {
        if ( ! coring_windows.count(name)){
          coring_windows[name] = size_for_all;
        }
      }
    }
    // core trajectory
    std::vector<std::size_t> cored_traj(n_frames);
    std::size_t current_core = states[0];
    std::vector<long> cores(n_frames);
    for (std::size_t i=0; i < states.size(); ++i) {
      std::size_t w = coring_windows[states[i]];
      bool is_in_core = true;
      for (std::size_t j=i+1; j < i+w; ++j) {
        if (states[j] != states[i]) {
          is_in_core = false;
          break;
        }
      }
      if (is_in_core) {
        current_core = states[i];
        cores[i] = current_core;
      } else {
        cores[i] = -1;
      }
      cored_traj[i] = current_core;
    }
    // write cored trajectory to file
    if (args.count("output")) {
      Clustering::Tools::write_clustered_trajectory(args["output"].as<std::string>(), cored_traj);
    }
    // write core information to file
    if (args.count("cores")) {
      Clustering::Tools::write_single_column<long>(args["cores"].as<std::string>(), cores, false);
    }
    // compute/save escape time distributions
    if (args.count("distribution")) {
      std::map<std::size_t, std::list<std::size_t>> streaks;
      std::size_t current_state = cored_traj[0];
      long n_counts = 0;
      for (std::size_t state: cored_traj) {
        if (state == current_state) {
          ++n_counts;
        } else {
          streaks[current_state].push_back(n_counts);
          current_state = state;
          n_counts = 1;
        }
      }
      streaks[current_state].push_back(n_counts);

      std::map<std::size_t, WTDMap> etds;
      for (std::size_t state: state_names) {
        etds[state] = compute_wtd(streaks[state]);
      }
      // write WTDs to file
      for (auto state_etd: etds) {
        std::string fname = Clustering::Tools::stringprintf(args["distribution"].as<std::string>() + "_%d", state_etd.first);
        Clustering::Tools::write_map<std::size_t, float>(fname, state_etd.second);
      }
    }
  } else {
    std::cerr << "\n" << "nothing to do! please define '--output', '--distribution' or both!" << "\n\n";
    std::cerr << desc << std::endl;
  }
  return EXIT_SUCCESS;
}

<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3297
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3297 to 3298<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3298
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3222
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3222 to 3223<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3223
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3482
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3482 to 3483<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3483
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3418
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3418 to 3419<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3419
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3464
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3464 to 3465<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3465
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3420
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3420 to 3421<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3421
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3221
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3221 to 3222<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3222
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/**
 * capture.cpp
 *
 * @date Nov 4, 2015
 * @author Ryan Peach
 * @version v0.1
 */

#include "capture.hpp"
#define TEST

void Capture::Frame(Mat img) {
	frame = &img;
	edges = NULL;
	polys = NULL;
	fps = NULL;
	rects = NULL;
}

Mat* Capture::getEdges() {

	if (edges == NULL) {
		auto out = edgesCanny(*frame, etol1, etol2, eSize);
		edges = &out;
	}

#ifdef TEST
	if (edges != NULL) {imshow("Canny",*edges);}
#endif

	return edges;
}

Cnts* Capture::getPolys() {
	if (polys == NULL && getEdges() != NULL) {
		auto out = findPolys(*getEdges(), polyTol);
		polys = &out;
	}
	return polys;
}

Fps* Capture::getFps() {

	if (fps == NULL && getPolys() != NULL) {
		auto out = findFocusPoints(*getPolys(), angleTol, distTol);
		fps = &out;
	}

#ifdef TEST
    cout << "Fp's Found: " << (*fps).size() << endl;
#endif

	return fps;
}

void Capture::set(cnt corners) {
	Points cent = corners;
	Point r = calcRef(corners); ref = &r;
	cnt b = sortCorners(cent,*getRef()); border = &b;
}

void Capture::set(Fps corners) {
	Points cent = centroids(corners);
	Point r = centroid(calcRef(corners)); ref = &r;
	cnt b = sortCorners(cent,*getRef()); border = &b;
}

Point* Capture::getRef() {
	if (ref == NULL) {
		getBorder();
	}
	return ref;
}

vector<cnt>* Capture::getRects() {
	if (rects == NULL) {
		vector<cnt> r = hasRectangles((*getPolys()).contours, angleTol, distTol);
		rects = &r;
	}
	return rects;
}

cnt* Capture::getBorder() {
	switch(sel) {
	case fpcorners: {
		if (border == NULL && getFps() != NULL) {
			vector<Fp> corners = calcCorners(*getFps(), angleTol, distTol);
			if (corners.size() == 4) {
				set(corners);
			}
		}} break;

	case strongborder: {
		vector<cnt> check;
		for (cnt r : (*getRects())) {
		    if (validRect(r)) {check.push_back(r);};
		}
	    vector<cnt> similar = findSimilar(check, distTol);
	    if (!similar.empty()) {
			cnt corners = largest(similar);
			set(corners);
	    }} break;

	case regular: {
		vector<cnt> valid;
		for (cnt r : (*getRects())) {
			if (validRect(r)) {valid.push_back(r);}
		}
		if (!valid.empty()) {
			cnt corners = largest(valid);
			set(corners);
		}} break;

	case automatic: {
		sel = fpcorners;
		if (getBorder() == NULL) {sel = strongborder;}
		if (getBorder() == NULL) {sel = regular;}
		getBorder();
		sel = automatic;
	} break;
	}
	return border;
}

// Uses polyTol, angleTol, distTol, wSize, C;
vector<Mat*> Capture::process() {
#ifdef TEST
    cout << "Running Capture::process..." << endl;
#endif
    // Variable Declaration
    Mat warp, drawing;
    vector<Mat*> out;

    if (getBorder() != NULL && getRef() != NULL) {
		// Get border from focus points and warp
		warp = fixPerspective(*frame, *getBorder(), *getRef());

		warp = toColor(warp);

		Scalar color = Scalar(255, 0, 0);
		drawing = warp;

		drawContours(drawing, *getBorder(), 0, color, 3, 8);
		out = vector<Mat*>{&drawing, &warp};
		return out;
    } else {
    	out = vector<Mat*>{frame,NULL};
    	return out;
    }
}

bool Capture::validRect(cnt r) {
    return contourArea(r) >= sizeRatio*(*frame).cols*(*frame).rows
            && isAspectRatio(r, aspectRatio, ratioTol)
    		&& ((*fps).size()==0 || allInside(r, *fps));
}
<commit_msg>Added capture.cpp method running print statements.<commit_after>/**
 * capture.cpp
 *
 * @date Nov 4, 2015
 * @author Ryan Peach
 * @version v0.1
 */

#include "capture.hpp"
#define TEST

void Capture::Frame(Mat img) {
#ifdef TEST
	cout << "Running Capture::Frame..." << endl;
#endif
	frame = &img;
	edges = NULL;
	polys = NULL;
	fps = NULL;
	rects = NULL;
}

Mat* Capture::getEdges() {
#ifdef TEST
	cout << "Running Capture::getEdges..." << endl;
#endif
	if (edges == NULL) {
		auto out = edgesCanny(*frame, etol1, etol2, eSize);
		edges = &out;
	}

#ifdef TEST
	if (edges != NULL) {imshow("Canny",*edges);}
#endif

	return edges;
}

Cnts* Capture::getPolys() {
#ifdef TEST
	cout << "Running Capture::getPolys..." << endl;
#endif
	if (polys == NULL && getEdges() != NULL) {
		auto out = findPolys(*getEdges(), polyTol);
		polys = &out;
	}
	return polys;
}

Fps* Capture::getFps() {
#ifdef TEST
	cout << "Running Capture::getFps..." << endl;
#endif
	if (fps == NULL && getPolys() != NULL) {
		auto out = findFocusPoints(*getPolys(), angleTol, distTol);
		fps = &out;
	}

#ifdef TEST
	cout << "Fp's Found: " << (*fps).size() << endl;
#endif

	return fps;
}

void Capture::set(cnt corners) {
#ifdef TEST
	cout << "Running Capture::set(cnt)..." << endl;
#endif
	Points cent = corners;
	Point r = calcRef(corners); ref = &r;
	cnt b = sortCorners(cent,*getRef()); border = &b;
}

void Capture::set(Fps corners) {
#ifdef TEST
	cout << "Running Capture::set(Fps)..." << endl;
#endif
	Points cent = centroids(corners);
	Point r = centroid(calcRef(corners)); ref = &r;
	cnt b = sortCorners(cent,*getRef()); border = &b;
}

Point* Capture::getRef() {
#ifdef TEST
	cout << "Running Capture::getRef..." << endl;
#endif
	if (ref == NULL) {
		getBorder();
	}
	return ref;
}

vector<cnt>* Capture::getRects() {
#ifdef TEST
	cout << "Running Capture::getRects..." << endl;
#endif
	if (rects == NULL) {
		vector<cnt> r = hasRectangles((*getPolys()).contours, angleTol, distTol);
		rects = &r;
	}
	return rects;
}

cnt* Capture::getBorder() {
#ifdef TEST
	cout << "Running Capture::getBorder..." << endl;
#endif
	switch(sel) {
	case fpcorners: {
#ifdef TEST
		cout << "Capture::getBorder: fpcorners..." << endl;
#endif
		if (border == NULL && getFps() != NULL) {
			vector<Fp> corners = calcCorners(*getFps(), angleTol, distTol);
			if (corners.size() == 4) {
				set(corners);
			}
		}} break;

	case strongborder: {
#ifdef TEST
		cout << "Capture::getBorder: strongborder..." << endl;
#endif
		vector<cnt> check;
		for (cnt r : (*getRects())) {
			if (validRect(r)) {check.push_back(r);}
		}
		vector<cnt> similar = findSimilar(check, distTol);
		if (!similar.empty()) {
			cnt corners = largest(similar);
			set(corners);
		}} break;

	case regular: {
#ifdef TEST
		cout << "Capture::getBorder: regular..." << endl;
#endif
		vector<cnt> valid;
		for (cnt r : (*getRects())) {
			if (validRect(r)) {valid.push_back(r);}
		}
		if (!valid.empty()) {
			cnt corners = largest(valid);
			set(corners);
		}} break;

	case automatic: {
#ifdef TEST
		cout << "Capture::getBorder: automatic..." << endl;
#endif
		sel = fpcorners;
		if (getBorder() == NULL) {sel = strongborder;}
		if (getBorder() == NULL) {sel = regular;}
		getBorder();
		sel = automatic;
	} break;
	}
	return border;
}

// Uses polyTol, angleTol, distTol, wSize, C;
vector<Mat*> Capture::process() {
#ifdef TEST
	cout << "Running Capture::process..." << endl;
#endif
	// Variable Declaration
	Mat warp, drawing;
	vector<Mat*> out;

	if (getBorder() != NULL && getRef() != NULL) {
		// Get border from focus points and warp
		warp = fixPerspective(*frame, *getBorder(), *getRef());

		warp = toColor(warp);

		Scalar color = Scalar(255, 0, 0);
		drawing = warp;

		drawContours(drawing, *getBorder(), 0, color, 3, 8);
		out = vector<Mat*>{&drawing, &warp};
		return out;
	} else {
		out = vector<Mat*>{frame,NULL};
		return out;
	}
}

bool Capture::validRect(cnt r) {
#ifdef TEST
	cout << "Capture::getBorder: validRect... " << endl;
#endif
	bool out = sizeRatio*(*frame).cols*(*frame).rows
			&& isAspectRatio(r, aspectRatio, ratioTol)
			&& ((*fps).size()==0 || allInside(r, *fps));
#ifdef TEST
	cout << "Capture::getBorder: validRect = " << out << endl;
#endif
	return out;
}
<|endoftext|>


<commit_before>#include <iostream>
using namespace std;

int divide(int dividend, int divisor);

int main()
{
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    cout << divide(2147483647,2) << endl;
    return 0;
}

int divide(int dividend, int divisor) {
    int symbol = 1;
    long n1 = dividend, n2 = divisor;
    if(n1 < 0) {symbol = symbol * -1; n1 = n1 * -1;}
    if(n2  < 0) {symbol = symbol * -1; n2 = n2 * -1;}

    int res = 0, count = 0;
    while(true){
        if(n2 == 1) return n1*symbol;
        if(n1 < n2) return res*symbol;
        else if(n1 == n2) return (res + 1)*symbol;
        else{
            while(n1 > n2){
                n2 = n2 << 1;
                if(count == 0) count = 1;
                else count = count << 1;
            }
            n1 = n1 - (n2 >> 1);
            n2 = divisor;
            res += count;
            count = 0;
        }
    }
}
<commit_msg>TLE was solved by a new algorithm<commit_after>class Solution {
    public:
        int divide(int dividend, int divisor) {
            int sign = 1;
            if((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0)) sign = -1;
            unsigned int a = dividend > 0 ? dividend : dividend * (-1);
            unsigned int b = divisor  > 0 ? divisor  : divisor  * (-1);
            unsigned int d = b, i = 0, res = 0;
            unsigned int nums[32];
            while(d <= a && d > 0){
                nums[i++] = d;
                d = d << 1;
            }
            i --;
            while(a >= b){
                if(a >= nums[i]){
                    a = a - nums[i];
                    res += (1 << i);
                }
                i--;
            }
            return res*sign;
        }
};

<|endoftext|>