FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
FragmentSlicer.hpp
1#ifndef __FIBEROPERATIONS_FRAGMENTSLICER_HPP
2#define __FIBEROPERATIONS_FRAGMENTSLICER_HPP
3
4#include "SliceExtractor.hpp"
5#include "RegularCoordinateSlice.hpp"
6
7#include <field/Field.hpp>
8
9#undef Verbose
10#define Verbose(X) AppVerbose("FieldSlice",X)
11
12namespace Fiber
13{
14
23template <class Converter, class InputTypes>
25{
27 double myCoordinateValue;
28 RefPtr<Field> myCoordinates;
29
30 RefPtr<Field> &mySliceCoordinateField;
31 RefPtr<Field> OutputField;
32
33 const Converter myConverter;
34
36
38 double theCoordinateValue,
42 : myRCS(theRCS)
43 , myCoordinateValue( theCoordinateValue )
44 , myCoordinates( theCoordinates )
45 , mySliceCoordinateField( theSliceCoordinates )
46 , myConverter( theConverter )
47 {}
48
49 /*
50 Note: the FragmentID is for the external field, my both fields in here have local fragment IDs.
51 */
53 {
54 double CoordinateIndex = -1U;
55
56 Verbose(5) << " FragmentSlicer::apply(fid=" << FragmentID::Name(fid) << ")";
57
58#ifdef VERBOSE
59 if (fid) printf(" FragmentSlicer::apply(fid=%s)\n", fid->Name().c_str() );
60 else puts (" FragmentSlicer::apply(contiguous field)");
61#endif
62
63 if (!myRCS.getRectilinearIndex(myCoordinateValue,
64 myCoordinates, fid,
66 {
67#ifdef VERBOSE
68 puts(" FragmentSlicer::apply(): could not get coordinate index");
69#endif
70 // use coordinate value for irregular/curvilinear
71 return true;
72 }
73#ifdef VERBOSE
74 printf(" FragmentSlicer's getRectilinearIndex() yielded an exact slice value of %lg)\n", CoordinateIndex );
75#endif
76
78 MultiIndex<3> DataDims;
79 if (!makeDimensions(DataDims, DataCreator) )
80 {
81// might try here to get a field fragment's
82// dimension from elsewhere, such as the coordinates, if possible
83 puts("FieldSlice: Could not Make Size Interface in Creator, no field Creatable!");
84 return true;
85 }
86
87 Verbose(5) << " FragmentSlicer::apply() Coordinate Index for this slice is " << sliceIndex;
88
89
92 {
93 if (!mySliceCoordinateField)
94 {
96 if (fid) FIC = fid->getFragmentIDCollection();
97
98 Verbose(0) << " No mySliceCoordinateField - Creating a new one!";
99 mySliceCoordinateField = new Field(FIC);
100 }
101
102 if (fid)
103 SliceFragID = mySliceCoordinateField->makeFragmentID( fid->Name() + "_2D" );
104
105// SliceFragID = fid;
106
107 bool GotSliceDimensions = false;
109 SliceFragmentCreator = mySliceCoordinateField->getCreator( SliceFragID ) )
110 {
112 {
113 GotSliceDimensions = true;
114 }
115 }
116
118 {
120 SliceCoordinates = mySliceCoordinateField->getData( SliceFragID );
121
122 if (!SliceCoordinates)
123 {
125 myCoordinates, fid);
126
128 {
129 Verbose(5) << "ADDING sliced data set originating from 3D source...";
130 mySliceCoordinateField->setDiscardableData(SliceCoordinates, MemCore::Cache::MemCache(), SliceFragID );
131 }
132 else
133 {
134 Verbose(5) << " Could not produce slice coordinates for index " << sliceIndex
135 <<", call to RegularCoordinateSlice::getCoordinates() failed.";
136 }
137 }
138
139 if (!SliceCoordinates)
140 {
141 Verbose(5) << " --> slice index is out of range for the given coordinate value, no slice data provided.";
142
143 // slice index out of range for the given coordinate value
144 // so nothing to be done here.
145 return true;
146 }
148 {
150 }
151 else
152 {
153 assert( 0 && "Sorry, slice data has not been specified as 3D array, which is easy to support but has not been implemented for now." );
154 return true;
155 }
156 }
157 }
158
159 assert( SliceDims.size()>0 );
160
162 if (!MySliceConstructor.canExtract())
163 {
164 printf(__FILE__ " FragmentSlicer: cannot extract slice, destination is too small for input %dx%dx%d\n",
165 int(SliceDims[0]), int(SliceDims[1]), int(SliceDims[2]) );
166// MemCore::breakpoint();
167 return true;
168 }
169
170 if (!OutputField)
171 {
172 Verbose(5) << "Creating new output field";
173 OutputField = new Field( mySliceCoordinateField->getFragmentIDCollection() );
174 }
175 else
176 {
177 Verbose(5) << "Reusing previous OutputField";
178 }
179
180 Verbose(5) << "Slicer is setting up slice constructor for "
181 << SliceDims[0] << "x" << SliceDims[1] << "x" << SliceDims[2];
182
183 Assert( mySliceCoordinateField->getFragmentIDCollection() == OutputField->getFragmentIDCollection() );
184
186
187 return true;
188 }
189};
190
191
192} // namespace Fiber
193
194#endif // __FIBEROPERATIONS_FRAGMENTSLICER_HPP
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
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
const string & Name() const
Text ID of the fragment.
Definition FragmentID.hpp:65
Base class for iterators over the fragments of a field.
Definition FragmentID.hpp:249
static RefPtr< Cache, CacheBase > & MemCache()
bool makeDimensions(MultiIndex< N > &Dims, const RefPtr< CreativeArrayBase > &DC)
Given a data creator, retrieve the dimensionality information from the associated data,...
Definition MemArrayBase.hpp:186
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
Definition CreativeIterator.hpp:84
Extract 2D slices from a regular 3D data field along a given coordinate.
Definition FragmentSlicer.hpp:25
bool apply(const RefPtr< FragmentID > &fid, const RefPtr< CreativeArrayBase > &DataCreator) override
Iteration callback function.
Definition FragmentSlicer.hpp:52
Helper class to select a slice from a regular grid.
Definition RegularCoordinateSlice.hpp:26
MemCore::RefPtr< MemBase > getCoordinates(index_t sliceIndex, const MultiIndex< 3 > &DataDims, const RefPtr< Field > &Coords, const RefPtr< FragmentID > &fid)
Definition RegularCoordinateSlice.cpp:95
bool getRectilinearIndex(double CoordinateValue, const MemCore::RefPtr< MemBase > &CoordValues, double &CoordinateIndex)
Given a dataset of three-dimensional coordinate values, either uniform or rectilinear,...
Definition RegularCoordinateSlice.cpp:27