34#ifndef VP_MB_SCANLINE_H
35#define VP_MB_SCANLINE_H
44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpCameraParameters.h>
46#include <visp3/core/vpColVector.h>
47#include <visp3/core/vpImage.h>
48#include <visp3/core/vpImageConvert.h>
49#include <visp3/core/vpImagePoint.h>
50#include <visp3/core/vpPoint.h>
54#if defined(DEBUG_DISP)
55#include <visp3/core/vpDisplay.h>
58#ifndef DOXYGEN_SHOULD_SKIP_THIS
78class VISP_EXPORT vpMbScanLine
83 typedef enum { START = 1, END = 0, POINT = 2 } vpMbScanLineType;
87 typedef std::pair<vpColVector, vpColVector> vpMbScanLineEdge;
90 struct vpMbScanLineSegment
92 vpMbScanLineSegment() :
type(START), edge(),
p(0), P1(0), P2(0), Z1(0), Z2(0), ID(0), b_sample_Y(false) { }
93 vpMbScanLineType
type;
94 vpMbScanLineEdge edge;
104 struct vpMbScanLineEdgeComparator
106 inline bool operator()(
const vpMbScanLineEdge &l0,
const vpMbScanLineEdge &l1)
const
108 for (
unsigned int i = 0;
i < 3; ++
i)
109 if (l0.first[i] < l1.first[i])
111 else if (l0.first[i] > l1.first[i])
113 for (
unsigned int i = 0;
i < 3; ++
i)
114 if (l0.second[i] < l1.second[i])
116 else if (l0.second[i] > l1.second[i])
123 struct vpMbScanLineSegmentComparator
125 inline bool operator()(
const vpMbScanLineSegment &a,
const vpMbScanLineSegment &b)
const
128 return (std::fabs(a.p - b.p) <= std::numeric_limits<double>::epsilon()) ? a.type < b.type : a.p < b.p;
131 inline bool operator()(
const std::pair<double, vpMbScanLineSegment> &a,
132 const std::pair<double, vpMbScanLineSegment> &b)
const
134 return a.first < b.first;
140 vpCameraParameters
K;
141 unsigned int maskBorder;
142 vpImage<unsigned char> mask;
143 vpImage<int> primitive_ids;
144 std::map<vpMbScanLineEdge, std::set<int>, vpMbScanLineEdgeComparator> visibility_samples;
145 double depthTreshold;
148#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(DEBUG_DISP)
149 vpDisplay *dispMaskDebug;
150 vpDisplay *dispLineDebug;
151 vpImage<unsigned char> linedebugImg;
155 vpMbScanLine(
const vpMbScanLine &scanline);
156 virtual ~vpMbScanLine();
157 vpMbScanLine &operator=(
const vpMbScanLine &scanline);
159 void drawScene(
const std::vector<std::vector<std::pair<vpPoint, unsigned int> > *> &polygons,
160 std::vector<int> listPolyIndices,
const vpCameraParameters &K,
unsigned int w,
unsigned int h);
169 double getDepthTreshold() {
return depthTreshold; }
170 unsigned int getMaskBorder() {
return maskBorder; }
171 const vpImage<unsigned char> &getMask()
const {
return mask; }
172 const vpImage<int> &getPrimitiveIDs()
const {
return primitive_ids; }
174 void queryLineVisibility(
const vpPoint &a,
const vpPoint &b, std::vector<std::pair<vpPoint, vpPoint> > &lines,
175 const bool &displayResults =
false);
184 void setDepthTreshold(
const double &treshold) { depthTreshold = treshold; }
185 void setMaskBorder(
const unsigned int &mb) { maskBorder = mb; }
188 void createScanLinesFromLocals(std::vector<std::vector<vpMbScanLineSegment> > &scanlines,
189 std::vector<std::vector<vpMbScanLineSegment> > &localScanlines,
190 const unsigned int &size);
192 void drawLineY(
const vpColVector &a,
const vpColVector &b,
const vpMbScanLineEdge &line_ID,
const int ID,
193 std::vector<std::vector<vpMbScanLineSegment> > &scanlines);
195 void drawLineX(
const vpColVector &a,
const vpColVector &b,
const vpMbScanLineEdge &line_ID,
const int ID,
196 std::vector<std::vector<vpMbScanLineSegment> > &scanlines);
198 void drawPolygonY(
const std::vector<std::pair<vpPoint, unsigned int> > &polygon,
const int ID,
199 std::vector<std::vector<vpMbScanLineSegment> > &scanlines);
201 void drawPolygonX(
const std::vector<std::pair<vpPoint, unsigned int> > &polygon,
const int ID,
202 std::vector<std::vector<vpMbScanLineSegment> > &scanlines);
205 static vpMbScanLineEdge makeMbScanLineEdge(
const vpPoint &a,
const vpPoint &b);
206 static void createVectorFromPoint(
const vpPoint &p, vpColVector &v,
const vpCameraParameters &K);
207 static double getAlpha(
double x,
double X0,
double Z0,
double X1,
double Z1);
208 static double mix(
double a,
double b,
double alpha);
209 static vpPoint mix(
const vpPoint &a,
const vpPoint &b,
double alpha);
210 static double norm(
const vpPoint &a,
const vpPoint &b);