tahoma2d/toonz/sources/include/tmeshimage.h

221 lines
5.9 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 TMESHIMAGE_INCLUDED
#define TMESHIMAGE_INCLUDED
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"
#include "tgeometry.h"
#include "timage.h"
// tcg includes
#include "tcg_wrap.h"
#include "tcg/tcg_vertex.h"
#include "tcg/tcg_edge.h"
#include "tcg/tcg_face.h"
#include "tcg/tcg_mesh.h"
#include "tcg/tcg_mesh_bgl.h"
#undef DVAPI
#undef DVVAR
#ifdef TVECTORIMAGE_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
//===========================================
//***********************************************************************************
// TTextureVertex (Textured Mesh Vertex Type) declaration
//***********************************************************************************
struct RigidPoint final : public TPointD {
2016-06-15 18:43:10 +12:00
double rigidity;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
RigidPoint() : TPointD(), rigidity(1.0) {}
explicit RigidPoint(double x, double y, double rigidity_ = 1.0)
: TPointD(x, y), rigidity(rigidity_) {}
explicit RigidPoint(const TPointD &point, double rigidity_ = 1.0)
: TPointD(point), rigidity(rigidity_) {}
RigidPoint &operator=(const TPointD &p) {
TPointD::operator=(p);
return *this;
}
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
RigidPoint operator+(const RigidPoint &other) const {
return RigidPoint(x + other.x, y + other.y, rigidity + other.rigidity);
}
RigidPoint &operator+=(const RigidPoint &other) {
x += other.x, y += other.y, rigidity += other.rigidity;
return *this;
}
RigidPoint operator-(const RigidPoint &other) const {
return RigidPoint(x - other.x, y - other.y, rigidity - other.rigidity);
}
RigidPoint &operator-=(const RigidPoint &other) {
x -= other.x, y -= other.y, rigidity -= other.rigidity;
return *this;
}
friend RigidPoint operator*(double a, const RigidPoint &b) {
return RigidPoint(a * b.x, a * b.y, a * b.rigidity);
}
friend RigidPoint operator*(const RigidPoint &a, double b) {
return RigidPoint(a.x * b, a.y * b, a.rigidity * b);
}
RigidPoint &operator*=(double a) {
x *= a, y *= a, rigidity *= a;
return *this;
}
friend RigidPoint operator*(const TAffine &aff, const RigidPoint &p) {
return RigidPoint(aff.operator*(p), p.rigidity);
}
2016-03-19 06:57:51 +13:00
};
//=================================================================================
2016-06-15 18:43:10 +12:00
namespace tcg {
2016-03-19 06:57:51 +13:00
template <>
struct point_traits<RigidPoint> {
2016-06-15 18:43:10 +12:00
typedef RigidPoint point_type;
typedef double value_type;
typedef double float_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline static value_type x(const point_type &p) { return p.x; }
inline static value_type y(const point_type &p) { return p.y; }
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
} // namespace tcg
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
template class DVAPI tcg::Vertex<TPointD>;
template class DVAPI tcg::Vertex<RigidPoint>;
typedef tcg::Vertex<RigidPoint> TTextureVertex;
template class DVAPI tcg::Mesh<TTextureVertex, tcg::Edge, tcg::FaceN<3>>;
template class DVAPI tcg::TriMesh<TTextureVertex, tcg::Edge, tcg::FaceN<3>>;
2016-03-19 06:57:51 +13:00
//***********************************************************************************
// TTextureMesh (Textured Mesh Type) declaration
//***********************************************************************************
class DVAPI TTextureMesh final
2016-06-15 18:43:10 +12:00
: public tcg::TriMesh<TTextureVertex, tcg::Edge, tcg::FaceN<3>>,
public TSmartObject,
public TPersist {
PERSIST_DECLARATION(TTextureMesh)
DECLARE_CLASS_CODE
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TTextureMesh();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TTextureMesh(const TTextureMesh &);
TTextureMesh &operator=(const TTextureMesh &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int faceContaining(const TPointD &p) const;
bool faceContains(int f, const TPointD &p) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRectD getBBox() const;
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-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
template class DVAPI TSmartPointerT<TTextureMesh>;
#endif
typedef TSmartPointerT<TTextureMesh> TTextureMeshP;
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
namespace boost {
2016-03-19 06:57:51 +13:00
template <>
struct graph_traits<TTextureMesh> final
2016-06-15 18:43:10 +12:00
: public graph_traits<
tcg::Mesh<TTextureMesh::vertex_type, TTextureMesh::edge_type,
TTextureMesh::face_type>> {};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
} // namespace boost
2016-03-19 06:57:51 +13:00
//***********************************************************************************
// TMeshImage (Textured Mesh Image) declaration
//***********************************************************************************
class DVAPI TMeshImage final : public TImage {
2016-06-15 18:43:10 +12:00
class Imp;
std::shared_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef std::vector<TTextureMeshP> meshes_container;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TMeshImage();
TMeshImage(std::shared_ptr<Imp> imp);
~TMeshImage();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TMeshImage(const TMeshImage &other);
TMeshImage &operator=(TMeshImage other);
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TImage::Type getType() const override { return TImage::MESH; }
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TRectD getBBox() const override;
TImage *cloneImage() const override;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getDpi(double &dpix, double &dpiy) const;
void setDpi(double dpix, double dpiy);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const meshes_container &meshes() const;
meshes_container &meshes();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
friend void swap(TMeshImage &a, TMeshImage &b) {
std::swap(a.m_imp, b.m_imp);
}
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<TMeshImage>;
template class DVAPI TDerivedSmartPointerT<TMeshImage, TImage>;
#endif
class DVAPI TMeshImageP final
: public TDerivedSmartPointerT<TMeshImage, TImage> {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TMeshImageP() {}
TMeshImageP(TMeshImage *image) : DerivedSmartPointer(image) {}
TMeshImageP(TImageP image) : DerivedSmartPointer(image) {}
2016-04-15 17:11:23 +12:00
#if !defined(_WIN32)
2016-06-15 18:43:10 +12:00
TMeshImageP(TImage *image) : DerivedSmartPointer(TImageP(image)) {}
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
operator TImageP() { return TImageP(m_pointer); }
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // TMESHIMAGE_INCLUDED