Branch data Line data Source code
1 : : #include "CubitPointData.hpp"
2 : : #include "CubitFacet.hpp"
3 : : #include "CubitFacetEdge.hpp"
4 : : #include "ToolData.hpp"
5 : : #include "CubitFacetData.hpp"
6 : : #include "CubitFacetEdgeData.hpp"
7 : : #include "CastTo.hpp"
8 : :
9 : : static int point_counter = 0;
10 : :
11 : : //===========================================================================
12 : : // Function Name: CubitPointData
13 : : //
14 : : // Member Type: PUBLIC
15 : : // Description: constructor
16 : : // Author:
17 : : // Date:
18 : : //===========================================================================
19 : 1430 : CubitPointData::CubitPointData( double x_val, double y_val, double z_val )
20 [ + - ]: 1430 : : coords( x_val, y_val, z_val )
21 : : {
22 : 1430 : attachedFacets = NULL;
23 : 1430 : point_counter++;
24 : 1430 : entityId = point_counter;
25 : 1430 : }
26 : :
27 : : //===========================================================================
28 : : // Function Name: CubitPointData
29 : : //
30 : : // Member Type: PUBLIC
31 : : // Description: constructor
32 : : // Author:
33 : : // Date:
34 : : //===========================================================================
35 : 0 : CubitPointData::CubitPointData(double x_val, double y_val, double z_val,int *)
36 [ # # ]: 0 : : coords(x_val, y_val, z_val)
37 : : {
38 : 0 : attachedFacets = NULL;
39 : 0 : point_counter++;
40 : 0 : entityId = point_counter;
41 : 0 : }
42 : :
43 : : //===========================================================================
44 : : // Function Name: CubitPointData
45 : : //
46 : : // Member Type: PUBLIC
47 : : // Description: constructor
48 : : // Author:
49 : : // Date:
50 : : //===========================================================================
51 : 0 : CubitPointData::CubitPointData( const CubitVector &new_point )
52 [ # # ]: 0 : : coords( new_point )
53 : : {
54 : 0 : attachedFacets = NULL;
55 : 0 : point_counter++;
56 : 0 : entityId = point_counter;
57 : 0 : }
58 : :
59 : : //===========================================================================
60 : : // Function Name: ~CubitPoint
61 : : //
62 : : // Member Type: PUBLIC
63 : : // Description: destructor
64 : : // Author:
65 : : // Date:
66 : : //===========================================================================
67 : 0 : CubitPointData::~CubitPointData()
68 : : {
69 [ # # ][ # # ]: 0 : delete attachedFacets;
70 [ # # ]: 0 : }
71 : :
72 : : //===========================================================================
73 : : // Function Name: coordinates
74 : : //
75 : : // Member Type: PUBLIC
76 : : // Description: return coordinates of point in form of array
77 : : // Author:
78 : : // Date:
79 : : //===========================================================================
80 : 0 : void CubitPointData::coordinates(double point_array[3])
81 : : {
82 : 0 : point_array[0] = coords.x();
83 : 0 : point_array[1] = coords.y();
84 : 0 : point_array[2] = coords.z();
85 : 0 : }
86 : :
87 : : //===========================================================================
88 : : // Function Name: add_facet
89 : : //
90 : : // Member Type: PUBLIC
91 : : // Description: add a facet to the point's adjacency list
92 : : // Author:
93 : : // Date:
94 : : //===========================================================================
95 : 4752 : void CubitPointData::add_facet( CubitFacet *facet )
96 : : {
97 [ + + ]: 4752 : if ( attachedFacets == NULL )
98 [ + - ]: 1122 : attachedFacets = new DLIList<CubitFacet*>(8);
99 : 4752 : attachedFacets->append(facet);
100 : 4752 : return;
101 : : }
102 : :
103 : : //===========================================================================
104 : : // Function Name: remove_facet
105 : : //
106 : : // Member Type: PUBLIC
107 : : // Description: remove a facet to the point's adjacency list
108 : : // Author:
109 : : // Date:
110 : : //===========================================================================
111 : 0 : void CubitPointData::remove_facet( CubitFacet *facet )
112 : : {
113 [ # # ]: 0 : if ( attachedFacets == NULL )
114 : 0 : return;
115 : 0 : attachedFacets->remove(facet);
116 : 0 : return;
117 : : }
118 : :
119 : : //===========================================================================
120 : : // Function Name: edges
121 : : //
122 : : // Member Type: PUBLIC
123 : : // Description: return the list of facet-edges attached to this point
124 : : // Author: sjowen
125 : : // Date: 4/28/01
126 : : //===========================================================================
127 : 2156 : void CubitPointData::edges( DLIList<CubitFacetEdge *> &edge_list )
128 : : {
129 : : int ii, jj, kk;
130 : : CubitFacet *facet_ptr;
131 : : CubitFacetEdge *edge_ptr, *check_edge_ptr;
132 : :
133 [ - + ]: 2156 : if(attachedFacets == NULL)
134 : 0 : return;
135 : :
136 [ + - ][ + + ]: 9482 : for (ii=0; ii<attachedFacets->size(); ii++)
137 : : {
138 [ + - ]: 7326 : facet_ptr = attachedFacets->get_and_step();
139 [ + + ]: 29304 : for (jj=0; jj<3; jj++)
140 : : {
141 [ + - ]: 21978 : edge_ptr = facet_ptr->edge( jj );
142 [ + - ]: 21978 : if (edge_ptr)
143 : : {
144 [ + - ][ + + ]: 35816 : if (edge_ptr->point(0) == this ||
[ + + ][ + + ]
145 [ + - ]: 13838 : edge_ptr->point(1) == this)
146 : : {
147 : 14652 : int found = 0;
148 [ + - ][ + + ]: 44429 : for (kk=0; kk<edge_list.size() && !found; kk++)
[ + + ][ + + ]
149 : : {
150 [ + - ]: 29777 : check_edge_ptr = edge_list.get_and_step();
151 [ + + ]: 29777 : if (check_edge_ptr == edge_ptr)
152 : 6314 : found = 1;
153 : : }
154 [ + + ]: 14652 : if (!found)
155 : : {
156 [ + - ]: 21978 : edge_list.append( edge_ptr );
157 : : }
158 : : }
159 : : }
160 : : }
161 : : }
162 : :
163 : 2156 : return;
164 : : }
165 : :
166 : :
167 : : //===========================================================================
168 : : // Function Name: num_adj_facets
169 : : //
170 : : // Member Type: PUBLIC
171 : : // Description: return the number of facets attached to the point
172 : : // Author:
173 : : // Date:
174 : : //===========================================================================
175 : 88 : int CubitPointData::num_adj_facets()
176 : : {
177 [ - + ]: 88 : if (attachedFacets == NULL)
178 : 0 : return 0;
179 : : else
180 : 88 : return attachedFacets->size();
181 : : }
182 : :
183 : : //===========================================================================
184 : : // Function Name: merge_points
185 : : //
186 : : // Member Type: PUBLIC
187 : : // Description: merge this point with another
188 : : // Note: currently ignores edges - call before defining the edges
189 : : // Author: sjowen
190 : : // Date: 9/18/01
191 : : //===========================================================================
192 : 0 : CubitStatus CubitPointData::merge_points( CubitPoint *other_point,
193 : : CubitBoolean keep_point /* = CUBIT_FALSE*/)
194 : : {
195 [ # # ]: 0 : if( other_point == this )
196 : 0 : return CUBIT_SUCCESS;
197 : :
198 [ # # ]: 0 : DLIList<CubitFacet *>facet_list;
199 [ # # ]: 0 : other_point->facets( facet_list );
200 : : CubitFacet *adj_facet;
201 : : CubitFacetData *afd;
202 : : int ii;
203 [ # # ][ # # ]: 0 : for (ii=0; ii<facet_list.size(); ii++)
204 : : {
205 [ # # ]: 0 : adj_facet = facet_list.get_and_step();
206 [ # # ]: 0 : other_point->remove_facet( adj_facet );
207 [ # # ]: 0 : afd = CAST_TO(adj_facet, CubitFacetData);
208 [ # # ][ # # ]: 0 : if (afd->point(0) == other_point)
209 [ # # ]: 0 : afd->set_point( this, 0 );
210 [ # # ][ # # ]: 0 : else if(afd->point(1) == other_point)
211 [ # # ]: 0 : afd->set_point( this, 1 );
212 [ # # ][ # # ]: 0 : else if(afd->point(2) == other_point)
213 [ # # ]: 0 : afd->set_point( this, 2 );
214 : : else
215 : : {
216 : 0 : assert(0);
217 : : return CUBIT_FAILURE;
218 : : }
219 : :
220 [ # # ]: 0 : this->add_facet( adj_facet );
221 : :
222 : : // added by J.Kraftcheck - 2/14/03 - update edges also!!!
223 : : CubitFacetEdgeData* afed;
224 [ # # ]: 0 : for ( int j = 0; j < 3; j++ ) {
225 [ # # ][ # # ]: 0 : if( adj_facet->edge(j) ) {
226 [ # # ][ # # ]: 0 : afed = dynamic_cast<CubitFacetEdgeData*>(adj_facet->edge(j));
227 [ # # ][ # # ]: 0 : if ( afed->point(0) == other_point )
228 [ # # ]: 0 : afed->set_point(this, 0);
229 [ # # ][ # # ]: 0 : else if( afed->point(1) == other_point )
230 [ # # ]: 0 : afed->set_point(this, 1);
231 : : }
232 : : }
233 : : }
234 : :
235 [ # # ]: 0 : if (!keep_point)
236 [ # # ][ # # ]: 0 : delete other_point;
237 [ # # ]: 0 : return CUBIT_SUCCESS;
238 : : }
239 : :
240 : 0 : CubitStatus CubitPointData::collapse_edge( CubitPointData *dead_point )
241 : : {
242 : : int i, j;
243 : :
244 : : // Get the list of facets that will be destroyed
245 [ # # ][ # # ]: 0 : DLIList<CubitFacet*> dead_facets, edge_facets;
[ # # ]
246 [ # # ]: 0 : shared_facets( dead_point, dead_facets );
247 : :
248 : : // Get edges to update
249 [ # # ][ # # ]: 0 : DLIList<CubitFacetEdge*> adj_edge_list;
250 [ # # ]: 0 : dead_point->edges(adj_edge_list);
251 : :
252 : : // Get edge to collapse
253 : 0 : CubitFacetEdge* collapse = 0;
254 [ # # ][ # # ]: 0 : for ( i = adj_edge_list.size(); i-- && !collapse; )
[ # # ][ # # ]
255 [ # # ][ # # ]: 0 : if (adj_edge_list.step_and_get()->other_point(dead_point) == this)
[ # # ]
256 [ # # ]: 0 : collapse = adj_edge_list.extract();
257 : :
258 : : // For each dead facet...
259 : : CubitFacetData *dead_facet, *edge_facet;
260 : : CubitFacetEdgeData *keep_edge, *dead_edge;
261 [ # # ][ # # ]: 0 : for ( i = dead_facets.size(); i--; )
262 : : {
263 : : // Get dead facet and relevant indices
264 [ # # ][ # # ]: 0 : dead_facet = dynamic_cast<CubitFacetData*>(dead_facets.get_and_step());
265 [ # # ]: 0 : assert(!!dead_facet);
266 [ # # ]: 0 : int dead_pt_index = dead_facet->point_index(dead_point);
267 [ # # ]: 0 : int this_pt_index = dead_facet->point_index(this);
268 : 0 : int other_pt_index = 3 - dead_pt_index - this_pt_index;
269 : :
270 : : // The get the other point (facet should have
271 : : // this point, the dead point, and one other).
272 [ # # ]: 0 : CubitPoint* other_pt = dead_facet->point(other_pt_index);
273 : :
274 : : // Get the edges to merge
275 [ # # ][ # # ]: 0 : dead_edge = dynamic_cast<CubitFacetEdgeData*>(dead_facet->edge(this_pt_index));
276 [ # # ][ # # ]: 0 : keep_edge = dynamic_cast<CubitFacetEdgeData*>(dead_facet->edge(dead_pt_index));
277 [ # # ]: 0 : edge_facets.clean_out();
278 : :
279 : : //propagate all the tds from dead edge to keep edge
280 [ # # ]: 0 : DLIList<ToolData*> tds;
281 [ # # ]: 0 : dead_edge->get_all_TDs(&tds);
282 [ # # ][ # # ]: 0 : for (int i=0; i<tds.size(); i++)
283 : : {
284 [ # # ][ # # ]: 0 : ToolData* new_td = tds.get_and_step()->propogate(keep_edge);
285 [ # # ]: 0 : if (new_td)
286 [ # # ]: 0 : keep_edge->add_TD(new_td);
287 : : }
288 : :
289 : : // Get the list of adjacent facets to be updated
290 [ # # ]: 0 : dead_point->shared_facets(other_pt, edge_facets);
291 : :
292 : : // Determine relative sense of edges
293 [ # # ]: 0 : int dead_edge_pt = dead_edge->point(0) == other_pt ? 0 : 1;
294 [ # # ][ # # ]: 0 : int rel_edge_sense = keep_edge->point(dead_edge_pt) == other_pt ? 1 : -1;
295 : :
296 : : // Update edge in each adjacent facet (merge keep_edge with dead_edge)
297 [ # # ][ # # ]: 0 : for ( j = edge_facets.size(); j--; )
298 : : {
299 [ # # ][ # # ]: 0 : edge_facet = dynamic_cast<CubitFacetData*>(edge_facets.get_and_step());
300 [ # # ]: 0 : if ( edge_facet == dead_facet )
301 : 0 : continue;
302 : :
303 [ # # ]: 0 : int dead_index = edge_facet->point_index(dead_point);
304 : 0 : int edge_index = (dead_index+1) % 3;
305 [ # # ][ # # ]: 0 : if ( edge_facet->point(edge_index) == other_pt )
306 : 0 : edge_index = (dead_index+2) % 3;
307 : :
308 [ # # ]: 0 : if ( dead_edge )
309 : : {
310 [ # # ][ # # ]: 0 : assert(edge_facet->edge(edge_index) == dead_edge);
311 [ # # ]: 0 : dead_edge->remove_facet(edge_facet);
312 [ # # ]: 0 : edge_facet->edge( 0, edge_index );
313 : : }
314 [ # # ]: 0 : if ( keep_edge )
315 : : {
316 [ # # ][ # # ]: 0 : assert(edge_facet->edge(edge_index) == 0);
317 [ # # ]: 0 : keep_edge->add_facet(edge_facet);
318 [ # # ]: 0 : edge_facet->edge( keep_edge, edge_index );
319 [ # # ]: 0 : int use = rel_edge_sense * edge_facet->edge_use(edge_index);
320 [ # # ]: 0 : edge_facet->edge_use( use, edge_index );
321 : : }
322 : : }
323 : :
324 : : // delete dead entities
325 : :
326 [ # # ][ # # ]: 0 : delete dead_facet;
327 : :
328 [ # # ]: 0 : if (dead_edge)
329 : : {
330 [ # # ][ # # ]: 0 : assert(dead_edge->num_adj_facets() == 0);
331 : :
332 [ # # ]: 0 : adj_edge_list.move_to(dead_edge);
333 [ # # ][ # # ]: 0 : assert(adj_edge_list.get() == dead_edge);
334 [ # # ]: 0 : adj_edge_list.extract();
335 : :
336 [ # # ][ # # ]: 0 : delete dead_edge;
337 : : }
338 [ # # ]: 0 : }
339 : :
340 [ # # ][ # # ]: 0 : while (adj_edge_list.size())
341 : : {
342 [ # # ][ # # ]: 0 : keep_edge = dynamic_cast<CubitFacetEdgeData*>(adj_edge_list.pop());
343 [ # # ]: 0 : assert(!!keep_edge);
344 [ # # ][ # # ]: 0 : if (keep_edge->point(0) == dead_point)
345 [ # # ]: 0 : keep_edge->set_point(this, 0);
346 [ # # ][ # # ]: 0 : else if(keep_edge->point(1) == dead_point)
347 [ # # ]: 0 : keep_edge->set_point(this, 1);
348 : : else
349 : 0 : assert(0);
350 : : }
351 : :
352 [ # # ][ # # ]: 0 : DLIList<CubitFacet*> adj_facet_list(dead_point->num_adj_facets());
[ # # ]
353 [ # # ]: 0 : dead_point->facets(adj_facet_list);
354 [ # # ][ # # ]: 0 : while (adj_facet_list.size())
355 : : {
356 [ # # ][ # # ]: 0 : CubitFacetData* facet = dynamic_cast<CubitFacetData*>(adj_facet_list.pop());
357 [ # # ]: 0 : assert(!!facet);
358 : :
359 [ # # ]: 0 : int index = facet->point_index(dead_point);
360 [ # # ][ # # ]: 0 : assert((unsigned)index < (unsigned)3 && facet->point(index) == dead_point);
[ # # ]
361 : :
362 [ # # ]: 0 : dead_point->remove_facet(facet);
363 [ # # ]: 0 : this->add_facet(facet);
364 [ # # ]: 0 : facet->set_point( this, index );
365 : : }
366 : :
367 : :
368 : : // delete dead entities
369 [ # # ]: 0 : if ( collapse )
370 : : {
371 [ # # ][ # # ]: 0 : assert( collapse->num_adj_facets() == 0 );
372 [ # # ][ # # ]: 0 : delete collapse;
373 : : }
374 : :
375 [ # # ][ # # ]: 0 : assert( dead_point->num_adj_facets() == 0 );
376 [ # # ][ # # ]: 0 : delete dead_point;
377 : :
378 [ # # ]: 0 : return CUBIT_SUCCESS;
379 : : }
380 : :
381 : :
|