00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Alex Lee 00008 * Side Effects Software Inc. 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: Geometry Library (C++) 00015 * 00016 * COMMENTS: 00017 * 00018 * This implements a graph where the graph abstracts trim loops on 00019 * a surface. Each vertex of the graph represents an intersection between 00020 * two edges, and each edge of the graph represents a segment between 00021 * two vertices on a trimLoop. 00022 * 00023 */ 00024 00025 #ifndef __GD_TrimGraph_h__ 00026 #define __GD_TrimGraph_h__ 00027 00028 #include "GD_API.h" 00029 typedef int GD_VERTEX; 00030 typedef int GD_EDGE; 00031 00032 enum GD_TrimGraphError { 00033 GD_NONE = 0, 00034 GD_CANT_FIND_LOOP = 1, 00035 GD_NOT_TWO_SIDES = 2 00036 }; 00037 00038 class GD_TrimLoop; 00039 class GD_TrimHitInfo; 00040 class GD_TrimVertex; 00041 class GD_TrimEdges; 00042 class GD_TrimRegion; 00043 class GD_Face; 00044 00045 class GD_API GD_TrimGraph { 00046 public: 00047 // clockwise indicated the direction of the graph. 00048 GD_TrimGraph(int clockwise, float tol=1e-4F); 00049 ~GD_TrimGraph(); 00050 00051 // Adds a new loop to the graph. After adding the the new loop, we 00052 // would try to find a closed loop. If a closed loop is found, we 00053 // return 1, otherwise 0. 00054 int addTrimLoop(GD_Face* face, GD_TrimLoop *tloop); 00055 00056 // Adds a new vertex to the graph. It serves the purpose of having 00057 // one central place to store all the vertices so that it's convenient 00058 // to reference a vertex or to delete them at the end. 00059 GD_VERTEX addTrimVertex(GD_TrimVertex *vertex); 00060 00061 // When a function finds a loop that's made up of two edges, we 00062 // call this function. edge1 and edge2 are the indices of the 00063 // edges that make up the loop, the "hitinfo" is the infomation 00064 // of intersecting edge2 with edge1 [ edge1->intersect(edge2) ] 00065 void foundLoop(GD_EDGE edge1, GD_EDGE edge2, 00066 const UT_RefArray<GD_TrimHitInfo> &hitinfo); 00067 00068 GD_TrimVertex* getVertex(GD_VERTEX n) const {return myVertices((unsigned)n);}; 00069 GD_TrimEdges* getEdge(GD_EDGE n) const {return myLoops((unsigned)n);}; 00070 int vertexCount() const {return (int)myVertices.entries();}; 00071 00072 // Returns a loop from the graph. This is just a loop that was 00073 // identified when adding the loops to the graph. Returns NIL if 00074 // no loop was found. It is the caller's responsibility to delete 00075 // the returned result. 00076 GD_TrimLoop* getLoop() const; 00077 GD_TrimGraphError toProfile(GD_TrimRegion *region, 00078 const UT_BoundingRect &brect); 00079 private: 00080 // Tries to find a loop, using "root" as the root of the tree. This 00081 // should be able to detect and identify if a cycle exists and it's 00082 // connected to the root. However, this makes no guarantee to which 00083 // cycle will be found. 00084 int findLoop(GD_VERTEX root); 00085 00086 // Indicates that we have a loop that is already closed; makes life 00087 // a lot easier. 00088 void foundClosedLoop(GD_EDGE edge); 00089 00090 // Writing out a single closed loop out to the region. The closed loop 00091 // has a vertx associated with it that has exactly one vertex, with 00092 // the end points of the loop recorded on it. 00093 void toProfileClosedLoop(GD_TrimVertex *vertex, 00094 GD_TrimRegion *region) const; 00095 00096 // Write out a cycle that consist of exactly two loops, (and thus 00097 // two vertices, curV and nextV) to the the region. 00098 // If region is nil, then we don't write it out. If tloop is not nil, 00099 // then, we would return the loop also. Make sure tloop has no 00100 // TrimPieces since we are just appending to it without checking. 00101 void toProfileTwoLoops(GD_TrimVertex *curV, 00102 GD_TrimVertex *nextV, 00103 GD_TrimRegion *region, 00104 GD_TrimLoop *tloop = 0) const; 00105 00106 void toProfileMultiLoops(GD_TrimVertex *nextV, 00107 GD_TrimRegion *region, 00108 GD_TrimLoop *tloop = 0) const; 00109 00110 int myFoundLoop; 00111 UT_PtrArray<GD_Face*> myFaces; 00112 UT_PtrArray<GD_TrimEdges*> myLoops; 00113 UT_PtrArray<GD_TrimVertex*> myVertices; 00114 int myClockwise; 00115 GD_TrimLoop* myClosedLoop; 00116 float myTol; 00117 }; 00118 00119 #endif 00120
1.5.9