Merge branch 'master' into test_b
This commit is contained in:
@@ -138,11 +138,13 @@ def cmdCreateImageScaling(name):
|
||||
def accept(self):
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
try:
|
||||
locale=QtCore.QLocale.system()
|
||||
#d, ok = locale.toFloat(str(eval(self.lineEdit.text())))
|
||||
try:
|
||||
d = float(str(eval(self.lineEdit.text().replace(',','.'))))
|
||||
ok = True
|
||||
q = FreeCAD.Units.parseQuantity(self.lineEdit.text())
|
||||
d = q.Value
|
||||
if q.Unit == FreeCAD.Units.Unit(): # plain number
|
||||
ok = True
|
||||
elif q.Unit == FreeCAD.Units.Length:
|
||||
ok = True
|
||||
except:
|
||||
ok = False
|
||||
if not ok:
|
||||
|
||||
@@ -26,20 +26,6 @@
|
||||
# include <algorithm>
|
||||
# include <map>
|
||||
#endif
|
||||
#ifdef FC_USE_OCC
|
||||
# include <Bnd_Box.hxx>
|
||||
# include <BndLib_Add3dCurve.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <GCPnts_UniformDeflection.hxx>
|
||||
# include <Geom_Curve.hxx>
|
||||
# include <Geom_Plane.hxx>
|
||||
# include <GeomAPI_IntCS.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Edge.hxx>
|
||||
#endif
|
||||
|
||||
#include "Projection.h"
|
||||
#include "MeshKernel.h"
|
||||
@@ -55,216 +41,6 @@
|
||||
using namespace MeshCore;
|
||||
|
||||
|
||||
#ifdef FC_USE_OCC
|
||||
MeshProjection::MeshProjection(const MeshKernel& rMesh)
|
||||
: _rcMesh(rMesh)
|
||||
{
|
||||
}
|
||||
|
||||
MeshProjection::~MeshProjection()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshProjection::splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDist ) const
|
||||
{
|
||||
std::vector<SplitEdge> cSplitEdges;
|
||||
projectToMesh( aShape, fMaxDist, cSplitEdges );
|
||||
|
||||
std::ofstream str("output.asc", std::ios::out | std::ios::binary);
|
||||
str.precision(4);
|
||||
str.setf(std::ios::fixed | std::ios::showpoint);
|
||||
for (std::vector<SplitEdge>::const_iterator it = cSplitEdges.begin();it!=cSplitEdges.end();++it) {
|
||||
str << it->cPt.x << " " << it->cPt.y << " " << it->cPt.z << std::endl;
|
||||
}
|
||||
str.close();
|
||||
}
|
||||
|
||||
void MeshProjection::projectToMesh ( const TopoDS_Shape &aShape, float fMaxDist, std::vector<SplitEdge>& rSplitEdges ) const
|
||||
{
|
||||
// calculate the average edge length and create a grid
|
||||
MeshAlgorithm clAlg( _rcMesh );
|
||||
float fAvgLen = clAlg.GetAverageEdgeLength();
|
||||
MeshFacetGrid cGrid( _rcMesh, 5.0f*fAvgLen );
|
||||
|
||||
TopExp_Explorer Ex;
|
||||
TopoDS_Shape Edge;
|
||||
|
||||
int iCnt=0;
|
||||
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next())
|
||||
iCnt++;
|
||||
|
||||
Base::Sequencer().start( "Project curve on mesh", iCnt );
|
||||
|
||||
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
|
||||
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
|
||||
projectEdgeToEdge( aEdge, fMaxDist, cGrid, rSplitEdges );
|
||||
Base::Sequencer().next();
|
||||
}
|
||||
|
||||
Base::Sequencer().stop();
|
||||
}
|
||||
|
||||
void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist, const MeshFacetGrid& rGrid,
|
||||
std::vector<SplitEdge>& rSplitEdges ) const
|
||||
{
|
||||
std::vector<unsigned long> auFInds;
|
||||
std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> > pEdgeToFace;
|
||||
const std::vector<MeshFacet>& rclFAry = _rcMesh.GetFacets();
|
||||
|
||||
// search the facets in the local area of the curve
|
||||
std::vector<Vector3f> acPolyLine;
|
||||
|
||||
BRepAdaptor_Curve clCurve( aEdge );
|
||||
|
||||
Standard_Real fFirst = clCurve.FirstParameter();
|
||||
Standard_Real fLast = clCurve.LastParameter();
|
||||
|
||||
GCPnts_UniformDeflection clDefl(clCurve, 0.01f, fFirst, fLast);
|
||||
if (clDefl.IsDone() == Standard_True) {
|
||||
Standard_Integer nNbPoints = clDefl.NbPoints();
|
||||
for (Standard_Integer i = 1; i <= nNbPoints; i++) {
|
||||
gp_Pnt gpPt = clCurve.Value(clDefl.Parameter(i));
|
||||
acPolyLine.push_back( Vector3f( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() ) );
|
||||
}
|
||||
}
|
||||
|
||||
MeshAlgorithm(_rcMesh).SearchFacetsFromPolyline( acPolyLine, fMaxDist, rGrid, auFInds);
|
||||
// remove duplicated elements
|
||||
std::sort(auFInds.begin(), auFInds.end());
|
||||
auFInds.erase(std::unique(auFInds.begin(), auFInds.end()), auFInds.end());
|
||||
|
||||
// facet to edge
|
||||
for ( std::vector<unsigned long>::iterator pI = auFInds.begin(); pI != auFInds.end(); ++pI ) {
|
||||
const MeshFacet& rF = rclFAry[*pI];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
unsigned long ulPt0 = std::min<unsigned long>(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
|
||||
unsigned long ulPt1 = std::max<unsigned long>(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
|
||||
pEdgeToFace[std::pair<unsigned long, unsigned long>(ulPt0, ulPt1)].push_front(*pI);
|
||||
}
|
||||
}
|
||||
|
||||
// sort intersection points by parameter
|
||||
std::map<Quantity_Parameter, SplitEdge> rParamSplitEdges;
|
||||
|
||||
// Standard_Real fFirst, fLast;
|
||||
Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
|
||||
|
||||
// bounds of curve
|
||||
// Bnd_Box clBB;
|
||||
// BndLib_Add3dCurve::Add( BRepAdaptor_Curve(aEdge), 0.0, clBB );
|
||||
|
||||
MeshPointIterator cPI( _rcMesh );
|
||||
MeshFacetIterator cFI( _rcMesh );
|
||||
|
||||
Base::Sequencer().start( "Project curve on mesh", pEdgeToFace.size() );
|
||||
std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> >::iterator it;
|
||||
for ( it = pEdgeToFace.begin(); it != pEdgeToFace.end(); ++it ) {
|
||||
Base::Sequencer().next();
|
||||
|
||||
// edge points
|
||||
unsigned long uE0 = it->first.first;
|
||||
cPI.Set( uE0 );
|
||||
Vector3f cE0 = *cPI;
|
||||
unsigned long uE1 = it->first.second;
|
||||
cPI.Set( uE1 );
|
||||
Vector3f cE1 = *cPI;
|
||||
|
||||
const std::list<unsigned long>& auFaces = it->second;
|
||||
if ( auFaces.size() > 2 )
|
||||
continue; // non-manifold edge -> don't handle this
|
||||
// if ( clBB.IsOut( gp_Pnt(cE0.x, cE0.y, cE0.z) ) && clBB.IsOut( gp_Pnt(cE1.x, cE1.y, cE1.z) ) )
|
||||
// continue;
|
||||
|
||||
Vector3f cEdgeNormal;
|
||||
for ( std::list<unsigned long>::const_iterator itF = auFaces.begin(); itF != auFaces.end(); ++itF ) {
|
||||
cFI.Set( *itF );
|
||||
cEdgeNormal += cFI->GetNormal();
|
||||
}
|
||||
|
||||
// create a plane from the edge normal and point
|
||||
Vector3f cPlaneNormal = cEdgeNormal % (cE1 - cE0);
|
||||
Handle(Geom_Plane) hPlane = new Geom_Plane(gp_Pln(gp_Pnt(cE0.x,cE0.y,cE0.z),
|
||||
gp_Dir(cPlaneNormal.x,cPlaneNormal.y,cPlaneNormal.z)));
|
||||
|
||||
// get intersection of curve and plane
|
||||
GeomAPI_IntCS Alg(hCurve,hPlane);
|
||||
if ( Alg.IsDone() ) {
|
||||
Standard_Integer nNbPoints = Alg.NbPoints();
|
||||
if ( nNbPoints == 1 ) {
|
||||
Quantity_Parameter fU, fV, fW;
|
||||
Alg.Parameters( 1, fU, fV, fW);
|
||||
|
||||
gp_Pnt P = Alg.Point(1);
|
||||
Vector3f cP0((float)P.X(), (float)P.Y(), (float)P.Z());
|
||||
|
||||
float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
|
||||
|
||||
// lies the point inside the edge?
|
||||
if ( l>=0.0f && l<=1.0f ) {
|
||||
Vector3f cSplitPoint = (1-l) * cE0 + l * cE1;
|
||||
float fDist = Base::Distance( cP0, cSplitPoint );
|
||||
|
||||
if ( fDist <= fMaxDist ) {
|
||||
SplitEdge splitEdge;
|
||||
splitEdge.uE0 = uE0;
|
||||
splitEdge.uE1 = uE1;
|
||||
splitEdge.cPt = cSplitPoint;
|
||||
rParamSplitEdges[fW] = splitEdge;
|
||||
}
|
||||
}
|
||||
}
|
||||
// search for the right solution
|
||||
else if ( nNbPoints > 1 ) {
|
||||
int nCntSol=0;
|
||||
Vector3f cSplitPoint;
|
||||
Quantity_Parameter fSol;
|
||||
Vector3f cP0;
|
||||
for ( int j=1; j<=nNbPoints; j++ ) {
|
||||
Quantity_Parameter fU, fV, fW;
|
||||
Alg.Parameters( j, fU, fV, fW);
|
||||
gp_Pnt P = Alg.Point(j);
|
||||
cP0.Set((float)P.X(), (float)P.Y(), (float)P.Z());
|
||||
|
||||
float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
|
||||
|
||||
// lies the point inside the edge?
|
||||
if ( l>=0.0 && l<=1.0 ) {
|
||||
cSplitPoint = (1-l) * cE0 + l * cE1;
|
||||
float fDist = Base::Distance( cP0, cSplitPoint );
|
||||
|
||||
if (fDist <= fMaxDist) {
|
||||
nCntSol++;
|
||||
fSol = fW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ok, only one sensible solution
|
||||
if ( nCntSol == 1 ) {
|
||||
SplitEdge splitEdge;
|
||||
splitEdge.uE0 = uE0;
|
||||
splitEdge.uE1 = uE1;
|
||||
splitEdge.cPt = cSplitPoint;
|
||||
rParamSplitEdges[fSol] = splitEdge;
|
||||
}
|
||||
else if ( nCntSol > 1 ) {
|
||||
Base::Console().Log("More than one possible intersection points\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sorted by parameter
|
||||
for (std::map<Quantity_Parameter, SplitEdge>::iterator itS =
|
||||
rParamSplitEdges.begin(); itS != rParamSplitEdges.end(); ++itS) {
|
||||
rSplitEdges.push_back( itS->second );
|
||||
}
|
||||
|
||||
Base::Sequencer().stop();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
MeshProjection::MeshProjection(const MeshKernel& mesh)
|
||||
|
||||
@@ -61,47 +61,6 @@ private:
|
||||
const MeshKernel& kernel;
|
||||
};
|
||||
|
||||
#ifdef FC_USE_OCC
|
||||
/// Helper class
|
||||
struct SplitEdge
|
||||
{
|
||||
unsigned long uE0, uE1; /**< start and endpoint of an edge */
|
||||
Base::Vector3f cPt; /**< Point on edge (\a uE0, \a uE1) */
|
||||
};
|
||||
|
||||
/**
|
||||
* The MeshProjection class projects a shape onto a mesh.
|
||||
* @author Werner Mayer
|
||||
*/
|
||||
class MeshExport MeshProjection
|
||||
{
|
||||
public:
|
||||
/// Construction
|
||||
MeshProjection( const MeshKernel& rMesh);
|
||||
/// Destruction
|
||||
~MeshProjection();
|
||||
|
||||
/**
|
||||
* Searches all edges that intersect with the projected curve \a aShape. Therefore \a aShape must
|
||||
* contain shapes of type TopoDS_Edge, other shape types are ignored. A possible solution is
|
||||
* taken if the distance between the curve point and the projected point is <= \a fMaxDist.
|
||||
*/
|
||||
void projectToMesh ( const TopoDS_Shape &aShape, float fMaxDist, std::vector<SplitEdge>& rSplitEdges ) const;
|
||||
/**
|
||||
* Cuts the mesh at the curve defined by \a aShape. This method call @ref projectToMesh() to get the
|
||||
* split the facet at the found points. @see projectToMesh() for more details.
|
||||
*/
|
||||
void splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDist ) const;
|
||||
|
||||
protected:
|
||||
void projectEdgeToEdge( const TopoDS_Edge &aCurve, float fMaxDist, const MeshFacetGrid& rGrid,
|
||||
std::vector<SplitEdge>& rSplitEdges ) const;
|
||||
|
||||
private:
|
||||
const MeshKernel& _rcMesh;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace MeshCore
|
||||
|
||||
#endif // MESH_PROJECTION_H
|
||||
|
||||
@@ -24,8 +24,20 @@
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# ifdef FC_OS_LINUX
|
||||
# include <unistd.h>
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
# include <Bnd_Box.hxx>
|
||||
# include <BndLib_Add3dCurve.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
# include <GCPnts_UniformDeflection.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS.hxx>
|
||||
# include <TopoDS_Edge.hxx>
|
||||
# include <Geom_Curve.hxx>
|
||||
# include <Geom_Plane.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <GeomAPI_IntCS.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -36,18 +48,13 @@
|
||||
#include <Mod/Mesh/App/Core/MeshKernel.h>
|
||||
#include <Mod/Mesh/App/Core/Iterator.h>
|
||||
#include <Mod/Mesh/App/Core/Algorithm.h>
|
||||
#include <Mod/Mesh/App/Core/Grid.h>
|
||||
#include <Mod/Mesh/App/Mesh.h>
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Sequencer.h>
|
||||
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <Geom_Curve.hxx>
|
||||
#include <Geom_Plane.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <GeomAPI_IntCS.hxx>
|
||||
|
||||
using namespace MeshPart;
|
||||
using namespace MeshCore;
|
||||
@@ -665,7 +672,209 @@ void CurveProjectorWithToolMesh::makeToolMesh( const TopoDS_Edge& aEdge,std::vec
|
||||
lp = (*It2).p;
|
||||
ln = (*It2).n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
MeshProjection::MeshProjection(const MeshKernel& rMesh)
|
||||
: _rcMesh(rMesh)
|
||||
{
|
||||
}
|
||||
|
||||
MeshProjection::~MeshProjection()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshProjection::splitMeshByShape ( const TopoDS_Shape &aShape, float fMaxDist ) const
|
||||
{
|
||||
std::vector<SplitEdge> cSplitEdges;
|
||||
projectToMesh( aShape, fMaxDist, cSplitEdges );
|
||||
|
||||
std::ofstream str("output.asc", std::ios::out | std::ios::binary);
|
||||
str.precision(4);
|
||||
str.setf(std::ios::fixed | std::ios::showpoint);
|
||||
for (std::vector<SplitEdge>::const_iterator it = cSplitEdges.begin();it!=cSplitEdges.end();++it) {
|
||||
str << it->cPt.x << " " << it->cPt.y << " " << it->cPt.z << std::endl;
|
||||
}
|
||||
str.close();
|
||||
}
|
||||
|
||||
void MeshProjection::projectToMesh ( const TopoDS_Shape &aShape, float fMaxDist, std::vector<SplitEdge>& rSplitEdges ) const
|
||||
{
|
||||
// calculate the average edge length and create a grid
|
||||
MeshAlgorithm clAlg( _rcMesh );
|
||||
float fAvgLen = clAlg.GetAverageEdgeLength();
|
||||
MeshFacetGrid cGrid( _rcMesh, 5.0f*fAvgLen );
|
||||
|
||||
TopExp_Explorer Ex;
|
||||
TopoDS_Shape Edge;
|
||||
|
||||
int iCnt=0;
|
||||
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next())
|
||||
iCnt++;
|
||||
|
||||
Base::SequencerLauncher seq( "Project curve on mesh", iCnt );
|
||||
|
||||
for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
|
||||
const TopoDS_Edge& aEdge = TopoDS::Edge(Ex.Current());
|
||||
projectEdgeToEdge( aEdge, fMaxDist, cGrid, rSplitEdges );
|
||||
seq.next();
|
||||
}
|
||||
}
|
||||
|
||||
void MeshProjection::projectEdgeToEdge( const TopoDS_Edge &aEdge, float fMaxDist, const MeshFacetGrid& rGrid,
|
||||
std::vector<SplitEdge>& rSplitEdges ) const
|
||||
{
|
||||
std::vector<unsigned long> auFInds;
|
||||
std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> > pEdgeToFace;
|
||||
const std::vector<MeshFacet>& rclFAry = _rcMesh.GetFacets();
|
||||
|
||||
// search the facets in the local area of the curve
|
||||
std::vector<Base::Vector3f> acPolyLine;
|
||||
|
||||
BRepAdaptor_Curve clCurve( aEdge );
|
||||
|
||||
Standard_Real fFirst = clCurve.FirstParameter();
|
||||
Standard_Real fLast = clCurve.LastParameter();
|
||||
|
||||
GCPnts_UniformDeflection clDefl(clCurve, 0.01f, fFirst, fLast);
|
||||
if (clDefl.IsDone() == Standard_True) {
|
||||
Standard_Integer nNbPoints = clDefl.NbPoints();
|
||||
for (Standard_Integer i = 1; i <= nNbPoints; i++) {
|
||||
gp_Pnt gpPt = clCurve.Value(clDefl.Parameter(i));
|
||||
acPolyLine.push_back( Base::Vector3f( (float)gpPt.X(), (float)gpPt.Y(), (float)gpPt.Z() ) );
|
||||
}
|
||||
}
|
||||
|
||||
MeshAlgorithm(_rcMesh).SearchFacetsFromPolyline( acPolyLine, fMaxDist, rGrid, auFInds);
|
||||
// remove duplicated elements
|
||||
std::sort(auFInds.begin(), auFInds.end());
|
||||
auFInds.erase(std::unique(auFInds.begin(), auFInds.end()), auFInds.end());
|
||||
|
||||
// facet to edge
|
||||
for ( std::vector<unsigned long>::iterator pI = auFInds.begin(); pI != auFInds.end(); ++pI ) {
|
||||
const MeshFacet& rF = rclFAry[*pI];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
unsigned long ulPt0 = std::min<unsigned long>(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
|
||||
unsigned long ulPt1 = std::max<unsigned long>(rF._aulPoints[i], rF._aulPoints[(i+1)%3]);
|
||||
pEdgeToFace[std::pair<unsigned long, unsigned long>(ulPt0, ulPt1)].push_front(*pI);
|
||||
}
|
||||
}
|
||||
|
||||
// sort intersection points by parameter
|
||||
std::map<Standard_Real, SplitEdge> rParamSplitEdges;
|
||||
|
||||
// Standard_Real fFirst, fLast;
|
||||
Handle(Geom_Curve) hCurve = BRep_Tool::Curve( aEdge,fFirst,fLast );
|
||||
|
||||
// bounds of curve
|
||||
// Bnd_Box clBB;
|
||||
// BndLib_Add3dCurve::Add( BRepAdaptor_Curve(aEdge), 0.0, clBB );
|
||||
|
||||
MeshPointIterator cPI( _rcMesh );
|
||||
MeshFacetIterator cFI( _rcMesh );
|
||||
|
||||
Base::SequencerLauncher seq( "Project curve on mesh", pEdgeToFace.size() );
|
||||
std::map<std::pair<unsigned long, unsigned long>, std::list<unsigned long> >::iterator it;
|
||||
for ( it = pEdgeToFace.begin(); it != pEdgeToFace.end(); ++it ) {
|
||||
seq.next();
|
||||
|
||||
// edge points
|
||||
unsigned long uE0 = it->first.first;
|
||||
cPI.Set( uE0 );
|
||||
Base::Vector3f cE0 = *cPI;
|
||||
unsigned long uE1 = it->first.second;
|
||||
cPI.Set( uE1 );
|
||||
Base::Vector3f cE1 = *cPI;
|
||||
|
||||
const std::list<unsigned long>& auFaces = it->second;
|
||||
if ( auFaces.size() > 2 )
|
||||
continue; // non-manifold edge -> don't handle this
|
||||
// if ( clBB.IsOut( gp_Pnt(cE0.x, cE0.y, cE0.z) ) && clBB.IsOut( gp_Pnt(cE1.x, cE1.y, cE1.z) ) )
|
||||
// continue;
|
||||
|
||||
Base::Vector3f cEdgeNormal;
|
||||
for ( std::list<unsigned long>::const_iterator itF = auFaces.begin(); itF != auFaces.end(); ++itF ) {
|
||||
cFI.Set( *itF );
|
||||
cEdgeNormal += cFI->GetNormal();
|
||||
}
|
||||
|
||||
// create a plane from the edge normal and point
|
||||
Base::Vector3f cPlaneNormal = cEdgeNormal % (cE1 - cE0);
|
||||
Handle(Geom_Plane) hPlane = new Geom_Plane(gp_Pln(gp_Pnt(cE0.x,cE0.y,cE0.z),
|
||||
gp_Dir(cPlaneNormal.x,cPlaneNormal.y,cPlaneNormal.z)));
|
||||
|
||||
// get intersection of curve and plane
|
||||
GeomAPI_IntCS Alg(hCurve,hPlane);
|
||||
if ( Alg.IsDone() ) {
|
||||
Standard_Integer nNbPoints = Alg.NbPoints();
|
||||
if ( nNbPoints == 1 ) {
|
||||
Standard_Real fU, fV, fW;
|
||||
Alg.Parameters( 1, fU, fV, fW);
|
||||
|
||||
gp_Pnt P = Alg.Point(1);
|
||||
Base::Vector3f cP0((float)P.X(), (float)P.Y(), (float)P.Z());
|
||||
|
||||
float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
|
||||
|
||||
// lies the point inside the edge?
|
||||
if ( l>=0.0f && l<=1.0f ) {
|
||||
Base::Vector3f cSplitPoint = (1-l) * cE0 + l * cE1;
|
||||
float fDist = Base::Distance( cP0, cSplitPoint );
|
||||
|
||||
if ( fDist <= fMaxDist ) {
|
||||
SplitEdge splitEdge;
|
||||
splitEdge.uE0 = uE0;
|
||||
splitEdge.uE1 = uE1;
|
||||
splitEdge.cPt = cSplitPoint;
|
||||
rParamSplitEdges[fW] = splitEdge;
|
||||
}
|
||||
}
|
||||
}
|
||||
// search for the right solution
|
||||
else if ( nNbPoints > 1 ) {
|
||||
int nCntSol=0;
|
||||
Base::Vector3f cSplitPoint;
|
||||
Standard_Real fSol;
|
||||
Base::Vector3f cP0;
|
||||
for ( int j=1; j<=nNbPoints; j++ ) {
|
||||
Standard_Real fU, fV, fW;
|
||||
Alg.Parameters( j, fU, fV, fW);
|
||||
gp_Pnt P = Alg.Point(j);
|
||||
cP0.Set((float)P.X(), (float)P.Y(), (float)P.Z());
|
||||
|
||||
float l = ( (cP0 - cE0) * (cE1 - cE0) ) / ( (cE1 - cE0) * ( cE1 - cE0) );
|
||||
|
||||
// lies the point inside the edge?
|
||||
if ( l>=0.0 && l<=1.0 ) {
|
||||
cSplitPoint = (1-l) * cE0 + l * cE1;
|
||||
float fDist = Base::Distance( cP0, cSplitPoint );
|
||||
|
||||
if (fDist <= fMaxDist) {
|
||||
nCntSol++;
|
||||
fSol = fW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ok, only one sensible solution
|
||||
if ( nCntSol == 1 ) {
|
||||
SplitEdge splitEdge;
|
||||
splitEdge.uE0 = uE0;
|
||||
splitEdge.uE1 = uE1;
|
||||
splitEdge.cPt = cSplitPoint;
|
||||
rParamSplitEdges[fSol] = splitEdge;
|
||||
}
|
||||
else if ( nCntSol > 1 ) {
|
||||
Base::Console().Log("More than one possible intersection points\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sorted by parameter
|
||||
for (std::map<Standard_Real, SplitEdge>::iterator itS =
|
||||
rParamSplitEdges.begin(); itS != rParamSplitEdges.end(); ++itS) {
|
||||
rSplitEdges.push_back( itS->second );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace MeshCore
|
||||
{
|
||||
class MeshKernel;
|
||||
class MeshGeomFacet;
|
||||
class MeshFacetGrid;
|
||||
};
|
||||
|
||||
using MeshCore::MeshKernel;
|
||||
@@ -67,8 +68,8 @@ public:
|
||||
|
||||
template<class T>
|
||||
struct TopoDSLess : public std::binary_function<T, T, bool> {
|
||||
bool operator()(const T& x, const T& y) const {
|
||||
return x.HashCode(INT_MAX-1) < y.HashCode(INT_MAX-1);
|
||||
bool operator()(const T& x, const T& y) const {
|
||||
return x.HashCode(INT_MAX-1) < y.HashCode(INT_MAX-1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -156,6 +157,45 @@ protected:
|
||||
virtual void Do();
|
||||
};
|
||||
|
||||
/**
|
||||
* The MeshProjection class projects a shape onto a mesh.
|
||||
* @author Werner Mayer
|
||||
*/
|
||||
class MeshPartExport MeshProjection
|
||||
{
|
||||
public:
|
||||
/// Helper class
|
||||
struct SplitEdge
|
||||
{
|
||||
unsigned long uE0, uE1; /**< start and endpoint of an edge */
|
||||
Base::Vector3f cPt; /**< Point on edge (\a uE0, \a uE1) */
|
||||
};
|
||||
|
||||
/// Construction
|
||||
MeshProjection(const MeshKernel& rMesh);
|
||||
/// Destruction
|
||||
~MeshProjection();
|
||||
|
||||
/**
|
||||
* Searches all edges that intersect with the projected curve \a aShape. Therefore \a aShape must
|
||||
* contain shapes of type TopoDS_Edge, other shape types are ignored. A possible solution is
|
||||
* taken if the distance between the curve point and the projected point is <= \a fMaxDist.
|
||||
*/
|
||||
void projectToMesh (const TopoDS_Shape &aShape, float fMaxDist, std::vector<SplitEdge>& rSplitEdges) const;
|
||||
/**
|
||||
* Cuts the mesh at the curve defined by \a aShape. This method call @ref projectToMesh() to get the
|
||||
* split the facet at the found points. @see projectToMesh() for more details.
|
||||
*/
|
||||
void splitMeshByShape (const TopoDS_Shape &aShape, float fMaxDist) const;
|
||||
|
||||
protected:
|
||||
void projectEdgeToEdge(const TopoDS_Edge &aCurve, float fMaxDist, const MeshCore::MeshFacetGrid& rGrid,
|
||||
std::vector<SplitEdge>& rSplitEdges) const;
|
||||
|
||||
private:
|
||||
const MeshKernel& _rcMesh;
|
||||
};
|
||||
|
||||
} // namespace MeshPart
|
||||
|
||||
#endif
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
#include <TColStd_SequenceOfExtendedString.hxx>
|
||||
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepBuilderAPI.hxx>
|
||||
@@ -145,6 +146,7 @@
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <GCE2d_MakeSegment.hxx>
|
||||
#include <GCPnts_TangentialDeflection.hxx>
|
||||
#include <GCPnts_UniformDeflection.hxx>
|
||||
#include <Geom_Axis2Placement.hxx>
|
||||
#include <Geom_CartesianPoint.hxx>
|
||||
#include <Geom_Line.hxx>
|
||||
@@ -171,6 +173,7 @@
|
||||
#include <Geom_Parabola.hxx>
|
||||
#include <Geom_Plane.hxx>
|
||||
#include <Geom_ToroidalSurface.hxx>
|
||||
#include <GeomAPI_IntCS.hxx>
|
||||
#include <GeomTools_Curve2dSet.hxx>
|
||||
#include <gp_Ax2d.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
@@ -228,6 +231,8 @@
|
||||
#include <TopTools_HSequenceOfShape.hxx>
|
||||
#include <TopTools_MapOfShape.hxx>
|
||||
#include <UnitsAPI.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <BndLib_Add3dCurve.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <BRepPrimAPI_MakeCylinder.hxx>
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace TechDraw
|
||||
|
||||
class TechDrawExport DrawLeaderLine : public TechDraw::DrawView
|
||||
{
|
||||
PROPERTY_HEADER(TechDraw::DrawLeaderLine);
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawLeaderLine);
|
||||
|
||||
public:
|
||||
DrawLeaderLine();
|
||||
@@ -49,16 +49,16 @@ public:
|
||||
App::PropertyBool Scalable;
|
||||
App::PropertyBool AutoHorizontal;
|
||||
|
||||
virtual short mustExecute() const;
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual short mustExecute() const override;
|
||||
virtual App::DocumentObjectExecReturn *execute(void) override;
|
||||
virtual void onDocumentRestored(void) override;
|
||||
|
||||
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
virtual const char* getViewProviderName(void) const override {
|
||||
return "TechDrawGui::ViewProviderLeader";
|
||||
}
|
||||
virtual PyObject *getPyObject(void);
|
||||
virtual QRectF getRect() const { return QRectF(0,0,1,1);}
|
||||
virtual PyObject *getPyObject(void) override;
|
||||
virtual QRectF getRect() const override { return QRectF(0,0,1,1);}
|
||||
|
||||
Base::Vector3d getAttachPoint(void);
|
||||
DrawView* getBaseView(void) const;
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
virtual void onChanged(const App::Property* prop) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
|
||||
enum {Type = QGraphicsItem::UserType + 210};
|
||||
|
||||
int type() const { return Type;}
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
|
||||
int type() const override { return Type;}
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) override;
|
||||
virtual QPainterPath shape() const override;
|
||||
virtual QRectF boundingRect() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user