serialization of GrainsAsEllipsoids
This commit is contained in:
+10
-15
@@ -17,26 +17,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/// CCPluginStub
|
||||
#include "ccStdPluginInterface.h"
|
||||
|
||||
//! Example qCC plugin
|
||||
/** Replace 'G3PointPlugin' by your own plugin class name throughout and then
|
||||
check 'G3PointPlugin.cpp' for more directions.
|
||||
// qCC_db
|
||||
#include <ccExternalFactory.h>
|
||||
|
||||
Each plugin requires an info.json file to provide information about itself -
|
||||
the name, authors, maintainers, icon, etc..
|
||||
class G3PointFactory : public ccExternalFactory
|
||||
{
|
||||
public:
|
||||
|
||||
The one method you are required to implement is 'getActions'. This should
|
||||
return all actions (QAction objects) for the plugin. CloudCompare will
|
||||
automatically add these with their icons in the plugin toolbar and to the
|
||||
plugin menu. If your plugin returns several actions, CC will create a
|
||||
dedicated toolbar and a sub-menu for your plugin. You are responsible for
|
||||
connecting these actions to methods in your plugin.
|
||||
G3PointFactory(QString factoryName) : ccExternalFactory(factoryName) { }
|
||||
|
||||
ccHObject* buildObject(const QString& metaName) override;
|
||||
};
|
||||
|
||||
Use the ccStdPluginInterface::m_app variable for access to most of the CC
|
||||
components (database, 3D views, console, etc.) - see the ccMainAppInterface
|
||||
class in ccMainAppInterface.h.
|
||||
**/
|
||||
class G3PointPlugin : public QObject, public ccStdPluginInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
#ifndef GRAINSASELLIPSOIDS_H
|
||||
#define GRAINSASELLIPSOIDS_H
|
||||
|
||||
#include "Eigen/Dense"
|
||||
// qcc_glWindow
|
||||
#include <ccGLWindowInterface.h>
|
||||
|
||||
// CCPluginAPI
|
||||
#include <ccMainAppInterface.h>
|
||||
|
||||
// qCC_db
|
||||
#include "ccAdvancedTypes.h"
|
||||
#include <ccColorTypes.h>
|
||||
#include <ccCustomObject.h>
|
||||
#include <ccHObject.h>
|
||||
#include <ccSerializableObject.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
||||
#include <ccGLWindowInterface.h>
|
||||
#include <ccHObject.h>
|
||||
#include <ccCustomObject.h>
|
||||
#include <ccMainAppInterface.h>
|
||||
#include <ccColorTypes.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
// Eigen
|
||||
#include "Eigen/Dense"
|
||||
|
||||
class ccPointCloud;
|
||||
|
||||
class GrainsAsEllipsoids : public QObject, public ccCustomHObject
|
||||
@@ -24,6 +31,8 @@ class GrainsAsEllipsoids : public QObject, public ccCustomHObject
|
||||
public:
|
||||
typedef Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic> Xb;
|
||||
|
||||
GrainsAsEllipsoids() { }
|
||||
|
||||
GrainsAsEllipsoids(ccPointCloud *cloud, ccMainAppInterface* app, const std::vector<std::vector<int> >& stacks, const RGBAColorsTableType& colors);
|
||||
|
||||
//! Set the path for shaders
|
||||
@@ -104,6 +113,10 @@ public:
|
||||
|
||||
ccBBox getOwnBB(bool withGLFeatures = false) override;
|
||||
|
||||
bool toFile(QFile& out, short dataVersion) const override;
|
||||
|
||||
bool fromFile(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
|
||||
|
||||
ccPointCloud* m_cloud;
|
||||
ccMainAppInterface* m_app;
|
||||
std::vector<std::vector<int>> m_stacks;
|
||||
|
||||
@@ -37,6 +37,20 @@
|
||||
|
||||
#include "ActionA.h"
|
||||
|
||||
ccHObject* G3PointFactory::buildObject(const QString& metaName)
|
||||
{
|
||||
if (metaName == "GrainsAsEllipsoids")
|
||||
{
|
||||
ccLog::Warning("[G3PointFactory::buildObject] build a GrainsAsEllipsoids object");
|
||||
return new GrainsAsEllipsoids();
|
||||
}
|
||||
else
|
||||
{
|
||||
ccLog::Warning("[G3PointFactory::buildObject] you are asking for the building of an unknown object: " + metaName);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Default constructor:
|
||||
// - pass the Qt resource path to the info.json file (from <yourPluginName>.qrc file)
|
||||
// - constructor should mainly be used to initialize actions and other members
|
||||
@@ -45,6 +59,9 @@ G3PointPlugin::G3PointPlugin( QObject *parent )
|
||||
, ccStdPluginInterface( ":/CC/plugin/G3PointPlugin/info.json" )
|
||||
, m_action( nullptr )
|
||||
{
|
||||
ccExternalFactory::Container::Shared container = ccExternalFactory::Container::GetUniqueInstance();
|
||||
G3PointFactory* g3PointFactory = new G3PointFactory("G3PointFactory");
|
||||
container->addFactory(g3PointFactory);
|
||||
}
|
||||
|
||||
// This method should enable or disable your plugin actions
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/// qCC_db
|
||||
#include <ccPointCloud.h>
|
||||
#include <ccGLMatrix.h>
|
||||
#include <ccSerializableObject.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
@@ -20,6 +21,9 @@ GrainsAsEllipsoids::GrainsAsEllipsoids(ccPointCloud *cloud, ccMainAppInterface *
|
||||
, m_app(app)
|
||||
, m_stacks(stacks)
|
||||
{
|
||||
this->setMetaData("class_name", "GrainsAsEllipsoids");
|
||||
this->setMetaData("plugin_name", "G3PointPlugin");
|
||||
|
||||
setShaderPath();
|
||||
setGrainColorsTable(colors);
|
||||
|
||||
@@ -989,4 +993,35 @@ ccBBox GrainsAsEllipsoids::getOwnBB(bool withGLFeatures)
|
||||
return m_ccBBox;
|
||||
}
|
||||
|
||||
bool GrainsAsEllipsoids::toFile(QFile& out, short dataVersion) const
|
||||
{
|
||||
ccLog::Print("[GrainsAsEllipsoids::toFile]");
|
||||
ccSerializationHelper::GenericArrayToFile<Eigen::Array3f, 1, float>(m_center, out);
|
||||
ccSerializationHelper::GenericArrayToFile<Eigen::Array3f, 1, float>(m_radii, out);
|
||||
ccSerializationHelper::GenericArrayToFile<Eigen::Matrix3f, 1, float>(m_rotationMatrix, out);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GrainsAsEllipsoids::fromFile(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap)
|
||||
{
|
||||
ccLog::Print("[GrainsAsEllipsoids::fromFile");
|
||||
ccSerializationHelper::GenericArrayFromFile<Eigen::Array3f, 1, float>(m_center, in, dataVersion);
|
||||
ccSerializationHelper::GenericArrayFromFile<Eigen::Array3f, 1, float>(m_radii, in, dataVersion);
|
||||
ccSerializationHelper::GenericArrayFromFile<Eigen::Matrix3f, 1, float>(m_rotationMatrix, in, dataVersion);
|
||||
|
||||
m_ccBBoxAll.setValidity(false);
|
||||
m_ccBBoxAll.clear();
|
||||
|
||||
// recompute bounding box
|
||||
for (int idx = 0; idx < m_center.size(); idx++)
|
||||
{
|
||||
float maxRadius = m_radii[idx].maxCoeff();
|
||||
CCVector3 center(m_center[idx](0), m_center[idx](1), m_center[idx](2));
|
||||
m_ccBBoxAll.add(CCVector3(center.x + maxRadius, center.y + maxRadius, center.z + maxRadius));
|
||||
m_ccBBoxAll.add(CCVector3(center.x - maxRadius, center.y - maxRadius, center.z - maxRadius));
|
||||
}
|
||||
|
||||
m_ccBBoxAll.setValidity(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user