controllerTest.cpp 4.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#include "gpu/testing.hpp"
#include "libvideostitch/controller.hpp"
#include "libvideostitch/panoDef.hpp"
#include "libvideostitch/ptv.hpp"
#include "libvideostitch/status.hpp"
#include <parallax/noFlow.hpp>
#include <parallax/noWarper.hpp>
#include "libvideostitch/parse.hpp"
#include "libvideostitch/output.hpp"
#include "common/fakeReader.hpp"
#include "common/fakeMerger.hpp"
#include "common/fakeWriter.hpp"

#include "libvideostitch/controller.hpp"
#include "libvideostitch/panoDef.hpp"
#include "libvideostitch/ptv.hpp"
#include "libvideostitch/parse.hpp"
#include "libvideostitch/output.hpp"

#include <cassert>
#include <iostream>
#include <memory>

namespace VideoStitch {
namespace Testing {

Core::PanoDefinition* getTestPanoDef() {
  Potential<Ptv::Parser> parser(Ptv::Parser::create());
  if (!parser->parseData("{"
                         " \"width\": 513, "
                         " \"height\": 315, "
                         " \"hfov\": 90.0, "
                         " \"proj\": \"rectilinear\", "
                         " \"inputs\": [ "
                         "  { "
                         "   \"width\": 17, "
                         "   \"height\": 13, "
                         "   \"hfov\": 90.0, "
                         "   \"yaw\": 0.0, "
                         "   \"pitch\": 0.0, "
                         "   \"roll\": 0.0, "
                         "   \"proj\": \"rectilinear\", "
                         "   \"viewpoint_model\": \"ptgui\", "
                         "   \"response\": \"linear\", "
                         "   \"filename\": \"\" "
                         "  }, "
                         "  { "
                         "   \"width\": 17, "
                         "   \"height\": 13, "
                         "   \"hfov\": 90.0, "
                         "   \"yaw\": 0.0, "
                         "   \"pitch\": 0.0, "
                         "   \"roll\": 0.0, "
                         "   \"proj\": \"rectilinear\", "
                         "   \"viewpoint_model\": \"ptgui\", "
                         "   \"response\": \"linear\", "
                         "   \"filename\": \"\" "
                         "  } "
                         " ]"
                         "}")) {
    std::cerr << parser->getErrorMessage() << std::endl;
    ENSURE(false, "could not parse");
    return NULL;
  }
  std::unique_ptr<Core::PanoDefinition> panoDef(Core::PanoDefinition::create(parser->getRoot()));
  ENSURE((bool)panoDef);
  return panoDef.release();
}

void testNotInteractive() {
  std::unique_ptr<Core::PanoDefinition> panoDef(getTestPanoDef());
  std::unique_ptr<Core::AudioPipeDefinition> audioPipeDef(Core::AudioPipeDefinition::createDefault());

  FakeReaderFactory* fakeReaderFactory = new FakeReaderFactory(0);
  std::atomic<int> totalNumSetups(0);
  FakeImageMergerFactory factory1(Core::ImageMergerFactory::CoreVersion1, &totalNumSetups);
  FakeImageMergerFactory factory2(Core::ImageMergerFactory::CoreVersion1, &totalNumSetups);

  factory1.setHash("hash1");
  factory2.setHash("hash2");

  ENSURE_EQ(0, (int)totalNumSetups);
  Core::PotentialController controller = Core::createController(
      *panoDef, factory1, Core::NoWarper::Factory(), Core::NoFlow::Factory(), fakeReaderFactory, *audioPipeDef);
  ENSURE_EQ(0, (int)totalNumSetups);

  ENSURE(controller.status());

  // Resetting merger factory without stitchers
  ENSURE(controller->resetMergerFactory(factory1, false));
  ENSURE_EQ(0, (int)totalNumSetups);  // Same factory
  ENSURE(controller->resetMergerFactory(factory2, false));
  ENSURE_EQ(0, (int)totalNumSetups);  // Different factory, setup not forced.
  ENSURE(controller->resetMergerFactory(factory1, true));
  ENSURE_EQ(0, (int)totalNumSetups);  // Different factory, setup forced, but no stitchers.

  {
    ENSURE(controller->createStitcher());
    ENSURE_EQ((int)panoDef->numInputs(), (int)totalNumSetups);  // Initial setup.

    // Resetting merger factory with stitchers
    ENSURE(controller->resetMergerFactory(factory1, false));
    ENSURE_EQ((int)panoDef->numInputs(), (int)totalNumSetups);  // Same factory

    ENSURE(controller->resetMergerFactory(factory2, false));
    ENSURE_EQ((int)panoDef->numInputs(), (int)totalNumSetups);  // Different factory, setup not forced.

    ENSURE(controller->resetMergerFactory(factory1, true));
    ENSURE_EQ(2 * (int)panoDef->numInputs(), (int)totalNumSetups);  // Different factory, setup forced.
  }
}

}  // namespace Testing
}  // namespace VideoStitch

int main() {
  VideoStitch::Testing::initTest();
  VideoStitch::Testing::ENSURE(VideoStitch::GPU::setDefaultBackendDevice(0));
  VideoStitch::Testing::testNotInteractive();

  return 0;
}