MeshFlattening: add function to unwrap mesh

This commit is contained in:
looooo
2017-10-03 22:52:49 +02:00
committed by wmayer
parent eb783b9054
commit 22fbe35ceb
5 changed files with 44 additions and 25 deletions

View File

@@ -112,6 +112,13 @@ PyMOD_INIT_FUNC(MeshGui)
// instantiating the commands
CreateMeshCommands();
(void)new MeshGui::CleanupHandler;
// try to instantiate flat-mesh commands
try{
Base::Interpreter().runString("import MeshFlatteningCommand");
} catch (Base::PyException &err){
err.ReportException();
}
// register preferences pages
(void)new Gui::PrefPageProducer<MeshGui::DlgSettingsMeshView> ("Display");

View File

@@ -193,7 +193,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Mesh_Merge" << "Mesh_PolySelect" << "Mesh_PolyCut"
<< "Mesh_PolySplit" << "Mesh_PolySegm" << "Mesh_PolyTrim" << "Separator"
<< "Mesh_TrimByPlane" << "Mesh_SectionByPlane" << "Mesh_Segmentation"
<< "Mesh_VertexCurvature";
<< "Mesh_VertexCurvature" << "CreateFlatMesh";
return root;
}

View File

@@ -39,13 +39,8 @@ class MeshWorkbench (Workbench):
def Initialize(self):
import Mesh
import MeshGui
# try:
import MeshFlatteningCommand
toolbar = MeshFlatteningCommand.initialize()
self.appendToolbar(toolbar)
# except ImportError:
# import FreeCAD as app
# app.Message("MeshPart not found")
def GetClassName(self):
return "MeshGui::Workbench"

View File

@@ -174,7 +174,8 @@ void FaceUnwrapper::findFlatNodes()
std::vector<long> fixed_pins; //TODO: INPUT
LscmRelax mesh_flattener(this->xyz_nodes.transpose(), this->tris.transpose(), fixed_pins);
mesh_flattener.lscm();
mesh_flattener.relax(0.9);
for (int j=0; j<9; j++)
mesh_flattener.relax(0.9);
this->ze_nodes = mesh_flattener.flat_vertices.transpose();
}

View File

@@ -1,42 +1,58 @@
import numpy as np
import FreeCADGui as gui
import Mesh
import FreeCAD as app
import flatMesh
import Part
import FreeCAD as App
import FreeCADGui as gui
class BaseCommand(object):
def __init__(self):
pass
def IsActive(self):
if FreeCAD.ActiveDocument is None:
if App.ActiveDocument is None:
return False
else:
return True
class CreateFlatMesh(BaseCommand):
"""create an involute gear"""
"""create flat wires from a meshed face"""
def GetResources(self):
return {'Pixmap': 'not_yet.svg', 'MenuText': 'unwrap mesh', 'ToolTip': 'find a flat representation of a mesh'}
return {'MenuText': 'Unwrap Mesh', 'ToolTip': 'find a flat representation of a mesh'}
def Activated(self):
obj = Gui.Selection.getSelection()[0] # obj must be a Mesh (Mesh-Design->Meshes->Create-Mesh)
import numpy as np
import flatmesh
import Part
obj = gui.Selection.getSelection()[0] # obj must be a Mesh (Mesh-Design->Meshes->Create-Mesh)
mesh = Mesh.Mesh(obj.Mesh) # copy of the mesh to set new vertices later on
points = np.array([[i.x, i.y, i.z] for i in obj.Mesh.Points])
faces = np.array([list(i) for i in obj.Mesh.Topology[1]])
flattener = flatMesh.FaceUnwrapper(points, faces)
print(faces)
flattener = flatmesh.FaceUnwrapper(points, faces)
flattener.findFlatNodes()
boundaries = flattener.getFlatBoundaryNodes()
wires = []
for edge in boundaries:
pi = Part.makePolygon([app.Vector(*node) for node in edge])
wires.append(pi)
Part.show(Part.Wire(wires))
pi = Part.makePolygon([App.Vector(*node) for node in edge])
Part.show(Part.Wire(pi))
def IsActive(self):
assert(super(CreateFlatMesh, self).IsActive())
assert(isinstance(gui.Selection.getSelection()[0].Mesh, Mesh.Mesh))
return True
def initialize():
Gui.addCommand('CreateFlatMesh', CreateFlatMesh())
return ["CreateFlatMesh"]
class CreateFlatFace(BaseCommand):
"""create a flat face from a single face
only full faces are supported right now"""
def GetResources(self):
return {'MenuText': 'Unwrap Face', 'ToolTip': 'find a flat representation of a mesh'}
def IsActive(self):
assert(super(CreateFlatMesh, self).IsActive())
assert(isinstance(gui.Selection.getSelection()[0], Part.Face))
return True
gui.addCommand('CreateFlatMesh', CreateFlatMesh())