1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#include "RemoveBlends.hpp"
#include "CubitUtil.hpp"
//#include "Model.hpp"
#include "GeometryQueryTool.hpp"

//#include "SVDrawTool.hpp"
#include "GMem.hpp"
#include "GfxDebug.hpp"

#include "VirtualQueryEngine.hpp"
#include "PartitionEngine.hpp"


#include "CompositeTool.hpp"
#include "PartitionTool.hpp"
#include "PartSurfFacetTool.hpp"

#include "RefFace.hpp"
#include "RefEdge.hpp"
#include "RefVertex.hpp"

#include "CompositeLump.hpp"
#include "PartitionCurve.hpp"
#include "SubSurface.hpp"
#include "SplitSurfaceTool.hpp"

namespace RemoveBlends
{
CubitStatus remove_blend(RefFace* ref_face,<--- The function 'remove_blend' is never used.
                                          DLIList<CubitVector>& locations,
                                          DLIList<RefFace*>& composite_faces)
{
   CubitStatus result = CUBIT_SUCCESS;
   int i;

   locations.reset();
   RefFace* the_face = ref_face;
   if (the_face && VirtualQueryEngine::is_virtual(the_face))
   {
      PRINT_WARNING ("Can not collapse a virtual surface.\n");
      return CUBIT_FAILURE;
   }

   // Find the curve to split along.
   SplitSurfaceTool                sst;
   DLIList<DLIList<CubitVector*>*> vec_lists;
   DLIList<Curve*>                 curve_list;

   DLIList<CubitVector*> *vec_list = new DLIList<CubitVector*>;

   vec_list->append( new CubitVector( locations.get_and_step() ) );
   vec_list->append( new CubitVector( locations.get_and_step() ) );

   vec_lists.append( vec_list );

   sst.calculate_split_curves(the_face, vec_lists, curve_list);

   //int num_segs = 2; 
   //double fraction =.5;
   //double distance = -1.;
   //RefEdge* from_curve_ptr = 0;
   //DLIList<RefVertex*> corner_vertex_list;
   //DLIList<RefVertex*> through_vertex_list;
   //RefEdge *curve_dir_ptr = 0;
   //CubitBoolean preview_flg = false;
   //CubitBoolean create_ref_edges_flg = false;
   //CubitBoolean just_curves_flg = false;
   //DLIList<DLIList<Curve*>*> curve_lists_list; 

//   sst.calculate_split_curves(ref_face_list, num_segs, fraction, distance, 
//                          from_curve_ptr, corner_vertex_list, through_vertex_list,
//                          curve_dir_ptr,
//                          preview_flg, create_ref_edges_flg, just_curves_flg,
//                          curve_lists_list ); 

   //partition the_face
   DLIList<RefEdge*> new_edges;
   DLIList<RefFace*> result_faces;
   result = PartitionTool::instance()->
          partition_face_by_curves( the_face, curve_list, result_faces, CUBIT_TRUE, &new_edges );
   // clean up curves
   while (curve_list.size())
   {
     Curve* curve = curve_list.pop();
     if (curve)
     {
       GeometryQueryEngine* gqe = curve->get_geometry_query_engine();
       gqe->delete_solid_model_entities(curve);
     }
   }
   if( result == CUBIT_FAILURE )
   {
      PRINT_ERROR("Failed to partition surface %d into 2 distinct pieces\n", the_face->id());
      return result;
   }

   // We MUST clean up an ambiguous partition.
   if (new_edges.size() > 1)
   {
      PRINT_ERROR("Attempted to partition surface %d more than 2 parts,\n"
                    "Ambiguous surface collapse. Collapse failed.\n",
                    the_face->id());
      DLIList<RefFace*> orig_faces;
      PartitionTool::instance()->unpartitionAll(result_faces, orig_faces);
      
      DLIList<RefEdge*> edges, edge_results;
      edges.clean_out();
      // We started out with one face, we should the same face back
      assert( the_face == orig_faces.next(0) );
      the_face->ref_edges( edges );

      // Do a quick sort to find the PartitionCurves
      for ( i = edges.size(); i--; ) 
      {
        if ( !dynamic_cast<PartitionCurve*>(edges.step_and_get()->get_curve_ptr()))
          edges.change_to(0);
      }
      edges.remove_all_with_value(0);

      // Now remove the partitioned edges
      // TODO: what if we are collapsing with an adjacent partitioned surface.
      // What happens to the partitioned edges?
      if ( edges.size() )
        PartitionTool::instance()->unpartitionAll(edges, edge_results);

      return CUBIT_FAILURE;
   }

   if (result_faces.size() < 2)
   {
      PRINT_WARNING("Surface %d has been improperly partitioned,\n"
                    "Ambiguous surface collapse. Collapse failed.\n",
                    the_face->id());
      return result;
   }
 
   //if(new_face == the_face)
   //   new_face = GeometryQueryTool::instance()->get_last_ref_face ();   

   new_edges.clean_out();
   //Re-composite surfaces
   DLIList<RefFace*> composite_result_faces;
   DLIList<RefFace*> remaining_faces;
   DLIList<RefFace*> surf_list;
   DLIList<int> id_list;
   RefFace*  face_to_composite = NULL;
   RefFace*  temp_face = NULL;
   RefFace*  second_face = NULL;
   RefFace*  composite_face = NULL;
   int  num_common_edge1, num_common_edge2;
   int  size;
   int  composite_count = 0;
   while (0 < (composite_faces.size() + remaining_faces.size()))
   {
      if(composite_count == 2)
        break;

      size = composite_faces.size();
      if( size > 0)
      {
        composite_faces.reset();
        face_to_composite = composite_faces.get();
        composite_faces.remove(face_to_composite);
      }

      else
      {
        remaining_faces.reset();
        face_to_composite = remaining_faces.get();
        remaining_faces.remove(face_to_composite);
      }
      
      if (NULL != second_face)
      {
         num_common_edge1 = second_face->common_ref_edges(face_to_composite,
                                                       new_edges); 
         new_edges.clean_out();
         if (num_common_edge1 == 0)
           continue;
         
         if (NULL == composite_face)
           num_common_edge2 = 0;
         else
           num_common_edge2 = composite_face->
                   common_ref_edges(face_to_composite, new_edges);
         new_edges.clean_out();
      }

      else 
      {
         if (NULL == result_faces[0])
           num_common_edge1 = 0;
         else 
         {
            num_common_edge1 = result_faces[0]->common_ref_edges(face_to_composite, 
                                                       new_edges);  
            new_edges.clean_out();
         }

         if(NULL == result_faces[1])
            num_common_edge2 = 0;
         else
         {
            num_common_edge2 = result_faces[1]->common_ref_edges(face_to_composite,
                                                          new_edges);
            new_edges.clean_out();
         }
      }

      if (num_common_edge1 == 0 && num_common_edge2 == 0)
         continue;

      else if(num_common_edge1 == 0 || num_common_edge2 == 0 || size == 0)
      {  
         surf_list.clean_out();
         if (NULL != second_face)
            surf_list.append(second_face);

         else if (num_common_edge2 == 0 || size == 0)        
         {
            temp_face = result_faces[0];
            second_face = result_faces[1];
            surf_list.append(temp_face);
         }

         else
         {
            temp_face = result_faces[1];
            second_face = result_faces[0];
            surf_list.append(temp_face);
         }
         surf_list.append(face_to_composite);
     
         // composite the surfaces together
         CompositeTool::instance()->composite(surf_list, composite_result_faces);
         composite_count++;

         if( composite_result_faces.size() > 0 )
         {
            DLIList<RefEdge*> surface_edges, new_edge_list;
            remaining_faces.clean_out();
            for(  i = 0; i < composite_result_faces.size(); i++)
            {
               // now composite together the edges of the new surface
               surface_edges.clean_out();
               composite_result_faces.get_and_step()->ref_edges( surface_edges );
               new_edge_list.clean_out();
               CompositeTool::instance()->composite( surface_edges, new_edge_list);

               // keep the lists coherent
               composite_face = composite_result_faces.pop();
               composite_faces.remove(composite_face);
               id_list.append( composite_face->id() );
            }
         }
                                                           
         else
            PRINT_ERROR("Composite surface %d and surface %d failed.\n",
                temp_face->id(), face_to_composite->id());
      }

      else 
         remaining_faces.append(face_to_composite);      
   }
   if (id_list.size() > 0)
      CubitUtil::list_entity_ids("Created composite surfaces ", id_list );
   return result;
}

CubitStatus remove_blends(DLIList<RefFace*>& ref_face_list,<--- The function 'remove_blends' is never used.
                                        int num_segs, double fraction, double distance,
                                        RefEdge* from_curve_ptr,
                                        DLIList<RefVertex*>& corner_vertex_list,
                                        DLIList<RefVertex*>& through_vertex_list,
                                        RefEdge *curve_dir_ptr,
                                        CubitBoolean preview_flg,
                                        DLIList<CubitVector*>& locations,
                                        DLIList<RefFace*>& composite_faces)
{
   CubitStatus result = CUBIT_SUCCESS;
   int i;

   if (ref_face_list.size() <= 1)
   {
      PRINT_WARNING ("Must specify a chain of surfaces.\n");
      return CUBIT_FAILURE;
   }
   locations.reset();

   // check and make sure that we aren't splitting virtual surfaces (yet)
   for (i = 0; i < ref_face_list.size(); i++)
   {
     RefFace* the_face = ref_face_list.get_and_step();
     if (the_face && VirtualQueryEngine::is_virtual(the_face))
     {
        PRINT_WARNING ("Can not collapse a virtual surface.\n");
        return CUBIT_FAILURE;
     }
   }

   // Find the curve to split along.
   SplitSurfaceTool                sst;
   DLIList<DLIList<CubitVector*>*> vec_lists;
   DLIList<Curve*>*                curve_list;
   DLIList<DLIList<Curve*>*> curve_lists_list; 

   DLIList<CubitVector*> *vec_list = new DLIList<CubitVector*>;

   vec_list->append( new CubitVector( *locations.get_and_step() ) );
   vec_list->append( new CubitVector( *locations.get_and_step() ) );

   vec_lists.append( vec_list );

   CubitBoolean create_ref_edges_flg = false;
   CubitBoolean just_curves_flg = false;

   sst.calculate_split_curves(ref_face_list, num_segs, fraction, distance, 
                          from_curve_ptr, corner_vertex_list, through_vertex_list,
                          curve_dir_ptr,
                          preview_flg, create_ref_edges_flg, just_curves_flg,
                          curve_lists_list ); 

   //partition the_face
   DLIList<RefEdge*> new_edges;
   DLIList<RefFace*> result_faces;
   RefFace* the_face;
   DLIList<int> id_list;

   for (i = 0; i < ref_face_list.size(); i++)
   {
     // get the face and the curves that split this face
     the_face = ref_face_list.get_and_step();
     curve_list = curve_lists_list.get_and_step();

     result = PartitionTool::instance()->
            partition_face_by_curves( the_face, *curve_list, result_faces, CUBIT_FALSE, &new_edges );
     if( result == CUBIT_FAILURE )
        return result;

     if (new_edges.size() > 1)
     {
        PRINT_WARNING("Surface %d has been partitioned into more than 2 parts,\n"
                      "Ambiguous surface collapse.\n",
                      the_face->id());
        return result;
     }
 
     new_edges.clean_out();
     //Re-composite surfaces
     DLIList<RefFace*> composite_result_faces;
     DLIList<RefFace*> remaining_faces;
     DLIList<RefFace*> surf_list;
     RefFace*  face_to_composite = NULL;
     RefFace*  temp_face = NULL;
     RefFace*  second_face = NULL;
     RefFace*  composite_face = NULL;
     int  num_common_edge1, num_common_edge2;
     int  size;
     int  composite_count = 0;
     while (0 < (composite_faces.size() + remaining_faces.size()))
     {
        if(composite_count == 2)
          break;

        size = composite_faces.size();
        if( size > 0)
        {
          composite_faces.reset();
          face_to_composite = composite_faces.get();
          composite_faces.remove(face_to_composite);
        }
        else
        {
          remaining_faces.reset();
          face_to_composite = remaining_faces.get();
          remaining_faces.remove(face_to_composite);
        }
        
        if (NULL != second_face)
        {
           num_common_edge1 = second_face->common_ref_edges(face_to_composite,
                                                         new_edges); 
           new_edges.clean_out();
           if (num_common_edge1 == 0)
             continue;
           
           if (NULL == composite_face)
             num_common_edge2 = 0;
           else
             num_common_edge2 = composite_face->
                     common_ref_edges(face_to_composite, new_edges);
           new_edges.clean_out();
        }
        else 
        {
           if (NULL == result_faces[0])
             num_common_edge1 = 0;
           else 
           {
              num_common_edge1 = result_faces[0]->common_ref_edges(face_to_composite, 
                                                         new_edges);  
              new_edges.clean_out();
           }

           if(NULL == result_faces[1])
              num_common_edge2 = 0;
           else
           {
              num_common_edge2 = result_faces[1]->common_ref_edges(face_to_composite,
                                                            new_edges);
              new_edges.clean_out();
           }
        }

        if (num_common_edge1 == 0 && num_common_edge2 == 0)
           continue;

        else if(num_common_edge1 == 0 || num_common_edge2 == 0 || size == 0)
        {  
           surf_list.clean_out();
           if (NULL != second_face)
              surf_list.append(second_face);

           else if (num_common_edge2 == 0 || size == 0)        
           {
              temp_face = result_faces[0];
              second_face = result_faces[1];
              surf_list.append(temp_face);
           }

           else
           {
              temp_face = result_faces[1];
              second_face = result_faces[0];
              surf_list.append(temp_face);
           }
           surf_list.append(face_to_composite);
       
           // composite the surfaces together
           CompositeTool::instance()->composite(surf_list, composite_result_faces);
           composite_count++;

           if( composite_result_faces.size() > 0 )
           {
              DLIList<RefEdge*> surface_edges, new_edge_list;
              remaining_faces.clean_out();
              for(  i = 0; i < composite_result_faces.size(); i++)
              {
                 // now composite together the edges of the new surface
                 surface_edges.clean_out();
                 composite_result_faces.get_and_step()->ref_edges( surface_edges );
                 new_edge_list.clean_out();
                 CompositeTool::instance()->composite( surface_edges, new_edge_list);

                 // keep the lists coherent
                 composite_face = composite_result_faces.pop();
                 composite_faces.remove(composite_face);
                 id_list.append( composite_face->id() );
              }
           }
           PRINT_ERROR("Composite surface %d and surface %d failed.\n",
                temp_face->id(), face_to_composite->id());
       }
     }
   }
   if (id_list.size() > 0)
      CubitUtil::list_entity_ids("Created composite surfaces ", id_list );
   return result;
}
} // namespace RemoveBlends