00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GEO_PrimTriBezier__
00020 #define __GEO_PrimTriBezier__
00021
00022 #include "GEO_API.h"
00023 #include <UT/UT_RefArray.h>
00024 #include <GB/GB_Defines.h>
00025 #include "GEO_Vertex.h"
00026 #include "GEO_Primitive.h"
00027
00028 class GB_FloatOffsets;
00029 class GD_Face;
00030 class GD_Detail;
00031 class GEO_Detail;
00032
00033 #define FOR_MESH_VERTICES(mesh, vtx, cnt) \
00034 for (cnt=0; (cnt < mesh->getVertexCount()) && \
00035 (vtx = &((*mesh)(cnt))); cnt++)
00036
00037 class GEO_API GEO_PrimTriBezier : public GEO_Primitive {
00038 public:
00039 GEO_PrimTriBezier(GEO_Detail *d);
00040 virtual ~GEO_PrimTriBezier();
00041
00042 virtual bool evaluatePoint(GEO_Vertex &result,
00043 GEO_AttributeHandleList &hlist,
00044 fpreal u, fpreal v, uint du, uint dv) const;
00045 virtual int evaluatePoint(UT_Vector4 &pos, float u, float v = 0,
00046 unsigned du=0, unsigned dv = 0) const;
00047 virtual int evaluatePointWAttrib(UT_Vector4 &pos,
00048 GB_AttributeData &adata,
00049 const GB_FloatOffsets &foffsets,
00050 float u, float v=0, unsigned du=0,
00051 unsigned dv = 0) const;
00052
00053
00054
00055 void fillArray(int fakeorder, UT_Vector4 *array) const;
00056 void fillArray(int fakeorder, GEO_Vertex *results,
00057 GEO_AttributeHandleList &hlist) const;
00058 void fillArrayWAttrib(int fakeorder, UT_Vector4 *array,
00059 GB_AttributeData *atrarray,
00060 const GB_FloatOffsets &foffsets) const;
00061 void fillArrayWAttrib(int fakeorder, UT_Vector4 *pts,
00062 GB_AttributeData *ptattrib,
00063 GB_AttributeData *vtxattrib) const;
00064
00065 virtual unsigned getPrimitiveId() const;
00066 virtual int getBBox(UT_BoundingBox *bbox) const;
00067 virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
00068 virtual UT_Vector3 baryCenter() const;
00069
00070 virtual void reverse();
00071 virtual UT_Vector3 computeNormal() const;
00072
00073 virtual float calcVolume(UT_Vector3 &refpt) const;
00074 virtual float calcArea() const;
00075 virtual float calcPerimeter() const;
00076
00077 virtual int save(ostream &os, int binary) const;
00078 virtual bool load(UT_IStream &is);
00079
00080 virtual void copyPrimitive(const GEO_Primitive *src,
00081 GEO_Point **ptredirect);
00082 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00083
00084 virtual void addPointRefToGroup(GB_PointGroup &grp) const;
00085 virtual void changePointRef(GB_Element *from, GB_Element *to);
00086
00087 virtual int isDegenerate() const;
00088
00089
00090 void setOrder(int order);
00091 int getOrder() const { return myOrder; }
00092
00093
00094 virtual int detachPoint (GB_Element *ppt, int allVertices=1);
00095 virtual int ifDetachPoint(GB_Element *ppt) const;
00096
00097
00098
00099
00100
00101
00102 virtual int detachPoints (GB_PointGroup &grp);
00103
00104
00105
00106 virtual unsigned getVertexCount() const;
00107
00108
00109
00110 int find(const GEO_Vertex &vtx) const { return vtxList.find(vtx); }
00111 int find(const GEO_Point &ppt) const;
00112
00113 virtual const GEO_Vertex &getVertex(unsigned i) const;
00114 virtual GEO_Vertex &getVertex(unsigned i);
00115 void setVertex(unsigned int i, GEO_Point *pt)
00116 {
00117 if (i < vtxList.entries())
00118 vtxList(i).setPt(pt);
00119 }
00120
00121
00122
00123 unsigned getRawIndex(unsigned row, unsigned col) const
00124 { return getRawIndex(row, col, myOrder); }
00125 unsigned getRawIndex(unsigned row, unsigned col, int order)const
00126 { return (order - row)*(order-row-1)/2 + col; }
00127 const GEO_Vertex &operator()(unsigned i, unsigned j) const
00128 { return vtxList(getRawIndex(i,j)); }
00129 GEO_Vertex &operator()(unsigned i, unsigned j)
00130 { return vtxList(getRawIndex(i,j)); }
00131 virtual const GEO_Vertex &getVertex(unsigned i, unsigned j) const
00132 { return getVertex(getRawIndex(i, j)); }
00133 virtual GEO_Vertex &getVertex(unsigned i, unsigned j)
00134 { return getVertex(getRawIndex(i, j)); }
00135 void setVertex(unsigned int i, unsigned int j,
00136 GEO_Point *pt)
00137 {
00138 i = getRawIndex(i, j);
00139 if (i < vtxList.entries())
00140 vtxList(i).setPt(pt);
00141 }
00142
00143 virtual int isPointUsed(GB_Element *pt) const;
00144 virtual int isPointGroupUsed(const GB_PointGroup &grp) const;
00145
00146
00147 virtual int vertexApply(int (*apply)(GB_Vertex &vtx, void *),
00148 void *data = 0);
00149 virtual int vertexApply(int (*apply)(const GB_Vertex &vtx, void *),
00150 void *data = 0) const;
00151
00152
00153
00154
00155 void homogenize (int startcv = 0, int endcv = -1);
00156 void dehomogenize(int startcv = 0, int endcv = -1);
00157 void homogenize(GEO_AttributeHandleList &hlist,
00158 int startcv = 0, int endcv = -1);
00159 void dehomogenize(GEO_AttributeHandleList &hlist,
00160 int startcv = 0, int endcv = -1);
00161 void homogenizeWAttrib(const GB_FloatOffsets &foffsets,
00162 int startcv = 0, int endcv = -1);
00163 void dehomogenizeWAttrib(const GB_FloatOffsets &foffsets,
00164 int startcv = 0, int endcv = -1);
00165
00166 protected:
00167 virtual void copyOffsetPrimitive(const GEO_Primitive *src, int base);
00168
00169
00170 virtual int savePrivate(ostream & ,int ) const {return 0;}
00171 virtual bool loadPrivate(UT_IStream &) { return true; }
00172 virtual int pointCanDelete(GB_Element *) const;
00173 virtual void pointDeleted(GB_Element *pt);
00174
00175
00176
00177 virtual bool validate(void) const;
00178
00179
00180 int multipleInsert(unsigned int where,
00181 unsigned int count,
00182 unsigned int appendPoints = 1);
00183
00184 void setSize(unsigned sz);
00185
00186 UT_RefArray<GEO_Vertex> vtxList;
00187 int myOrder;
00188
00189 private:
00190
00191
00192
00193 int evaluateBPointWAttrib(UT_Vector4 &pos,
00194 GB_AttributeData &adata,
00195 GB_AttributeData ablossom[][GB_MAXORDER],
00196 const GB_FloatOffsets &foffsets,
00197 float u, float v=0, unsigned du=0,
00198 unsigned dv = 0) const;
00199
00200 int evaluateBPointWAttrib(UT_Vector4 &pos,
00201 GB_AttributeData *ptadata,
00202 GB_AttributeData ptablossom[][GB_MAXORDER],
00203 const GB_FloatOffsets &ptfoffsets,
00204 GB_AttributeData *vtxadata,
00205 GB_AttributeData vtxablossom[][GB_MAXORDER],
00206 const GB_FloatOffsets &vtxfoffsets,
00207 float u, float v=0, unsigned du=0,
00208 unsigned dv = 0) const;
00209
00210 friend ostream &operator<<(ostream &os, const GEO_PrimTriBezier &d)
00211 {
00212 d.save(os, 0);
00213 return os;
00214 }
00215 };
00216 #endif
00217