/************************************************************************** * Copyright (c) 2007 Joachim Zettler * * Copyright (c) 2007 Human Rezai * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #include "deviation.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include Deviation::Deviation() {} Deviation::~Deviation() {} void Deviation::ImportGeometry(const TopoDS_Shape& aShape, const MeshCore::MeshKernel& aMesh) { m_Mesh = aMesh; m_Cad = aShape; } bool Deviation::GenNormals() { Base::Builder3D log; TopExp_Explorer aExpFace; MeshPnt aMeshStruct; std::pair inp; std::map::iterator meshIt; MeshCore::MeshKernel FaceMesh; MeshCore::MeshPointArray MeshPnts; int n; MeshPnts = m_MeshCad.GetPoints(); m_pnts.resize(m_MeshCad.CountPoints()); m_nlvec.resize((m_MeshCad.CountPoints())); for (unsigned int i=0; iNodes(); // create array of node points in absolute coordinate system TColgp_Array1OfPnt aPoints(1, aNodes.Length()); for (Standard_Integer i = 1; i <= aNodes.Length(); i++) aPoints(i) = aNodes(i).Transformed(aLocation); const TColgp_Array1OfPnt2d& aUVNodes = aTr->UVNodes(); BRepAdaptor_Surface aSurface(aFace); Base::Vector3f pnt, normal; gp_Pnt2d par; gp_Pnt P; gp_Vec D1U, D1V; for (int i=1; i FailProj; MeshCore::MeshFacetGrid aFacetGrid(m_Mesh,10); MeshCore::MeshAlgorithm malg(m_Mesh); MeshCore::MeshAlgorithm malg2(m_Mesh); MeshCore::MeshPointIterator p_it(m_MeshCad); Base::Vector3f projPoint, distVec, nvec(0,0,0), projPoint2; unsigned long facetIndex; std::stringstream text; unsigned int c=0; int i=0; for (p_it.Begin(); p_it.More(); p_it.Next()) { if (malg.NearestFacetOnRay(*p_it, m_nlvec[i], aFacetGrid, projPoint, facetIndex)) // gridoptimiert { distVec = projPoint - *p_it; m_nlvec[i] = distVec; // überschreibt normalenvektor } else { if (!malg2.NearestFacetOnRay(*p_it, m_nlvec[i], projPoint, facetIndex)) // nicht gridoptimiert { c++; FailProj.push_back(i); m_nlvec[i] = nvec; } else { distVec = projPoint - *p_it; m_nlvec[i] = distVec; // überschreibt normalenvektor } } ++i; } for(int i=0; i #include void Deviation::WriteOutput(const QString &dateiname) { QFile anOutputFile(dateiname); if (!anOutputFile.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&anOutputFile); out << m_nlvec.size() << endl; for(int i=0; i