2 #ifndef CommandAreaAnalysis_h
3 #define CommandAreaAnalysis_h
6 #include <unordered_map>
7 #include <unordered_set>
13 #define DOUBLE_PRECISION 0.001
15 #define MAXIMUM_RATIO 200000
18 using std::vector, std::unordered_map, std::unordered_set;
43 return entityReflexion;
49 bool doNotPlaySequence =
false;
63 vector<const CscPoint3d *> areaVertices;
64 vector<vector<const CscPoint3d *>> holes;
65 vector<vector<CommandAreaAnalysis::Tile *>> tiles;
66 double areaOfPerceptionWidth;
72 vector<CscPoint3d *> tilePathToPointPath(vector<CommandAreaAnalysis::Tile *> tilePath,
const CscPoint3d *bottomLeftCorner);
81 vector<CscPoint3d *> filterPointInsidePolygon(vector<CscPoint3d *> toFilter);
89 void trapezoidalDecomposition(CommandAreaAnalysis::Area
polygon,
double tileSideLength, vector<Polygon *> &cells, vector<Edge *> edges);
94 void processEvent(CommandAreaAnalysis::Area
polygon,
double tileSideLength, Vertex *eventVertex, vector<Edge *> edges, vector<Polygon *> &cells, vector<Vertex *> vertices);
104 vector<CscPoint3d *> explore(vector<CommandAreaAnalysis::Cell *> spanningTree, vector<Cell *> graphCells, CommandAreaAnalysis::Area
polygon,
double tileSideLength, CommandAreaAnalysis::Cell *firstCell, vector<Edge *> edges);
106 void showPointPathOnSceneFloor(vector<CscPoint3d *> sequence,
CscEnvironmentSimulator &environmentSimulator,
bool clear,
bool line);
107 void createAreaTiles(
int numberOfLines,
int numberOfColumns,
const CscPoint3d *firstPoint, CommandAreaAnalysis::Polygon
polygon);
118 static bool equalsTwoDouble(
double lhs,
double rhs);
123 static void siftDown(
const CscPoint3d *lexicalOrder[],
int length,
int i);
128 static void heapSort(
const CscPoint3d *lexicalOrder[],
int length);
134 static CscPoint3d *convertTileToPoint(Tile *tile,
const CscPoint3d *firstPoint,
double areaOfPerceptionWidth);
143 vector<Polygon *> forbiddenAreas;
144 vector<const CscPoint3d *> intersections;
148 Polygon *areaToExplore;
150 Area(Polygon *areaToExplore, vector<Polygon *> forbiddenAreas,
double &areaOfPerceptionWidth,
CscEnvironmentSimulator *envi);
152 vector<const CscPoint3d *> areaVertices();
154 vector<Edge *> getEdges();
156 bool isPointInside(
const CscPoint3d *pointToCheck);
158 vector<const CscPoint3d *> getLexicalOrder();
163 const CscPoint3d *getNearestVisibleVertex(vector<Vertex *> vertices, vector<Edge *> edges,
const CscPoint3d *triggerVertex,
const CscPoint3d *vertexEndPoint);
168 bool isVertexVisible(vector<Edge *> edges,
const CscPoint3d *triggerVertex,
const CscPoint3d *otherVertex);
175 Endpoint *getEndpoint(
const CscPoint3d *vertex,
double tileSideLength, vector<Edge *> edges,
bool isAbove);
177 Polygon *continueEvent(Vertex *triggerVertex,
double tileSideLength, vector<Edge *> edges, vector<Vertex *> vertices);
179 Polygon *mergeEvent(Vertex *triggerVertex,
double tileSideLength, vector<Edge *> edges, vector<Vertex *> vertices);
181 vector<Polygon *> outEvent(Vertex *triggerVertex,
double tileSideLength, vector<Edge *> edges, vector<Vertex *> vertices);
183 Polygon *splitEvent(Vertex *triggerVertex,
double tileSideLength, vector<Edge *> edges, vector<Vertex *> vertices);
190 bool isVisited =
false;
195 bool accessible =
true) : indexX(indexX), indexY(indexY), accessible(accessible) {}
202 Edge(
const CscPoint3d *first,
const CscPoint3d *second) : firstPoint(first), secondPoint(second) {}
210 return std::hash<std::string>()(concat);
216 return (equalsTwoPoints(lhs.firstPoint, rhs.firstPoint) && equalsTwoPoints(lhs.secondPoint, rhs.secondPoint)) || (equalsTwoPoints(lhs.firstPoint, rhs.secondPoint) && equalsTwoPoints(lhs.secondPoint, rhs.firstPoint));
229 Endpoint(
const CscPoint3d *point, Edge *edge) : point(point), edge(edge) {}
241 Vertex(
const CscPoint3d *point, Edge *firstEdge, Edge *secondEdge) : point(point), firstEdge(firstEdge), secondEdge(secondEdge) {}
250 bool operator()(
const Vertex *lhs,
const Vertex *rhs)
const {
251 return equalsTwoPoints(lhs->point, rhs->point);
259 vector<const CscPoint3d *> polygonVertices;
260 vector<Edge *> edges;
262 Polygon(vector<const CscPoint3d *> areaVertices,
CscEnvironmentSimulator *envi) : polygonVertices(areaVertices), envi(envi) {
263 int j = areaVertices.size() - 1;
266 while (
i < areaVertices.size()) {
268 if (isFirstBeforeSecond(areaVertices.at(
j), areaVertices.at(
i))) {
269 firstEdge =
new Edge(areaVertices.at(
j), areaVertices.at(
i));
271 firstEdge =
new Edge(areaVertices.at(
i), areaVertices.at(
j));
273 edges.push_back(firstEdge);
282 vector<const CscPoint3d *> getLexicalOrder();
294 vector<CommandAreaAnalysis::Tile *> boustrophedonPath(vector<vector<CommandAreaAnalysis::Tile *>>
polygon,
CscPoint3d *position);
299 vector<vector<CommandAreaAnalysis::Tile *>> getTranspose(vector<vector<CommandAreaAnalysis::Tile *>>
polygon);
304 void createAreaTiles(
int numberOfLines,
int numberOfColumns,
double tileSideLength, vector<vector<CommandAreaAnalysis::Tile *>> &tiless);
312 bool isPointInside(
const CscPoint3d *pointToCheck);
313 bool isAdjacentTo(Polygon *other);
314 bool overlaps(Polygon *other);
316 CscPoint3d *adjacencyPointWith(Polygon *other);
320 CommandAreaAnalysis::Polygon *polygonCell;
322 vector<EdgeCell *> adjacentCells;
324 Cell(Polygon *polygonCell,
string name) : polygonCell(polygonCell), name(name) {}
326 Cell(Cell cell, vector<EdgeCell *> adjacentCells) : adjacentCells(adjacentCells) {
328 polygonCell = cell.polygonCell;
333 return std::hash<std::string>()(cell->name);
339 return lhs->name == rhs->name;
345 return std::hash<std::string>()(cell.name);
351 return lhs.name == rhs.name;
354 void initializeAdjacencyList(vector<Cell *> cellsOfGraph);
360 EdgeCell(Cell *cell,
double weight) : cell(cell), weight(weight) {}
367 CellNode(Cell *cell, CellNode *parent) : cell(cell), parent(parent) {}
371 return std::hash<std::string>()(cellNode->cell->name);
376 bool operator()(
const CellNode *lhs,
const CellNode *rhs)
const {
377 return lhs->cell->name == rhs->cell->name;
384 vector<Cell> adjacencyList;
391 PriorityCell(Cell *cell,
double priority) : cell(cell), priority(priority) {}
395 vector<CommandAreaAnalysis::Polygon *> polygonsOfGraph;
396 vector<Cell *> cellsOfGraph;
402 CellGraph(vector<Polygon *> polygonsOfGraph) : polygonsOfGraph(polygonsOfGraph) {
404 for (Polygon *
polygon : polygonsOfGraph) {
408 for (Cell *cell : cellsOfGraph) {
409 cell->initializeAdjacencyList(cellsOfGraph);
416 vector<Cell *> makeTree(unordered_map<Cell, optional<Cell>, Cell::CellHash, Cell::CellEqual> primMap);
421 unordered_map<Cell, optional<Cell>, Cell::CellHash, Cell::CellEqual> generateSpanningTree(Cell *source);