+ Reduce redundant code in mesh classes
This commit is contained in:
parent
249e806a31
commit
b9fb862c66
|
@ -832,23 +832,9 @@ void MeshObject::crossSections(const std::vector<MeshObject::TPlane>& planes, st
|
|||
}
|
||||
}
|
||||
|
||||
void MeshObject::cut(const std::vector<Base::Vector3f>& polygon, MeshObject::CutType type)
|
||||
void MeshObject::cut(const Base::Polygon2D& polygon2d,
|
||||
const Base::ViewProjMethod& proj, MeshObject::CutType type)
|
||||
{
|
||||
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();
|
||||
|
||||
std::vector<Base::Vector3f> poly = tria.ProjectToFitPlane();
|
||||
|
||||
Base::ViewProjMatrix proj(mat);
|
||||
Base::Polygon2D polygon2d;
|
||||
for (std::vector<Base::Vector3f>::const_iterator it = poly.begin(); it != poly.end(); ++it)
|
||||
polygon2d.Add(Base::Vector2D(it->x, it->y));
|
||||
|
||||
MeshCore::MeshAlgorithm meshAlg(this->_kernel);
|
||||
std::vector<unsigned long> check;
|
||||
|
||||
|
@ -868,22 +854,9 @@ void MeshObject::cut(const std::vector<Base::Vector3f>& polygon, MeshObject::Cut
|
|||
this->deleteFacets(check);
|
||||
}
|
||||
|
||||
void MeshObject::trim(const std::vector<Base::Vector3f>& polygon, MeshObject::CutType type)
|
||||
void MeshObject::trim(const Base::Polygon2D& polygon2d,
|
||||
const Base::ViewProjMethod& proj, MeshObject::CutType type)
|
||||
{
|
||||
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();
|
||||
|
||||
std::vector<Base::Vector3f> poly = tria.ProjectToFitPlane();
|
||||
|
||||
Base::ViewProjMatrix proj(mat);
|
||||
Base::Polygon2D polygon2d;
|
||||
for (std::vector<Base::Vector3f>::const_iterator it = poly.begin(); it != poly.end(); ++it)
|
||||
polygon2d.Add(Base::Vector2D(it->x, it->y));
|
||||
MeshCore::MeshTrimming trim(this->_kernel, &proj, polygon2d);
|
||||
std::vector<unsigned long> check;
|
||||
std::vector<MeshCore::MeshGeomFacet> triangle;
|
||||
|
|
|
@ -49,6 +49,11 @@ namespace Py {
|
|||
class List;
|
||||
}
|
||||
|
||||
namespace Base {
|
||||
class Polygon2D;
|
||||
class ViewProjMethod;
|
||||
}
|
||||
|
||||
namespace MeshCore {
|
||||
class AbstractPolygonTriangulator;
|
||||
}
|
||||
|
@ -200,8 +205,8 @@ public:
|
|||
Base::Vector3d getPointNormal(unsigned long) const;
|
||||
void crossSections(const std::vector<TPlane>&, std::vector<TPolylines> §ions,
|
||||
float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const;
|
||||
void cut(const std::vector<Base::Vector3f>& polygon, CutType);
|
||||
void trim(const std::vector<Base::Vector3f>& polygon, CutType);
|
||||
void cut(const Base::Polygon2D& polygon, const Base::ViewProjMethod& proj, CutType);
|
||||
void trim(const Base::Polygon2D& polygon, const Base::ViewProjMethod& proj, CutType);
|
||||
//@}
|
||||
|
||||
/** @name Selection */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
# include <Inventor/details/SoFaceDetail.h>
|
||||
# include <Inventor/events/SoLocation2Event.h>
|
||||
# include <Inventor/events/SoMouseButtonEvent.h>
|
||||
# include <Inventor/nodes/SoCamera.h>
|
||||
#endif
|
||||
|
||||
#include "MeshSelection.h"
|
||||
|
@ -42,6 +43,7 @@
|
|||
#include <Gui/Document.h>
|
||||
#include <Gui/MouseSelection.h>
|
||||
#include <Gui/NavigationStyle.h>
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
|
@ -372,7 +374,10 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n)
|
|||
const MeshCore::MeshKernel& kernel = mesh.getKernel();
|
||||
|
||||
// simply get all triangles under the polygon
|
||||
vp->getFacetsFromPolygon(polygon, *view, true, faces);
|
||||
SoCamera* cam = view->getCamera();
|
||||
SbViewVolume vv = cam->getViewVolume();
|
||||
Gui::ViewVolumeProjection proj(vv);
|
||||
vp->getFacetsFromPolygon(polygon, proj, true, faces);
|
||||
if (self->onlyVisibleTriangles) {
|
||||
const SbVec2s& sz = view->getViewportRegion().getWindowSize();
|
||||
short width,height; sz.getValue(width,height);
|
||||
|
|
|
@ -674,10 +674,13 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
|
|||
if (!views.empty()) {
|
||||
Gui::Application::Instance->activeDocument()->openCommand("Cut");
|
||||
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
|
||||
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
|
||||
if (that->getEditingMode() > -1) {
|
||||
that->finishEditing();
|
||||
that->cutMesh(clPoly, *view, clip_inner);
|
||||
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
|
||||
if (self->getEditingMode() > -1) {
|
||||
self->finishEditing();
|
||||
SoCamera* cam = view->getCamera();
|
||||
SbViewVolume vv = cam->getViewVolume();
|
||||
Gui::ViewVolumeProjection proj(vv);
|
||||
self->cutMesh(clPoly, proj, clip_inner);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -709,10 +712,13 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n)
|
|||
if (!views.empty()) {
|
||||
Gui::Application::Instance->activeDocument()->openCommand("Cut");
|
||||
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
|
||||
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
|
||||
if (that->getEditingMode() > -1) {
|
||||
that->finishEditing();
|
||||
that->trimMesh(clPoly, *view, clip_inner);
|
||||
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
|
||||
if (self->getEditingMode() > -1) {
|
||||
self->finishEditing();
|
||||
SoCamera* cam = view->getCamera();
|
||||
SbViewVolume vv = cam->getViewVolume();
|
||||
Gui::ViewVolumeProjection proj(vv);
|
||||
self->trimMesh(clPoly, proj, clip_inner);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -889,15 +895,12 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n)
|
|||
}
|
||||
|
||||
void ViewProviderMesh::getFacetsFromPolygon(const std::vector<SbVec2f>& picked,
|
||||
Gui::View3DInventorViewer &Viewer,
|
||||
const Base::ViewProjMethod& proj,
|
||||
SbBool inner,
|
||||
std::vector<unsigned long>& indices) const
|
||||
{
|
||||
#if 1
|
||||
bool ok = true;
|
||||
SoCamera* cam = Viewer.getCamera();
|
||||
SbViewVolume vv = cam->getViewVolume();
|
||||
Gui::ViewVolumeProjection proj(vv);
|
||||
Base::Polygon2D polygon;
|
||||
for (std::vector<SbVec2f>::const_iterator it = picked.begin(); it != picked.end(); ++it)
|
||||
polygon.Add(Base::Vector2D((*it)[0],(*it)[1]));
|
||||
|
@ -1115,69 +1118,27 @@ std::vector<unsigned long> ViewProviderMesh::getVisibleFacets(const SbViewportRe
|
|||
}
|
||||
|
||||
void ViewProviderMesh::cutMesh(const std::vector<SbVec2f>& picked,
|
||||
Gui::View3DInventorViewer &Viewer, SbBool inner)
|
||||
const Base::ViewProjMethod& proj, SbBool inner)
|
||||
{
|
||||
// Get the facet indices inside the tool mesh
|
||||
std::vector<unsigned long> indices;
|
||||
getFacetsFromPolygon(picked, Viewer, inner, indices);
|
||||
getFacetsFromPolygon(picked, proj, inner, indices);
|
||||
removeFacets(indices);
|
||||
}
|
||||
|
||||
void ViewProviderMesh::trimMesh(const std::vector<SbVec2f>& polygon,
|
||||
Gui::View3DInventorViewer& viewer, SbBool inner)
|
||||
const Base::ViewProjMethod& proj, SbBool inner)
|
||||
{
|
||||
// get the drawing plane
|
||||
SbViewVolume vol = viewer.getCamera()->getViewVolume();
|
||||
SbPlane drawPlane = vol.getPlane(viewer.getCamera()->focalDistance.getValue());
|
||||
|
||||
std::vector<unsigned long> indices;
|
||||
Mesh::MeshObject* mesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.startEditing();
|
||||
MeshCore::MeshFacetGrid meshGrid(mesh->getKernel());
|
||||
MeshCore::MeshAlgorithm meshAlg(mesh->getKernel());
|
||||
|
||||
#if 0
|
||||
for (std::vector<SbVec2f>::const_iterator it = polygon.begin(); it != polygon.end(); ++it) {
|
||||
// the following element
|
||||
std::vector<SbVec2f>::const_iterator nt = it + 1;
|
||||
if (nt == polygon.end())
|
||||
break;
|
||||
else if (*it == *nt)
|
||||
continue; // two adjacent vertices are equal
|
||||
|
||||
SbVec3f p1,p2;
|
||||
SbLine l1, l2;
|
||||
vol.projectPointToLine(*it, l1);
|
||||
drawPlane.intersect(l1, p1);
|
||||
vol.projectPointToLine(*nt, l2);
|
||||
drawPlane.intersect(l2, p2);
|
||||
|
||||
SbPlane plane(l1.getPosition(), l2.getPosition(),
|
||||
l1.getPosition()+l1.getDirection());
|
||||
const SbVec3f& n = plane.getNormal();
|
||||
float d = plane.getDistanceFromOrigin();
|
||||
meshAlg.GetFacetsFromPlane(meshGrid,
|
||||
Base::Vector3f(n[0],n[1],n[2]), d,
|
||||
Base::Vector3f(p1[0],p1[1],p1[2]),
|
||||
Base::Vector3f(p2[0],p2[1],p2[2]), indices);
|
||||
}
|
||||
#endif
|
||||
|
||||
Gui::ViewVolumeProjection proj(vol);
|
||||
Base::Polygon2D polygon2d;
|
||||
for (std::vector<SbVec2f>::const_iterator it = polygon.begin(); it != polygon.end(); ++it)
|
||||
polygon2d.Add(Base::Vector2D((*it)[0],(*it)[1]));
|
||||
MeshCore::MeshTrimming trim(mesh->getKernel(), &proj, polygon2d);
|
||||
std::vector<unsigned long> check;
|
||||
std::vector<MeshCore::MeshGeomFacet> triangle;
|
||||
trim.SetInnerOrOuter(inner ? MeshCore::MeshTrimming::INNER : MeshCore::MeshTrimming::OUTER);
|
||||
trim.CheckFacets(meshGrid, check);
|
||||
trim.TrimFacets(check, triangle);
|
||||
mesh->deleteFacets(check);
|
||||
if (!triangle.empty()) {
|
||||
mesh->getKernel().AddFacets(triangle);
|
||||
}
|
||||
//Remove the facets from the mesh and open a transaction object for the undo/redo stuff
|
||||
//mesh->deleteFacets(indices);
|
||||
|
||||
Mesh::MeshObject::CutType type = inner ?
|
||||
Mesh::MeshObject::INNER :
|
||||
Mesh::MeshObject::OUTER;
|
||||
mesh->trim(polygon2d, proj, type);
|
||||
static_cast<Mesh::Feature*>(pcObject)->Mesh.finishEditing();
|
||||
pcObject->purgeTouched();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,10 @@ namespace App {
|
|||
class Color;
|
||||
}
|
||||
|
||||
namespace Base {
|
||||
class ViewProjMethod;
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
class View3DInventorViewer;
|
||||
class SoFCSelection;
|
||||
|
@ -139,7 +143,7 @@ public:
|
|||
void clearSelection();
|
||||
void deleteSelection();
|
||||
void getFacetsFromPolygon(const std::vector<SbVec2f>& picked,
|
||||
Gui::View3DInventorViewer &Viewer, SbBool inner,
|
||||
const Base::ViewProjMethod& proj, SbBool inner,
|
||||
std::vector<unsigned long>& indices) const;
|
||||
std::vector<unsigned long> getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const;
|
||||
std::vector<unsigned long> getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const;
|
||||
|
@ -156,8 +160,8 @@ protected:
|
|||
void onChanged(const App::Property* prop);
|
||||
virtual void showOpenEdges(bool);
|
||||
void setOpenEdgeColorFrom(const App::Color& col);
|
||||
virtual void cutMesh(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer, SbBool inner);
|
||||
virtual void trimMesh(const std::vector<SbVec2f>& picked, Gui::View3DInventorViewer &Viewer, SbBool inner);
|
||||
virtual void cutMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
|
||||
virtual void trimMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
|
||||
virtual void splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner);
|
||||
virtual void segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner);
|
||||
virtual void faceInfo(unsigned long facet);
|
||||
|
|
Loading…
Reference in New Issue
Block a user