AlignPlugin.hh 2.7 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3 4 5 6 7
#pragma once

/**
 * @author Vladimir Chalupecky (vladimir.chalupecky@gmail.com)
 */

#include <set>
Jan Möbius's avatar
Jan Möbius committed
8

Matthias Möller's avatar
Matthias Möller committed
9
#include <OpenFlipper/common/Types.hh>
Jan Möbius's avatar
Jan Möbius committed
10 11 12 13 14
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
Matthias Möller's avatar
Matthias Möller committed
15 16

#include <QObject>
Jan Möbius's avatar
Jan Möbius committed
17 18 19

#include <Eigen/Geometry>

Jan Möbius's avatar
Jan Möbius committed
20

Jan Möbius's avatar
Jan Möbius committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#include "ObjectInfoListModel.hh"

class AlignPlugin : public QObject,
	BackupInterface,
	BaseInterface,
	LoadSaveInterface,
	LoggingInterface,
	ToolboxInterface
{
	Q_OBJECT
	Q_INTERFACES(BackupInterface)
	Q_INTERFACES(BaseInterface)
	Q_INTERFACES(LoadSaveInterface)
	Q_INTERFACES(LoggingInterface)
	Q_INTERFACES(ToolboxInterface)

#if QT_VERSION >= 0x050000
	Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Align")
#endif

public:
	AlignPlugin();

signals:
	// BackupInterface
	void createBackup(int objectId, QString name, UpdateType type = UPDATE_ALL);

	// BaseInterface
	void updateView();
	void updatedObject(int objectId, UpdateType const& type);

	// LoggingInterface
	void log(Logtype type, QString message);
	void log(QString message);

	// ToolboxInterface
	void addToolbox(QString name, QWidget *widget, QIcon *icon);

private slots:
	// BaseInterface
	void initializePlugin();
	void pluginsInitialized();
	void slotObjectUpdated(int, UpdateType const&);
	void slotObjectSelectionChanged(int);

	// LoadSaveInterface
	void objectDeleted(int objectId);

private slots:
	void slotAlignMeshes();

	void slotSourceMeshChanged(int objectId);
	void slotTargetMeshChanged(int objectId);

private:
	void updateGui();

	QComboBox *sourceMeshCombo_;
	ObjectInfoListModel<Is_source_mesh> sourceMeshList_;

	QComboBox *targetMeshCombo_;
	ObjectInfoListModel<Is_target_mesh> targetMeshList_;

	QCheckBox *doScaleCheckBox_;
	QPushButton *alignMeshesButton_;

private:
	typedef std::pair<Eigen::Vector3d, Eigen::Vector3d> BBox;
	typedef std::vector<Eigen::Vector3d> Point_container;

	Point_container getPoints(BaseObjectData *object);
	void transformObject(BaseObjectData *object, Eigen::Affine3d const& t);
	void transformPoints(Point_container& points, Eigen::Affine3d const& t);
	BBox computeBoundingBox(Point_container const& points);
	Eigen::Vector3d computeCentroid(Point_container const& points);
	bool computePCA(Point_container const& points, Eigen::Vector3d& centroid, Eigen::Matrix3d& principal_directions);

	int sourceId_;
	int targetId_;

public:
	// BaseInterface
	QString name()
	{
		return QString("Mesh alignment plugin");
	}

	QString description()
	{
		return QString("Align two meshes by using PCA and scaling");
	}

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