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(
auto it : _edges) {
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(
auto it : _edges) {
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) {
353 if(voh_it.to().idx() == *(it+1)) {
354 edges.push_back(voh_it.edge().idx());
364 emit log(
LOGERR,
"Could not get mesh object!");
370 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
374 if(voh_it.to().idx() == *(it+1)) {
375 edges.push_back(voh_it.edge().idx());
391 emit log(
LOGERR,
"colorizeEdgeSelection : unable to get object" );
400 emit log(
LOGERR,
"colorizeEdgeSelection : Unsupported object Type" );
404 emit scriptInfo(
"colorizeEdgeSelection( ObjectId(" + QString::number(objectId) +
"), "
405 + QString::number(r) +
", " + QString::number(g) +
", " + QString::number(b) +
" )" );
413inline bool edgeSelected(
MeshT &mesh,
typename MeshT::HalfedgeHandle he) {
414 return mesh.status(mesh.edge_handle(he)).selected();
417void traceEdgePath(
MeshT &mesh,
double threshold) {
418 typedef typename MeshT::HalfedgeHandle HEH;
420 for (
auto he_it : mesh.halfedges()) {
421 if (edgeSelected(mesh, he_it)) {
425 for (
bool tracing =
true; tracing;) {
426 const typename MeshT::Normal cur_vec = mesh.
calc_edge_vector(current_he).normalized();
427 const HEH back_out_he = current_he.
opp();
429 double best_alignment = -std::numeric_limits<double>::infinity();
433 if (voh_it == back_out_he)
continue;
434 if (edgeSelected(mesh, voh_it)) {
438 const typename MeshT::Normal next_vec = mesh.
calc_edge_vector(voh_it).normalized();
439 if (best_alignment < (cur_vec | next_vec)) {
440 best_alignment = (cur_vec | next_vec);
441 best_out_he = voh_it;
444 if (tracing && best_alignment > threshold) {
445 current_he = best_out_he;
446 mesh.status(current_he.
edge()).set_selected(
true);
459 emit log(
LOGERR,
"traceEdgePath: unable to get object" );
468 emit log(
LOGERR,
"traceEdgePath: Unsupported object Type" );
472 emit scriptInfo(QString::fromUtf8(
"traceEdgePath(ObjectId(%1), %2)")
473 .arg(objectId).arg(threshold));
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Functions for selection on a mesh.
#define DATA_TRIANGLE_MESH
bool dataType(DataType _type) const
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
IdList convertVertexPairsToEdges(int _id, const IdList &_vertices)
Inverse of function above.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
void unselectEdges(int objectId, IdList _edgeList)
Unselect given Edges.
IdList getEdgeSelection(int objectId)
Return a list of all selected edges.
bool selectElement(int _objectId, HandleT _handle, bool _fly_to_element)
set dihedral angle threshold for edge selection
void invertEdgeSelection(int objectId)
Unselect all Edges.
int createMeshFromEdgeSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
void selectEdges(int objectId, IdList _edgeList, const double _dihedral_angle_threshold=0.0)
Select given Edges.
bool selectEdge(int _objectId, int _idx, bool _fly_to_edge)
Select edge with id _idx and maybe fly to it.
void selectAllEdges(int objectId)
Select all Edges.
void clearEdgeSelection(int objectId)
Invert the current edge selection.
void traceEdgePath(int objectId, double threshold)
Trace Edge Path.
SelectionInterface::PrimitiveType edgeType_
Handle to selection environment.
void selectBoundaryEdges(int objectId)
select boundary edges
void update_dihedral_angle_threshold_from_ui()
set dihedral angle threshold for edge selection
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a)
Colorize the edge selection.
IdList convertEdgesToVertexPairs(int _id, const IdList &_edges)
Convert edge ids to vertex pairs.
void deleteEdgeSelection(int _objectId)
Delete edges that are currently selected.
MeshT * mesh()
return a pointer to the mesh
bool is_valid() const
The handle is valid iff the index is not negative.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::EdgeHandle EdgeHandle
Scalar type.
void calc_edge_vector(EdgeHandle _eh, Normal &_edge_vec) const
Type for a Meshobject containing a poly mesh.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_SELECTION_EDGES(UpdateTypeSet(64))
Edge selection has changed.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Handle for a edge entity.
SmartEdgeHandle edge() const
Returns incident edge of halfedge.
SmartHalfedgeHandle opp() const
Returns opposite halfedge handle.
SmartVertexHandle to() const
Returns vertex pointed to by halfedge.
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
PolyConnectivity::ConstVertexOHalfedgeRange outgoing_halfedges() const
Returns a range of incoming halfedges incident to the vertex (PolyConnectivity::voh_range())