moab
|
00001 #include "vtkMOABMesh.hpp" 00002 00003 #include "vtkFloatArray.h" 00004 #include "vtkCellArray.h" 00005 #include "vtkCellData.h" 00006 #include "vtkIntArray.h" 00007 #include "vtkCharArray.h" 00008 #include "vtkPolyData.h" 00009 #include "vtkObjectFactory.h" 00010 #include "vtkUnstructuredGrid.h" 00011 #include "vtkExtractUnstructuredGrid.h" 00012 #include "vtkThreshold.h" 00013 #include "vtkDoubleArray.h" 00014 #include "vtkIntArray.h" 00015 #include "vtkPointData.h" 00016 #include <sstream> 00017 #include <vector> 00018 #include "assert.h" 00019 #include "MBTagConventions.hpp" 00020 00021 #include "moab/Core.hpp" 00022 #include "moab/CN.hpp" 00023 00024 #define MOABMeshErrorMacro(s) std::cerr s << std::endl 00025 using namespace moab; 00026 00027 const int vtkMOABMesh::vtk_cell_types[] = { 00028 1, 3, 5, 9, 7, 10, 14, 13, 0, 12, 0, 0, 0}; 00029 00030 const bool new_outputs = false; 00031 const bool use_filters = true; 00032 00033 vtkMOABMesh *vtkMOABMesh::instance_ = NULL; 00034 00035 vtkMOABMesh *vtkMOABMesh::instance(Interface *iface, bool create_new) 00036 { 00037 if (!instance_ && create_new) 00038 instance_ = new vtkMOABMesh(iface); 00039 00040 return instance_; 00041 } 00042 00043 ErrorCode vtkMOABMesh::delete_instance() 00044 { 00045 if (instance_) { 00046 delete instance_; 00047 instance_ = NULL; 00048 } 00049 00050 return MB_SUCCESS; 00051 } 00052 00053 vtkMOABMesh::vtkMOABMesh(Interface *iface) 00054 : mbImpl(iface), myUG(NULL), iFace(NULL), maxPointId(-1), maxCellId(-1), 00055 vtkIdTag(0), outOfDate(true) 00056 { 00057 if (!mbImpl) mbImpl = new Core(); 00058 00059 mbImpl->query_interface(iFace); 00060 assert(NULL != iFace); 00061 00062 int def_val = -1; 00063 ErrorCode rval = mbImpl->tag_get_handle("__vtkIdTag", 1, MB_TYPE_INTEGER, 00064 vtkIdTag, MB_TAG_DENSE|MB_TAG_CREAT, 00065 &def_val); 00066 assert(MB_SUCCESS == rval); 00067 } 00068 00069 ErrorCode vtkMOABMesh::load_file(const char *file_name, const char *options, 00070 EntityHandle &file_set) 00071 { 00072 ErrorCode rval; 00073 00074 rval = mbImpl->create_meshset(MESHSET_SET, file_set); 00075 if (MB_SUCCESS != rval) return rval; 00076 00077 fileSets.insert(file_set); 00078 00079 rval = mbImpl->load_file(file_name, &file_set, options); 00080 if (MB_SUCCESS != rval) return rval; 00081 00082 outOfDate = true; 00083 00084 fileNames.push_back(std::string(file_name)); 00085 00086 return rval; 00087 } 00088 00089 void vtkMOABMesh::Execute() 00090 { 00091 Update(); 00092 } 00093 00094 vtkMOABMesh::~vtkMOABMesh() 00095 { 00096 if (mbImpl) { 00097 if (iFace) 00098 mbImpl->release_interface(iFace); 00099 00100 delete mbImpl; 00101 } 00102 } 00103 00104 ErrorCode vtkMOABMesh::Update(EntityHandle file_set) 00105 { 00106 if (!outOfDate) return MB_SUCCESS; 00107 00108 // get the data set & allocate an initial chunk of data 00109 vtkUnstructuredGrid *ug = this->GetOutput(); 00110 ug->Allocate(); 00111 00112 ErrorCode rval = construct_mesh(file_set); 00113 if (MB_SUCCESS != rval) 00114 { 00115 MOABMeshErrorMacro( << "Failed to construct mesh"); 00116 return rval; 00117 } 00118 MOABMeshErrorMacro(<<"Constructed mesh..."); 00119 00120 if (use_filters) 00121 rval = construct_filters(); 00122 if (MB_SUCCESS != rval) 00123 { 00124 MOABMeshErrorMacro( << "Failed to construct filters "); 00125 return MB_FAILURE; 00126 } 00127 MOABMeshErrorMacro(<<"Filters constructed..."); 00128 00129 // get all dense tags 00130 rval = read_tags(file_set); 00131 MOABMeshErrorMacro(<<"Tags read..."); 00132 00133 outOfDate = false; 00134 00135 MOABMeshErrorMacro(<< "After Update: ug has " << myUG->GetNumberOfPoints() 00136 << " points, " << myUG->GetNumberOfCells() << " cells."); 00137 00138 return rval; 00139 } 00140 00141 ErrorCode vtkMOABMesh::read_tags(EntityHandle file_set) 00142 { 00143 ErrorCode rval = read_dense_tags(file_set); 00144 if (MB_SUCCESS != rval) return rval; 00145 00146 rval = read_sparse_tags(file_set); 00147 return rval; 00148 } 00149 00150 ErrorCode vtkMOABMesh::read_dense_tags(EntityHandle file_set) 00151 { 00152 // get all the tags 00153 std::vector<Tag> tmptags, all_tags; 00154 ErrorCode rval = mbImpl->tag_get_tags(tmptags); 00155 if (MB_SUCCESS != rval) return rval; 00156 00157 for (std::vector<Tag>::iterator vit = tmptags.begin(); vit != tmptags.end(); vit++) { 00158 // skip sparse tags 00159 TagType ttype; 00160 rval = mbImpl->tag_get_type(*vit, ttype); 00161 if (MB_SUCCESS == rval && MB_TAG_DENSE == ttype) all_tags.push_back(*vit); 00162 } 00163 00164 // now create field arrays on all 2d and 3d entities 00165 Range ents2d, ents3d, verts; 00166 rval = mbImpl->get_entities_by_dimension(file_set, 2, ents2d); 00167 if (MB_SUCCESS != rval) return rval; 00168 00169 rval = mbImpl->get_entities_by_dimension(file_set, 3, ents3d); 00170 if (MB_SUCCESS != rval) return rval; 00171 00172 rval = mbImpl->get_entities_by_dimension(file_set, 0, verts); 00173 if (MB_SUCCESS != rval) return rval; 00174 00175 int *vids; 00176 void *data; 00177 if (MB_SUCCESS != rval) return rval; 00178 std::vector<double> tag_dvals; 00179 std::vector<int> tag_ivals; 00180 vtkIntArray *int_array; 00181 vtkDoubleArray *dbl_array; 00182 int idef, *idata; 00183 double ddef, *ddata; 00184 int min, max; 00185 00186 for (std::vector<Tag>::iterator vit = all_tags.begin(); vit != all_tags.end(); vit++) { 00187 if (*vit == vtkIdTag) continue; 00188 00189 // create a data array 00190 DataType dtype; 00191 rval = mbImpl->tag_get_data_type(*vit, dtype); 00192 if (MB_SUCCESS != rval) continue; 00193 std::string tag_name; 00194 bool has_default = false; 00195 rval = mbImpl->tag_get_name(*vit, tag_name); 00196 if (MB_SUCCESS != rval) continue; 00197 if (MB_TYPE_DOUBLE == dtype) { 00198 dbl_array = vtkDoubleArray::New(); 00199 dbl_array->SetName(tag_name.c_str()); 00200 if (MB_SUCCESS == mbImpl->tag_get_default_value(*vit, &ddef)) 00201 has_default = true; 00202 } 00203 else if (MB_TYPE_INTEGER == dtype) { 00204 int_array = vtkIntArray::New(); 00205 int_array->SetName(tag_name.c_str()); 00206 if (MB_SUCCESS == mbImpl->tag_get_default_value(*vit, &idef)) 00207 has_default = true; 00208 } 00209 00210 if (MB_SUCCESS != rval) continue; 00211 00212 Range::iterator rit, rit2; 00213 rit = rit2 = ents2d.begin(); 00214 while (rit != ents2d.end()) { 00215 // get tag iterator for gids 00216 rval = mbImpl->tag_iterate(vtkIdTag, rit, ents2d.end(), (void*&)vids); 00217 if (MB_SUCCESS != rval) continue; 00218 int count = rit - rit2; 00219 00220 rval = mbImpl->tag_iterate(*vit, rit2, ents2d.end(), data); 00221 if (MB_SUCCESS != rval) continue; 00222 00223 if (MB_TYPE_DOUBLE == dtype) { 00224 ddata = (double*)data; 00225 for (int i = 0; i < count; i++) { 00226 assert(-1 < vids[i] && vids[i] <= maxCellId); 00227 if (!has_default || ddata[i] != ddef) 00228 dbl_array->InsertValue(vids[i], ddata[i]); 00229 } 00230 } 00231 else if (MB_TYPE_INTEGER == dtype) { 00232 idata = (int*)data; 00233 for (int i = 0; i < count; i++) { 00234 assert(-1 < vids[i] && vids[i] <= maxCellId); 00235 if (!has_default || idata[i] != idef) 00236 int_array->InsertValue(vids[i], idata[i]); 00237 } 00238 } 00239 00240 min = *std::min_element(vids, vids+count); 00241 max = *std::max_element(vids, vids+count); 00242 MOABMeshErrorMacro(<< "2d: min = " << min << ", max = " << max); 00243 } 00244 00245 rit = rit2 = ents3d.begin(); 00246 while (rit != ents3d.end()) { 00247 // get tag iterator for vids 00248 rval = mbImpl->tag_iterate(vtkIdTag, rit, ents3d.end(), (void*&)vids); 00249 if (MB_SUCCESS != rval) continue; 00250 int count = rit - rit2; 00251 00252 rval = mbImpl->tag_iterate(*vit, rit2, ents3d.end(), data); 00253 if (MB_SUCCESS != rval) continue; 00254 00255 if (MB_TYPE_DOUBLE == dtype) { 00256 ddata = (double*)data; 00257 for (int i = 0; i < count; i++) { 00258 assert(-1 < vids[i] && vids[i] <= maxCellId); 00259 if (!has_default || ddata[i] != ddef) 00260 dbl_array->InsertValue(vids[i], ddata[i]); 00261 } 00262 } 00263 else if (MB_TYPE_INTEGER == dtype) { 00264 idata = (int*)data; 00265 for (int i = 0; i < count; i++) { 00266 assert(-1 < vids[i] && vids[i] <= maxCellId); 00267 if (!has_default || idata[i] != idef) 00268 int_array->InsertValue(vids[i], idata[i]); 00269 } 00270 } 00271 min = *std::min_element(vids, vids+count); 00272 max = *std::max_element(vids, vids+count); 00273 MOABMeshErrorMacro(<< "3d: min = " << min << ", max = " << max); 00274 } 00275 00276 if (MB_TYPE_DOUBLE == dtype) { 00277 this->GetOutput()->GetCellData()->AddArray(dbl_array); 00278 dbl_array->Delete(); 00279 MOABMeshErrorMacro(<< "Read " << dbl_array->GetSize() << " values of dbl tag " << tag_name); 00280 } 00281 else if (MB_TYPE_INTEGER == dtype) { 00282 this->GetOutput()->GetCellData()->AddArray(int_array); 00283 int_array->Delete(); 00284 MOABMeshErrorMacro(<< "Read " << int_array->GetSize() << " values of int tag " << tag_name); 00285 } 00286 00287 rit = rit2 = verts.begin(); 00288 if (MB_TYPE_DOUBLE == dtype) { 00289 dbl_array = vtkDoubleArray::New(); 00290 dbl_array->SetName(tag_name.c_str()); 00291 } 00292 else if (MB_TYPE_INTEGER == dtype) { 00293 int_array = vtkIntArray::New(); 00294 int_array->SetName(tag_name.c_str()); 00295 } 00296 while (rit != verts.end()) { 00297 // get tag iterator for vids 00298 rval = mbImpl->tag_iterate(vtkIdTag, rit, verts.end(), (void*&)vids); 00299 if (MB_SUCCESS != rval) continue; 00300 int count = rit - rit2; 00301 00302 rval = mbImpl->tag_iterate(*vit, rit2, verts.end(), data); 00303 if (MB_SUCCESS != rval) continue; 00304 00305 if (MB_TYPE_DOUBLE == dtype) { 00306 ddata = (double*)data; 00307 for (int i = 0; i < count; i++) { 00308 assert(vids[i] >= 0 && vids[i] <= maxPointId); 00309 if (!has_default || ddata[i] != ddef) 00310 dbl_array->InsertValue(vids[i], ddata[i]); 00311 } 00312 } 00313 else if (MB_TYPE_INTEGER == dtype) { 00314 idata = (int*)data; 00315 for (int i = 0; i < count; i++) { 00316 assert(vids[i] >= 0 && vids[i] <= maxPointId); 00317 if (!has_default || idata[i] != idef) 00318 int_array->InsertValue(vids[i], idata[i]); 00319 } 00320 } 00321 00322 min = *std::min_element(vids, vids+count); 00323 max = *std::max_element(vids, vids+count); 00324 MOABMeshErrorMacro(<< "verts: min = " << min << ", max = " << max); 00325 } 00326 00327 if (MB_TYPE_DOUBLE == dtype) { 00328 this->GetOutput()->GetPointData()->AddArray(dbl_array); 00329 dbl_array->Delete(); 00330 MOABMeshErrorMacro(<< "Read " << dbl_array->GetSize() << " values of dbl tag " << tag_name); 00331 } 00332 else if (MB_TYPE_INTEGER == dtype) { 00333 this->GetOutput()->GetPointData()->AddArray(int_array); 00334 int_array->Delete(); 00335 MOABMeshErrorMacro(<< "Read " << int_array->GetSize() << " values of int tag " << tag_name); 00336 } 00337 } 00338 00339 return MB_SUCCESS; 00340 } 00341 00342 ErrorCode vtkMOABMesh::read_sparse_tags(EntityHandle file_set) 00343 { 00344 // get all the tags 00345 std::vector<Tag> tmptags, all_tags; 00346 ErrorCode rval = mbImpl->tag_get_tags(tmptags); 00347 if (MB_SUCCESS != rval) return rval; 00348 00349 for (std::vector<Tag>::iterator vit = tmptags.begin(); vit != tmptags.end(); vit++) { 00350 // skip dense tags 00351 TagType ttype; 00352 DataType dtype; 00353 rval = mbImpl->tag_get_type(*vit, ttype); 00354 rval = mbImpl->tag_get_data_type(*vit, dtype); 00355 if (MB_SUCCESS == rval && MB_TAG_SPARSE == ttype && MB_TYPE_INTEGER == dtype) 00356 all_tags.push_back(*vit); 00357 } 00358 00359 // now create field arrays on all 2d and 3d entities 00360 Range sets, ents, verts; 00361 vtkIntArray *int_array; 00362 00363 Tag gid_tag, gdim_tag; 00364 rval = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag); 00365 if (MB_SUCCESS != rval) return rval; 00366 00367 rval = mbImpl->tag_get_handle(GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, gdim_tag); 00368 if (MB_SUCCESS != rval) return rval; 00369 00370 std::vector<int> vids; 00371 for (std::vector<Tag>::iterator vit = all_tags.begin(); vit != all_tags.end(); vit++) { 00372 if (*vit == vtkIdTag) continue; 00373 00374 // if this is a geometry tag, loop 00375 int lmax = (*vit == gdim_tag ? 3 : 0); 00376 static int lvals[] = {0, 1, 2, 3}; 00377 static const char *lnames[] = {"GeomVertex", "GeomCurve", "GeomSurface", "GeomVolume"}; 00378 00379 for (int l = 1; l <= lmax; l++) { 00380 sets.clear(); 00381 int *lval = lvals+l; 00382 rval = mbImpl->get_entities_by_type_and_tag(file_set, MBENTITYSET, &(*vit), 00383 (const void* const*)(lmax ? &lval : NULL), 1, sets); 00384 if (MB_SUCCESS != rval || sets.empty()) continue; 00385 00386 // create a data array 00387 std::string tag_name; 00388 bool has_default = false; 00389 if (lmax) tag_name = std::string(lnames[l]); 00390 else { 00391 rval = mbImpl->tag_get_name(*vit, tag_name); 00392 if (MB_SUCCESS != rval) continue; 00393 } 00394 if (MB_SUCCESS != rval) continue; 00395 int_array = vtkIntArray::New(); 00396 int_array->SetName(tag_name.c_str()); 00397 bool had_ents = false; 00398 00399 // loop over sets then entities 00400 for (Range::iterator rit = sets.begin(); rit != sets.end(); rit++) { 00401 // get the tag value 00402 int this_val; 00403 rval = mbImpl->tag_get_data((lmax ? gid_tag : *vit), &(*rit), 1, &this_val); 00404 if (MB_SUCCESS != rval) continue; 00405 00406 // get the non-vertex entities, and their vtk ids 00407 ents.clear(); 00408 for (int d = 1; d <= 3; d++) { 00409 rval = mbImpl->get_entities_by_dimension(*rit, d, ents, true); 00410 if (MB_SUCCESS != rval) continue; 00411 } 00412 if (ents.empty()) continue; 00413 vids.resize(ents.size()); 00414 rval = mbImpl->tag_get_data(vtkIdTag, ents, &vids[0]); 00415 if (MB_SUCCESS != rval || ents.empty()) continue; 00416 00417 std::cout << "Tag " << tag_name << ", value " << this_val << ", entities:" << std::endl; 00418 ents.print(" "); 00419 00420 for (unsigned int e = 0; e < vids.size(); e++) { 00421 assert(-1 != vids[e]); 00422 int_array->InsertValue(vids[e], this_val); 00423 } 00424 00425 had_ents = true; 00426 } 00427 00428 // add the data array to the output 00429 if (had_ents) this->GetOutput()->GetCellData()->AddArray(int_array); 00430 int_array->Delete(); 00431 } 00432 } 00433 00434 return MB_SUCCESS; 00435 } 00436 00437 ErrorCode vtkMOABMesh::construct_mesh(EntityHandle file_set) 00438 { 00439 // construct the vtk representation of the mesh 00440 00441 // get all the hexes and quads 00442 Range all_elems; 00443 ErrorCode result = MB_SUCCESS, tmp_result; 00444 for (int dim = 0; dim <= 3; dim++) 00445 { 00446 tmp_result = mbImpl->get_entities_by_dimension(file_set, dim, all_elems); 00447 if (tmp_result != MB_SUCCESS) result = tmp_result; 00448 } 00449 if (MB_SUCCESS != result) 00450 { 00451 MOABMeshErrorMacro( << "Failure getting hexes from mesh. " ); 00452 return result; 00453 } 00454 00455 MOABMeshErrorMacro(<< "Read " << all_elems.size() << " entities from MOAB."); 00456 00457 // create the elements 00458 int success = this->create_elements(file_set); 00459 if (MB_SUCCESS != result) 00460 { 00461 MOABMeshErrorMacro( << "Problem filling in quad data. " ); 00462 return result; 00463 } 00464 00465 return MB_SUCCESS; 00466 00467 } 00468 00469 ErrorCode vtkMOABMesh::create_points_vertices(EntityHandle file_set, Range &verts) 00470 { 00471 // get the global id tag 00472 ErrorCode result; 00473 00474 result = mbImpl->get_entities_by_type(file_set, MBVERTEX, verts); 00475 if (MB_SUCCESS != result) 00476 { 00477 MOABMeshErrorMacro( << "Couldn't gather vertices. " ); 00478 return result; 00479 } 00480 00481 MOABMeshErrorMacro(<< "Gathered " << verts.size() << " vertices from MOAB."); 00482 00483 // assign ids to the vertices 00484 std::vector<int> vids(verts.size()); 00485 for (unsigned int i = 0; i < verts.size(); i++) 00486 vids[i] = ++maxPointId; 00487 00488 result = mbImpl->tag_set_data(vtkIdTag, verts, &vids[0]); 00489 if (MB_SUCCESS != result) 00490 { 00491 MOABMeshErrorMacro( << "Couldn't set ids on vertices. " ); 00492 return result; 00493 } 00494 00495 // allocate and fill in coordinate arrays 00496 std::vector<double*> coords(3); 00497 coords[0] = new double[verts.size()]; 00498 coords[1] = new double[verts.size()]; 00499 coords[2] = new double[verts.size()]; 00500 result = iFace->get_node_coords(3, verts.size(), verts, 00501 0, 0, coords); 00502 if (MB_SUCCESS != result) 00503 { 00504 MOABMeshErrorMacro( << "Couldn't get nodal coordinates. " ); 00505 return result; 00506 } 00507 00508 // put these data into a point array 00509 vtkPoints *points = vtkPoints::New(); 00510 int dum; 00511 points->SetNumberOfPoints(verts.size()); 00512 assert(MB_SUCCESS == result); 00513 unsigned int i = 0; 00514 for (Range::const_iterator rit = verts.begin(); rit != verts.end(); rit++, i++) 00515 { 00516 points->SetPoint(vids[i], coords[0][i], coords[1][i], coords[2][i]); 00517 } 00518 myUG->SetPoints(points); 00519 points->Delete(); 00520 00521 return MB_SUCCESS; 00522 } 00523 00524 ErrorCode vtkMOABMesh::create_elements(EntityHandle file_set) 00525 { 00526 // get the vertices 00527 Range verts; 00528 ErrorCode result; 00529 00530 // create points/vertices in vtk database 00531 result = create_points_vertices(file_set, verts); 00532 if (MB_SUCCESS != result) 00533 { 00534 MOABMeshErrorMacro( << "Couldn't create points/vertices. " ); 00535 return result; 00536 } 00537 00538 MOABMeshErrorMacro(<< "After create_points_vertices: ug has " << myUG->GetNumberOfPoints() 00539 << " points, " << myUG->GetNumberOfCells() << " cells."); 00540 00541 // for the remaining elements, add them individually 00542 int ids[CN::MAX_NODES_PER_ELEMENT]; 00543 vtkIdType vtkids[CN::MAX_NODES_PER_ELEMENT]; 00544 const EntityHandle *connect; 00545 int num_connect; 00546 bool first = true; 00547 00548 for (EntityType this_type = MBEDGE; this_type != MBENTITYSET; this_type++) { 00549 00550 // don't try to represent elements vtk doesn't understand 00551 if (vtk_cell_types[this_type] == 0) continue; 00552 00553 Range elems; 00554 result = mbImpl->get_entities_by_type(file_set, this_type, elems); 00555 if (MB_SUCCESS != result) 00556 { 00557 MOABMeshErrorMacro( << "Couldn't get elements. " ); 00558 return result; 00559 } 00560 00561 std::vector<int> eids(elems.size()); 00562 result = mbImpl->tag_get_data(vtkIdTag, elems, &eids[0]); 00563 if (MB_SUCCESS != result) 00564 { 00565 MOABMeshErrorMacro( << "Couldn't get elements vtkIdTag. " ); 00566 return result; 00567 } 00568 00569 int e = 0; 00570 bool changed = false; 00571 for (Range::iterator rit = elems.begin(); rit != elems.end(); rit++, e++) { 00572 if (-1 != eids[e]) continue; 00573 00574 changed = true; 00575 00576 // get the connectivity of these elements 00577 result = mbImpl->get_connectivity(*rit, connect, num_connect, true); 00578 if (MB_SUCCESS != result) 00579 { 00580 MOABMeshErrorMacro( << "Couldn't get element connectivity. " ); 00581 return result; 00582 } 00583 00584 // get the id tag for these vertices 00585 result = mbImpl->tag_get_data(vtkIdTag, connect, num_connect, ids); 00586 if (MB_SUCCESS != result) 00587 { 00588 MOABMeshErrorMacro( << "Couldn't get vertex ids for element. " ); 00589 return result; 00590 } 00591 00592 // ok, now insert this cell 00593 for (int i = 0; i < num_connect; i++) vtkids[i] = ids[i]; 00594 int last_id = myUG->InsertNextCell(vtk_cell_types[this_type], num_connect, vtkids); 00595 eids[e] = last_id; 00596 maxCellId = std::max(last_id, maxCellId); 00597 } 00598 00599 if (changed) { 00600 result = mbImpl->tag_set_data(vtkIdTag, elems, &eids[0]); 00601 if (MB_SUCCESS != result) 00602 { 00603 MOABMeshErrorMacro( << "Couldn't save element ids. " ); 00604 return result; 00605 } 00606 } 00607 } 00608 00609 MOABMeshErrorMacro(<< "After creating cells: ug has " << myUG->GetNumberOfPoints() 00610 << " points, " << myUG->GetNumberOfCells() << " cells."); 00611 00612 return MB_SUCCESS; 00613 } 00614 00615 moab::ErrorCode vtkMOABMesh::construct_filters() 00616 { 00617 // apply threshold and type filters to the output to get multiple actors 00618 // corresponding to dual surfaces and curves, then group the dual actors 00619 // together using a group filter 00620 00621 vtkUnstructuredGrid *ug = this->GetOutput(); 00622 /* 00623 // first, get the non-dual mesh 00624 vtkExtractUnstructuredGrid *primal = vtkExtractUnstructuredGrid::New(); 00625 primal->SetInput(this->GetOutput()); 00626 primal->SetCellMinimum(0); 00627 primal->SetCellMaximum(this->MaxPrimalId); 00628 00629 // set merging on so points aren't duplicated 00630 primal->SetMerging(1); 00631 00632 // now do dual surfaces; do threshold-based extraction for now 00633 MBTag vtkIdTag; 00634 MBErrorCode result = mbImpl->tag_get_handle(GLOBAL_ID_TAG_NAME, vtkIdTag); 00635 assert(MB_SUCCESS == result && 0 != vtkIdTag); 00636 00637 int ds_id; 00638 for (ds_id = 0; ds_id < this->NumberOfDualSurfaces; ds_id++) { 00639 vtkThreshold *ds_filter = vtkThreshold::New(); 00640 ds_filter->SelectInputScalars(DUAL_SURF_ATTRIBUTE_NAME); 00641 ds_filter->SetAttributeModeToUseCellData(); 00642 ds_filter->ThresholdBetween(((double)ds_id-0.5), ((double)ds_id+0.5)); 00643 ds_filter->SetInput(ug); 00644 this->add_name(ds_filter->GetOutput(), "dual_surf_", ds_id); 00645 } 00646 00647 // same for dual curves 00648 int dc_id; 00649 for (dc_id = 0; dc_id < this->NumberOfDualCurves; dc_id++) { 00650 vtkThreshold *dc_filter = vtkThreshold::New(); 00651 dc_filter->SelectInputScalars(DUAL_CURVE_ATTRIBUTE_NAME); 00652 dc_filter->SetAttributeModeToUseCellData(); 00653 dc_filter->ThresholdBetween(((double)dc_id-0.5), ((double)dc_id+0.5)); 00654 dc_filter->SetInput(ug); 00655 this->add_name(dc_filter->GetOutput(), "dual_curve_", dc_id); 00656 } 00657 00658 // lastly, get the dual vertices and put those in a group 00659 // first, get the non-dual mesh 00660 vtkExtractUnstructuredGrid *dual_verts = vtkExtractUnstructuredGrid::New(); 00661 dual_verts->SetCellMinimum(this->DualVertexIdOffset); 00662 dual_verts->SetCellMaximum(this->DualVertexIdOffset+this->NumberOfDualVertices-1); 00663 this->add_name(dual_verts->GetOutput(), "dual_verts", 0); 00664 */ 00665 return MB_SUCCESS; 00666 } 00667 00668 void vtkMOABMesh::add_name(vtkUnstructuredGrid *output, const char *prefix, 00669 const int id) 00670 { 00671 vtkCharArray* nmArray = vtkCharArray::New(); 00672 nmArray->SetName("Name"); 00673 vtkstd::ostringstream name; 00674 name << prefix << id << "\0"; 00675 nmArray->SetNumberOfTuples(static_cast<vtkIdType>(name.str().length())); 00676 char* copy = nmArray->GetPointer(0); 00677 memcpy(copy, name.str().c_str(), name.str().length()); 00678 output->GetFieldData()->AddArray(nmArray); 00679 nmArray->Delete(); 00680 }