FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
CoordinateAxisArray.hpp
1#ifndef __FIBER_COORDINATEAXISARRAY_HPP
2#define __FIBER_COORDINATEAXISARRAY_HPP
3
4#ifndef DONT_USE_PRAGMA_ONCE
5#pragma once
6#endif
7
8#include "MemArray.hpp"
9#include <map>
10
11namespace Fiber
12{
13
21
22template <class T, class Category>
24
33template <class T>
35{
36public:
37 index_t length;
38
45
49 {
50 index_t p = this->elements()-1;
51 T t = (*this)[p];
52 while(p>0)
53 {
54 t *= i;
55 p--;
56 t += (*this)[p];
57 }
58 return t;
59 }
60
61 index_t Length() const
62 {
63 return length;
64 }
65
66#if 0
76 bool locate(T&value) const
77 {
78 if (Length()==2)
79 {
80 value = (value - (*this)[0] ) / (*this)[1];
81 return true;
82 }
83
84 return false;
85 }
86#endif
87};
88
89
94template <class T>
96{
97public:
98 index_t length;
99
100 CoordinateAxisArray() = delete;
101
104 , length(max_idx)
105 {}
106
108 : MemCore::Chunk<T>( Src.std_vector() )
109 , length( Src.length )
110 {}
111
122 : MemCore::Chunk<T>(2)
123 , length(max_idx)
124 {
125 (*this)[0] = C0;
126 (*this)[1] = C1;
127 }
128
132 {
133 return (*this)[0] + i*(*this)[1];
134 }
135
143 double reverse(const T&value) const
144 {
145 const T&delta = (*this)[1];
146
147// printf("CoordinateAxisArray::reverse(value=%lg) delta=%lg\n", double(value), double(delta) );
148 // if there is no delta, then always yield the 0th coordinate index
149 if ( delta == 0.0)
150 {
151// printf("CoordinateAxisArray::reverse() delta=%lg ZERO delta! \n", double(delta) );
152 return 0.0;
153 }
154 return (value - (*this)[0] ) / delta;
155 }
156
163 {
164 return length;
165 }
166
167
168#if 0
178 bool locate(T&value) const
179 {
180 double FloatIndex = reverse(value);
181
182 return FloatIndex>=0.0 && FloatIndex<=1.0;
183 }
184#endif
185};
186
187
192template <class T>
194{
195public:
197 CoordinateLookupMap_t CoordinateLookupMap;
198
199 void setupCoordinateLookupMap()
200 {
201 const std::vector<T>&data = this->std_vector();
202
203 CoordinateLookupMap.clear();
204 for(index_t i=0; i<data.size(); i++)
205 {
206 CoordinateLookupMap[ data[i] ] = i;
207 }
208 }
209
210
211
218
220 : MemCore::Chunk<T>( Src.std_vector() )
221 {}
222
226 {
227 return (*this)[i];
228 }
229
230 index_t Length() const
231 {
232 return this->elements();
233 }
234
235 double reverse(const T&value)
236 {
237 if (this->elements()<1) return 0.0;
238#if 0
239 MEMCORE_PROFILE_THIS("CoordinateAxisArray::reverse(): Non STL Bin Search", 1);
240 const std::vector<T>&data = this->std_vector();
241
242
243 size_t elements = CoordinateLookupMap.size() - 1;
244 size_t low,mid,high;
245 /*
246 if(value < 0 || value > CoordinateLookupMap[elements])
247 {
248 //printf("x[82]=%17.14f px = %17.14f is outside the box\n",x_values[elements],px);
249 //scanf("%d",&n);
250 return false;
251 }
252 */
253 low=0;
254 high=elements;
255 printf("\nReverse lookup, Explicit Coordinates: Elements= %d, Low= %d, high= %d\n", elements, low, high);
256 if(value<CoordinateLookupMap[low])
257 {
258 return CoordinateLookupMap[low];
259 }
260 else if(value>CoordinateLookupMap[high])
261 {
262 return CoordinateLookupMap[high];
263 }
264 printf("\nCoordinate in range");
265 while(high>low+1)
266 {
267 mid=(low+high)/2;
268 if(value<CoordinateLookupMap[mid])
269 high=mid;
270 else
271 low=mid;
272 }
273 printf("\nReverse lookup, Explicit Coordinates: Elements= %d, Low= %d, high= %d\n", elements, low, high);
274 T LeftValue = CoordinateLookupMap[low];
275 T RightValue = CoordinateLookupMap[high];
276 index_t IndexValue = low;
277
278#else
279 if (CoordinateLookupMap.empty() )
280 {
281 setupCoordinateLookupMap();
282 }
283 typename CoordinateLookupMap_t::const_iterator
284 LocationJustLargerThanValue = CoordinateLookupMap.lower_bound( value );
285
286 if (LocationJustLargerThanValue == CoordinateLookupMap.end() )
287 return double( CoordinateLookupMap.rbegin()->second ); // nothing found, max boundary
288
289 if (LocationJustLargerThanValue == CoordinateLookupMap.begin() )
290 return double( CoordinateLookupMap.begin()->second ); // nothing found, min boundary
291
292 typename CoordinateLookupMap_t::const_iterator
293 LocationJustSmallerThanValue = LocationJustLargerThanValue;
294 LocationJustSmallerThanValue--;
295
296 T LeftValue = LocationJustSmallerThanValue->first;
297 T RightValue = LocationJustLargerThanValue ->first;
298
299 if(value < LeftValue)
300 {
301 printf("\n%lg, %lg, %lg\n", value, LeftValue, (value - LeftValue));
302 printf("%lg, %d \n", CoordinateLookupMap.begin()->first, int(CoordinateLookupMap.begin()->second) );
303
304 }
305 //assert( !(LeftValue < key) );
306 assert( value >= LeftValue );
307 assert( value <= RightValue );
308
309 index_t IndexValue = LocationJustSmallerThanValue->second;
310#endif
311 double Weight = (value - LeftValue) / ( RightValue - LeftValue);
312
313 return IndexValue + Weight;
314
315 }
316
317#if 0
327 bool locate(T&value) const
328 {
329 if (Length()==2)
330 {
331 value = (value - (*this)[0] ) / (*this)[1];
332 return true;
333 }
334
335 return false;
336 }
337#endif
338};
339
340
341} /* namespace Fiber */
342
343#endif /* __FIBER_COORDINATEAXISARRAY_HPP */
constexpr void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
bool empty() const noexcept
const_reverse_iterator rbegin() const noexcept
const_iterator end() const noexcept
void clear() noexcept
size_type size() const noexcept
iterator lower_bound(const key_type &__x)
const_iterator begin() const noexcept
T operator()(index_t i) const
The element access function.
Definition CoordinateAxisArray.hpp:225
CoordinateAxisArray(index_t max_idx)
Construct an coordinate array.
Definition CoordinateAxisArray.hpp:215
T operator()(index_t i) const
The element access function.
Definition CoordinateAxisArray.hpp:131
CoordinateAxisArray(const T &C0, const T &C1, index_t max_idx)
Create a procedural array of equidistant values.
Definition CoordinateAxisArray.hpp:121
index_t Length() const
Return the length of the array in terms of points covered.
Definition CoordinateAxisArray.hpp:162
double reverse(const T &value) const
Compute the floating point index that corresponds to the given coordinate value.
Definition CoordinateAxisArray.hpp:143
T operator()(index_t i) const
The element access function.
Definition CoordinateAxisArray.hpp:48
CoordinateAxisArray(index_t max_idx)
Construct a polynomial array.
Definition CoordinateAxisArray.hpp:42
Definition CoordinateAxisArray.hpp:23
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
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 CoordinateAxisArray.hpp:20
Definition CoordinateAxisArray.hpp:18
Definition CoordinateAxisArray.hpp:19