#ifndef BLURRED_SEGMENT_TRACKER_H #define BLURRED_SEGMENT_TRACKER_H #include <vector> #include "scannerprovider.h" #include "blurredsegment.h" #include "vmap.h" using namespace std; /** * @class BSTracker bstracker.h * \brief Blurred segment tracker in grey level images. * \author {P. Even and B. Kerautret} */ class BSTracker { public: /** * \brief Creates a blurred segment tracker. */ BSTracker (); /** * \brief Deletes the blurred segment tracker. */ ~BSTracker (); /** * \brief Clears off stored information. */ void clear (); /** * \brief Builds and returns a blurred segment from only gradient maximum. * @param p1 Initial stroke start point. * @param p2 Initial stroke end point. * @param p0 Initial segment start point (if different from NULL). */ BlurredSegment *fastTrack (const Pt2i &p1, const Pt2i &p2, Pt2i *p0 = NULL); /** * \brief Builds and returns a blurred segment from local gradient maxima. * Finer detection using gradient ridges and direction input. * @param center Central point of the scan. * @param scandir Scan direction * @param scanwidth Width of the scan strip. * @param bswidth Initial maximal width of the blurred segment to build. * @param gref Gradient vector reference to select candidates. */ BlurredSegment *fineTrack (const Pt2i ¢er, const Vr2i &scandir, int scanwidth, int bswidth, const Vr2i &gref); /** * \brief Returns the assigned maximal width for fast tracks. */ inline int fastTracksMaxWidth () const { return imaxWidth; } /** * \brief Sets the assigned maximal width for fast tracks. */ inline void setFastTracksMaxWidth (int value) { if (value > 0) imaxWidth = value; } /** * \brief Returns the assigned maximal width for fine tracks. */ inline int fineTracksMaxWidth () const { return fmaxWidth; } /** * \brief Sets the assigned maximal width for fine tracks. */ inline void setFineTracksMaxWidth (int value) { if (value > 0) fmaxWidth = value; } /** * \brief Returns the pixel lack tolerence for exdending the blurred segment.. */ inline int pixelLackTolerence () const { return acceptedLacks; } /** * \brief Sets the pixel lack tolerence for extending the blurred segment. */ inline void setPixelLackTolerence (int number) { if (number >= 0) { acceptedLacks = number; if (minRestart != 1) minRestart = number; } } /** * \brief Returns the count of accepted points to release a failure. */ inline int getRestartOnLack () { return minRestart; } /** * \brief Switches on or off the automatic restart after failure. */ inline void switchAutoRestart () { minRestart = (minRestart == 1 ? acceptedLacks : 1); } /** * \brief Sets the image data. */ void setGradientMap (VMap *data); /** * \brief Returns the vicinity threshold used for fast tracking. */ inline int getVicinityThreshold () { return vicinityThreshold; } /** * \brief Increments the vicinity threshold used for fast tracking. * @param inc Increment value. */ inline void incVicinityThreshold (int inc) { if (vicinityThreshold < NO_VICINITY) { vicinityThreshold += inc; if (vicinityThreshold < 1) vicinityThreshold = 1; } } /** * \brief Returns the vicinity test status. */ inline bool vicinityConstraintOn () { return (vicinityThreshold < NO_VICINITY); } /** * \brief Switches the vicinity test used for fast tracking. */ inline void switchVicinityConstraint () { vicinityThreshold += (vicinityThreshold > NO_VICINITY ? - NO_VICINITY : NO_VICINITY); } /** * \brief Returns if the dynamic scans are used. */ inline bool dynamicScansOn () { return dynamicScans; } /** * \brief Returns the upper bound of the final scan. */ inline vector<Pt2i> getScanBound1 () const { return scanBound1; } /** * \brief Returns the lower bound of the final scan. */ inline vector<Pt2i> getScanBound2 () const { return scanBound2; } /** * \brief Returns the scan lines. */ inline vector <vector <Pt2i> > getScans () const { return scanLine; } /** * \brief Returns whether the scan record modality is set. */ inline bool scanRecordOn () { return recordScans; } /** * \brief Sets the scan record modality. * @param status Sets on if true, off otherwise. */ inline void setScanRecord (bool status) { recordScans = status; } /** * \brief Toggles the dynamic scans use. */ inline void toggleDynamicScans () { dynamicScans = ! dynamicScans; } /** * \brief Switches the scan extent limitation.. */ void switchScanExtent (); /** * \brief Returns the scan extent limit. */ inline int maxScanExtent () { return (maxScan); } /** * \brief Sets the dynamic scans on or off. */ inline void setDynamicScans (bool onOff) { dynamicScans = onOff; } /** * \brief Returns if the thinning is activated. */ inline bool isThinningActivated () { return thinningOn; } /** * \brief Toggles the thinning strategy. */ inline void toggleThinning () { thinningOn = ! thinningOn; } /** * \brief Switches on or off the orthogonal scanning modality. */ void switchOrthoScans (); /** * \brief Switches on or off the orthogonal scanning modality. */ inline bool orthoScansOn () { return orthoScan; } private : // Segment detection default parameters. /** Default value for the max segment width for fast tracks. */ static const int DEFAULT_FAST_TRACK_MAX_WIDTH; /** Default value for the max segment width for fine tracks. */ static const int DEFAULT_FINE_TRACK_MAX_WIDTH; /** Default value for the accepted number of successive lacks. */ static const int DEFAULT_ACCEPTED_LACKS; /** Default value for the vicinity test used for fast tracking. */ static const int DEFAULT_VICINITY_THRESHOLD; /** Large value to release the vicinity constraint. */ static const int NO_VICINITY; /** Minimal length of scan length to be processed. */ static const int MIN_SCAN; /** Default value for the maximal number of scans processed on each side. */ static const int DEFAULT_MAX_SCAN; // Dynamical scan default parameters. /* Count of points before activating the fitting on the detected segment. */ static const int DEFAULT_FITTING_DELAY; // Width thinning default parameters. /* Count of points before activating the width thinning. */ static const int DEFAULT_THINNING_DELAY; /** Value which controls the width thinning speed. * It is the percentage of width offset withdrawn from the width tolerence. * Width offset = width tolerence - blurred segment width. */ static const int DEFAULT_THINNING_SPEED; /** Minimal value of the percentage of width offset wrt segment width. */ static const int DEFAULT_THINNING_REACH; /** Resolution of the max segment width when thinning. */ static const int DEFAULT_THINNING_RESOLUTION; /** Segment stop information : no start point found. */ static const int FAILURE_NO_START; /** Segment stop information : image bound reached on the right. */ static const int FAILURE_IMAGE_BOUND_ON_RIGHT; /** Segment stop information : image bound reached on the left. */ static const int FAILURE_IMAGE_BOUND_ON_LEFT; /** Segment stop information : lost orientation at dynamical reset start. */ static const int FAILURE_LOST_ORIENTATION; /** Scanned map left bound. */ int xmin; /** Scanned map lower bound. */ int ymin; /** Scanned map width. */ int width; /** Scanned map height. */ int height; /** Blurred segment max width for fast tracks. */ int imaxWidth; /** Blurred segment max width for fine tracks. */ int fmaxWidth; /** Number of awaited points after each failure. */ int minRestart; /** Accepted number of successive lacks (wrt restart points). */ int acceptedLacks; /** Vicinity threshold used for fast tracking. */ int vicinityThreshold; /** Orthogonal scanning modality status */ bool orthoScan; /** Kind of scans used : dynamic if true. */ bool dynamicScans; /** Minimal detection width before activating the dynamical scans. */ int fittingDelay; /** Segment thinning strategy. */ bool thinningOn; /** Width thinning delay. */ int thinningDelay; /** Width thinning speed : amount of thinning offset withdrawn. */ AbsRat thinningSpeed; /** Minimal control width wrt detected segment width when thinning. */ AbsRat thinningReach; /** Gradient map. */ VMap *gMap; /** Maximum number of scans. */ int maxScan; /** Failure cause. */ int fail; /** Candidates array for internal use. */ int *cand; /** Index of the last successful scan on right side. */ int rscan; /** Index of the last successful scan on left side. */ int lscan; /** Directional scanner provider. * Automatically selects the appropriate octant. */ ScannerProvider scanp; /** Upper bound of the scan. */ vector<Pt2i> scanBound1; /** Lower bound of the scan. */ vector<Pt2i> scanBound2; /** Scan lines. */ vector <vector <Pt2i> > scanLine; /** Dynamical scanner record modality. */ bool recordScans; }; #endif