50 #include "MeshObjectSelectionPlugin.hh" 61 if(_edgeList.empty() )
return;
65 emit log(
LOGERR,tr(
"selectEdges : unable to get object") );
74 emit log(
LOGERR,tr(
"selectEdges : Unsupported object Type") );
78 QString selection =
"selectEdges( ObjectId(" + QString::number(objectId) +
") , [ " + QString::number(_edgeList[0]);
80 for ( uint i = 1 ; i < _edgeList.size(); ++i) {
81 selection +=
" , " + QString::number(_edgeList[i]);
87 emit scriptInfo( selection );
101 if(_edgeList.empty())
return;
105 emit log(
LOGERR,tr(
"unselectEdges : unable to get object") );
114 emit log(
LOGERR,tr(
"unselectEdges : Unsupported object Type") );
118 QString selection =
"unselectVertices( ObjectId(" + QString::number(objectId) +
") , [ " + QString::number(_edgeList[0]);
120 for ( uint i = 1 ; i < _edgeList.size(); ++i) {
121 selection +=
" , " + QString::number(_edgeList[i]);
127 emit scriptInfo( selection );
136 emit log(
LOGERR,tr(
"selectAllVertices : unable to get object") );
145 emit log(
LOGERR,tr(
"selectAllEdges : Unsupported object Type") );
150 emit scriptInfo(
"selectAllEdges( ObjectId(" + QString::number(objectId) +
") )" );
159 emit log(
LOGERR,tr(
"clearEdgeSelection : unable to get object") );
168 emit log(
LOGERR,tr(
"clearEdgeSelection : Unsupported object Type") );
173 emit scriptInfo(
"clearEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
182 emit log(
LOGERR,tr(
"invertEdgeSelection : unable to get object") );
191 emit log(
LOGERR,tr(
"invertEdgeSelection : Unsupported object Type") );
196 emit scriptInfo(
"invertEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
205 emit log(
LOGERR,tr(
"selectBoundaryEdges : unable to get object") );
214 emit log(
LOGERR,tr(
"selectBoundaryEdges : Unsupported object Type") );
219 emit scriptInfo(
"selectBoundaryEdges( ObjectId(" + QString::number(objectId) +
") )" );
228 emit log(
LOGERR,tr(
"deleteEdgeSelection: unable to get object"));
237 emit log(
LOGERR,tr(
"deleteEdgeSelection: Unsupported object Type"));
242 emit scriptInfo(
"deleteEdgeSelection(ObjectId(" + QString::number(_objectId) +
"))");
257 emit log(
LOGERR,tr(
"getEdgeSelection : unable to get object") );
261 emit scriptInfo(
"getEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
268 emit log(
LOGERR,tr(
"getEdgeSelection : Unsupported object Type") );
284 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
292 emit log(
LOGERR,
"Could not get mesh object!");
298 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
299 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
300 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
307 emit log(
LOGERR,
"Could not get mesh object!");
313 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
314 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
315 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
326 if(_vertices.size() % 2 != 0) {
327 emit log(
LOGERR,
"Number of vertices is not even!");
335 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
343 emit log(
LOGERR,
"Could not get mesh object!");
349 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
351 if(!vh.is_valid())
continue;
353 voh_it.is_valid(); ++voh_it) {
354 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
355 edges.push_back(mesh->edge_handle(*voh_it).idx());
365 emit log(
LOGERR,
"Could not get mesh object!");
371 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
373 if(!vh.is_valid())
continue;
375 voh_it.is_valid(); ++voh_it) {
376 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
377 edges.push_back(mesh->edge_handle(*voh_it).idx());
393 emit log(
LOGERR,
"colorizeEdgeSelection : unable to get object" );
402 emit log(
LOGERR,
"colorizeEdgeSelection : Unsupported object Type" );
406 emit scriptInfo(
"colorizeEdgeSelection( ObjectId(" + QString::number(objectId) +
"), " 407 + QString::number(r) +
", " + QString::number(g) +
", " + QString::number(b) +
" )" );
414 template<
class MeshT>
415 inline bool edgeSelected(MeshT &mesh,
typename MeshT::HalfedgeHandle he) {
416 return mesh.status(mesh.edge_handle(he)).selected();
418 template<
class MeshT>
420 typedef typename MeshT::HalfedgeIter HEIt;
421 typedef typename MeshT::VOHIter VOHIter;
422 typedef typename MeshT::HalfedgeHandle HEH;
424 for (HEIt he_it = mesh.halfedges_begin(), he_end = mesh.halfedges_end();
425 he_it != he_end; ++he_it) {
426 if (edgeSelected(mesh, *he_it)) {
428 HEH current_he = *he_it;
430 for (
bool tracing =
true; tracing;) {
431 const typename MeshT::Normal cur_vec =
432 mesh.calc_edge_vector(current_he).normalized();
433 const HEH back_out_he = mesh.opposite_halfedge_handle(current_he);
435 double best_alignment = -std::numeric_limits<double>::infinity();
436 const typename MeshT::VertexHandle to_vtx =
437 mesh.to_vertex_handle(current_he);
439 for (VOHIter voh_it = mesh.voh_begin(to_vtx),
440 voh_end = mesh.voh_end(to_vtx);
441 voh_it != voh_end; ++voh_it) {
442 if (*voh_it == back_out_he)
continue;
443 if (edgeSelected(mesh, *voh_it)) {
447 const typename MeshT::Normal next_vec =
448 mesh.calc_edge_vector(*voh_it).normalized();
449 if (best_alignment < (cur_vec | next_vec)) {
450 best_alignment = (cur_vec | next_vec);
451 best_out_he = *voh_it;
454 if (tracing && best_alignment > threshold) {
455 current_he = best_out_he;
456 mesh.status(mesh.edge_handle(current_he)).set_selected(
true);
469 emit log(
LOGERR,
"traceEdgePath: unable to get object" );
478 emit log(
LOGERR,
"traceEdgePath: Unsupported object Type" );
482 emit scriptInfo(QString::fromUtf8(
"traceEdgePath(ObjectId(%1), %2)")
483 .arg(objectId).arg(threshold));
void selectEdges(int objectId, IdList _edgeList, const double _dihedral_angle_threshold=0.0)
Select given Edges.
Handle for a edge entity.
void deleteEdgeSelection(int _objectId)
Delete edges that are currently selected.
#define DATA_TRIANGLE_MESH
void selectBoundaryEdges(int objectId)
select boundary edges
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Type for a Meshobject containing a poly mesh.
int createMeshFromEdgeSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
void selectAllEdges(int objectId)
Select all Edges.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
IdList convertVertexPairsToEdges(int _id, const IdList &_vertices)
Inverse of function above.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
MeshT * mesh()
return a pointer to the mesh
bool dataType(DataType _type) const
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
void update_dihedral_angle_threshold_from_ui()
set dihedral angle threshold for edge selection
void traceEdgePath(int objectId, double threshold)
Trace Edge Path.
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a)
Colorize the edge selection.
Functions for selection on a mesh.
void unselectEdges(int objectId, IdList _edgeList)
Unselect given Edges.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_SELECTION_EDGES(UpdateTypeSet(1)<< 6)
Edge selection has changed.
SelectionInterface::PrimitiveType edgeType_
Handle to selection environment.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
bool selectEdge(int _objectId, int _idx, bool _fly_to_edge)
Select edge with id _idx and maybe fly to it.
bool selectElement(int _objectId, HandleT _handle, bool _fly_to_element)
set dihedral angle threshold for edge selection
IdList convertEdgesToVertexPairs(int _id, const IdList &_edges)
Convert edge ids to vertex pairs.
IdList getEdgeSelection(int objectId)
Return a list of all selected edges.
void invertEdgeSelection(int objectId)
Unselect all Edges.
void clearEdgeSelection(int objectId)
Invert the current edge selection.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.