moab
uiQVDual.ui.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile$
00005   Language:  C++
00006   Date:      $Date$
00007   Version:   $Revision$
00008 
00009   Copyright 2004 Sandia Corporation.
00010   Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00011   license for use of this work by or on behalf of the
00012   U.S. Government. Redistribution and use in source and binary forms, with
00013   or without modification, are permitted provided that this Notice and any
00014   statement of authorship are reproduced on all copies.
00015 
00016 =========================================================================*/
00017 /****************************************************************************
00018 ** ui.h extension file, included from the uic-generated form implementation.
00019 **
00020 ** If you wish to add, delete or rename functions or slots use
00021 ** Qt Designer which will update this file, preserving your code. Create an
00022 ** init() function in place of a constructor, and a destroy() function in
00023 ** place of a destructor.
00024 *****************************************************************************/
00025 
00026 #include "assert.h"
00027 
00028 #include "vtkObjectFactory.h"
00029 #include "vtkUnstructuredGrid.h"
00030 #include "vtkMOABUtils.h"
00031 #include "moab/MeshTopoUtil.hpp"
00032 #include "vtkPolyDataMapper.h"
00033 #include "vtkDataSetMapper.h"
00034 #include "vtkActor.h"
00035 #include "vtkCamera.h"
00036 #include "vtkProperty.h"
00037 #include "vtkExtractEdges.h"
00038 #include "vtkTubeFilter.h"
00039 #include "vtkRenderer.h"
00040 #include "vtkExtractGeometry.h"
00041 #include "vtkPlane.h"
00042 #include <algorithm>
00043 
00044 void uiQVDual::fileNew()
00045 {
00046   resetDisplay();
00047   
00048   delete vtkMOABUtils::mbImpl;
00049   vtkMOABUtils::mbImpl = NULL;
00050   
00051   redrawDisplay();
00052 }
00053 
00054 
00055 void uiQVDual::fileOpen()
00056 {
00057   assert(NULL != vtkMOABUtils::mbImpl);
00058   QString filename = QFileDialog::getOpenFileName(
00059       QString::null,
00060       "Exodus files (*.g *.gen *.exoII);;Cub files (*.cub);;SLAC Netcdf files (*.ncdf);;All Files (*)", this
00061       );
00062   if(filename == QString::null)
00063     return;
00064 
00065   fileOpen(filename);
00066 }
00067 
00068 void uiQVDual::fileOpen( const QString &filename )
00069 {
00070   // create a MOAB vtk reader and pass responsibility to that
00071   vtkMOABReader *reader = vtkMOABReader::New();
00072   
00073   // if we already have a grid, make sure it's that reader's output too
00074   if (NULL != vtkMOABUtils::myUG) reader->SetOutput(vtkMOABUtils::myUG);
00075   
00076   reader->SetFileName(filename.ascii());
00077 
00078   // need to update here, in case we're doing something else which requires moab data
00079   reader->Update();
00080 
00081   vtkMOABUtils::assign_global_ids();
00082   
00083   vtkMOABUtils::update_display(reader->GetOutput());
00084   
00085     // compute dual, if requested
00086   if (computeDual)
00087     constructDual();
00088 
00089   this->updateMesh();
00090   
00091   lastOpened = filename;
00092 
00093   reader->Delete();
00094 }
00095 
00096 void uiQVDual::fileSave()
00097 {
00098   if (lastOpened == QString::null)
00099     fileSaveAs();
00100   else
00101     fileSaveAs(lastOpened);
00102 }
00103 
00104 
00105 void uiQVDual::fileSaveAs(const QString &filename)
00106 {
00107   if(filename == QString::null)
00108     return;
00109 
00110   resetDisplay();
00111   
00112   vtkMOABUtils::dualTool->delete_whole_dual();
00113 
00114   computeDual = false;
00115 
00116   vtkMOABUtils::assign_global_ids();
00117   
00118     // make a set to specify what gets saved
00119   MBEntityHandle save_set;
00120   MBErrorCode result = vtkMOABUtils::mbImpl->create_meshset(MESHSET_SET, save_set);
00121   if (MB_SUCCESS != result) return;
00122   MBRange hexes;
00123   result = vtkMOABUtils::mbImpl->get_entities_by_type(0, MBHEX, hexes);
00124   if (MB_SUCCESS != result) return;
00125   result = vtkMOABUtils::mbImpl->add_entities(save_set, hexes);
00126   if (MB_SUCCESS != result) return;
00127 
00128   vtkMOABUtils::mbImpl->write_file(filename.ascii(), NULL, NULL, &save_set, 1);
00129 
00130   redrawDisplay();
00131 }
00132 
00133 
00134 void uiQVDual::filePrint()
00135 {
00136   
00137 }
00138 
00139 
00140 void uiQVDual::fileExit()
00141 {
00142   qApp->exit();
00143 }
00144 
00145 
00146 void uiQVDual::helpIndex()
00147 {
00148   
00149 }
00150 
00151 
00152 void uiQVDual::helpContents()
00153 {
00154   
00155 }
00156 
00157 
00158 void uiQVDual::helpAbout()
00159 {
00160   
00161 }
00162 
00163 
00164 void uiQVDual::init()
00165 {
00166   // initialize vtk stuff
00167   vtkRenderer *ren = vtkRenderer::New();
00168 
00169   if (NULL == vtkWidget) {
00170     vtkWidget = new QVTKWidget( centralWidget(), "vtkWidget" );
00171     vtkWidget->setGeometry( QRect( 400, 10, 470, 569 ) );
00172     vtkWidget->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 5, 1, vtkWidget->sizePolicy().hasHeightForWidth() ) );
00173     vtkWidget->setMinimumSize( QSize( 0, 0 ) );
00174   }
00175   
00176   vtkWidget->GetRenderWindow()->AddRenderer(ren);
00177   
00178   // save the renderer
00179   vtkMOABUtils::init(NULL, ren);
00180   
00181   currentWin = 0;
00182 
00183   cropToolPopup = NULL;
00184 
00185   computeDual = false;
00186 
00187   if (NULL == vtkMOABUtils::drawDual) 
00188     vtkMOABUtils::drawDual = new DrawDual(pickline1, pickline2);
00189 }
00190 
00191 
00192 void uiQVDual::destroy()
00193 {
00194   vtkMOABUtils::destroy();
00195 }
00196 
00197 
00198 
00199 void uiQVDual::constructDual()
00200 {
00201   // tell MOAB to construct the dual first
00202   MBErrorCode result = vtkMOABUtils::dualTool->construct_hex_dual(NULL, 0);
00203 
00204   redrawDisplay();
00205   
00206   QListViewItemIterator it = QListViewItemIterator(TagListView1);
00207   while ( it.current() ) {
00208     QString this_name((*it)->text(0));
00209     
00210     if (this_name == "DUAL_SURFACE") {
00211       (*it)->setOpen(true);
00212       break;
00213     }
00214 
00215     ++it;
00216   }
00217 
00218   MBRange sheet_sets;
00219   result = vtkMOABUtils::dualTool->get_dual_hyperplanes(vtkMOABUtils::mbImpl, 2, sheet_sets);
00220   if (MB_SUCCESS != result) return;
00221 
00222   if (!sheet_sets.empty()) {
00223       // draw the first sheet
00224     if (NULL == vtkMOABUtils::drawDual) vtkMOABUtils::drawDual = 
00225                                             new DrawDual(pickline1, pickline2);
00226     vtkMOABUtils::drawDual->draw_dual_surf(*sheet_sets.begin());
00227   }
00228 }
00229 
00230 void uiQVDual::updateMesh()
00231 {
00232   // mesh was updated; update the various UI elements
00233   this->updateTagList();
00234   this->updateActorList();
00235 }
00236 
00237 
00238 
00239 void uiQVDual::DebugButton_pressed()
00240 {
00241   vtkMOABUtils::print_debug();
00242 
00243 }
00244 
00245 
00246 void uiQVDual::updateTagList()
00247 {
00248   // clean the tag list view
00249   TagListView1->clear();    
00250   QListViewItemIterator it = QListViewItemIterator(TagListView1);
00251   while ( it.current() ) {
00252     itemSetMap.erase(*it);
00253     ++it;
00254   }
00255   
00256   // get a list of tags
00257   std::vector<MBTag> tag_handles;
00258   MBErrorCode result = vtkMOABUtils::mbImpl->tag_get_tags(tag_handles);
00259   if (MB_SUCCESS != result) return;
00260 
00261   // display each tag as a parent item
00262   QListViewItem *tags_item;
00263   
00264   for (std::vector<MBTag>::iterator tag_it = tag_handles.begin(); tag_it != tag_handles.end();
00265        tag_it++) {
00266     
00267     std::string tag_name;
00268     result = vtkMOABUtils::mbImpl->tag_get_name(*tag_it, tag_name);
00269     if (MB_SUCCESS != result) continue;
00270 
00271     // don't display tags with "__" prefix
00272     if (0 == strncmp(tag_name.c_str(), "__", 2))
00273       continue;
00274     
00275     // get all the sets which contain this tag
00276     MBRange tag_sets;
00277     result = vtkMOABUtils::mbImpl->get_entities_by_type_and_tag(
00278       0, MBENTITYSET, &(*tag_it), NULL, 1, tag_sets, MBInterface::UNION);
00279     if (MB_SUCCESS != result) continue;
00280 
00281     // create a parent tag item
00282     tags_item = new QListViewItem(TagListView1, tag_name.c_str());
00283     if (tag_name != "DUAL_SURFACE")
00284       tags_item->setOpen(false);
00285     else
00286       tags_item->setOpen(true);
00287 
00288     itemSetMap[tags_item] = 0;
00289 
00290     int i;
00291     MBRange::iterator set_it;
00292     QString set_id;
00293     QListViewItem *set_item;
00294     for (i = 0, set_it = tag_sets.begin(); set_it != tag_sets.end(); set_it++, i++) {
00295     // make an item for this set
00296       char set_name[CATEGORY_TAG_SIZE];
00297       result = vtkMOABUtils::get_set_category_name(*set_it, set_name);
00298       if (MB_SUCCESS != result) sprintf(set_name, "(none)\0");
00299       set_item = new QListViewItem(tags_item, set_name);
00300       itemSetMap[set_item] = *set_it;
00301     }
00302   }
00303 }
00304 
00305 
00306 void uiQVDual::updateActorList()
00307 {
00308     // clean the ActorView
00309   ActorListView1->clear();    
00310   QListViewItemIterator it = QListViewItemIterator(ActorListView1);
00311   while ( it.current() ) {
00312     itemSetMap.erase(*it);
00313     ++it;
00314   }
00315   
00316     // update "contains" view
00317   MBRange top_sets;
00318   QListViewItem *last_item;
00319   MBErrorCode result = vtkMOABUtils::get_top_contains_sets(top_sets);
00320   if (MB_SUCCESS == result && !top_sets.empty()) {
00321   
00322       // keep track of last actor line shown
00323     last_item = new QListViewItem(ActorListView1, "Contains Sets");
00324     itemSetMap[last_item] = 0;
00325     last_item->setOpen(false);
00326 
00327     for (MBRange::iterator rit = top_sets.begin(); rit != top_sets.end(); rit++)
00328       updateActorContainsList(last_item, *rit);
00329   }
00330   
00331     // update "parent/child" view
00332   top_sets.clear();
00333   result = vtkMOABUtils::get_top_parent_sets(top_sets);
00334   if (MB_SUCCESS == result && !top_sets.empty()) {
00335   
00336       // keep track of last actor line shown
00337     last_item = new QListViewItem(ActorListView1, "Parent/Child Sets");
00338     itemSetMap[last_item] = 0;
00339     last_item->setOpen(false);
00340 
00341     for (MBRange::iterator rit = top_sets.begin(); rit != top_sets.end(); rit++)
00342       updateActorParentList(last_item, *rit);
00343   }
00344 }
00345 
00346 
00347 
00348 void uiQVDual::ActorTreeView_selectionChanged()
00349 {
00350   currentWin = 1;
00351 
00352     // go through selected items, acting accordingly
00353   static std::set<QListViewItem*> high_items, unhigh_items, tmp_sel, tmp_unsel;
00354   high_items.clear(); unhigh_items.clear(); tmp_sel.clear(); tmp_unsel.clear();
00355   getSelected(ActorListView1, tmp_sel, tmp_unsel);
00356   // newly selected is difference between selected and itemSelList
00357   std::set_difference(tmp_sel.begin(), tmp_sel.end(),
00358                       itemSelList.begin(), itemSelList.end(),
00359                       std::inserter(high_items, high_items.begin()));
00360   
00361   // newly unselected is intersection between unselected and itemSelList
00362   std::set_intersection(tmp_unsel.begin(), tmp_unsel.end(),
00363                         itemSelList.begin(), itemSelList.end(),
00364                         std::inserter(unhigh_items, unhigh_items.begin()));
00365 
00366   if (!high_items.empty() || !unhigh_items.empty()) {
00367       // reset the properties of the items
00368     changeSetProperty(high_items, unhigh_items);
00369     
00370       // Re-render
00371     vtkWidget->GetRenderWindow()->Render();
00372   }
00373 }
00374 
00375 void uiQVDual::TagTreeView_selectionChanged()
00376 {
00377   currentWin = 2;
00378   
00379     // go through selected items, acting accordingly
00380   static std::set<QListViewItem*> high_items, unhigh_items, tmp_sel, tmp_unsel;
00381   high_items.clear(); unhigh_items.clear(); tmp_sel.clear(); tmp_unsel.clear();
00382   getSelected(TagListView1, tmp_sel, tmp_unsel);
00383   // newly selected is difference between selected and itemSelList
00384   std::set_difference(tmp_sel.begin(), tmp_sel.end(),
00385                       itemSelList.begin(), itemSelList.end(),
00386                       std::inserter(high_items, high_items.begin()));
00387   
00388   // newly unselected is intersection between unselected and itemSelList
00389   std::set_intersection(tmp_unsel.begin(), tmp_unsel.end(),
00390                         itemSelList.begin(), itemSelList.end(),
00391                         std::inserter(unhigh_items, unhigh_items.begin()));
00392   
00393   if (!high_items.empty() || !unhigh_items.empty()) {
00394       // reset the properties of the items
00395     changeSetProperty(high_items, unhigh_items);
00396     
00397       // Re-render
00398     vtkWidget->GetRenderWindow()->Render();
00399   }
00400 }
00401 
00402 void uiQVDual::updateActorContainsList( QListViewItem *item, MBEntityHandle set_handle )
00403 {
00404   vtkActor *set_actor;
00405   QListViewItem *set_item;
00406 
00407     // get the actor for this set
00408   MBErrorCode result = vtkMOABUtils::mbImpl->tag_get_data(vtkMOABUtils::vtkSetActorTag,
00409                                                           &set_handle, 1, &set_actor);
00410   if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) return;
00411   
00412   int num_sets;
00413   if (NULL == set_actor) {
00414       // no entities - check for contained sets, and if none, return
00415     result = vtkMOABUtils::mbImpl->get_number_entities_by_type(set_handle, MBENTITYSET,
00416                                                                num_sets);
00417     if (MB_SUCCESS != result || 0 == num_sets) return;
00418   }
00419   
00420     // has an actor, or contains sets; allocate a list item
00421   char set_name[CATEGORY_TAG_SIZE];
00422   vtkMOABUtils::get_set_category_name(set_handle, set_name);
00423   set_item = new QListViewItem(item, set_name);
00424   itemSetMap[set_item] = set_handle;
00425   set_item->setOpen(false);
00426 
00427   if (NULL == set_actor && 0 == num_sets) return;
00428   
00429     // get the list of sets in this set
00430   MBRange contained_sets;
00431   result = vtkMOABUtils::mbImpl->get_entities_by_type(set_handle, MBENTITYSET, 
00432                                                       contained_sets);
00433   if (MB_SUCCESS != result) return;
00434 
00435   for (MBRange::iterator rit = contained_sets.begin(); rit != contained_sets.end(); rit++)
00436     updateActorContainsList(set_item, *rit);
00437 }
00438 
00439 
00440 void uiQVDual::updateActorParentList( QListViewItem *item, MBEntityHandle set_handle )
00441 {
00442   vtkActor *set_actor;
00443   QListViewItem *set_item;
00444 
00445     // get the actor for this set
00446   MBErrorCode result = vtkMOABUtils::mbImpl->tag_get_data(vtkMOABUtils::vtkSetActorTag,
00447                                                           &set_handle, 1, &set_actor);
00448   if (MB_SUCCESS != result && MB_TAG_NOT_FOUND != result) return;
00449   
00450   int num_sets;
00451   if (NULL == set_actor) {
00452       // no entities - check for child sets, and if none, return
00453     result = vtkMOABUtils::mbImpl->num_child_meshsets(set_handle, &num_sets);
00454     if (MB_SUCCESS != result || 0 == num_sets) return;
00455   }
00456   
00457     // has an actor, or parent sets; allocate a list item
00458   char set_name[CATEGORY_TAG_SIZE];
00459   vtkMOABUtils::get_set_category_name(set_handle, set_name);
00460   set_item = new QListViewItem(item, set_name);
00461   itemSetMap[set_item] = set_handle;
00462   set_item->setOpen(false);
00463 
00464     // get the list of child sets
00465   if (NULL == set_actor && 0 == num_sets) return;
00466 
00467   std::vector<MBEntityHandle> child_sets;
00468   result = vtkMOABUtils::mbImpl->get_child_meshsets(set_handle, child_sets);
00469   if (MB_SUCCESS != result) return;
00470 
00471   for (std::vector<MBEntityHandle>::iterator vit = child_sets.begin(); 
00472        vit != child_sets.end(); vit++)
00473     updateActorParentList(set_item, *vit);
00474 }
00475 
00476 void uiQVDual::changeSetProperty( std::set<QListViewItem *> &high_sets, std::set<QListViewItem *> &unhigh_sets )
00477 {
00478   MBRange high_mbsets, unhigh_mbsets;
00479   MBEntityHandle item_set;
00480   vtkActor *this_actor;
00481   
00482   for (std::set<QListViewItem *>::iterator sit = high_sets.begin(); 
00483        sit != high_sets.end(); sit++) {
00484 
00485     item_set = itemSetMap[*sit];
00486     if (0 == item_set)
00487         // must have child items - evaluate them too
00488       evalItem(*sit, true, high_mbsets, unhigh_mbsets);
00489 
00490     else {
00491       this_actor = vtkMOABUtils::get_actor(item_set);
00492       if (NULL == this_actor) evalItem(*sit, true, high_mbsets, unhigh_mbsets);
00493       else
00494         high_mbsets.insert(item_set);
00495     }
00496     
00497       // either way, add item to selection list
00498     itemSelList.insert(*sit);
00499   }
00500   for (std::set<QListViewItem *>::iterator sit = unhigh_sets.begin(); 
00501        sit != unhigh_sets.end(); sit++) {
00502 
00503     item_set = itemSetMap[*sit];
00504     if (0 == item_set)
00505         // must have child items - evaluate them too
00506       evalItem(*sit, false, unhigh_mbsets, unhigh_mbsets);
00507 
00508     else {
00509       this_actor = vtkMOABUtils::get_actor(item_set);
00510       if (NULL == this_actor) evalItem(*sit, true, high_mbsets, unhigh_mbsets);
00511       else
00512         unhigh_mbsets.insert(item_set);
00513     }
00514 
00515       // either way, remove item from selection list
00516     itemSelList.erase(*sit);
00517   }
00518 
00519   vtkMOABUtils::change_set_properties(high_mbsets, unhigh_mbsets);
00520 }
00521 
00522 void uiQVDual::evalItem( QListViewItem * item, const bool high, 
00523                          MBRange & high_mbsets, MBRange & unhigh_mbsets )
00524 {
00525     // item is a parent, evaluate all the child items
00526   QListViewItem *child_item = item->firstChild();
00527   while (NULL != child_item) {
00528     MBEntityHandle child_set = itemSetMap[child_item];
00529     if (0 == child_set) 
00530         // if child item also has no set, must be a parent too
00531       this->evalItem(child_item, high, high_mbsets, unhigh_mbsets);
00532     else if (child_item->isSelected() != high) {
00533         // selection state is changing; put item set in proper (high or unhigh) set
00534       if (high) high_mbsets.insert(child_set);
00535       else unhigh_mbsets.insert(child_set);
00536         // since selection state changed on parent item and not child, need to set
00537         // selection state of child directly
00538       child_item->setSelected(high);
00539     }
00540     
00541     child_item = child_item->nextSibling();
00542   }
00543 }
00544 
00545 
00546 void uiQVDual::displayVisible()
00547 {
00548   MBRange selected, unselected;
00549   getSelected(NULL, selected, unselected);
00550 
00551     // get child sets of selected ones, they should be drawn too
00552   std::vector<MBEntityHandle> children;
00553   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
00554     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
00555 
00556   std::copy(children.begin(), children.end(), range_inserter(selected));
00557   
00558   unselected.clear();
00559   vtkMOABUtils::change_set_visibility(selected, unselected);
00560   vtkWidget->GetRenderWindow()->Render();
00561 }
00562 
00563 
00564 void uiQVDual::displayDraw()
00565 {
00566   MBRange selected, unselected;
00567   getSelected(NULL, selected, unselected);
00568   
00569     // get child sets of selected ones, they should be drawn too
00570   std::vector<MBEntityHandle> children;
00571   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
00572     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
00573 
00574   std::copy(children.begin(), children.end(), range_inserter(selected));
00575   
00576   vtkMOABUtils::change_set_visibility(selected, unselected);
00577 
00578     // unhighlight the visible ones; don't change the others
00579   unselected.clear();
00580   vtkMOABUtils::change_set_properties(unselected, selected);
00581 
00582   vtkWidget->GetRenderWindow()->Render();
00583 }
00584 
00585 
00586 void uiQVDual::displayWireframeShaded()
00587 {
00588   MBRange selected, unselected;
00589   getSelected(NULL, selected, unselected);
00590   
00591   vtkMOABUtils::toggle_wireframe_shaded(selected);
00592 }
00593 
00594 void uiQVDual::displayInvertSelection()
00595 {
00596 
00597 }
00598 
00599 void uiQVDual::ActorListView1_rightButtonPressed( QListViewItem *item, const QPoint &, int )
00600 {
00601   currentWin = 1;
00602   Display->exec(QCursor::pos());
00603 }
00604 
00605 void uiQVDual::displayInvisible()
00606 {
00607   MBRange selected, unselected;
00608   getSelected(NULL, selected, unselected);
00609 
00610     // get child sets of selected ones, they should be set too
00611   std::vector<MBEntityHandle> children;
00612   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++)
00613     vtkMOABUtils::mbImpl->get_child_meshsets(*rit, children, 0);
00614 
00615   std::copy(children.begin(), children.end(), range_inserter(selected));
00616   
00617   unselected.clear();
00618   vtkMOABUtils::change_set_visibility(unselected, selected);
00619   vtkWidget->GetRenderWindow()->Render();
00620 }
00621 
00622 void uiQVDual::getSelected( QListView *listv, 
00623                             std::set<QListViewItem *> &selected, 
00624                             std::set<QListViewItem *> &unselected )
00625 {
00626   if (NULL == listv && currentWin == 0) {
00627       // check all items
00628     for (std::map<QListViewItem*, MBEntityHandle>::iterator mit = itemSetMap.begin();
00629          mit != itemSetMap.end(); mit++) {
00630       if ((*mit).first->isSelected())
00631         selected.insert((*mit).first);
00632       else
00633         unselected.insert((*mit).first);
00634     }
00635     
00636     return;
00637   }
00638   
00639   QListViewItemIterator it;
00640   if (NULL == listv) {
00641     if (1 == currentWin) 
00642       it = QListViewItemIterator(ActorListView1);
00643     else if (2 == currentWin)
00644       it = QListViewItemIterator(TagListView1);
00645   }
00646   else it = QListViewItemIterator(listv);
00647   
00648   while ( it.current() ) {
00649     if ( it.current()->isSelected())
00650      selected.insert(*it);
00651     else
00652       unselected.insert(*it);
00653     ++it;
00654   }
00655 }
00656 
00657 void uiQVDual::getSelected( QListView *listv, MBRange &selected, MBRange &unselected )
00658 {
00659   static std::set<QListViewItem*> selected_s, unselected_s;
00660   selected_s.clear(); unselected_s.clear();
00661   getSelected(listv, selected_s, unselected_s);
00662   getItemSets(selected_s, selected);
00663   getItemSets(unselected_s, unselected);
00664 }
00665 
00666 void uiQVDual::TagListView1_rightButtonPressed( QListViewItem *, const QPoint &, int )
00667 {
00668   currentWin = 2;
00669   Display->exec(QCursor::pos());
00670 }
00671 
00672 
00673 void uiQVDual::displayDisplayAll()
00674 {
00675   currentWin = 0;
00676   MBRange selected, unselected;
00677   getSelected(NULL, selected, unselected);
00678   selected.merge(unselected);
00679   selected.erase(1);
00680   unselected.clear();
00681   vtkMOABUtils::change_set_visibility(selected, unselected);
00682   vtkWidget->GetRenderWindow()->Render();
00683 
00684 }
00685 
00686 void uiQVDual::getItemSets( std::set<QListViewItem *> &items, MBRange &sets )
00687 {
00688   std::set<QListViewItem*>::iterator sit;
00689   std::map<QListViewItem*, MBEntityHandle>::iterator mit;
00690   for (sit = items.begin(); sit != items.end(); sit++) {
00691     mit = itemSetMap.find(*sit);
00692     if (mit != itemSetMap.end() && (*mit).second != 0) 
00693       sets.insert((*mit).second);
00694   }
00695 }
00696 
00697 
00698 void uiQVDual::CropToolButton_clicked()
00699 {
00700     /*
00701   if (NULL == cropToolPopup) {
00702     cropToolPopup = new CropToolPopup();
00703     cropToolPopup->vtk_widget(vtkWidget);
00704   }
00705 
00706   cropToolPopup->show();
00707     */
00708   vtkMOABUtils::dualTool->check_dual_adjs();
00709 }
00710 
00711 
00712 void uiQVDual::displayDrawSheetAction_activated()
00713 {
00714   MBRange selected, unselected;
00715   getSelected(NULL, selected, unselected);
00716 
00717     // get selected sets which are dual surfaces
00718   MBRange dual_surfs;
00719   MBEntityHandle dum_tag;
00720   MBErrorCode result;
00721   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++) {
00722     result = vtkMOABUtils::mbImpl->tag_get_data(vtkMOABUtils::dualTool->dualSurface_tag(), 
00723                                                 &(*rit), 1, &dum_tag);
00724     if (MB_SUCCESS == result && 0 != dum_tag)
00725       dual_surfs.insert(*rit);
00726   }
00727 
00728   if (NULL == vtkMOABUtils::drawDual) vtkMOABUtils::drawDual = new DrawDual(pickline1, pickline2);
00729 
00730   // now draw them
00731   bool success = vtkMOABUtils::drawDual->draw_dual_surfs(dual_surfs);
00732   if (!success) 
00733     std::cout << "Problem drawing dual surface(s)." << std::endl;
00734 }
00735 
00736 
00737 void uiQVDual::APbutton_clicked()
00738 {
00739 
00740     // make sure the last picked entity is an edge
00741   MBEntityHandle edge = vtkMOABUtils::drawDual->lastPickedEnt;
00742   if (0 == edge) {
00743     std::cerr << "Didn't find a picked entity." << std::endl;
00744     return;
00745   }
00746   
00747   if (MBEDGE != vtkMOABUtils::mbImpl->type_from_handle(edge)) {
00748     std::cerr << "AP must apply to a dual edge." << std::endl;
00749     return;
00750   }
00751 
00752   MBErrorCode result = vtkMOABUtils::drawDual->reset_drawn_sheets();
00753 
00754     // otherwise, do the AP
00755   MBEntityHandle quad1, quad2;
00756   result = vtkMOABUtils::dualTool->atomic_pillow(edge, quad1, quad2);
00757   if (MB_SUCCESS != result) {
00758     std::cerr << "AP failed." << std::endl;
00759     return;
00760   }
00761 
00762     // get the dual surfaces for those quads
00763   MBEntityHandle chord = vtkMOABUtils::dualTool->
00764       get_dual_hyperplane(vtkMOABUtils::dualTool->get_dual_entity(quad1));
00765   if (0 == chord) return;
00766   
00767   std::vector<MBEntityHandle> sheets;
00768   result = vtkMOABUtils::mbImpl->get_parent_meshsets(chord, sheets);
00769   if (MB_SUCCESS != result) {
00770     std::cerr << "Couldn't get parent dual surfaces of dual edge." << std::endl;
00771     return;
00772   }
00773   
00774   std::cerr << "AP succeeded" << std::endl;
00775 
00776   redrawDisplay();
00777 
00778     // now draw the sheets affected
00779   bool success = vtkMOABUtils::drawDual->draw_dual_surfs(sheets, true);
00780   if (!success)
00781     std::cerr << "Problem drawing dual surfaces from atomic pillow." << std::endl;
00782 }
00783 
00784 
00785 void uiQVDual::negAPbutton_clicked()
00786 {
00787     // make sure the last picked entity is a 2cell
00788   MBEntityHandle tcell = vtkMOABUtils::drawDual->lastPickedEnt;
00789   if (0 == tcell) {
00790     std::cerr << "Didn't find a picked entity." << std::endl;
00791     return;
00792   }
00793   
00794   if (MBPOLYGON != vtkMOABUtils::mbImpl->type_from_handle(tcell)) {
00795     std::cerr << "-AP must apply to a dual face." << std::endl;
00796     return;
00797   }
00798 
00799   MBErrorCode result = vtkMOABUtils::drawDual->reset_drawn_sheets();
00800 
00801     // get the dual surface containing that 2cell
00802   MBEntityHandle sheet = vtkMOABUtils::dualTool->get_dual_hyperplane(tcell);
00803   MBRange chords;
00804   result = vtkMOABUtils::mbImpl->get_child_meshsets(sheet, chords);
00805   if (MB_SUCCESS != result) {
00806     std::cerr << "Couldn't get child dual chords of dual surface." << std::endl;
00807     return;
00808   }
00809   else if (2 != chords.size()) {
00810     std::cerr << "Wrong number of (child) chords for a dual surface; not a pillow?." 
00811               << std::endl;
00812     return;
00813   }
00814 
00815   MBRange other_sheets;
00816   for (MBRange::iterator rit = chords.begin(); rit != chords.end(); rit++) {
00817     result = vtkMOABUtils::mbImpl->get_parent_meshsets(*rit, other_sheets);
00818     if (MB_SUCCESS != result) {
00819       std::cerr << "Trouble getting chord parents." << std::endl;
00820       return;
00821     }
00822   }
00823   other_sheets.erase(sheet);
00824   
00825     // otherwise, do the -AP
00826   
00827   result = vtkMOABUtils::dualTool->rev_atomic_pillow(sheet, chords);
00828   if (MB_SUCCESS != result) {
00829     std::cerr << "-AP failed." << std::endl;
00830     return;
00831   }
00832 
00833   redrawDisplay();
00834 
00835     // now draw the other sheets
00836   bool success = vtkMOABUtils::drawDual->draw_dual_surfs(other_sheets, true);
00837   if (!success)
00838     std::cerr << "Problem drawing other dual surfaces from reverse atomic pillow." 
00839               << std::endl;
00840 }
00841 
00842 
00843 void uiQVDual::FOCbutton_clicked()
00844 {
00845     // make sure the last picked entities are edges
00846   MBEntityHandle edge1 = vtkMOABUtils::drawDual->lastPickedEnt,
00847     edge2 = vtkMOABUtils::drawDual->secondLastPickedEnt;
00848   if (0 == edge1 || 0 == edge2) {
00849     std::cerr << "Didn't find a picked entity." << std::endl;
00850     return;
00851   }
00852 
00853   MeshTopoUtil mtu(vtkMOABUtils::mbImpl);
00854   if (0 == mtu.common_entity(edge1, edge2, 2)) {
00855     std::cerr << "Dual edges don't share a common 2-cell." << std::endl;
00856     return;
00857   }
00858   
00859   MBErrorCode result;
00860   
00861   if (MBEDGE != vtkMOABUtils::mbImpl->type_from_handle(edge1) ||
00862       MBEDGE != vtkMOABUtils::mbImpl->type_from_handle(edge2)) {
00863     std::cerr << "FOC must apply to dual edges." << std::endl;
00864     return;
00865   }
00866 
00867     // save the quad from edge1, 'cuz the dual sheets/chord might change;
00868   MBEntityHandle quad = vtkMOABUtils::dualTool->get_dual_entity(edge1);
00869   assert(0 != quad);
00870 
00871     // reset any drawn sheets (will get redrawn later)
00872   MBRange drawn_sheets;
00873   result = vtkMOABUtils::drawDual->reset_drawn_sheets(&drawn_sheets);
00874   
00875     // otherwise, do the FOC
00876   result = vtkMOABUtils::dualTool->face_open_collapse(edge1, edge2);
00877   if (MB_SUCCESS != result) {
00878     std::cerr << "FOC failed." << std::endl;
00879     return;
00880   }
00881 
00882   std::cerr << "FOC succeeded." << std::endl;
00883 
00884   redrawDisplay();
00885 
00886     // get the dual surfaces for the edges
00887   edge1 = vtkMOABUtils::dualTool->get_dual_entity(quad);
00888   MBEntityHandle chord = vtkMOABUtils::dualTool->get_dual_hyperplane(edge1);
00889   MBRange sheets;
00890   result = vtkMOABUtils::mbImpl->get_parent_meshsets(chord, sheets);
00891   if (MB_SUCCESS == result) drawn_sheets.merge(sheets);
00892   std::vector<MBEntityHandle> dum_sheets;
00893   for (MBRange::iterator rit = drawn_sheets.begin(); rit != drawn_sheets.end(); rit++) {
00894     int dum;
00895     if (vtkMOABUtils::mbImpl->get_number_entities_by_handle(*rit, dum) == MB_SUCCESS &&
00896         dum > 0) {
00897       dum_sheets.push_back(*rit);
00898     }
00899   }
00900   bool success = vtkMOABUtils::drawDual->draw_dual_surfs(dum_sheets, true);
00901   if (!success)
00902     std::cerr << "Problem drawing previously-drawn dual surfaces." << std::endl;
00903 }
00904 
00905 
00906 void uiQVDual::FSbutton_clicked()
00907 {
00908     // make sure the last picked entity is an edge
00909   MBEntityHandle edge = vtkMOABUtils::drawDual->lastPickedEnt;
00910   if (0 == edge) {
00911     std::cerr << "Didn't find a picked entity." << std::endl;
00912     return;
00913   }
00914   
00915   if (MBEDGE != vtkMOABUtils::mbImpl->type_from_handle(edge)) {
00916     std::cerr << "FS must apply to a dual edge." << std::endl;
00917     return;
00918   }
00919 
00920     // save the quad, 'cuz the dual sheets/chord might change
00921   MBEntityHandle quad = vtkMOABUtils::dualTool->get_dual_entity(edge);
00922   assert(0 != quad);
00923 
00924     // reset any drawn sheets (will get redrawn later)
00925   MBRange drawn_sheets;
00926   MBErrorCode result = vtkMOABUtils::drawDual->reset_drawn_sheets(&drawn_sheets);
00927   
00928     // otherwise, do the FS
00929   result = vtkMOABUtils::dualTool->face_shrink(edge);
00930   if (MB_SUCCESS != result) {
00931     std::cerr << "FS failed." << std::endl;
00932     return;
00933   }
00934 
00935   std::cerr << "FS succeeded." << std::endl;
00936 
00937   redrawDisplay();
00938 
00939     // get the dual surfaces for that edge
00940   edge = vtkMOABUtils::dualTool->get_dual_entity(quad);
00941   MBEntityHandle chord = vtkMOABUtils::dualTool->get_dual_hyperplane(edge);
00942   MBRange sheets;
00943   std::vector<MBEntityHandle> dum_sheets;
00944   result = vtkMOABUtils::mbImpl->get_parent_meshsets(chord, sheets);
00945   if (MB_SUCCESS == result) {
00946     drawn_sheets = drawn_sheets.subtract(sheets);
00947     for (MBRange::iterator rit = drawn_sheets.begin(); rit != drawn_sheets.end(); rit++) {
00948       int dum;
00949       if (vtkMOABUtils::mbImpl->get_number_entities_by_handle(*rit, dum) == MB_SUCCESS &&
00950           dum > 0) {
00951         dum_sheets.push_back(*rit);
00952         
00953       }
00954     }
00955     
00956     std::copy(sheets.begin(), sheets.end(), std::back_inserter(dum_sheets));
00957     
00958     bool success = vtkMOABUtils::drawDual->draw_dual_surfs(dum_sheets, true);
00959     if (!success)
00960       std::cerr << "Problem drawing dual surfaces for face shrink." << std::endl;
00961     
00962   }
00963   else {
00964     std::cerr << "Couldn't get parent dual surfaces of dual edge." << std::endl;
00965   }
00966 }
00967 
00968 
00969 void uiQVDual::negFCbutton_clicked()
00970 {
00971     // make sure the last picked entity is an edge
00972   MBEntityHandle edge = vtkMOABUtils::drawDual->lastPickedEnt;
00973   if (0 == edge) {
00974     std::cerr << "Didn't find a picked entity." << std::endl;
00975     return;
00976   }
00977   
00978   if (MBEDGE != vtkMOABUtils::mbImpl->type_from_handle(edge)) {
00979     std::cerr << "Reverse FS must apply to a dual edge." << std::endl;
00980     return;
00981   }
00982 
00983 
00984     // save the quad, 'cuz the dual sheets/chord might change
00985   MBEntityHandle quad = vtkMOABUtils::dualTool->get_dual_entity(edge);
00986   assert(0 != quad);
00987 
00988     // reset any drawn sheets (will get redrawn later)
00989   MBRange drawn_sheets;
00990   MBErrorCode result = vtkMOABUtils::drawDual->reset_drawn_sheets(&drawn_sheets);
00991   
00992     // otherwise, do the rev FS
00993   result = vtkMOABUtils::dualTool->rev_face_shrink(edge);
00994   if (MB_SUCCESS != result) {
00995     std::cerr << "Reverse FS failed." << std::endl;
00996     vtkMOABUtils::drawDual->draw_dual_surfs(drawn_sheets);
00997     return;
00998   }
00999 
01000   redrawDisplay();
01001 
01002   std::cerr << "Reverse FS succeeded." << std::endl;
01003 
01004     // get the dual surfaces for that edge
01005   edge = vtkMOABUtils::dualTool->get_dual_entity(quad);
01006   MBEntityHandle chord = vtkMOABUtils::dualTool->get_dual_hyperplane(edge);
01007   MBRange sheets;
01008   std::vector<MBEntityHandle> dum_sheets;
01009   result = vtkMOABUtils::mbImpl->get_parent_meshsets(chord, sheets);
01010   if (MB_SUCCESS == result) {
01011     drawn_sheets = drawn_sheets.subtract(sheets);
01012     for (MBRange::iterator rit = drawn_sheets.begin(); rit != drawn_sheets.end(); rit++) {
01013       int dum;
01014       if (vtkMOABUtils::mbImpl->get_number_entities_by_handle(*rit, dum) == MB_SUCCESS &&
01015           dum > 0) {
01016         dum_sheets.push_back(*rit);
01017         
01018       }
01019     }
01020     
01021     std::copy(sheets.begin(), sheets.end(), std::back_inserter(dum_sheets));
01022     
01023     if (NULL == vtkMOABUtils::drawDual) vtkMOABUtils::drawDual = new DrawDual(pickline1, pickline2);
01024     bool success = vtkMOABUtils::drawDual->draw_dual_surfs(dum_sheets, true);
01025     if (!success)
01026       std::cerr << "Problem drawing dual surfaces for reverse face shrink." << std::endl;
01027     
01028   }
01029   else {
01030     std::cerr << "Couldn't get parent dual surfaces of dual edge." << std::endl;
01031   }
01032 }
01033 
01034 
01035 void uiQVDual::fileSaveAs()
01036 {
01037   QString filename = QFileDialog::getSaveFileName(
01038       QString::null,
01039       "Exodus files (*.g *.gen *.exoII);;Cub files (*.cub);;SLAC Netcdf files (*.ncdf);;All Files (*)", this
01040       );
01041   if(filename == QString::null)
01042     return;
01043 
01044   fileSaveAs(filename);
01045 }
01046 
01047 
01048 void uiQVDual::resetDisplay()
01049 {
01050   bool save_compute = computeDual;
01051 
01052   if (NULL != vtkMOABUtils::drawDual) {
01053     vtkMOABUtils::drawDual->reset_drawn_sheets();
01054   }
01055 
01056   vtkMOABUtils::reset_drawing_data();
01057 
01058   computeDual = save_compute;
01059 }
01060 
01061 
01062 void uiQVDual::redrawDisplay()
01063 {
01064   vtkMOABUtils::update_display();
01065 
01066   this->updateMesh();
01067 }
01068 
01069 
01070 void uiQVDual::pickline1_returnPressed()
01071 {
01072     // get the currently picked entity
01073   QString line = pickline1->text();
01074 
01075   MBRange cell_ents, picked_ents;
01076   int last_match = 0, next_match = 0;
01077   MBHandleUtils hu(vtkMOABUtils::mbImpl->proc_rank(), 
01078                    vtkMOABUtils::mbImpl->proc_size());
01079   while (true) {
01080     last_match = next_match;
01081     if (-1 == last_match) break;
01082     if (0 != last_match) last_match++;
01083     next_match = line.find("-", last_match);
01084     int ent_no = -1;
01085     MBEntityType etype = MBMAXTYPE;
01086     if (line.ascii()[last_match] == 'h') etype = MBHEX;
01087     else if (line.ascii()[last_match] == 'f') etype = MBQUAD;
01088     sscanf(line.ascii()+last_match+1, "%d", &ent_no);
01089     if (-1 != ent_no && MBMAXTYPE != etype)
01090       cell_ents.insert(hu.create_handle(etype, ent_no, 0));
01091   }
01092 #define PR(a) {pickline1->setText(QString(a));return;}
01093 
01094   if (cell_ents.size() < 2) PR("(not a dual entity!)");
01095 
01096   MBErrorCode result;
01097   if (cell_ents.size() > 2) {
01098       // assume it's a dual 2-cell
01099     result = vtkMOABUtils::mbImpl->get_adjacencies(cell_ents, 1, false, 
01100                                                    picked_ents);
01101     if (picked_ents.empty()) PR("(not a dual 2-cell!)");
01102   }
01103   else {
01104     result = vtkMOABUtils::mbImpl->get_adjacencies(cell_ents, 2, false, 
01105                                                    picked_ents);
01106     if (picked_ents.empty()) PR("(not a dual 1-cell!)");
01107   }
01108   
01109   MBEntityHandle dual_ent = vtkMOABUtils::dualTool->get_dual_entity(*picked_ents.begin());
01110   if (0 ==  dual_ent) PR("(no dual entity!)");
01111   picked_ents.clear();
01112   picked_ents.insert(dual_ent);
01113     
01114   vtkMOABUtils::drawDual->print_picked_ents(picked_ents, true);
01115 }
01116 
01117 
01118 void uiQVDual::displayPrintSheet()
01119 {
01120   MBRange selected, unselected;
01121   getSelected(NULL, selected, unselected);
01122 
01123     // get selected sets which are dual surfaces
01124   MBRange dual_surfs;
01125   MBEntityHandle dum_tag;
01126   MBErrorCode result;
01127   for (MBRange::iterator rit = selected.begin(); rit != selected.end(); rit++) {
01128     result = vtkMOABUtils::mbImpl->tag_get_data(vtkMOABUtils::dualTool->dualSurface_tag(), 
01129                                                 &(*rit), 1, &dum_tag);
01130     if (MB_SUCCESS == result && 0 != dum_tag)
01131       dual_surfs.insert(*rit);
01132   }
01133 
01134   if (NULL == vtkMOABUtils::drawDual) 
01135     vtkMOABUtils::drawDual = new DrawDual(pickline1, pickline2);
01136 
01137   // now draw them
01138   bool success = vtkMOABUtils::drawDual->print_dual_surfs(dual_surfs);
01139   if (!success) 
01140     std::cout << "Problem drawing dual surface(s)." << std::endl;
01141 
01142 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines