PetaVision  Alpha
SegmentLayer.hpp
1 #ifndef SEGMENTLAYER_HPP_
2 #define SEGMENTLAYER_HPP_
3 
4 #include "HyPerLayer.hpp"
5 #include <map>
6 
7 namespace PV {
8 
9 class SegmentLayer : public PV::HyPerLayer {
10  public:
11  SegmentLayer(const char *name, HyPerCol *hc);
12  virtual Response::Status
13  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
14  virtual Response::Status allocateDataStructures() override;
15  virtual bool activityIsSpiking() override { return false; }
16  virtual ~SegmentLayer();
17  const std::map<int, int> getCenterIdxBuf(int batch) { return centerIdx[batch]; }
18 
19  protected:
20  SegmentLayer();
21  int initialize(const char *name, HyPerCol *hc);
22  int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
23  void ioParam_originalLayerName(enum ParamsIOFlag ioFlag);
24  void ioParam_segmentMethod(enum ParamsIOFlag ioFlag);
25  virtual void initializeActivity() override;
26 
27  virtual void allocateV() override;
28  virtual void initializeV() override;
29 
30  virtual Response::Status updateState(double timef, double dt) override;
31 
32  private:
33  int initialize_base();
34  int checkLabelBufSize(int newSize);
35  int loadLabelBuf();
36  int loadCenterIdxMap(int batchIdx, int numLabels);
37 
38  int checkIdxBufSize(int newSize);
39 
40  // Data structures to keep track of segmentation labels and centroid idx
41  char *segmentMethod;
42  char *originalLayerName;
43  HyPerLayer *originalLayer;
44 
45  protected:
46  int labelBufSize;
47  int *labelBuf;
48  int *maxXBuf;
49  int *maxYBuf;
50  int *minXBuf;
51  int *minYBuf;
52 
53  int centerIdxBufSize;
54  int *allLabelsBuf;
55  int *centerIdxBuf;
56 
57  // Maps which go from segment label to max x/y global res index
58  std::map<int, int> maxX;
59  std::map<int, int> maxY;
60  std::map<int, int> minX;
61  std::map<int, int> minY;
62 
63  // Stores centriod linear index as global res
64  std::vector<std::map<int, int>> centerIdx;
65 
66 }; // class SegmentLayer
67 
68 } /* namespace PV */
69 #endif
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override