| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <limits>
|
| |
|
| | #include <Base/Converter.h>
|
| |
|
| | #include "Core/Algorithm.h"
|
| | #include "Core/Evaluation.h"
|
| |
|
| | #include "FeatureMeshSegmentByMesh.h"
|
| |
|
| |
|
| | using namespace Mesh;
|
| | using namespace MeshCore;
|
| |
|
| | PROPERTY_SOURCE(Mesh::SegmentByMesh, Mesh::Feature)
|
| |
|
| |
|
| | SegmentByMesh::SegmentByMesh()
|
| | {
|
| | ADD_PROPERTY(Source, (nullptr));
|
| | ADD_PROPERTY(Tool, (nullptr));
|
| | ADD_PROPERTY(Base, (0.0, 0.0, 0.0));
|
| | ADD_PROPERTY(Normal, (0.0, 0.0, 1.0));
|
| | }
|
| |
|
| | short SegmentByMesh::mustExecute() const
|
| | {
|
| | if (Source.isTouched() || Tool.isTouched()) {
|
| | return 1;
|
| | }
|
| | if (Source.getValue() && Source.getValue()->isTouched()) {
|
| | return 1;
|
| | }
|
| | if (Tool.getValue() && Tool.getValue()->isTouched()) {
|
| | return 1;
|
| | }
|
| | return 0;
|
| | }
|
| |
|
| | App::DocumentObjectExecReturn* SegmentByMesh::execute()
|
| | {
|
| | Mesh::PropertyMeshKernel* kernel = nullptr;
|
| | App::DocumentObject* mesh = Source.getValue();
|
| | if (mesh) {
|
| | App::Property* prop = mesh->getPropertyByName("Mesh");
|
| | if (prop && prop->is<Mesh::PropertyMeshKernel>()) {
|
| | kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
|
| | }
|
| | }
|
| | if (!kernel) {
|
| | return new App::DocumentObjectExecReturn("No mesh specified.\n");
|
| | }
|
| | if (mesh->isError()) {
|
| | return new App::DocumentObjectExecReturn("No valid mesh.\n");
|
| | }
|
| |
|
| | Mesh::PropertyMeshKernel* toolmesh = nullptr;
|
| | App::DocumentObject* tool = Tool.getValue();
|
| | if (tool) {
|
| | App::Property* prop = tool->getPropertyByName("Mesh");
|
| | if (prop && prop->is<Mesh::PropertyMeshKernel>()) {
|
| | toolmesh = static_cast<Mesh::PropertyMeshKernel*>(prop);
|
| | }
|
| | }
|
| | if (!toolmesh) {
|
| | return new App::DocumentObjectExecReturn("No toolmesh specified.\n");
|
| | }
|
| | if (tool->isError()) {
|
| | return new App::DocumentObjectExecReturn("No valid toolmesh.\n");
|
| | }
|
| |
|
| |
|
| | Base::Vector3f cBase, cNormal;
|
| | cBase = Base::convertTo<Base::Vector3f>(Base.getValue());
|
| | cNormal = Base::convertTo<Base::Vector3f>(Normal.getValue());
|
| |
|
| |
|
| | const MeshKernel& rMeshKernel = kernel->getValue().getKernel();
|
| | const MeshKernel& rToolMesh = toolmesh->getValue().getKernel();
|
| |
|
| |
|
| | if (!MeshEvalSolid(rToolMesh).Evaluate()) {
|
| | return new App::DocumentObjectExecReturn("Toolmesh is not solid.\n");
|
| | }
|
| |
|
| | std::vector<MeshCore::FacetIndex> faces;
|
| |
|
| | MeshAlgorithm cAlg(rMeshKernel);
|
| | if (cNormal.Length() > 0.1F) {
|
| | cAlg.GetFacetsFromToolMesh(rToolMesh, cNormal, faces);
|
| | }
|
| | else {
|
| | cAlg.GetFacetsFromToolMesh(rToolMesh, Base::Vector3f(0.0, 1.0F, 0.0F), faces);
|
| | }
|
| |
|
| |
|
| | if (cNormal.Length() > 0.1F) {
|
| |
|
| |
|
| |
|
| | float fDist = std::numeric_limits<float>::max();
|
| | MeshCore::FacetIndex uIdx = MeshCore::FACET_INDEX_MAX;
|
| | MeshFacetIterator cFIt(rMeshKernel);
|
| |
|
| |
|
| | for (MeshCore::FacetIndex it : faces) {
|
| | cFIt.Set(it);
|
| | float dist = (float)fabs(cFIt->GetGravityPoint().DistanceToPlane(cBase, cNormal));
|
| | if (dist < fDist) {
|
| | fDist = dist;
|
| | uIdx = it;
|
| | }
|
| | }
|
| |
|
| |
|
| | if (uIdx != MeshCore::FACET_INDEX_MAX) {
|
| |
|
| | cAlg.SetFacetFlag(MeshFacet::VISIT);
|
| | cAlg.ResetFacetsFlag(faces, MeshFacet::VISIT);
|
| |
|
| | faces.clear();
|
| | MeshTopFacetVisitor clVisitor(faces);
|
| | rMeshKernel.VisitNeighbourFacets(clVisitor, uIdx);
|
| |
|
| |
|
| | faces.push_back(uIdx);
|
| | }
|
| | }
|
| |
|
| | std::vector<MeshGeomFacet> aFaces;
|
| | aFaces.reserve(faces.size());
|
| | for (MeshCore::FacetIndex it : faces) {
|
| | aFaces.push_back(rMeshKernel.GetFacet(it));
|
| | }
|
| |
|
| | std::unique_ptr<MeshObject> pcKernel(new MeshObject);
|
| | pcKernel->addFacets(aFaces);
|
| | Mesh.setValuePtr(pcKernel.release());
|
| |
|
| | return App::DocumentObject::StdReturn;
|
| | }
|
| |
|