00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __GEO_Primitive_H__
00023 #define __GEO_Primitive_H__
00024
00025 #include "GEO_API.h"
00026 #include <iostream.h>
00027 #include <UT/UT_Matrix4.h>
00028 #include <GB/GB_Primitive.h>
00029 #include <GB/GB_Attribute.h>
00030 #include "GEO_Point.h"
00031
00032 class GB_FloatOffsets;
00033 class GB_Edge;
00034 class GEO_Detail;
00035 class GEO_Vertex;
00036 class GEO_VertexAttribDict;
00037 class GEO_MetaPrim;
00038 class GEO_AttributeHandleList;
00039
00040 typedef void (* GEO_EdgeApplyFunc)(GEO_Primitive &prim, GEO_Point &a,
00041 GEO_Point &b, void *data);
00042 typedef void (* GEO_EdgeApplyIndexFunc)(GEO_Primitive &prim, int v1,
00043 int v2, void *data);
00044
00045 class GEO_API GEO_Primitive : public GB_Primitive, public GB_AttributeElem
00046 {
00047 public:
00048 GEO_Primitive(GEO_Detail *d);
00049 virtual ~GEO_Primitive();
00050
00051 virtual int isPrimary(void) const;
00052
00053 void copyAttributeData(const GEO_Primitive *src, int asize)
00054 {
00055 copyAttribData(src, asize);
00056 }
00057 void copyAttributeData(const GEO_Primitive *src);
00058
00059
00060
00061
00062
00063
00064
00065
00066 virtual void copyPrimitive(const GEO_Primitive *src,
00067 GEO_Point **ptredirect)=0;
00068 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00069
00070
00071
00072
00073
00074 virtual void transform(const UT_Matrix4 &);
00075
00076
00077
00078 virtual void realToUnitPair(float ureal, float vreal,
00079 float &uunit, float &vunit) const;
00080
00081
00082 virtual void unitToRealPair(float uunit, float vunit,
00083 float &ureal, float &vreal) const;
00084
00085
00086
00087 virtual void unitLengthToUnitPair(float ulength, float vlength,
00088 float &uparm, float &vparm)const;
00089
00090 virtual void unitToUnitLengthPair(float uparm, float vparm,
00091 float &ulength, float &vlength)
00092 const;
00093
00094
00095
00096
00097
00098 virtual bool evaluatePoint(GEO_Vertex &result,
00099 GEO_AttributeHandleList &gah,
00100 fpreal u, fpreal v=0,
00101 uint du=0, uint dv=0) const = 0;
00102
00103
00104
00105
00106 virtual int evaluatePoint( UT_Vector4 &pos, float u, float v = 0,
00107 unsigned du=0, unsigned dv=0) const;
00108 virtual int evaluatePointWAttrib(UT_Vector4 &pos,
00109 GB_AttributeData &adata,
00110 const GB_FloatOffsets &foffsets,
00111 float u, float v = 0, unsigned du = 0,
00112 unsigned dv = 0) const;
00113 virtual int evaluateNormalVector(UT_Vector3 &nml, float u,
00114 float v = 0) const;
00115
00116
00117
00118
00119
00120
00121
00122 virtual bool evaluateInteriorPoint(GEO_Vertex &result,
00123 GEO_AttributeHandleList &hlist,
00124 fpreal u, fpreal v) const;
00125 virtual int evaluateInteriorPoint(UT_Vector4 &pos,
00126 float u, float v) const;
00127 virtual int evaluateInteriorPointWAttrib
00128 (UT_Vector4 &pos,
00129 GB_AttributeData &adata,
00130 const GB_FloatOffsets &foffsets,
00131 float u, float v) const;
00132
00133 GEO_Detail *getParent() const { return (GEO_Detail*)parent; }
00134 static unsigned getPrimitiveType(const char *name);
00135 static const char *getPrimitiveName(unsigned type);
00136 static unsigned getPrimitiveMask(const char *maskstr);
00137
00138 virtual void *castTo() const;
00139
00140 virtual int hasEdge(const GEO_Point &a, const GEO_Point &b) const;
00141 virtual int hasEdge(const GB_Edge &edge) const;
00142 virtual int hasGuideEdge(int edgeid, UT_Vector4 &a,
00143 UT_Vector4 &b) const;
00144 virtual int hasXsectPoint(int pointid, UT_Vector4 &p) const;
00145
00146 virtual void edgeApply(GEO_EdgeApplyFunc apply , void *data = 0);
00147 virtual void edgeApplyIndex(GEO_EdgeApplyIndexFunc apply,
00148 void *data = 0);
00149
00150 virtual const GEO_Vertex &getVertex(unsigned index) const = 0;
00151 virtual GEO_Vertex &getVertex(unsigned index) = 0;
00152
00153
00154
00155 virtual GEO_MetaPrim *castToMetaPrim(void);
00156 virtual const GEO_MetaPrim *castToMetaPrim(void) const;
00157
00158
00159
00160
00161 virtual int parametricBBox(float u, float v,
00162 float *u0, float *u1,
00163 float *v0, float *v1);
00164
00165
00166
00167 virtual float uvDist(float u1, float v1, float u2, float v2) const;
00168
00169
00170 virtual void stashed(int onoff);
00171
00172
00173
00174 int bboxIntersectRay(const UT_Vector3 &rayorig,
00175 const UT_Vector3 &raydir,
00176 int maxtries = 10,
00177 float tmax = 1E17F,
00178 float *distance = 0,
00179 UT_Vector3 *nml=0) const;
00180
00181
00182 virtual float calcVolume(UT_Vector3 &refpt) const { return 0; }
00183 virtual float calcArea() const { return 0; }
00184 virtual float calcPerimeter() const { return 0; }
00185
00186
00187 virtual bool isQuadric() const { return false; }
00188
00189 protected:
00190 virtual void copyOffsetPrimitive(const GEO_Primitive *src,
00191 int basept) = 0;
00192 void copyBasePrimitive(const GEO_Primitive *src,
00193 GEO_Point **ptredirect);
00194 void copyOffsetBasePrimitive(const GEO_Primitive *src,
00195 int basept);
00196
00197 private:
00198 friend class GEO_Detail;
00199
00200 friend ostream &operator<<(ostream &os, const GEO_Primitive &d)
00201 {
00202 d.save(os, 0);
00203 return os;
00204 }
00205 };
00206 #endif