-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/step-conversion
- Loading branch information
Showing
6 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"files.associations": { | ||
"__bit_reference": "cpp", | ||
"__config": "cpp", | ||
"__debug": "cpp", | ||
"__errc": "cpp", | ||
"__hash_table": "cpp", | ||
"__locale": "cpp", | ||
"__mutex_base": "cpp", | ||
"__node_handle": "cpp", | ||
"__split_buffer": "cpp", | ||
"__threading_support": "cpp", | ||
"__verbose_abort": "cpp", | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"bitset": "cpp", | ||
"cctype": "cpp", | ||
"charconv": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"complex": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"exception": "cpp", | ||
"fstream": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"ios": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"locale": "cpp", | ||
"mutex": "cpp", | ||
"new": "cpp", | ||
"optional": "cpp", | ||
"ostream": "cpp", | ||
"ratio": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"string": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"typeinfo": "cpp", | ||
"unordered_map": "cpp", | ||
"variant": "cpp", | ||
"vector": "cpp", | ||
"algorithm": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"tasks": [ | ||
{ | ||
"type": "cppbuild", | ||
"label": "C/C++: clang build active file", | ||
"command": "/usr/bin/clang", | ||
"args": [ | ||
"-fcolor-diagnostics", | ||
"-fansi-escape-codes", | ||
"-g", | ||
"${file}", | ||
"-o", | ||
"${fileDirname}/${fileBasenameNoExtension}" | ||
], | ||
"options": { | ||
"cwd": "${fileDirname}" | ||
}, | ||
"problemMatcher": [ | ||
"$gcc" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"detail": "Task generated by Debugger." | ||
} | ||
], | ||
"version": "2.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <TopoDS_Shape.hxx> | ||
#include <TopExp_Explorer.hxx> | ||
#include <TopoDS_Edge.hxx> | ||
#include <BRep_Tool.hxx> | ||
#include <Geom_Curve.hxx> | ||
#include <GeomAPI_Interpolate.hxx> | ||
#include <TColgp_HArray1OfPnt.hxx> | ||
#include <GCPnts_AbscissaPoint.hxx> | ||
#include <GeomAdaptor_Curve.hxx> | ||
#include <vector> | ||
#include <GeomAPI_PointsToBSpline.hxx> | ||
#include <TopoDS_Vertex.hxx> | ||
#include <TopExp.hxx> | ||
#include <TopoDS.hxx> | ||
#include <gp_Pnt.hxx> | ||
|
||
bool VerticesMatch(const TopoDS_Vertex& v1, const TopoDS_Vertex& v2) { | ||
gp_Pnt p1 = BRep_Tool::Pnt(v1); | ||
gp_Pnt p2 = BRep_Tool::Pnt(v2); | ||
return p1.IsEqual(p2, Precision::Confusion()); | ||
} | ||
|
||
std::vector<TopoDS_Edge> OrderEdges(const TopoDS_Shape& shape) { | ||
std::vector<TopoDS_Edge> unorderedEdges, orderedEdges; | ||
|
||
// Fill unorderedEdges with all edges in the shape | ||
for (TopExp_Explorer exp(shape, TopAbs_EDGE); exp.More(); exp.Next()) { | ||
unorderedEdges.push_back(TopoDS::Edge(exp.Current())); | ||
} | ||
|
||
if (unorderedEdges.empty()) return orderedEdges; | ||
|
||
// Start with a random edge | ||
orderedEdges.push_back(unorderedEdges.front()); | ||
unorderedEdges.erase(unorderedEdges.begin()); | ||
|
||
while (!unorderedEdges.empty()) { | ||
bool matchFound = false; | ||
|
||
TopoDS_Vertex startV, endV; | ||
TopExp::Vertices(orderedEdges.front(), startV, endV); // Get start/end vertices of the current path | ||
|
||
for (auto it = unorderedEdges.begin(); it != unorderedEdges.end(); ++it) { | ||
TopoDS_Vertex startVNext, endVNext; | ||
TopExp::Vertices(*it, startVNext, endVNext); // Get vertices of the next candidate edge | ||
|
||
if (VerticesMatch(endV, startVNext)) { // Match end to start | ||
orderedEdges.push_back(*it); // Place it at the end | ||
endV = endVNext; // Update end vertex of the path | ||
unorderedEdges.erase(it); | ||
matchFound = true; | ||
break; | ||
} else if (VerticesMatch(startV, endVNext)) { // Match start to end | ||
orderedEdges.insert(orderedEdges.begin(), *it); // Place it at the beginning | ||
startV = startVNext; // Update start vertex of the path | ||
unorderedEdges.erase(it); | ||
matchFound = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!matchFound) { | ||
break; | ||
} | ||
} | ||
|
||
return orderedEdges; | ||
} | ||
|
||
// Function to sample points from an edge | ||
std::vector<gp_Pnt> SamplePointsFromEdge(const TopoDS_Edge& edge, int numPoints) { | ||
std::vector<gp_Pnt> points; | ||
double first, last; | ||
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, first, last); | ||
if (!curve.IsNull()) { | ||
double step = (last - first) / (numPoints - 1); | ||
for (int i = 0; i < numPoints; ++i) { | ||
gp_Pnt pnt = curve->Value(first + i * step); | ||
points.push_back(pnt); | ||
} | ||
} | ||
return points; | ||
} | ||
|
||
Handle(Geom_BSplineCurve) CreateBSplineFromShape(const TopoDS_Shape& shape) { | ||
std::vector<TopoDS_Edge> orderedEdges = OrderEdges(shape); | ||
std::vector<gp_Pnt> allPoints; | ||
const int SAMPLE_NUM = 10; | ||
|
||
for (const auto& edge : orderedEdges) { | ||
std::vector<gp_Pnt> edgePoints = SamplePointsFromEdge(edge, SAMPLE_NUM); | ||
allPoints.insert(allPoints.end(), edgePoints.begin(), edgePoints.end()); | ||
} | ||
|
||
// Convert std::vector<gp_Pnt> to TColgp_Array1OfPnt | ||
TColgp_Array1OfPnt arrayPoints(1, allPoints.size()); | ||
for (Standard_Integer i = 0; i < allPoints.size(); ++i) { | ||
arrayPoints.SetValue(i + 1, allPoints[i]); | ||
} | ||
|
||
GeomAPI_PointsToBSpline splineBuilder(arrayPoints); | ||
return splineBuilder.Curve(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#include <Geom_Curve.hxx> | ||
#include <Geom_BSplineCurve.hxx> | ||
#include <GeomLProp_SLProps.hxx> | ||
#include <gp_Pnt.hxx> | ||
#include <gp_Vec.hxx> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
// outputs a list of vectors containing the tangents to the knots on the curve | ||
std::vector<gp_Vec> calculate_tangent_vectors(const Handle(Geom_BSplineCurve)& bsplineCurve) { | ||
std::vector<gp_Vec> tangentVectors; | ||
gp_Vec tangentVector; | ||
gp_Pnt point; | ||
int knots = bsplineCurve->NbKnots(); | ||
Standard_Real step_size = 1 / knots; | ||
Standard_Real first_parameter = bsplineCurve->FirstParameter(); | ||
Standard_Real last_parameter = bsplineCurve->LastParameter(); | ||
for (int u = first_parameter; u < last_parameter; u += step_size) { | ||
bsplineCurve->D1(u, point, tangentVector); | ||
tangentVectors.push_back(tangentVector); | ||
} | ||
return tangentVectors; | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
return 1; | ||
} |