Commit 9f59b018 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Added trace edge path function.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18673 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7873a57c
......@@ -397,3 +397,79 @@ void MeshObjectSelectionPlugin::colorizeEdgeSelection(int objectId, int r, int g
emit updatedObject(object->id(), UPDATE_COLOR);
}
namespace {
template<class MeshT>
inline bool edgeSelected(MeshT &mesh, typename MeshT::HalfedgeHandle he) {
return mesh.status(mesh.edge_handle(he)).selected();
}
template<class MeshT>
void traceEdgePath(MeshT &mesh, double threshold) {
typedef typename MeshT::HalfedgeIter HEIt;
typedef typename MeshT::VOHIter VOHIter;
typedef typename MeshT::HalfedgeHandle HEH;
for (HEIt he_it = mesh.halfedges_begin(), he_end = mesh.halfedges_end();
he_it != he_end; ++he_it) {
if (edgeSelected(mesh, *he_it)) {
HEH current_he = *he_it;
for (bool tracing = true; tracing;) {
const typename MeshT::Normal cur_vec =
mesh.calc_edge_vector(current_he).normalized();
const HEH back_out_he = mesh.opposite_halfedge_handle(current_he);
HEH best_out_he;
double best_alignment = -std::numeric_limits<double>::infinity();
const typename MeshT::VertexHandle to_vtx =
mesh.to_vertex_handle(current_he);
for (VOHIter voh_it = mesh.voh_begin(to_vtx),
voh_end = mesh.voh_end(to_vtx);
voh_it != voh_end; ++voh_it) {
if (*voh_it == back_out_he) continue;
if (edgeSelected(mesh, *voh_it)) {
tracing = false;
break;
}
const typename MeshT::Normal next_vec =
mesh.calc_edge_vector(*voh_it).normalized();
if (best_alignment < (cur_vec | next_vec)) {
best_alignment = (cur_vec | next_vec);
best_out_he = *voh_it;
}
}
if (tracing && best_alignment > threshold) {
current_he = best_out_he;
mesh.status(mesh.edge_handle(current_he)).set_selected(true);
} else {
tracing = false;
}
}
}
}
}
}
void MeshObjectSelectionPlugin::traceEdgePath(int objectId, double threshold) {
BaseObjectData* object;
if ( ! PluginFunctions::getObject(objectId,object) ) {
emit log(LOGERR,"traceEdgePath: unable to get object" );
return;
}
if ( object->dataType() == DATA_TRIANGLE_MESH ) {
::traceEdgePath(*PluginFunctions::triMesh(object), threshold);
} else if ( object->dataType() == DATA_POLY_MESH ) {
::traceEdgePath(*PluginFunctions::polyMesh(object), threshold);
} else {
emit log(LOGERR,"traceEdgePath: Unsupported object Type" );
return;
}
emit scriptInfo(QString::fromUtf8("traceEdgePath(ObjectId(%1), %2)")
.arg(objectId).arg(threshold));
emit updatedObject(object->id(), UPDATE_SELECTION_EDGES);
}
......@@ -81,6 +81,8 @@
#define E_BOUNDARY "Select Boundary Edges"
#define E_COLORIZE "Colorize selected Edges"
#define E_COPYSELECTION "Create mesh from Edge Selection"
#define E_TRACE_PATH "Trace Edge Path"
// Halfedges
#define HE_SELECT_ALL "Select All Halfedges"
#define HE_CLEAR "Clear Halfedge Selection"
......@@ -201,6 +203,7 @@ void MeshObjectSelectionPlugin::pluginsInitialized() {
edgeOperations.append(E_BOUNDARY);
edgeOperations.append(E_COLORIZE);
edgeOperations.append(E_COPYSELECTION);
edgeOperations.append(E_TRACE_PATH);
// Define halfedge operations
QStringList hedgeOperations;
......@@ -546,6 +549,13 @@ void MeshObjectSelectionPlugin::slotSelectionOperation(QString _operation) {
for ( unsigned int i = 0 ; i < objects.size() ; ++i)
createMeshFromSelection(objects[i],edgeType_);
} else if (_operation == E_TRACE_PATH) {
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (o_it->visible()) {
traceEdgePath(o_it->id(), .9);
}
}
} else if(_operation == HE_SELECT_ALL) {
// Select all edges
for (PluginFunctions::ObjectIterator o_it(restriction, DataType(DATA_ALL));
......
......@@ -367,6 +367,9 @@ public slots:
/// Colorize the edge selection
void colorizeEdgeSelection(int objectId, int r, int g, int b, int a);
/// Trace Edge Path
void traceEdgePath(int objectId, double threshold);
//==========================================
// HALFEDGE OPERATIONS
//==========================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment