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 * George ElKoura 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: GEO Library (C++) 00015 * 00016 * COMMENTS: This class builds a useful structure for determining the 00017 * connectivity of points. 00018 * 00019 */ 00020 00021 #ifndef __GEO_PointConnector_h__ 00022 #define __GEO_PointConnector_h__ 00023 00024 #include "GEO_API.h" 00025 #include <UT/UT_BitArray.h> 00026 #include <UT/UT_PtrArray.h> 00027 #include <UT/UT_RefArray.h> 00028 #include <GB/GB_Group.h> 00029 #include "GEO_Detail.h" 00030 #include "GEO_PointRef.h" 00031 00032 00033 typedef UT_PtrArray<GEO_Point *> geo_PointArray; 00034 typedef UT_PtrArray<GEO_Primitive *> geo_PrimArray; 00035 00036 00037 class GEO_API GEO_PointConnector 00038 { 00039 public: 00040 GEO_PointConnector(GEO_Detail &gdp, GEO_PointRefArray *ptrefarray = 0); 00041 GEO_PointConnector(GEO_Detail &gdp, const GB_PointGroup &ptgrp, 00042 bool collapse=false, GEO_PointRefArray *ptrefarray = 0); 00043 ~GEO_PointConnector(); 00044 00045 00046 int getTreeCount() const 00047 { return (int)myForest.entries(); } 00048 00049 // points(i) returns the points list of tree i 00050 const geo_PointArray &points(int i) const 00051 { return myForest((unsigned)i).myPoints; } 00052 00053 // connectedPoints(i) returns the connected points of tree i 00054 const geo_PointArray &connectedPoints(int i) const 00055 { return myForest((unsigned)i).myConnectedPoints; } 00056 00057 const geo_PrimArray &connectedPrims(int i) const 00058 { return myForest((unsigned)i).myConnectedPrims; } 00059 00060 // Clears the connections built 00061 void clear(); 00062 00063 // Returns the index of the tree with pt in it. 00064 int buildPointConnections(GEO_Point &pt, 00065 bool collapse = false); 00066 // Returns the index of the last tree built. 00067 int buildPointConnections( 00068 const GB_PointGroup &ptgroup, 00069 bool collapse = false); 00070 00071 00072 // These methods look for the point or primitive in the connected list 00073 // (the point one doesn't even look in the "points" list, so everything 00074 // should be collapsed. This is so to avoid having to wonder which list 00075 // our point is in, and is in most cases the desired behaviour. Returns 00076 // -1 if point or prim doesn't exist in what we've built. 00077 00078 // The parameters to these functions are not const because UT_PtrArray's 00079 // find method doesn't take a const 00080 int getPointTree(GEO_Point &pt); 00081 int getPrimTree(GEO_Primitive &prim); 00082 00083 // Returns true if both points are connected to one another, and 00084 // false otherwise 00085 bool arePointsConnected(GEO_Point &pt0, 00086 GEO_Point &pt1); 00087 00088 00089 00090 // This method is only public because a callback function needs to call it, 00091 int addPoint(GEO_Point *pt); 00092 private: 00093 00094 // geo_PointConnectivity class represents two lists of points, one that 00095 // contains the connected points that we were in our original point group 00096 // (those points whose connectivity we want to establish), and the other 00097 // contains all the points connected to them. 00098 00099 // When the methods that build these guys have collapse set to true, 00100 // myPoints will be empty and all the points will be added to 00101 // myConnectedPoints 00102 class GEO_API geo_PointConnectivity 00103 { 00104 public: 00105 #ifdef INTEL_COMPILER 00106 geo_PointConnectivity() { } 00107 #endif 00108 geo_PointArray myPoints; // Points we know about 00109 geo_PointArray myConnectedPoints; // Points connected to them 00110 geo_PrimArray myConnectedPrims; // Primitives in the closure 00111 private: 00112 #ifdef INTEL_COMPILER 00113 geo_PointConnectivity(const geo_PointConnectivity& ) { } 00114 #endif 00115 }; 00116 00117 00118 void buildConnections(const GB_PointGroup &ptgrp, 00119 bool collapse = false); 00120 00121 00122 // Members: 00123 GEO_Detail &myGdp; 00124 const GB_PointGroup *mySourcePtGroup; 00125 GEO_PointRefArray *myPointRefArray; 00126 bool myOwnRefArray; // do we own the point ref array 00127 UT_BitArray myVisitedPoints; // bits of "used" source points 00128 UT_BitArray myAddedPrims; // Tracks which prims are added. 00129 int myCurrentTree; // keeps track of the tree we're 00130 // working on 00131 00132 bool myCollapse; // Are we collapsing the structure 00133 00134 // The forest contains the lists of connected points (trees) 00135 UT_RefArray<geo_PointConnectivity> myForest; 00136 }; 00137 #endif
1.5.9