50 #include "MeshObjectSelectionPlugin.hh"
60 if(_edgeList.empty() )
return;
64 emit log(
LOGERR,tr(
"selectEdges : unable to get object") );
73 emit log(
LOGERR,tr(
"selectEdges : Unsupported object Type") );
77 QString selection =
"selectEdges( ObjectId(" + QString::number(objectId) +
") , [ " + QString::number(_edgeList[0]);
79 for ( uint i = 1 ; i < _edgeList.size(); ++i) {
80 selection +=
" , " + QString::number(_edgeList[i]);
86 emit scriptInfo( selection );
93 if(_edgeList.empty())
return;
97 emit log(
LOGERR,tr(
"unselectEdges : unable to get object") );
106 emit log(
LOGERR,tr(
"unselectEdges : Unsupported object Type") );
110 QString selection =
"unselectVertices( ObjectId(" + QString::number(objectId) +
") , [ " + QString::number(_edgeList[0]);
112 for ( uint i = 1 ; i < _edgeList.size(); ++i) {
113 selection +=
" , " + QString::number(_edgeList[i]);
119 emit scriptInfo( selection );
128 emit log(
LOGERR,tr(
"selectAllVertices : unable to get object") );
137 emit log(
LOGERR,tr(
"selectAllEdges : Unsupported object Type") );
142 emit scriptInfo(
"selectAllEdges( ObjectId(" + QString::number(objectId) +
") )" );
151 emit log(
LOGERR,tr(
"clearEdgeSelection : unable to get object") );
160 emit log(
LOGERR,tr(
"clearEdgeSelection : Unsupported object Type") );
165 emit scriptInfo(
"clearEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
174 emit log(
LOGERR,tr(
"invertEdgeSelection : unable to get object") );
183 emit log(
LOGERR,tr(
"invertEdgeSelection : Unsupported object Type") );
188 emit scriptInfo(
"invertEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
197 emit log(
LOGERR,tr(
"selectBoundaryEdges : unable to get object") );
206 emit log(
LOGERR,tr(
"selectBoundaryEdges : Unsupported object Type") );
211 emit scriptInfo(
"selectBoundaryEdges( ObjectId(" + QString::number(objectId) +
") )" );
220 emit log(
LOGERR,tr(
"deleteEdgeSelection: unable to get object"));
229 emit log(
LOGERR,tr(
"deleteEdgeSelection: Unsupported object Type"));
234 emit scriptInfo(
"deleteEdgeSelection(ObjectId(" + QString::number(_objectId) +
"))");
249 emit log(
LOGERR,tr(
"getEdgeSelection : unable to get object") );
253 emit scriptInfo(
"getEdgeSelection( ObjectId(" + QString::number(objectId) +
") )" );
260 emit log(
LOGERR,tr(
"getEdgeSelection : Unsupported object Type") );
276 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
284 emit log(
LOGERR,
"Could not get mesh object!");
288 TriMesh* mesh = obj->
mesh();
290 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
291 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
292 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
299 emit log(
LOGERR,
"Could not get mesh object!");
305 for(IdList::const_iterator it = _edges.begin(); it != _edges.end(); ++it) {
306 vertex_pairs.push_back(mesh->from_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
307 vertex_pairs.push_back(mesh->to_vertex_handle(mesh->halfedge_handle(TriMesh::EdgeHandle(*it), 0)).idx());
318 if(_vertices.size() % 2 != 0) {
319 emit log(
LOGERR,
"Number of vertices is not even!");
327 emit log(
LOGERR,tr(
"Cannot find object for id ") + QString::number(_id));
335 emit log(
LOGERR,
"Could not get mesh object!");
339 TriMesh* mesh = obj->
mesh();
341 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
342 TriMesh::VertexHandle vh = TriMesh::VertexHandle(*it);
343 if(!vh.is_valid())
continue;
344 for(TriMesh::VertexOHalfedgeIter voh_it = mesh->voh_iter(vh);
345 voh_it.is_valid(); ++voh_it) {
346 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
347 edges.push_back(mesh->edge_handle(*voh_it).idx());
357 emit log(
LOGERR,
"Could not get mesh object!");
363 for(IdList::const_iterator it = _vertices.begin(); it != _vertices.end(); it+=2) {
365 if(!vh.is_valid())
continue;
367 voh_it.is_valid(); ++voh_it) {
368 if(mesh->to_vertex_handle(*voh_it).idx() == *(it+1)) {
369 edges.push_back(mesh->edge_handle(*voh_it).idx());
385 emit log(
LOGERR,
"colorizeEdgeSelection : unable to get object" );
394 emit log(
LOGERR,
"colorizeEdgeSelection : Unsupported object Type" );
398 emit scriptInfo(
"colorizeEdgeSelection( ObjectId(" + QString::number(objectId) +
"), "
399 + QString::number(r) +
", " + QString::number(g) +
", " + QString::number(b) +
" )" );
406 template<
class MeshT>
407 inline bool edgeSelected(MeshT &mesh,
typename MeshT::HalfedgeHandle he) {
408 return mesh.status(mesh.edge_handle(he)).selected();
410 template<
class MeshT>
411 void traceEdgePath(MeshT &mesh,
double threshold) {
412 typedef typename MeshT::HalfedgeIter HEIt;
413 typedef typename MeshT::VOHIter VOHIter;
414 typedef typename MeshT::HalfedgeHandle HEH;
416 for (HEIt he_it = mesh.halfedges_begin(), he_end = mesh.halfedges_end();
417 he_it != he_end; ++he_it) {
418 if (edgeSelected(mesh, *he_it)) {
420 HEH current_he = *he_it;
422 for (
bool tracing =
true; tracing;) {
424 mesh.calc_edge_vector(current_he).normalized();
425 const HEH back_out_he = mesh.opposite_halfedge_handle(current_he);
427 double best_alignment = -std::numeric_limits<double>::infinity();
428 const typename MeshT::VertexHandle to_vtx =
429 mesh.to_vertex_handle(current_he);
431 for (VOHIter voh_it = mesh.voh_begin(to_vtx),
432 voh_end = mesh.voh_end(to_vtx);
433 voh_it != voh_end; ++voh_it) {
434 if (*voh_it == back_out_he)
continue;
435 if (edgeSelected(mesh, *voh_it)) {
440 mesh.calc_edge_vector(*voh_it).normalized();
441 if (best_alignment < (cur_vec | next_vec)) {
442 best_alignment = (cur_vec | next_vec);
443 best_out_he = *voh_it;
446 if (tracing && best_alignment > threshold) {
447 current_he = best_out_he;
448 mesh.status(mesh.edge_handle(current_he)).set_selected(
true);
461 emit log(
LOGERR,
"traceEdgePath: unable to get object" );
470 emit log(
LOGERR,
"traceEdgePath: Unsupported object Type" );
474 emit scriptInfo(QString::fromUtf8(
"traceEdgePath(ObjectId(%1), %2)")
475 .arg(objectId).arg(threshold));
void colorizeSelection(MeshT *_mesh, PrimitiveType _primitiveTypes, int _red, int _green, int _blue, int _alpha)
Colorize the selection.
MeshT * mesh()
return a pointer to the mesh
Type for a Meshobject containing a poly mesh.
void selectEdges(int objectId, IdList _vertexList)
Select given Edges.
IdList convertVertexPairsToEdges(int _id, const IdList &_vertices)
Inverse of function above.
bool deleteSelection(MeshT *_mesh, PrimitiveType _primitiveType)
Delete all selected elements of a mesh.
void selectAllEdges(int objectId)
Select all Edges.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
void createMeshFromSelection(MeshT &_mesh, MeshT &_newMesh, PrimitiveType _primitiveType)
Create a new mesh from the selection.
int createMeshFromEdgeSelection(int _objectId)
Create a mesh containing the face selection of the given mesh.
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a)
Colorize the edge selection.
bool dataType(DataType _type) const
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
const UpdateType UPDATE_SELECTION_EDGES(UpdateTypeSet(1)<< 6)
Edge selection has changed.
IdList convertEdgesToVertexPairs(int _id, const IdList &_edges)
Convert edge ids to vertex pairs.
SelectionInterface::PrimitiveType edgeType_
Handle to selection environment.
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Add normals to mesh item (vertices/faces)
void invertEdgeSelection(int objectId)
Unselect all Edges.
Functions for selection on a mesh.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
void traceEdgePath(int objectId, double threshold)
Trace Edge Path.
void deleteEdgeSelection(int _objectId)
Delete edges that are currently selected.
#define DATA_TRIANGLE_MESH
void selectBoundaryEdges(int objectId)
select boundary edges
void clearEdgeSelection(int objectId)
Invert the current edge selection.
void unselectEdges(int objectId, IdList _vertexList)
Unselect given Edges.
IdList getEdgeSelection(int objectId)
Return a list of all selected edges.