source: NonGTP/FCollada/FCDocument/FCDGeometrySpline.h @ 964

Revision 964, 5.2 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5/**
6        @file FCDGeometrySpline.h
7        This file contains the FCDGeometrySpline class.
8        The FCDGeometrySpline class hold the information for one COLLADA geometric spline.
9*/
10#ifndef _FCD_GEOMETRY_SPLINE_H_
11#define _FCD_GEOMETRY_SPLINE_H_
12
13#include "FCDocument/FCDObject.h"
14
15class FCDocument;
16class FCDGeometry;
17
18/** A dynamically-sized array of geometric spline control points. Each control point is simply one 3D position. @ingroup FCDGeometry */
19typedef vector<FMVector3> FCDCVs;
20/** A dynamically-sized array of weight values. Each weigth value represents a knot of a control point. @ingroup FCDGeometry */
21typedef vector<double> FCDKnots;
22
23/**
24        A COLLADA geometric spline.
25
26        A COLLADA spline contains a list of control points (CVs) that define an ordered list of 3D coordinates
27        that influence the spline. The spline also contains a matching list of knots: there should be as many control
28        points as there are knots.
29       
30        A COLLADA spline may be closed or open. If the spline is closed, then the first control point should be
31        re-used when evaluating the last control point: the result should be a continuous curve, while an open
32        spline will result in a discontinuity at each end.
33
34        @todo: Insert the mathematical formula to calculate the spline position.
35
36        @ingroup FCDGeometry
37*/
38class FCOLLADA_EXPORT FCDGeometrySpline : public FCDObject
39{
40private:
41        DeclareObjectType;
42        FCDGeometry* parent;
43        FCDCVs cvs;
44        FCDKnots knots;
45        bool isClosed;
46
47public:
48        /** Constructor: do not use directly. Use the FCDGeometry::CreateMesh function instead.
49                @param document The COLLADA document that owns the new spline.
50                @param parent The geometry entity that contains the new spline. */
51        FCDGeometrySpline(FCDocument* document, FCDGeometry* parent);
52
53        /** Destructor: do not use directly. All geometric splines are released with the geometry that they belong to. */
54        virtual ~FCDGeometrySpline();
55
56        /** Retrieve the parent of this geometric spline: the geometry entity.
57                @return The geometry entity that this spline belongs to. */
58        FCDGeometry* GetParent() { return parent; }
59        const FCDGeometry* GetParent() const { return parent; } /**< See above. */
60
61        /** Retrieves the list of control points for the spline.
62                @return The list of control points. */
63        inline FCDCVs& GetCVs() { return cvs; }
64        inline const FCDCVs& GetCVs() const { return cvs; } /**< See above. */
65
66        /** Retrieves the number of control points for the spline.
67                @return The control point count. */
68        inline size_t GetCVCount() const { return cvs.size(); }
69
70        /** Retrieves a specific control point of the spline.
71                @param index The index of the control point.
72                        The index should always be less than the number of control point.
73                @return The control point. */
74        inline FMVector3* GetCV(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); }
75        inline const FMVector3* GetCV(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } /**< See above. */
76
77        /** Retrieves the list of knots for the spline.
78                @return The list of knots. */
79        inline FCDKnots& GetKnots() { return knots; }
80        inline const FCDKnots& GetKnots() const { return knots; } /**< See above. */
81
82        /** Retrieves the number of knots for the spline.
83                @return The knot count. */
84        inline size_t GetKnotCount() const { return knots.size(); }
85
86        /** Retrieves a specific knot of the spline.
87                @param index The index of the knot. The index should always be less than the number of knots.
88                @return The knot value. */
89        inline double GetKnot(size_t index) const { FUAssert(index < GetKnotCount(), return 0.0); return knots.at(index); }
90
91        /** Retrieves whether this spline is closed.
92                @return Whether the spline is closed. */
93        inline bool IsClosed() const { return isClosed; }
94
95        /** Retrieves whether this spline is open.
96                @return Whether the spline is open. */
97        inline bool IsOpen() const { return !isClosed; }
98
99        /** Overwrites the list of control points for this spline with a new ordered list of control points.
100                @param _cvs The new control points. */
101        inline void SetCVs(const FCDCVs& _cvs) { cvs = _cvs; }
102
103        /** Overwrites the list of knots for this spline with a new ordered list of knots.
104                @param _knots The new knots. */
105        inline void SetKnots(const FCDKnots& _knots) { knots = _knots; }
106
107        /** Sets the spline closed state.
108                @param _isClosed The new closed state. */
109        inline void SetClosed(bool _isClosed) { isClosed = _isClosed; }
110
111        /** [INTERNAL] Reads in the \<spline\> element from a given COLLADA XML tree node.
112                @param splineNode The COLLADA XML tree node.
113                @return The status of the import. If the status is not successful,
114                        it may be dangerous to extract information from the spline.*/
115        FUStatus LoadFromXML(xmlNode* splineNode);
116
117        /** [INTERNAL] Writes out the \<spline\> element to the given COLLADA XML tree node.
118                @param parentNode The COLLADA XML parent node in which to insert the spline information.
119                @return The created \<spline\> element XML tree node. */
120        xmlNode* WriteToXML(xmlNode* parentNode) const;
121};
122
123#endif // _FCD_GEOMETRY_SPLINE_H_
Note: See TracBrowser for help on using the repository browser.