cgma
VirtualImprintTool.cpp
Go to the documentation of this file.
00001 //------------------------------------------------------------------
00002 //Class: VirtualImprintTool
00003 //Description: Provides functionality and interface to imprinting
00004 //             topology through virtual geometry and faceted booleans.
00005 //Author:  David R. White
00006 //Date: 2/15/2002
00007 //------------------------------------------------------------------
00008 
00009 #include "VirtualImprintTool.hpp"
00010 #include "RefFace.hpp"
00011 #include "RefVolume.hpp"
00012 #include "CubitMessage.hpp"
00013 #include "CubitBox.hpp"
00014 #include "RTree.hpp"
00015 #include "ImprintBoundaryTool.hpp"
00016 #include "AppUtil.hpp"
00017 
00018 CubitBoolean VirtualImprintTool::useRealIntersection = CUBIT_FALSE;
00019 
00020 //-------------------------------------------------------------------
00021 // Constructor
00022 //-------------------------------------------------------------------
00023 VirtualImprintTool::VirtualImprintTool()
00024 {
00025 }
00026 //-------------------------------------------------------------------
00027 // Destructor
00028 //-------------------------------------------------------------------
00029 VirtualImprintTool::~VirtualImprintTool()
00030 {}
00031 
00032 //--------------------------------------------------------------------
00033 // virtual_imprint
00034 //  Does the imprinting between two surfaces...
00035 //--------------------------------------------------------------------
00036 CubitStatus VirtualImprintTool::virtual_imprint(RefFace *ref_face1,
00037                                                 RefFace *ref_face2,
00038                                                 DLIList <RefFace*> &results,
00039                                                 double feature_size,
00040                                                 CubitBoolean &curves_modified)
00041 {
00042   if ( useRealIntersection )
00043   {
00044 /*    SurfaceImprintTool imp_tool(feature_size);
00045     CubitStatus stat = imp_tool.imprint_surface(ref_face1, ref_face2, results);
00046     if (stat != CUBIT_SUCCESS )
00047       return stat;
00048     curves_modified = imp_tool.curves_modified();
00049     return CUBIT_SUCCESS;
00050 */
00051     return CUBIT_FAILURE;
00052   }
00053   else
00054   {
00055     ImprintBoundaryTool ib_tool(ref_face1, ref_face2, feature_size);
00056     CubitStatus stat=ib_tool.imprint(results, CUBIT_FALSE);
00057     if (stat != CUBIT_SUCCESS )
00058       return stat;
00059     if ( ib_tool.modified_bound_1() || ib_tool.modified_bound_2() )
00060       curves_modified = CUBIT_TRUE;
00061     return CUBIT_SUCCESS;
00062   }
00063 }
00064 //--------------------------------------------------------------------
00065 // virtual_imprint
00066 //  Does the imprinting between multiple surfaces
00067 //--------------------------------------------------------------------
00068 CubitStatus VirtualImprintTool::virtual_imprint(DLIList <RefFace*> &input_faces,
00069                                                 DLIList <RefFace*> &surf_results,
00070                                                 double feature_size,
00071                                                 CubitBoolean &curves_modified)
00072 {
00073   int ii, jj;
00074     //Do the n^2 thing, imprint every volume against every other volume...
00075   DLIList <RefFace*> faces_stack = input_faces, ref_faces_close, tmp_results;
00076   RefFace *curr_face, *canidate_face;
00077   while ( faces_stack.size() > 0 )
00078   {
00079     curr_face = faces_stack.pop();
00080     curr_face->marked(1);
00081     ref_faces_close.clean_out();
00082     CubitBox curr_box = curr_face->bounding_box();
00083     for ( jj = input_faces.size(); jj > 0; jj-- )
00084     {
00085       canidate_face = input_faces.get_and_step();
00086       if ( canidate_face == curr_face || canidate_face->marked() )
00087         continue;
00088       CubitBox canidate_box = canidate_face->bounding_box();
00089       if ( curr_box.overlap(feature_size, canidate_box) )
00090         ref_faces_close.append(canidate_face);
00091     }
00092     for ( jj = ref_faces_close.size(); jj > 0; jj-- )
00093     {
00094         //check for interrupt.
00095       if ( AppUtil::instance()->interrupt() )
00096       {
00097         break;
00098       }
00099       
00100       tmp_results.clean_out();
00101       canidate_face = ref_faces_close.get_and_step();
00102       PRINT_INFO("Imprint Surfaces: %d %d\n", curr_face->id(), canidate_face->id() );
00103       CubitStatus stat = virtual_imprint(curr_face, canidate_face,
00104                                          tmp_results, feature_size,
00105                                          curves_modified);
00106       if ( stat != CUBIT_SUCCESS )
00107       {
00108         PRINT_ERROR("Problems imprinting Surface %d and %d\n",
00109                     curr_face->id(), canidate_face->id());
00110         return stat;
00111       }
00112       if ( tmp_results.size() )
00113       {
00114         faces_stack.remove(canidate_face);
00115         input_faces.remove(curr_face);
00116         input_faces.remove(canidate_face);
00117         int ll;
00118         for ( ll = tmp_results.size(); ll > 0; ll-- )
00119         {
00120           canidate_face = tmp_results.get_and_step();
00121           canidate_face->marked(0);
00122           faces_stack.append(canidate_face);
00123           input_faces.append(canidate_face);
00124         }
00125         surf_results += tmp_results;
00126         break;
00127       }
00128     }
00129       //check for interrupt.
00130     if ( AppUtil::instance()->interrupt() )
00131     {
00132         //just break out and still clean up marks and stuff...
00133       break;
00134     }
00135   }
00136   for ( ii = 0; ii < surf_results.size(); ii++ )
00137     surf_results.get_and_step()->marked(0);
00138   DLIList <RefFace*> tmp_list;
00139   for ( ii = 0; ii < surf_results.size(); ii++ )
00140   {
00141     curr_face = surf_results.get_and_step();
00142     if ( curr_face->marked() )
00143       continue;
00144     else
00145     {
00146       tmp_list.append(curr_face);
00147       curr_face->marked(1);
00148     }
00149   }
00150   surf_results.clean_out();
00151   for ( ii = 0; ii < tmp_list.size(); ii++ )
00152   {
00153     curr_face = tmp_list.get_and_step();
00154     curr_face->marked(0);
00155     surf_results.append(curr_face);
00156   }
00157   return CUBIT_SUCCESS;
00158 }
00159 
00160 
00161 CubitStatus VirtualImprintTool::virtual_imprint(RefVolume *ref_volume1,
00162                                                 RefVolume *ref_volume2,
00163                                                 DLIList <RefVolume*> &vol_results,
00164                                                 double feature_size,
00165                                                 CubitBoolean &curves_modified)
00166 {
00167   CubitBoolean ref_1_mod=CUBIT_FALSE, ref_2_mod = CUBIT_FALSE;
00168   curves_modified = CUBIT_FALSE;
00169     //First make sure the bounding boxes are close...
00170   CubitBox ref_vol1_box = ref_volume1->bounding_box();
00171   CubitBox ref_vol2_box = ref_volume2->bounding_box();
00172   if ( !ref_vol1_box.overlap(feature_size, ref_vol2_box) )
00173     return CUBIT_SUCCESS;
00174 
00175     //Now get the list of surfaces for imprinting.
00176   DLIList <RefFace*> ref_faces1, ref_faces2, ref_faces_close;
00177   DLIList <RefFace*> faces1_stack, tmp_faces1,tmp_faces2, tmp_output;
00178   DLIList <RefVolume*> tmp_vols;
00179   RefFace *curr_ref_face, *canidate_ref_face;
00180   ref_volume1->ref_faces(ref_faces1);
00181   ref_volume2->ref_faces(ref_faces2);
00182   int ii, jj;
00183   CubitStatus stat;
00184     //loop over the the ref_faces from the first list.
00185     //Get all the reffaces that are within tolerance of its
00186     //bounding box.
00187   for ( ii = ref_faces1.size(); ii > 0; ii-- )
00188   {
00189     curr_ref_face = ref_faces1.get_and_step();
00190     CubitBox curr_box = curr_ref_face->bounding_box();
00191     ref_faces_close.clean_out();
00192     //do this everytime to get the most up-to-date ones...
00193     ref_faces2.clean_out();
00194     ref_volume2->ref_faces(ref_faces2);
00195     for ( jj = ref_faces2.size(); jj > 0; jj-- )
00196     {
00197       canidate_ref_face = ref_faces2.get_and_step();
00198       CubitBox canidate_box = canidate_ref_face->bounding_box();
00199       if ( curr_box.overlap(feature_size, canidate_box) )
00200         ref_faces_close.append(canidate_ref_face);
00201     }
00202       //Now imprint the faces that are close with the curr_ref_face.
00203     faces1_stack.clean_out();
00204     faces1_stack.append( curr_ref_face);
00205     while( faces1_stack.size() && (curr_ref_face = faces1_stack.pop()) != NULL &&
00206            ref_faces_close.size() > 0 )
00207     {
00208       if ( AppUtil::instance()->interrupt() )
00209       {
00210           //just break out and still clean up marks and stuff...
00211         break;
00212       }
00213       while (ref_faces_close.size() && (canidate_ref_face = ref_faces_close.pop()) != NULL )
00214       {
00215         tmp_output.clean_out();
00216         stat = virtual_imprint(curr_ref_face,canidate_ref_face,
00217                                tmp_output, feature_size, curves_modified );
00218         if ( stat != CUBIT_SUCCESS )
00219           return stat;
00220           //check for interrupt.
00221         if ( AppUtil::instance()->interrupt() )
00222         {
00223             //just break out and still clean up marks and stuff...
00224           break;
00225         }
00226         //Now sort the faces in tmp_output into two lists associated
00227         //with the owning volumes...
00228         for ( jj = tmp_output.size(); jj > 0;jj-- )
00229         {
00230           RefFace *ref_face = tmp_output.get_and_step();
00231           tmp_vols.clean_out();
00232           ref_face->ref_volumes(tmp_vols);
00233           if ( tmp_vols.move_to(ref_volume1) )
00234           {
00235             ref_1_mod = CUBIT_TRUE;
00236             tmp_faces1.append(ref_face);
00237           }
00238           else
00239           {
00240             ref_2_mod = CUBIT_TRUE;
00241             tmp_faces2.append(ref_face);
00242           }
00243         }
00244         if ( tmp_faces1.size() > 0 )
00245           break;
00246       }
00247       faces1_stack += tmp_faces1;
00248       ref_faces_close += tmp_faces2;
00249       tmp_faces1.clean_out();
00250       tmp_faces2.clean_out();
00251     }
00252     if ( AppUtil::instance()->interrupt() )
00253     {
00254         //just break out and still clean up marks and stuff...
00255       break;
00256     }
00257   }
00258   if ( ref_1_mod )
00259     vol_results.append(ref_volume1);
00260   if ( ref_2_mod )
00261     vol_results.append(ref_volume2);
00262     
00263   return CUBIT_SUCCESS;
00264 }
00265 CubitStatus VirtualImprintTool::virtual_imprint(DLIList <RefVolume*> &input_vols,
00266                                                 DLIList <RefVolume*> &vol_results,
00267                                                 double feature_size,
00268                                                 CubitBoolean &curves_modified)
00269 {
00270   int ii, jj;
00271     //Do the n^2 thing, imprint every volume against every other volume...
00272   DLIList <RefVolume*> marked_vols;
00273   DLIList <RefVolume*> vols_stack = input_vols, ref_vols_close;
00274   RefVolume *curr_volume, *canidate_volume;
00275   while ( vols_stack.size() > 0 )
00276   {
00277     if ( AppUtil::instance()->interrupt() )
00278     {
00279         //just break out and still clean up marks and stuff...
00280       break;
00281     }
00282     curr_volume = vols_stack.pop();
00283     curr_volume->marked(1);
00284     marked_vols.append(curr_volume);
00285     ref_vols_close.clean_out();
00286     CubitBox curr_box = curr_volume->bounding_box();
00287     for ( jj = input_vols.size(); jj > 0; jj-- )
00288     {
00289       canidate_volume = input_vols.get_and_step();
00290       if ( canidate_volume == curr_volume || canidate_volume->marked() )
00291         continue;
00292       CubitBox canidate_box = canidate_volume->bounding_box();
00293       if ( curr_box.overlap(feature_size, canidate_box) )
00294         ref_vols_close.append(canidate_volume);
00295     }
00296     for ( jj = ref_vols_close.size(); jj > 0; jj-- )
00297     {
00298       if ( AppUtil::instance()->interrupt() )
00299       {
00300           //just break out and still clean up marks and stuff...
00301         break;
00302       }
00303       canidate_volume = ref_vols_close.get_and_step();
00304       PRINT_INFO("Imprint Volumes: %d %d\n", curr_volume->id(), canidate_volume->id() );
00305       CubitStatus stat = virtual_imprint(curr_volume, canidate_volume,
00306                                          vol_results, feature_size,
00307                                          curves_modified);
00308       if ( stat != CUBIT_SUCCESS )
00309       {
00310         PRINT_ERROR("Problems imprinting volume %d and %d\n",
00311                     curr_volume->id(), canidate_volume->id());
00312         return stat;
00313       }
00314     }
00315   }
00316   DLIList <RefVolume*> tmp_list;
00317   for ( ii = 0; ii < vol_results.size(); ii++ )
00318   {
00319     curr_volume = vol_results.get_and_step();
00320     if ( curr_volume->marked() )
00321       continue;
00322     else
00323     {
00324       tmp_list.append(curr_volume);
00325       curr_volume->marked(1);
00326       marked_vols.append(curr_volume);
00327     }
00328   }
00329   vol_results.clean_out();
00330   for ( ii = 0; ii < tmp_list.size(); ii++ )
00331   {
00332     curr_volume = tmp_list.get_and_step();
00333     vol_results.append(curr_volume);
00334   }
00335   for ( ii = 0; ii < marked_vols.size(); ii++ )
00336     marked_vols.get_and_step()->marked(0);
00337   return CUBIT_SUCCESS;
00338 }
00339 
00340     
00341         
00342                         
00343     
00344   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines