OpenLexocad  28.0
WireTool.h
Go to the documentation of this file.
1 #pragma once
2 #include <Topo/Types.h>
3 #include <Geom/Precision.h>
4 #include <vector>
5 
6 namespace Geom
7 {
8 class Pln;
9 class Pnt;
10 class Dir;
11 class Trsf;
12 }
13 
14 namespace Topo
15 {
22 class LX_TOPO_EXPORT WireTool
23 {
24 public:
26  // //
27  // --------------------- BEGIN API --------------------- //
28  // //
29  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
30  // //
32 
34  static pWire projectWireOnPlane(const Geom::Pln& pln, pConstWire wire, double precision = Geom::Precision::linear_Resolution());
36  static bool projectPointOnWire(const Geom::Pnt& p, pConstWire wire, Geom::Pnt& nearest);
38  static bool projectPointOnWire(const Geom::Pnt& p, pConstWire wire, Geom::Pnt& nearest, Geom::Dir& refDirection);
40  static bool isPlanar(pConstWire wire, Geom::Pln& plane);
42  static bool isClosed(pConstWire wire);
44  static bool close(pWire wire, double precision = Geom::Precision::linear_Resolution());
46  static pWire closed(pConstWire wire, double precision = Geom::Precision::linear_Resolution());
48  static bool addEdge(pWire wire, pEdge edge, double precision = Geom::Precision::linear_Resolution());
50  static bool addEdge(pWire wire, const std::vector<pEdge>& edges, double precision = Geom::Precision::linear_Resolution());
52  static bool addConstEdge(pWire wire, pConstEdge edge, double precision = Geom::Precision::linear_Resolution());
54  static bool addConstEdge(pWire wire, const std::vector<pEdge>& edges, double precision = Geom::Precision::linear_Resolution());
56  static pWire addedEdge(pConstWire wire, pConstEdge edge, double precision = Geom::Precision::linear_Resolution());
58  static pWire addedEdge(pConstWire wire, const std::vector<pConstEdge>& edges, double precision = Geom::Precision::linear_Resolution());
62  static std::vector<pConstEdge> getClosestEdgesToPoint(const Geom::Pnt& p, pConstWire wire, double& distance, double tolerance = 1E-06);
64  static std::vector<pConstEdge> getAdjacentEdgesToVertexOnWire(pConstVertex vertex, pConstWire wire);
66  static void getAdjacentEdgesToPointOnWire(const Geom::Pnt& point, pConstWire wire, std::vector<pConstEdge>& adjacentEdges);
68  static pWire makeWire(const std::vector<pEdge>& edges, double precision = Geom::Precision::linear_Resolution());
70  static pWire makeWire(pEdge edges);
73  static pWire makeWire(pConstVertex vertex);
75  static std::vector<pWire> makeWires(const std::vector<pEdge>& edges, double precision = Geom::Precision::linear_Resolution());
77  static pWire copy(pConstWire wire);
79  static pWire makePolygon(const std::vector<Geom::Pnt>& points);
81  static pWire makePolyline(const std::vector<Geom::Pnt>& points);
83  static std::vector<pConstEdge> getEdges(pConstWire wire);
85  static std::vector<pEdge> getEdgesCopy(pConstWire wire);
87  static std::vector<pConstVertex> getVertices(pConstWire wire);
89  static void getPoints(pConstWire wire, std::vector<Geom::Pnt>& pnts);
91  static bool hasOnlyLines(pConstWire wire);
93  static bool hasHelix(pConstWire wire);
95  static bool fixReorder(pWire wire);
97  static void writeDbgInfo(pConstWire wire);
101  static bool filletWireAtVertex(pWire wire, const Geom::Pnt& p, double radius, double precision = Geom::Precision::linear_Resolution());
103  static bool chamferWireAtVertex(pWire wire, const Geom::Pnt& p, double offset, double precision = Geom::Precision::linear_Resolution());
106  static bool removeEdgesFromWire(pWire wire,
107  std::vector<pConstEdge> edges,
108  double precision = Geom::Precision::linear_Resolution(),
109  bool stayInBndBox = false);
111  static pWire transformed(pConstWire base, const Geom::Trsf& t);
113  static bool isSelfIntersecting(pConstWire wire);
115  static pWire createOffset(pConstWire wire, const Geom::Dir& refDirection, double offset);
117  static pWire reversed(pConstWire wire);
119  static pWire joined(pConstWire wire1, pConstWire wire2);
121  static bool getWirePlane(pConstWire wire, Geom::Pln& plane);
122 
124  // //
125  // ---------------------- END API ---------------------- //
126  // //
128 
129 #ifndef LXAPI // INTERFACES BELOW ARE -NOT- PART OF THE LEXOCAD API
130 
133  static void __setDefaultWireTool__(Topo::WireTool* tool) { _defaultTool = tool; }
135  static pWire reverseWirePointsConnection(pConstWire wire, double precision = Geom::Precision::linear_Resolution());
138  static pWire
139  combineWireWithWire(pConstWire hWire, pConstWire vWire, const uint& x, const uint& y, const uint& z, const double& start, const double& end);
140 
141 protected:
142  virtual pWire _projectWireOnPlane(const Geom::Pln& pln, pConstWire wire, double precision);
143  virtual bool _projectPointOnWire(const Geom::Pnt& p, pConstWire wire, Geom::Pnt& nearest);
144  virtual bool _projectPointOnWire(const Geom::Pnt& p, pConstWire wire, Geom::Pnt& nearest, Geom::Dir& refDirection);
145  virtual bool _isPlanar(pConstWire wire, Geom::Pln& plane);
146  virtual bool _isClosed(pConstWire wire);
147  virtual pWire _closed(pConstWire wire, double precision);
148  virtual pWire _addedEdge(pConstWire wire, pConstEdge edge, double precision);
149  virtual pWire _addedEdge(pConstWire wire, const std::vector<pConstEdge>& edges, double precision);
150  virtual pConstVertex _getClosestVertexToPoint(const Geom::Pnt& p, pConstWire wire);
151  virtual std::vector<pConstEdge> _getClosestEdgesToPoint(const Geom::Pnt& p, pConstWire wire, double& distance, double precision = 1E-06);
152  virtual std::vector<pConstEdge> _getAdjacentEdgesToVertexOnWire(pConstVertex vertex, pConstWire wire);
153  virtual void _getAdjacentEdgesToPointOnWire(const Geom::Pnt& point, pConstWire wire, std::vector<pConstEdge>& adjacentEdges);
154  virtual pWire _makeWire(const std::vector<pEdge>& edges, double precision);
155  virtual pWire _makeWire(pConstVertex vertex);
156  virtual std::vector<pWire> _makeWires(const std::vector<pEdge>& edges, double precision);
157  virtual pWire _copy(pConstWire wire);
158  virtual pWire _makePolygon(const std::vector<Geom::Pnt>& points);
159  virtual pWire _makePolyline(const std::vector<Geom::Pnt>& points);
160  virtual std::vector<pConstEdge> _getEdges(pConstWire wire);
161  virtual std::vector<pConstVertex> _getVertices(pConstWire wire);
162  virtual void _getPoints(pConstWire wire, std::vector<Geom::Pnt>& pnts);
163  virtual pWire _reverseWirePointsConnection(pConstWire wire, double precision);
164  virtual pWire _createOffset(pConstWire wire, const Geom::Dir& refDirection, double offset);
165  virtual bool _fixReorder(pWire wire);
166  virtual void _writeDbgInfo(pConstWire wire);
167  virtual Geom::Pnt _getCentre(pConstWire wire);
168  virtual bool _filletWireAtVertex(pWire wire, const Geom::Pnt& p, double radius, double precision);
169  virtual bool _chamferWireAtVertex(pWire wire, const Geom::Pnt& p, double offset, double precision);
170  virtual bool _removeEdgesFromWire(pWire wire, std::vector<pConstEdge> edges, double precision, bool stayInBndBox = false);
171  virtual bool _isSelfIntersecting(pConstWire wire);
172  virtual pWire _reversed(pConstWire wire);
173  virtual pWire _joined(pConstWire wire1, pConstWire wire2);
174  virtual bool _getWirePlane(pConstWire& wire, Geom::Pln& pln);
175  virtual pWire
176  _combineWireWithWire(pConstWire hWire, pConstWire vWire, const uint& x, const uint& y, const uint& z, const double& start, const double& end);
177  static Topo::WireTool* _defaultTool;
179 #endif
180 };
181 
182 } // namespace Topo
pConstVertex
std::shared_ptr< Topo::Vertex const > pConstVertex
Definition: Types.h:74
Topo::WireTool::reversed
static pWire reversed(pConstWire wire)
Returns a reversed wire.
Topo::WireTool::getPoints
static void getPoints(pConstWire wire, std::vector< Geom::Pnt > &pnts)
Returns the points of a wire in a connection order.
Topo::WireTool::getCentre
static Geom::Pnt getCentre(pConstWire wire)
Returns centre of mass (centre of gravity) of the wire.
Topo::WireTool::filletWireAtVertex
static bool filletWireAtVertex(pWire wire, const Geom::Pnt &p, double radius, double precision=Geom::Precision::linear_Resolution())
Fillets a wire at the given vertex with the given radius. The give wire is modified in place....
Topo::WireTool::projectPointOnWire
static bool projectPointOnWire(const Geom::Pnt &p, pConstWire wire, Geom::Pnt &nearest)
Projects point 'p' on 'wire'. Returns the nearest solution point.
Topo::WireTool::close
static bool close(pWire wire, double precision=Geom::Precision::linear_Resolution())
Closes the wire.
Precision.h
Topo::WireTool::makeWire
static pWire makeWire(pConstVertex vertex)
Topo::WireTool::createOffset
static pWire createOffset(pConstWire wire, const Geom::Dir &refDirection, double offset)
Create offset of wire.
Topo::WireTool
Tools for creating, manipulating and querying Wires.
Definition: WireTool.h:23
pConstWire
std::shared_ptr< Topo::Wire const > pConstWire
Definition: Types.h:71
Topo::WireTool::getAdjacentEdgesToPointOnWire
static void getAdjacentEdgesToPointOnWire(const Geom::Pnt &point, pConstWire wire, std::vector< pConstEdge > &adjacentEdges)
Get the adjacent edges from a point on a wire.
Topo::WireTool::getClosestVertexToPoint
static pConstVertex getClosestVertexToPoint(const Geom::Pnt &p, pConstWire wire)
Returns the closest vertex from a point on a wire. Returns nullptr on failure.
Topo::WireTool::getEdges
static std::vector< pConstEdge > getEdges(pConstWire wire)
Returns the edges of a wire in a connection order.
Topo::WireTool::isSelfIntersecting
static bool isSelfIntersecting(pConstWire wire)
Check if the wire is self-intersecting.
Geom::Dir
Definition: Dir.h:45
Topo::WireTool::addEdge
static bool addEdge(pWire wire, const std::vector< pEdge > &edges, double precision=Geom::Precision::linear_Resolution())
Adds a vector of edges to a wire.
Topo::WireTool::joined
static pWire joined(pConstWire wire1, pConstWire wire2)
Joins two wires at coincident vertices. Returns the joined wire.
Topo::WireTool::addedEdge
static pWire addedEdge(pConstWire wire, const std::vector< pConstEdge > &edges, double precision=Geom::Precision::linear_Resolution())
Returns the new wire with the added edges.
Topo::WireTool::projectWireOnPlane
static pWire projectWireOnPlane(const Geom::Pln &pln, pConstWire wire, double precision=Geom::Precision::linear_Resolution())
Projects a wire onto a plane. Returns the new projected wire.
Topo::WireTool::addConstEdge
static bool addConstEdge(pWire wire, pConstEdge edge, double precision=Geom::Precision::linear_Resolution())
Takes a const edge and copies it. The copy is added to the wire.
pEdge
std::shared_ptr< Topo::Edge > pEdge
Definition: Types.h:55
Geom::Pln
Definition: Pln.h:52
pWire
std::shared_ptr< Topo::Wire > pWire
Definition: Types.h:54
Topo::WireTool::isClosed
static bool isClosed(pConstWire wire)
Checks if the wire is closed.
Topo::WireTool::getClosestEdgesToPoint
static std::vector< pConstEdge > getClosestEdgesToPoint(const Geom::Pnt &p, pConstWire wire, double &distance, double tolerance=1E-06)
Returns the closest edges from a point on a wire.
Topo::WireTool::makePolyline
static pWire makePolyline(const std::vector< Geom::Pnt > &points)
Makes a polyline wire (as opposed to makePoligon, the wire is not forced to be closed)
Topo::WireTool::hasHelix
static bool hasHelix(pConstWire wire)
Checks if wire has at least one helix edge.
Topo::WireTool::transformed
static pWire transformed(pConstWire base, const Geom::Trsf &t)
Creates a copy of the wire and transforms the copy.
Geom::Pnt
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:44
Topo::WireTool::fixReorder
static bool fixReorder(pWire wire)
Performs an analysis and reorders edges in the wire.
Topo::WireTool::getAdjacentEdgesToVertexOnWire
static std::vector< pConstEdge > getAdjacentEdgesToVertexOnWire(pConstVertex vertex, pConstWire wire)
Returns the adjacent edges from a vertex on a wire.
Topo::WireTool::addedEdge
static pWire addedEdge(pConstWire wire, pConstEdge edge, double precision=Geom::Precision::linear_Resolution())
Returns the new wire with the added edge.
Geom::distance
double distance(const Geom::Vec &v1, const Geom::Vec &v2)
Returns the distance between two points.
Definition: Vec.h:341
Topo::WireTool::writeDbgInfo
static void writeDbgInfo(pConstWire wire)
Writes debug information of wire to stdout.
Topo::WireTool::getVertices
static std::vector< pConstVertex > getVertices(pConstWire wire)
Returns the vertices of a wire in a connection order.
Topo::WireTool::hasOnlyLines
static bool hasOnlyLines(pConstWire wire)
Checks if all edges of the wire are lines.
Topo::WireTool::addEdge
static bool addEdge(pWire wire, pEdge edge, double precision=Geom::Precision::linear_Resolution())
Adds an edge to the wire.
pConstEdge
std::shared_ptr< Topo::Edge const > pConstEdge
Definition: Types.h:72
Topo::WireTool::chamferWireAtVertex
static bool chamferWireAtVertex(pWire wire, const Geom::Pnt &p, double offset, double precision=Geom::Precision::linear_Resolution())
Chamfers a wire at the given vertex with the given offset. The give wire is modified in place....
Topo
Definition: DbgInfo.h:17
Types.h
Topo::WireTool::makeWires
static std::vector< pWire > makeWires(const std::vector< pEdge > &edges, double precision=Geom::Precision::linear_Resolution())
Makes (possibly sevaral) wires from edges.
Topo::WireTool::addConstEdge
static bool addConstEdge(pWire wire, const std::vector< pEdge > &edges, double precision=Geom::Precision::linear_Resolution())
Takes a vector of const edges and copies them. The copies are added to the wire.
Topo::WireTool::makeWire
static pWire makeWire(pEdge edges)
Makes a wire one edges.
Topo::WireTool::getWirePlane
static bool getWirePlane(pConstWire wire, Geom::Pln &plane)
Gets the plane of a 3D wire.
Topo::WireTool::copy
static pWire copy(pConstWire wire)
Copies a wire.
Topo::WireTool::isPlanar
static bool isPlanar(pConstWire wire, Geom::Pln &plane)
Checks if the wire is planar.
Topo::WireTool::makePolygon
static pWire makePolygon(const std::vector< Geom::Pnt > &points)
Makes an polygonal wire.
Geom::Trsf
Definition: Trsf.h:58
Topo::WireTool::removeEdgesFromWire
static bool removeEdgesFromWire(pWire wire, std::vector< pConstEdge > edges, double precision=Geom::Precision::linear_Resolution(), bool stayInBndBox=false)
Topo::WireTool::getEdgesCopy
static std::vector< pEdge > getEdgesCopy(pConstWire wire)
Returns copy of the edges of a wire in a connection order.
Topo::WireTool::projectPointOnWire
static bool projectPointOnWire(const Geom::Pnt &p, pConstWire wire, Geom::Pnt &nearest, Geom::Dir &refDirection)
Projects point 'p' on 'wire'. Returns the nearest solution point and the reference (up) direction at ...
Geom::Precision::linear_Resolution
static constexpr double linear_Resolution()
Definition: Precision.h:23
Topo::WireTool::makeWire
static pWire makeWire(const std::vector< pEdge > &edges, double precision=Geom::Precision::linear_Resolution())
Makes a wire from edges.
Geom
Definition: PropertyContainer.h:33
Topo::WireTool::closed
static pWire closed(pConstWire wire, double precision=Geom::Precision::linear_Resolution())
Returns the closed wire.