From c6bc17ffc13aee4d38d2938800ef5002fc874fc3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 2 Sep 2023 11:46:46 +0200 Subject: [PATCH] RE: apply clang format --- src/Mod/MeshPart/Init.py | 44 +- src/Mod/MeshPart/InitGui.py | 49 +- src/Mod/MeshPart/MeshPartGlobal.h | 10 +- .../App/AppReverseEngineering.cpp | 15 +- .../ReverseEngineering/App/ApproxSurface.cpp | 1037 ++++++++++------- .../ReverseEngineering/App/ApproxSurface.h | 161 +-- .../ReverseEngineering/App/BSplineFitting.cpp | 118 +- .../ReverseEngineering/App/BSplineFitting.h | 15 +- src/Mod/ReverseEngineering/App/PreCompiled.h | 18 +- .../ReverseEngineering/App/RegionGrowing.cpp | 131 ++- .../ReverseEngineering/App/RegionGrowing.h | 25 +- .../App/SampleConsensus.cpp | 117 +- .../ReverseEngineering/App/SampleConsensus.h | 29 +- .../ReverseEngineering/App/Segmentation.cpp | 182 +-- src/Mod/ReverseEngineering/App/Segmentation.h | 46 +- .../App/SurfaceTriangulation.cpp | 490 ++++---- .../App/SurfaceTriangulation.h | 151 +-- src/Mod/ReverseEngineering/InitGui.py | 54 +- .../ReverseEngineeringGlobal.h | 10 +- 19 files changed, 1465 insertions(+), 1237 deletions(-) diff --git a/src/Mod/MeshPart/Init.py b/src/Mod/MeshPart/Init.py index dd8dea3aee..d6eb27fe80 100644 --- a/src/Mod/MeshPart/Init.py +++ b/src/Mod/MeshPart/Init.py @@ -1,25 +1,25 @@ # FreeCAD init script of the MeshPart module # (c) 2001 Juergen Riegel -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ diff --git a/src/Mod/MeshPart/InitGui.py b/src/Mod/MeshPart/InitGui.py index 17d0102f1f..c4cea6af20 100644 --- a/src/Mod/MeshPart/InitGui.py +++ b/src/Mod/MeshPart/InitGui.py @@ -5,31 +5,31 @@ # This is the second one of three init scripts, the third one # runs when the gui is up -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ -class MeshPartWorkbench ( Workbench ): +class MeshPartWorkbench(Workbench): "MeshPart workbench object" Icon = """ /* XPM */ @@ -58,14 +58,13 @@ class MeshPartWorkbench ( Workbench ): MenuText = "MeshPart" ToolTip = "MeshPart workbench" - def Initialize(self): # load the module import MeshPartGui import MeshPart - def GetClassName(self): return "MeshPartGui::Workbench" + # Gui.addWorkbench(MeshPartWorkbench()) diff --git a/src/Mod/MeshPart/MeshPartGlobal.h b/src/Mod/MeshPart/MeshPartGlobal.h index 38af3fd22a..3978649a9c 100644 --- a/src/Mod/MeshPart/MeshPartGlobal.h +++ b/src/Mod/MeshPart/MeshPartGlobal.h @@ -29,19 +29,19 @@ // MeshPart #ifndef MeshPartExport #ifdef MeshPart_EXPORTS -# define MeshPartExport FREECAD_DECL_EXPORT +#define MeshPartExport FREECAD_DECL_EXPORT #else -# define MeshPartExport FREECAD_DECL_IMPORT +#define MeshPartExport FREECAD_DECL_IMPORT #endif #endif // MeshPartGui #ifndef MeshPartGuiExport #ifdef MeshPartGui_EXPORTS -# define MeshPartGuiExport FREECAD_DECL_EXPORT +#define MeshPartGuiExport FREECAD_DECL_EXPORT #else -# define MeshPartGuiExport FREECAD_DECL_IMPORT +#define MeshPartGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //MESHPART_GLOBAL_H +#endif// MESHPART_GLOBAL_H diff --git a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp index 1f2a4cd1f5..61a107583a 100644 --- a/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp +++ b/src/Mod/ReverseEngineering/App/AppReverseEngineering.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -31,13 +31,13 @@ #include #include #include -#include #include +#include #include #if defined(HAVE_PCL_FILTERS) -# include -# include -# include +#include +#include +#include #endif #include "ApproxSurface.h" @@ -47,7 +47,7 @@ #include "Segmentation.h" #include "SurfaceTriangulation.h" - +// clang-format off /* Dependency of pcl components: common: none @@ -855,3 +855,4 @@ PyMOD_INIT_FUNC(ReverseEngineering) Base::Console().Log("Loading ReverseEngineering module... done\n"); PyMOD_Return(mod); } +// clang-format on diff --git a/src/Mod/ReverseEngineering/App/ApproxSurface.cpp b/src/Mod/ReverseEngineering/App/ApproxSurface.cpp index 9318dcd89e..ed506ec0db 100644 --- a/src/Mod/ReverseEngineering/App/ApproxSurface.cpp +++ b/src/Mod/ReverseEngineering/App/ApproxSurface.cpp @@ -22,14 +22,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -45,28 +45,29 @@ namespace sp = std::placeholders; // SplineBasisfunction SplineBasisfunction::SplineBasisfunction(int iSize) - : _vKnotVector(0,iSize-1) - , _iOrder(1) -{ -} + : _vKnotVector(0, iSize - 1) + , _iOrder(1) +{} SplineBasisfunction::SplineBasisfunction(TColStd_Array1OfReal& vKnots, TColStd_Array1OfInteger& vMults, - int iSize, int iOrder) - : _vKnotVector(0,iSize-1) + int iSize, + int iOrder) + : _vKnotVector(0, iSize - 1) { int sum = 0; - for (int h=vMults.Lower(); h<=vMults.Upper(); h++) + for (int h = vMults.Lower(); h <= vMults.Upper(); h++) { sum += vMults(h); + } if (vKnots.Length() != vMults.Length() || iSize != sum) { // Throw exception Standard_ConstructionError::Raise("BSplineBasis"); } - int k=0; - for (int i=vMults.Lower(); i<=vMults.Upper(); i++) { - for (int j=0; j= _vKnotVector(mid+1)) { - if (fParam < _vKnotVector(mid)) + while (fParam < _vKnotVector(mid) || fParam >= _vKnotVector(mid + 1)) { + if (fParam < _vKnotVector(mid)) { high = mid; - else + } + else { low = mid; - mid = (low+high)/2; + } + mid = (low + high) / 2; } return mid; @@ -156,23 +164,24 @@ int BSplineBasis::FindSpan(double fParam) void BSplineBasis::AllBasisFunctions(double fParam, TColStd_Array1OfReal& vFuncVals) { - if (vFuncVals.Length() != _iOrder) + if (vFuncVals.Length() != _iOrder) { Standard_RangeError::Raise("BSplineBasis"); + } int iIndex = FindSpan(fParam); - TColStd_Array1OfReal zaehler_left(1,_iOrder-1); - TColStd_Array1OfReal zaehler_right(1,_iOrder-1); + TColStd_Array1OfReal zaehler_left(1, _iOrder - 1); + TColStd_Array1OfReal zaehler_right(1, _iOrder - 1); vFuncVals(0) = 1.0; - for (int j=1; j<_iOrder; j++) { - zaehler_left(j) = fParam - _vKnotVector(iIndex+1-j); - zaehler_right(j) = _vKnotVector(iIndex+j) - fParam; + for (int j = 1; j < _iOrder; j++) { + zaehler_left(j) = fParam - _vKnotVector(iIndex + 1 - j); + zaehler_right(j) = _vKnotVector(iIndex + j) - fParam; double saved = 0.0; - for (int r=0; r= _vKnotVector(iIndex+p+1)) { + if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex + p + 1)) { return BSplineBasis::Zero; } @@ -198,45 +207,50 @@ BSplineBasis::ValueT BSplineBasis::LocalSupport(int iIndex, double fParam) double BSplineBasis::BasisFunction(int iIndex, double fParam) { - int m = _vKnotVector.Length()-1; - int p = _iOrder-1; + int m = _vKnotVector.Length() - 1; + int p = _iOrder - 1; double saved; - TColStd_Array1OfReal N(0,p); + TColStd_Array1OfReal N(0, p); - if ((iIndex == 0 && fParam == _vKnotVector(0)) || - (iIndex == m-p-1 && fParam == _vKnotVector(m))) { + if ((iIndex == 0 && fParam == _vKnotVector(0)) + || (iIndex == m - p - 1 && fParam == _vKnotVector(m))) { return 1.0; } - if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex+p+1)) { + if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex + p + 1)) { return 0.0; } - for (int j=0; j<=p; j++) { - if (fParam >= _vKnotVector(iIndex+j) && fParam < _vKnotVector(iIndex+j+1)) + for (int j = 0; j <= p; j++) { + if (fParam >= _vKnotVector(iIndex + j) && fParam < _vKnotVector(iIndex + j + 1)) { N(j) = 1.0; - else + } + else { N(j) = 0.0; + } } - for (int k=1; k<=p; k++) { - if (N(0) == 0.0) + for (int k = 1; k <= p; k++) { + if (N(0) == 0.0) { saved = 0.0; - else - saved = ((fParam - _vKnotVector(iIndex))*N(0)) / (_vKnotVector(iIndex+k) - _vKnotVector(iIndex)); + } + else { + saved = ((fParam - _vKnotVector(iIndex)) * N(0)) + / (_vKnotVector(iIndex + k) - _vKnotVector(iIndex)); + } - for (int j=0; j degrees) are zero + } + // kth derivatives (k> degrees) are zero if (iMax >= _iOrder) { - for (int i=_iOrder; i<=iMaxDer; i++) + for (int i = _iOrder; i <= iMaxDer; i++) { Derivat(i) = 0.0; + } iMax = _iOrder - 1; } TColStd_Array1OfReal ND(0, iMax); - int p = _iOrder-1; - math_Matrix N(0,p,0,p); + int p = _iOrder - 1; + math_Matrix N(0, p, 0, p); double saved; // if value is outside the interval, then function value and all derivatives equal null - if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex+p+1)) { - for (int k=0; k<=iMax; k++) + if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex + p + 1)) { + for (int k = 0; k <= iMax; k++) { Derivat(k) = 0.0; + } return; } // Calculate the basis functions of Order 1 - for (int j=0; j<_iOrder; j++) { - if (fParam >= _vKnotVector(iIndex+j) && fParam < _vKnotVector(iIndex+j+1)) - N(j,0) = 1.0; - else - N(j,0) = 0.0; + for (int j = 0; j < _iOrder; j++) { + if (fParam >= _vKnotVector(iIndex + j) && fParam < _vKnotVector(iIndex + j + 1)) { + N(j, 0) = 1.0; + } + else { + N(j, 0) = 0.0; + } } // Calculate a triangular table of the function values - for (int k=1; k<_iOrder; k++) { - if (N(0,k-1) == 0.0) + for (int k = 1; k < _iOrder; k++) { + if (N(0, k - 1) == 0.0) { saved = 0.0; - else - saved = ((fParam - _vKnotVector(iIndex))*N(0,k-1))/(_vKnotVector(iIndex+k)-_vKnotVector(iIndex)); - for (int j=0; jdegrees) are null if (iMax >= _iOrder) { @@ -347,100 +374,108 @@ double BSplineBasis::DerivativeOfBasisFunction(int iIndex, int iMaxDer, double f } TColStd_Array1OfReal ND(0, iMax); - int p = _iOrder-1; - math_Matrix N(0,p,0,p); + int p = _iOrder - 1; + math_Matrix N(0, p, 0, p); double saved; // If value is outside the interval, then function value and derivatives equal null - if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex+p+1)) { + if (fParam < _vKnotVector(iIndex) || fParam >= _vKnotVector(iIndex + p + 1)) { return 0.0; } // Calculate the basis functions of Order 1 - for (int j=0; j<_iOrder; j++) { - if (fParam >= _vKnotVector(iIndex+j) && fParam < _vKnotVector(iIndex+j+1)) - N(j,0) = 1.0; - else - N(j,0) = 0.0; + for (int j = 0; j < _iOrder; j++) { + if (fParam >= _vKnotVector(iIndex + j) && fParam < _vKnotVector(iIndex + j + 1)) { + N(j, 0) = 1.0; + } + else { + N(j, 0) = 0.0; + } } // Calculate triangular table of function values - for (int k=1; k<_iOrder; k++) { - if (N(0,k-1) == 0.0) + for (int k = 1; k < _iOrder; k++) { + if (N(0, k - 1) == 0.0) { saved = 0.0; - else - saved = ((fParam - _vKnotVector(iIndex))*N(0,k-1))/(_vKnotVector(iIndex+k)-_vKnotVector(iIndex)); + } + else { + saved = ((fParam - _vKnotVector(iIndex)) * N(0, k - 1)) + / (_vKnotVector(iIndex + k) - _vKnotVector(iIndex)); + } - for (int j=0; j fMin) { - for (int i=0; i<=iMax; i++) { - double fParam = 0.5*(vRoots(i)+1)*(fMax-fMin)+fMin; - dIntegral += 0.5*(fMax-fMin)*vWeights(i) * - DerivativeOfBasisFunction(iIdx1, iOrd1, fParam) * - DerivativeOfBasisFunction(iIdx2, iOrd2, fParam); + for (int i = 0; i <= iMax; i++) { + double fParam = 0.5 * (vRoots(i) + 1) * (fMax - fMin) + fMin; + dIntegral += 0.5 * (fMax - fMin) * vWeights(i) + * DerivativeOfBasisFunction(iIdx1, iOrd1, fParam) + * DerivativeOfBasisFunction(iIdx2, iOrd2, fParam); } } } @@ -448,67 +483,111 @@ double BSplineBasis::GetIntegralOfProductOfBSplines(int iIdx1, int iIdx2, int iO return dIntegral; } -void BSplineBasis::GenerateRootsAndWeights(TColStd_Array1OfReal& vRoots, TColStd_Array1OfReal& vWeights) +void BSplineBasis::GenerateRootsAndWeights(TColStd_Array1OfReal& vRoots, + TColStd_Array1OfReal& vWeights) { int iSize = vRoots.Length(); // Zeroing the Legendre-Polynomials and the corresponding weights if (iSize == 1) { - vRoots(0) = 0.0; vWeights(0) = 2.0; + vRoots(0) = 0.0; + vWeights(0) = 2.0; } else if (iSize == 2) { - vRoots(0) = 0.57735; vWeights(0) = 1.0; - vRoots(1) = -vRoots(0); vWeights(1) = vWeights(0); + vRoots(0) = 0.57735; + vWeights(0) = 1.0; + vRoots(1) = -vRoots(0); + vWeights(1) = vWeights(0); } else if (iSize == 4) { - vRoots(0) = 0.33998; vWeights(0) = 0.65214; - vRoots(1) = 0.86113; vWeights(1) = 0.34785; - vRoots(2) = -vRoots(0); vWeights(2) = vWeights(0); - vRoots(3) = -vRoots(1); vWeights(3) = vWeights(1); + vRoots(0) = 0.33998; + vWeights(0) = 0.65214; + vRoots(1) = 0.86113; + vWeights(1) = 0.34785; + vRoots(2) = -vRoots(0); + vWeights(2) = vWeights(0); + vRoots(3) = -vRoots(1); + vWeights(3) = vWeights(1); } else if (iSize == 6) { - vRoots(0) = 0.23861; vWeights(0) = 0.46791; - vRoots(1) = 0.66120; vWeights(1) = 0.36076; - vRoots(2) = 0.93246; vWeights(2) = 0.17132; - vRoots(3) = -vRoots(0); vWeights(3) = vWeights(0); - vRoots(4) = -vRoots(1); vWeights(4) = vWeights(1); - vRoots(5) = -vRoots(2); vWeights(5) = vWeights(2); + vRoots(0) = 0.23861; + vWeights(0) = 0.46791; + vRoots(1) = 0.66120; + vWeights(1) = 0.36076; + vRoots(2) = 0.93246; + vWeights(2) = 0.17132; + vRoots(3) = -vRoots(0); + vWeights(3) = vWeights(0); + vRoots(4) = -vRoots(1); + vWeights(4) = vWeights(1); + vRoots(5) = -vRoots(2); + vWeights(5) = vWeights(2); } else if (iSize == 8) { - vRoots(0) = 0.18343; vWeights(0) = 0.36268; - vRoots(1) = 0.52553; vWeights(1) = 0.31370; - vRoots(2) = 0.79666; vWeights(2) = 0.22238; - vRoots(3) = 0.96028; vWeights(3) = 0.10122; - vRoots(4) = -vRoots(0); vWeights(4) = vWeights(0); - vRoots(5) = -vRoots(1); vWeights(5) = vWeights(1); - vRoots(6) = -vRoots(2); vWeights(6) = vWeights(2); - vRoots(7) = -vRoots(3); vWeights(7) = vWeights(3); + vRoots(0) = 0.18343; + vWeights(0) = 0.36268; + vRoots(1) = 0.52553; + vWeights(1) = 0.31370; + vRoots(2) = 0.79666; + vWeights(2) = 0.22238; + vRoots(3) = 0.96028; + vWeights(3) = 0.10122; + vRoots(4) = -vRoots(0); + vWeights(4) = vWeights(0); + vRoots(5) = -vRoots(1); + vWeights(5) = vWeights(1); + vRoots(6) = -vRoots(2); + vWeights(6) = vWeights(2); + vRoots(7) = -vRoots(3); + vWeights(7) = vWeights(3); } else if (iSize == 10) { - vRoots(0) = 0.14887; vWeights(0) = 0.29552; - vRoots(1) = 0.43339; vWeights(1) = 0.26926; - vRoots(2) = 0.67940; vWeights(2) = 0.21908; - vRoots(3) = 0.86506; vWeights(3) = 0.14945; - vRoots(4) = 0.97390; vWeights(4) = 0.06667; - vRoots(5) = -vRoots(0); vWeights(5) = vWeights(0); - vRoots(6) = -vRoots(1); vWeights(6) = vWeights(1); - vRoots(7) = -vRoots(2); vWeights(7) = vWeights(2); - vRoots(8) = -vRoots(3); vWeights(8) = vWeights(3); - vRoots(9) = -vRoots(4); vWeights(9) = vWeights(4); + vRoots(0) = 0.14887; + vWeights(0) = 0.29552; + vRoots(1) = 0.43339; + vWeights(1) = 0.26926; + vRoots(2) = 0.67940; + vWeights(2) = 0.21908; + vRoots(3) = 0.86506; + vWeights(3) = 0.14945; + vRoots(4) = 0.97390; + vWeights(4) = 0.06667; + vRoots(5) = -vRoots(0); + vWeights(5) = vWeights(0); + vRoots(6) = -vRoots(1); + vWeights(6) = vWeights(1); + vRoots(7) = -vRoots(2); + vWeights(7) = vWeights(2); + vRoots(8) = -vRoots(3); + vWeights(8) = vWeights(3); + vRoots(9) = -vRoots(4); + vWeights(9) = vWeights(4); } else { - vRoots(0) = 0.12523; vWeights(0) = 0.24914; - vRoots(1) = 0.36783; vWeights(1) = 0.23349; - vRoots(2) = 0.58731; vWeights(2) = 0.20316; - vRoots(3) = 0.76990; vWeights(3) = 0.16007; - vRoots(4) = 0.90411; vWeights(4) = 0.10693; - vRoots(5) = 0.98156; vWeights(5) = 0.04717; - vRoots(6) = -vRoots(0); vWeights(6) = vWeights(0); - vRoots(7) = -vRoots(1); vWeights(7) = vWeights(1); - vRoots(8) = -vRoots(2); vWeights(8) = vWeights(2); - vRoots(9) = -vRoots(3); vWeights(9) = vWeights(3); - vRoots(10)= -vRoots(4); vWeights(10)= vWeights(4); - vRoots(11)= -vRoots(5); vWeights(11)= vWeights(5); + vRoots(0) = 0.12523; + vWeights(0) = 0.24914; + vRoots(1) = 0.36783; + vWeights(1) = 0.23349; + vRoots(2) = 0.58731; + vWeights(2) = 0.20316; + vRoots(3) = 0.76990; + vWeights(3) = 0.16007; + vRoots(4) = 0.90411; + vWeights(4) = 0.10693; + vRoots(5) = 0.98156; + vWeights(5) = 0.04717; + vRoots(6) = -vRoots(0); + vWeights(6) = vWeights(0); + vRoots(7) = -vRoots(1); + vWeights(7) = vWeights(1); + vRoots(8) = -vRoots(2); + vWeights(8) = vWeights(2); + vRoots(9) = -vRoots(3); + vWeights(9) = vWeights(3); + vRoots(10) = -vRoots(4); + vWeights(10) = vWeights(4); + vRoots(11) = -vRoots(5); + vWeights(11) = vWeights(5); } } @@ -516,50 +595,60 @@ void BSplineBasis::FindIntegrationArea(int iIdx1, int iIdx2, int& iBegin, int& i { // order by index if (iIdx2 < iIdx1) { - int tmp=iIdx1; + int tmp = iIdx1; iIdx1 = iIdx2; iIdx2 = tmp; } iBegin = iIdx2; - iEnd = iIdx1+_iOrder; - if (iEnd == _vKnotVector.Upper()) + iEnd = iIdx1 + _iOrder; + if (iEnd == _vKnotVector.Upper()) { iEnd -= 1; + } } int BSplineBasis::CalcSize(int r, int s) { - int iMaxDegree = 2*(_iOrder-1)-r-s; + int iMaxDegree = 2 * (_iOrder - 1) - r - s; - if (iMaxDegree < 0) + if (iMaxDegree < 0) { return 0; - else if (iMaxDegree < 4) + } + else if (iMaxDegree < 4) { return 1; - else if (iMaxDegree < 8) + } + else if (iMaxDegree < 8) { return 3; - else if (iMaxDegree < 12) + } + else if (iMaxDegree < 12) { return 5; - else if (iMaxDegree < 16) + } + else if (iMaxDegree < 16) { return 7; - else if (iMaxDegree < 20) + } + else if (iMaxDegree < 20) { return 9; - else + } + else { return 11; + } } /////////////////// ParameterCorrection -ParameterCorrection::ParameterCorrection(unsigned usUOrder, unsigned usVOrder, - unsigned usUCtrlpoints, unsigned usVCtrlpoints) - : _usUOrder(usUOrder) - , _usVOrder(usVOrder) - , _usUCtrlpoints(usUCtrlpoints) - , _usVCtrlpoints(usVCtrlpoints) - , _vCtrlPntsOfSurf(0,usUCtrlpoints-1,0,usVCtrlpoints-1) - , _vUKnots(0,usUCtrlpoints-usUOrder+1) - , _vVKnots(0,usVCtrlpoints-usVOrder+1) - , _vUMults(0,usUCtrlpoints-usUOrder+1) - , _vVMults(0,usVCtrlpoints-usVOrder+1) +ParameterCorrection::ParameterCorrection(unsigned usUOrder, + unsigned usVOrder, + unsigned usUCtrlpoints, + unsigned usVCtrlpoints) + : _usUOrder(usUOrder) + , _usVOrder(usVOrder) + , _usUCtrlpoints(usUCtrlpoints) + , _usVCtrlpoints(usVCtrlpoints) + , _vCtrlPntsOfSurf(0, usUCtrlpoints - 1, 0, usVCtrlpoints - 1) + , _vUKnots(0, usUCtrlpoints - usUOrder + 1) + , _vVKnots(0, usVCtrlpoints - usVOrder + 1) + , _vUMults(0, usUCtrlpoints - usUOrder + 1) + , _vVMults(0, usVCtrlpoints - usVOrder + 1) { _bGetUVDir = false; _bSmoothing = false; @@ -569,7 +658,7 @@ ParameterCorrection::ParameterCorrection(unsigned usUOrder, unsigned usVOrder, void ParameterCorrection::CalcEigenvectors() { MeshCore::PlaneFit planeFit; - for (int i=_pvcPoints->Lower(); i<=_pvcPoints->Upper(); i++) { + for (int i = _pvcPoints->Lower(); i <= _pvcPoints->Upper(); i++) { const gp_Pnt& pnt = (*_pvcPoints)(i); planeFit.AddPoint(Base::Vector3f((float)pnt.X(), (float)pnt.Y(), (float)pnt.Z())); } @@ -583,17 +672,21 @@ void ParameterCorrection::CalcEigenvectors() bool ParameterCorrection::DoInitialParameterCorrection(double fSizeFactor) { // if directions are not given, calculate yourself - if (!_bGetUVDir) + if (!_bGetUVDir) { CalcEigenvectors(); - if (!GetUVParameters(fSizeFactor)) + } + if (!GetUVParameters(fSizeFactor)) { return false; + } if (_bSmoothing) { - if (!SolveWithSmoothing(_fSmoothInfluence)) + if (!SolveWithSmoothing(_fSmoothInfluence)) { return false; + } } else { - if (!SolveWithoutSmoothing()) + if (!SolveWithoutSmoothing()) { return false; + } } return true; @@ -609,9 +702,11 @@ bool ParameterCorrection::GetUVParameters(double fSizeFactor) // Canonical base of R^3 Base::Vector3d b[3]; - b[0]=Base::Vector3d(1.0,0.0,0.0); b[1]=Base::Vector3d(0.0,1.0,0.0);b[2]=Base::Vector3d(0.0,0.0,1.0); + b[0] = Base::Vector3d(1.0, 0.0, 0.0); + b[1] = Base::Vector3d(0.0, 1.0, 0.0); + b[2] = Base::Vector3d(0.0, 0.0, 1.0); // Create a right system from the orthogonal eigenvectors - if ((e[0]%e[1])*e[2] < 0) { + if ((e[0] % e[1]) * e[2] < 0) { Base::Vector3d tmp = e[0]; e[0] = e[1]; e[1] = tmp; @@ -619,9 +714,9 @@ bool ParameterCorrection::GetUVParameters(double fSizeFactor) // Now generate the transpon. Rotation matrix Wm4::Matrix3d clRotMatTrans; - for (int i=0; i<3; i++) { - for (int j=0; j<3; j++) { - clRotMatTrans[i][j] = b[j]*e[i]; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + clRotMatTrans[i][j] = b[j] * e[i]; } } @@ -630,32 +725,33 @@ bool ParameterCorrection::GetUVParameters(double fSizeFactor) // Calculate the coordinates of the transf. Points and project // these on to the x,y-plane of the new coordinate system - for (int ii=_pvcPoints->Lower(); ii<=_pvcPoints->Upper(); ii++) { + for (int ii = _pvcPoints->Lower(); ii <= _pvcPoints->Upper(); ii++) { const gp_Pnt& pnt = (*_pvcPoints)(ii); Wm4::Vector3d clProjPnt = clRotMatTrans * Wm4::Vector3d(pnt.X(), pnt.Y(), pnt.Z()); vcProjPts.emplace_back(clProjPnt.X(), clProjPnt.Y()); clBBox.Add(Base::Vector2d(clProjPnt.X(), clProjPnt.Y())); } - if ((clBBox.MaxX == clBBox.MinX) || (clBBox.MaxY == clBBox.MinY)) + if ((clBBox.MaxX == clBBox.MinX) || (clBBox.MaxY == clBBox.MinY)) { return false; - double tx = fSizeFactor*clBBox.MinX-(fSizeFactor-1.0)*clBBox.MaxX; - double ty = fSizeFactor*clBBox.MinY-(fSizeFactor-1.0)*clBBox.MaxY; - double fDeltaX = (2*fSizeFactor-1.0)*(clBBox.MaxX - clBBox.MinX); - double fDeltaY = (2*fSizeFactor-1.0)*(clBBox.MaxY - clBBox.MinY); + } + double tx = fSizeFactor * clBBox.MinX - (fSizeFactor - 1.0) * clBBox.MaxX; + double ty = fSizeFactor * clBBox.MinY - (fSizeFactor - 1.0) * clBBox.MaxY; + double fDeltaX = (2 * fSizeFactor - 1.0) * (clBBox.MaxX - clBBox.MinX); + double fDeltaY = (2 * fSizeFactor - 1.0) * (clBBox.MaxY - clBBox.MinY); // Calculate the u,v parameters with u,v from [0,1] _pvcUVParam->Init(gp_Pnt2d(0.0, 0.0)); - int ii=0; + int ii = 0; if (clBBox.MaxX - clBBox.MinX >= clBBox.MaxY - clBBox.MinY) { - for (const auto & pt : vcProjPts) { - (*_pvcUVParam)(ii) = gp_Pnt2d((pt.x-tx)/fDeltaX, (pt.y-ty)/fDeltaY); + for (const auto& pt : vcProjPts) { + (*_pvcUVParam)(ii) = gp_Pnt2d((pt.x - tx) / fDeltaX, (pt.y - ty) / fDeltaY); ii++; } } else { - for (const auto & pt : vcProjPts) { - (*_pvcUVParam)(ii) = gp_Pnt2d((pt.y-ty)/fDeltaY, (pt.x-tx)/fDeltaX); + for (const auto& pt : vcProjPts) { + (*_pvcUVParam)(ii) = gp_Pnt2d((pt.y - ty) / fDeltaY, (pt.x - tx) / fDeltaX); ii++; } } @@ -673,7 +769,9 @@ void ParameterCorrection::SetUV(const Base::Vector3d& clU, const Base::Vector3d& } } -void ParameterCorrection::GetUVW(Base::Vector3d& clU, Base::Vector3d& clV, Base::Vector3d& clW) const +void ParameterCorrection::GetUVW(Base::Vector3d& clU, + Base::Vector3d& clV, + Base::Vector3d& clW) const { clU = _clU; clV = _clV; @@ -683,36 +781,36 @@ void ParameterCorrection::GetUVW(Base::Vector3d& clU, Base::Vector3d& clV, Base: Base::Vector3d ParameterCorrection::GetGravityPoint() const { Standard_Integer ulSize = _pvcPoints->Length(); - double x=0.0, y=0.0, z=0.0; - for (int i=_pvcPoints->Lower(); i<=_pvcPoints->Upper(); i++) { + double x = 0.0, y = 0.0, z = 0.0; + for (int i = _pvcPoints->Lower(); i <= _pvcPoints->Upper(); i++) { const gp_Pnt& pnt = (*_pvcPoints)(i); x += pnt.X(); y += pnt.Y(); z += pnt.Z(); } - return Base::Vector3d(x/ulSize, y/ulSize, z/ulSize); + return Base::Vector3d(x / ulSize, y / ulSize, z / ulSize); } void ParameterCorrection::ProjectControlPointsOnPlane() { Base::Vector3d base = GetGravityPoint(); - for (unsigned j=0;j<_usUCtrlpoints;j++) { - for (unsigned k=0;k<_usVCtrlpoints;k++) { - gp_Pnt pole = _vCtrlPntsOfSurf(j,k); + for (unsigned j = 0; j < _usUCtrlpoints; j++) { + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + gp_Pnt pole = _vCtrlPntsOfSurf(j, k); Base::Vector3d pnt(pole.X(), pole.Y(), pole.Z()); pnt.ProjectToPlane(base, _clW); pole.SetX(pnt.x); pole.SetY(pnt.y); pole.SetZ(pnt.z); - _vCtrlPntsOfSurf(j,k) = pole; + _vCtrlPntsOfSurf(j, k) = pole; } } } Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Array1OfPnt& points, int iIter, - bool bParaCor, + bool bParaCor, double fSizeFactor) { if (_pvcPoints) { @@ -726,10 +824,12 @@ Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Arra *_pvcPoints = points; _pvcUVParam = new TColgp_Array1OfPnt2d(points.Lower(), points.Upper()); - if (_usUCtrlpoints*_usVCtrlpoints > static_cast(_pvcPoints->Length())) - return nullptr; // LGS under-determined - if (!DoInitialParameterCorrection(fSizeFactor)) + if (_usUCtrlpoints * _usVCtrlpoints > static_cast(_pvcPoints->Length())) { + return nullptr;// LGS under-determined + } + if (!DoInitialParameterCorrection(fSizeFactor)) { return nullptr; + } // Generate the approximation plane as a B-spline area if (iIter < 0) { @@ -741,11 +841,17 @@ Handle(Geom_BSplineSurface) ParameterCorrection::CreateSurface(const TColgp_Arra bParaCor = false; } - if (bParaCor) + if (bParaCor) { DoParameterCorrection(iIter); + } - return new Geom_BSplineSurface(_vCtrlPntsOfSurf, _vUKnots, _vVKnots, - _vUMults, _vVMults, _usUOrder-1, _usVOrder-1); + return new Geom_BSplineSurface(_vCtrlPntsOfSurf, + _vUKnots, + _vVKnots, + _vUMults, + _vVMults, + _usUOrder - 1, + _usVOrder - 1); } void ParameterCorrection::EnableSmoothing(bool bSmooth, double fSmoothInfl) @@ -757,19 +863,17 @@ void ParameterCorrection::EnableSmoothing(bool bSmooth, double fSmoothInfl) /////////////////// BSplineParameterCorrection -BSplineParameterCorrection::BSplineParameterCorrection(unsigned usUOrder, unsigned usVOrder, - unsigned usUCtrlpoints, unsigned usVCtrlpoints) - : ParameterCorrection(usUOrder, usVOrder, usUCtrlpoints, usVCtrlpoints) - , _clUSpline(usUCtrlpoints+usUOrder) - , _clVSpline(usVCtrlpoints+usVOrder) - , _clSmoothMatrix(0,usUCtrlpoints*usVCtrlpoints-1, - 0,usUCtrlpoints*usVCtrlpoints-1) - , _clFirstMatrix (0,usUCtrlpoints*usVCtrlpoints-1, - 0,usUCtrlpoints*usVCtrlpoints-1) - , _clSecondMatrix(0,usUCtrlpoints*usVCtrlpoints-1, - 0,usUCtrlpoints*usVCtrlpoints-1) - , _clThirdMatrix (0,usUCtrlpoints*usVCtrlpoints-1, - 0,usUCtrlpoints*usVCtrlpoints-1) +BSplineParameterCorrection::BSplineParameterCorrection(unsigned usUOrder, + unsigned usVOrder, + unsigned usUCtrlpoints, + unsigned usVCtrlpoints) + : ParameterCorrection(usUOrder, usVOrder, usUCtrlpoints, usVCtrlpoints) + , _clUSpline(usUCtrlpoints + usUOrder) + , _clVSpline(usVCtrlpoints + usVOrder) + , _clSmoothMatrix(0, usUCtrlpoints * usVCtrlpoints - 1, 0, usUCtrlpoints * usVCtrlpoints - 1) + , _clFirstMatrix(0, usUCtrlpoints * usVCtrlpoints - 1, 0, usUCtrlpoints * usVCtrlpoints - 1) + , _clSecondMatrix(0, usUCtrlpoints * usVCtrlpoints - 1, 0, usUCtrlpoints * usVCtrlpoints - 1) + , _clThirdMatrix(0, usUCtrlpoints * usVCtrlpoints - 1, 0, usUCtrlpoints * usVCtrlpoints - 1) { Init(); } @@ -777,20 +881,20 @@ BSplineParameterCorrection::BSplineParameterCorrection(unsigned usUOrder, unsign void BSplineParameterCorrection::Init() { // Initializations - _pvcUVParam = nullptr; - _pvcPoints = nullptr; + _pvcUVParam = nullptr; + _pvcPoints = nullptr; _clFirstMatrix.Init(0.0); _clSecondMatrix.Init(0.0); _clThirdMatrix.Init(0.0); _clSmoothMatrix.Init(0.0); /* Calculate the knot vectors */ - unsigned usUMax = _usUCtrlpoints-_usUOrder+1; - unsigned usVMax = _usVCtrlpoints-_usVOrder+1; + unsigned usUMax = _usUCtrlpoints - _usUOrder + 1; + unsigned usVMax = _usVCtrlpoints - _usVOrder + 1; // Knot vector for the CAS.CADE class // u-direction - for (unsigned i=0;i<=usUMax; i++) { + for (unsigned i = 0; i <= usUMax; i++) { _vUKnots(i) = static_cast(i) / static_cast(usUMax); _vUMults(i) = 1; } @@ -799,7 +903,7 @@ void BSplineParameterCorrection::Init() _vUMults(usUMax) = _usUOrder; // v-direction - for (unsigned i=0; i<=usVMax; i++) { + for (unsigned i = 0; i <= usVMax; i++) { _vVKnots(i) = static_cast(i) / static_cast(usVMax); _vVMults(i) = 1; } @@ -816,15 +920,16 @@ void BSplineParameterCorrection::SetUKnots(const std::vector& afKnots) { std::size_t numPoints = static_cast(_usUCtrlpoints); std::size_t order = static_cast(_usUOrder); - if (afKnots.size() != (numPoints + order)) + if (afKnots.size() != (numPoints + order)) { return; + } - unsigned usUMax = _usUCtrlpoints-_usUOrder+1; + unsigned usUMax = _usUCtrlpoints - _usUOrder + 1; // Knot vector for the CAS.CADE class // u-direction - for (unsigned i=1;i& afKnots) { std::size_t numPoints = static_cast(_usVCtrlpoints); std::size_t order = static_cast(_usVOrder); - if (afKnots.size() != (numPoints + order)) + if (afKnots.size() != (numPoints + order)) { return; + } - unsigned usVMax = _usVCtrlpoints-_usVOrder+1; + unsigned usVMax = _usVCtrlpoints - _usVOrder + 1; // Knot vector for the CAS.CADE class // v-direction - for (unsigned i=1; i& afKnots) void BSplineParameterCorrection::DoParameterCorrection(int iIter) { - int i=0; - double fMaxDiff=0.0, fMaxScalar=1.0; + int i = 0; + double fMaxDiff = 0.0, fMaxScalar = 1.0; double fWeight = _fSmoothInfluence; - Base::SequencerLauncher seq("Calc surface...", iIter*_pvcPoints->Length()); + Base::SequencerLauncher seq("Calc surface...", iIter * _pvcPoints->Length()); do { fMaxScalar = 1.0; - fMaxDiff = 0.0; + fMaxDiff = 0.0; Handle(Geom_BSplineSurface) pclBSplineSurf = new Geom_BSplineSurface(_vCtrlPntsOfSurf, - _vUKnots, _vVKnots, _vUMults, _vVMults, _usUOrder-1, _usVOrder-1); + _vUKnots, + _vVKnots, + _vUMults, + _vVMults, + _usUOrder - 1, + _usVOrder - 1); - for (int ii=_pvcPoints->Lower();ii <=_pvcPoints->Upper();ii++) { + for (int ii = _pvcPoints->Lower(); ii <= _pvcPoints->Upper(); ii++) { double fDeltaU, fDeltaV, fU, fV; const gp_Pnt& pnt = (*_pvcPoints)(ii); gp_Vec P(pnt.X(), pnt.Y(), pnt.Z()); @@ -882,25 +993,27 @@ void BSplineParameterCorrection::DoParameterCorrection(int iIter) // Calculate Xu x Xv the normal in X(u,v) gp_Dir clNormal = Xu ^ Xv; - //Check, if X = P - if (!(X.IsEqual(P,0.001,0.001))) { + // Check, if X = P + if (!(X.IsEqual(P, 0.001, 0.001))) { ErrorVec.Normalize(); - if (fabs(clNormal*ErrorVec) < fMaxScalar) - fMaxScalar = fabs(clNormal*ErrorVec); + if (fabs(clNormal * ErrorVec) < fMaxScalar) { + fMaxScalar = fabs(clNormal * ErrorVec); + } } - fDeltaU = ( (P-X) * Xu ) / ( (P-X)*Xuu - Xu*Xu ); - if (fabs(fDeltaU) < Precision::Confusion()) + fDeltaU = ((P - X) * Xu) / ((P - X) * Xuu - Xu * Xu); + if (fabs(fDeltaU) < Precision::Confusion()) { fDeltaU = 0.0; - fDeltaV = ( (P-X) * Xv ) / ( (P-X)*Xvv - Xv*Xv ); - if (fabs(fDeltaV) < Precision::Confusion()) + } + fDeltaV = ((P - X) * Xv) / ((P - X) * Xvv - Xv * Xv); + if (fabs(fDeltaV) < Precision::Confusion()) { fDeltaV = 0.0; + } - //Replace old u/v values with new ones + // Replace old u/v values with new ones fU = uvValue.X() - fDeltaU; fV = uvValue.Y() - fDeltaV; - if (fU <= 1.0 && fU >= 0.0 && - fV <= 1.0 && fV >= 0.0) { + if (fU <= 1.0 && fU >= 0.0 && fV <= 1.0 && fV >= 0.0) { uvValue.SetX(fU); uvValue.SetY(fV); fMaxDiff = std::max(fabs(fDeltaU), fMaxDiff); @@ -919,50 +1032,49 @@ void BSplineParameterCorrection::DoParameterCorrection(int iIter) } i++; - } - while(i Precision::Confusion() && fMaxScalar < 0.99); + } while (i < iIter && fMaxDiff > Precision::Confusion() && fMaxScalar < 0.99); } bool BSplineParameterCorrection::SolveWithoutSmoothing() { unsigned ulSize = _pvcPoints->Length(); - unsigned ulDim = _usUCtrlpoints*_usVCtrlpoints; - math_Matrix M (0, ulSize-1, 0, ulDim-1); - math_Matrix Xx (0, ulDim-1, 0, 0); - math_Matrix Xy (0, ulDim-1, 0, 0); - math_Matrix Xz (0, ulDim-1, 0, 0); - math_Vector bx (0, ulSize-1); - math_Vector by (0, ulSize-1); - math_Vector bz (0, ulSize-1); + unsigned ulDim = _usUCtrlpoints * _usVCtrlpoints; + math_Matrix M(0, ulSize - 1, 0, ulDim - 1); + math_Matrix Xx(0, ulDim - 1, 0, 0); + math_Matrix Xy(0, ulDim - 1, 0, 0); + math_Matrix Xz(0, ulDim - 1, 0, 0); + math_Vector bx(0, ulSize - 1); + math_Vector by(0, ulSize - 1); + math_Vector bz(0, ulSize - 1); // Determining the coefficient matrix of the overdetermined LGS - for (unsigned i=0; i basisU(_usUCtrlpoints); - for (unsigned j=0; j<_usUCtrlpoints; j++) { - basisU[j] = _clUSpline.BasisFunction(j,fU); + for (unsigned j = 0; j < _usUCtrlpoints; j++) { + basisU[j] = _clUSpline.BasisFunction(j, fU); } std::vector basisV(_usVCtrlpoints); - for (unsigned k=0; k<_usVCtrlpoints; k++) { - basisV[k] = _clVSpline.BasisFunction(k,fV); + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + basisV[k] = _clVSpline.BasisFunction(k, fV); } - for (unsigned j=0; j<_usUCtrlpoints; j++) { + for (unsigned j = 0; j < _usUCtrlpoints; j++) { double valueU = basisU[j]; if (valueU == 0.0) { - for (unsigned k=0; k<_usVCtrlpoints; k++) { - M(i,ulIdx) = 0.0; + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + M(i, ulIdx) = 0.0; ulIdx++; } } else { - for (unsigned k=0; k<_usVCtrlpoints; k++) { - M(i,ulIdx) = valueU * basisV[k]; + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + M(i, ulIdx) = valueU * basisV[k]; ulIdx++; } } @@ -970,27 +1082,30 @@ bool BSplineParameterCorrection::SolveWithoutSmoothing() } // Determine the right side - for (int ii=_pvcPoints->Lower(); ii<=_pvcPoints->Upper(); ii++) { + for (int ii = _pvcPoints->Lower(); ii <= _pvcPoints->Upper(); ii++) { const gp_Pnt& pnt = (*_pvcPoints)(ii); - bx(ii) = pnt.X(); by(ii) = pnt.Y(); bz(ii) = pnt.Z(); + bx(ii) = pnt.X(); + by(ii) = pnt.Y(); + bz(ii) = pnt.Z(); } // Solve the over-determined LGS with Householder-Transformation - math_Householder hhX(M,bx); - math_Householder hhY(M,by); - math_Householder hhZ(M,bz); + math_Householder hhX(M, bx); + math_Householder hhY(M, by); + math_Householder hhZ(M, bz); - if (!(hhX.IsDone() && hhY.IsDone() && hhZ.IsDone())) + if (!(hhX.IsDone() && hhY.IsDone() && hhZ.IsDone())) { // LGS could not be solved return false; + } Xx = hhX.AllValues(); Xy = hhY.AllValues(); Xz = hhZ.AllValues(); - unsigned ulIdx=0; - for (unsigned j=0;j<_usUCtrlpoints;j++) { - for (unsigned k=0;k<_usVCtrlpoints;k++) { - _vCtrlPntsOfSurf(j,k) = gp_Pnt(Xx(ulIdx,0),Xy(ulIdx,0),Xz(ulIdx,0)); + unsigned ulIdx = 0; + for (unsigned j = 0; j < _usUCtrlpoints; j++) { + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + _vCtrlPntsOfSurf(j, k) = gp_Pnt(Xx(ulIdx, 0), Xy(ulIdx, 0), Xz(ulIdx, 0)); ulIdx++; } } @@ -998,18 +1113,19 @@ bool BSplineParameterCorrection::SolveWithoutSmoothing() return true; } -namespace Reen { +namespace Reen +{ class ScalarProduct { public: - explicit ScalarProduct(const math_Matrix& mat) : mat(mat) - { - } + explicit ScalarProduct(const math_Matrix& mat) + : mat(mat) + {} std::vector multiply(int col) const { math_Vector vec = mat.Col(col); std::vector out(mat.ColNumber()); - for (int n=mat.LowerCol(); n<=mat.UpperCol(); n++) { + for (int n = mat.LowerCol(); n <= mat.UpperCol(); n++) { out[n] = vec * mat.Col(n); } return out; @@ -1018,51 +1134,51 @@ public: private: const math_Matrix& mat; }; -} +}// namespace Reen bool BSplineParameterCorrection::SolveWithSmoothing(double fWeight) { unsigned ulSize = _pvcPoints->Length(); - unsigned ulDim = _usUCtrlpoints*_usVCtrlpoints; - math_Matrix M (0, ulSize-1, 0, ulDim-1); - math_Vector Xx (0, ulDim-1); - math_Vector Xy (0, ulDim-1); - math_Vector Xz (0, ulDim-1); - math_Vector bx (0, ulSize-1); - math_Vector by (0, ulSize-1); - math_Vector bz (0, ulSize-1); - math_Vector Mbx(0, ulDim-1); - math_Vector Mby(0, ulDim-1); - math_Vector Mbz(0, ulDim-1); + unsigned ulDim = _usUCtrlpoints * _usVCtrlpoints; + math_Matrix M(0, ulSize - 1, 0, ulDim - 1); + math_Vector Xx(0, ulDim - 1); + math_Vector Xy(0, ulDim - 1); + math_Vector Xz(0, ulDim - 1); + math_Vector bx(0, ulSize - 1); + math_Vector by(0, ulSize - 1); + math_Vector bz(0, ulSize - 1); + math_Vector Mbx(0, ulDim - 1); + math_Vector Mby(0, ulDim - 1); + math_Vector Mbz(0, ulDim - 1); // Determining the coefficient matrix of the overdetermined LGS - for (unsigned i=0; i basisU(_usUCtrlpoints); - for (unsigned j=0; j<_usUCtrlpoints; j++) { - basisU[j] = _clUSpline.BasisFunction(j,fU); + for (unsigned j = 0; j < _usUCtrlpoints; j++) { + basisU[j] = _clUSpline.BasisFunction(j, fU); } std::vector basisV(_usVCtrlpoints); - for (unsigned k=0; k<_usVCtrlpoints; k++) { - basisV[k] = _clVSpline.BasisFunction(k,fV); + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + basisV[k] = _clVSpline.BasisFunction(k, fV); } - for (unsigned j=0; j<_usUCtrlpoints; j++) { + for (unsigned j = 0; j < _usUCtrlpoints; j++) { double valueU = basisU[j]; if (valueU == 0.0) { - for (unsigned k=0; k<_usVCtrlpoints; k++) { - M(i,ulIdx) = 0.0; + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + M(i, ulIdx) = 0.0; ulIdx++; } } else { - for (unsigned k=0; k<_usVCtrlpoints; k++) { - M(i,ulIdx) = valueU * basisV[k]; + for (unsigned k = 0; k < _usVCtrlpoints; k++) { + M(i, ulIdx) = valueU * basisV[k]; ulIdx++; } } @@ -1074,41 +1190,45 @@ bool BSplineParameterCorrection::SolveWithSmoothing(double fWeight) #if 0 math_Matrix MTM = M.TMultiply(M); #elif 0 - math_Matrix MTM(0, ulDim-1, 0, ulDim-1); - for (unsigned m=0; m columns(ulDim); std::generate(columns.begin(), columns.end(), Base::iotaGen(0)); ScalarProduct scalar(M); - //NOLINTBEGIN - QFuture< std::vector > future = QtConcurrent::mapped - (columns, std::bind(&ScalarProduct::multiply, &scalar, sp::_1)); - //NOLINTEND - QFutureWatcher< std::vector > watcher; + // NOLINTBEGIN + QFuture> future = + QtConcurrent::mapped(columns, std::bind(&ScalarProduct::multiply, &scalar, sp::_1)); + // NOLINTEND + QFutureWatcher> watcher; watcher.setFuture(future); watcher.waitForFinished(); - math_Matrix MTM(0, ulDim-1, 0, ulDim-1); - int rowIndex=0; - for (const auto & it : future) { - int colIndex=0; - for (std::vector::const_iterator jt = it.begin(); jt != it.end(); ++jt, colIndex++) + math_Matrix MTM(0, ulDim - 1, 0, ulDim - 1); + int rowIndex = 0; + for (const auto& it : future) { + int colIndex = 0; + for (std::vector::const_iterator jt = it.begin(); jt != it.end(); + ++jt, colIndex++) { MTM(rowIndex, colIndex) = *jt; + } rowIndex++; } #endif // Determine the right side - for (int ii=_pvcPoints->Lower(); ii<=_pvcPoints->Upper(); ii++) { + for (int ii = _pvcPoints->Lower(); ii <= _pvcPoints->Upper(); ii++) { const gp_Pnt& pnt = (*_pvcPoints)(ii); - bx(ii) = pnt.X(); by(ii) = pnt.Y(); bz(ii) = pnt.Z(); + bx(ii) = pnt.X(); + by(ii) = pnt.Y(); + bz(ii) = pnt.Z(); } - for (unsigned i=0; i -#include -#include +#include #include #include -#include +#include +#include +#include #include #include #include -namespace Base { +namespace Base +{ class SequencerLauncher; } // TODO: Replace OCC stuff with ublas & co -namespace Reen { +namespace Reen +{ class ReenExport SplineBasisfunction { public: - enum ValueT { + enum ValueT + { Zero = 0, Full, Other @@ -62,7 +65,7 @@ public: * @param vKnots Knot vector * @param iOrder Order (degree + 1) of the basic polynomial */ - explicit SplineBasisfunction(TColStd_Array1OfReal& vKnots, int iOrder=1); + explicit SplineBasisfunction(TColStd_Array1OfReal& vKnots, int iOrder = 1); /** * Constructor @@ -73,7 +76,10 @@ public: * and the sum of the values in @a vMults has to be identical to @a iSize. * @param iOrder Order (degree + 1) of the basic polynomial */ - SplineBasisfunction(TColStd_Array1OfReal& vKnots, TColStd_Array1OfInteger& vMults, int iSize, int iOrder=1); + SplineBasisfunction(TColStd_Array1OfReal& vKnots, + TColStd_Array1OfInteger& vMults, + int iSize, + int iOrder = 1); virtual ~SplineBasisfunction(); @@ -86,7 +92,7 @@ public: * @param fParam Parameter value * @return ValueT */ - virtual ValueT LocalSupport(int iIndex, double fParam)=0; + virtual ValueT LocalSupport(int iIndex, double fParam) = 0; /** * Calculates the function value Nik(t) at the point fParam * (from: Piegl/Tiller 96 The NURBS-Book) @@ -95,7 +101,7 @@ public: * @param fParam Parameter value * @return Function value Nik(t) */ - virtual double BasisFunction(int iIndex, double fParam)=0; + virtual double BasisFunction(int iIndex, double fParam) = 0; /** * Calculates the function values of the first iMaxDer derivatives on the * fParam position (from: Piegl/Tiller 96 The NURBS-Book) @@ -107,28 +113,31 @@ public: * * The list must be sufficiently long for iMaxDer+1 elements. */ - virtual void DerivativesOfBasisFunction(int iIndex, int iMaxDer, double fParam, - TColStd_Array1OfReal& Derivat)=0; + virtual void DerivativesOfBasisFunction(int iIndex, + int iMaxDer, + double fParam, + TColStd_Array1OfReal& Derivat) = 0; /** * Calculates the kth derivative at the point fParam */ - virtual double DerivativeOfBasisFunction(int iIndex, int k, double fParam)=0; + virtual double DerivativeOfBasisFunction(int iIndex, int k, double fParam) = 0; /** * Sets the knot vector and the order. The size of the knot vector has to be exactly as * large as defined in the constructor. */ - virtual void SetKnots(TColStd_Array1OfReal& vKnots, int iOrder=1); + virtual void SetKnots(TColStd_Array1OfReal& vKnots, int iOrder = 1); /** * Sets the knot vector and the order. The knot vector in the form of (Value, Multiplicity) * is passed on. Internally, this is converted into a knot vector in the form of (value, 1). * The size of this new vector has to be exactly as big as specified in the constructor. */ - virtual void SetKnots(TColStd_Array1OfReal& vKnots, TColStd_Array1OfInteger& vMults, int iOrder=1); + virtual void + SetKnots(TColStd_Array1OfReal& vKnots, TColStd_Array1OfInteger& vMults, int iOrder = 1); -protected: //Member +protected:// Member // Knot vector TColStd_Array1OfReal _vKnotVector; @@ -136,10 +145,9 @@ protected: //Member int _iOrder; }; -class ReenExport BSplineBasis : public SplineBasisfunction +class ReenExport BSplineBasis: public SplineBasisfunction { public: - /** * Constructor * @param iSize Length of the knot vector @@ -151,7 +159,7 @@ public: * @param vKnots Knot vector * @param iOrder Order (degree + 1) of the basic polynomial */ - explicit BSplineBasis(TColStd_Array1OfReal& vKnots, int iOrder=1); + explicit BSplineBasis(TColStd_Array1OfReal& vKnots, int iOrder = 1); /** * Constructor @@ -162,7 +170,10 @@ public: * sum of the values in @a vMults has to be identical to @a iSize. * @param iOrder Order (degree + 1) of the basic polynomial */ - BSplineBasis(TColStd_Array1OfReal& vKnots, TColStd_Array1OfInteger& vMults, int iSize, int iOrder=1); + BSplineBasis(TColStd_Array1OfReal& vKnots, + TColStd_Array1OfInteger& vMults, + int iSize, + int iOrder = 1); /** * Specifies the knot index for the parameter value (from: Piegl/Tiller 96 The NURBS-Book) @@ -173,7 +184,7 @@ public: /** * Calculates the function values of the basic functions that do not vanish at fParam. - * It must be ensured that the list for d (= degree of the B-spline) + * It must be ensured that the list for d (= degree of the B-spline) * elements (0, ..., d-1) is sufficient (from: Piegl/Tiller 96 The NURBS-Book) * @param fParam Parameter * @param vFuncVals List of function values @@ -211,8 +222,10 @@ public: * The list must be sufficiently long for iMaxDer+1 elements. * @return List of function values */ - void DerivativesOfBasisFunction(int iIndex, int iMaxDer, double fParam, - TColStd_Array1OfReal& Derivat) override; + void DerivativesOfBasisFunction(int iIndex, + int iMaxDer, + double fParam, + TColStd_Array1OfReal& Derivat) override; /** * Calculates the kth derivative at the point fParam @@ -229,14 +242,14 @@ public: /** * Destructor */ - ~ BSplineBasis() override; + ~BSplineBasis() override; protected: - /** * Calculates the roots of the Legendre-Polynomials and the corresponding weights */ - virtual void GenerateRootsAndWeights(TColStd_Array1OfReal& vAbscissas, TColStd_Array1OfReal& vWeights); + virtual void GenerateRootsAndWeights(TColStd_Array1OfReal& vAbscissas, + TColStd_Array1OfReal& vWeights); /** * Calculates the limits of integration (Indexes of the knots) @@ -255,10 +268,11 @@ class ReenExport ParameterCorrection public: // Constructor - explicit ParameterCorrection(unsigned usUOrder=4, //Order in u-direction (order = degree + 1) - unsigned usVOrder=4, //Order in v-direction - unsigned usUCtrlpoints=6, //Qty. of the control points in the u-direction - unsigned usVCtrlpoints=6); //Qty. of the control points in the v-direction + explicit ParameterCorrection( + unsigned usUOrder = 4, // Order in u-direction (order = degree + 1) + unsigned usVOrder = 4, // Order in v-direction + unsigned usUCtrlpoints = 6, // Qty. of the control points in the u-direction + unsigned usVCtrlpoints = 6);// Qty. of the control points in the v-direction virtual ~ParameterCorrection() { @@ -285,7 +299,7 @@ protected: * The bounding box is calculated from these points, then the u/v parameters for * the points are calculated. */ - virtual bool DoInitialParameterCorrection(double fSizeFactor=0.0f); + virtual bool DoInitialParameterCorrection(double fSizeFactor = 0.0f); /** * Calculates the (u, v) values of the points @@ -295,31 +309,31 @@ protected: /** * Carries out a parameter correction. */ - virtual void DoParameterCorrection(int iIter)=0; + virtual void DoParameterCorrection(int iIter) = 0; /** * Solves system of equations */ - virtual bool SolveWithoutSmoothing()=0; + virtual bool SolveWithoutSmoothing() = 0; /** * Solve a regular system of equations */ - virtual bool SolveWithSmoothing(double fWeight)=0; + virtual bool SolveWithSmoothing(double fWeight) = 0; public: /** * Calculates a B-spline surface from the given points */ virtual Handle(Geom_BSplineSurface) CreateSurface(const TColgp_Array1OfPnt& points, - int iIter, - bool bParaCor, - double fSizeFactor=0.0f); + int iIter, + bool bParaCor, + double fSizeFactor = 0.0f); /** * Setting the u/v directions * The third parameter specifies whether the directions should actually be used. */ - virtual void SetUV(const Base::Vector3d& clU, const Base::Vector3d& clV, bool bUseDir=true); + virtual void SetUV(const Base::Vector3d& clU, const Base::Vector3d& clV, bool bUseDir = true); /** * Returns the u/v/w directions @@ -334,26 +348,26 @@ public: /** * Use smoothing-terms */ - virtual void EnableSmoothing(bool bSmooth=true, double fSmoothInfl=1.0f); + virtual void EnableSmoothing(bool bSmooth = true, double fSmoothInfl = 1.0f); protected: - bool _bGetUVDir; //! Determines whether u/v direction is given - bool _bSmoothing; //! Use smoothing - double _fSmoothInfluence; //! Influence of smoothing - unsigned _usUOrder; //! Order in u-direction - unsigned _usVOrder; //! Order in v-direction - unsigned _usUCtrlpoints; //! Number of control points in the u-direction - unsigned _usVCtrlpoints; //! Number of control points in the v-direction - Base::Vector3d _clU; //! u-direction - Base::Vector3d _clV; //! v-direction - Base::Vector3d _clW; //! w-direction (perpendicular to u & v directions) - TColgp_Array1OfPnt* _pvcPoints{nullptr}; //! Raw data point list - TColgp_Array1OfPnt2d* _pvcUVParam{nullptr}; //! Parameter value for the points in the list - TColgp_Array2OfPnt _vCtrlPntsOfSurf; //! Array of control points - TColStd_Array1OfReal _vUKnots; //! Knot vector of the B-spline surface in the u-direction - TColStd_Array1OfReal _vVKnots; //! Knot vector of the B-spline surface in the v-direction - TColStd_Array1OfInteger _vUMults; //! Multiplicity of the knots in the knot vector - TColStd_Array1OfInteger _vVMults; //! Multiplicity of the knots in the knot vector + bool _bGetUVDir; //! Determines whether u/v direction is given + bool _bSmoothing; //! Use smoothing + double _fSmoothInfluence; //! Influence of smoothing + unsigned _usUOrder; //! Order in u-direction + unsigned _usVOrder; //! Order in v-direction + unsigned _usUCtrlpoints; //! Number of control points in the u-direction + unsigned _usVCtrlpoints; //! Number of control points in the v-direction + Base::Vector3d _clU; //! u-direction + Base::Vector3d _clV; //! v-direction + Base::Vector3d _clW; //! w-direction (perpendicular to u & v directions) + TColgp_Array1OfPnt* _pvcPoints {nullptr}; //! Raw data point list + TColgp_Array1OfPnt2d* _pvcUVParam {nullptr};//! Parameter value for the points in the list + TColgp_Array2OfPnt _vCtrlPntsOfSurf; //! Array of control points + TColStd_Array1OfReal _vUKnots; //! Knot vector of the B-spline surface in the u-direction + TColStd_Array1OfReal _vVKnots; //! Knot vector of the B-spline surface in the v-direction + TColStd_Array1OfInteger _vUMults;//! Multiplicity of the knots in the knot vector + TColStd_Array1OfInteger _vVMults;//! Multiplicity of the knots in the knot vector }; /////////////////////////////////////////////////////////////////////////////////////////////// @@ -366,14 +380,15 @@ protected: * can be generated. */ -class ReenExport BSplineParameterCorrection : public ParameterCorrection +class ReenExport BSplineParameterCorrection: public ParameterCorrection { public: // Constructor - explicit BSplineParameterCorrection(unsigned usUOrder=4, //Order in u-direction (order = degree + 1) - unsigned usVOrder=4, //Order in the v-direction - unsigned usUCtrlpoints=6, //Qty. of the control points in u-direction - unsigned usVCtrlpoints=6); //Qty. of the control points in v-direction + explicit BSplineParameterCorrection( + unsigned usUOrder = 4, // Order in u-direction (order = degree + 1) + unsigned usVOrder = 4, // Order in the v-direction + unsigned usUCtrlpoints = 6, // Qty. of the control points in u-direction + unsigned usVCtrlpoints = 6);// Qty. of the control points in v-direction ~BSplineParameterCorrection() override = default; @@ -443,13 +458,13 @@ public: /** * Use smoothing-terms */ - void EnableSmoothing(bool bSmooth=true, double fSmoothInfl=1.0f) override; + void EnableSmoothing(bool bSmooth = true, double fSmoothInfl = 1.0f) override; /** * Use smoothing-terms */ - virtual void EnableSmoothing(bool bSmooth, double fSmoothInfl, - double fFirst, double fSec, double fThird); + virtual void + EnableSmoothing(bool bSmooth, double fSmoothInfl, double fFirst, double fSec, double fThird); protected: /** @@ -476,14 +491,14 @@ protected: virtual void CalcThirdSmoothMatrix(Base::SequencerLauncher&); protected: - BSplineBasis _clUSpline; //! B-spline basic function in the u-direction - BSplineBasis _clVSpline; //! B-spline basic function in the v-direction - math_Matrix _clSmoothMatrix; //! Matrix of smoothing functionals - math_Matrix _clFirstMatrix; //! Matrix of the 1st smoothing functionals - math_Matrix _clSecondMatrix; //! Matrix of the 2nd smoothing functionals - math_Matrix _clThirdMatrix; //! Matrix of the 3rd smoothing functionals + BSplineBasis _clUSpline; //! B-spline basic function in the u-direction + BSplineBasis _clVSpline; //! B-spline basic function in the v-direction + math_Matrix _clSmoothMatrix;//! Matrix of smoothing functionals + math_Matrix _clFirstMatrix; //! Matrix of the 1st smoothing functionals + math_Matrix _clSecondMatrix;//! Matrix of the 2nd smoothing functionals + math_Matrix _clThirdMatrix; //! Matrix of the 3rd smoothing functionals }; -} // namespace Reen +}// namespace Reen -#endif // REEN_APPROXSURFACE_H +#endif// REEN_APPROXSURFACE_H diff --git a/src/Mod/ReverseEngineering/App/BSplineFitting.cpp b/src/Mod/ReverseEngineering/App/BSplineFitting.cpp index 6df1ded66d..681030efd6 100644 --- a/src/Mod/ReverseEngineering/App/BSplineFitting.cpp +++ b/src/Mod/ReverseEngineering/App/BSplineFitting.cpp @@ -23,13 +23,13 @@ #include "PreCompiled.h" #if defined(HAVE_PCL_OPENNURBS) #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include #endif #include @@ -37,28 +37,27 @@ #include "BSplineFitting.h" #include -#if PCL_VERSION_COMPARE(>=,1,7,0) -# include -# include -# include -# include -# include +#if PCL_VERSION_COMPARE(>=, 1, 7, 0) +#include +#include +#include +#include +#include #endif using namespace Reen; BSplineFitting::BSplineFitting(const std::vector& pts) - : myPoints(pts) - , myIterations(10) - , myOrder(3) - , myRefinement(4) - , myInteriorSmoothness(0.2) - , myInteriorWeight(1.0) - , myBoundarySmoothness(0.2) - , myBoundaryWeight(0.0) -{ -} + : myPoints(pts) + , myIterations(10) + , myOrder(3) + , myRefinement(4) + , myInteriorSmoothness(0.2) + , myInteriorWeight(1.0) + , myBoundarySmoothness(0.2) + , myBoundaryWeight(0.0) +{} void BSplineFitting::setIterations(unsigned value) { @@ -97,11 +96,13 @@ void BSplineFitting::setBoundaryWeight(double value) Handle(Geom_BSplineSurface) BSplineFitting::perform() { -#if PCL_VERSION_COMPARE(>=,1,7,0) +#if PCL_VERSION_COMPARE(>=, 1, 7, 0) pcl::on_nurbs::NurbsDataSurface data; - for (std::vector::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!pcl_isnan (it->x) && !pcl_isnan (it->y) && !pcl_isnan (it->z)) - data.interior.push_back (Eigen::Vector3d (it->x, it->y, it->z)); + for (std::vector::const_iterator it = myPoints.begin(); it != myPoints.end(); + ++it) { + if (!pcl_isnan(it->x) && !pcl_isnan(it->y) && !pcl_isnan(it->z)) { + data.interior.push_back(Eigen::Vector3d(it->x, it->y, it->z)); + } } @@ -115,8 +116,8 @@ Handle(Geom_BSplineSurface) BSplineFitting::perform() params.boundary_weight = myBoundaryWeight; // initialize - ON_NurbsSurface nurbs = pcl::on_nurbs::FittingSurface::initNurbsPCABoundingBox (myOrder, &data); - pcl::on_nurbs::FittingSurface fit (&data, nurbs); + ON_NurbsSurface nurbs = pcl::on_nurbs::FittingSurface::initNurbsPCABoundingBox(myOrder, &data); + pcl::on_nurbs::FittingSurface fit(&data, nurbs); // fit.setQuiet (false); // enable/disable debug output // surface refinement @@ -179,61 +180,74 @@ Handle(Geom_BSplineSurface) BSplineFitting::perform() TColgp_Array2OfPnt poles(1, numUPoles, 1, numVPoles); TColStd_Array2OfReal weights(1, numUPoles, 1, numVPoles); - for (int i=0; i::iterator it = uKnots.find(value); - if (it == uKnots.end()) + if (it == uKnots.end()) { uKnots[value] = 1; - else + } + else { it->second++; + } } - vKnots[fit.m_nurbs.SuperfluousKnot(1,0)] = 1; - vKnots[fit.m_nurbs.SuperfluousKnot(1,1)] = 1; - for (int i=0; i::iterator it = vKnots.find(value); - if (it == vKnots.end()) + if (it == vKnots.end()) { vKnots[value] = 1; - else + } + else { it->second++; + } } - TColStd_Array1OfReal uKnotArray(1,uKnots.size()); - TColStd_Array1OfInteger uMultArray(1,uKnots.size()); + TColStd_Array1OfReal uKnotArray(1, uKnots.size()); + TColStd_Array1OfInteger uMultArray(1, uKnots.size()); int index = 1; - for (std::map::iterator it = uKnots.begin(); it != uKnots.end(); ++it, index++) { + for (std::map::iterator it = uKnots.begin(); it != uKnots.end(); + ++it, index++) { uKnotArray.SetValue(index, it->first); uMultArray.SetValue(index, it->second); } - TColStd_Array1OfReal vKnotArray(1,vKnots.size()); - TColStd_Array1OfInteger vMultArray(1,vKnots.size()); + TColStd_Array1OfReal vKnotArray(1, vKnots.size()); + TColStd_Array1OfInteger vMultArray(1, vKnots.size()); index = 1; - for (std::map::iterator it = vKnots.begin(); it != vKnots.end(); ++it, index++) { + for (std::map::iterator it = vKnots.begin(); it != vKnots.end(); + ++it, index++) { vKnotArray.SetValue(index, it->first); vMultArray.SetValue(index, it->second); } - Handle(Geom_BSplineSurface) spline = new Geom_BSplineSurface(poles,weights, - uKnotArray, vKnotArray, uMultArray, vMultArray, uDegree, vDegree, - uPeriodic, vPeriodic); + Handle(Geom_BSplineSurface) spline = new Geom_BSplineSurface(poles, + weights, + uKnotArray, + vKnotArray, + uMultArray, + vMultArray, + uDegree, + vDegree, + uPeriodic, + vPeriodic); return spline; #else return Handle(Geom_BSplineSurface)(); #endif } -#endif // HAVE_PCL_OPENNURBS +#endif// HAVE_PCL_OPENNURBS diff --git a/src/Mod/ReverseEngineering/App/BSplineFitting.h b/src/Mod/ReverseEngineering/App/BSplineFitting.h index 0dd1f2b740..35381d65f4 100644 --- a/src/Mod/ReverseEngineering/App/BSplineFitting.h +++ b/src/Mod/ReverseEngineering/App/BSplineFitting.h @@ -24,13 +24,14 @@ #define REEN_BSPLINEFITTING_H #if defined(HAVE_PCL_OPENNURBS) -# include +#include -# include -# include +#include +#include -namespace Reen { +namespace Reen +{ class BSplineFitting { @@ -57,8 +58,8 @@ private: double myBoundaryWeight; }; -} +}// namespace Reen -#endif // HAVE_PCL_OPENNURBS +#endif// HAVE_PCL_OPENNURBS -#endif // REEN_BSPLINEFITTING_H +#endif// REEN_BSPLINEFITTING_H diff --git a/src/Mod/ReverseEngineering/App/PreCompiled.h b/src/Mod/ReverseEngineering/App/PreCompiled.h index f600eeed2b..616dab89eb 100644 --- a/src/Mod/ReverseEngineering/App/PreCompiled.h +++ b/src/Mod/ReverseEngineering/App/PreCompiled.h @@ -26,16 +26,16 @@ #include #ifdef _MSC_VER -# pragma warning(disable : 4181) -# pragma warning(disable : 4267) -# pragma warning(disable : 4275) -# pragma warning(disable : 4305) -# pragma warning(disable : 4522) +#pragma warning(disable : 4181) +#pragma warning(disable : 4267) +#pragma warning(disable : 4275) +#pragma warning(disable : 4305) +#pragma warning(disable : 4522) #endif // pcl headers include instead of #ifndef BOOST_BIND_GLOBAL_PLACEHOLDERS -# define BOOST_BIND_GLOBAL_PLACEHOLDERS +#define BOOST_BIND_GLOBAL_PLACEHOLDERS #endif #ifdef _PreComp_ @@ -48,15 +48,15 @@ // OpenCasCade #include -#include -#include #include #include +#include +#include // Qt #include #include #include -#endif // _PreComp_ +#endif// _PreComp_ #endif diff --git a/src/Mod/ReverseEngineering/App/RegionGrowing.cpp b/src/Mod/ReverseEngineering/App/RegionGrowing.cpp index 3c5816a176..65fb275af7 100644 --- a/src/Mod/ReverseEngineering/App/RegionGrowing.cpp +++ b/src/Mod/ReverseEngineering/App/RegionGrowing.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -31,69 +31,71 @@ #if defined(HAVE_PCL_FILTERS) -# include -# include +#include +#include #endif #if defined(HAVE_PCL_SEGMENTATION) -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include using namespace std; using namespace Reen; -using pcl::PointXYZ; -using pcl::PointNormal; using pcl::PointCloud; +using pcl::PointNormal; +using pcl::PointXYZ; -RegionGrowing::RegionGrowing(const Points::PointKernel& pts, std::list >& clusters) - : myPoints(pts) - , myClusters(clusters) -{ -} +RegionGrowing::RegionGrowing(const Points::PointKernel& pts, std::list>& clusters) + : myPoints(pts) + , myClusters(clusters) +{} void RegionGrowing::perform(int ksearch) { - pcl::PointCloud::Ptr cloud (new pcl::PointCloud); + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z)); + } } - //normal estimation + // normal estimation pcl::search::Search::Ptr tree(new pcl::search::KdTree); - pcl::PointCloud ::Ptr normals (new pcl::PointCloud ); + pcl::PointCloud::Ptr normals(new pcl::PointCloud); pcl::NormalEstimation normal_estimator; - normal_estimator.setSearchMethod (tree); - normal_estimator.setInputCloud (cloud); - normal_estimator.setKSearch (ksearch); - normal_estimator.compute (*normals); + normal_estimator.setSearchMethod(tree); + normal_estimator.setInputCloud(cloud); + normal_estimator.setKSearch(ksearch); + normal_estimator.compute(*normals); // pass through - pcl::IndicesPtr indices (new std::vector ); + pcl::IndicesPtr indices(new std::vector); pcl::PassThrough pass; - pass.setInputCloud (cloud); - pass.setFilterFieldName ("z"); - pass.setFilterLimits (0.0, 1.0); - pass.filter (*indices); + pass.setInputCloud(cloud); + pass.setFilterFieldName("z"); + pass.setFilterLimits(0.0, 1.0); + pass.filter(*indices); pcl::RegionGrowing reg; - reg.setMinClusterSize (50); - reg.setMaxClusterSize (1000000); - reg.setSearchMethod (tree); - reg.setNumberOfNeighbours (30); - reg.setInputCloud (cloud); - //reg.setIndices (indices); - reg.setInputNormals (normals); - reg.setSmoothnessThreshold (3.0 / 180.0 * M_PI); - reg.setCurvatureThreshold (1.0); + reg.setMinClusterSize(50); + reg.setMaxClusterSize(1000000); + reg.setSearchMethod(tree); + reg.setNumberOfNeighbours(30); + reg.setInputCloud(cloud); + // reg.setIndices (indices); + reg.setInputNormals(normals); + reg.setSmoothnessThreshold(3.0 / 180.0 * M_PI); + reg.setCurvatureThreshold(1.0); - std::vector clusters; - reg.extract (clusters); + std::vector clusters; + reg.extract(clusters); - for (std::vector::iterator it = clusters.begin (); it != clusters.end (); ++it) { + for (std::vector::iterator it = clusters.begin(); it != clusters.end(); + ++it) { myClusters.push_back(std::vector()); myClusters.back().swap(it->indices); } @@ -101,17 +103,18 @@ void RegionGrowing::perform(int ksearch) void RegionGrowing::perform(const std::vector& myNormals) { - if (myPoints.size() != myNormals.size()) + if (myPoints.size() != myNormals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - pcl::PointCloud::Ptr cloud (new pcl::PointCloud); + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); cloud->reserve(myPoints.size()); - pcl::PointCloud ::Ptr normals (new pcl::PointCloud ); + pcl::PointCloud::Ptr normals(new pcl::PointCloud); normals->reserve(myNormals.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& myNormals) } pcl::search::Search::Ptr tree(new pcl::search::KdTree); - tree->setInputCloud (cloud); + tree->setInputCloud(cloud); // pass through - pcl::IndicesPtr indices (new std::vector ); + pcl::IndicesPtr indices(new std::vector); pcl::PassThrough pass; - pass.setInputCloud (cloud); - pass.setFilterFieldName ("z"); - pass.setFilterLimits (0.0, 1.0); - pass.filter (*indices); + pass.setInputCloud(cloud); + pass.setFilterFieldName("z"); + pass.setFilterLimits(0.0, 1.0); + pass.filter(*indices); pcl::RegionGrowing reg; - reg.setMinClusterSize (50); - reg.setMaxClusterSize (1000000); - reg.setSearchMethod (tree); - reg.setNumberOfNeighbours (30); - reg.setInputCloud (cloud); - //reg.setIndices (indices); - reg.setInputNormals (normals); - reg.setSmoothnessThreshold (3.0 / 180.0 * M_PI); - reg.setCurvatureThreshold (1.0); + reg.setMinClusterSize(50); + reg.setMaxClusterSize(1000000); + reg.setSearchMethod(tree); + reg.setNumberOfNeighbours(30); + reg.setInputCloud(cloud); + // reg.setIndices (indices); + reg.setInputNormals(normals); + reg.setSmoothnessThreshold(3.0 / 180.0 * M_PI); + reg.setCurvatureThreshold(1.0); - std::vector clusters; - reg.extract (clusters); + std::vector clusters; + reg.extract(clusters); - for (std::vector::iterator it = clusters.begin (); it != clusters.end (); ++it) { + for (std::vector::iterator it = clusters.begin(); it != clusters.end(); + ++it) { myClusters.push_back(std::vector()); myClusters.back().swap(it->indices); } } -#endif // HAVE_PCL_SEGMENTATION - +#endif// HAVE_PCL_SEGMENTATION diff --git a/src/Mod/ReverseEngineering/App/RegionGrowing.h b/src/Mod/ReverseEngineering/App/RegionGrowing.h index f38b92ece7..6dc6539d64 100644 --- a/src/Mod/ReverseEngineering/App/RegionGrowing.h +++ b/src/Mod/ReverseEngineering/App/RegionGrowing.h @@ -29,29 +29,32 @@ #include -namespace Points {class PointKernel;} +namespace Points +{ +class PointKernel; +} -namespace Reen { +namespace Reen +{ class RegionGrowing { public: - RegionGrowing(const Points::PointKernel&, std::list >&); + RegionGrowing(const Points::PointKernel&, std::list>&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ + * \param[in] k the number of k-nearest neighbors + */ void perform(int ksearch); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); private: const Points::PointKernel& myPoints; - std::list >& myClusters; + std::list>& myClusters; }; -} // namespace Reen - -#endif // REEN_REGIONGROWING_H +}// namespace Reen +#endif// REEN_REGIONGROWING_H diff --git a/src/Mod/ReverseEngineering/App/SampleConsensus.cpp b/src/Mod/ReverseEngineering/App/SampleConsensus.cpp index 5dcf320ed1..9b5ddb46f5 100644 --- a/src/Mod/ReverseEngineering/App/SampleConsensus.cpp +++ b/src/Mod/ReverseEngineering/App/SampleConsensus.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -32,41 +32,44 @@ #if defined(HAVE_PCL_SAMPLE_CONSENSUS) -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace Reen; -using pcl::PointXYZ; -using pcl::PointNormal; using pcl::PointCloud; +using pcl::PointNormal; +using pcl::PointXYZ; -SampleConsensus::SampleConsensus(SacModel sac, const Points::PointKernel& pts, const std::vector& nor) - : mySac(sac) - , myPoints(pts) - , myNormals(nor) -{ -} +SampleConsensus::SampleConsensus(SacModel sac, + const Points::PointKernel& pts, + const std::vector& nor) + : mySac(sac) + , myPoints(pts) + , myNormals(nor) +{} double SampleConsensus::perform(std::vector& parameters, std::vector& model) { - pcl::PointCloud::Ptr cloud (new pcl::PointCloud); + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z)); + } } - cloud->width = int (cloud->points.size ()); + cloud->width = int(cloud->points.size()); cloud->height = 1; cloud->is_dense = true; - pcl::PointCloud::Ptr normals (new pcl::PointCloud ()); + pcl::PointCloud::Ptr normals(new pcl::PointCloud()); if (mySac == SACMODEL_CONE || mySac == SACMODEL_CYLINDER) { #if 0 // Create search tree @@ -83,9 +86,13 @@ double SampleConsensus::perform(std::vector& parameters, std::vector n.compute (*normals); #else normals->reserve(myNormals.size()); - for (std::vector::const_iterator it = myNormals.begin(); it != myNormals.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + for (std::vector::const_iterator it = myNormals.begin(); + it != myNormals.end(); + ++it) { + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { normals->push_back(pcl::Normal(it->x, it->y, it->z)); + } } #endif } @@ -93,48 +100,44 @@ double SampleConsensus::perform(std::vector& parameters, std::vector // created RandomSampleConsensus object and compute the appropriated model pcl::SampleConsensusModel::Ptr model_p; switch (mySac) { - case SACMODEL_PLANE: - { - model_p.reset(new pcl::SampleConsensusModelPlane (cloud)); - break; - } - case SACMODEL_SPHERE: - { - model_p.reset(new pcl::SampleConsensusModelSphere (cloud)); - break; - } - case SACMODEL_CONE: - { - pcl::SampleConsensusModelCone::Ptr model_c - (new pcl::SampleConsensusModelCone (cloud)); - model_c->setInputNormals(normals); - model_p = model_c; - break; - } - case SACMODEL_CYLINDER: - { - pcl::SampleConsensusModelCylinder::Ptr model_c - (new pcl::SampleConsensusModelCylinder (cloud)); - model_c->setInputNormals(normals); - model_p = model_c; - break; - } - default: - throw Base::RuntimeError("Unsupported SAC model"); + case SACMODEL_PLANE: { + model_p.reset(new pcl::SampleConsensusModelPlane(cloud)); + break; + } + case SACMODEL_SPHERE: { + model_p.reset(new pcl::SampleConsensusModelSphere(cloud)); + break; + } + case SACMODEL_CONE: { + pcl::SampleConsensusModelCone::Ptr model_c( + new pcl::SampleConsensusModelCone(cloud)); + model_c->setInputNormals(normals); + model_p = model_c; + break; + } + case SACMODEL_CYLINDER: { + pcl::SampleConsensusModelCylinder::Ptr model_c( + new pcl::SampleConsensusModelCylinder(cloud)); + model_c->setInputNormals(normals); + model_p = model_c; + break; + } + default: + throw Base::RuntimeError("Unsupported SAC model"); } - pcl::RandomSampleConsensus ransac (model_p); - ransac.setDistanceThreshold (.01); + pcl::RandomSampleConsensus ransac(model_p); + ransac.setDistanceThreshold(.01); ransac.computeModel(); ransac.getInliers(model); - //ransac.getModel (model); + // ransac.getModel (model); Eigen::VectorXf model_p_coefficients; - ransac.getModelCoefficients (model_p_coefficients); - for (int i=0; i -namespace Points {class PointKernel;} +namespace Points +{ +class PointKernel; +} -namespace Reen { +namespace Reen +{ class SampleConsensus { public: enum SacModel { - SACMODEL_PLANE, - SACMODEL_LINE, - SACMODEL_CIRCLE2D, - SACMODEL_CIRCLE3D, - SACMODEL_SPHERE, - SACMODEL_CYLINDER, - SACMODEL_CONE, - SACMODEL_TORUS, + SACMODEL_PLANE, + SACMODEL_LINE, + SACMODEL_CIRCLE2D, + SACMODEL_CIRCLE3D, + SACMODEL_SPHERE, + SACMODEL_CYLINDER, + SACMODEL_CONE, + SACMODEL_TORUS, }; SampleConsensus(SacModel sac, const Points::PointKernel&, const std::vector&); double perform(std::vector& parameters, std::vector& model); @@ -55,7 +59,6 @@ private: const std::vector& myNormals; }; -} // namespace Reen - -#endif // REEN_SAMPLECONSENSUS_H +}// namespace Reen +#endif// REEN_SAMPLECONSENSUS_H diff --git a/src/Mod/ReverseEngineering/App/Segmentation.cpp b/src/Mod/ReverseEngineering/App/Segmentation.cpp index 4f25a9344e..16d63459f0 100644 --- a/src/Mod/ReverseEngineering/App/Segmentation.cpp +++ b/src/Mod/ReverseEngineering/App/Segmentation.cpp @@ -28,38 +28,37 @@ #if defined(HAVE_PCL_FILTERS) -# include -# include -# include +#include +#include +#include #endif #if defined(HAVE_PCL_SAMPLE_CONSENSUS) -# include -# include +#include +#include #endif #if defined(HAVE_PCL_SEGMENTATION) -# include -# include -# include -# include +#include +#include +#include +#include #endif using namespace std; using namespace Reen; #if defined(HAVE_PCL_FILTERS) -using pcl::PointXYZ; -using pcl::PointNormal; using pcl::PointCloud; +using pcl::PointNormal; +using pcl::PointXYZ; #endif #if defined(HAVE_PCL_SEGMENTATION) -Segmentation::Segmentation(const Points::PointKernel& pts, std::list >& clusters) - : myPoints(pts) - , myClusters(clusters) -{ -} +Segmentation::Segmentation(const Points::PointKernel& pts, std::list>& clusters) + : myPoints(pts) + , myClusters(clusters) +{} void Segmentation::perform(int ksearch) { @@ -69,16 +68,18 @@ void Segmentation::perform(int ksearch) pcl::SACSegmentationFromNormals seg; pcl::ExtractIndices extract; pcl::ExtractIndices extract_normals; - pcl::search::KdTree::Ptr tree (new pcl::search::KdTree ()); + pcl::search::KdTree::Ptr tree(new pcl::search::KdTree()); // Datasets - pcl::PointCloud::Ptr cloud (new pcl::PointCloud); - pcl::PointCloud::Ptr cloud_filtered (new pcl::PointCloud); - pcl::PointCloud::Ptr cloud_normals (new pcl::PointCloud); - pcl::PointCloud::Ptr cloud_filtered2 (new pcl::PointCloud); - pcl::PointCloud::Ptr cloud_normals2 (new pcl::PointCloud); - pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients), coefficients_cylinder (new pcl::ModelCoefficients); - pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices), inliers_cylinder (new pcl::PointIndices); + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); + pcl::PointCloud::Ptr cloud_filtered(new pcl::PointCloud); + pcl::PointCloud::Ptr cloud_normals(new pcl::PointCloud); + pcl::PointCloud::Ptr cloud_filtered2(new pcl::PointCloud); + pcl::PointCloud::Ptr cloud_normals2(new pcl::PointCloud); + pcl::ModelCoefficients::Ptr coefficients_plane(new pcl::ModelCoefficients), + coefficients_cylinder(new pcl::ModelCoefficients); + pcl::PointIndices::Ptr inliers_plane(new pcl::PointIndices), + inliers_cylinder(new pcl::PointIndices); // Copy the points cloud->reserve(myPoints.size()); @@ -86,97 +87,96 @@ void Segmentation::perform(int ksearch) cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z)); } - cloud->width = int (cloud->points.size ()); + cloud->width = int(cloud->points.size()); cloud->height = 1; // Build a passthrough filter to remove spurious NaNs - pass.setInputCloud (cloud); - pass.setFilterFieldName ("z"); - pass.setFilterLimits (0, 1.5); - pass.filter (*cloud_filtered); + pass.setInputCloud(cloud); + pass.setFilterFieldName("z"); + pass.setFilterLimits(0, 1.5); + pass.filter(*cloud_filtered); // Estimate point normals - ne.setSearchMethod (tree); - ne.setInputCloud (cloud_filtered); - ne.setKSearch (ksearch); - ne.compute (*cloud_normals); + ne.setSearchMethod(tree); + ne.setInputCloud(cloud_filtered); + ne.setKSearch(ksearch); + ne.compute(*cloud_normals); // Create the segmentation object for the planar model and set all the parameters - seg.setOptimizeCoefficients (true); - seg.setModelType (pcl::SACMODEL_NORMAL_PLANE); - seg.setNormalDistanceWeight (0.1); - seg.setMethodType (pcl::SAC_RANSAC); - seg.setMaxIterations (100); - seg.setDistanceThreshold (0.03); - seg.setInputCloud (cloud_filtered); - seg.setInputNormals (cloud_normals); + seg.setOptimizeCoefficients(true); + seg.setModelType(pcl::SACMODEL_NORMAL_PLANE); + seg.setNormalDistanceWeight(0.1); + seg.setMethodType(pcl::SAC_RANSAC); + seg.setMaxIterations(100); + seg.setDistanceThreshold(0.03); + seg.setInputCloud(cloud_filtered); + seg.setInputNormals(cloud_normals); // Obtain the plane inliers and coefficients - seg.segment (*inliers_plane, *coefficients_plane); + seg.segment(*inliers_plane, *coefficients_plane); myClusters.push_back(inliers_plane->indices); // Extract the planar inliers from the input cloud - extract.setInputCloud (cloud_filtered); - extract.setIndices (inliers_plane); - extract.setNegative (false); + extract.setInputCloud(cloud_filtered); + extract.setIndices(inliers_plane); + extract.setNegative(false); // Write the planar inliers to disk - pcl::PointCloud::Ptr cloud_plane (new pcl::PointCloud ()); - extract.filter (*cloud_plane); + pcl::PointCloud::Ptr cloud_plane(new pcl::PointCloud()); + extract.filter(*cloud_plane); // Remove the planar inliers, extract the rest - extract.setNegative (true); - extract.filter (*cloud_filtered2); - extract_normals.setNegative (true); - extract_normals.setInputCloud (cloud_normals); - extract_normals.setIndices (inliers_plane); - extract_normals.filter (*cloud_normals2); + extract.setNegative(true); + extract.filter(*cloud_filtered2); + extract_normals.setNegative(true); + extract_normals.setInputCloud(cloud_normals); + extract_normals.setIndices(inliers_plane); + extract_normals.filter(*cloud_normals2); // Create the segmentation object for cylinder segmentation and set all the parameters - seg.setOptimizeCoefficients (true); - seg.setModelType (pcl::SACMODEL_CYLINDER); - seg.setNormalDistanceWeight (0.1); - seg.setMethodType (pcl::SAC_RANSAC); - seg.setMaxIterations (10000); - seg.setDistanceThreshold (0.05); - seg.setRadiusLimits (0, 0.1); - seg.setInputCloud (cloud_filtered2); - seg.setInputNormals (cloud_normals2); + seg.setOptimizeCoefficients(true); + seg.setModelType(pcl::SACMODEL_CYLINDER); + seg.setNormalDistanceWeight(0.1); + seg.setMethodType(pcl::SAC_RANSAC); + seg.setMaxIterations(10000); + seg.setDistanceThreshold(0.05); + seg.setRadiusLimits(0, 0.1); + seg.setInputCloud(cloud_filtered2); + seg.setInputNormals(cloud_normals2); // Obtain the cylinder inliers and coefficients - seg.segment (*inliers_cylinder, *coefficients_cylinder); + seg.segment(*inliers_cylinder, *coefficients_cylinder); myClusters.push_back(inliers_cylinder->indices); // Write the cylinder inliers to disk - extract.setInputCloud (cloud_filtered2); - extract.setIndices (inliers_cylinder); - extract.setNegative (false); - pcl::PointCloud::Ptr cloud_cylinder (new pcl::PointCloud ()); - extract.filter (*cloud_cylinder); + extract.setInputCloud(cloud_filtered2); + extract.setIndices(inliers_cylinder); + extract.setNegative(false); + pcl::PointCloud::Ptr cloud_cylinder(new pcl::PointCloud()); + extract.filter(*cloud_cylinder); } -#endif // HAVE_PCL_SEGMENTATION +#endif// HAVE_PCL_SEGMENTATION // ---------------------------------------------------------------------------- -#if defined (HAVE_PCL_FILTERS) +#if defined(HAVE_PCL_FILTERS) NormalEstimation::NormalEstimation(const Points::PointKernel& pts) - : myPoints(pts) - , kSearch(0) - , searchRadius(0) -{ -} + : myPoints(pts) + , kSearch(0) + , searchRadius(0) +{} void NormalEstimation::perform(std::vector& normals) { // Copy the points - pcl::PointCloud::Ptr cloud (new pcl::PointCloud); + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { cloud->push_back(pcl::PointXYZ(it->x, it->y, it->z)); } - cloud->width = int (cloud->points.size ()); + cloud->width = int(cloud->points.size()); cloud->height = 1; #if 0 @@ -190,22 +190,26 @@ void NormalEstimation::perform(std::vector& normals) #endif // Estimate point normals - pcl::PointCloud::Ptr cloud_normals (new pcl::PointCloud); - pcl::search::KdTree::Ptr tree (new pcl::search::KdTree ()); + pcl::PointCloud::Ptr cloud_normals(new pcl::PointCloud); + pcl::search::KdTree::Ptr tree(new pcl::search::KdTree()); pcl::NormalEstimation ne; - ne.setSearchMethod (tree); - //ne.setInputCloud (cloud_filtered); - ne.setInputCloud (cloud); - if (kSearch > 0) - ne.setKSearch (kSearch); - if (searchRadius > 0) - ne.setRadiusSearch (searchRadius); - ne.compute (*cloud_normals); + ne.setSearchMethod(tree); + // ne.setInputCloud (cloud_filtered); + ne.setInputCloud(cloud); + if (kSearch > 0) { + ne.setKSearch(kSearch); + } + if (searchRadius > 0) { + ne.setRadiusSearch(searchRadius); + } + ne.compute(*cloud_normals); normals.reserve(cloud_normals->size()); - for (pcl::PointCloud::const_iterator it = cloud_normals->begin(); it != cloud_normals->end(); ++it) { + for (pcl::PointCloud::const_iterator it = cloud_normals->begin(); + it != cloud_normals->end(); + ++it) { normals.push_back(Base::Vector3d(it->normal_x, it->normal_y, it->normal_z)); } } -#endif // HAVE_PCL_FILTERS +#endif// HAVE_PCL_FILTERS diff --git a/src/Mod/ReverseEngineering/App/Segmentation.h b/src/Mod/ReverseEngineering/App/Segmentation.h index 94137e2357..f03ec63e67 100644 --- a/src/Mod/ReverseEngineering/App/Segmentation.h +++ b/src/Mod/ReverseEngineering/App/Segmentation.h @@ -29,22 +29,26 @@ #include -namespace Points {class PointKernel;} +namespace Points +{ +class PointKernel; +} -namespace Reen { +namespace Reen +{ class Segmentation { public: - Segmentation(const Points::PointKernel&, std::list >& clusters); + Segmentation(const Points::PointKernel&, std::list>& clusters); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ + * \param[in] k the number of k-nearest neighbors + */ void perform(int ksearch); private: const Points::PointKernel& myPoints; - std::list >& myClusters; + std::list>& myClusters; }; class NormalEstimation @@ -52,24 +56,25 @@ class NormalEstimation public: explicit NormalEstimation(const Points::PointKernel&); /** \brief Set the number of k nearest neighbors to use for the feature estimation. - * \param[in] k the number of k-nearest neighbors - */ - inline void - setKSearch (int k) { kSearch = k; } + * \param[in] k the number of k-nearest neighbors + */ + inline void setKSearch(int k) + { + kSearch = k; + } - /** \brief Set the sphere radius that is to be used for determining the nearest neighbors used for the feature - * estimation. - * \param[in] radius the sphere radius used as the maximum distance to consider a point a neighbor - */ - inline void - setSearchRadius (double radius) + /** \brief Set the sphere radius that is to be used for determining the nearest neighbors used + * for the feature estimation. \param[in] radius the sphere radius used as the maximum distance + * to consider a point a neighbor + */ + inline void setSearchRadius(double radius) { searchRadius = radius; } /** \brief Perform the normal estimation. - * \param[out] the estimated normals - */ + * \param[out] the estimated normals + */ void perform(std::vector& normals); private: @@ -78,7 +83,6 @@ private: double searchRadius; }; -} // namespace Reen - -#endif // REEN_SEGMENTATION_H +}// namespace Reen +#endif// REEN_SEGMENTATION_H diff --git a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp index 4baaa5c870..c9e38d6a6d 100644 --- a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp +++ b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp @@ -23,36 +23,36 @@ #include "PreCompiled.h" #include -#include -#include #include #include #include +#include +#include #include "SurfaceTriangulation.h" // http://svn.pointclouds.org/pcl/tags/pcl-1.5.1/test/ #if defined(HAVE_PCL_SURFACE) -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifndef PCL_REVISION_VERSION -# define PCL_REVISION_VERSION 0 +#define PCL_REVISION_VERSION 0 #endif using namespace pcl; @@ -64,84 +64,86 @@ using namespace Reen; // http://www.ics.uci.edu/~gopi/PAPERS/Euro00.pdf // http://www.ics.uci.edu/~gopi/PAPERS/CGMV.pdf SurfaceTriangulation::SurfaceTriangulation(const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : myPoints(pts) - , myMesh(mesh) - , mu(0) - , searchRadius(0) -{ -} + : myPoints(pts) + , myMesh(mesh) + , mu(0) + , searchRadius(0) +{} void SurfaceTriangulation::perform(int ksearch) { - PointCloud::Ptr cloud (new PointCloud); - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud(new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; search::KdTree::Ptr tree2; cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(PointXYZ(it->x, it->y, it->z)); + } } // Create search tree - tree.reset (new search::KdTree (false)); - tree->setInputCloud (cloud); + tree.reset(new search::KdTree(false)); + tree->setInputCloud(cloud); // Normal estimation NormalEstimation n; - PointCloud::Ptr normals (new PointCloud ()); - n.setInputCloud (cloud); - //n.setIndices (indices[B); - n.setSearchMethod (tree); - n.setKSearch (ksearch); - n.compute (*normals); + PointCloud::Ptr normals(new PointCloud()); + n.setInputCloud(cloud); + // n.setIndices (indices[B); + n.setSearchMethod(tree); + n.setKSearch(ksearch); + n.compute(*normals); // Concatenate XYZ and normal information - pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); + pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); // Create search tree - tree2.reset (new search::KdTree); - tree2->setInputCloud (cloud_with_normals); + tree2.reset(new search::KdTree); + tree2->setInputCloud(cloud_with_normals); // Init objects GreedyProjectionTriangulation gp3; // Set parameters - gp3.setInputCloud (cloud_with_normals); - gp3.setSearchMethod (tree2); - gp3.setSearchRadius (searchRadius); - gp3.setMu (mu); - gp3.setMaximumNearestNeighbors (100); - gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees - gp3.setMinimumAngle(M_PI/18); // 10 degrees - gp3.setMaximumAngle(2*M_PI/3); // 120 degrees + gp3.setInputCloud(cloud_with_normals); + gp3.setSearchMethod(tree2); + gp3.setSearchRadius(searchRadius); + gp3.setMu(mu); + gp3.setMaximumNearestNeighbors(100); + gp3.setMaximumSurfaceAngle(M_PI / 4);// 45 degrees + gp3.setMinimumAngle(M_PI / 18); // 10 degrees + gp3.setMaximumAngle(2 * M_PI / 3); // 120 degrees gp3.setNormalConsistency(false); gp3.setConsistentVertexOrdering(true); // Reconstruct PolygonMesh mesh; - gp3.reconstruct (mesh); + gp3.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); // Additional vertex information - //std::vector parts = gp3.getPartIDs(); - //std::vector states = gp3.getPointStates(); + // std::vector parts = gp3.getPartIDs(); + // std::vector states = gp3.getPointStates(); } void SurfaceTriangulation::perform(const std::vector& normals) { - if (myPoints.size() != normals.size()) + if (myPoints.size() != normals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; cloud_with_normals->reserve(myPoints.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& normals) } // Create search tree - tree.reset (new search::KdTree); - tree->setInputCloud (cloud_with_normals); + tree.reset(new search::KdTree); + tree->setInputCloud(cloud_with_normals); // Init objects GreedyProjectionTriangulation gp3; // Set parameters - gp3.setInputCloud (cloud_with_normals); - gp3.setSearchMethod (tree); - gp3.setSearchRadius (searchRadius); - gp3.setMu (mu); - gp3.setMaximumNearestNeighbors (100); - gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees - gp3.setMinimumAngle(M_PI/18); // 10 degrees - gp3.setMaximumAngle(2*M_PI/3); // 120 degrees + gp3.setInputCloud(cloud_with_normals); + gp3.setSearchMethod(tree); + gp3.setSearchRadius(searchRadius); + gp3.setMu(mu); + gp3.setMaximumNearestNeighbors(100); + gp3.setMaximumSurfaceAngle(M_PI / 4);// 45 degrees + gp3.setMinimumAngle(M_PI / 18); // 10 degrees + gp3.setMaximumAngle(2 * M_PI / 3); // 120 degrees gp3.setNormalConsistency(true); gp3.setConsistentVertexOrdering(true); // Reconstruct PolygonMesh mesh; - gp3.reconstruct (mesh); + gp3.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); // Additional vertex information - //std::vector parts = gp3.getPartIDs(); - //std::vector states = gp3.getPointStates(); + // std::vector parts = gp3.getPartIDs(); + // std::vector states = gp3.getPointStates(); } // ---------------------------------------------------------------------------- @@ -191,79 +193,84 @@ void SurfaceTriangulation::perform(const std::vector& normals) // See // http://www.cs.jhu.edu/~misha/Code/PoissonRecon/Version8.0/ PoissonReconstruction::PoissonReconstruction(const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : myPoints(pts) - , myMesh(mesh) - , depth(-1) - , solverDivide(-1) - , samplesPerNode(-1.0f) -{ -} + : myPoints(pts) + , myMesh(mesh) + , depth(-1) + , solverDivide(-1) + , samplesPerNode(-1.0f) +{} void PoissonReconstruction::perform(int ksearch) { - PointCloud::Ptr cloud (new PointCloud); - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud(new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; search::KdTree::Ptr tree2; cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(PointXYZ(it->x, it->y, it->z)); + } } // Create search tree - tree.reset (new search::KdTree (false)); - tree->setInputCloud (cloud); + tree.reset(new search::KdTree(false)); + tree->setInputCloud(cloud); // Normal estimation NormalEstimation n; - PointCloud::Ptr normals (new PointCloud ()); - n.setInputCloud (cloud); - //n.setIndices (indices[B); - n.setSearchMethod (tree); - n.setKSearch (ksearch); - n.compute (*normals); + PointCloud::Ptr normals(new PointCloud()); + n.setInputCloud(cloud); + // n.setIndices (indices[B); + n.setSearchMethod(tree); + n.setKSearch(ksearch); + n.compute(*normals); // Concatenate XYZ and normal information - pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); + pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); // Create search tree - tree2.reset (new search::KdTree); - tree2->setInputCloud (cloud_with_normals); + tree2.reset(new search::KdTree); + tree2->setInputCloud(cloud_with_normals); // Init objects Poisson poisson; // Set parameters - poisson.setInputCloud (cloud_with_normals); - poisson.setSearchMethod (tree2); - if (depth >= 1) + poisson.setInputCloud(cloud_with_normals); + poisson.setSearchMethod(tree2); + if (depth >= 1) { poisson.setDepth(depth); - if (solverDivide >= 1) + } + if (solverDivide >= 1) { poisson.setSolverDivide(solverDivide); - if (samplesPerNode >= 1.0f) + } + if (samplesPerNode >= 1.0f) { poisson.setSamplesPerNode(samplesPerNode); + } // Reconstruct PolygonMesh mesh; - poisson.reconstruct (mesh); + poisson.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } void PoissonReconstruction::perform(const std::vector& normals) { - if (myPoints.size() != normals.size()) + if (myPoints.size() != normals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; cloud_with_normals->reserve(myPoints.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& normals) } // Create search tree - tree.reset (new search::KdTree); - tree->setInputCloud (cloud_with_normals); + tree.reset(new search::KdTree); + tree->setInputCloud(cloud_with_normals); // Init objects Poisson poisson; // Set parameters - poisson.setInputCloud (cloud_with_normals); - poisson.setSearchMethod (tree); - if (depth >= 1) + poisson.setInputCloud(cloud_with_normals); + poisson.setSearchMethod(tree); + if (depth >= 1) { poisson.setDepth(depth); - if (solverDivide >= 1) + } + if (solverDivide >= 1) { poisson.setSolverDivide(solverDivide); - if (samplesPerNode >= 1.0f) + } + if (samplesPerNode >= 1.0f) { poisson.setSamplesPerNode(samplesPerNode); + } // Reconstruct PolygonMesh mesh; - poisson.reconstruct (mesh); + poisson.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } @@ -305,43 +315,44 @@ void PoissonReconstruction::perform(const std::vector& normals) // ---------------------------------------------------------------------------- GridReconstruction::GridReconstruction(const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : myPoints(pts) - , myMesh(mesh) -{ -} + : myPoints(pts) + , myMesh(mesh) +{} void GridReconstruction::perform(int ksearch) { - PointCloud::Ptr cloud (new PointCloud); - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud(new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; search::KdTree::Ptr tree2; cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(PointXYZ(it->x, it->y, it->z)); + } } // Create search tree - tree.reset (new search::KdTree (false)); - tree->setInputCloud (cloud); + tree.reset(new search::KdTree(false)); + tree->setInputCloud(cloud); // Normal estimation NormalEstimation n; - PointCloud::Ptr normals (new PointCloud ()); - n.setInputCloud (cloud); - //n.setIndices (indices[B); - n.setSearchMethod (tree); - n.setKSearch (ksearch); - n.compute (*normals); + PointCloud::Ptr normals(new PointCloud()); + n.setInputCloud(cloud); + // n.setIndices (indices[B); + n.setSearchMethod(tree); + n.setKSearch(ksearch); + n.compute(*normals); // Concatenate XYZ and normal information - pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); + pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); // Create search tree - tree2.reset (new search::KdTree); - tree2->setInputCloud (cloud_with_normals); + tree2.reset(new search::KdTree); + tree2->setInputCloud(cloud_with_normals); // Init objects GridProjection grid; @@ -351,28 +362,29 @@ void GridReconstruction::perform(int ksearch) grid.setPaddingSize(3); grid.setNearestNeighborNum(100); grid.setMaxBinarySearchLevel(10); - grid.setInputCloud (cloud_with_normals); - grid.setSearchMethod (tree2); + grid.setInputCloud(cloud_with_normals); + grid.setSearchMethod(tree2); // Reconstruct PolygonMesh mesh; - grid.reconstruct (mesh); + grid.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } void GridReconstruction::perform(const std::vector& normals) { - if (myPoints.size() != normals.size()) + if (myPoints.size() != normals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; cloud_with_normals->reserve(myPoints.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& normals) } // Create search tree - tree.reset (new search::KdTree); - tree->setInputCloud (cloud_with_normals); + tree.reset(new search::KdTree); + tree->setInputCloud(cloud_with_normals); // Init objects GridProjection grid; @@ -399,36 +411,39 @@ void GridReconstruction::perform(const std::vector& normals) grid.setPaddingSize(3); grid.setNearestNeighborNum(100); grid.setMaxBinarySearchLevel(10); - grid.setInputCloud (cloud_with_normals); - grid.setSearchMethod (tree); + grid.setInputCloud(cloud_with_normals); + grid.setSearchMethod(tree); // Reconstruct PolygonMesh mesh; - grid.reconstruct (mesh); + grid.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } // ---------------------------------------------------------------------------- -ImageTriangulation::ImageTriangulation(int width, int height, const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : width(width) - , height(height) - , myPoints(pts) - , myMesh(mesh) -{ -} +ImageTriangulation::ImageTriangulation(int width, + int height, + const Points::PointKernel& pts, + Mesh::MeshObject& mesh) + : width(width) + , height(height) + , myPoints(pts) + , myMesh(mesh) +{} void ImageTriangulation::perform() { - if (myPoints.size() != static_cast(width * height)) + if (myPoints.size() != static_cast(width * height)) { throw Base::RuntimeError("Number of points doesn't match with given width and height"); + } - //construct dataset - pcl::PointCloud::Ptr cloud_organized (new pcl::PointCloud ()); + // construct dataset + pcl::PointCloud::Ptr cloud_organized(new pcl::PointCloud()); cloud_organized->width = width; cloud_organized->height = height; - cloud_organized->points.resize (cloud_organized->width * cloud_organized->height); + cloud_organized->points.resize(cloud_organized->width * cloud_organized->height); const std::vector& points = myPoints.getBasicPoints(); @@ -446,16 +461,16 @@ void ImageTriangulation::perform() OrganizedFastMesh ofm; // Set parameters - ofm.setInputCloud (cloud_organized); + ofm.setInputCloud(cloud_organized); // This parameter is not yet implemented (pcl 1.7) - ofm.setMaxEdgeLength (1.5); - ofm.setTrianglePixelSize (1); - ofm.setTriangulationType (OrganizedFastMesh::TRIANGLE_ADAPTIVE_CUT); + ofm.setMaxEdgeLength(1.5); + ofm.setTrianglePixelSize(1); + ofm.setTriangulationType(OrganizedFastMesh::TRIANGLE_ADAPTIVE_CUT); ofm.storeShadowedFaces(true); // Reconstruct PolygonMesh mesh; - ofm.reconstruct (mesh); + ofm.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); @@ -466,7 +481,7 @@ void ImageTriangulation::perform() MeshCore::MeshAlgorithm meshAlg(kernel); meshAlg.SetPointFlag(MeshCore::MeshPoint::INVALID); std::vector validPoints; - validPoints.reserve(face.size()*3); + validPoints.reserve(face.size() * 3); for (MeshCore::MeshFacetArray::_TConstIterator it = face.begin(); it != face.end(); ++it) { validPoints.push_back(it->_aulPoints[0]); validPoints.push_back(it->_aulPoints[1]); @@ -491,75 +506,77 @@ void ImageTriangulation::perform() // ---------------------------------------------------------------------------- Reen::MarchingCubesRBF::MarchingCubesRBF(const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : myPoints(pts) - , myMesh(mesh) -{ -} + : myPoints(pts) + , myMesh(mesh) +{} void Reen::MarchingCubesRBF::perform(int ksearch) { - PointCloud::Ptr cloud (new PointCloud); - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud(new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; search::KdTree::Ptr tree2; cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(PointXYZ(it->x, it->y, it->z)); + } } // Create search tree - tree.reset (new search::KdTree (false)); - tree->setInputCloud (cloud); + tree.reset(new search::KdTree(false)); + tree->setInputCloud(cloud); // Normal estimation NormalEstimation n; - PointCloud::Ptr normals (new PointCloud ()); - n.setInputCloud (cloud); - //n.setIndices (indices[B); - n.setSearchMethod (tree); - n.setKSearch (ksearch); - n.compute (*normals); + PointCloud::Ptr normals(new PointCloud()); + n.setInputCloud(cloud); + // n.setIndices (indices[B); + n.setSearchMethod(tree); + n.setKSearch(ksearch); + n.compute(*normals); // Concatenate XYZ and normal information - pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); + pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); // Create search tree - tree2.reset (new search::KdTree); - tree2->setInputCloud (cloud_with_normals); + tree2.reset(new search::KdTree); + tree2->setInputCloud(cloud_with_normals); // Init objects pcl::MarchingCubesRBF rbf; // Set parameters - rbf.setIsoLevel (0); - rbf.setGridResolution (60, 60, 60); - rbf.setPercentageExtendGrid (0.1f); - rbf.setOffSurfaceDisplacement (0.02f); + rbf.setIsoLevel(0); + rbf.setGridResolution(60, 60, 60); + rbf.setPercentageExtendGrid(0.1f); + rbf.setOffSurfaceDisplacement(0.02f); - rbf.setInputCloud (cloud_with_normals); - rbf.setSearchMethod (tree2); + rbf.setInputCloud(cloud_with_normals); + rbf.setSearchMethod(tree2); // Reconstruct PolygonMesh mesh; - rbf.reconstruct (mesh); + rbf.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } void Reen::MarchingCubesRBF::perform(const std::vector& normals) { - if (myPoints.size() != normals.size()) + if (myPoints.size() != normals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; cloud_with_normals->reserve(myPoints.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& normals) } // Create search tree - tree.reset (new search::KdTree); - tree->setInputCloud (cloud_with_normals); + tree.reset(new search::KdTree); + tree->setInputCloud(cloud_with_normals); // Init objects pcl::MarchingCubesRBF rbf; // Set parameters - rbf.setIsoLevel (0); - rbf.setGridResolution (60, 60, 60); - rbf.setPercentageExtendGrid (0.1f); - rbf.setOffSurfaceDisplacement (0.02f); + rbf.setIsoLevel(0); + rbf.setGridResolution(60, 60, 60); + rbf.setPercentageExtendGrid(0.1f); + rbf.setOffSurfaceDisplacement(0.02f); - rbf.setInputCloud (cloud_with_normals); - rbf.setSearchMethod (tree); + rbf.setInputCloud(cloud_with_normals); + rbf.setSearchMethod(tree); // Reconstruct PolygonMesh mesh; - rbf.reconstruct (mesh); + rbf.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } @@ -601,74 +618,76 @@ void Reen::MarchingCubesRBF::perform(const std::vector& normals) // ---------------------------------------------------------------------------- Reen::MarchingCubesHoppe::MarchingCubesHoppe(const Points::PointKernel& pts, Mesh::MeshObject& mesh) - : myPoints(pts) - , myMesh(mesh) -{ -} + : myPoints(pts) + , myMesh(mesh) +{} void Reen::MarchingCubesHoppe::perform(int ksearch) { - PointCloud::Ptr cloud (new PointCloud); - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud(new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; search::KdTree::Ptr tree2; cloud->reserve(myPoints.size()); for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) { - if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z)) + if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) + && !boost::math::isnan(it->z)) { cloud->push_back(PointXYZ(it->x, it->y, it->z)); + } } // Create search tree - tree.reset (new search::KdTree (false)); - tree->setInputCloud (cloud); + tree.reset(new search::KdTree(false)); + tree->setInputCloud(cloud); // Normal estimation NormalEstimation n; - PointCloud::Ptr normals (new PointCloud ()); - n.setInputCloud (cloud); - //n.setIndices (indices[B); - n.setSearchMethod (tree); - n.setKSearch (ksearch); - n.compute (*normals); + PointCloud::Ptr normals(new PointCloud()); + n.setInputCloud(cloud); + // n.setIndices (indices[B); + n.setSearchMethod(tree); + n.setKSearch(ksearch); + n.compute(*normals); // Concatenate XYZ and normal information - pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); + pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); // Create search tree - tree2.reset (new search::KdTree); - tree2->setInputCloud (cloud_with_normals); + tree2.reset(new search::KdTree); + tree2->setInputCloud(cloud_with_normals); // Init objects pcl::MarchingCubesHoppe hoppe; // Set parameters - hoppe.setIsoLevel (0); - hoppe.setGridResolution (60, 60, 60); - hoppe.setPercentageExtendGrid (0.1f); + hoppe.setIsoLevel(0); + hoppe.setGridResolution(60, 60, 60); + hoppe.setPercentageExtendGrid(0.1f); - hoppe.setInputCloud (cloud_with_normals); - hoppe.setSearchMethod (tree2); + hoppe.setInputCloud(cloud_with_normals); + hoppe.setSearchMethod(tree2); // Reconstruct PolygonMesh mesh; - hoppe.reconstruct (mesh); + hoppe.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } void Reen::MarchingCubesHoppe::perform(const std::vector& normals) { - if (myPoints.size() != normals.size()) + if (myPoints.size() != normals.size()) { throw Base::RuntimeError("Number of points doesn't match with number of normals"); + } - PointCloud::Ptr cloud_with_normals (new PointCloud); + PointCloud::Ptr cloud_with_normals(new PointCloud); search::KdTree::Ptr tree; cloud_with_normals->reserve(myPoints.size()); std::size_t num_points = myPoints.size(); const std::vector& points = myPoints.getBasicPoints(); - for (std::size_t index=0; index& normal } // Create search tree - tree.reset (new search::KdTree); - tree->setInputCloud (cloud_with_normals); + tree.reset(new search::KdTree); + tree->setInputCloud(cloud_with_normals); // Init objects pcl::MarchingCubesHoppe hoppe; // Set parameters - hoppe.setIsoLevel (0); - hoppe.setGridResolution (60, 60, 60); - hoppe.setPercentageExtendGrid (0.1f); + hoppe.setIsoLevel(0); + hoppe.setGridResolution(60, 60, 60); + hoppe.setPercentageExtendGrid(0.1f); - hoppe.setInputCloud (cloud_with_normals); - hoppe.setSearchMethod (tree); + hoppe.setInputCloud(cloud_with_normals); + hoppe.setSearchMethod(tree); // Reconstruct PolygonMesh mesh; - hoppe.reconstruct (mesh); + hoppe.reconstruct(mesh); MeshConversion::convert(mesh, myMesh); } @@ -711,10 +730,10 @@ void Reen::MarchingCubesHoppe::perform(const std::vector& normal void MeshConversion::convert(const pcl::PolygonMesh& pclMesh, Mesh::MeshObject& meshObject) { // number of points - size_t nr_points = pclMesh.cloud.width * pclMesh.cloud.height; - size_t point_size = pclMesh.cloud.data.size () / nr_points; + size_t nr_points = pclMesh.cloud.width * pclMesh.cloud.height; + size_t point_size = pclMesh.cloud.data.size() / nr_points; // number of faces for header - size_t nr_faces = pclMesh.polygons.size (); + size_t nr_faces = pclMesh.polygons.size(); MeshCore::MeshPointArray points; points.reserve(nr_points); @@ -729,17 +748,20 @@ void MeshConversion::convert(const pcl::PolygonMesh& pclMesh, Mesh::MeshObject& int c = 0; // adding vertex if ((pclMesh.cloud.fields[d].datatype == -#if PCL_VERSION_COMPARE(>,1,6,0) - pcl::PCLPointField::FLOAT32) && +#if PCL_VERSION_COMPARE(>, 1, 6, 0) + pcl::PCLPointField::FLOAT32) + && #else - sensor_msgs::PointField::FLOAT32) && + sensor_msgs::PointField::FLOAT32) + && #endif - (pclMesh.cloud.fields[d].name == "x" || - pclMesh.cloud.fields[d].name == "y" || - pclMesh.cloud.fields[d].name == "z")) - { + (pclMesh.cloud.fields[d].name == "x" || pclMesh.cloud.fields[d].name == "y" + || pclMesh.cloud.fields[d].name == "z")) { float value; - memcpy (&value, &pclMesh.cloud.data[i * point_size + pclMesh.cloud.fields[d].offset + c * sizeof (float)], sizeof (float)); + memcpy(&value, + &pclMesh.cloud.data[i * point_size + pclMesh.cloud.fields[d].offset + + c * sizeof(float)], + sizeof(float)); vertex[xyz] = value; if (++xyz == 3) { points.push_back(vertex); @@ -763,4 +785,4 @@ void MeshConversion::convert(const pcl::PolygonMesh& pclMesh, Mesh::MeshObject& meshObject.harmonizeNormals(); } -#endif // HAVE_PCL_SURFACE +#endif// HAVE_PCL_SURFACE diff --git a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.h b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.h index 3041d72ab5..d96b8e17ec 100644 --- a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.h +++ b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.h @@ -28,11 +28,21 @@ #include -namespace Points {class PointKernel;} -namespace Mesh {class MeshObject;} -namespace pcl {struct PolygonMesh;} +namespace Points +{ +class PointKernel; +} +namespace Mesh +{ +class MeshObject; +} +namespace pcl +{ +struct PolygonMesh; +} -namespace Reen { +namespace Reen +{ class MeshConversion { @@ -45,27 +55,31 @@ class SurfaceTriangulation public: SurfaceTriangulation(const Points::PointKernel&, Mesh::MeshObject&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ + * \param[in] k the number of k-nearest neighbors + */ void perform(int ksearch); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); - /** \brief Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point - * (this will make the algorithm adapt to different point densities in the cloud). - * \param[in] mu the multiplier - */ - inline void - setMu (double mu) { this->mu = mu; } + /** \brief Set the multiplier of the nearest neighbor distance to obtain the final search radius + * for each point (this will make the algorithm adapt to different point densities in the + * cloud). \param[in] mu the multiplier + */ + inline void setMu(double mu) + { + this->mu = mu; + } - /** \brief Set the sphere radius that is to be used for determining the k-nearest neighbors used for triangulating. - * \param[in] radius the sphere radius that is to contain all k-nearest neighbors - * \note This distance limits the maximum edge length! - */ - inline void - setSearchRadius (double radius) { this->searchRadius = radius; } + /** \brief Set the sphere radius that is to be used for determining the k-nearest neighbors used + * for triangulating. \param[in] radius the sphere radius that is to contain all k-nearest + * neighbors \note This distance limits the maximum edge length! + */ + inline void setSearchRadius(double radius) + { + this->searchRadius = radius; + } private: const Points::PointKernel& myPoints; @@ -79,40 +93,46 @@ class PoissonReconstruction public: PoissonReconstruction(const Points::PointKernel&, Mesh::MeshObject&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ - void perform(int ksearch=5); + * \param[in] k the number of k-nearest neighbors + */ + void perform(int ksearch = 5); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); /** \brief Set the maximum depth of the tree that will be used for surface reconstruction. - * \note Running at depth d corresponds to solving on a voxel grid whose resolution is no larger than - * 2^d x 2^d x 2^d. Note that since the reconstructor adapts the octree to the sampling density, the specified - * reconstruction depth is only an upper bound. - * \param[in] depth the depth parameter - */ - inline void - setDepth (int depth) { this->depth = depth; } + * \note Running at depth d corresponds to solving on a voxel grid whose resolution is no larger + * than 2^d x 2^d x 2^d. Note that since the reconstructor adapts the octree to the sampling + * density, the specified reconstruction depth is only an upper bound. \param[in] depth the + * depth parameter + */ + inline void setDepth(int depth) + { + this->depth = depth; + } - /** \brief Set the depth at which a block Gauss-Seidel solver is used to solve the Laplacian equation - * \note Using this parameter helps reduce the memory overhead at the cost of a small increase in - * reconstruction time. (In practice, we have found that for reconstructions of depth 9 or higher a subdivide - * depth of 7 or 8 can greatly reduce the memory usage.) - * \param[in] solver_divide the given parameter value - */ - inline void - setSolverDivide (int solverDivide) { this->solverDivide = solverDivide; } + /** \brief Set the depth at which a block Gauss-Seidel solver is used to solve the Laplacian + * equation \note Using this parameter helps reduce the memory overhead at the cost of a small + * increase in reconstruction time. (In practice, we have found that for reconstructions of + * depth 9 or higher a subdivide depth of 7 or 8 can greatly reduce the memory usage.) + * \param[in] solver_divide the given parameter value + */ + inline void setSolverDivide(int solverDivide) + { + this->solverDivide = solverDivide; + } - /** \brief Set the minimum number of sample points that should fall within an octree node as the octree - * construction is adapted to sampling density - * \note For noise-free samples, small values in the range [1.0 - 5.0] can be used. For more noisy samples, - * larger values in the range [15.0 - 20.0] may be needed to provide a smoother, noise-reduced, reconstruction. - * \param[in] samples_per_node the given parameter value - */ - inline void - setSamplesPerNode(float samplesPerNode) { this->samplesPerNode = samplesPerNode; } + /** \brief Set the minimum number of sample points that should fall within an octree node as the + * octree construction is adapted to sampling density \note For noise-free samples, small values + * in the range [1.0 - 5.0] can be used. For more noisy samples, larger values in the range + * [15.0 - 20.0] may be needed to provide a smoother, noise-reduced, reconstruction. \param[in] + * samples_per_node the given parameter value + */ + inline void setSamplesPerNode(float samplesPerNode) + { + this->samplesPerNode = samplesPerNode; + } private: const Points::PointKernel& myPoints; @@ -127,12 +147,12 @@ class GridReconstruction public: GridReconstruction(const Points::PointKernel&, Mesh::MeshObject&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ - void perform(int ksearch=5); + * \param[in] k the number of k-nearest neighbors + */ + void perform(int ksearch = 5); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); private: @@ -157,12 +177,12 @@ class MarchingCubesRBF public: MarchingCubesRBF(const Points::PointKernel&, Mesh::MeshObject&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ - void perform(int ksearch=5); + * \param[in] k the number of k-nearest neighbors + */ + void perform(int ksearch = 5); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); private: @@ -175,12 +195,12 @@ class MarchingCubesHoppe public: MarchingCubesHoppe(const Points::PointKernel&, Mesh::MeshObject&); /** \brief Set the number of k nearest neighbors to use for the normal estimation. - * \param[in] k the number of k-nearest neighbors - */ - void perform(int ksearch=5); + * \param[in] k the number of k-nearest neighbors + */ + void perform(int ksearch = 5); /** \brief Pass the normals to the points given in the constructor. - * \param[in] normals the normals to the given points. - */ + * \param[in] normals the normals to the given points. + */ void perform(const std::vector& normals); private: @@ -188,7 +208,6 @@ private: Mesh::MeshObject& myMesh; }; -} // namespace Reen - -#endif // REEN_SURFACETRIANGULATION_H +}// namespace Reen +#endif// REEN_SURFACETRIANGULATION_H diff --git a/src/Mod/ReverseEngineering/InitGui.py b/src/Mod/ReverseEngineering/InitGui.py index 7b647c2b5a..148bc9b369 100644 --- a/src/Mod/ReverseEngineering/InitGui.py +++ b/src/Mod/ReverseEngineering/InitGui.py @@ -1,25 +1,25 @@ -#*************************************************************************** -#* Copyright (c) 2002 Juergen Riegel * -#* * -#* This file is part of the FreeCAD CAx development system. * -#* * -#* This program is free software; you can redistribute it and/or modify * -#* it under the terms of the GNU Lesser General Public License (LGPL) * -#* as published by the Free Software Foundation; either version 2 of * -#* the License, or (at your option) any later version. * -#* for detail see the LICENCE text file. * -#* * -#* FreeCAD is distributed in the hope that it will be useful, * -#* but WITHOUT ANY WARRANTY; without even the implied warranty of * -#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -#* GNU Lesser General Public License for more details. * -#* * -#* You should have received a copy of the GNU Library General Public * -#* License along with FreeCAD; if not, write to the Free Software * -#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * -#* USA * -#* * -#***************************************************************************/ +# *************************************************************************** +# * Copyright (c) 2002 Juergen Riegel * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Lesser General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# ***************************************************************************/ # ReverseEngineering gui init module # @@ -28,10 +28,14 @@ # runs when the gui is up -class ReverseEngineeringWorkbench ( Workbench ): +class ReverseEngineeringWorkbench(Workbench): "ReverseEngineering workbench object" + def __init__(self): - self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/ReverseEngineering/Resources/icons/ReverseEngineeringWorkbench.svg" + self.__class__.Icon = ( + FreeCAD.getResourceDir() + + "Mod/ReverseEngineering/Resources/icons/ReverseEngineeringWorkbench.svg" + ) self.__class__.MenuText = "Reverse Engineering" self.__class__.ToolTip = "Reverse Engineering workbench" @@ -39,7 +43,9 @@ class ReverseEngineeringWorkbench ( Workbench ): # load the module import ReverseEngineeringGui import ReverseEngineering + def GetClassName(self): return "ReverseEngineeringGui::Workbench" + Gui.addWorkbench(ReverseEngineeringWorkbench()) diff --git a/src/Mod/ReverseEngineering/ReverseEngineeringGlobal.h b/src/Mod/ReverseEngineering/ReverseEngineeringGlobal.h index 329692bba2..f4189d8227 100644 --- a/src/Mod/ReverseEngineering/ReverseEngineeringGlobal.h +++ b/src/Mod/ReverseEngineering/ReverseEngineeringGlobal.h @@ -29,19 +29,19 @@ // Reen #ifndef ReenExport #ifdef ReverseEngineering_EXPORTS -# define ReenExport FREECAD_DECL_EXPORT +#define ReenExport FREECAD_DECL_EXPORT #else -# define ReenExport FREECAD_DECL_IMPORT +#define ReenExport FREECAD_DECL_IMPORT #endif #endif // ReenGui #ifndef ReenGuiExport #ifdef ReverseEngineeringGui_EXPORTS -# define ReenGuiExport FREECAD_DECL_EXPORT +#define ReenGuiExport FREECAD_DECL_EXPORT #else -# define ReenGuiExport FREECAD_DECL_IMPORT +#define ReenGuiExport FREECAD_DECL_IMPORT #endif #endif -#endif //REEN_GLOBAL_H +#endif// REEN_GLOBAL_H