Commit 5b47a3f9 authored by Jan Möbius's avatar Jan Möbius

Python interface for decimater

parent 2c1a7de2
include (plugin)
openflipper_plugin (INSTALLDATA Icons
openflipper_plugin (PYTHONINTERFACE
INSTALLDATA Icons
TYPES TRIANGLEMESH)
......@@ -514,6 +514,46 @@ void DecimaterPlugin::slot_decimate_finished(QString _jobId)
}
//-----------------------------------------------------------------------------
void DecimaterPlugin::decimate(int _objID, QString _constraints) {
QStringList constraintList = _constraints.split(";");
QVariantMap map;
for ( auto i = 0 ; i < constraintList.size() ; ++i) {
const auto& currentConstraint = constraintList[i];
int pos = currentConstraint.indexOf("=" );
if ( pos == -1 ) {
emit log(LOGERR,"Wrong parameter format for decimater: " + currentConstraint);
return;
}
QString constraintName = currentConstraint.left(pos);
QString constraintValue = currentConstraint.right(currentConstraint.size() - pos -1 );
bool ok = false;
double value = constraintValue.toDouble(&ok);
if ( !ok) {
emit log(LOGERR,"Wrong parameter format for decimater. Conversion failed!");
emit log(LOGERR,"Got Name : " + constraintName );
emit log(LOGERR,"Got Value: " + constraintValue);
return;
}
// decimater.decimate(5,"random_samples=2;decimater_type=2;distance=0.0001")
map[constraintName] = value;
}
decimate(_objID,map);
}
//-----------------------------------------------------------------------------
void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
......
......@@ -39,10 +39,7 @@
* *
\*===========================================================================*/
#ifndef DECIMATERPLUGIN_HH
#define DECIMATERPLUGIN_HH
#pragma once
//== INCLUDES =================================================================
......@@ -54,6 +51,7 @@
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
#include <OpenFlipper/BasePlugin/PythonInterface.hh>
#include <OpenFlipper/common/Types.hh>
......@@ -91,7 +89,7 @@
/** Plugin for Decimater Support
*/
class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, ScriptInterface, BackupInterface, RPCInterface, LoadSaveInterface, ProcessInterface
class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, ScriptInterface, BackupInterface, RPCInterface, LoadSaveInterface, ProcessInterface, PythonInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
......@@ -102,6 +100,8 @@ class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, Logging
Q_INTERFACES(RPCInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ProcessInterface)
Q_INTERFACES(PythonInterface)
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Decimater")
signals:
......@@ -262,10 +262,16 @@ public slots:
/** @} */
/** \brief decimate an object
*
* @param _objID Id of the object that should be decimated
* @param _constraints List of constraints for the decimater as a string separated by ;
*
*/
void decimate(int _objID, QString _constraints);
public slots:
QString version() { return QString("1.0"); };
};
#endif //DECIMATERPLUGIN_HH
/*===========================================================================*\
* *
* 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 <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
#include <DecimaterPlugin.hh>
#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
#include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
namespace py = pybind11;
PYBIND11_EMBEDDED_MODULE(Decimater, m) {
QObject* pluginPointer = getPluginPointer("Decimater");
if (!pluginPointer) {
std::cerr << "Error Getting plugin pointer for Plugin-Decimater" << std::endl;
return;
}
DecimaterPlugin* plugin = qobject_cast<DecimaterPlugin*>(pluginPointer);
if (!plugin) {
std::cerr << "Error converting plugin pointer for Plugin-Decimater" << std::endl;
return;
}
// Export our core. Make sure that the c++ worlds core object is not deleted if
// the python side gets deleted!!
py::class_< DecimaterPlugin,std::unique_ptr<DecimaterPlugin, py::nodelete> > decimater(m, "Decimater");
// On the c++ side we will just return the existing core instance
// and prevent the system to recreate a new core as we need
// to work on the existing one.
decimater.def(py::init([plugin]() { return plugin; }));
decimater.def("decimate", static_cast<void (DecimaterPlugin::*) (int,QString)>(&DecimaterPlugin::decimate),
QCoreApplication::translate("PythonDocDecimater","Decimate a mesh. You can use the following parameters:\n\n\
decimater_type [0 (Incremental), 1 (MC), 2 (Mixed)] \n\
random_samples [For MC/Mixed] \n\
incremental_percentage [For Mixed] \n\
decimation_order [0 (by distance), 1 (by normal deviation), 2 (by edge length)] \n\
distance \n\
edge_length \n\
normal_deviation \n\
roundness \n\
aspect_ratio,independent_sets \n\
vertices \n\
triangles \n\
\n\
\n\
Example call: \n\
decimater.decimate(5,\"random_samples=2;decimater_type=2;distance=0.0000001;decimation_order=0\") " ).toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocDecimater","ID of the object").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocDecimater","List of Decimation parameters as a list separated by ';'").toLatin1().data()) );
}
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