+ Reduce redundant code in mesh classes

This commit is contained in:
wmayer
2013-07-06 15:02:52 +02:00
parent 249e806a31
commit b9fb862c66
6 changed files with 77 additions and 101 deletions

View File

@@ -1295,7 +1295,21 @@ PyObject* MeshPy::cut(PyObject *args)
polygon.push_back(Base::convertTo<Base::Vector3f>(pnt));
}
getMeshObjectPtr()->cut(polygon, MeshObject::CutType(mode));
MeshCore::FlatTriangulator tria;
tria.SetPolygon(polygon);
// this gives us the inverse matrix
Base::Matrix4D inv = tria.GetTransformToFitPlane();
// compute the matrix for the coordinate transformation
Base::Matrix4D mat = inv;
mat.inverseOrthogonal();
polygon = tria.ProjectToFitPlane();
Base::ViewProjMatrix proj(mat);
Base::Polygon2D polygon2d;
for (std::vector<Base::Vector3f>::const_iterator it = polygon.begin(); it != polygon.end(); ++it)
polygon2d.Add(Base::Vector2D(it->x, it->y));
getMeshObjectPtr()->cut(polygon2d, proj, MeshObject::CutType(mode));
Py_Return;
}
@@ -1315,7 +1329,21 @@ PyObject* MeshPy::trim(PyObject *args)
polygon.push_back(Base::convertTo<Base::Vector3f>(pnt));
}
getMeshObjectPtr()->trim(polygon, MeshObject::CutType(mode));
MeshCore::FlatTriangulator tria;
tria.SetPolygon(polygon);
// this gives us the inverse matrix
Base::Matrix4D inv = tria.GetTransformToFitPlane();
// compute the matrix for the coordinate transformation
Base::Matrix4D mat = inv;
mat.inverseOrthogonal();
polygon = tria.ProjectToFitPlane();
Base::ViewProjMatrix proj(mat);
Base::Polygon2D polygon2d;
for (std::vector<Base::Vector3f>::const_iterator it = polygon.begin(); it != polygon.end(); ++it)
polygon2d.Add(Base::Vector2D(it->x, it->y));
getMeshObjectPtr()->trim(polygon2d, proj, MeshObject::CutType(mode));
Py_Return;
}