Commit aa239243 authored by Jan Möbius's avatar Jan Möbius

Dennis: Provide-min-max-mean-edge-length-scripting-functions

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6025 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 22dbfc68
......@@ -471,6 +471,70 @@ InfoPlugin::
//------------------------------------------------------------------------------
template< class MeshT >
void InfoPlugin::getEdgeLengths(MeshT* _mesh, double &min, double &max, double &mean)
{
typename MeshT::ConstEdgeIter e_it(_mesh->edges_sbegin()),
e_end(_mesh->edges_end());
min = FLT_MIN;
max = FLT_MAX;
mean = 0.0;
for (; e_it!=e_end; ++e_it)
{
typename MeshT::Scalar len = (_mesh->point(_mesh->to_vertex_handle(_mesh->halfedge_handle(e_it, 0))) -
_mesh->point(_mesh->to_vertex_handle(_mesh->halfedge_handle(e_it, 1)))).norm ();
if (len < min) min = len;
if (len > max) max = len;
mean += len;
}
mean /= _mesh->n_edges();
}
//------------------------------------------------------------------------------
bool InfoPlugin::getEdgeLengths(int _id, double &min, double &max, double &mean)
{
BaseObjectData* object;
if ( ! PluginFunctions::getObject(_id,object) )
return false;
if ( object == 0){
emit log(LOGERR, "Unable to get object");
return false;
}
if ( object->dataType(DATA_TRIANGLE_MESH) ) {
TriMesh* mesh = PluginFunctions::triMesh(object);
if ( mesh == 0 ) {
emit log(LOGERR,"Unable to get mesh");
return false;
}
getEdgeLengths (mesh, min, max, mean);
return true;
} else {
PolyMesh* mesh = PluginFunctions::polyMesh(object);
if ( mesh == 0 ) {
emit log(LOGERR,"Unable to get mesh");
return false;
}
getEdgeLengths (mesh, min, max, mean);
return true;
}
return false;
}
//------------------------------------------------------------------------------
Q_EXPORT_PLUGIN2( InfoPlugin , InfoPlugin );
......@@ -117,6 +117,13 @@ class InfoPlugin : public QObject, BaseInterface, MouseInterface, LoggingInterfa
/// get vertex valence
int vertexValence (int _id, int _vertexHandle);
/// get the minimal edge length
double minEdgeLength(int _id);
/// get the maximal edge length
double maxEdgeLength(int _id);
/// get the mean edge length
double meanEdgeLength(int _id);
public slots:
QString version() { return QString("1.0"); };
......@@ -131,6 +138,13 @@ class InfoPlugin : public QObject, BaseInterface, MouseInterface, LoggingInterfa
/// Get closest edge index
template< class MeshT >
int getClosestEdge(MeshT* _mesh, int _face_idx);
/// Get edge lengths
template< class MeshT >
void getEdgeLengths(MeshT* _mesh, double &min, double &max, double &mean);
/// Get edge lengths
bool getEdgeLengths(int _id, double &min, double &max, double &mean);
/// Mouse click hit point on face
ACG::Vec3d hit_point_;
......
......@@ -59,6 +59,15 @@ void InfoPlugin::setDescriptions(){
QString("ObjectId,VertexHandle").split(","),
QString("id of the object, handle of a vertex").split(","));
emit setSlotDescription("minEdgeLength(int)","Get the minimal edge length of an object",
QStringList("ObjectId"), QStringList("id of the object"));
emit setSlotDescription("maxEdgeLength(int)","Get the maximal edge length of an object",
QStringList("ObjectId"), QStringList("id of the object"));
emit setSlotDescription("meanEdgeLength(int)","Get the mean edge length of an object",
QStringList("ObjectId"), QStringList("id of the object"));
}
......@@ -769,4 +778,53 @@ int InfoPlugin::vertexValence (int _id, int _vertexHandle)
}
}
//------------------------------------------------------------------------------
/** \brief get minimal edge length for a given object
*
* @param _id object id
* @return minimal edge length or -1 if an error occured
*/
double InfoPlugin::minEdgeLength(int _id)
{
double min, max, mean;
if (getEdgeLengths (_id, min, max, mean))
return min;
else
return -1;
}
//------------------------------------------------------------------------------
/** \brief get maximal edge length for a given object
*
* @param _id object id
* @return maximal edge length or -1 if an error occured
*/
double InfoPlugin::maxEdgeLength(int _id)
{
double min, max, mean;
if (getEdgeLengths (_id, min, max, mean))
return max;
else
return -1;
}
//------------------------------------------------------------------------------
/** \brief get the mean edge length for a given object
*
* @param _id object id
* @return mean edge length or -1 if an error occured
*/
double InfoPlugin::meanEdgeLength(int _id)
{
double min, max, mean;
if (getEdgeLengths (_id, min, max, mean))
return mean;
else
return -1;
}
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