Skip to content

Commit

Permalink
Updates and bugfixes for the MeshGrading Plugin
Browse files Browse the repository at this point in the history
1: Fixed issues with latest OpenFlipper version.

2: Added Python API support for scripting.

3: Restricted to triangular meshes. Quad-meshes were allowed but could not be handeled.

4: Added option to ony grade until the center of the head for simulating both ears at the same time. Credit: Oliver Weissbarth (https://github.com/oweissbarth/OpenFlipper-MeshGrading)

original commit fbrinkmann 2020-08-27
  • Loading branch information
f-brinkmann committed Sep 23, 2020
1 parent d5d24b1 commit 565e532
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 197 deletions.
4 changes: 3 additions & 1 deletion PreProcessing/MeshGrading(OpenFlipper)/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include (plugin)
openflipper_plugin (INSTALLDATA Icons)
openflipper_plugin (PYTHONINTERFACE
INSTALLDATA Icons
TYPES TRIANGLEMESH)
17 changes: 11 additions & 6 deletions PreProcessing/MeshGrading(OpenFlipper)/MeshGradingPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ thread_(0)

/// init the Toolbox
void MeshGradingPlugin::initializePlugin() {
tool_ = new MeshGradingToolBox();
if ( OpenFlipper::Options::gui()) {
tool_ = new MeshGradingToolBox();

QSize size(300, 300);
tool_->resize(size);
QSize size(300, 300);
tool_->resize(size);

connect(tool_->meshGradingButton, SIGNAL(clicked()), this, SLOT(slotMeshGradingButtonClicked()) );
connect(tool_->meshGradingButton, SIGNAL(clicked()), this, SLOT(slotMeshGradingButtonClicked()) );

toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"MeshGrading.png");
emit addToolbox( tr("Mesh Grading") , tool_, toolIcon_ );
toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"MeshGrading.png");
emit addToolbox( tr("Mesh Grading") , tool_, toolIcon_ );
}
}

void MeshGradingPlugin::slotMeshGradingButtonClicked() {
Expand All @@ -112,6 +114,9 @@ void MeshGradingPlugin::slotMeshGradingButtonClicked() {
if (tool_->ear_right->isChecked()){
ear_ = 2;
}
if (tool_->ear_both->isChecked()){
ear_ = 3;
}

if (tool_->POWalpha->isChecked()){
gradingFunction_ = 1;
Expand Down
7 changes: 5 additions & 2 deletions PreProcessing/MeshGrading(OpenFlipper)/MeshGradingPlugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/PythonInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Expand All @@ -97,7 +98,7 @@


class MeshGradingPlugin : public QObject, BaseInterface, BackupInterface , ToolboxInterface, LoggingInterface,
RPCInterface, ProcessInterface, ScriptInterface
RPCInterface, ProcessInterface, ScriptInterface, PythonInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Expand All @@ -107,6 +108,7 @@ Q_INTERFACES(RPCInterface)
Q_INTERFACES(ProcessInterface)
Q_INTERFACES(ScriptInterface)
Q_INTERFACES(BackupInterface)
Q_INTERFACES(PythonInterface)

#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MeshGrading")
Expand Down Expand Up @@ -156,7 +158,7 @@ public :
MeshGradingPlugin();
~MeshGradingPlugin() {};

QString name() { return (QString("Mesh Grading")); };
QString name() { return (QString("MeshGrading")); }; // This has to be one word as it is used as a variable name by the python api
QString description( ) { return (QString("Pre-processing for Mesh2HRTF (a-priori mesh-grading).")); };

//GUI
Expand Down Expand Up @@ -190,6 +192,7 @@ public slots:

public slots:
QString version() { return QString("1.0"); };
void noguiSupported() {}
};

#endif //MESHGRADINGPLUGIN_HH
99 changes: 75 additions & 24 deletions PreProcessing/MeshGrading(OpenFlipper)/MeshGradingT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,42 +88,49 @@ template< class MeshT >
void MeshGrading< MeshT >::grading( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const unsigned int _ear, const unsigned int _gradingFunction, const double _gradingOrder )
{

typename MeshT::Point earVertex;
earVertex[0]=100.0;
earVertex[1]=0.0;
earVertex[2]=100.0;
typename MeshT::Point earVertexLeft;
earVertexLeft[0]=100.0;
earVertexLeft[1]=0.0;
earVertexLeft[2]=100.0;
typename MeshT::Point earVertexRight;
earVertexRight[0]=100.0;
earVertexRight[1]=0.0;
earVertexRight[2]=100.0;
typename MeshT::VertexIter v_it;
typename MeshT::VertexIter v_end = _mesh.vertices_end();

if (_ear==1)
if (_ear==1 || _ear==3)
{
for (v_it = _mesh.vertices_begin(); v_it != v_end; ++v_it)
{
typename MeshT::Point currentVertex = _mesh.point(*v_it);
if (currentVertex[1]>0)
{
if (sqrt(currentVertex[0]*currentVertex[0]+currentVertex[2]*currentVertex[2])<=sqrt(earVertex[0]*earVertex[0]+earVertex[2]*earVertex[2]))
if (sqrt(currentVertex[0]*currentVertex[0]+currentVertex[2]*currentVertex[2])<=sqrt(earVertexLeft[0]*earVertexLeft[0]+earVertexLeft[2]*earVertexLeft[2]))
{
earVertex=currentVertex;
earVertexLeft=currentVertex;
}
}
}
}
if (_ear==2)
if (_ear==2 || _ear==3)
{
for (v_it = _mesh.vertices_begin(); v_it != v_end; ++v_it)
{
typename MeshT::Point currentVertex = _mesh.point(*v_it);
if (currentVertex[1]<0)
{
if (sqrt(currentVertex[0]*currentVertex[0]+currentVertex[2]*currentVertex[2])<=sqrt(earVertex[0]*earVertex[0]+earVertex[2]*earVertex[2]))
if (sqrt(currentVertex[0]*currentVertex[0]+currentVertex[2]*currentVertex[2])<=sqrt(earVertexRight[0]*earVertexRight[0]+earVertexRight[2]*earVertexRight[2]))
{
earVertex=currentVertex;
earVertexRight=currentVertex;
}
}
}
}
std::cout << earVertex[0] << ' ' << earVertex[1] << ' ' << earVertex[2] << ' ' << std::endl;

std::cout << earVertexLeft[0] << ' ' << earVertexLeft[1] << ' ' << earVertexLeft[2] << ' ' << std::endl;
std::cout << earVertexRight[0] << ' ' << earVertexRight[1] << ' ' << earVertexRight[2] << ' ' << std::endl;


MeshT meshCopy = _mesh;
OpenMeshTriangleBSPT< MeshT >* triangleBSP = getTriangleBSP(meshCopy);
Expand All @@ -134,11 +141,11 @@ void MeshGrading< MeshT >::grading( MeshT& _mesh, const double _minEdgeLengthGlo

std::cout << "Iteration = " << i << std::endl;

splitLongEdges(_mesh, _minEdgeLengthGlobal, _maxEdgeLengthGlobal, earVertex, _gradingFunction, _gradingOrder);
splitLongEdges(_mesh, _minEdgeLengthGlobal, _maxEdgeLengthGlobal, earVertexLeft, earVertexRight, _ear, _gradingFunction, _gradingOrder);
if (prgEmt_)
prgEmt_->sendProgressSignal(i + 0.2);

collapseShortEdges(_mesh, _minEdgeLengthGlobal, _maxEdgeLengthGlobal, earVertex, _gradingFunction, _gradingOrder);
collapseShortEdges(_mesh, _minEdgeLengthGlobal, _maxEdgeLengthGlobal, earVertexLeft, earVertexRight, _ear, _gradingFunction, _gradingOrder);
if (prgEmt_)
prgEmt_->sendProgressSignal(i + 0.4);

Expand Down Expand Up @@ -178,17 +185,51 @@ OpenMeshTriangleBSPT< MeshT >* MeshGrading< MeshT >::getTriangleBSP(MeshT& _mesh
// return pointer to triangle bsp
return triangle_bsp;
}
template< class MeshT>
double MeshGrading<MeshT>::compute_distance(const typename MeshT::Point vec_midpoint, const unsigned int _ear,const typename MeshT::Point earVertex, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight){
double distance;

if(_ear == 1 || _ear == 2){
typename MeshT::Point vec_distance = vec_midpoint - earVertex;
distance = sqrt(vec_distance.sqrnorm());
}else{
typename MeshT::Point vec_distance_left = vec_midpoint - earVertexLeft;
typename MeshT::Point vec_distance_right = vec_midpoint - earVertexRight;
const double distance_left = sqrt(vec_distance_left.sqrnorm());
const double distance_right = sqrt(vec_distance_right.sqrnorm());
if(distance_left < distance_right){
distance = distance_left;
}else{
distance = distance_right;
}
}
return distance;
}

/// performs edge splits until all edges are shorter than the threshold
template< class MeshT >
void MeshGrading< MeshT >::splitLongEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertex, const unsigned int _gradingFunction, const double _gradingOrder )
void MeshGrading< MeshT >::splitLongEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight, const unsigned int _ear, const unsigned int _gradingFunction, const double _gradingOrder )
{

double maxEdgeLength = 0;
double distance = 0;
double grading = 0;

const double headwidth = sqrt(earVertex.sqrnorm())*2;
typename MeshT::Point earVertex;
double headwidth;

if(_ear == 1){
headwidth = sqrt(earVertexLeft.sqrnorm())*2;
earVertex = earVertexLeft;
}
if(_ear == 2){
headwidth = sqrt(earVertexRight.sqrnorm())*2;
earVertex = earVertexRight;
}
if(_ear == 3){
headwidth = sqrt((earVertexLeft - earVertexRight).sqrnorm());
}



typename MeshT::EdgeIter e_it;
typename MeshT::EdgeIter e_end = _mesh.edges_end();
Expand All @@ -203,11 +244,10 @@ void MeshGrading< MeshT >::splitLongEdges( MeshT& _mesh, const double _minEdgeLe
const typename MeshT::Point vec_edge = _mesh.point(v1) - _mesh.point(v0);
const typename MeshT::Point vec_midpoint = (_mesh.point(v1) + _mesh.point(v0))/2;

typename MeshT::Point vec_distance = vec_midpoint - earVertex;
distance = sqrt(vec_distance.sqrnorm());
const double distance = compute_distance(vec_midpoint, _ear, earVertex, earVertexLeft, earVertexRight);

grading=distance/headwidth;

switch(_gradingFunction)
{
case 1:
Expand Down Expand Up @@ -250,15 +290,27 @@ void MeshGrading< MeshT >::splitLongEdges( MeshT& _mesh, const double _minEdgeLe

/// collapse edges shorter than minEdgeLength if collapsing doesn't result in new edge longer than maxEdgeLength
template< class MeshT >
void MeshGrading< MeshT >::collapseShortEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertex, const unsigned int _gradingFunction, const double _gradingOrder )
void MeshGrading< MeshT >::collapseShortEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight, const unsigned int _ear, const unsigned int _gradingFunction, const double _gradingOrder )
{

double minEdgeLength = 0;
double maxEdgeLength = 0;
double distance = 0;
double grading = 0;

const double headwidth = sqrt(earVertex.sqrnorm())*2;
typename MeshT::Point earVertex;
double headwidth;

if(_ear == 1){
headwidth = sqrt(earVertexLeft.sqrnorm())*2;
earVertex = earVertexLeft;
}
if(_ear == 2){
headwidth = sqrt(earVertexRight.sqrnorm())*2;
earVertex = earVertexRight;
}
if(_ear == 3){
headwidth = sqrt((earVertexLeft - earVertexRight).sqrnorm());
}

//add checked property
OpenMesh::EPropHandleT< bool > checked;
Expand Down Expand Up @@ -293,8 +345,7 @@ void MeshGrading< MeshT >::collapseShortEdges( MeshT& _mesh, const double _minEd
const typename MeshT::Point vec_edge = _mesh.point(v1) - _mesh.point(v0);
const typename MeshT::Point vec_midpoint = (_mesh.point(v1) + _mesh.point(v0))/2;

typename MeshT::Point vec_distance = vec_midpoint - earVertex;
double distance = sqrt(vec_distance.sqrnorm());
const double distance = compute_distance(vec_midpoint, _ear, earVertex, earVertexLeft, earVertexRight);

const double edgeLength = vec_edge.sqrnorm();

Expand Down
6 changes: 4 additions & 2 deletions PreProcessing/MeshGrading(OpenFlipper)/MeshGradingT.hh
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ public:

private:

void splitLongEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertex, const unsigned int _gradingFunction, const double _gradingOrder );
void splitLongEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight, const unsigned int _ear, const unsigned int _gradingFunction, const double _gradingOrder);

void collapseShortEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertex, const unsigned int _gradingFunction, const double _gradingOrder );
void collapseShortEdges( MeshT& _mesh, const double _minEdgeLengthGlobal, const double _maxEdgeLengthGlobal, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight, const unsigned int _ear, const unsigned int _gradingFunction, const double _gradingOrder);

void equalizeValences( MeshT& _mesh );

double compute_distance(const typename MeshT::Point vec_midpoint, const unsigned int _ear,const typename MeshT::Point earVertex, const typename MeshT::Point earVertexLeft, const typename MeshT::Point earVertexRight);

inline
int targetValence( MeshT& _mesh, const typename MeshT::VertexHandle& _vh );

Expand Down
4 changes: 3 additions & 1 deletion PreProcessing/MeshGrading(OpenFlipper)/MeshGradingToolbox.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
* *
\*===========================================================================*/

#include "ui_toolbox.hh"
#pragma once

#include "ui_toolbox.h"

#if QT_VERSION >= 0x050000
#include <QtWidgets>
Expand Down
53 changes: 53 additions & 0 deletions PreProcessing/MeshGrading(OpenFlipper)/ProgressEmitter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/

#include "ProgressEmitter.hh"

ProgressEmitter::ProgressEmitter(QString _jobId) : jobId_(_jobId) {};

void ProgressEmitter::sendProgressSignal(double _percent) {
emit signalJobState(jobId_, (int)_percent);
}

void ProgressEmitter::sendChangeDescriptionSignal(QString _description) {
emit changeDescription(jobId_, _description);
}

16 changes: 4 additions & 12 deletions PreProcessing/MeshGrading(OpenFlipper)/ProgressEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@
* *
\*===========================================================================*/

#ifndef PROGRESSEMITTER_HH
#define PROGRESSEMITTER_HH
#pragma once

#include <QObject>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

class ProgressEmitter : public QObject
{
Expand All @@ -86,19 +84,13 @@ class ProgressEmitter : public QObject
void changeDescription(QString _jobId, QString _description);

public:
ProgressEmitter(QString _jobId) : jobId_(_jobId) {}
explicit ProgressEmitter(QString _jobId);

void sendProgressSignal(double _percent) {
emit signalJobState(jobId_, (int)_percent);
}
void sendProgressSignal(double _percent);

void sendChangeDescriptionSignal(QString _description) {
emit changeDescription(jobId_, _description);
}
void sendChangeDescriptionSignal(QString _description);

private:
QString jobId_;
};


#endif //PROGRESSEMITTER_HH
Loading

0 comments on commit 565e532

Please sign in to comment.