00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef VRS_POLYGONSETTOOL_H
00026 #define VRS_POLYGONSETTOOL_H
00027
00028 #include <vrs/matrix.h>
00029 #include <vrs/vector.h>
00030
00031 namespace VRS {
00032
00033 class PolygonSet;
00034 class Transform;
00035 template<typename T> class Iterator;
00036 class Bounds;
00037 class Facet;
00038 class Color;
00039
00041 class VRS_CORE_API PolygonSetTool {
00042 public:
00043
00049 static SO<Facet> removeRedundantVertices(SO<Facet> soFacet, double toleranceDegrees = 0.0);
00050
00053 static SO<PolygonSet> tesselateFacet(SO<Facet> facet, const Vector& forceNormal = Vector::origin);
00054
00056 static void copy(const PolygonSet* source, PolygonSet* dest, bool deepCopy = true);
00057
00059 static PolygonSet* copy(const PolygonSet* poly, bool deepCopy = true);
00060
00061
00068 static PolygonSet* mergePolygonSets(Iterator<SO<PolygonSet> >* polys);
00069
00070
00074 static SO<Iterator<SO<PolygonSet> > > forceMerge(SO<Iterator<SO<PolygonSet> > > meshes, bool indexed, int maxVertices = 65535);
00075
00082 static SO<PolygonSet> forceTriangleMerge(SO<Iterator<SO<PolygonSet> > > polys, bool indexed);
00083
00089 static bool canBeMerged(PolygonSet* poly1, PolygonSet* poly2, bool considerEfficiency = true);
00090
00092 static SO<PolygonSet> convertToIndexedForm(SO<PolygonSet> poly, bool packData = false);
00093
00096 static SO<PolygonSet> convertToTrivialIndexedForm(SO<PolygonSet> poly);
00097
00107 static SO<PolygonSet> convertToNonIndexedForm(SO<PolygonSet> poly, bool packData = false);
00108
00112 static PolygonSet* invertOrientation(const PolygonSet* poly);
00113
00115
00122 static PolygonSet* extractTriangleMesh(const PolygonSet* mesh, bool removeUnusedVertices = false);
00123
00125
00132
00133 static bool isValid(const PolygonSet* poly);
00134
00138 static void ValidatePolygonSet(SO<PolygonSet> poly);
00139
00146 static bool isSimpleTriangleMesh(const PolygonSet* mesh);
00147
00150 static void computeFaceNormals(PolygonSet* mesh);
00151
00153 static void invertNormals(PolygonSet* mesh);
00154
00155
00157 static void computeVertexNormals(PolygonSet* mesh);
00158
00160
00164 static void computeSmoothingNormals(PolygonSet* mesh,double maxAngle=30.0);
00165
00167 static void computeSphericalTexCoords(PolygonSet* mesh, const Vector& center);
00168
00170
00176 static void computeTangents(PolygonSet* mesh);
00177
00179 static Vector getTriangleNormal(const Vector& a, const Vector& b, const Vector& c);
00180
00181
00182
00184
00188 static void transformPolygonSet(PolygonSet* mesh, const Matrix& matrix);
00189
00193 static void compress(SO<PolygonSet> poly);
00194
00195 enum ClipMethod { KEEP_INTERSECTING_TRIANGLES, REMOVE_INTERSECTING_TRIANGLES,
00196 CLIP_INTERSECTING_TRIANGLES };
00197 VRS_SERIALIZABLE_CLASS_ENUM(ClipMethod);
00198 static SO<PolygonSet> clipMesh(SO<PolygonSet> mesh, Bounds clipBounds,
00199 ClipMethod method = PolygonSetTool::CLIP_INTERSECTING_TRIANGLES);
00209
00210 static SO<PolygonSet> clipMesh(
00211 SO<PolygonSet> poly,
00212 const Vector& onPlane,
00213 const Vector& planeNormal,
00214 PolygonSetTool::ClipMethod method = PolygonSetTool::CLIP_INTERSECTING_TRIANGLES
00215 );
00216
00218 static PolygonSet* createSphere(Vector midpoint, double radius, UINT subdivisions = 4);
00219
00221
00234 static PolygonSet* extrudeEdges(const Facet* polygon, double height, bool stripes = false, Vector direction = Vector(0.0, 0.0, 0.0));
00235
00244 static PolygonSet* splitTriangles(const PolygonSet* poly, double maxEdgeLength);
00245
00253 static SO<PolygonSet> filterTriangles(
00254 SO<PolygonSet> poly,
00255 const Vector& normal,
00256 double maxAngle,
00257 bool complement = false
00258 );
00259
00260
00261 enum EdgeGroup {
00262 SoftEdge = 1<<0,
00263 HardEdge = 1<<1,
00264 BoundaryEdge = 1<<2,
00265 NonManifoldEdge = 1<<3
00266 };
00267
00272 static SO<PolygonSet> extractEdges(const PolygonSet* poly, double angle, EdgeGroup group = PolygonSetTool::HardEdge);
00273
00278 static PolygonSet* computeNormals(const PolygonSet* poly, double length, Color color);
00279
00286 static void unifySimilarVertices(SO<PolygonSet> poly, double minDistance);
00287
00293 static VRS::SO<VRS::Iterator<VRS::Vector> > unifySimilarVertices(
00294 VRS::Iterator<VRS::Vector> *vertices,
00295 double minDistance);
00296
00297
00305 static VRS::SO<VRS::Iterator<VRS::SO<VRS::Iterator<VRS::Vector> > > > unifySimilarVerticesInMultipleItems(
00306 VRS::SO<VRS::Iterator<VRS::SO<VRS::Iterator<VRS::Vector> > > > items,
00307 double minDistance);
00308
00309
00313 static SO<PolygonSet> extrudeSurface(
00314 SO<PolygonSet> surface,
00315 const Vector& shift,
00316 bool createTopSurface = true,
00317 bool createBottomSurface = true
00318 );
00319
00323 static SO<Iterator<SO<PolygonSet> > > splitPolygonSet(
00324 SO<PolygonSet> poly,
00325 unsigned int maxElements = 10000,
00326 bool allowSplitX = true,
00327 bool allowSplitY = true,
00328 bool allowSplitZ = true
00329 );
00330 };
00331
00332 inline Vector PolygonSetTool::getTriangleNormal(const Vector& a, const Vector& b, const Vector& c) {
00333 return ((c-a) * (b-a)).normalized();
00334 }
00335
00336 }
00337
00338 #endif // VRS_POLYGONSETTOOL_H