AliceVision
Photogrammetric Computer Vision Framework
compositer.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2020 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <aliceVision/image/Image.hpp>
10 
11 #include "cachedImage.hpp"
12 #include "imageOps.hpp"
13 #include "seams.hpp"
14 
15 namespace aliceVision {
16 
18 {
19  public:
20  Compositer(int width, int height)
21  : _panoramaWidth(width),
22  _panoramaHeight(height)
23  {}
24 
25  virtual ~Compositer() {}
26 
27  virtual bool append(aliceVision::image::Image<image::RGBfColor>& color,
30  int offsetX,
31  int offsetY)
32  {
33  offsetX -= _outputRoi.left;
34  offsetY -= _outputRoi.top;
35 
36  for (int i = 0; i < color.height(); i++)
37  {
38  int y = i + offsetY;
39  if (y < 0 || y >= _outputRoi.height)
40  continue;
41 
42  for (int j = 0; j < color.width(); j++)
43  {
44  int x = j + offsetX;
45  if (x < 0 || x >= _outputRoi.width)
46  continue;
47 
48  if (!inputMask(i, j))
49  {
50  continue;
51  }
52 
53  _panorama(y, x).r() = color(i, j).r();
54  _panorama(y, x).g() = color(i, j).g();
55  _panorama(y, x).b() = color(i, j).b();
56  _panorama(y, x).a() = 1.0f;
57  }
58  }
59 
60  return true;
61  }
62 
63  virtual bool initialize(const BoundingBox& outputRoi)
64  {
65  _outputRoi = outputRoi;
66 
67  if (_outputRoi.left < 0)
68  return false;
69  if (_outputRoi.top < 0)
70  return false;
71  if (_outputRoi.getRight() >= _panoramaWidth)
72  return false;
73  if (_outputRoi.getBottom() >= _panoramaHeight)
74  return false;
75 
76  _panorama = image::Image<image::RGBAfColor>(_outputRoi.width, _outputRoi.height, true, image::RGBAfColor(0.0f, 0.0f, 0.0f, 0.0f));
77 
78  return true;
79  }
80 
81  virtual bool terminate() { return true; }
82 
83  image::Image<image::RGBAfColor>& getOutput() { return _panorama; }
84 
85  virtual int getBorderSize() const { return 0; }
86 
87  protected:
89  int _panoramaWidth;
90  int _panoramaHeight;
91  BoundingBox _outputRoi;
92 };
93 
94 } // namespace aliceVision
aliceVision::BoundingBox
Definition: boundingBox.hpp:17
aliceVision::image::Rgba
RGBA templated pixel type.
Definition: pixelTypes.hpp:179
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::image::Image
Definition: ImageDescriber_AKAZE_OCV.hpp:21
aliceVision::image::Image::width
int width() const
Retrieve the width of the image.
Definition: Image.hpp:110
aliceVision::image::Image::height
int height() const
Retrieve the height of the image.
Definition: Image.hpp:116
aliceVision::Compositer
Definition: compositer.hpp:17