cheshirekow  v0.1.0
Simplex.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_SIMPLEX_TREE_SIMPLEX_HPP_
28 #define MPBLOCKS_SIMPLEX_TREE_SIMPLEX_HPP_
29 
30 
31 namespace mpblocks {
32 namespace simplex_tree {
33 
34 template <class Traits>
36 {
37  // reserve storage for all the children and create the child simplex
38  // structures
39  Index_t n = Traits::NDim+1;
40  m_children.reserve(n);
41  for(int i=0; i < n; i++)
42  m_children.push_back( new Simplex_t() );
43 
44  // for each of the N+1 points find the face midway between all other points
45  for(Index_t i=0; i < n; i++)
46  {
47  const Point_t& xi = m_points[i]->getPoint();
48 
49  // copy the i'th face from the parent
50  //
51 
52  // all other faces are found by the plane separating the i'th
53  // from one of the other points
54  for(Index_t j=i; j < n; j++)
55  {
56  const Point_t& xj = m_points[i]->getPoints();
57  Vector_t v = xj - xi;
58  Vector_t nj = v.normalized();
59  Format_t dj = nj.dot(xi) + 0.5*v.norm();
60  }
61  }
62 
63  // now clear our point list and force the vector to release it's memory
64  m_points.clear();
65  NodeList_t tmp; tmp.swap(m_points);
66 }
67 
68 
69 template <class Traits>
71 {
72 
73 }
74 
75 
76 template <class Traits>
78 {
79  if(isLeaf())
80  {
81  m_points.push_back(x);
82  if(m_points.size() > Traits::NDim+1 )
83  split();
84  }
85  else
86  {
87  const int n = m_children.size();
88  for(int i=0; i < n; i++)
89  {
90  if( m_children[i]->contains(x) )
91  {
92  m_children[i]->insert(x);
93  break;
94  }
95  }
96  }
97 }
98 
99 
100 
101 
102 
103 } // namespace simplex_tree
104 } // namespace mpblocks
105 
106 
107 
108 #endif // SIMPLEX_HPP_
Eigen::Matrix< Format_t, Traits::NDim, 1 > Vector_t
Definition: Simplex.h:56
void insert(Node_t *)
insert the point into the simplex, recursively inserting into children or splitting as necessary ...
Definition: Simplex.hpp:77
void initAsLeaf(Simplex_t *parent, Index_t i, Point_t &v)
initialize the simplex as leaf, reserving storage for all the child node pointers ...
Definition: Simplex.hpp:70
std::vector< Node_t * > NodeList_t
Definition: Simplex.h:62
void split()
list of points in this node, if it's a leaf
Definition: Simplex.hpp:35
base class for nodes, implements storage and interface for the simplex tree
Definition: Simplex.h:48
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: Simplex.h:57