00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GU_VolumeBreak__
00020 #define __GU_VolumeBreak__
00021
00022 #include "GU_API.h"
00023 #include <GEO/GEO_PrimList.h>
00024 #include <UT/UT_HashTable.h>
00025 #include <UT/UT_RefArray.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_FloatArray.h>
00028
00029 class GU_Detail;
00030 class GEO_Point;
00031 class GEO_PrimVolume;
00032 class GEO_PrimPoly;
00033
00034 enum guBreakPolyType
00035 {
00036 GU_INSIDE_POLY,
00037 GU_OUTSIDE_POLY,
00038 GU_UNKNOWN
00039 };
00040
00041 enum guBreakPointStatus
00042 {
00043 GU_INTERIOR_POINT,
00044 GU_VERTEX_POINT
00045 };
00046
00047 struct guBreakPoly;
00048
00049 struct guBreakPoint
00050 {
00051
00052 guBreakPointStatus status;
00053
00054
00055 GEO_Point *pt;
00056
00057
00058
00059 GEO_Point *pt1;
00060 GEO_Point *pt2;
00061
00062
00063 guBreakPoint *prev;
00064 guBreakPoint *next;
00065
00066
00067 UT_PtrArray<guBreakPoly *> polys;
00068 };
00069
00070 struct guBreakPoly
00071 {
00072
00073 guBreakPolyType type;
00074
00075
00076 GEO_PrimPoly *poly;
00077
00078
00079 UT_PtrArray<guBreakPoint *> points;
00080 };
00081
00082 typedef UT_PtrArray<guBreakPoint *> guBreakPointArray;
00083 typedef UT_PtrArray<guBreakPoly *> guBreakPolyArray;
00084
00085 enum guLoopCloseMethod
00086 {
00087 GU_NO_CLOSE,
00088 GU_FLAT_CLOSE,
00089 GU_APEX_CLOSE,
00090 GU_MULTIAPEX_CLOSE,
00091 GU_GRADIENT_CLOSE
00092 };
00093
00094
00095
00096 class GU_API GU_VolumeBreak
00097 {
00098 public:
00099 GU_VolumeBreak();
00100 virtual ~GU_VolumeBreak();
00101
00102 void setGroups(const GB_PrimitiveGroup *agrp) { myGrp = agrp; }
00103 void setSnapDistance(fpreal snapdistance) { myTol = snapdistance; }
00104 void setKeepInside(bool inside) { myKeepInside = inside; }
00105 void setKeepOutside(bool outside) { myKeepOutside = outside; }
00106 void setCloseGeometry(bool closegeo) { myCloseGeo = closegeo; }
00107 void setCloseHoles(guLoopCloseMethod closemethod)
00108 { myCloseMethod = closemethod; }
00109
00110 void volumeBreak(GU_Detail &gdp, GEO_PrimVolume &volume,
00111 GB_PrimitiveGroup *ingrp, GB_PrimitiveGroup *inclgrp,
00112 GB_PrimitiveGroup *outgrp, GB_PrimitiveGroup *outclgrp);
00113
00114
00115 private:
00116 GU_Detail *myGdp;
00117 GEO_PrimVolume *myVolume;
00118
00119 const GB_PrimitiveGroup *myGrp;
00120
00121 fpreal myTol;
00122 bool myKeepInside;
00123 bool myKeepOutside;
00124 bool myCloseGeo;
00125 guLoopCloseMethod myCloseMethod;
00126
00127
00128 UT_HashTable myEdgeTable;
00129
00130
00131 UT_PtrArray<guBreakPoint *> myPointList;
00132
00133
00134 UT_PtrArray<guBreakPoly *> myPolyList;
00135
00136
00137 UT_FloatArray myPointDistances;
00138
00139 void clearPointList();
00140 void clearPolyList();
00141 void printPointList();
00142 void printPolyList();
00143
00144 static void addBreakPoint(GEO_Primitive &prim,
00145 GEO_Point &pa, GEO_Point &pb, void *data);
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 GEO_Point * makeBreakPoint(GEO_Point *pt1, GEO_Point *pt2);
00156
00157 int findRoot(const GEO_PrimVolume &volume,
00158 const UT_Vector3 &in1, fpreal indist1,
00159 const UT_Vector3 &in2, fpreal indist2,
00160 UT_Vector3 &out,
00161 int maxiters = 100);
00162
00163 int findRoot(const GEO_PrimVolume &volume,
00164 const UT_Vector3 &origin,
00165 const UT_Vector3 &dir,
00166 UT_Vector3 &out,
00167 int maxiters = 100);
00168
00169 int fusePoints(guBreakPoly *poly);
00170
00171
00172 int splitPoly(guBreakPoly *poly);
00173
00174
00175
00176 int splitClosedPoly(guBreakPoly *poly, bool &finished);
00177
00178
00179
00180 int splitOpenPoly(guBreakPoly *poly, bool &finished);
00181
00182
00183
00184 void sortBreakPoints(guBreakPoly *poly);
00185
00186 void findLoops(UT_RefArray<guBreakPointArray> &loops,
00187 guBreakPointArray &breakpoints);
00188
00189 int closeLoops(UT_RefArray<guBreakPointArray> &loops,
00190 GU_Detail &gdp, GEO_PrimVolume &sdf,
00191 UT_PtrArray<GEO_PrimPoly *> &closurepolys);
00192
00193 guBreakPolyType classifyPoly(guBreakPoly *poly);
00194
00195 GEO_PrimPoly * createPolygon(GU_Detail &gdp,
00196 GEO_PrimPoly *srcpoly = 0,
00197 bool preservegroups = true);
00198
00199 GEO_PrimPoly * createPolygon(GU_Detail &gdp,
00200 const UT_PtrArray<GEO_Vertex *> &vtxes,
00201 bool closed,
00202 GEO_PrimPoly *srcpoly = 0,
00203 bool preservegroups = true);
00204
00205 int linkBreakPoints(guBreakPoint *p1, guBreakPoint *p2);
00206 bool linkExistsInPoly(guBreakPoint *pt, guBreakPoly *p);
00207 };
00208
00209 struct guPolyApplyData
00210 {
00211 GU_VolumeBreak *breaker;
00212 guBreakPoly *poly;
00213 };
00214
00215
00216
00217 #endif
00218