SheafSystem  0.0.0.0
visualization_iterator_1_3.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class visualization_iterator_1_3
19 
20 
21 #include "SheafSystem/visualization_iterator_1_3.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/base_space_member.h"
25 #include "SheafSystem/binary_section_space_schema_member.h"
26 #include "SheafSystem/eval_family.h"
27 #include "SheafSystem/int_set.h"
28 #include "SheafSystem/sec_rep_descriptor.h"
29 #include "SheafSystem/sec_vd.h"
30 #include "SheafSystem/section_evaluator.h"
31 #include "SheafSystem/section_space_schema_member.h"
32 #include "SheafSystem/std_limits.h"
33 #include "SheafSystem/structured_block_1d.h"
34 #include "SheafSystem/structured_block_2d.h"
35 #include "SheafSystem/structured_block_3d.h"
36 #include "SheafSystem/subposet_member_iterator.h"
37 #include "SheafSystem/uniform_eval_family.h"
38 #include "vtkDoubleArray.h"
39 #include "vtkIdTypeArray.h"
40 
41 //#define DIAGNOSTIC_OUTPUT 1
42 
43 // Workaround for MS Visual C++
44 using namespace tool;
45 using namespace std;
46 using namespace unordered;
47 
48 // ===========================================================
49 // ANY FACET
50 // ===========================================================
51 
52 bool
54 is_ancestor_of(const any* xother) const
55 {
56  // Preconditions:
57 
58  // Body:
59 
60  bool result = dynamic_cast<const visualization_iterator_1_3*>(xother) != 0;
61 
62  // Postconditions:
63 
64  // Exit
65 
66  return result;
67 }
68 
71 clone() const
72 {
73  // Preconditions:
74 
75  // Body:
76 
78  const_cast<visualization_iterator_1_3*>(this);
79 
82  cthis->property_schema());
83 
84  // Postconditions:
85 
86  // ensure(invariant());
87  ensure(result != 0);
88 
89  // Exit
90 
91  return result;
92 }
93 
94 bool
96 invariant() const
97 {
98  bool result = true;
99 
100  // Preconditions:
101 
102  // Body:
103 
104  if(invariant_check())
105  {
106  invariance(visualization_iterator::invariant());
107 
108  disable_invariant_check();
109 
110  invariance(order() == BIORDER);
111 
112  invariance((is_initialized() && has_property()) ?
113  !property_schema().rep().eval_is_above_disc() :
114  true);
115 
116  // Finished, turn invariant checking back on.
117 
118  enable_invariant_check();
119  }
120 
121  // Postconditions:
122 
123  // Exit
124 
125  return result;
126 }
127 
128 
129 // ===========================================================
130 // DEPTH_FIRST_ITERATOR FACET
131 // ===========================================================
132 
133 void
135 next(bool xtruncate)
136 {
137  // Preconditions:
138 
139  require(!is_done());
140 
141  // Body:
142 
143  // A set to contain discretization ids.
144 
145  int_set lvisited;
146 
147  bool ltruncate = xtruncate;
148 
149  // Traverse the graph gathering coord and prop disc members until
150  // we have enough context to evaluate the coordinates at the
151  // the property disc points or until the trversal is done.
152 
153  visualization_iterator::next(ltruncate);
154 
155  while(!is_done())
156  {
157  if(action() == PREVISIT_ACTION)
158  {
159  // The coord and prop eval are both the element subposet and
160  // the coord disc is the vertices. The prop disc is at or
161  // above the elements.
162 
163  _at.vis_eval = _vis_state.eval_sp.contains_member(_index);
164  _at.vis_disc = _vis_state.disc_sp.contains_member(_index);
165  _at.prop_disc = _prop_state.disc_sp.contains_member(_index);
166 
167  if(!_maximal_eval_id.is_valid() && _at.vis_eval)
168  {
169  _above.vis_eval = false;
170  _maximal_eval_id = _index;
171 
172  // Turn off put_visit_once.
173 
174  put_visit_once(false);
175 
176  _vis_state.set_evaluation_member(_index);
177  _vis_state.initialize_order_correction();
178  _vis_state.discretization_members.set_ct(0);
179 
180  _prop_state.set_evaluation_member(_index);
181  }
182 
183  if(_at.vis_disc)
184  {
185  _above.vis_disc = false;
186 
187  int lid = _index.hub_pod();
188  if(!lvisited.contains(lid))
189  {
190  lvisited.insert(lid);
191  _vis_state.gather_discretization_member(_index, greater_index());
192  _vis_state.local_id++;
193  }
194 
195  ltruncate = true;
196  }
197 
198  if(_at.prop_disc)
199  {
200  _prop_state.discretization_members.set_ct(0);
201  _prop_state.gather_discretization_member(_index);
202  }
203 
204  }
205  else if(action() == POSTVISIT_ACTION)
206  {
207  if(_maximal_eval_id ==~ index())
208  {
209  _maximal_eval_id.invalidate();
210 
211  // Turn off put_visit_once.
212 
213  put_visit_once(true);
214 
215  _above.vis_eval = true;
216 
217  break;
218  }
219 
220  // If we invoke visualization_iterator::next() from the postvisit action,
221  // the truncation flag will be ignored, since you can only truncate
222  // in the previsit action. But just to be specific, we'll set it false no
223  // matter what we've done here.
224 
225  ltruncate = false;
226  }
227  else
228  {
229  post_fatal_error_message("unrecognized action");
230  }
231 
232  visualization_iterator::next(ltruncate);
233 
234  } // end while(!is_done())
235 
236  // Postconditions:
237 
238  ensure(invariant());
239  ensure(!is_done() ? action() == POSTVISIT_ACTION : true);
240 
241  // Exit
242 
243  return;
244 }
245 
246 // ===========================================================
247 // VISUALIZATION_ITERATOR FACET
248 // ===========================================================
249 
250 void
252 set_vtk_data(const sec_vd& xcoords,
253  const sec_vd& xprop,
254  vtkDoubleArray* xvtk_pt_coords,
255  vtkDoubleArray* xvtk_prop,
256  int xprop_tensor_rank,
257  block<int>& xvtk_cell_types,
258  block<vtkIdType>& xvtk_cell_connectivity,
259  block<int>& xvtk_cell_type_map,
260  vtkIdTypeArray* xvtk_pt_label_ids,
261  vtkIdTypeArray* xvtk_cell_label_ids)
262 {
263  // Preconditions:
264 
265  require(xcoords.state_is_read_accessible());
266  require(xcoords.schema().is_same_state(&coordinates_schema()));
267 
268  require(xprop.state_is_read_accessible());
269  require(xprop.schema().is_same_state(&property_schema()));
270 
273 
274  require(xcoords.schema().df() <= 3);
275 
276  // Body:
277 
278 #ifdef DIAGNOSTIC_OUTPUT
279  cout << "id: " << index()
280  << " eval_id: " << _vis_state.eval_id
281  << endl;
282 #endif
283 
284  typedef unordered_map<pod_index_type, pod_index_type> map_type;
285  typedef map_type::const_iterator iterator_type;
286 
287  int lprop_df = xprop.schema().df();
288  block<discretization_context>& ldisc_mbrs = _vis_state.discretization_members;
289  size_type ldisc_ct = ldisc_mbrs.ct();
290  map_type* lmap = _vis_state.disc_to_seq_map;
291 
292  const index_space_handle& ldisc_id_space =
293  xcoords.schema().discretization_id_space();
294 
295  // Transfer the cell label ids.
296 
297  pod_index_type lvtk_cell_id =
298  _use_cell_top_ids ?
299  _vis_state.eval_id.hub_pod() :
300  xcoords.schema().evaluation().id_space().pod(_vis_state.eval_id);
301 
302  xvtk_cell_label_ids->InsertNextValue(lvtk_cell_id);
303 
304  // Transfer the cell type.
305 
306  xvtk_cell_types.push_back(xvtk_cell_type_map[_vis_state.eval_type_id]);
307 
308  // Transfer the connectivity count.
309 
310  xvtk_cell_connectivity.push_back(ldisc_ct);
311 
312  for(size_type i=0; i<ldisc_ct; ++i)
313  {
314  scoped_index ldisc_id = ldisc_mbrs[i].disc_id;
315  pod_index_type ldisc_pod = ldisc_id.hub_pod();
316  iterator_type lmap_itr = lmap->find(ldisc_pod);
317 
318 #ifdef DIAGNOSTIC_OUTPUT
319  cout << "\tdisc_id: " << setw(6) << ldisc_id;
320 #endif
321 
322  pod_index_type lseq_id;
323 
324  if(lmap_itr == lmap->end())
325  {
326  // Haven't visited this vertex before.
327  // Create a seq id for it.
328 
329  lseq_id = _vis_state.next_seq_id++;
330  (*lmap)[ldisc_pod] = lseq_id;
331 
332 #ifdef DIAGNOSTIC_OUTPUT
333  cout << " seq_id:" << setw(6) << lseq_id;
334 #endif
335 
336  // Transfer the coordinate data
337 
338  xcoords.get_fiber(ldisc_id, _coord_dofs,
339  static_cast<size_type>(COORD_DOFS_UB)*sizeof(sec_vd_dof_type), false);
340 
341  xvtk_pt_coords->SetTuple(lseq_id, _coord_dofs);
342 
343  // Transfer the point label ids.
344 
345  pod_index_type lvtk_pt_id =
346  _use_point_top_ids ?
347  ldisc_id.hub_pod() : ldisc_id_space.pod(ldisc_id);
348 
349  xvtk_pt_label_ids->SetValue(lseq_id, lvtk_pt_id);
350 
351 #ifdef DIAGNOSTIC_OUTPUT
352  cout << " coords: "
353  << setw(6) << _coord_dofs[0]
354  << setw(6) << _coord_dofs[1]
355  << setw(6) << _coord_dofs[2];
356 #endif
357  }
358  else
359  {
360  lseq_id = lmap_itr->second;
361 
362 #ifdef DIAGNOSTIC_OUTPUT
363  cout << " seq_id:" << setw(6) << lseq_id;
364 #endif
365 
366  }
367 
368 #ifdef DIAGNOSTIC_OUTPUT
369  cout << endl;
370 #endif
371 
372  // Transfer the connectivity.
373 
374  xvtk_cell_connectivity.push_back(lseq_id);
375  }
376 
377  // Transfer the property data and increment the cell seq id.
378 
379  scoped_index lprop_disc_id = _prop_state.discretization_members[0].disc_id;
380 
381  xprop.get_fiber(lprop_disc_id, _prop_dofs,
382  static_cast<size_type>(PROP_DOFS_UB)*sizeof(sec_vd_dof_type), false);
383 
384  put_prop_dofs(_prop_dofs, lprop_df, xprop_tensor_rank, xvtk_prop, _cell_seq_id++);
385 
386  assertion(_cell_seq_id == xvtk_cell_types.ct());
387 
388 #ifdef DIAGNOSTIC_OUTPUT
389  cout << "\tprop seq id: " << setw(6) << (_vis_state.eval_id - 1);
390  cout << " prop: " << setw(10) << _prop_dofs[0] << endl;
391 #endif
392 
393  // Postconditions:
394 
395  // Exit:
396 
397  return;
398 }
399 
400 void
402 set_vtk_data(const sec_vd& xcoords,
403  vtkDoubleArray* xvtk_pt_coords,
404  block<int>& xvtk_cell_types,
405  block<vtkIdType>& xvtk_cell_connectivity,
406  block<int>& xvtk_cell_type_map,
407  vtkIdTypeArray* xvtk_pt_label_ids,
408  vtkIdTypeArray* xvtk_cell_label_ids)
409 {
410  // Preconditions:
411 
412  require(xcoords.state_is_read_accessible());
413  require(xcoords.schema().is_same_state(&coordinates_schema()));
414 
417 
418  require(xcoords.schema().df() <= 3);
419 
420  // Body:
421 
422 #ifdef DIAGNOSTIC_OUTPUT
423  cout << "id: " << index()
424  << " eval_id: " << _vis_state.eval_id
425  << endl;
426 #endif
427 
428  typedef unordered_map<pod_index_type, pod_index_type> map_type;
429  typedef map_type::const_iterator iterator_type;
430 
431  block<discretization_context>& ldisc_mbrs = _vis_state.discretization_members;
432  size_type ldisc_ct = ldisc_mbrs.ct();
433  map_type* lmap = _vis_state.disc_to_seq_map;
434 
435  const index_space_handle& ldisc_id_space =
436  xcoords.schema().discretization_id_space();
437 
438  // Transfer the cell label ids.
439 
440  pod_index_type lvtk_cell_id =
441  _use_cell_top_ids ?
442  _vis_state.eval_id.hub_pod() :
443  xcoords.schema().evaluation().id_space().pod(_vis_state.eval_id);
444 
445  xvtk_cell_label_ids->InsertNextValue(lvtk_cell_id);
446 
447  // Transfer the cell type.
448 
449  xvtk_cell_types.push_back(xvtk_cell_type_map[_vis_state.eval_type_id]);
450 
451  // Transfer the connectivity count.
452 
453  xvtk_cell_connectivity.push_back(ldisc_ct);
454 
455  for(size_type i=0; i<ldisc_ct; ++i)
456  {
457  scoped_index ldisc_id = ldisc_mbrs[i].disc_id;
458  pod_index_type ldisc_pod = ldisc_id.hub_pod();
459  iterator_type lmap_itr = lmap->find(ldisc_pod);
460 
461 #ifdef DIAGNOSTIC_OUTPUT
462  cout << "\tdisc_id: " << setw(6) << ldisc_id;
463 #endif
464 
465  pod_index_type lseq_id;
466 
467  if(lmap_itr == lmap->end())
468  {
469  // Haven't visited this vertex before.
470  // Create a seq id for it.
471 
472  lseq_id = _vis_state.next_seq_id++;
473  (*lmap)[ldisc_pod] = lseq_id;
474 
475 #ifdef DIAGNOSTIC_OUTPUT
476  cout << " seq_id:" << setw(6) << lseq_id;
477 #endif
478 
479  // Transfer the coordinate data
480 
481  xcoords.get_fiber(ldisc_id, _coord_dofs,
482  static_cast<size_type>(COORD_DOFS_UB)*sizeof(sec_vd_dof_type), false);
483 
484  xvtk_pt_coords->SetTuple(lseq_id, _coord_dofs);
485 
486  // Transfer the point label ids.
487 
488  pod_index_type lvtk_pt_id =
489  _use_point_top_ids ?
490  ldisc_id.hub_pod() : ldisc_id_space.pod(ldisc_id);
491 
492  xvtk_pt_label_ids->SetValue(lseq_id, lvtk_pt_id);
493 
494 #ifdef DIAGNOSTIC_OUTPUT
495  cout << " coords: "
496  << setw(6) << _coord_dofs[0]
497  << setw(6) << _coord_dofs[1]
498  << setw(6) << _coord_dofs[2];
499 #endif
500  }
501  else
502  {
503  lseq_id = lmap_itr->second;
504 
505 #ifdef DIAGNOSTIC_OUTPUT
506  cout << " seq_id:" << setw(6) << lseq_id;
507 #endif
508 
509  }
510 
511 #ifdef DIAGNOSTIC_OUTPUT
512  cout << endl;
513 #endif
514 
515  // Transfer the connectivity.
516 
517  xvtk_cell_connectivity.push_back(lseq_id);
518  }
519 
520  // Postconditions:
521 
522  // Exit:
523 
524  return;
525 }
526 
527 void
529 set_vtk_data(const sec_vd& xprop,
530  vtkDoubleArray* xvtk_prop,
531  int xprop_tensor_rank)
532 {
533  // Preconditions:
534 
535  require(xprop.state_is_read_accessible());
536  require(xprop.schema().is_same_state(&property_schema()));
537 
538  // Body:
539 
540  // Transfer the property data and increment the cell seq id.
541 
542  scoped_index lprop_disc_id = _prop_state.discretization_members[0].disc_id;
543 
544  xprop.get_fiber(lprop_disc_id, _prop_dofs,
545  static_cast<size_type>(PROP_DOFS_UB)*sizeof(sec_vd_dof_type), false);
546 
547 #ifdef DIAGNOSTIC_OUTPUT
548  cout << "\tid: " << index() << " eval_id: " << _vis_state.eval_id;
549  cout << " prop seq id: " << setw(6) << _cell_seq_id;
550  cout << " prop: " << setw(10) << _prop_dofs[0] << endl;
551 #endif
552 
553  int lprop_df = xprop.schema().df();
554  put_prop_dofs(_prop_dofs, lprop_df, xprop_tensor_rank, xvtk_prop,
555  _cell_seq_id++);
556 
557  // Postconditions:
558 
559  // Exit:
560 
561  return;
562 }
563 
564 // ===========================================================
565 // VISUALIZATION_ITERATOR_1_3 FACET
566 // ===========================================================
567 
571 {
572  // Preconditions:
573 
574  // Body:
575 
576  // Postconditions:
577 
578  ensure(!is_initialized());
579 
580  // Exit:
581 
582  return;
583 }
584 
587  const section_space_schema_member& xproperty_schema)
589 {
590 
591  // Preconditions:
592 
593  require(xcoordinates_schema.state_is_read_accessible());
594  require(xcoordinates_schema.base_space().schema().\ conforms_to(base_space_member::standard_schema_path()));
595  require(xproperty_schema.state_is_read_accessible());
596  require(xproperty_schema.base_space().le(&xcoordinates_schema.base_space()));
597  require(!xproperty_schema.rep().eval_is_above_disc());
598 
599  // Body:
600 
601  put_anchor(xcoordinates_schema, xproperty_schema);
602  reset();
603 
604  // Postconditions:
605 
606  ensure(invariant());
607  ensure(is_initialized());
608  ensure(coordinates_schema().is_same_state(&xcoordinates_schema));
609  ensure(coordinates_schema().is_same_type(&xcoordinates_schema));
610  ensure(coordinates_schema().version() == xcoordinates_schema.version());
611  ensure(has_property());
612  ensure(property_schema().is_same_state(&xproperty_schema));
613  ensure(property_schema().is_same_type(&xproperty_schema));
614  ensure(property_schema().version() == xproperty_schema.version());
615  ensure(descending());
616  ensure(!strict());
617  ensure(unexecutable(!is_done() implies this is first member));
618 
619  // Exit:
620 
621  return;
622 }
623 
626 {
627  // Preconditions:
628 
629  // Body:
630 
631  // Postconditions:
632 
633  // Exit:
634 
635 }
636 
637 // ===========================================================
638 // PROTECTED MEMBER FUNCTIONS
639 // ===========================================================
640 
641 // =============================================================================
642 // PRIVATE MEMBER FUNCTIONS
643 // =============================================================================
644 
645 
646 
An STL set representation for a set of integers.
Definition: int_set.h:47
bool contains(int xindex) const
True if this set contains xindex Deprecated - use contains_member(int xindex)
Definition: int_set.h:104
visualization_iterator_1_3()
Creates an uninitialized iterator.
int version(bool xunalias=true) const
The (possibly aliased) version of this component. The version of the host used when evaluating proper...
size_type ct() const
The number of items currently in use.
virtual bool is_initialized() const
True if this has been initialized for iteration with respect to a specific anchor.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
void get_fiber(pod_index_type xdisc_id, vd_lite &xfiber) const
Sets xfiber to the fiber referred to by discretization id xdisc_id.
Definition: sec_vd.cc:1087
subposet & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
bool has_property() const
True if this visualization has a property section.
STL namespace.
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...
virtual pod_type pod(pod_type xid) const
The pod index in this space equivalent to xid in the hub id space.
Namespace for the tools component of the sheaf system.
Abstract base class with useful features for all objects.
Definition: any.h:39
void push_back(const_reference_type item)
Insert item at the end of the items in the auto_block.
bool eval_is_above_disc() const
True is the evaluation subposet is strictly above the discretization subposet.
bool invariant() const
The class invariant.
const section_space_schema_member & coordinates_schema() const
The coordinates field schema member which is being iterated over.
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
virtual bool is_ancestor_of(const any *xother) const
True if other conforms to this.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
bool descending() const
True if iterating over down set of anchor.
virtual void set_vtk_data(const sec_vd &xcoords, const sec_vd &xprop, vtkDoubleArray *xvtk_pt_coords, vtkDoubleArray *xvtk_prop, int xprop_tensor_rank, block< int > &xvtk_cell_types, block< vtkIdType > &xvtk_cell_connectivity, block< int > &xvtk_cell_type_map, vtkIdTypeArray *xvtk_pt_label_ids, vtkIdTypeArray *xvtk_cell_label_ids)
Transfers coordinate and property data to vtk data structures.
virtual visualization_iterator_1_3 * clone() const
Make a new instance of the same type as this.
bool le(pod_index_type xother_index) const
True if this is less than or equal to the member with index xother_index.
A visualization iterator for a coordinate section with discretization equal to vertices and property ...
void next()
Makes this the next member of the subset.
bool invariant() const
The class invariant.
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.
Definition: sec_vd.h:54
bool is_done() const
True if iteration finished.
const scattered_insertion_index_space_handle & id_space() const
The id space for the members of with this (const version).
Definition: subposet.cc:508
static const poset_path & standard_schema_path()
The path of the schema required by this class.
pod_type hub_pod(pod_type xid) const
The pod index in the unglued hub id space equivalent to xid in this id space; synonym for unglued_hub...
void first()
Moves this to the first member of the iteration.
Abstract iterator over the schema of both the coordinates and property sections of a visualization...
virtual void put_anchor(const section_space_schema_member &xcoords_schema, const section_space_schema_member &xprop_schema)
Reinitializes anchor() to iterate over xcoord_schema and xprop_schema.
total_poset_member & base_space()
The base space component of this (mutable version).
const index_space_handle & discretization_id_space() const
The id space for the discretization members in the down set of the base space of this (const version)...
virtual section_space_schema_member & schema()
The restricted schema for this (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
A client handle for a poset member which has been prepared for use as a schema for a section space...
virtual void reset(bool xreset_markers=true)
Restarts the iteration over the down set of anchor().
const section_space_schema_member & property_schema() const
The property field schema member which is being iterated over.
int df() const
The dimension of the fiber space component.
double sec_vd_dof_type
The type of degree of freedom in the section space.
Definition: fiber_bundle.h:78
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).
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
bool strict() const
True if iterating over xstrict up/down set of anchor.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710