Conscience Core
CommandGenerateCompletePath.h
Go to the documentation of this file.
1 #ifndef CommandGenerateCompletePath_h
2 #define CommandGenerateCompletePath_h
3 
4 #include "./Command.h"
5 
6 #include <memory>
8 #include <opencv2/opencv.hpp>
9 
12 
13 using namespace conscience_core::ai;
14 using namespace conscience_utils;
15 
16 namespace fs = std::filesystem;
17 using std::ceil, std::map, std::pair, std::make_pair, std::max, std::floor, std::numeric_limits, std::optional, std::array, std::string, std::vector, std::unique_ptr;
18 
20 
22 
23  public:
24  inline static const CommandTypeId COMMAND_ID = "GENERATE_COMPLETE_PATH_FOR_SCENE";
25 
29  CommandGenerateCompletePath(ptr<CscEntityReflexion> entityReflexion, optional<float> tileSizeCmMaybe, optional<CscArea3d*> area, optional<string> placeId);
30  virtual ~CommandGenerateCompletePath() = default;
31 
32  protected:
33  const CscCommandExecutionResultSequence * doExecute(CscEnvironmentSimulator &environmentSimulator) override;
34 
36  return entityReflexion;
37  }
38 
39  private:
40  std::unique_ptr<CscLogger> logger;
41  ptr<CscEntityReflexion> entityReflexion;
42  optional<string> placeId = {};
43 
44  bool areaDefined = false;
45  CscArea3d area;
46  CscArea3d areaPlace;
47  float tileSizeCm = 100.0f;
48  const float BEST_PATH_POINTS_HEIGHT_CM = 10;
49 
50  vector<CscPoint3dOriented *> bestPath;
51  int columnsCount = 0;
52  int tilesPerColumnCount = 0;
53 
54  float tileWidth = 0;
55  float tileHeight = 0;
56 
57  int inaccessibleTilesCount = 0;
58  int visitedOnceTilesCount = 0;
59  int allVisitedTilesCount = 0;
60  CscLocationTag* base = nullptr;
61  void computeBaseTile();
62 
63 
64  struct CSC_DLL_IMPORTEXPORT Tile {
65  public:
66  const int indexX;
67  const int indexY;
68 
69  bool visited = false;
70  bool accessible;
71  vector<int> visitsIndices;
72 
73  Tile(int indexX,
74  int indexY,
75  bool accessible) :indexX(indexX), indexY(indexY),accessible(accessible) {
76 
77  }
78  };
79 
83  struct CSC_DLL_IMPORTEXPORT ColumnChunkCrossroad {
84  public:
85  const int remoteChunkIndexInColumn;
86  const int y;
87  const int tileIndexInRemoteChunk;
88  const bool left;
89  bool disabled = false;
90 
91  ColumnChunkCrossroad(int remoteChunkIndexInColumn,
92  int y,
93  int tileIndexInRemoteChunk,
94  bool left) :
95  remoteChunkIndexInColumn(remoteChunkIndexInColumn), y(y),tileIndexInRemoteChunk(tileIndexInRemoteChunk), left(left) {
96  }
97  };
98 
99  struct CSC_DLL_IMPORTEXPORT ColumnChunk {
100  public:
104  vector<Tile *> tiles;
105 
106  int yMin = -1;
107  int yMax = -1;
108 
109  vector<ColumnChunkCrossroad *> pivotsLeft;
110  vector<ColumnChunkCrossroad *> pivotsRight;
111 
112  bool allTilesVisited() {
113  for (Tile * tile : tiles) {
114  if (!tile->visited) {
115  return false;
116  }
117  }
118  return true;
119  }
120  };
121 
122  struct CSC_DLL_IMPORTEXPORT Image {
123  public:
124  cv::Mat image;
125  int imageHeight;
126  };
127 
128 
129  Image* mapImage = nullptr;
130  CscPoint3d simulatorPlaceShift = CscPoint3d(0,0,0);
131  ColumnChunkCrossroad * lastCrossRoad = nullptr;
132  vector<vector<ColumnChunk>> columns;
133  vector<vector<Tile *>> tiles;
134  void processChunk(int ix, ColumnChunk & current, int currentTileIndexInChunk);
135 
136  pair<int, int> lastTile = make_pair(-1, -1);
137  void addToBestPath(int tileX, int tileY);
138 
139  void initializeDimensions();
140  void generateTiles();
141  bool computeAccessibleTiles(float x2D, float y2D, float height);
142  bool computeAccessibleTilesCartography(vector<CscPoint3d*> *placeVertices);
143  bool computeAccessibleTilesPlace(vector<const CscPoint3d*> *placeVertices);
144  bool initTilesFromPlace(CscWorldPlace *place, CscEnvironmentSimulator &environmentSimulator);
145 
146  void addPathToTargetToBestPath(int tileX, int currentTileY, int targetTileY);
147  void enterCrossroad(int currentColumnIndex, ColumnChunkCrossroad * crossroad);
148  void freeMemory();
150  CscSequencePositions* backToBase(CscEnvironmentSimulator &environmentSimulator, string target, CscPoint3d* lastPosition);
151 
152  };
153 
154 COMMAND_REGISTER(CommandGenerateCompletePath, ptr<CscEntityReflexion>, optional<float>, optional<CscArea3d*>, optional<string>)
155 }
156 
157 #endif
conscience_core::axiomes::CscPoint3d
The CscPoint3d class represents a point in three-dimensional space. It is primarily used to denote a ...
Definition: Csc3dTypes.h:24
conscience_core::bridging::commands::CommandGenerateCompletePath
Definition: CommandGenerateCompletePath.h:21
CSC_DLL_IMPORTEXPORT
#define CSC_DLL_IMPORTEXPORT
Definition: os.h:31
conscience_core::ai
Definition: alerts.cpp:12
CscLocationTag
Definition: CscWorldElementParts.h:63
conscience_core::ai::logger
unique_ptr< CscLogger > logger
Definition: CscMrptAutonomousExploration.cpp:49
CscSequencePositions
Definition: CscSequencePositions.h:23
conscience_core::axiomes::CscArea3d
Definition: Csc3dTypes.h:231
Command.h
conscience_core::bridging::commands::result::CscCommandExecutionResultSequence
Definition: CommandExecutionResultSequence.h:15
conscience_core::bridging::commands::CommandTypeId
string CommandTypeId
Definition: Command.h:29
CommandExecutionResultNone.h
CscEntityReflexion.h
conscience_core::bridging::commands
Definition: cartographyCommands.cpp:4
conscience_core::bridging::commands::CscCommand
Definition: Command.h:40
COMMAND_REGISTER
#define COMMAND_REGISTER(COMMAND_REGISTER_className,...)
Definition: CscCommandAutoParse.h:467
conscience_utils
Definition: CscEntityReflexion.h:50
CscEnvironmentSimulator
Definition: CscEnvironmentSimulator.h:35
CscCommandAutoParse.h
CscWorldPlace
Definition: CscWorldPlace.h:43
conscience_core::bridging::commands::environment_objects::optional< string >
const ptr< CscObjectModel > const string const CscPoint3d const CscPoint3d optional< string >
Definition: environmentObjectsCommands.h:373
ptr
std::shared_ptr< T > ptr
Definition: CscCommon.h:29
conscience_core::bridging::commands::CommandGenerateCompletePath::getEntityReflexion
ptr< CscEntityReflexion > getEntityReflexion() const override
Definition: CommandGenerateCompletePath.h:35