tahoma2d/toonz/sources/include/ext/plasticskeleton.h

178 lines
5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef PLASTICSKELETON_H
#define PLASTICSKELETON_H
2016-04-14 22:15:09 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
// TnzCore includes
#include "tsmartpointer.h"
#include "tpersist.h"
// TnzExt includes
#include "plastichandle.h"
// Boost includes
#include <boost/config.hpp>
// Qt includes
#include <QString>
#if (defined TNZEXT_EXPORTS && !defined INCLUDE_HPP)
#define REMOVE_INCLUDE_HPP
2016-06-15 18:43:10 +12:00
#define INCLUDE_HPP // Exporting templates needs full instantiation
2016-03-19 06:57:51 +13:00
#endif
#include "tcg_wrap.h"
#include "tcg/tcg_vertex.h"
#include "tcg/tcg_edge.h"
#include "tcg/tcg_face.h"
#include "tcg/tcg_mesh.h"
#ifdef REMOVE_INCLUDE_HPP
#undef INCLUDE_HPP
#endif
#undef DVAPI
#undef DVVAR
#ifdef TNZEXT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//==========================================================================
// Forward declarations
class PlasticSkeletonDeformation;
//==========================================================================
//************************************************************************************
// PlasticSkeletonVertex declaration
//************************************************************************************
//! PlasticSkeletonVertex is the vertex of a plastic skeleton object.
struct DVAPI PlasticSkeletonVertex final : public tcg::Vertex<TPointD>,
public TPersist {
2016-06-15 18:43:10 +12:00
PERSIST_DECLARATION(PlasticSkeletonVertex)
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
friend class PlasticSkeleton;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QString m_name; //!< Vertex name
int m_number; //!< Vertex \a number - assigned persistently upon addition
//!< in a skeleton
int m_parent; //!< Index of the parent vertex in the skeleton
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
// Tool data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double m_minAngle, m_maxAngle; //!< Minimum and maximum accepted angles when
2016-06-20 14:23:05 +12:00
//! updating the vertex
//!< position with the mouse. In degrees.
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
// Handle data
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_interpolate; //!< Whether the vertex needs to be interpolated (see
2016-06-20 14:23:05 +12:00
//! plasticdeformer.h)
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PlasticSkeletonVertex();
explicit PlasticSkeletonVertex(const TPointD &pos);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
operator PlasticHandle() const;
operator TPointD() const { return P(); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const QString &name() const { return m_name; }
int number() const { return m_number; } // Should be removed
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int parent() const { return m_parent; }
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void saveData(TOStream &os) override;
void loadData(TIStream &is) override;
2016-03-19 06:57:51 +13:00
};
//************************************************************************************
// PlasticSkeleton declaration
//************************************************************************************
class DVAPI PlasticSkeleton final
2016-06-15 18:43:10 +12:00
: public TSmartObject,
public tcg::Mesh<PlasticSkeletonVertex, tcg::Edge, tcg::FaceN<3>>,
public TPersist {
DECLARE_CLASS_CODE
PERSIST_DECLARATION(PlasticSkeleton)
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
std::unique_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef tcg::Mesh<PlasticSkeletonVertex, tcg::Edge, tcg::FaceN<3>> mesh_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PlasticSkeleton();
PlasticSkeleton(const PlasticSkeleton &other);
~PlasticSkeleton();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
PlasticSkeleton &operator=(const PlasticSkeleton &other);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int parentVertex(int v) { return vertex(v).m_parent; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void moveVertex(int v, const TPointD &pos); //!< Moves a vertex to the
2016-06-20 14:23:05 +12:00
//! specified position, informing
//! associated deformers
2016-06-15 18:43:10 +12:00
int addVertex(const PlasticSkeletonVertex &vx,
int parent); //!< Adds a vertex to the skeleton
int insertVertex(const PlasticSkeletonVertex &vx,
int e); //!< Inserts a vertex splitting an existing edge
//!< \note Inserted Vertex will connect to parent first
int insertVertex(
const PlasticSkeletonVertex &vx,
int parent, //!< Generalization of vertex addition/insertion,
const std::vector<int>
&children); //!< it is useful as inverse of vertex removal.
void removeVertex(
int v); //!< Removes a vertex, reattaching all its children to parent
void clear();
void squeeze();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool setVertexName(int v, const QString &name);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void saveData(TOStream &os) override;
void loadData(TIStream &is) override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Utility functions
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int closestVertex(const TPointD &pos, double *distance = 0) const;
int closestEdge(const TPointD &pos, double *distance = 0) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::vector<PlasticHandle> verticesToHandles() const;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
// RValues-related functions
PlasticSkeleton(PlasticSkeleton &&other);
PlasticSkeleton &operator=(PlasticSkeleton &&other);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
friend class PlasticSkeletonDeformation; // Skeleton deformations can
// register to be notified
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addListener(PlasticSkeletonDeformation *deformation);
void removeListener(PlasticSkeletonDeformation *deformation);
2016-03-19 06:57:51 +13:00
};
//===============================================================================
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
template class DVAPI TSmartPointerT<PlasticSkeleton>;
#endif
typedef TSmartPointerT<PlasticSkeleton> PlasticSkeletonP;
2016-06-15 18:43:10 +12:00
#endif // PLASTICSKELETON_H