Commit d31347ab authored by Ben Boeckel's avatar Ben Boeckel

octree: create a module

parent a420dd86
......@@ -15,8 +15,3 @@ set(classes
vtk_module_add_module(VTK::RenderingLabel
CLASSES ${classes})
# TODO: need to convert octree to module.
target_include_directories(vtkRenderingLabel
PRIVATE
${VTK_SOURCE_DIR}/Utilities) # octree
project( ndtree )
cmake_minimum_required( VERSION 2.6 )
if(POLICY CMP0053)
cmake_policy(SET CMP0053 NEW) # CMake 3.1
endif()
find_package( VTK REQUIRED )
include( ${VTK_USE_FILE} )
include_directories(
${ndtree_SOURCE_DIR}
)
enable_testing()
add_executable( Octree
test_octree.cxx
)
find_package( Doxygen )
configure_file(
${ndtree_SOURCE_DIR}/doxyfile.in
${ndtree_BINARY_DIR}/doxyfile
@ONLY
)
add_custom_target( docs
COMMAND ${DOXYGEN_EXECUTABLE} ${ndtree_BINARY_DIR}/doxyfile
DEPENDS ${ndtree_BINARY_DIR}/doxyfile
)
set(template_classes
octree/octree
octree/octree_cursor
octree/octree_iterator
octree/octree_node
octree/octree_path)
set(headers
octree/octree)
vtk_module_add_module(VTK::octree
TEMPLATE_CLASSES ${template_classes}
HEADERS ${headers}
HEADERS_SUBDIR "octree"
HEADER_ONLY)
This diff is collapsed.
......@@ -19,11 +19,11 @@
#include <octree/octree_iterator.h>
#include <octree/octree.h>
#include <octree/octree_node.cxx>
#include <octree/octree_path.cxx>
#include <octree/octree_cursor.cxx>
#include <octree/octree_iterator.cxx>
#include <octree/octree.cxx>
#include <octree/octree_node.txx>
#include <octree/octree_path.txx>
#include <octree/octree_cursor.txx>
#include <octree/octree_iterator.txx>
#include <octree/octree.txx>
#undef __octree_interior
......
/*!
\mainpage N-Dimensional Binary Trees
This documentation describes how to use the n-dimensional binary tree C++ classes.
The classes are all templated and behave similarly to the STL.
Even though the class names all contain octree, they provide a generalization to any integer dimension.
The octree class stores the root node of the tree plus information about the geometric embedding of the tree (if any).
The octree_node class represents nodes in the tree and stores a pointer to the parent and child nodes plus a templated
class instance of your choosing.
Finally, octree_cursor and octree_iterator are subclasses of octree_path and provide a way to traverse
the tree in either free-form or a depth-first fashion, respectively.
*/
#include <octree>
#include <iostream>
int main()
{
// Construct a small 2-d binary tree.
double center[2] = { 0.5, 0.5 };
octree<int,2> foo( center, 1. );
foo.root()->add_children();
foo.root()->value() = 42;
*(*foo.root())[0] = 25;
*(*foo.root())[1] = 19;
(*foo.root())[1].add_children();
(*foo.root())[3].add_children();
*(*foo.root())[1][0] = 38;
*(*foo.root())[1][1] = 5;
*(*foo.root())[1][2] = -19;
*(*foo.root())[1][3] = 1;
*(*foo.root())[2] = 8;
*(*foo.root())[3] = 3;
*(*foo.root())[3][0] = 15;
(*foo.root())[3].remove_children();
cout << "Root is " << foo.root()->value() << "\n";
cout << "Child 0 is " << (*foo.root())[0].value() << "\n";
cout << "Child 1 is " << (*foo.root())[1].value() << "\n";
// Now test an iterator
octree<int,2>::iterator it;
for ( it = foo.begin(); it != foo.end(); ++it )
{
/*
const double* bds = it->center();
double he = it->size() / 2.;
*/
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value()
/*
<< " [" << (bds[0] - he) << "->" << (bds[0] + he)
<< ", " << (bds[1] - he) << "->" << (bds[1] + he) << "]"
*/
<< "\n";
}
cout << "\n\n";
for ( it = foo.begin( false ); it != foo.end( false ); ++it )
{
/*
const double* bds = it->center();
double he = it->size() / 2.;
*/
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value()
/*
<< " [" << (bds[0] - he) << "->" << (bds[0] + he)
<< ", " << (bds[1] - he) << "->" << (bds[1] + he) << "]"
*/
<< "\n";
}
cout << "\n\n";
it = foo.end();
do
{
--it;
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value() << "\n";
}
while ( it != foo.begin() );
cout << "\n\n";
it = foo.end( false );
do
{
--it;
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value() << "\n";
}
while ( it != foo.begin( false ) );
cout << "\n\n";
// Now test the "immediate family" mode.
it = foo.begin();
++it;
it.immediate_family( true );
for ( ; it != foo.end(); ++it )
{
/*
const double* bds = it->center();
double he = it->size() / 2.;
*/
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value()
/*
<< " [" << (bds[0] - he) << "->" << (bds[0] + he)
<< ", " << (bds[1] - he) << "->" << (bds[1] + he) << "]"
*/
<< "\n";
}
cout << "\n\n";
it = foo.begin( false );
++it;
it.immediate_family( true );
for ( ; it != foo.end( false ); ++it )
{
/*
const double* bds = it->center();
double he = it->size() / 2.;
*/
cout
<< "Node 0x" << hex << (&*it)
<< " (" << (it.level()) << ") "
<< " = " << it->value()
/*
<< " [" << (bds[0] - he) << "->" << (bds[0] + he)
<< ", " << (bds[1] - he) << "->" << (bds[1] + he) << "]"
*/
<< "\n";
}
cout << "\n\n";
// Test octree cursors:
octree<int,2>::cursor curs( &foo );
curs.down( 0 );
curs.over( 1 );
cout << "Initial L2Node: " << "level " << curs.level() << " where " << curs.where() << " val " << curs->value() << "\n";
curs.axis_partner( 1 );
cout << "Axis 1 partner: " << "level " << curs.level() << " where " << curs.where() << " val " << curs->value() << "\n";
curs.over( 1 );
curs.axis_partner( 0 );
cout << "Axis 0 partner: " << "level " << curs.level() << " where " << curs.where() << " val " << curs->value() << "\n";
curs.over( 1 );
curs.down( 3 );
cout << "Down to level2: " << "level " << curs.level() << " where " << curs.where() << " val " << curs->value() << "\n";
// Copy an iterator's position
curs = foo.begin();
cout << "level " << curs.level() << " where " << curs.where() << " val " << curs->value() << "\n";
return 0;
}
NAME
VTK::octree
LIBRARY_NAME
vtkoctree
EXCLUDE_WRAP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment