-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene3d.hpp
128 lines (98 loc) · 2.8 KB
/
scene3d.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
119
120
121
122
123
124
125
126
127
128
/*
* scene3d.hpp
*
* Created on: Feb 23, 2018
* Author: graffy
*/
#ifndef SCENE3D_HPP_
#define SCENE3D_HPP_
#include <string>
#include <vector>
#include "types.hpp"
#include "polyline.hpp"
#include "plane.hpp"
#include "transform.hpp"
namespace scefig
{
typedef std::string LabelType;
class Scene3D
{
public:
class Shape;
class PointShape;
class PolyLineShape;
class PlaneShape;
class IShapeVisitor
{
public:
virtual void visitPoint( const PointShape & point) = 0;
virtual void visitPolyLine( const PolyLineShape & polyLine) = 0;
virtual void visitPlane( const PlaneShape & plane) = 0;
};
class TransformNode
{
public:
TransformNode() : m_transform() {}
void addShape(Shape* pShape);
void addChildTransform(TransformNode* pChild);
void getShapes(std::vector<const Shape*> & shapes) const;
protected:
Transform m_transform;
std::vector<TransformNode*> m_children;
std::vector<Shape*> m_shapes; ///< a transform node owns its shapes
};
class Shape
{
public:
Shape(const LabelType & label, TransformNode * pTransformNode=0);
const LabelType & getLabel(void) const {return m_label;}
void setTransformNode(TransformNode & transformNode) { m_pTransformNode = &transformNode; }
virtual void visit( IShapeVisitor & shapeVisitor) const = 0;
private:
LabelType m_label;
TransformNode* m_pTransformNode;
};
class PointShape : public scefig::Scene3D::Shape
{
public:
typedef scefig::Scene3D::Shape super;
PointShape(const LabelType & label, const Vector3 & values);
virtual void visit( IShapeVisitor & shapeVisitor) const;
const Vector3 & getPosition(void) const {return m_position;}
private:
Vector3 m_position;
};
class PolyLineShape : public scefig::Scene3D::Shape
{
public:
typedef scefig::Scene3D::Shape super;
PolyLineShape(const LabelType & label);
virtual void visit( IShapeVisitor & shapeVisitor) const;
const scefig::PolyLine & getPolyLine(void) const {return m_polyLine;}
void appendVertex(const Vector3 & vertex);
bool isClosed(void) const;
protected:
scefig::PolyLine m_polyLine;
};
class LineShape : public PolyLineShape
{
LineShape(const LabelType & label, const Vector3 & fromPos, const Vector3 & toPos);
};
class PlaneShape : public Shape
{
public:
PlaneShape(const LabelType & label, const Plane & plane);
virtual void visit( IShapeVisitor & shapeVisitor) const;
const Plane & getPlane(void) const;
protected:
Plane m_plane;
};
Scene3D(void) {}
TransformNode & getRootNode(void) {return m_rootNode;}
void getShapes(std::vector<const Shape*> & shapes) const { m_rootNode.getShapes(shapes); }
//Point3D * createPoint(const LabelType & label, const Vector3f & values);
protected:
TransformNode m_rootNode;
};
};
#endif /* SCENE3D_HPP_ */