30 #include <dxflib/dl_dxf.h> 43 if(!dxf.in(_dxfPath, &creationInterface))
45 std::cerr <<
"\t" << _dxfPath <<
" could not be opened.\n";
49 std::vector<Line> lineSegments;
50 const std::vector<DL_LineData> lines = creationInterface.
getLines();
52 for(
const DL_LineData & line : lines)
54 std::vector<Line> segs =
splitLine(line, _segLength);
55 lineSegments.insert(lineSegments.end(), segs.begin(), segs.end());
58 const std::vector<DL_CircleData> circles = creationInterface.
getCircles();
60 for(
const DL_CircleData & circle : circles)
62 std::vector<Line> segs =
splitCircle(circle, _segLength);
63 lineSegments.insert(lineSegments.end(), segs.begin(), segs.end());
66 const std::vector<DL_ArcData> arcs = creationInterface.
getArcs();
68 for(
const DL_ArcData & arc : arcs)
70 std::vector<Line> segs =
splitArc(arc, _segLength);
71 lineSegments.insert(lineSegments.end(), segs.begin(), segs.end());
75 std::vector<DL_ImageData> image = creationInterface.
getImage();
78 std::cerr <<
"\tToo many images in the dxf file" << std::endl;
84 std::cerr <<
"\tInconsistant scale in image" << std::endl;
96 std::vector<Line> segments;
97 Eigen::Vector2d start(_line.x1, _line.y1);
98 Eigen::Vector2d end(_line.x2, _line.y2);
100 float length = (end - start).norm();
101 uint32_t splits = length / _segLength;
103 Eigen::Vector2d increment = (end - start) / splits;
104 Eigen::Vector2d current = start;
106 for(uint32_t i = 0; i < splits; i++)
108 Line l(current, current + increment);
109 segments.push_back(l);
110 current += increment;
113 if(segments.size() == 0)
116 segments.push_back(l);
124 DL_ArcData _arc(_circle.cx, _circle.cy, _circle.cz, _circle.radius, 0, 360);
131 std::vector<Line> segments;
134 float angle1 = _arc.angle1 / 180 * M_PI;
135 float angle2 = _arc.angle2 / 180 * M_PI;;
137 if(_arc.angle1 >= _arc.angle2)
140 float arcLength = (angle2 - angle1) * _arc.radius;
141 uint32_t splits = arcLength / _segLength;
143 float angleIncrement_radians = (arcLength / (
float)splits) / _arc.radius;
144 float current_angle_radians = angle1;
145 Eigen::Vector2d current_point(_arc.cx + _arc.radius * cos(current_angle_radians), _arc.cy + _arc.radius * sin(current_angle_radians));
147 for(uint32_t i = 0; i < splits; i++)
149 current_angle_radians += angleIncrement_radians;
150 Eigen::Vector2d nextPoint(_arc.cx + _arc.radius * cos(current_angle_radians), _arc.cy + _arc.radius * sin(current_angle_radians));
151 Line l(current_point, nextPoint);
152 segments.push_back(l);
154 current_point = nextPoint;
166 _offset[0] = _image.ipx;
167 _offset[1] = _image.ipy;
169 float scale_u = sqrt((_image.ux * _image.ux) + (_image.uy * _image.uy));
170 float scale_v = sqrt((_image.vx * _image.vx) + (_image.vy * _image.vy));
172 if(scale_u != scale_v)
181 std::vector< Segment >
DxfToGraph::generateGraph(
const std::vector< Line > &_lines,
const float _segWidth,
const float &_scale,
const Eigen::Vector2d &_offset)
const 183 std::vector<Segment> segments;
187 for(uint32_t i = 0; i < _lines.size(); i++)
189 std::vector<Eigen::Vector2d> points({ (_lines[i].start-_offset)/
scale_, (_lines[i].end-_offset)/
scale_ });
192 segments.push_back(s);
197 for(uint32_t i = 0; i < _lines.size(); i++)
199 for(uint32_t j = 0; j < _lines.size(); j++)
203 if(((segments[i].getStart() - segments[j].getStart()).norm() < _scale) ||
204 ((segments[i].getStart() - segments[j].getEnd()).norm() < _scale))
206 segments[i].addPredecessor(j);
208 if(((segments[i].getEnd() - segments[j].getStart()).norm() < _scale) ||
209 ((segments[i].getEnd() - segments[j].getEnd()).norm() < _scale))
211 segments[i].addSuccessor(j);
bool getGraphData(const DL_ImageData &_image, float &_scale, Eigen::Vector2d &_offset) const
void serializeGraph(const std::string &_graphPath) const
serializes the graph and saves it to memory
std::vector< Segment > generateGraph(const std::vector< Line > &_lines, const float _segWidth, const float &_scale, const Eigen::Vector2d &_offset) const
static void resetId()
resets the id counter (which is used to generate uinique ids)
std::vector< Line > splitCircle(const DL_CircleData &_circle, const float _segLength) const
bool parseGraph(const std::string &_dxfPath, const float _segLength, const float _segWidth)
reads the graph from the dx file
const std::vector< DL_ArcData > & getArcs()
const std::vector< DL_CircleData > & getCircles()
std::vector< Segment > graphData_
const std::vector< DL_ImageData > & getImage()
void save(const std::string &_mapPath, const std::vector< Segment > &_segs, const Eigen::Vector2d &_origin, const float &_resolution)
saves the graph to a specific path in xml format
std::vector< Line > splitLine(const DL_LineData &_line, const float _segLength) const
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
std::vector< Line > splitArc(const DL_ArcData &_arc, const float _segLength) const
const std::vector< DL_LineData > & getLines()