00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GEO_TriMesh__
00020 #define __GEO_TriMesh__
00021
00022 #include "GEO_API.h"
00023 #include <UT/UT_RefArray.h>
00024 #include "GEO_Vertex.h"
00025 #include "GEO_Primitive.h"
00026
00027 class GB_FloatOffsets;
00028 class GD_Face;
00029 class GD_Detail;
00030 class GEO_Detail;
00031
00032 #define FOR_MESH_VERTICES(mesh, vtx, cnt) \
00033 for (cnt=0; (cnt < mesh->getVertexCount()) && \
00034 (vtx = &((*mesh)(cnt))); cnt++)
00035
00036 class GEO_API GEO_TriMesh : public GEO_Primitive {
00037 public:
00038 GEO_TriMesh(GEO_Detail *d);
00039 virtual ~GEO_TriMesh();
00040
00041 virtual unsigned getPrimitiveId() const = 0;
00042 virtual int getBBox(UT_BoundingBox *bbox) const;
00043 virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
00044 virtual UT_Vector3 baryCenter() const;
00045 virtual bool evaluatePoint(GEO_Vertex &vertex,
00046 GEO_AttributeHandleList &hlist,
00047 fpreal u, fpreal v, uint du, uint dv) const;
00048
00049 virtual int save(ostream &os, int binary) const;
00050 virtual bool load(UT_IStream &is);
00051
00052 virtual void copyPrimitive(const GEO_Primitive *src,
00053 GEO_Point **ptredirect);
00054 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00055
00056 virtual void addPointRefToGroup(GB_PointGroup &grp) const;
00057 virtual void changePointRef(GB_Element *from, GB_Element *to);
00058
00059 virtual int isDegenerate() const;
00060
00061
00062 void setSize(unsigned int sz);
00063
00064
00065 virtual int detachPoint (GB_Element *ppt, int allVertices=1);
00066 virtual int ifDetachPoint(GB_Element *ppt) const;
00067
00068
00069
00070
00071
00072
00073 virtual int detachPoints (GB_PointGroup &grp);
00074
00075
00076
00077
00078 virtual int insertVertex(GEO_Point *ppt, unsigned int where=0);
00079 virtual int appendVertex(GEO_Point *ppt);
00080 virtual int deleteVertex(GEO_Vertex &vtx);
00081 virtual int deleteVertex(unsigned int num);
00082
00083
00084
00085 virtual unsigned getVertexCount() const;
00086 unsigned getFastVertexCount() const
00087 { return vtxList.entries(); }
00088
00089
00090
00091 int find(const GEO_Vertex &vtx) const { return vtxList.find(vtx); }
00092 int find(const GEO_Point &ppt) const;
00093
00094
00095 const GEO_Vertex &operator()(unsigned i) const { return vtxList(i); }
00096 GEO_Vertex &operator()(unsigned i) { return vtxList(i); }
00097 const GEO_Vertex &operator[](unsigned i) const
00098 {
00099 return (i < vtxList.entries()) ? vtxList(i)
00100 : vtxList(0);
00101 }
00102 GEO_Vertex &operator[](unsigned i)
00103 {
00104 return (i < vtxList.entries()) ? vtxList(i)
00105 : vtxList(0);
00106 }
00107 virtual const GEO_Vertex &getVertex(unsigned i) const;
00108 virtual GEO_Vertex &getVertex(unsigned i);
00109 void setVertex(unsigned int i, GEO_Point *pt)
00110 {
00111 if (i < vtxList.entries())
00112 vtxList(i).setPt(pt);
00113 }
00114
00115 virtual int isPointUsed(GB_Element *pt) const;
00116 virtual int isPointGroupUsed(const GB_PointGroup &grp) const;
00117
00118
00119 virtual int vertexApply(int (*apply)(GB_Vertex &vtx, void *),
00120 void *data = 0);
00121 virtual int vertexApply(int (*apply)(const GB_Vertex &vtx, void *),
00122 void *data = 0) const;
00123
00124
00125
00126
00127 void homogenize(GEO_AttributeHandleList &hlist,
00128 int startcv=0, int endcv=-1);
00129 void dehomogenize(GEO_AttributeHandleList &hlist,
00130 int startcv=0, int endcv=-1);
00131 void homogenize (int startcv = 0, int endcv = -1);
00132 void dehomogenize(int startcv = 0, int endcv = -1);
00133 void homogenizeWAttrib(const GB_FloatOffsets &foffsets,
00134 int startcv = 0, int endcv = -1);
00135 void dehomogenizeWAttrib(const GB_FloatOffsets &foffsets,
00136 int startcv = 0, int endcv = -1);
00137 void homogenizeWAttrib(const GB_FloatOffsets *ptoffsets,
00138 const GB_FloatOffsets *vtxoffsets,
00139 int startcv = 0, int endcv = -1);
00140 void dehomogenizeWAttrib(const GB_FloatOffsets *ptoffsets,
00141 const GB_FloatOffsets *vtxoffsets,
00142 int startcv = 0, int endcv = -1);
00143
00144
00145
00146 virtual void unitLengthToUnitPair(float ulength, float vlength,
00147 float &uparm, float &vparm)const;
00148
00149 virtual void unitToUnitLengthPair(float uparm, float vparm,
00150 float &ulength, float &vlength)
00151 const;
00152
00153 protected:
00154 virtual void copyOffsetPrimitive(const GEO_Primitive *src, int base);
00155
00156
00157 virtual int savePrivate(ostream &os, int binary) const = 0;
00158 virtual bool loadPrivate(UT_IStream &is) = 0;
00159 virtual int pointCanDelete(GB_Element *) const;
00160 virtual void pointDeleted(GB_Element *pt);
00161
00162
00163
00164 virtual bool validate(void) const;
00165
00166
00167 int multipleInsert(unsigned int where,
00168 unsigned int count,
00169 unsigned int appendPoints = 1);
00170
00171 void setSizeFast(int new_entries, int src_size);
00172
00173 UT_RefArray<GEO_Vertex> vtxList;
00174
00175
00176 private:
00177 friend ostream &operator<<(ostream &os, const GEO_TriMesh &d)
00178 {
00179 d.save(os, 0);
00180 return os;
00181 }
00182 };
00183 #endif
00184