SHARE
TWEET

Untitled

a guest Oct 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @file ImageTraversal.h
  3.  */
  4. #pragma once
  5.  
  6. #include <iterator>
  7. #include "../cs225/HSLAPixel.h"
  8. #include "../cs225/PNG.h"
  9. #include "../Point.h"
  10.  
  11. #include <vector>
  12. using namespace cs225;
  13.  
  14. /**
  15.  * A base class for traversal algorithms on images.
  16.  *
  17.  * BFS and DFS will inherit from this class
  18.  *
  19.  * Each derived class must maintain an ordering of points on an image,
  20.  * through calls to the virtual member functions `add` and `pop`.
  21.  *
  22.  * A derived class provides a traversal by returning instances of
  23.  * ImageTraversal::Iterator.
  24.  */
  25. class ImageTraversal {
  26. public:
  27.   /**
  28.    * A forward iterator through an ImageTraversal.
  29.    */
  30.   class Iterator : std::iterator<std::forward_iterator_tag, Point> {
  31.   public:
  32.     Iterator();
  33.     Iterator(PNG png, Point start, double tolerance, ImageTraversal *traversal);
  34.     Iterator & operator++();
  35.     Point operator*();
  36.     bool operator!=(const Iterator &other);
  37.  
  38.     /** @todo [Part 1] */
  39.     /** add member functions if neccesary*/
  40.    
  41.     bool canVisit(Point point);
  42.     void setEnd(bool end);
  43.     bool atEnd;
  44.  
  45.   private:
  46.     /** @todo [Part 1] */
  47.     /** add private members here if neccesary*/
  48.     ImageTraversal *traversal_;
  49.     Point start_;
  50.     Point start_unchanged_;
  51.     PNG png_;
  52.     double tolerance_;
  53.     std::vector<Point> path_;
  54.     std::vector<bool> points_visited;
  55.  
  56.   };
  57.  
  58.   /**
  59.    * The begining of an iterator
  60.    * Virtual function. Derived class need to implement this
  61.    */
  62.   virtual Iterator begin() = 0;
  63.  
  64.   /**
  65.    * The end of an iterator
  66.    * Virtual function. Derived class need to implement this
  67.    */
  68.   virtual Iterator end() = 0;
  69.  
  70.   /**
  71.    * Add new point to the traversal
  72.    * Virtual function. Derived class need to implement this
  73.    */
  74.   virtual void add(const Point & t) = 0;
  75.   /**
  76.    * Remove and return the next point of the traversal
  77.    * Virtual function. Derived class need to implement this
  78.    */
  79.   virtual Point pop() = 0;
  80.   /**
  81.    * Return but not remove the next point of the traversal
  82.    * Virtual function. Derived class need to implement this
  83.    */
  84.   virtual Point peek() const = 0;
  85.   /**
  86.    * To see if the traversal has no points left
  87.    * Virtual function. Derived class need to implement this
  88.    */
  89.   virtual bool empty() const = 0;
  90.  
  91. private:
  92.   static double calculateDelta(const HSLAPixel & p1, const HSLAPixel & p2);  
  93. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top