20 #include "SheafSystem/vtk_poly_data_builder.h" 21 #include "SheafSystem/assert_contract.h" 22 #include "SheafSystem/base_space_member.h" 23 #include "SheafSystem/eval_iterator.h" 24 #include "SheafSystem/namespace_poset.h" 25 #include "SheafSystem/sec_vd_space.h" 27 #include "vtkPolyData.h" 28 #include "vtkPolyDataWriter.h" 29 #include "vtkDoubleArray.h" 30 #include "vtkFieldData.h" 31 #include "vtkIntArray.h" 33 #include "vtkPoints.h" 34 #include "vtkCellArray.h" 35 #include "vtkPointData.h" 88 ensure(is_same_type(result));
125 if(invariant_check())
129 disable_invariant_check();
143 enable_invariant_check();
158 tool::vtk_poly_data_builder::
199 tool::vtk_poly_data_builder::
210 init_cell_type_map();
227 const std::string& xvtk_file_name,
bool xis_ascii)
233 require(xcoords.
schema().
df() <= 3);
237 require(!xvtk_file_name.empty());
244 vtkPolyData* lug = build(xcoords, xproperty);
249 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
250 writer->SetInputData(lug);
251 writer->SetFileName(xvtk_file_name.c_str());
254 writer->SetFileTypeToASCII();
256 writer->SetFileTypeToBinary();
281 const std::string& xvtk_file_name,
bool xis_ascii)
287 require(xcoords.
schema().
df() <= 3);
288 require(!xvtk_file_name.empty());
295 vtkPolyData* lug = build(xcoords);
300 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
301 writer->SetInputData(lug);
302 writer->SetFileName(xvtk_file_name.c_str());
305 writer->SetFileTypeToASCII();
307 writer->SetFileTypeToBinary();
339 require(xcoords.
schema().
df() <= 3);
346 result = vtkPolyData::New();
348 build_pa(xcoords, xproperty, *result);
369 require(xcoords.
schema().
df() <= 3);
373 result = vtkPolyData::New();
375 build_pa(xcoords, *result);
394 require(xcoords.
schema().
df() <= 3);
398 require(&xresult != 0);
402 construct_mesh(xcoords, xresult);
406 construct_property(xproperty, xresult);
408 #ifdef DIAGNOSTIC_OUTPUT 411 xresult.PrintSelf(cout, lindent);
431 require(xcoords.
schema().
df() <= 3);
432 require(&xresult != 0);
436 construct_mesh(const_cast<sec_vd&>(xcoords), xresult);
451 tool::vtk_poly_data_builder::
452 vtk_poly_data_builder()
473 tool::vtk_poly_data_builder::
478 require(name_space().state_is_read_accessible());
488 _cell_type_map.set_ct(_cell_type_map.ub());
489 _cell_type_map.assign(0);
493 _cell_type_map.set_item(lmbr.
type_id(), 3);
496 _cell_type_map.set_item(lmbr.
type_id(), 3);
535 tool::vtk_poly_data_builder::
536 get_connectivity(
const sec_vd& xcoords)
542 require(xcoords.
schema().
df() <= 3);
551 _vtk_cell_types.reserve(leval_ct);
552 _vtk_cell_types.set_ct(0);
556 int num_cells = leval_ct;
558 size_type lconn_ct = count_connectivity_entries(xcoords);
559 size_type lconn_tuple_ct = lconn_ct + leval_ct;
560 _vtk_cell_connectivity.reserve(lconn_tuple_ct);
561 _vtk_cell_connectivity.set_ct(0);
573 while(!litr.is_done())
577 int lvtk_cell_type = _cell_type_map[litr.type_id()];
578 _vtk_cell_types.push_back(lvtk_cell_type);
585 size_type ldisc_ct = ldisc_ids.
ct();
587 _vtk_cell_connectivity.push_back(ldisc_ct);
592 for(size_type i=0; i<ldisc_ct; ++i)
596 int lclient_id = ldisc_space.
pod(ldisc_id);
600 _vtk_cell_connectivity.push_back(lclient_id);
617 tool::vtk_poly_data_builder::
618 count_connectivity_entries(
const sec_vd& xcoords)
const 620 size_type result = 0;
629 while(!litr.is_done())
647 tool::vtk_poly_data_builder::
655 tool::vtk_poly_data_builder::
656 construct_mesh(
const sec_vd& xcoords, vtkPolyData& xresult)
660 require(xcoords.
df() == 1);
666 vtkPoints* vtk_points = vtkPoints::New();
668 vtk_points->SetNumberOfPoints(num_points);
670 int num_vtk_points = vtk_points->GetNumberOfPoints();
672 int coord_dof_count = get_dof_count(xcoords);
674 dof_type* coord_dofs = get_dofs(const_cast<sec_vd&>(xcoords));
676 vtkDoubleArray* vtk_coord_dofs = vtkDoubleArray::New();
677 vtk_coord_dofs->SetName(xcoords.
name().c_str());
679 int num_comps = xcoords.
df();
681 vtk_coord_dofs->SetNumberOfComponents(3);
685 int num_tuples = coord_dof_count/num_comps;
686 vtk_coord_dofs->SetNumberOfTuples(num_tuples);
688 for(
int i=0; i<num_tuples; ++i)
690 x[0] = coord_dofs[index++];
692 x[1] = coord_dofs[index++];
696 vtk_coord_dofs->SetTuple(i, x);
699 vtk_points->SetData(vtk_coord_dofs);
700 vtk_points->SetDataTypeToDouble();
704 get_connectivity(xcoords);
706 vtkCellArray* vtk_cells = vtkCellArray::New();
707 int num_cells = _vtk_cell_types.ct();
708 vtk_cells->Allocate(num_cells);
710 vtkIdTypeArray* vtk_connectivity = vtkIdTypeArray::New();
711 vtk_connectivity->SetNumberOfComponents(1);
712 vtk_connectivity->SetArray(_vtk_cell_connectivity.base(), _vtk_cell_connectivity.ct(), 1);
714 vtk_cells->SetCells(num_cells, vtk_connectivity);
716 xresult.SetPoints(vtk_points);
717 xresult.SetPolys(vtk_cells);
719 vtk_points->Delete();
721 vtk_connectivity->Delete();
722 vtk_coord_dofs->Delete();
735 require(xproperty.
df() == 1);
739 vtkDoubleArray* propertyArray = vtkDoubleArray::New();
741 int dof_count = get_dof_count(xproperty);
742 dof_type* dofs = get_dofs(xproperty);
744 propertyArray->SetName(xproperty.
name().c_str());
748 propertyArray->SetNumberOfComponents(1);
749 propertyArray->SetArray(dofs, dof_count, 1);
750 xresult.GetPointData()->SetScalars(propertyArray);
752 propertyArray->Delete();
761 tool::vtk_poly_data_builder::
762 get_dof_count(
const sec_vd& xmbr)
const 768 tool::vtk_poly_data_builder::dof_type*
769 tool::vtk_poly_data_builder::
770 get_dofs(
const sec_vd& xmbr)
const 774 dof_type* result =
reinterpret_cast<dof_type*
>(
const_cast<section_dof_map&
>(dof_map).dof_tuple());
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
int df() const
The dimension of the restricted fiber.
host_type * host() const
The poset this is a member 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.
The abstract map from section dof ids to section dof values of heterogeneous type.
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...
An iterator over the members of the evaluation subposet contained in the downset of the base space of...
subposet & evaluation()
The evaluation subposet for section spaces on this schema (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.
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.
A client handle for a mutable partially ordered set.
An index within the external ("client") scope of a given id space.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
int discretization_ct() const
The number of members in the intersection of the discretization subposet and the down set of the base...
static int row_dof_ct(const namespace_poset &xns, const poset_path &xpath, bool xauto_access=true)
The number of row dofs defined by the schema specified by xns and xpath. Synonym for dof_ct(xns...
subposet & discretization()
The discretization subposet for section spaces on this schema (mutable version).
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...
virtual pod_type pod(pod_type xid) const =0
The pod index in this space equivalent to xid in the hub id space.
A section of a fiber bundle with a d-dimensional vector space fiber.
const scattered_insertion_index_space_handle & id_space() const
The id space for the members of with this (const version).
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;.
int evaluation_ct() const
The number of members in the intersection of the evaluation subposet and the down set of the base spa...
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.
block< scoped_index > & discretization_members()
The discretization members in the downset of the current evaluation member (mutable version)...
virtual schema_poset_member & schema()
The schema for this member (mutable version).
virtual section_dof_map & dof_map(bool xrequire_write_access=false)
The map from client_ids to dof values for this poset member (mutable version)
A handle for a poset whose members are numerical representations of sections of a fiber bundle...