Ophidian
All Classes Namespaces Functions
subrows.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef OPHIDIAN_SUBROWS_H
22 #define OPHIDIAN_SUBROWS_H
23 
24 #include <boost/geometry/index/rtree.hpp>
25 #include "floorplan.h"
26 #include <placement.h>
27 #include <entity_system.h>
28 
29 namespace ophidian {
30  namespace placement {
31  namespace legalization {
32  using point = geometry::point<double>;
33  using box = geometry::box<point>;
34  using rtree_node = std::pair<box, entity_system::entity>;
35  using rtree = boost::geometry::index::rtree<rtree_node, boost::geometry::index::rstar<16>>;
36  class subrows {
37 
39 
43 
44  rtree subrows_rtree;
45  public:
46 
48  : m_system(system){
49  m_system.register_property(&m_begin);
50  m_system.register_property(&m_end);
51  m_system.register_property(&m_row);
52  }
53 
54  std::size_t count() {
55  return m_system.size();
56  }
57 
58  void create_subrows(floorplan::floorplan * floorplan, placement * placement);
59 
60  double begin(entity_system::entity subrow) {
61  return m_begin[m_system.lookup(subrow)];
62  }
63  void begin(entity_system::entity subrow, double begin);
64 
65  double end(entity_system::entity subrow) {
66  return m_end[m_system.lookup(subrow)];
67  }
68  void end(entity_system::entity subrow, double end);
69 
70  entity_system::entity row(entity_system::entity subrow) {
71  return m_row[m_system.lookup(subrow)];
72  }
73  void row(entity_system::entity subrow, entity_system::entity row);
74 
75  entity_system::entity find_subrow(point coordinate);
76 
77  std::vector<entity_system::entity> find_closest_subrows(point coordinate, unsigned number_of_rows);
78 
79  };
80 
81  class subrow_not_found : public std::exception {
82  public:
83  const char * what() const throw() {
84  return "No subrow found in the given coordinate";
85  }
86  };
87  }
88  }
89 }
90 
91 
92 #endif //OPHIDIAN_SUBROWS_H
Placement class.
Definition: placement.h:35
entity_system class.
Definition: entity_system.h:40
std::size_t size() const
Returns the size of the system.
Definition: entity_system.h:82
Floorplan class.
Definition: floorplan.h:37
entity_index lookup(entity e) const
Gets the index of an entity.
Definition: entity_system.h:149
void register_property(property *property)
Registers property.
Definition: entity_system.cpp:61