20 #include "SheafSystem/vtk_unstructured_grid_builder.h" 22 #include "SheafSystem/assert_contract.h" 23 #include "SheafSystem/base_space_member.h" 24 #include "SheafSystem/biorder_iterator.h" 25 #include "SheafSystem/block.impl.h" 26 #include "SheafSystem/error_message.h" 27 #include "SheafSystem/eval_iterator.h" 28 #include "SheafSystem/namespace_poset.h" 29 #include "SheafSystem/postorder_iterator.h" 30 #include "SheafSystem/preorder_iterator.h" 31 #include "SheafSystem/sec_rep_descriptor.h" 32 #include "SheafSystem/sec_vd_space.h" 33 #include "SheafSystem/section_space_schema_poset.h" 34 #include "SheafSystem/visualization_iterator.h" 36 #include "vtkUnstructuredGrid.h" 37 #include "vtkUnstructuredGridWriter.h" 38 #include "vtkDoubleArray.h" 39 #include "vtkFieldData.h" 40 #include "vtkIdTypeArray.h" 41 #include "vtkIntArray.h" 42 #include "vtkPoints.h" 43 #include "vtkCellArray.h" 44 #include "vtkCellData.h" 45 #include "vtkPointData.h" 93 ensure(is_same_type(result));
126 require(is_ancestor_of(&xother));
147 if(invariant_check())
151 disable_invariant_check();
165 enable_invariant_check();
240 delete _vtk_cell_types;
241 delete _vtk_cell_connectivity;
258 if(_name_space != &xns)
264 init_cell_type_map();
280 vtkUnstructuredGrid* result;
284 require(precondition_of(build_pa(xcoords, xproperty, result)));
288 result = vtkUnstructuredGrid::New();
290 build_pa(xcoords, xproperty, *result);
295 ensure(postcondition_of(build_pa(xcoords, xproperty, result)));
306 vtkUnstructuredGrid* result;
310 require(precondition_of(build_pa(xcoords, xproperty1, xproperty2, result)));
314 result = vtkUnstructuredGrid::New();
316 build_pa(xcoords, xproperty1, xproperty2, *result);
321 ensure(postcondition_of(build_pa(xcoords, xproperty1, xproperty2, result)));
332 vtkUnstructuredGrid* result;
336 require(precondition_of(build_pa(xcoords, result)));
340 result = vtkUnstructuredGrid::New();
342 build_pa(xcoords, *result);
347 ensure(postcondition_of(build_pa(xcoords, result)));
358 vtkUnstructuredGrid* result;
362 require(precondition_of(build_pa(xcoords, xparitition_name, result)));
366 result = vtkUnstructuredGrid::New();
368 build_pa(xcoords, xpartition_name, *result);
373 ensure(postcondition_of(build_pa(xcoords, xparitition_name, result)));
384 vtkUnstructuredGrid* result;
388 require(precondition_of(build_pa(xcoords, xproperties, result)));
392 result = vtkUnstructuredGrid::New();
394 build_pa(xcoords, xproperties, *result);
399 ensure(postcondition_of(build_pa(xcoords, xproperties, result)));
410 vtkUnstructuredGrid& xresult)
413 #ifdef DIAGNOSTIC_OUTPUT 414 post_information_message(
"build_pa with property");
421 require(xcoords.
schema().
df() <= 3);
422 require(!xcoords.
name().empty());
427 require(xproperty.
is_jim());
446 initialize_vtk_mesh_data(lsmaller, xcoords.
name());
450 _vtk_prop_dofs.set_ct(0);
451 _prop_is_pt_data.set_ct(0);
452 _prop_tensor_rank.set_ct(0);
456 initialize_vtk_prop_data(&xproperty);
476 _prop_tensor_rank[0],
478 *_vtk_cell_connectivity,
481 _vtk_cell_label_ids);
519 _prop_tensor_rank[0],
521 *_vtk_cell_connectivity,
524 _vtk_cell_label_ids);
534 finalize_vtk_mesh_data(xresult);
535 finalize_vtk_prop_data(&xproperty,
537 _prop_tensor_rank[0],
545 #ifdef DIAGNOSTIC_OUTPUT 548 xresult.PrintSelf(cout, lindent);
562 vtkUnstructuredGrid& xresult)
565 #ifdef DIAGNOSTIC_OUTPUT 566 post_information_message(
"build_pa with properties");
573 require(xcoords.
schema().
df() <= 3);
574 require(!xcoords.
name().empty());
580 require(xproperty1.
is_jim());
581 require(xproperty2.
is_jim());
596 properties.
push_back(const_cast<sec_vd*>(&xproperty1));
597 properties.
push_back(const_cast<sec_vd*>(&xproperty2));
601 build_pa(xcoords, properties, xresult);
616 #ifdef DIAGNOSTIC_OUTPUT 617 post_information_message(
"build_pa without property");
624 require(xcoords.
schema().
df() <= 3);
625 require(!xcoords.
name().empty());
629 initialize_vtk_mesh_data(xcoords, xcoords.
name());
638 const_cast<sec_vd&>(xcoords).schema());
648 *_vtk_cell_connectivity,
651 _vtk_cell_label_ids);
666 const_cast<sec_vd&>(xcoords).schema(),
false);
673 while(!lbranch_itr.is_done())
687 *_vtk_cell_connectivity,
690 _vtk_cell_label_ids);
700 finalize_vtk_mesh_data(xresult);
706 #ifdef DIAGNOSTIC_OUTPUT 708 xresult.PrintSelf(cout, lindent);
722 const std::string& xpartition_name,
723 vtkUnstructuredGrid& xresult)
726 #ifdef DIAGNOSTIC_OUTPUT 727 post_information_message(
"build_pa with partition");
734 require(xcoords.
schema().
df() <= 3);
735 require(!xpartition_name.empty());
740 build_pa(xcoords, xresult);
741 set_cell_data(const_cast<sec_vd&>(xcoords).schema().base_space(), xpartition_name, xresult);
752 vtkUnstructuredGrid& xresult)
755 #ifdef DIAGNOSTIC_OUTPUT 756 post_information_message(
"build_pa with multiple properties");
763 require(xcoords.
schema().
df() <= 3);
764 require(!xcoords.
name().empty());
765 require(xproperties.
ct() > 0);
766 require_for_all(i, 0, xproperties.
ct(), xproperties[i]->state_is_read_accessible());
770 require_for_all(i, 0, xproperties.
ct(), xproperties[i]->is_jim());
777 require_for_all(i, 0, xproperties.
ct(), !xcoords.
is_jim() ?
778 xproperties[i]->schema().same_base_space(xcoords.
schema()) :
true);
785 const sec_vd* lsmaller = &xcoords;
786 for(
int i=0; i<xproperties.
ct(); ++i)
788 if(xproperties[i]->schema().base_space().le(&lsmaller->
schema().
base_space()))
790 lsmaller = xproperties[i];
794 initialize_vtk_mesh_data(*lsmaller, xcoords.
name());
799 _prop_is_pt_data.set_ct(0);
800 _prop_tensor_rank.set_ct(0);
804 for(
int i=0; i<xproperties.
ct(); ++i)
806 initialize_vtk_prop_data(xproperties[i]);
821 xproperties[0]->schema());
832 _prop_tensor_rank[0],
834 *_vtk_cell_connectivity,
837 _vtk_cell_label_ids);
851 xproperties[0]->schema(),
865 litr->
put_anchor(lbranch_schema, xproperties[0]->schema());
874 _prop_tensor_rank[0],
876 *_vtk_cell_connectivity,
879 _vtk_cell_label_ids);
891 for(
int i=1; i<xproperties.
ct(); ++i)
898 xproperties[i]->schema());
905 litr->
set_vtk_data(*xproperties[i], _vtk_prop_dofs[i], _prop_tensor_rank[i]);
914 finalize_vtk_mesh_data(xresult);
916 for(
int i=0; i<xproperties.
ct(); ++i)
918 finalize_vtk_prop_data(xproperties[i],
920 _prop_tensor_rank[i],
929 #ifdef DIAGNOSTIC_OUTPUT 931 xresult.PrintSelf(cout, lindent);
947 tool::vtk_unstructured_grid_builder::
954 tool::vtk_unstructured_grid_builder::
959 require(name_space().state_is_read_accessible());
970 _cell_type_map.set_ct(_cell_type_map.ub());
971 _cell_type_map.assign(0);
975 _cell_type_map.set_item(lmbr.
type_id(), 1);
978 _cell_type_map.set_item(lmbr.
type_id(), 3);
981 _cell_type_map.set_item(lmbr.
type_id(), 3);
984 _cell_type_map.set_item(lmbr.
type_id(), 5);
987 _cell_type_map.set_item(lmbr.
type_id(), 5);
990 _cell_type_map.set_item(lmbr.
type_id(), 5);
993 _cell_type_map.set_item(lmbr.
type_id(), 9);
996 _cell_type_map.set_item(lmbr.
type_id(), 9);
999 _cell_type_map.set_item(lmbr.
type_id(), 9);
1002 _cell_type_map.set_item(lmbr.
type_id(), 12);
1005 _cell_type_map.set_item(lmbr.
type_id(), 12);
1008 _cell_type_map.set_item(lmbr.
type_id(), 12);
1011 _cell_type_map.set_item(lmbr.
type_id(), 10);
1014 _cell_type_map.set_item(lmbr.
type_id(), 10);
1017 _cell_type_map.set_item(lmbr.
type_id(), 10);
1030 tool::vtk_unstructured_grid_builder::
1032 const std::string& xpartition_name,
1033 vtkUnstructuredGrid& xresult)
1037 require(!xpartition_name.empty());
1044 vtkDoubleArray* lvtk_part_ids = vtkDoubleArray::New();
1045 string lpart_ids_name(xpartition_name +
"_mbr_ids");
1046 lvtk_part_ids->SetName(lpart_ids_name.c_str());
1047 lvtk_part_ids->SetNumberOfComponents(1);
1048 lvtk_part_ids->SetNumberOfTuples(_cell_ct);
1050 #ifdef DIAGNOSTIC_OUTPUT 1051 cout << xbase << endl;
1057 double lpart_id = 0.0;
1061 bool ltruncate =
false;
1067 switch(lpart_itr.
action())
1069 case biorder_iterator::PREVISIT_ACTION:
1071 if(lparts.contains_member(lmbr_id))
1076 lpart_id =
static_cast<double>(lpart_space.pod(lmbr_id) + 1);
1078 #ifdef DIAGNOSTIC_OUTPUT 1079 cout <<
"entering part with mbr_id: " << lmbr_id
1080 <<
" and with part id: " << lpart_id
1086 else if(lzones.contains_member(lmbr_id))
1093 #ifdef DIAGNOSTIC_OUTPUT 1094 cout <<
"mbr_id: " << lmbr_id
1095 <<
" is a zone with seq id: " << lzone_id
1096 <<
" and with part id: " << lpart_id
1100 lvtk_part_ids->SetTuple(lzone_id++, &lpart_id);
1112 case biorder_iterator::POSTVISIT_ACTION:
1114 if(lparts.contains_member(lmbr_id))
1119 #ifdef DIAGNOSTIC_OUTPUT 1120 cout <<
"leaving part with mbr_id: " << lmbr_id
1121 <<
" and with part id: " << lpart_id
1131 post_fatal_error_message(
"Unrecognized iterator action");
1134 lpart_itr.
next(ltruncate);
1139 xresult.GetCellData()->SetScalars(lvtk_part_ids);
1143 lzones.detach_from_state();
1144 lparts.detach_from_state();
1145 lvtk_part_ids->Delete();
1157 build_file(
const sec_vd& xcoords,
const sec_vd& xproperty,
const std::string& xvtk_file_name,
bool xis_ascii)
1163 require(xcoords.
schema().
df() <= 3);
1167 require(!xvtk_file_name.empty());
1174 vtkUnstructuredGrid* lug = build(xcoords, xproperty);
1179 vtkUnstructuredGridWriter* writer = vtkUnstructuredGridWriter::New();
1180 writer->SetInputData(lug);
1181 writer->SetFileName(xvtk_file_name.c_str());
1184 writer->SetFileTypeToASCII();
1186 writer->SetFileTypeToBinary();
1217 static const int num_paths = 2;
1219 static const string schema_paths[num_paths] =
1221 "fiber_space_schema/at0_schema",
1222 "fiber_space_schema/e1_schema" 1225 bool result =
false;
1229 for(
int i=0; i<num_paths; ++i)
1231 result = fiber_schema.
conforms_to(schema_paths[i]);
1253 static const int num_paths = 2;
1255 static const string schema_paths[num_paths] =
1257 "fiber_space_schema/e2_schema",
1258 "fiber_space_schema/e3_schema" 1261 bool result =
false;
1265 for(
int i=0; i<num_paths; ++i)
1267 result = fiber_schema.
conforms_to(schema_paths[i]);
1291 static const int num_paths = 7;
1293 static const string schema_paths[num_paths] =
1301 "fiber_space_schema/st2_e2_schema",
1302 "fiber_space_schema/st2_e3_schema" 1305 bool result =
false;
1309 for(
int i=0; i<num_paths; ++i)
1311 result = fiber_schema.
conforms_to(schema_paths[i]);
1324 tool::vtk_unstructured_grid_builder::
1325 initialize_vtk_mesh_data(
const sec_vd& xsec, std::string xcoords_name)
1342 int ldb = lschema.
db();
1344 _is_point_mesh = (lbase_host.
max_db() == 0);
1358 while(!litr2.is_done())
1367 _vtk_coord_dofs = vtkDoubleArray::New();
1368 _vtk_coord_dofs->SetName(xcoords_name.c_str());
1369 _vtk_coord_dofs->SetNumberOfComponents(3);
1370 _vtk_coord_dofs->SetNumberOfTuples(_pt_ct);
1375 _vtk_cell_types->reserve(_cell_ct);
1376 _vtk_cell_types->set_ct(0);
1378 _vtk_cell_connectivity->reserve(_cell_ct*9);
1379 _vtk_cell_connectivity->set_ct(0);
1382 _vtk_pt_label_ids = vtkIdTypeArray::New();
1383 _vtk_pt_label_ids->SetName(
"point_label_ids");
1384 _vtk_pt_label_ids->SetNumberOfComponents(1);
1389 _vtk_pt_label_ids->SetNumberOfValues(_pt_ct);
1391 _vtk_cell_label_ids = vtkIdTypeArray::New();
1392 _vtk_cell_label_ids->SetName(
"cell_label_ids");
1393 _vtk_cell_label_ids->SetNumberOfComponents(1);
1402 #ifdef DIAGNOSTIC_OUTPUT 1403 cout <<
"in initialize_vtk_mesh_data: pt ct: " << _pt_ct
1404 <<
" cell ct: " << _cell_ct << endl;
1413 tool::vtk_unstructured_grid_builder::
1414 finalize_vtk_mesh_data(vtkUnstructuredGrid& xresult)
1422 vtkPoints* lvtk_points = vtkPoints::New();
1423 lvtk_points->SetNumberOfPoints(_pt_ct);
1424 lvtk_points->SetData(_vtk_coord_dofs);
1425 lvtk_points->SetDataTypeToDouble();
1426 xresult.SetPoints(lvtk_points);
1430 vtkCellArray* lvtk_cells = vtkCellArray::New();
1431 lvtk_cells->Allocate(_cell_ct);
1433 vtkIdTypeArray* lvtk_connectivity = vtkIdTypeArray::New();
1434 lvtk_connectivity->SetNumberOfComponents(1);
1435 lvtk_connectivity->SetArray(_vtk_cell_connectivity->base(),
1436 _vtk_cell_connectivity->ct(),
1439 lvtk_cells->SetCells(_cell_ct, lvtk_connectivity);
1441 xresult.SetCells(_vtk_cell_types->base(), lvtk_cells);
1443 vtkPointData* lpt_data = xresult.GetPointData();
1444 lpt_data->AddArray(_vtk_pt_label_ids);
1446 vtkCellData* lcell_data = xresult.GetCellData();
1447 lcell_data->AddArray(_vtk_cell_label_ids);
1451 lvtk_points->Delete();
1452 _vtk_coord_dofs->Delete();
1453 lvtk_cells->Delete();
1454 lvtk_connectivity->Delete();
1455 _vtk_pt_label_ids->Delete();
1456 _vtk_cell_label_ids->Delete();
1466 tool::vtk_unstructured_grid_builder::
1467 initialize_vtk_prop_data(
const sec_vd* xprop)
1475 define_old_variable(
int old_vtk_prop_dofs_ct = _vtk_prop_dofs.ct());
1478 string lprop_name = xprop->
name();
1483 bool lprop_is_pt_data = _is_point_mesh || lschema.rep().eval_is_above_disc();
1484 _prop_is_pt_data.push_back(lprop_is_pt_data);
1487 if(is_scalar(xprop))
1491 else if(is_vector(xprop))
1495 else if(is_tensor(xprop))
1519 _prop_tensor_rank.push_back(ltensor_rank);
1521 vtkDoubleArray* lvtk_prop_dofs = vtkDoubleArray::New();
1522 lvtk_prop_dofs->SetName(lprop_name.c_str());
1523 lvtk_prop_dofs->SetNumberOfComponents(ltensor_rank == 2 ? 9 : lschema.df());
1524 lvtk_prop_dofs->SetNumberOfTuples(lprop_is_pt_data ? _pt_ct : _cell_ct);
1526 _vtk_prop_dofs.push_back(lvtk_prop_dofs);
1530 ensure(_vtk_prop_dofs.ct() == old_vtk_prop_dofs_ct + 1);
1531 ensure(_prop_is_pt_data.ct() == _vtk_prop_dofs.ct());
1532 ensure(_prop_tensor_rank.ct() == _vtk_prop_dofs.ct());
1540 tool::vtk_unstructured_grid_builder::
1541 finalize_vtk_prop_data(
const sec_vd* xprop,
1542 bool xprop_is_pt_data,
1543 int xprop_tensor_rank,
1544 vtkDoubleArray* xvtk_prop_dofs,
1545 vtkUnstructuredGrid& xresult)
1554 vtkDataSetAttributes* latt;
1555 if(xprop_is_pt_data)
1557 latt = xresult.GetPointData();
1561 latt = xresult.GetCellData();
1566 switch(xprop_tensor_rank)
1569 latt->SetScalars(xvtk_prop_dofs);
1572 latt->SetVectors(xvtk_prop_dofs);
1575 latt->SetTensors(xvtk_prop_dofs);
1578 post_warning_message(
"Algebraic type of property section not supported");
1586 xvtk_prop_dofs->Delete();
1601
poset_state_handle * host() const
The poset which this is a handle to a component of.
virtual bool is_jim(bool xin_current_version=true) const
True if this member is join irreducible in the current version of the host (xin_current_version == tr...
A client handle for a subposet.
host_type * host() const
The poset this is a member of.
section_space_schema_poset * host() const
The poset which this is a handle to a component of.
size_type ct() const
The number of items currently in use.
const pod_type & pod() const
The "plain old data" storage of this; the value in the external id space.
const scoped_index & index() const
The member index of this poset within the namespace host()
schema_poset_member & fiber_schema()
The fiber schema component of this (mutable version).
action_type action() const
The type of action the client should take when the iterator returns control to the client...
bool conforms_to(const schema_poset_member &xother) const
True if the dofs defined by this agree in type and in order with the dofs defined by xother...
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
subposet & d_cells(int xd)
The subposet containing the cells of dimension xd (mutable version).
subposet & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
const index_space_family & member_id_spaces(bool xauto_access) const
Collection of member id spaces for this (const version).
abstract_poset_member & base()
The restricted base of this section space member (mutable version)
bool is_same_state(const poset_state_handle *xhost, pod_index_type xhub_id) const
True is this is attached to state with hub id xhub_id in host xhost.
An abstract handle to a space of alternate integer identifiers (aliases) for a subset of a hub set of...
const pod_index_type & type_id() const
The cell type id of this. The id of the prototype of this in the "cell_types" id space of the prototy...
std::string name() const
A name for this.
Dperecated. Use postorder_itr. Specialization of the filtered depth-first iterator which exposes the ...
static const std::string & prototypes_poset_name()
The name of the prototypes poset.
A client handle for a member of a base space poset.
Abstract base class with useful features for all objects.
The lattice of closed cells of a cellular space; a lattice representation of a computational mesh...
const bool NOT_STRICT
Iteration strictness control.
const bool DOWN
Iteration directions.
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
section_dof_map & member_dof_map(pod_index_type xmbr_index, bool xrequire_write_access=false)
The dof map associated with the member identified by xmbr_id (mutable version).
bool same_base_space(const section_space_schema_member &xother) const
True if this has the same base as xother.
A client handle for a mutable partially ordered set.
void set_ct(size_type xct)
Sets ct() == xct.
An index within the external ("client") scope of a given id space.
Specialization of the filtered depth-first iterator which exposes the PREVISIT_ACTION and the POSTVIS...
bool le(pod_index_type xother_index) const
True if this is less than or equal to the member with index xother_index.
void next()
Makes this the next member of the subset.
virtual void release_access(bool xall=false) const
Release access. If xall is true, release all levels of access. Otherwise, release one level of access...
A section of a fiber bundle with a d-dimensional vector space fiber.
bool is_done() const
True if iteration finished.
void detach_from_state()
Detaches field from state it is currently attached to.
static const poset_path & standard_schema_path()
The path of the schema required by this class.
virtual void detach_from_state()
Detach this handle from its state, if any.
total_poset_member & base_space()
The base space component of this (mutable version).
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
virtual scoped_index member_index_ub() const
The upper bound on the member_index;.
A client handle for a poset member which has been prepared for use as a schema for a section space...
bool contains(pod_type xid) const
True, if this contains an id space with id xid.
int db() const
The dimension of the base space component.
int df() const
The dimension of the fiber space component.
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
virtual void get_read_access() const
Get read access to the state associated with this.
int max_db() const
The maximum dimension of the members of this base space.
An abstract client handle for a member of a poset.
sec_rep_descriptor & rep()
The representation for section spaces on this schema (mutable version).
virtual schema_poset_member & schema()
The schema for this member (mutable version).
A client handle for a poset member which has been prepared for use as a schema.
base_space_poset & base_space()
The base space for section spaces on this schema.
const scoped_index & index() const
The index of the current member of the iteration.
A handle for a poset whose members are numerical representations of sections of a fiber bundle...