1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestHyperTreeGridElderChildIndex.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkBitArray.h"
#include "vtkHyperTree.h"
#include "vtkHyperTreeGridNonOrientedCursor.h"
#include "vtkUniformHyperTreeGrid.h"
#include <iostream>
#include <string>
//------------------------------------------------------------------------------
void SubdivideAndInitMaskChildrenTrue(vtkHyperTreeGridNonOrientedCursor* cursor)
{
cursor->SubdivideLeaf();
for (unsigned char i = 0; i < cursor->GetNumberOfChildren(); ++i)
{
cursor->ToChild(i);
cursor->SetMask(true);
cursor->ToParent();
}
}
//------------------------------------------------------------------------------
void generateTree2(vtkUniformHyperTreeGrid* uhtg, unsigned int treeId)
{
std::cout << "Initializing octree " << treeId << "\n";
std::cout.flush();
vtkNew<vtkHyperTreeGridNonOrientedCursor> cursor;
uhtg->InitializeNonOrientedCursor(cursor, treeId, true);
cursor->SetGlobalIndexStart(uhtg->GetNumberOfCells());
// level 0
cursor->SetMask(false);
// ElderChildIndex: a
// bitmask: 0
// level 0, 0
SubdivideAndInitMaskChildrenTrue(cursor);
// ElderChildIndex: 1
// bitmask: 0 11111111
cursor->ToChild(3);
// level 1, 0.3
cursor->SetMask(false);
// bitmask: 0 11101111
SubdivideAndInitMaskChildrenTrue(cursor);
// ElderChildIndex: 1 aaa9
// bitmask: 0 11101111 11111111
cursor->ToChild(1);
// level 2, 0.3.1
cursor->SetMask(false);
// bitmask: 0 11101111 10111111
cursor->ToParent();
// level 1, 0.3
cursor->ToParent();
// level 0, 0
cursor->ToChild(0);
// level 1, 0.0
cursor->SetMask(false);
// bitmask: 0 01101111 10111111
SubdivideAndInitMaskChildrenTrue(cursor);
// ElderChildIndex: 1 17-aa9
// bitmask: 0 01101111 10111111 11111111
cursor->ToChild(7);
cursor->SetMask(false);
// bitmask: 0 01101111 10111111 11111110
}
//------------------------------------------------------------------------------
int TestElderChildIndexOK(vtkUniformHyperTreeGrid* htg)
{
std::cout << "Starting Elder Child indices comparison\n";
std::cout.flush();
int rc = 0;
vtkNew<vtkHyperTreeGridNonOrientedCursor> cursor;
vtkHyperTreeGrid::vtkHyperTreeGridIterator it;
htg->InitializeTreeIterator(it);
vtkHyperTree* ht1 = it.GetNextTree();
vtkHyperTree* ht2 = it.GetNextTree();
size_t nbElements = 0;
const unsigned int* ElderChildHT1 = (ht1) ? ht1->GetElderChildIndexArray(nbElements) : nullptr;
const unsigned int* ElderChildHT2 = (ht2) ? ht2->GetElderChildIndexArray(nbElements) : nullptr;
if (ht1 == nullptr || ht2 == nullptr)
{
nbElements = 0;
std::cout << "Impossible to retrieve either of the trees" << std::endl;
std::cout.flush();
}
for (unsigned int i = 0; i < nbElements; ++i)
{
std::cout << "index " << i << ": " << ElderChildHT1[i] << "\n";
std::cout.flush();
if (ElderChildHT1[i] != ElderChildHT2[i])
{
rc = 1;
break;
}
}
vtkBitArray* mask = htg->GetMask();
if (mask)
{
std::cout << "Mask: ";
for (vtkIdType i = 0; i < mask->GetNumberOfValues(); ++i)
{
std::cout << mask->GetValue(i);
}
std::cout << std::endl;
}
else
{
std::cout << "No mask" << std::endl;
}
return rc;
}
void generateTree(vtkUniformHyperTreeGrid* uhtg, unsigned int treeId)
{
std::cout << "Initializing quadtree " << treeId << "\n";
std::cout.flush();
vtkNew<vtkHyperTreeGridNonOrientedCursor> cursor;
uhtg->InitializeNonOrientedCursor(cursor, treeId, true);
cursor->SetGlobalIndexStart(uhtg->GetNumberOfCells());
// level 0
cursor->SubdivideLeaf();
cursor->ToChild(0);
// level 1.0
cursor->SubdivideLeaf();
cursor->ToParent();
// level 0
cursor->ToChild(1);
// level 1.1
cursor->SubdivideLeaf();
cursor->ToParent();
// level 0
cursor->ToChild(0);
// level 1.0
cursor->ToChild(0);
// level 2.0
cursor->SubdivideLeaf();
cursor->ToChild(2);
// level 3.2
cursor->SubdivideLeaf();
cursor->ToChild(0);
// level 4.0
cursor->SubdivideLeaf();
}
void initializeUniformHyperTreeGridQuadTree(vtkUniformHyperTreeGrid* uhtg)
{
std::cout << "Initializing Uniform Grid\n";
std::cout.flush();
uhtg->SetBranchFactor(2);
uhtg->SetGridScale(1.1);
uhtg->SetOrigin(0., 0., 0.);
uhtg->SetDimensions(5, 2, 1);
generateTree(uhtg, 1);
generateTree(uhtg, 3);
}
//------------------------------------------------------------------------------
void initializeUniformHyperTreeGridOcTree(vtkUniformHyperTreeGrid* uhtg)
{
std::cout << "Initializing Uniform Grid\n";
std::cout.flush();
uhtg->SetBranchFactor(2);
uhtg->SetGridScale(1.1);
uhtg->SetOrigin(0., 0., 0.);
uhtg->SetDimensions(3, 3, 2);
vtkNew<vtkBitArray> mask;
uhtg->SetMask(mask);
generateTree2(uhtg, 0);
generateTree2(uhtg, 1);
}
//------------------------------------------------------------------------------
void CheckTestStatusHTG(int rc, const std::string& TestName)
{
std::cout << "Test " << TestName << "...";
std::cout.flush();
if (rc == 0)
{
std::cout << "PASSED!\n";
std::cout.flush();
}
else
{
std::cout << "FAILED!\n";
std::cout.flush();
}
}
int TestHyperTreeGridElderChildIndex(int, char*[])
{
std::cout << "Starting test 1\n";
std::cout.flush();
int rc = 0;
{
vtkNew<vtkUniformHyperTreeGrid> uhtg1;
initializeUniformHyperTreeGridQuadTree(uhtg1);
rc += TestElderChildIndexOK(uhtg1);
CheckTestStatusHTG(rc, "TestElderChildIndexOKQuadTree");
}
{
vtkNew<vtkUniformHyperTreeGrid> uhtg1;
initializeUniformHyperTreeGridOcTree(uhtg1);
rc += TestElderChildIndexOK(uhtg1);
CheckTestStatusHTG(rc, "TestElderChildIndexOKOctree");
}
return (rc);
}
|