SheafSystem  0.0.0.0
vtk_abstract_grid_builder.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 vtk_abstract_grid_builder
19 
20 #include "SheafSystem/vtk_abstract_grid_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 
26 #include "vtkUnstructuredGrid.h"
27 #include "vtkUnstructuredGridWriter.h"
28 #include "vtkDoubleArray.h"
29 #include "vtkFieldData.h"
30 #include "vtkIdTypeArray.h"
31 #include "vtkIntArray.h"
32 #include "vtkPoints.h"
33 #include "vtkCellArray.h"
34 #include "vtkPointData.h"
35 #include "vtkCellData.h"
36 
37 //#unfine DIAGNOSTIC_OUTPUT
38 // #define DIAGNOSTIC_OUTPUT
39 
40 // Workaround for MS Visual C++
41 using namespace tool;
42 using namespace std;
43 
44 // ============================================================================
45 // ANY FACET
46 // ============================================================================
47 
49 bool
51 is_ancestor_of(const any* other) const
52 {
53 
54  // Preconditions:
55 
56  require(other != 0);
57 
58  // Body:
59 
60  // True if other conforms to this
61 
62  bool result = dynamic_cast<const vtk_abstract_grid_builder*>(other) != 0;
63 
64  // Postconditions:
65 
66  return result;
67 }
68 
69 
70 
74 clone() const
75 {
76  vtk_abstract_grid_builder* result = 0; // Just to silence compiler warnings.
77 
78  // Preconditions:
79 
80  // Body:
81 
82  is_abstract();
83 
84  // Postconditions:
85 
86  // Exit:
87 
88  return result;
89 }
90 
91 
96 {
97 
98  // Preconditions:
99 
100 
101  // Body:
102 
103  is_abstract();
104 
105  // Postconditions:
106 
107  ensure(invariant());
108 
109  // Exit
110 
111  return *this;
112 }
113 
115 bool
117 invariant() const
118 {
119  bool result = true;
120 
121  if(invariant_check())
122  {
123  // Prevent recursive calls to invariant
124 
125  disable_invariant_check();
126 
127  // Must satisfy base class invariant
128 
129  invariance(any::invariant());
130 
131  // Invariances for this class:
132 
133  // Finished, turn invariant checking back on.
134 
135  enable_invariant_check();
136  }
137 
138  // Exit
139 
140  return result;
141 }
142 
143 
144 
145 // ============================================================================
146 // VTK_DATA_SET_BUILDER FACET
147 // ============================================================================
148 
152 {
153 
154  // Preconditions:
155 
156 
157  // Body:
158 
159  // Nothing to do.
160 
161  // Postconditions:
162 
163  // Exit:
164 
165  return;
166 }
167 
169 void
172 {
173  // Preconditions:
174 
175  // Body:
176 
177  is_abstract();
178 
179  // Postconditions:
180 
181  // Exit:
182 
183  return;
184 }
185 
187 vtkUnstructuredGrid*
189 build(const sec_vd& xcoords, const sec_vd& xproperty)
190 {
191  vtkUnstructuredGrid* result;
192 
193  // Preconditions:
194 
195  require(xcoords.state_is_read_accessible());
197  require(xcoords.schema().df() <= 3);
198  require(xproperty.state_is_read_accessible());
199  require(xproperty.schema().base_space().is_same_state(&xcoords.schema().base_space()));
200  require(xproperty.schema().evaluation().is_same_state(&xcoords.schema().evaluation()));
201 
202  // Body:
203 
204  result = vtkUnstructuredGrid::New();
205 
206  build_pa(xcoords, xproperty, *result);
207 
208  // Postconditions:
209 
210 
211  // Exit:
212 
213  return result;
214 }
215 
217 vtkUnstructuredGrid*
219 build(const sec_vd& xcoords, const sec_vd& xproperty1, const sec_vd& xproperty2)
220 {
221  vtkUnstructuredGrid* result;
222 
223  // Preconditions:
224 
225  require(xcoords.state_is_read_accessible());
227  require(xcoords.schema().df() <= 3);
228  require(xproperty1.state_is_read_accessible());
229  require(xproperty1.schema().base_space().is_same_state(&xcoords.schema().base_space()));
230  require(xproperty1.schema().evaluation().is_same_state(&xcoords.schema().evaluation()));
231  require(xproperty2.state_is_read_accessible());
232  require(xproperty2.schema().base_space().is_same_state(&xcoords.schema().base_space()));
233  require(xproperty2.schema().evaluation().is_same_state(&xcoords.schema().evaluation()));
234 
235  // Body:
236 
237  result = vtkUnstructuredGrid::New();
238 
239  build_pa(xcoords, xproperty1, xproperty2, *result);
240 
241  // Postconditions:
242 
243 
244  // Exit:
245 
246  return result;
247 }
248 
250 vtkUnstructuredGrid*
252 build(const sec_vd& xcoords)
253 {
254  vtkUnstructuredGrid* result;
255 
256  // Preconditions:
257 
258  require(xcoords.state_is_read_accessible());
260  require(xcoords.schema().df() <= 3);
261 
262  // Body:
263 
264  result = vtkUnstructuredGrid::New();
265 
266  build_pa(xcoords, *result);
267 
268  // Postconditions:
269 
270 
271  // Exit:
272 
273  return result;
274 }
275 
277 void
279 build_pa(const sec_vd& xcoords, const sec_vd& xproperty, vtkUnstructuredGrid& xresult)
280 {
281  // Preconditions:
282 
283  // Body:
284 
285  is_abstract();
286 
287  // Postconditions:
288 
289 
290  // Exit:
291 
292  return;
293 }
294 
296 void
298 build_pa(const sec_vd& xcoords, const sec_vd& xproperty1,
299  const sec_vd& xproperty2, vtkUnstructuredGrid& xresult)
300 {
301  // Preconditions:
302 
303  // Body:
304 
305  is_abstract();
306 
307  // Postconditions:
308 
309 
310  // Exit:
311 
312  return;
313 }
314 
316 void
318 build_pa(const sec_vd& xcoords, vtkUnstructuredGrid& xresult)
319 {
320  // Preconditions:
321 
322  // Body:
323 
324  is_abstract();
325 
326  // Postconditions:
327 
328 
329  // Exit:
330 
331  return;
332 }
333 
334 bool
337 {
338  return _use_point_top_ids;
339 }
340 
341 void
344 {
345  _use_point_top_ids = xvalue;
346 
347  ensure(use_point_top_ids() == xvalue);
348 
349  return;
350 }
351 
352 bool
355 {
356  return _use_cell_top_ids;
357 }
358 
359 void
362 {
363  _use_cell_top_ids = xvalue;
364 
365  ensure(use_cell_top_ids() == xvalue);
366 
367  return;
368 }
369 
370 vtkIdTypeArray*
373 {
374  return _vtk_pt_label_ids;
375 }
376 
377 vtkIdTypeArray*
380 {
381  return _vtk_cell_label_ids;
382 }
383 
386 {
387  // Preconditions:
388 
389 
390  // Body:
391 
392  _vtk_pt_label_ids = 0;
393  _vtk_cell_label_ids = 0;
394 
395  _use_point_top_ids = true;
396  _use_cell_top_ids = true;
397 
398  // Postconditions:
399 
400 
401  // Exit:
402 
403  return;
404 }
405 
406 // ============================================================================
407 // NON-MEMBER FUNCTIONS
408 // ============================================================================
409 
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
Definition: any.cc:153
void build_pa(const sec_vd &xcoords, const sec_vd &xproperty, vtkUnstructuredGrid &xresult)
Builds a vtkUnstructuredGrid from xcoords and xproperty (pre-allocated version).
vtk_abstract_grid_builder()
Defualt constructor.
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 & evaluation()
The evaluation subposet for section spaces on this schema (mutable version).
void put_use_point_top_ids(bool xvalue)
Sets use_point_top_ids() to xvalue.
virtual bool invariant() const
Class invariant.
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.
bool use_cell_top_ids() const
If true use top ids to label cells; otherwise, use evaluation ids.
Abstract class for creating a vtkUnstructuredGrid from sheaf field objects.
vtkIdTypeArray * vtk_cell_label_ids() const
Array of top ids for cells.
Namespace for the tools component of the sheaf system.
vtkIdTypeArray * vtk_pt_label_ids() const
Array of top ids for points.
Abstract base class with useful features for all objects.
Definition: any.h:39
void put_use_cell_top_ids(bool xvalue)
Sets use_cell_top_ids() to xvalue.
void set_name_space(namespace_poset &xns)
If this instance&#39;s namespace is not equal to xns, this instance is initialized to have namespace xns...
A section of a fiber bundle with a d-dimensional vector space fiber.
Definition: sec_vd.h:54
vtkUnstructuredGrid * build(const sec_vd &xcoords, const sec_vd &xproperty)
Builds a vtkUnstructuredGrid from xcoords and xproperty.
static const poset_path & standard_schema_path()
The path of the schema required by this class.
virtual vtk_abstract_grid_builder & operator=(const vtk_abstract_grid_builder &xother)
Assignment operator.
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 bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual vtk_abstract_grid_builder * clone() const
Virtual constructor, makes a new instance of the same type as this.
int df() const
The dimension of the fiber space component.
bool use_point_top_ids() const
If true use top ids to label points; otherwise, use discretization ids.
virtual schema_poset_member & schema()
The schema for this member (mutable version).