FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
grid/types/RegularlyFragmentedGrid.hpp
1#ifndef __FIBER_GRID_TYPES_REGULARLYFRAGMENTEDREGULARGRID_HPP
2#define __FIBER_GRID_TYPES_REGULARLYFRAGMENTEDREGULARGRID_HPP
3
4
5#include "GridWithCartesianVertices.hpp"
6#include "fish/fiber/field/UniformCartesianArray.hpp"
7#include "fish/fiber/field/RegularlyFragmentedField.hpp"
8
9
10namespace Fiber
11{
12
13extern gridtypes_API SkeletonID computeFragmentSkeletonID(const DynamicSize&Fragmentation, const SkeletonID&SID);
14extern gridtypes_API SkeletonID computeFragmentSkeletonID(const Field&F, const SkeletonID&SID);
15
16extern gridtypes_API bool createRegularlyFragmentedSkeleton( Grid&, const RefPtr<Skeleton>&, const FragmentIDCollection&FIC);
17extern gridtypes_API bool createRegularlyFragmentedSkeleton( Grid&, const RefPtr<Skeleton>&, const Field&FragmentedField);
18extern gridtypes_API bool createRegularlyFragmentedSkeleton( Grid&, const RefPtr<Skeleton>&);
19extern gridtypes_API bool createRegularlyFragmentedSkeleton( Grid&, const Skeleton&, const FragmentIDCollection&FIC);
20extern gridtypes_API bool createRegularlyFragmentedSkeleton( Grid&, const Skeleton&);
21
22
26{
27static SkeletonID FragmentVerticesSkeletonID()
28 {
29 return SkeletonID(0, 2);
30 }
31
32static SkeletonID computeFragmentSkeletonID(const Field&F, const SkeletonID&SID);
33
34
40
41 bool assign(const RefPtr<Grid>&theGrid)
42 {
43 if (!TypedGrid::assign(theGrid) ) return false;
44
45 Grid&G = *theGrid;
46 FragmentVerticesSkeleton = G( FragmentVerticesSkeletonID() );
47
48 if (!FragmentVerticesSkeleton) return false;
49
50 return true;
51 }
52
53static void create( Grid&myGrid )
54 {
55 myGrid[ FragmentVerticesSkeletonID() ];
56 }
57#if 0
58static bool
59 createFragmentSkeleton( Grid&myGrid, const RefPtr<Skeleton>&Vertices,
60 const Field&VertexPositions,
61 Skeleton&FragmentSkeleton);
62#endif
63
64};
65
66
69template <int VertexDims>
71{
72static constexpr int Dims = VertexDims;
73
74static SkeletonID FragmentSkeletonID(int IndexDepth=0,int RefLevel = 0)
75 {
76 SkeletonID SID(VertexDims, IndexDepth + 2);
77
78 if (RefLevel > 0)
79 SID.setIsotropicRefinement( RefLevel );
80
81 return SID;
82 }
83
84static SkeletonID ID()
85 {
86 return FragmentSkeletonID();
87 }
88
89static SkeletonID FragmentSkeletonID(const SkeletonID&S)
90 {
91 return SkeletonID( S.DomainSize(), S.IndexDepth()+2, S.RefinementSize() );
92 }
93
95
100
102
103 RefPtr<FragmentArray_t> FragmentArray;
104
110 {
111 if (FragmentArray)
112 return FragmentArray->Size();
113
114 return MultiIndex<VertexDims>();
115 }
116
117
123 {
124 if (FragmentArray)
125 return (*FragmentArray)[FragmentIndex];
126
127 return NullPtr();
128 }
129
130
131 RegularlyFragmentedGrid(const RefPtr<Grid>&G = nullptr)
132 {
133 assign(G);
134 }
135
136
137 bool assign(const RefPtr<Grid>&theGrid)
138 {
139 FragmentSkeleton = nullptr;
140 FragmentsAsVertices = nullptr;
141 FragmentArray = nullptr;
142
143 if (!RegularlyFragmentedGridBase::assign(theGrid) ) return false;
144
145 Grid&G = *theGrid;
146 FragmentSkeleton = G( FragmentSkeletonID() );
147 if (!FragmentSkeleton) return false;
148
149 RefPtr<Skeleton> Vertices = G.findVertices();
150 if (!Vertices) return false;
151
152 FragmentsAsVertices = (*FragmentSkeleton)( *Vertices );
153
154 if (!FragmentsAsVertices) return false;
155
156 if (RefPtr<Field> FragmentField = FragmentsAsVertices->getPositions() )
157 FragmentArray = FragmentField->getData();
158
159 return true;
160 }
161
168static RegularlyFragmentedGrid
170 {
171 RegularlyFragmentedGridBase::create( myGrid );
172
173 RefPtr<Skeleton> Vertices = myGrid.findVertices();
174 if (!Vertices)
175 return RegularlyFragmentedGrid( nullptr );
176
177// RefPtr<Skeleton> pFragmentSkeleton = myGrid( FragmentSkeletonID(FragmentedSkeletonID) );
178 Skeleton&FragmentSkeleton = myGrid[ FragmentSkeletonID(FragmentedSkeletonID) ];
179
180 return createFragmentSkeleton( myGrid, Vertices, VertexPositions, FragmentSkeleton);
181 }
182
184 create( Grid&myGrid, const RefPtr<RegularlyFragmentedField<VertexDims> >&VertexPositions,
185 const RefPtr<Skeleton>&Vertices)
186 {
187 if (!Vertices) return RegularlyFragmentedGrid( nullptr );
188
189 RegularlyFragmentedGridBase::create( myGrid );
190
191 Skeleton&FragmentSkeleton = myGrid[ FragmentSkeletonID(*Vertices) ];
192
193 return createFragmentSkeleton( myGrid, Vertices, VertexPositions, FragmentSkeleton);
194 }
195
196static RegularlyFragmentedGrid
197 create( Grid&myGrid, const RefPtr<RegularlyFragmentedField<VertexDims> >&VertexPositions)
198 {
199 RegularlyFragmentedGridBase::create( myGrid );
200
201 int IndexDepth=0; int RefLevel=0;
202 Assert( IndexDepth == 0 );
203 RefPtr<Skeleton> Vertices = myGrid.findVertices();
204 if (!Vertices)
205 return RegularlyFragmentedGrid( nullptr );
206
207// RefPtr<Skeleton> pFragmentSkeleton = myGrid( FragmentSkeletonID(IndexDepth,RefLevel) );
208 Skeleton&FragmentSkeleton = myGrid[ FragmentSkeletonID(IndexDepth,RefLevel) ];
209
210 return createFragmentSkeleton( myGrid, Vertices, VertexPositions, FragmentSkeleton);
211 }
212
213static RegularlyFragmentedGrid
214 createFragmentSkeleton( Grid&myGrid, const RefPtr<Skeleton>&Vertices,
215 const RefPtr<RegularlyFragmentedField<VertexDims> >&VertexPositions,
216 Skeleton&FragmentSkeleton)
217 {
218 Assert( VertexPositions );
219 Assert( VertexPositions->getFragmentIDCollection() );
220 Assert( VertexPositions->getFragmentIDCollection()->getFragmentLayout().isValid() );
221 if (!VertexPositions->getFragmentIDCollection()->getFragmentLayout().isValid() )
222 {
223 Verbose(0) << " NOTE: RegularlyFragmentedGrid::createFragmentSkeleton() got a regularly fragmented field without fragment layout.";
224 }
225
226 //
227 // Note: Vertices dimensionality is -1 yet at this point because we don't have data there so far.
228 // because no field is defined on the representations yet. And we can't define a field yet
229 // because we want to save it later, and we can't save it until all the representations
230 // have been defined because these will not be saved on demand.
231 //
232 Representation&FragmentsAsVertices = FragmentSkeleton[ *Vertices ];
233
234 if (RefPtr<Field> HaveField = FragmentsAsVertices.getPositions())
235 {
236 AppVerbose("FiberLib",10) << "Info: RegularlyFragmentedGrid creating found fragments as Vertices";
237 }
238
239 if (!FragmentsAsVertices.getPositions())
240 {
241// RefPtr<MemArrayBase<VertexDims> >
242 RefPtr<MemBase>
243 FragmentTopologyField = VertexPositions->newFragmentationArray();
244
245#if 0
246 Verbose(0) << "VertexPositions fragments are " << VertexPositions->getNumberOfFragments();
247 Verbose(0) << "FragmentTopologyField is of size " << FragmentTopologyField->Size();
248
249 if (!pFragmentSkeleton)
250 {
251 Verbose(0) << "FragmentSkeleton has no size yet, freshly created.";
252 }
253#endif
254
255 if (!FragmentsAsVertices.setPositions( new Field( FragmentTopologyField->self() )) )
256 {
257 AppVerbose("FiberLib",0) << "CANNOT set positions for RegularlyFragmentedGrid Fragments as Vertices - wrong size!? "
258 << " VertexPositions fragments are " << VertexPositions->getNumberOfFragments()
259 << " FragmentTopologyField is of size " << FragmentTopologyField->getSize();
260 return RegularlyFragmentedGrid(nullptr);
261 }
262
263/*
264 if (FragmentsAsVertices.getSize())
265 Verbose(0) << " FragmentsAsVertices have size " << *FragmentsAsVertices.getSize();
266
267 Verbose(0) << "Fragment Skeleton has size " << FragmentSkeleton.Size();
268*/
269 }
270
271 return RegularlyFragmentedGrid( myGrid.self() );
272 }
273
274
275static RegularlyFragmentedGrid
276 createWithCartesianVertices( Grid&myGrid, const MultiIndex<VertexDims>&NumberOfFragments)
277 {
278 RefPtr<RegularlyFragmentedField<VertexDims> >
279 Positions = new RegularlyFragmentedField<VertexDims>(NumberOfFragments);
280
281 GridWithCartesianVertices::create( myGrid, VertexDims, Positions);
282
283 return create(myGrid, Positions);
284 }
285
286};
287
288
291template <int VertexDims>
294{
296
302
308
311
312
313 RefPtr<CreativeArrayBase> getCoordCreator(const MultiIndex<VertexDims>&I) const
314 {
315 if (Positions)
316 return (*Positions)(I);
317
318 return NullPtr();
319 }
320
321 RefPtr<MemBase> getCoordData(const MultiIndex<VertexDims>&I) const
322 {
323 if (RefPtr<CreativeArrayBase> CAB = getCoordCreator(I))
324 return CAB->create();
325
326 return NullPtr();
327 }
328
329 RefPtr<CoordsArray_t> getCoords(const MultiIndex<VertexDims>&I) const
330 {
331 return getCoordData(I);
332 }
333
339 {
341 return NullPtr();
342
345 (*CartesianVertices)[ Fieldname ] = Values;
346 return Values;
347 }
348
354 {
356 return NullPtr();
357
359 Values = (*CartesianVertices)( Fieldname );
360
361 if (!Values)
362 {
364 (*CartesianVertices)[ Fieldname ] = Values;
365 }
366
367 return Values;
368 }
369
375 {
376 if (Positions)
377 return Positions->getNumberOfFragments();
378
379 return MultiIndex<VertexDims>(0);
380 }
381
382
383 bool isValid() const
384 {
385 return getCoords( MultiIndex<VertexDims>(0) ).valid();
386 }
387
388 RegularlyFragmentedGridWithCartesianVertices()
389 {}
390
391 RegularlyFragmentedGridWithCartesianVertices(const RefPtr<Grid>&theGrid)
392 {
393 assign( theGrid );
394 }
395
396 bool assign(const RefPtr<Grid>&theGrid)
397 {
400 Positions = nullptr;
401
402 if (!GridWithCartesianVertices::assign(theGrid) ) return false;
403 if (!RegularlyFragmentedGrid<VertexDims>::assign(theGrid) ) return false;
404 if (!this->FragmentVerticesSkeleton) return false;
405
406 FragmentVerticesInCartesianCoordinates= (*this->FragmentVerticesSkeleton)( theGrid->findCartesianChart() );
408
409 if (this->FragmentSkeleton)
410 PerFragmentDataInCartesianCoordinates = (*this->FragmentSkeleton)( theGrid->findCartesianChart() );
411
412// if (!PerFragmentDataInCartesianCoordinates) return false;
413
414 Positions = CartesianPositions;
415 if (!Positions) return false;
416
417 return true;
418 }
419
420
421
427static RegularlyFragmentedGridWithCartesianVertices
429 bool NeedPerFragmentData = false)
430 {
431
434
435
436 if (myGrid.getCartesianPositions() )
437 {
438 if (!Positions)
439 {
440
441 Verbose(10) << "Positions with " << myGrid.getCartesianPositions()->nFragments()
442 << " fragments are already on the provided grid but incompatible as they are not regularly fragmented, cannot create regularly fragmented Grid.";
444 }
445
446 Verbose(50) << "HAVE Regular Positions with " << Positions->getNumberOfFragments() << " and want " << NumberOfFragments << " fragments.";
447
448 if (Positions->getNumberOfFragments() != NumberOfFragments)
450 }
451 else
452 {
454 }
455
456 // Positions are already on the provided grid but incompatible.
457 if (!Positions)
458 {
459 Verbose(10) << "Could not create Positions!?";
461 }
462
463 GridWithCartesianVertices::create( myGrid, VertexDims, Positions);
464
465 Verbose(0) << "Have cartesian vertices in " << Positions->nFragments()
466 << " fragments, add fragment topology for "
467 << Positions->getNumberOfFragments() <<" to Grid";
468
471 {
472
474 Assert(CartesianChart.valid());
475
476 Assert(RG.FragmentSkeleton.valid());
477
478 // it is sufficient to access the skeleton with the [] operator
479 // to create a Representation. This Representation will be
480 // used to story fragment-centered information in cartesian coordinates.
482 {
483 (*RG.FragmentSkeleton)[ CartesianChart ];
484 }
485
486 Assert(RG.FragmentVerticesSkeleton.valid());
487 (*RG.FragmentVerticesSkeleton)[ CartesianChart ];
488 }
489
490 return RegularlyFragmentedGridWithCartesianVertices( myGrid.self() );
491 }
492
493};
494
495
496
497} // namespace Fiber
498
499#endif // __FIBER_GRID_TYPES_REGULARLYFRAGMENTEDREGULARGRID_HPP
500
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
RefPtr< Chart > findCartesianChart(const string &name={}) const
Find a cartesian chart here.
Definition Grid.cpp:119
RefPtr< Field > getCartesianPositions() const
Shortcut function: get the coordinates of the vertices in the default cartesian chart.
Definition Grid.hpp:246
static RefPtr< RegularlyFragmentedField > newField(const MultiIndex< DIMS > &FragmentNumbers, const WeakPtr< Field > &SimilarField, const string &FragmentNamePrefix="RegularFragment")
Create a new regularly fragmented Field from an existing Field that is sufficiently fragmented.
Definition RegularlyFragmentedField.hpp:145
Identifier for Skeletons within a Grid.
Definition SkeletonID.hpp:24
int IndexDepth() const
Index depth of this skeleton.
Definition SkeletonID.hpp:89
RefPtr< Skeleton > findVertices(int TotalRefinement=-1) const
Find the Skeleton describing the Vertices on this Grid.
Definition SkeletonMap.cpp:285
A Skeleton is a set of Representation object, each of them accessed by an Representer object.
Definition Skeleton.hpp:102
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
StrongPtr< Object, ObjectBase > RefPtr
Fragment Skeleton: Each fragment of a field is assigned some value in the form of a field defined on ...
Definition FragmentSkeleton.hpp:20
Definition GridWithCartesianVertices.hpp:11
RefPtr< Representation > CartesianVertices
Collection of all fields given on vertices relative to cartesian coordinates.
Definition GridWithCartesianVertices.hpp:17
Definition grid/types/RegularlyFragmentedGrid.hpp:26
RefPtr< Skeleton > FragmentVerticesSkeleton
The Skeleton containing the vertices of fragments, i.e.
Definition grid/types/RegularlyFragmentedGrid.hpp:39
Definition grid/types/RegularlyFragmentedGrid.hpp:294
RefPtr< Representation > PerFragmentDataInCartesianCoordinates
Collection of fields that are defined per fragment in cartesian coordinates.
Definition grid/types/RegularlyFragmentedGrid.hpp:307
RefPtr< RegularlyFragmentedField< VertexDims > > newVertexField(const char *Fieldname)
Create a new regularly fragmented field on the vertices under the given name, overwriting an existing...
Definition grid/types/RegularlyFragmentedGrid.hpp:338
RefPtr< RegularlyFragmentedField< VertexDims > > Positions
Field for the vertex coordinates.
Definition grid/types/RegularlyFragmentedGrid.hpp:310
RefPtr< RegularlyFragmentedField< VertexDims > > getVertexField(const char *Fieldname)
Find a new regularly fragmented field on the vertices under the given name, creating a new one if not...
Definition grid/types/RegularlyFragmentedGrid.hpp:353
static RegularlyFragmentedGridWithCartesianVertices create(Grid &myGrid, const MultiIndex< VertexDims > &NumberOfFragments, bool NeedPerFragmentData=false)
Create a regularly fragmented grid with cartesian vertices.
Definition grid/types/RegularlyFragmentedGrid.hpp:428
RefPtr< Representation > FragmentVerticesInCartesianCoordinates
Collection of fields that are defined per fragment vertex in cartesian coordinates.
Definition grid/types/RegularlyFragmentedGrid.hpp:301
MultiIndex< VertexDims > NumberOfFragments() const
Get the number of fragments here as multi-dimensional index.
Definition grid/types/RegularlyFragmentedGrid.hpp:374
Definition grid/types/RegularlyFragmentedGrid.hpp:71
RefPtr< Representation > FragmentsAsVertices
Fields per fragment providing coordinate-independent information.
Definition grid/types/RegularlyFragmentedGrid.hpp:99
RefPtr< FragmentID > getFragmentID(const MultiIndex< VertexDims > &FragmentIndex) const
Get the fragment ID for the given fragment index.
Definition grid/types/RegularlyFragmentedGrid.hpp:122
static RegularlyFragmentedGrid create(Grid &myGrid, const RefPtr< RegularlyFragmentedField< VertexDims > > &VertexPositions, const SkeletonID &FragmentedSkeletonID)
Create a fragment skeleton on the given Grid.
Definition grid/types/RegularlyFragmentedGrid.hpp:169
MultiIndex< VertexDims > NumberOfFragments() const
Get the number of fragments here as multi-dimensional index.
Definition grid/types/RegularlyFragmentedGrid.hpp:109
Base class for grid types.
Definition TypedGrid.hpp:47