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 );
94 if(_edgeList.empty())
return;
98 emit log(
LOGERR,tr(
"unselectEdges : unable to get object") );
107 emit log(
LOGERR,tr(
"unselectEdges : Unsupported object Type") );
111 QString selection =
"unselectVertices( ObjectId(" + QString::number(objectId) +
") , [ " + QString::number(_edgeList[0]);
113 for ( uint i = 1 ; i < _edgeList.size(); ++i) {
114 selection +=
" , " + QString::number(_edgeList[i]);
120 emit scriptInfo( selection );
129 emit log(
LOGERR,tr(
"selectAllVertices : unable to get object") );
138 emit log(
LOGERR,tr(
"selectAllEdges : Unsupported object Type") );
143 emit scriptInfo(
"selectAllEdges( ObjectId(" + QString::number(objectId) +
") )" );
152 emit log(
LOGERR,tr(
"clearEdgeSelection : unable to get object") );
161 emit log(
LOGERR,tr(
"clearEdgeSelection : Unsupported object Type") );
166 emit scriptInfo(
"clearEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
175 emit log(
LOGERR,tr(
"invertEdgeSelection : unable to get object") );
184 emit log(
LOGERR,tr(
"invertEdgeSelection : Unsupported object Type") );
189 emit scriptInfo(
"invertEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
198 emit log(
LOGERR,tr(
"selectBoundaryEdges : unable to get object") );
207 emit log(
LOGERR,tr(
"selectBoundaryEdges : Unsupported object Type") );
212 emit scriptInfo(
"selectBoundaryEdges( ObjectId(" + QString::number(objectId) +
") )" );
221 emit log(
LOGERR,tr(
"deleteEdgeSelection: unable to get object"));
230 emit log(
LOGERR,tr(
"deleteEdgeSelection: Unsupported object Type"));
235 emit scriptInfo(
"deleteEdgeSelection(ObjectId(" + QString::number(_objectId) +
"))");
250 emit log(
LOGERR,tr(
"getEdgeSelection : unable to get object") );
254 emit scriptInfo(
"getEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
261 emit log(
LOGERR,tr(
"getEdgeSelection : Unsupported object Type") );
277 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
285 emit log(
LOGERR,
"Could not get mesh object!");
291 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
292 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
293 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
300 emit log(
LOGERR,
"Could not get mesh object!");
306 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
307 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
308 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
319 if(_vertices.size() % 2 != 0) {
320 emit log(
LOGERR,
"Number of vertices is not even!");
328 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
336 emit log(
LOGERR,
"Could not get mesh object!");
342 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
344 if(!vh.is_valid())
continue;
346 voh_it.is_valid(); ++voh_it) {
347 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
348 edges.push_back(mesh->edge_handle(*voh_it).idx());
358 emit log(
LOGERR,
"Could not get mesh object!");
364 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
366 if(!vh.is_valid())
continue;
368 voh_it.is_valid(); ++voh_it) {
369 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
370 edges.push_back(mesh->edge_handle(*voh_it).idx());
386 emit log(
LOGERR,
"colorizeEdgeSelection : unable to get object" );
395 emit log(
LOGERR,
"colorizeEdgeSelection : Unsupported object Type" );
399 emit scriptInfo(
"colorizeEdgeSelection( ObjectId(" + QString::number(objectId) +
"), " 400 + QString::number(r) +
", " + QString::number(g) +
", " + QString::number(b) +
" )" );
407 template<
class MeshT>
408 inline bool edgeSelected(MeshT &mesh,
typename MeshT::HalfedgeHandle he) {
409 return mesh.status(mesh.edge_handle(he)).selected();
411 template<
class MeshT>
413 typedef typename MeshT::HalfedgeIter HEIt;
414 typedef typename MeshT::VOHIter VOHIter;
415 typedef typename MeshT::HalfedgeHandle HEH;
417 for (HEIt he_it = mesh.halfedges_begin(), he_end = mesh.halfedges_end();
418 he_it != he_end; ++he_it) {
419 if (edgeSelected(mesh, *he_it)) {
421 HEH current_he = *he_it;
423 for (
bool tracing =
true; tracing;) {
424 const typename MeshT::Normal cur_vec =
425 mesh.calc_edge_vector(current_he).normalized();
426 const HEH back_out_he = mesh.opposite_halfedge_handle(current_he);
428 double best_alignment = -std::numeric_limits<double>::infinity();
429 const typename MeshT::VertexHandle to_vtx =
430 mesh.to_vertex_handle(current_he);
432 for (VOHIter voh_it = mesh.voh_begin(to_vtx),
433 voh_end = mesh.voh_end(to_vtx);
434 voh_it != voh_end; ++voh_it) {
435 if (*voh_it == back_out_he)
continue;
436 if (edgeSelected(mesh, *voh_it)) {
440 const typename MeshT::Normal next_vec =
441 mesh.calc_edge_vector(*voh_it).normalized();
442 if (best_alignment < (cur_vec | next_vec)) {
443 best_alignment = (cur_vec | next_vec);
444 best_out_he = *voh_it;
447 if (tracing && best_alignment > threshold) {
448 current_he = best_out_he;
449 mesh.status(mesh.edge_handle(current_he)).set_selected(
true);
462 emit log(
LOGERR,
"traceEdgePath: unable to get object" );
471 emit log(
LOGERR,
"traceEdgePath: Unsupported object Type" );
475 emit scriptInfo(QString::fromUtf8(
"traceEdgePath(ObjectId(%1), %2)")
476 .arg(objectId).arg(threshold));
void invertEdgeSelection(int objectId)
Unselect all Edges.
int createMeshFromEdgeSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a)
Colorize the edge selection.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
IdList convertEdgesToVertexPairs(int _id, const IdList &_edges)
Convert edge ids to vertex pairs.
void clearEdgeSelection(int objectId)
Invert the current edge selection.
bool dataType(DataType _type) const
MeshT * mesh()
return a pointer to the mesh
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void selectAllEdges(int objectId)
Select all Edges.
void unselectEdges(int objectId, IdList _edgeList)
Unselect given Edges.
SelectionInterface::PrimitiveType edgeType_
Handle to selection environment.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Type for a MeshObject containing a triangle mesh.
void update_dihedral_angle_threshold_from_ui()
set dihedral angle threshold for edge selection
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Functions for selection on a mesh.
void selectBoundaryEdges(int objectId)
select boundary edges
void deleteEdgeSelection(int _objectId)
Delete edges that are currently selected.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
void selectEdges(int objectId, IdList _edgeList, const double _dihedral_angle_threshold=0.0)
Select given Edges.
#define DATA_TRIANGLE_MESH
const UpdateType UPDATE_SELECTION_EDGES(UpdateTypeSet(1)<< 6)
Edge selection has changed.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
IdList getEdgeSelection(int objectId)
Return a list of all selected edges.
Type for a Meshobject containing a poly mesh.
void traceEdgePath(int objectId, double threshold)
Trace Edge Path.
IdList convertVertexPairsToEdges(int _id, const IdList &_vertices)
Inverse of function above.