cgma
|
00001 //======================================================================= 00002 // 00003 // File: CubitFacetEdgeData 00004 // Description: used for edges of CubitFacets. These are optional 00005 // and used only if specific information must be stored at 00006 // the edge common to tow facets 00007 // Owner: sjowen 00008 // 00009 //======================================================================= 00010 00011 #include "CubitFacetEdge.hpp" 00012 #include "CubitFacetEdgeData.hpp" 00013 #include "CubitFacetData.hpp" 00014 #include "CubitPoint.hpp" 00015 #include "CubitVector.hpp" 00016 #include "GeometryDefines.h" 00017 #include "ToolData.hpp" 00018 00019 static int counter_id = 0; 00020 00021 //====================================================================== 00022 // Function: CubitFacetEdgeData (PUBLIC) 00023 // Description: constructor. Determines the adjacencies from existing 00024 // CubitPoint adjacency information 00025 // Note: can handle non-manifold topology 00026 // Author: sjowen 00027 // Date: 8/00 00028 //====================================================================== 00029 CubitFacetEdgeData::CubitFacetEdgeData( CubitPoint *p1, CubitPoint *p2 ) 00030 { 00031 assert( p1 && p2 ); 00032 assert( p1 != p2 ); 00033 pointArray[0] = p1; 00034 pointArray[1] = p2; 00035 00036 counter_id++; 00037 entityId = counter_id; 00038 00039 // determine adjacency (assumes facets are already defined) 00040 // set the edge and use on the adjacent facets 00041 00042 int sense; 00043 int eindex; 00044 CubitFacet *facet_ptr; 00045 DLIList<CubitFacet*> facet_list; 00046 p1->facets( facet_list ); 00047 CubitBoolean found; 00048 for(int ii=0; ii<facet_list.size(); ii++) { 00049 found = CUBIT_FALSE; 00050 facet_ptr = facet_list.get_and_step(); 00051 for(int jj=0; jj<3 && !found; jj++) 00052 { 00053 if (facet_ptr->point(jj) == p2) 00054 { 00055 found = CUBIT_TRUE; 00056 adjFacetList.append(facet_ptr); 00057 eindex = facet_ptr->edge_index( p1, p2, sense ); 00058 facet_ptr->edge( this, eindex ); 00059 facet_ptr->edge_use( sense, eindex ); 00060 } 00061 } 00062 } 00063 } 00064 00065 //====================================================================== 00066 // Function: CubitFacetEdgeData (PUBLIC) 00067 // Description: overloaded constructor: Adjacency information is 00068 // provided in the arguments -- assumes a 2D topology 00069 // Author: sjowen 00070 // Date: 8/00 00071 //====================================================================== 00072 CubitFacetEdgeData::CubitFacetEdgeData( CubitPoint *p1, CubitPoint *p2, 00073 CubitFacet *facet1, CubitFacet *facet2, 00074 int edge_index1, int edge_index2) 00075 { 00076 assert( p1 && p2 ); 00077 assert( p1 != p2 ); 00078 pointArray[0] = p1; 00079 pointArray[1] = p2; 00080 00081 counter_id++; 00082 entityId = counter_id; 00083 00084 if (facet1) { 00085 adjFacetList.append(facet1); 00086 facet1->edge( this, edge_index1 ); 00087 facet1->edge_use( 1, edge_index1 ); 00088 } 00089 if (facet2) { 00090 adjFacetList.append(facet2); 00091 facet2->edge( this, edge_index2 ); 00092 facet2->edge_use( -1, edge_index2 ); 00093 } 00094 } 00095 00096 //====================================================================== 00097 // Function: ~CubitFacetEdgeData (PUBLIC) 00098 // Description: destructor 00099 // Author: sjowen 00100 // Date: 8/00 00101 //====================================================================== 00102 CubitFacetEdgeData::~CubitFacetEdgeData() 00103 { 00104 assert(adjFacetList.size() == 0); 00105 } 00106 00107 //====================================================================== 00108 // Function: adj_facet (PUBLIC) 00109 // Description: get a specific adjacent facet (by index) 00110 // Author: sjowen 00111 // Date: 4/01 00112 //====================================================================== 00113 CubitFacet *CubitFacetEdgeData::adj_facet( int index ) 00114 { 00115 if (index < 0 || index > adjFacetList.size() - 1) 00116 return (CubitFacet *)NULL; 00117 adjFacetList.reset(); 00118 return adjFacetList.next(index); 00119 } 00120 00121 //====================================================================== 00122 // Function: facets (PUBLIC) 00123 // Description: get the atached facets 00124 // Author: sjowen 00125 // Date: 4/01 00126 //====================================================================== 00127 void CubitFacetEdgeData::facets(DLIList<CubitFacet*> &facet_list) 00128 { 00129 facet_list += adjFacetList; 00130 } 00131 00132 //====================================================================== 00133 // Function: edges (PUBLIC) 00134 // Description: get the atached edges 00135 // Author: sjowen 00136 // Date: 4/01 00137 //====================================================================== 00138 void CubitFacetEdgeData::edges(DLIList<CubitFacetEdge*> &edge_list ) 00139 { 00140 edge_list.append( this ); 00141 } 00142 00143 //====================================================================== 00144 // Function: points (PUBLIC) 00145 // Description: get the attached points 00146 // Author: sjowen 00147 // Date: 4/01 00148 //====================================================================== 00149 void CubitFacetEdgeData::points(DLIList<CubitPoint*> &point_list ) 00150 { 00151 point_list.append( pointArray[0] ); 00152 point_list.append( pointArray[1] ); 00153 } 00154 00155 //====================================================================== 00156 // Function: remove_facet (PUBLIC) 00157 // Description: remove the facet from the edge adjacency list 00158 // Author: sjowen 00159 // Date: 4/01 00160 //====================================================================== 00161 CubitStatus CubitFacetEdgeData::remove_facet( CubitFacet *facet_ptr ) 00162 { 00163 CubitStatus stat = CUBIT_SUCCESS; 00164 bool removed = adjFacetList.remove( facet_ptr ); 00165 if (removed) 00166 stat = CUBIT_SUCCESS; 00167 else 00168 stat = CUBIT_FAILURE; 00169 return stat; 00170 } 00171 00172 //------------------------------------------------------------------------- 00173 // Purpose : Merge edges 00174 // 00175 // Special Notes : points must already be merged. 00176 // 00177 // Creator : Jason Kraftcheck 00178 // 00179 // Creation Date : 02/24/03 00180 //------------------------------------------------------------------------- 00181 CubitStatus CubitFacetEdgeData::merge_edges( CubitFacetEdgeData* other_edge ) 00182 { 00183 if( other_edge == this ) 00184 return CUBIT_SUCCESS; 00185 00186 int reversed = false; 00187 if ( point(0) == other_edge->point(1) && point(1) == other_edge->point(0) ) 00188 reversed = true; 00189 else if( point(0) != other_edge->point(0) || point(1) != other_edge->point(1) ) 00190 return CUBIT_FAILURE; 00191 00192 CubitFacetData* facet; 00193 adjFacetList.reset(); 00194 while( other_edge->adjFacetList.size() ) 00195 { 00196 facet = dynamic_cast<CubitFacetData*>(other_edge->adjFacetList.pop()); 00197 for ( int i = 0; i < 3; i++ ) 00198 { 00199 if( facet->edge(i) == other_edge ) 00200 { 00201 facet->edge( this, i ); 00202 add_facet(facet); 00203 if( reversed ) 00204 facet->edge_use( -facet->edge_use(i), i ); 00205 } 00206 } 00207 } 00208 00209 delete other_edge; 00210 return CUBIT_SUCCESS; 00211 } 00212 00213 void CubitFacetEdgeData::flip() 00214 { 00215 CubitPoint* tmp = pointArray[0]; 00216 pointArray[0] = pointArray[1]; 00217 pointArray[1] = tmp; 00218 for ( int i = adjFacetList.size(); i--; ) 00219 { 00220 CubitFacet* facet = adjFacetList.get_and_step(); 00221 int index = facet->edge_index(this); 00222 assert(index >= 0); 00223 facet->edge_use( -facet->edge_use(index), index ); 00224 } 00225 toggle_is_flipped(); 00226 } 00227