Skip to content

Commit

Permalink
Remove NormalDetector
Browse files Browse the repository at this point in the history
NormalDetector function now in ExamplesBase (utility)
  • Loading branch information
ncPUMA committed Jan 21, 2024
1 parent 4252f98 commit fe70acd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 140 deletions.
2 changes: 0 additions & 2 deletions EdgeExplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
normaldetector.cpp
normaldetector.h
viewport.cpp
viewport.h
)
Expand Down
110 changes: 0 additions & 110 deletions EdgeExplorer/normaldetector.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions EdgeExplorer/normaldetector.h

This file was deleted.

8 changes: 4 additions & 4 deletions EdgeExplorer/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
#include <ExamplesBase/InteractiveObjects/interactivenormal.h>
#include <ExamplesBase/InteractiveObjects/interactivefacenormal.h>
#include <ExamplesBase/InteractiveObjects/interactivefacenormalserializer.h>
#include <ExamplesBase/utility.h>

#include "brepserializer.h"
#include "normaldetector.h"

static constexpr size_t sPerfPointsCount = 1000000ul;

Expand Down Expand Up @@ -132,7 +132,7 @@ class ViewportPrivate
gp_Pnt P;
gp_Vec V1, V2, V3;
curve.D2(U, P, V1, V2);
const gp_Dir normal = NormalDetector::getNormal(TopoDS::Face(face), P);
const gp_Dir normal = ExamplesBase::getNormal(TopoDS::Face(face), P);

const gp_Pnt normalEnd = P.Translated(normal.XYZ() * 5);
auto lineN = new AIS_Line(new Geom_CartesianPoint(P), new Geom_CartesianPoint(normalEnd));
Expand Down Expand Up @@ -279,7 +279,7 @@ class ViewportPrivate
return;
}

auto normal = NormalDetector::getNormal(face, pnt);
auto normal = ExamplesBase::getNormal(face, pnt);
auto normalObj = new ExamplesBase::InteractiveNormal;
normalObj->setLabel("Р1"); //cyrilic test
gp_Trsf trsf;
Expand Down Expand Up @@ -502,7 +502,7 @@ void Viewport::slNormalV1Test()
std::vector <gp_Dir> normals;
normals.reserve(points.size());
t.restart();
normals = NormalDetector::getNormals(face, points);
normals = ExamplesBase::getNormals(face, points);
qDebug() << "Find" << normals.size() << "normals on curve by" << t.elapsed() << "ms.";
}

Expand Down
42 changes: 42 additions & 0 deletions ExamplesBase/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepTools.hxx>
#include <GeomLProp_SLProps.hxx>
#include <ShapeAnalysis_Surface.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>

Expand Down Expand Up @@ -53,4 +56,43 @@ TopoDS_Edge findEdgeByPoint(const TopoDS_Shape &shape, const gp_Pnt &localPnt)
return res;
}

gp_Dir getNormal(const TopoDS_Face &face, const gp_Pnt &point)
{
auto aSurf = BRep_Tool::Surface(face);
Standard_Real u1, u2, v1, v2;
BRepTools::UVBounds(face, u1, u2, v1, v2);

Handle(ShapeAnalysis_Surface) surfAnalis = new ShapeAnalysis_Surface(aSurf);
const gp_Pnt2d pUV = surfAnalis->ValueOfUV(point, Precision::Confusion());

GeomLProp_SLProps props(aSurf, pUV.X(), pUV.Y(), 1, 0.01);
gp_Dir normal = props.Normal();
if (face.Orientation() == TopAbs_REVERSED || face.Orientation() == TopAbs_INTERNAL) {
normal.Reverse();
}
return normal;
}

std::vector<gp_Dir> getNormals(const TopoDS_Face &face, const std::vector<gp_Pnt> &points)
{
std::vector <gp_Dir> normals;
normals.reserve(points.size());

auto aSurf = BRep_Tool::Surface(face);
Standard_Real u1, u2, v1, v2;
BRepTools::UVBounds(face, u1, u2, v1, v2);

Handle(ShapeAnalysis_Surface) surfAnalis = new ShapeAnalysis_Surface(aSurf);
for (const auto &point : points) {
const gp_Pnt2d pUV = surfAnalis->ValueOfUV(point, Precision::Confusion());
GeomLProp_SLProps props(aSurf, pUV.X(), pUV.Y(), 1, 0.01);
gp_Dir normal = props.Normal();
if (face.Orientation() == TopAbs_REVERSED || face.Orientation() == TopAbs_INTERNAL) {
normal.Reverse();
}
normals.push_back(normal);
}
return normals;
}

}
10 changes: 8 additions & 2 deletions ExamplesBase/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@

#include "ExamplesBase_global.h"

#include <vector>

class gp_Dir;
class gp_Pnt;
class TopoDS_Edge;
class TopoDS_Face;
class TopoDS_Shape;

namespace ExamplesBase {

TopoDS_Face EXAMPLESBASE_EXPORT findFaceByPoint(const TopoDS_Shape &shape, const gp_Pnt &localPnt);
TopoDS_Edge EXAMPLESBASE_EXPORT findEdgeByPoint(const TopoDS_Shape &shape, const gp_Pnt &localPnt);
EXAMPLESBASE_EXPORT TopoDS_Face findFaceByPoint(const TopoDS_Shape &shape, const gp_Pnt &localPnt);
EXAMPLESBASE_EXPORT TopoDS_Edge findEdgeByPoint(const TopoDS_Shape &shape, const gp_Pnt &localPnt);

EXAMPLESBASE_EXPORT gp_Dir getNormal(const TopoDS_Face &face, const gp_Pnt &point);
EXAMPLESBASE_EXPORT std::vector <gp_Dir> getNormals(const TopoDS_Face &face, const std::vector <gp_Pnt> &points);

}

Expand Down

0 comments on commit fe70acd

Please sign in to comment.