otbStreamingGraphToImageFilter.h 3.04 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
/*
 * otbStreamingGraphToImageFilter.h
 *
 *  Created on: 6 nov. 2017
 *      Author: cresson
 */

#ifndef MODULES_REMOTE_LSGRM_INCLUDE_OTBSTREAMINGGRAPHTOIMAGEFILTER_H_
#define MODULES_REMOTE_LSGRM_INCLUDE_OTBSTREAMINGGRAPHTOIMAGEFILTER_H_

#include "itkImageSource.h"
#include "itkExceptionObject.h"
#include "itkImageRegion.h"
#include "itkGrayscaleFillholeImageFilter.h"

#include "grmGraphOperations.h"

// Boost R-Tree
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>

#include <boost/geometry/index/rtree.hpp>

// to store queries results
#include <vector>

// just for output
#include <iostream>
#include <boost/foreach.hpp>

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

namespace lsgrm
{

template <class TGraph, class TLabelImage>
class ITK_EXPORT StreamingGraphToImageFilter : public itk::ImageSource<TLabelImage>
{
public:
  /** Standard class typedefs. */
  typedef StreamingGraphToImageFilter                   Self;
  typedef itk::ImageSource<TLabelImage>                 Superclass;
  typedef itk::SmartPointer<Self>                       Pointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(StreamingGraphToImageFilter, ImageSource);

  /** Typedefs for processing */
  typedef typename TLabelImage::RegionType              RegionType;
  typedef typename TLabelImage::IndexType               IndexType;
  typedef typename TLabelImage::SizeType                SizeType;
57 58
  typedef typename TLabelImage::SpacingType             SpacingType;
  typedef typename TLabelImage::PointType               PointType;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  typedef typename TGraph::NodePointerType              NodePointerType;
  typedef itk::GrayscaleFillholeImageFilter<TLabelImage,TLabelImage> FillholeFilterType;
  typedef bg::model::point<float, 2, bg::cs::cartesian> point;
  typedef bg::model::box<point> box;
  typedef std::pair<box, unsigned> value;

  /** Set the input graph and build the R-Tree */
  void SetGraph(const TGraph graph);

  /** Prepare image allocation at the first call of the pipeline processing */
  virtual void GenerateOutputInformation(void);

  /** Does the real work. */
  virtual void GenerateData();

  itkSetMacro(OutputSize, SizeType);
75 76 77
  itkSetMacro(OutputOrigin, PointType);
  itkSetMacro(OutputSpacing, SpacingType);
  itkSetMacro(OutputProjectionRef, std::string);
78 79

protected:
80
  StreamingGraphToImageFilter(){};
81 82 83 84 85 86 87
  virtual ~StreamingGraphToImageFilter(){};

private:

  StreamingGraphToImageFilter(const Self &); //purposely not implemented
  void operator =(const Self&); //purposely not implemented

88
  TGraph       m_Graph;
89
  bgi::rtree< value, bgi::quadratic<16> > rtree;
90 91 92 93
  SizeType     m_OutputSize;
  SpacingType  m_OutputSpacing;
  PointType    m_OutputOrigin;
  std::string  m_OutputProjectionRef;
94 95 96 97 98 99 100 101 102
};

} /* namespace lsgrm */

#ifndef OTB_MANUAL_INSTANTIATION
#include <otbStreamingGraphToImageFilter.txx>
#endif

#endif /* MODULES_REMOTE_LSGRM_INCLUDE_OTBSTREAMINGGRAPHTOIMAGEFILTER_H_ */