FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
TreeFunctions.hpp
1#ifndef __BASEOP_TREEFUNCTIONS_HPP
2#define __BASEOP_TREEFUNCTIONS_HPP
3
4#include "elementary/aerie/KDTree.hpp"
5#include "elementary/aerie/OcTree.hpp"
6#include "fish/fiber/field/CreativeArrayBase.hpp"
7//#include "omp.h"
8
12
13namespace Fiber
14{
15using namespace MemCore;
16
18
19template<int N, class T, class C>
21{
22MemCore::RefPtr<Eagle::KDTree<N,T> > tree = new Eagle::KDTree <N,T>();
23
24//#pragma omp parallel for
26 for (T i = 0; i < size; i++)
27 tree->insert(FixedArray<double,N>(coordinates[i], 0.0), i);
28
29 assert (tree && "TreeFunctions::createTree ... assert(tree)");
30
31 Verbose(50) << "TreeFunctions::createTree ... tree filled ... size = " << size;
32
33 return tree;
34}
35
37
38template<int N, class T, class C>
41{
42 if (!cab)
43 Verbose(0) << "TreeFunctions::createTree ... no CreativeArrayBase found";
44
45 /*
46 Note (WB): Code like this can be signficantly shortened:
47
48 if (RefPtr a = findInterface)
49 return a;
50 else
51 {
52 RefPtr a = createTree();
53 cab->addInterface(a);
54 return a;
55 }
56 */
57 MemCore::RefPtr<Eagle::KDInterface< N,T > > myKDinterface = cab->findInterface(typeid (Eagle::KDTree < N,T > ));
59
60 if (!myKDinterface)
61 {
64
65 cab->addInterface (myKDinterface);
66 }
67 else
68 {
69 tree = myKDinterface->Tree;
70 Verbose(50) << "TreeFunctions::createTree ... found cached tree";
71 }
72
73 return tree;
74}
75
76template<class T>
77MemCore::RefPtr<Eagle::OcTree<T> > createOcTree (const MultiArray<1, Eagle::PhysicalSpace::point>& coordinates, const size_t size,
79{
80MemCore::RefPtr<Eagle::OcTree<T> > octree = new Eagle::OcTree <T>( bb );
81
82 for (index_t i = 0; i < size; i++)
83 {
84// if( i % 10000 == 0)
85// Verbose(0) << coordinates[i] << ", " << size << ", " << bb->minCoord() << "-" << bb->maxCoord();
86
87 octree->insert( coordinates[i], i);
88 }
89 return octree;
90}
91
92
93template<class T>
94MemCore::RefPtr<Eagle::QuadTree<T> > createQuadTree (const MultiArray<1, Eagle::PhysicalSpace::point>& coordinates, const size_t size,
96{
98
99 for (index_t i = 0; i < size; i++)
100 {
101// if( i % 10000 == 0)
102// Verbose(0) << coordinates[i] << ", " << size << ", " << bb->minCoord() << "-" << bb->maxCoord();
103
104 quad_tree->insert( coordinates[i], i);
105 }
106 return quad_tree;
107}
108
109} // namespace Fiber
110
111#endif // __BASEOP_TREEFUNCTIONS_HPP
valarray< size_t > size() const
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
MemCore::RefPtr< Eagle::KDTree< N, T > > createTree(const C &coordinates, const unsigned size)
create a KDTree
Definition TreeFunctions.hpp:20