#ifndef _gpuCacheGeometry_h_
#define _gpuCacheGeometry_h_
#include "gpuCacheSample.h"
#include "gpuCacheTimeInterval.h"
#include <maya/MTime.h>
#include <maya/MString.h>
#include <map>
#include <memory>
namespace GPUCache {
class SubNode;
class SubNodeVisitor;
class SubNodeData
{
public:
typedef std::shared_ptr<const SubNodeData> Ptr;
virtual void accept(SubNodeVisitor& visitor,
const SubNode& subNode) const = 0;
const TimeInterval& animTimeRange() const
{ return fAnimTimeRange; }
void setAnimTimeRange(const TimeInterval& animTimeRange)
{ fAnimTimeRange = animTimeRange; }
protected:
SubNodeData() : fAnimTimeRange(TimeInterval::kInvalid) {}
virtual ~SubNodeData() = 0;
TimeInterval fAnimTimeRange;
};
class ShapeData: public SubNodeData
{
public:
typedef std::shared_ptr<const ShapeData> Ptr;
typedef std::shared_ptr<ShapeData> MPtr;
typedef std::map<double, std::shared_ptr<const ShapeSample> > SampleMap;
static MPtr create() {
return std::make_shared<ShapeData>();
}
~ShapeData() override;
const std::shared_ptr<const ShapeSample>&
getSample(double seconds) const;
const std::shared_ptr<const ShapeSample>&
getSample(
const MTime& time)
const
{
}
const SampleMap& getSamples() const { return fSamples; }
void addSample(const std::shared_ptr<const ShapeSample>& sample);
void accept(SubNodeVisitor& visitor,
const SubNode& subNode) const override;
void setMaterial(
const MString& material);
void setMaterials(const std::vector<MString>& materials);
const std::vector<MString>& getMaterials() const;
protected:
template<class T> friend void boost::checked_delete(T * x);
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND;
ShapeData();
ShapeData(const ShapeData&);
const ShapeData& operator=(const ShapeData&);
SampleMap fSamples;
std::vector<MString> fMaterials;
};
class XformData: public SubNodeData
{
public:
typedef std::shared_ptr<const XformData> Ptr;
typedef std::shared_ptr<XformData> MPtr;
typedef std::map<double, std::shared_ptr<const XformSample> > SampleMap;
static MPtr create() {
return std::make_shared<XformData>();
}
~XformData() override;
const std::shared_ptr<const XformSample>&
getSample(double seconds) const;
const std::shared_ptr<const XformSample>&
getSample(
const MTime& time)
const
{
}
const SampleMap& getSamples() const { return fSamples; }
void addSample(const std::shared_ptr<const XformSample>& sample)
{
fSamples[sample->timeInSeconds()] = sample;
}
void accept(SubNodeVisitor& visitor,
const SubNode& subNode) const override;
private:
template<class T> friend void boost::checked_delete(T * x);
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND;
XformData() {}
XformData(const XformData&);
const XformData& operator=(const XformData&);
SampleMap fSamples;
};
class SubNodeVisitor
{
public:
virtual void visit(const XformData& xform,
const SubNode& subNode) = 0;
virtual void visit(const ShapeData& shape,
const SubNode& subNode) = 0;
virtual ~SubNodeVisitor();
};
class SubNode
{
public:
typedef std::shared_ptr<SubNode> MPtr;
typedef std::shared_ptr<const SubNode> Ptr;
typedef std::weak_ptr<const SubNode> WPtr;
enum TransparentType {
kOpaque,
kTransparent,
kOpaqueAndTransparent,
kUnknown
};
static MPtr create(
const MString& name,
const SubNodeData::Ptr& nodeData) {
return std::make_shared<SubNode>(name, nodeData);
}
static void connect(const MPtr& parent, const MPtr& child)
{
parent->fChildren.push_back(child);
child->fParents.push_back(parent);
}
static void swapNodeData(const MPtr& left, const MPtr& right)
{
assert(left);
assert(right);
left->fNodeData.swap(right->fNodeData);
std::swap(left->fTransparentType, right->fTransparentType);
}
~SubNode();
const MString& getName()
const {
return fName; }
const SubNodeData::Ptr& getData() const { return fNodeData; }
const std::vector<WPtr>& getParents() const { return fParents; }
const std::vector<Ptr>& getChildren() const { return fChildren;}
void setName(
const MString& name) { fName = name; }
TransparentType transparentType() const { return fTransparentType; }
void setTransparentType(const TransparentType transparentType)
{ fTransparentType = transparentType; }
void accept(SubNodeVisitor& visitor) const
{ fNodeData->accept(visitor, *this); }
private:
template<class T> friend void boost::checked_delete(T * x);
GPUCACHE_DECLARE_MAKE_SHARED_FRIEND;
SubNode(
const SubNodeData::Ptr& nodeData);
SubNodeData::Ptr fNodeData;
std::vector<WPtr> fParents;
std::vector<Ptr> fChildren;
TransparentType fTransparentType;
};
}
#endif