Skip to content
Snippets Groups Projects
Commit 728a7172 authored by even's avatar even
Browse files

Install code

parent 691754a4
No related branches found
No related tags found
No related merge requests found
Showing
with 4594 additions and 0 deletions
#include "blurredsegmentproto.h"
BlurredSegmentProto::BlurredSegmentProto (int maxWidth, Pt2i pix)
{
this->maxWidth.set (maxWidth);
plist = new BiPtList (pix);
leftOK = false;
rightOK = false;
bsFlat = false;
bsOK = false;
convexhull = NULL;
chChanged = false;
dss = NULL;
}
BlurredSegmentProto::BlurredSegmentProto (int maxWidth, Pt2i center,
const vector<Pt2i> &leftPts, const vector<Pt2i> &rightPts)
{
this->maxWidth.set (maxWidth);
plist = new BiPtList (center);
leftOK = false;
rightOK = false;
bsFlat = false;
bsOK = false;
convexhull = NULL;
chChanged = false;
dss = NULL;
vector<Pt2i>::const_iterator itr = rightPts.begin ();
vector<Pt2i>::const_iterator itl = leftPts.begin ();
bool scanningRight = true;
bool scanningLeft = true;
while (scanningRight || scanningLeft)
{
if (scanningRight)
{
if (itr == rightPts.end ())
{
scanningRight = false;
rightOK = true;
}
else plist->addBack (*itr++);
}
if (scanningLeft)
{
if (itl == leftPts.end ()) scanningLeft = false;
else
{
plist->addFront (*itl++);
leftOK = true;
}
}
if (! bsOK && plist->size () > 2)
{
if (! plist->backPoint().colinearTo (plist->frontPoint (),
plist->initialPoint ()))
bsOK = true;
}
}
}
BlurredSegmentProto::~BlurredSegmentProto ()
{
if (convexhull != NULL) delete convexhull;
}
AbsRat BlurredSegmentProto::segmentRationalWidth () const
{
return (convexhull != NULL ? convexhull->rationalThickness ()
: AbsRat (0, 1));
}
DigitalStraightLine *BlurredSegmentProto::getLine () const
{
if (bsOK)
{
Pt2i s, e, v;
convexhull->antipodalEdgeAndVertex (s, e, v);
return (new DigitalStraightLine (s, e, v));
}
if (bsFlat) return (new DigitalStraightLine (getLastLeft (), getLastRight (),
DigitalStraightLine::DSL_THIN));
return (NULL);
}
bool BlurredSegmentProto::addLeft (Pt2i pix)
{
if (bsOK) // convexhull defined
{
bool res = addPoint (pix, true);
return (res);
}
else if (bsFlat) // leftOK && rightOK
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () != 0)
{
convexhull = new ConvexHull (pix, plist->frontPoint (),
plist->backPoint ());
bsOK = true;
}
plist->addFront (pix);
}
else if (leftOK) // thus ! rightOK
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () == 0) bsFlat = true;
else
{
convexhull = new ConvexHull (pix, plist->frontPoint (),
plist->backPoint ());
bsOK = true;
}
plist->addFront (pix);
}
else if (rightOK)
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () == 0) bsFlat = true;
else
{
convexhull = new ConvexHull (pix, plist->frontPoint (),
plist->backPoint ());
bsOK = true;
}
plist->addFront (pix);
}
else // only the central point is ok
{
plist->addFront (pix);
leftOK = true;
}
chChanged = true;
return true;
}
bool BlurredSegmentProto::addRight (Pt2i pix)
{
if (bsOK) // bs != NULL
{
bool res = addPoint (pix, false);
return (res);
}
else if (bsFlat) // leftOK && rightOK
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () != 0)
{
convexhull = new ConvexHull (plist->frontPoint (),
plist->backPoint (), pix);
bsOK = true;
}
plist->addBack (pix);
}
else if (rightOK) // thus ! leftOK
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () == 0) bsFlat = true;
else
{
convexhull = new ConvexHull (plist->frontPoint (),
plist->backPoint (), pix);
bsOK = true;
}
plist->addBack (pix);
}
else if (leftOK)
{
AbsRat height = plist->heightToEnds (pix);
if (height.greaterThan (maxWidth)) return false;
if (height.numerator () == 0) bsFlat = true;
else
{
convexhull = new ConvexHull (plist->frontPoint (),
plist->backPoint (), pix);
bsOK = true;
}
plist->addBack (pix);
}
else // only the central point is ok
{
plist->addBack (pix);
rightOK = true;
}
chChanged = true;
return true;
}
bool BlurredSegmentProto::addPoint (Pt2i p, bool onleft)
{
bool inserted = convexhull->addPointDS (p, onleft);
if ((segmentRationalWidth ()).greaterThan (maxWidth))
{
if (inserted) convexhull->restore ();
return false;
}
if (onleft) plist->addFront (p);
else plist->addBack (p);
chChanged = true;
return true;
}
void BlurredSegmentProto::removeLeft (int n)
{
if (bsOK) plist->removeFront (n);
}
void BlurredSegmentProto::removeRight (int n)
{
if (bsOK) plist->removeBack (n);
}
Vr2i BlurredSegmentProto::getSupportVector ()
{
if (bsOK)
{
Pt2i s, e, v;
convexhull->antipodalEdgeAndVertex (s, e, v);
return (s.vectorTo (e));
}
if (bsFlat || leftOK || rightOK)
return (getLastLeft().vectorTo (getLastRight ()));
return (Vr2i (1, 0)); // hardly better with only one point !
}
BlurredSegment *BlurredSegmentProto::endOfBirth ()
{
DigitalStraightSegment *seg = NULL;
if (bsOK)
{
int xmin, ymin, xmax, ymax;
plist->findExtrema (xmin, ymin, xmax, ymax);
Pt2i s, e, v;
convexhull->antipodalEdgeAndVertex (s, e, v);
seg = new DigitalStraightSegment (s, e, v, xmin, ymin, xmax, ymax);
}
else if (bsFlat || rightOK || leftOK)
{
Pt2i llast = plist->frontPoint ();
Pt2i rlast = plist->backPoint ();
int xmin = llast.x ();
if (rlast.x () < llast.x ()) xmin = rlast.x ();
int ymin = llast.y ();
if (rlast.y () < llast.y ()) ymin = rlast.y ();
int xmax = llast.x ();
if (rlast.x () > llast.x ()) xmax = rlast.x ();
int ymax = llast.y ();
if (rlast.y () > llast.y ()) ymax = rlast.y ();
seg = new DigitalStraightSegment (llast, rlast,
DigitalStraightLine::DSL_THIN,
xmin, ymin, xmax, ymax);
}
BlurredSegment *bbs = new BlurredSegment (plist, seg);
plist = NULL; // NECESSARY TO AVOID CONTENTS CLEARANCE !!!
return (bbs);
}
#ifndef BLURRED_SEGMENT_PROTO_H
#define BLURRED_SEGMENT_PROTO_H
#include "blurredsegment.h"
using namespace std;
/**
* @class BlurredSegmentProto blurredsegmentproto.h
* \brief A prototype of blurred segment, untill complete specification.
* It is mostly based on a evolving list of points, its convex hull and
* the successive states of the blurred segment construction.
* \author {P. Even}
*/
class BlurredSegmentProto : public BlurredSegment
{
public:
/**
* Creates a blurred segment prototype.
* @param maxWidth Maximal width of the blurred segment to build
* @param pix Central point of the blurred segment to build
*/
BlurredSegmentProto (int maxWidth, Pt2i pix);
/**
* Creates a blurred segment prototype with lists of points.
* @param maxWidth Maximal width of the blurred segment to build.
* @param center Central point of the blurred segment to build.
* @param leftPts Points to add on left side
* @param rightPts Points to add on right side.
*/
BlurredSegmentProto (int maxWidth, Pt2i center,
const vector<Pt2i> &leftPts, const vector<Pt2i> &rightPts);
/**
* \brief Deletes the blurred segment prototype.
*/
~BlurredSegmentProto ();
/**
* \brief Returns the minimal vertical or horizontal width.
*/
AbsRat segmentRationalWidth () const;
/**
* \brief Returns the requested max width of the segment.
*/
inline const AbsRat getMaxWidth () const { return maxWidth; }
/**
* \brief Sets the requested max width of the segment.
* @param maxwidth The new vaue for the requested max width.
*/
inline void setMaxWidth (const AbsRat &val) { maxWidth.set (val); }
/**
* \brief Returns the underlying digital straight line.
*/
DigitalStraightLine *getLine () const;
/**
* Adds a new point on the left.
* @param pix point to be added.
* Returns true if the point is accepted.
*/
bool addLeft (Pt2i pix);
/**
* Adds a new point on the right.
* @param pix point to be added.
* Returns true if the point is accepted.
*/
bool addRight (Pt2i pix);
/**
* \brief Remove last points on the left side.
* @param n Number of points to remove.
*/
void removeLeft (int n);
/**
* \brief Remove last points on the right side.
* @param n Number of points to remove.
*/
void removeRight (int n);
/**
* \brief Returns the support vector of the blurred segment.
*/
Vr2i getSupportVector ();
/**
* \brief Returns a stable blurred segment from available information.
*/
BlurredSegment *endOfBirth ();
protected:
/** Maximal width of the blurred segment. */
AbsRat maxWidth;
/** Maintained convex hull of the blurred segment. */
ConvexHull *convexhull;
/** Indicates if the blurred segment is constructed. */
bool bsOK;
/** Indicates if the points are aligned. */
bool bsFlat;
/** Indicates if the left point is defined. */
bool leftOK;
/** Indicates if the right point is defined. */
bool rightOK;
/** Flag indicating if the convex hull changed since last DSS extraction. */
bool chChanged;
/**
* \brief Submits a new point to extend the blurred segment.
* @param p Submitted point.
* @param onleft Adding direction (true for LEFT, false for RIGHT).
*/
bool addPoint (Pt2i p, bool onleft);
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "chvertex.h"
CHVertex::CHVertex () : Pt2i ()
{
lv = NULL;
rv = NULL;
}
CHVertex::CHVertex (int x, int y) : Pt2i (x, y)
{
lv = NULL;
rv = NULL;
}
CHVertex::CHVertex (const Pt2i &p) : Pt2i (p)
{
lv = NULL;
rv = NULL;
}
CHVertex::~CHVertex ()
{
}
ostream& operator<< (ostream &os, const CHVertex &v)
{
os << "(" << v.xp << ", " << v.yp << ")";
return os;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include <cstdlib>
#include "directionalscanner.h"
void DirectionalScanner::bindTo (int a, int b, int c)
{
(void) a;
(void) b;
(void) c;
}
DirectionalScanner::~DirectionalScanner ()
{
if (steps != NULL) delete steps;
steps = NULL;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment