FCDocument/FCDGeometrySpline.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005-2007 Feeling Software Inc.
00003     Portions of the code are:
00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
00005     
00006     MIT License: http://www.opensource.org/licenses/mit-license.php
00007 */
00013 #ifndef _FCD_GEOMETRY_SPLINE_H_
00014 #define _FCD_GEOMETRY_SPLINE_H_
00015 
00016 #ifndef __FCD_OBJECT_H_
00017 #include "FCDocument/FCDObject.h"
00018 #endif // __FCD_OBJECT_H_
00019 #ifndef _FU_DAE_ENUM_H_
00020 #include "FUtils/FUDaeEnum.h"
00021 #endif // _FU_DAE_ENUM_H_
00022 #ifndef _FU_PARAMETER_H_
00023 #include "FUtils/FUParameter.h"
00024 #endif // _FU_PARAMETER_H_
00025 
00026 class FCDocument;
00027 class FCDGeometry;
00028 class FCDBezierSpline;
00029 class FCDNURBSSpline;
00030 
00033 class FCOLLADA_EXPORT FCDSpline : public FCDObject
00034 {
00035 private:
00036     DeclareObjectType(FCDObject);
00037 
00038     FUDaeSplineForm::Form form;
00039     fm::string name;
00040 
00041 protected:
00042     FMVector3List cvs; 
00044 public:
00047     FCDSpline(FCDocument* document);
00048 
00050     virtual ~FCDSpline();
00051 
00054     virtual FUDaeSplineType::Type GetSplineType() const = 0;
00055 
00058     inline fm::string& GetName() { return name; }
00059     inline const fm::string& GetName() const { return name; } 
00063     inline void SetName(const fm::string& _name) { name = _name; }
00064 
00067     inline bool IsClosed() const { return form == FUDaeSplineForm::CLOSED; }
00068 
00071     inline void SetClosed(bool closed) { form = (closed) ? FUDaeSplineForm::CLOSED : FUDaeSplineForm::OPEN; }
00072 
00075     inline size_t GetCVCount() const { return cvs.size(); }
00076 
00080     inline FMVector3* GetCV(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); }
00081     inline const FMVector3* GetCV(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(cvs.at(index)); } 
00085     inline FMVector3List& GetCVs() { return cvs; }
00086     inline const FMVector3List& GetCVs() const { return cvs; } 
00089     inline void ClearCVs() { cvs.clear(); }
00090 
00095     virtual FCDSpline* Clone(FCDSpline* clone) const;
00096 };
00097 
00098 typedef fm::pvector<FCDSpline> FCDSplineList; 
00099 typedef FUObjectContainer<FCDSpline> FCDSplineContainer; 
00100 typedef fm::pvector<FCDBezierSpline> FCDBezierSplineList; 
00101 typedef fm::pvector<FCDNURBSSpline> FCDNURBSSplineList; 
00110 class FCOLLADA_EXPORT FCDLinearSpline : public FCDSpline
00111 {
00112 private:
00113     DeclareObjectType(FCDSpline);
00114 
00115 public:
00118     FCDLinearSpline(FCDocument* document);
00119 
00121     virtual ~FCDLinearSpline();
00122 
00125     virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::LINEAR; }
00126 
00129     bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; }
00130 
00133     void ToBezier(FCDBezierSpline& toFill);
00134 
00137     virtual bool IsValid() const;
00138 };
00139 
00147 class FCOLLADA_EXPORT FCDBezierSpline : public FCDSpline
00148 {
00149 private:
00150     DeclareObjectType(FCDSpline);
00151 
00152 public:
00155     FCDBezierSpline(FCDocument* document);
00156     
00158     virtual ~FCDBezierSpline();
00159 
00162     virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::BEZIER; }
00163 
00166     bool AddCV(const FMVector3& cv){ cvs.push_back(cv); return true; }
00167 
00170     void ToNURBs(FCDNURBSSplineList &toFill) const;
00171 
00174     virtual bool IsValid() const;
00175 };
00176 
00184 class FCOLLADA_EXPORT FCDNURBSSpline : public FCDSpline
00185 {
00186 private:
00187     DeclareObjectType(FCDSpline);
00188 
00189     FloatList weights;
00190     FloatList knots;
00191     uint32 degree;
00192 
00193 public:
00196     FCDNURBSSpline(FCDocument* document);
00197     
00199     virtual ~FCDNURBSSpline();
00200 
00203     virtual FUDaeSplineType::Type GetSplineType() const { return FUDaeSplineType::NURBS; }
00204 
00207     inline uint32 GetDegree() const { return degree; }
00208 
00211     inline void SetDegree(uint32 deg){ degree = deg; }
00212 
00216     bool AddCV(const FMVector3& cv, float weight);
00217 
00221     inline float* GetWeight(size_t index) { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); }
00222     inline const float* GetWeight(size_t index) const { FUAssert(index < GetCVCount(), return NULL); return &(weights.at(index)); } 
00226     inline size_t GetKnotCount() const { return knots.size(); }
00227 
00230     inline void AddKnot(float knot) { knots.push_back(knot); }
00231 
00235     inline float* GetKnot(size_t index) { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));}
00236     inline const float* GetKnot(size_t index) const { FUAssert(index < GetKnotCount(), return NULL); return &(knots.at(index));} 
00240     inline FloatList& GetWeights() { return weights; }
00241     inline const FloatList& GetWeights() const { return weights; } 
00245     inline FloatList& GetKnots() { return knots; }
00246     inline const FloatList& GetKnots() const { return knots; } 
00250     virtual bool IsValid() const;
00251 
00256     virtual FCDSpline* Clone(FCDSpline* clone) const;
00257 };
00258 
00268 class FCOLLADA_EXPORT FCDGeometrySpline : public FCDObject
00269 {
00270 private:
00271     DeclareObjectType(FCDObject);
00272     FCDGeometry* parent;
00273 
00274     DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, type, FC("Spline Type")); // FUDaeSplineType::Type;
00275     DeclareParameterContainer(FCDSpline, splines, FC("Splines"));
00276 
00277 public:
00281     FCDGeometrySpline(FCDocument* document, FCDGeometry* parent);
00282 
00284     virtual ~FCDGeometrySpline();
00285 
00288     FCDGeometry* GetParent() { return parent; }
00289     const FCDGeometry* GetParent() const { return parent; } 
00293     FUDaeSplineType::Type GetType() const { return (FUDaeSplineType::Type) *type; }
00294 
00298     bool SetType(FUDaeSplineType::Type _type);
00299 
00302     size_t GetSplineCount() const { return splines.size(); }
00303 
00306     size_t GetTotalCVCount();
00307 
00311     FCDSpline* GetSpline(size_t index){ FUAssert(index < GetSplineCount(), return NULL); return splines[index]; }
00312     const FCDSpline* GetSpline(size_t index) const { FUAssert(index < GetSplineCount(), return NULL); return splines[index]; }
00322     FCDSpline* AddSpline(FUDaeSplineType::Type type = FUDaeSplineType::UNKNOWN);
00323 
00326     void ConvertBezierToNURBS(FCDNURBSSplineList& toFill);
00327 
00333     FCDGeometrySpline* Clone(FCDGeometrySpline* clone = NULL) const;
00334 };
00335 
00336 #endif // _FCD_GEOMETRY_SPLINE_H_

Generated on Thu Feb 14 16:58:34 2008 for FCollada by  doxygen 1.4.6-NO