54 #include "MeshRepairPlugin.hh"
62 emit scriptInfo(
"selectEdgesShorterThan(" + QString::number(_objectId) +
", " + QString::number(_length) +
")" );
70 emit scriptInfo(
"selectEdgesLongerThan(" + QString::number(_objectId) +
", " + QString::number(_length) +
")" );
84 TriMesh::EdgeIter e_it, e_end=triMesh->edges_end();
87 MeshSelection::clearEdgeSelection(triMesh);
90 for (e_it = triMesh->edges_begin(); e_it != e_end ; ++e_it) {
91 TriMesh::HalfedgeHandle he = triMesh->halfedge_handle( *e_it, 0 );
92 TriMesh::Point p1 = triMesh->point( triMesh->from_vertex_handle( he ) );
93 TriMesh::Point p2 = triMesh->point( triMesh->to_vertex_handle( he ) );
96 if ( (p1 - p2).norm() > _length)
97 triMesh->status(*e_it).set_selected(
true);
99 if ( (p1 - p2).norm() < _length)
100 triMesh->status(*e_it).set_selected(
true);
115 PolyMesh::EdgeIter e_it, e_end=polyMesh->edges_end();
118 MeshSelection::clearEdgeSelection(polyMesh);
121 for (e_it = polyMesh->edges_begin(); e_it != e_end ; ++e_it) {
122 PolyMesh::HalfedgeHandle he = polyMesh->halfedge_handle( *e_it, 0 );
123 PolyMesh::Point p1 = polyMesh->point( polyMesh->from_vertex_handle( he ) );
124 PolyMesh::Point p2 = polyMesh->point( polyMesh->to_vertex_handle( he ) );
127 if ( (p1 - p2).norm() > _length)
128 polyMesh->status(*e_it).set_selected(
true);
130 if ( (p1 - p2).norm() < _length)
131 polyMesh->status(*e_it).set_selected(
true);
141 emit log(
LOGERR,tr(
"Unsupported Object Type for edge selection") );
150 TriMesh* triMesh = 0;
156 TriMesh::EdgeIter e_it, e_end = triMesh->edges_end();
158 for (e_it = triMesh->edges_begin(); e_it != e_end; ++e_it) {
160 if (!triMesh->status(*e_it).deleted() && triMesh->status(*e_it).selected()) {
162 const TriMesh::VHandle v0 = triMesh->to_vertex_handle(triMesh->halfedge_handle(*e_it, 0));
163 const TriMesh::VHandle v1 = triMesh->to_vertex_handle(triMesh->halfedge_handle(*e_it, 1));
165 const bool boundary0 = triMesh->is_boundary(v0);
166 const bool boundary1 = triMesh->is_boundary(v1);
168 const bool feature0 = triMesh->status(v0).feature();
169 const bool feature1 = triMesh->status(v1).feature();
170 const bool featureE = triMesh->status(*e_it).feature();
175 if ((!boundary1 || boundary0) && (!feature1 || (feature0 && featureE)) && triMesh->is_collapse_ok(
176 triMesh->halfedge_handle(*e_it, 0)))
177 triMesh->collapse(triMesh->halfedge_handle(*e_it, 0));
178 else if ((!boundary0 || boundary1) && (!feature0 || (feature1 && featureE)) && triMesh->is_collapse_ok(
179 triMesh->halfedge_handle(*e_it, 1)))
180 triMesh->collapse(triMesh->halfedge_handle(*e_it, 1));
184 triMesh->garbage_collection();
185 triMesh->update_normals();
188 emit createBackup(_objectId,
"Removed selected Edges",
UPDATE_ALL);
189 emit scriptInfo(
"removeSelectedEdges(" + QString::number(_objectId) +
")");
194 emit log(
LOGERR, tr(
"Unsupported Object Type for edge removal"));
202 TriMesh* triMesh = 0;
209 MeshSelection::clearEdgeSelection(triMesh);
211 double maxAngle = cos(_angle * M_PI / 180.0);
213 TriMesh::EdgeIter e_it, e_end = triMesh->edges_end();
215 for (e_it = triMesh->edges_begin(); e_it != e_end; ++e_it) {
218 if (!triMesh->status(*e_it).deleted() && !triMesh->status(*e_it).feature() && triMesh->is_flip_ok(*e_it)) {
221 for (
unsigned int h = 0; h < 2; ++h) {
222 TriMesh::HalfedgeHandle hh = triMesh->halfedge_handle(*e_it, h);
223 const TriMesh::Point& a = triMesh->point(triMesh->from_vertex_handle(hh));
224 const TriMesh::Point& b = triMesh->point(triMesh->to_vertex_handle(hh));
225 hh = triMesh->next_halfedge_handle(hh);
226 const TriMesh::Point& c = triMesh->point(triMesh->to_vertex_handle(hh));
228 angle = ((a - c).normalize() | (b - c).normalize());
230 if (angle < maxAngle) {
233 triMesh->status(*e_it).set_selected(
true);
237 triMesh->flip(*e_it);
245 emit createBackup(_objectId, tr(
"Removed cap edges"),
UPDATE_ALL);
248 emit createBackup(_objectId, tr(
"Selected cap edges"),
UPDATE_ALL);
251 "detectSkinnyTriangleByAngle(" + QString::number(_objectId) +
"," + QString::number(_angle) +
","
257 emit log(
LOGERR, tr(
"Unsupported Object Type for Cap detection!"));
272 unsigned int count = 0;
274 if (trimesh_o != 0) {
277 TriMesh* mesh = trimesh_o->
mesh();
282 MeshSelection::clearEdgeSelection(mesh);
284 TriMesh::EdgeIter e_it, e_end(mesh->edges_end());
285 TriMesh::FaceHandle fh;
286 TriMesh::Scalar a, cosa = cos(_angle / 180.0 * M_PI);
288 for (e_it = mesh->edges_begin(); e_it != e_end; ++e_it) {
289 if (!mesh->is_boundary(*e_it)) {
290 a = (mesh->normal(mesh->face_handle(mesh->halfedge_handle(*e_it, 0))) | mesh->normal(
291 mesh->face_handle(mesh->halfedge_handle(*e_it, 1))));
294 mesh->status(mesh->edge_handle(mesh->halfedge_handle(*e_it, 0))). set_selected(
true);
300 }
else if (polymesh_o != 0) {
308 MeshSelection::clearEdgeSelection(mesh);
310 PolyMesh::EdgeIter e_it, e_end(mesh->edges_end());
311 PolyMesh::FaceHandle fh;
314 for (e_it = mesh->edges_begin(); e_it != e_end; ++e_it) {
315 if (!mesh->is_boundary(*e_it)) {
316 a = (mesh->normal(mesh->face_handle(mesh->halfedge_handle(*e_it, 0))) | mesh->normal(
317 mesh->face_handle(mesh->halfedge_handle(*e_it, 1))));
320 mesh->status(mesh->edge_handle(mesh->halfedge_handle(*e_it, 0))). set_selected(
true);
331 emit scriptInfo(
"detectFoldover(" + QString::number(_objectId) +
", " + QString::number(_angle) +
")");
334 "Selected " + QString::number(count) +
" fold-overs on object " + QString::number(_objectId)
335 +
" with angle greater than " + QString::number(_angle) +
".");
MeshT * mesh()
return a pointer to the mesh
Type for a Meshobject containing a poly mesh.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void removeSelectedEdges(int _objectId)
Removes all selected edges.
Kernel::Point Point
Coordinate type.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
void selectEdgesLongerThan(int _objectId, double _length)
Selects all edges of an object which are larger than the given length.
void detectSkinnyTriangleByAngle(int _objectId, double _angle, bool _remove)
Detect/Remove edges where neighboring faces form angle > _angle degrees.
Kernel::Scalar Scalar
Scalar type.
Functions for selection on a mesh.
void selectEdgesShorterThan(int _objectId, double _length)
Selects all edges of an object which are shorter than the given length.
void selectionEdgeLength(int _objectId, double _length, bool _larger)
select edges based on length
void detectFoldover(int _objectId, float _angle)
Detect folded-over configurations by the dihedral angle.