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 <UT/UT_BoundingBox.h>
00029 #include <UT/UT_BoundingSphere.h>
00030 #include <GA/GA_Primitive.h>
00031 #include "GEO_PrimType.h"
00032 #include "GEO_Vertex.h"
00033
00034 class GA_Edge;
00035 class GA_PrimitiveWrangler;
00036 class GEO_Detail;
00037 class GEO_Vertex;
00038 class GEO_VertexAttribDict;
00039 class GEO_MetaPrim;
00040 class GEO_AttributeHandleList;
00041
00042 typedef void (* GEO_EdgeApplyFunc)(GEO_Primitive &prim, GA_Offset pt_a,
00043 GA_Offset pt_b, void *data);
00044 typedef void (* GEO_EdgeApplyElementFunc)(GEO_Primitive &prim, GEO_Point &a,
00045 GEO_Point &b, void *data);
00046 typedef void (* GEO_EdgeApplyIndexFunc)(GEO_Primitive &prim, int v1,
00047 int v2, void *data);
00048
00049 class GEO_API GEO_Primitive : public GA_Primitive
00050 {
00051 public:
00052 GEO_Primitive(GEO_Detail *d, GA_Offset offset = GA_INVALID_OFFSET);
00053 virtual ~GEO_Primitive();
00054
00055 virtual GA_PrimCompat::TypeMask getPrimitiveId() const;
00056
00057
00058
00059 void copyAttributesAndGroups(const GEO_Primitive &src,
00060 bool copy_groups=true)
00061 {
00062 copyAttributeData(src);
00063 if (copy_groups)
00064 copyGroupMembership(src);
00065 }
00066 void copyAttributesAndGroups(const GEO_Primitive &src,
00067 GA_AttributeRefMap &gah,
00068 bool copy_groups=true)
00069 {
00070 copyAttributeData(src, gah);
00071 if (copy_groups)
00072 copyGroupMembership(src);
00073 }
00074 void copyAttributesAndGroups(const GEO_Primitive &src,
00075 GA_PrimitiveWrangler &wrangler,
00076 bool copy_groups=true)
00077 {
00078 copyAttributeData(src, wrangler);
00079 if (copy_groups)
00080 copyGroupMembership(src);
00081 }
00082
00083
00084
00085 void copyAttributeData(const GEO_Primitive &src);
00086 void copyAttributeData(const GEO_Primitive &src,
00087 GA_AttributeRefMap &gah);
00088 void copyAttributeData(const GEO_Primitive &src,
00089 GA_PrimitiveWrangler &wrangler);
00090
00091 using GA_Primitive::copyAttributeValues;
00092 void copyAttributeValues(const GEO_Primitive &src,
00093 GA_PrimitiveWrangler &wrangler);
00094
00095
00096
00097 void copyGroupMembership(const GEO_Primitive &src);
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 virtual void copyPrimitive(const GEO_Primitive *src,
00110 GEO_Point **ptredirect)=0;
00111 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00112
00113
00114
00115
00116
00117 virtual void transform(const UT_Matrix4 &);
00118
00119
00120
00121 virtual void realToUnitPair(float ureal, float vreal,
00122 float &uunit, float &vunit) const;
00123
00124
00125 virtual void unitToRealPair(float uunit, float vunit,
00126 float &ureal, float &vreal) const;
00127
00128
00129
00130 virtual void unitLengthToUnitPair(float ulength, float vlength,
00131 float &uparm, float &vparm)const;
00132
00133 virtual void unitToUnitLengthPair(float uparm, float vparm,
00134 float &ulength, float &vlength)
00135 const;
00136
00137
00138
00139 SYS_DEPRECATED bool evaluateBaryCenter(GEO_Vertex result,
00140 GEO_AttributeHandleList &gah) const;
00141
00142 bool evaluateBaryCenter(GA_Offset result,
00143 GA_AttributeRefMap &map) const
00144 { return evaluateBaryCenterRefMap
00145 (result, map); }
00146
00147
00148
00149
00150 SYS_DEPRECATED bool evaluatePoint(GEO_Vertex result,
00151 GEO_AttributeHandleList &gah,
00152 fpreal u, fpreal v=0,
00153 uint du=0, uint dv=0) const;
00154
00155 bool evaluatePoint(GA_Offset result,
00156 GA_AttributeRefMap &map,
00157 fpreal u, fpreal v=0,
00158 uint du=0, uint dv=0) const
00159 { return evaluatePointRefMap
00160 (result, map, u, v, du, dv); }
00161
00162
00163
00164
00165
00166 int evaluatePoint( UT_Vector4 &pos, float u, float v = 0,
00167 unsigned du=0, unsigned dv=0) const
00168 { return evaluatePointV4(pos, u, v, du, dv); }
00169
00170 virtual int evaluateNormalVector(UT_Vector3 &nml, float u,
00171 float v = 0) const;
00172
00173
00174
00175
00176
00177
00178
00179 SYS_DEPRECATED bool evaluateInteriorPoint(GEO_Vertex result,
00180 GEO_AttributeHandleList &hlist,
00181 fpreal u, fpreal v, fpreal w = 0) const;
00182 bool evaluateInteriorPoint(GA_Offset result,
00183 GA_AttributeRefMap &map,
00184 fpreal u, fpreal v, fpreal w = 0) const
00185 { return evaluateInteriorPointRefMap(result, map,
00186 u, v, w); }
00187 int evaluateInteriorPoint(UT_Vector4 &pos,
00188 fpreal u, fpreal v, fpreal w = 0) const
00189 { return evaluateInteriorPointV4(pos, u, v, w); }
00190
00191 GEO_Detail *getParent() const;
00192 static GA_PrimCompat::TypeMask getPrimitiveMaskH9(const char *maskstr);
00193
00194 virtual void *castTo() const;
00195
00196
00197
00198 virtual int getBBox(UT_BoundingBox *bbox) const = 0;
00199
00200
00201
00202 virtual bool enlargeBoundingBox(UT_BoundingRect &b,
00203 const GA_Attribute *P) const;
00204 virtual bool enlargeBoundingBox(UT_BoundingBox &b,
00205 const GA_Attribute *P) const;
00206
00207
00208
00209 virtual UT_Vector3 computeNormal() const = 0;
00210
00211
00212 virtual void reverse() = 0;
00213
00214
00215
00216
00217 virtual UT_Vector3 baryCenter() const;
00218
00219
00220
00221
00222
00223
00224 virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
00225
00226
00227 virtual void isolate() { }
00228
00229
00230
00231
00232 virtual void addPointRefToGroup(GA_PointGroup &grp) const;
00233
00234
00235
00236
00237
00238
00239 virtual int detachPoints (GA_PointGroup &grp) = 0;
00240
00241 virtual int hasEdge(const GEO_Point &a, const GEO_Point &b) const;
00242 virtual int hasEdge(const GA_Edge &edge) const;
00243 virtual int hasGuideEdge(int edgeid, UT_Vector4 &a,
00244 UT_Vector4 &b) const;
00245 virtual int hasXsectPoint(int pointid, UT_Vector4 &p) const;
00246
00247 virtual void edgeApply(GEO_EdgeApplyFunc apply, void *data = 0);
00248 virtual void edgeApply(GEO_EdgeApplyElementFunc apply,
00249 void *data = 0);
00250 virtual void edgeApplyIndex(GEO_EdgeApplyIndexFunc apply,
00251 void *data = 0);
00252
00253
00254
00255
00256 virtual int vertexApply(int (*apply)(GEO_Vertex vtx, void *),
00257 void *data = 0);
00258 virtual int vertexApply(int (*apply)(const GEO_Vertex &vtx, void*),
00259 void *data = 0) const;
00260
00261
00262
00263
00264 bool isPointUsed(const GEO_Point *ppt) const;
00265
00266
00267
00268 SYS_DEPRECATED const GEO_Vertex getVertex(unsigned i = 0) const
00269 { return getVertexElement(i); }
00270 SYS_DEPRECATED GEO_Vertex getVertex(unsigned i = 0)
00271 { return getVertexElement(i); }
00272 GEO_Vertex getVertexElement(unsigned i) const;
00273
00274
00275
00276 virtual GEO_MetaPrim *castToMetaPrim(void);
00277 virtual const GEO_MetaPrim *castToMetaPrim(void) const;
00278
00279
00280
00281
00282 virtual int parametricBBox(float u, float v,
00283 float *u0, float *u1,
00284 float *v0, float *v1);
00285
00286
00287
00288 virtual float uvDist(float u1, float v1, float u2, float v2) const;
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 virtual void stashed(int onoff,
00300 GA_Offset offset = GA_INVALID_OFFSET);
00301
00302
00303
00304 int bboxIntersectRay(const UT_Vector3 &rayorig,
00305 const UT_Vector3 &raydir,
00306 int maxtries = 10,
00307 float tmax = 1E17F,
00308 float *distance = 0,
00309 UT_Vector3 *nml=0) const;
00310
00311
00312
00313 virtual fpreal calcVolume(const UT_Vector3 &) const { return 0; }
00314 virtual fpreal calcArea() const { return 0; }
00315 virtual fpreal calcPerimeter() const { return 0; }
00316
00317
00318
00319 virtual bool isQuadric() const { return false; }
00320
00321
00322 static const UT_RefArray<GA_AttribLoadDataH9> &theEmptyLoadAttribs;
00323 static const UT_RefArray<GA_AttribSaveDataH9> &theEmptySaveAttribs;
00324
00325 protected:
00326
00327
00328
00329 static GA_IntrinsicManager::Registrar
00330 registerIntrinsics(GA_PrimitiveDefinition &defn)
00331 { return GA_Primitive::registerIntrinsics(defn); }
00332
00333 virtual void copyOffsetPrimitive(const GEO_Primitive *src,
00334 int basept) = 0;
00335 void copyBasePrimitive(const GEO_Primitive *src,
00336 GEO_Point **ptredirect);
00337 void copyOffsetBasePrimitive(const GEO_Primitive *src,
00338 int basept);
00339
00340 GEO_Vertex buildVertexElement(GA_Offset vertex_offset) const;
00341
00342 virtual bool evaluatePointRefMap(GA_Offset result,
00343 GA_AttributeRefMap &map,
00344 fpreal u, fpreal v=0,
00345 uint du=0, uint dv=0) const = 0;
00346
00347
00348
00349
00350 virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
00351 unsigned du=0, unsigned dv=0) const;
00352
00353
00354
00355
00356 virtual bool evaluateBaryCenterRefMap(GA_Offset result,
00357 GA_AttributeRefMap &map) const;
00358
00359 virtual bool evaluateInteriorPointRefMap(GA_Offset result,
00360 GA_AttributeRefMap &map,
00361 fpreal u, fpreal v, fpreal w = 0) const;
00362 virtual int evaluateInteriorPointV4(UT_Vector4 &pos,
00363 fpreal u, fpreal v, fpreal w = 0) const;
00364
00365 private:
00366 friend class GEO_Detail;
00367
00368
00369 friend ostream &operator<<(ostream &os, const GEO_Primitive &d)
00370 {
00371 d.saveH9(os, 0,
00372 GEO_Primitive::theEmptySaveAttribs,
00373 GEO_Primitive::theEmptySaveAttribs);
00374 return os;
00375 }
00376 };
00377 #endif