📄 octatree.cpp
字号:
// OctaTree.cpp: implementation of the OctaTree class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FastRBF.h"
#include "OctaTree.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
OctaTree::OctaTree()
{
m_pPointTable = 0;
m_pRoot = 0;
}
OctaTree::~OctaTree()
{
if (m_pPointTable)
{
delete m_pPointTable;
m_pPointTable = 0;
}
if (m_pRoot)
{
// m_pRoot->Delete();
delete m_pRoot;
m_pRoot = 0;
}
}
void OctaTree::GetOriginCoord(float &ox, float &oy, float &oz)
{
ox = m_fOriginX;
oy = m_fOriginY;
oz = m_fOriginZ;
}
void OctaTree::GetSize(float &sx, float &sy, float &sz)
{
sx = m_fSizeX;
sy = m_fSizeY;
sz = m_fSizeZ;
}
void OctaTree::SetPointSet(PointSet *ps)
{
float minCoord[3], maxCoord[3];
ps->GetBoundingBox(minCoord, maxCoord);
m_fOriginX = minCoord[0];
m_fOriginY = minCoord[1];
m_fOriginZ = minCoord[2];
m_fSizeX = maxCoord[0] - minCoord[0];
m_fSizeY = maxCoord[1] - minCoord[1];
m_fSizeZ = maxCoord[2] - minCoord[2];
if (m_pRoot)
delete m_pRoot;
m_pRoot = new Cell(0, m_fOriginX, m_fOriginY, m_fOriginZ);
int pointNum = ps->GetPointNum();
for (int i=0; i<pointNum; i++)
m_pRoot->AddPoint(i, ps, m_fSizeX, m_fSizeY, m_fSizeZ);
m_pRoot->CleanChildren();
}
void OctaTree::BuildTree(PointSet *ps, int MaxLevel)
{
m_pRoot->SplitChild(MaxLevel, ps, m_fSizeX, m_fSizeY, m_fSizeZ);
}
void OctaTree::GetPointIndexTable(PointSet *ps, int &tableSize, float x, float y, float z, float r)
{
tableSize = 0;
m_pRoot->AddIntoTable(ps, m_pPointTable, tableSize, x, y, z, r, m_fSizeX,
m_fSizeY, m_fSizeZ);
}
int* OctaTree::GetPointTable()
{
return m_pPointTable;
}
int* OctaTree::GetCoarseGrid(int num, int* indexTable, int n)
{
m_pRoot->GetCoarseGrid(num, indexTable, n);
return indexTable;
}
Cell* OctaTree::GetRoot()
{
return m_pRoot;
}
void OctaTree::SetOriginCoord(float ox, float oy, float oz)
{
m_fOriginX = ox;
m_fOriginY = oy;
m_fOriginZ = oz;
}
void OctaTree::SetSize(float sx, float sy, float sz)
{
m_fSizeX = sx;
m_fSizeY = sy;
m_fSizeZ = sz;
}
void OctaTree::Draw()
{
m_pRoot->DrawCell(m_fSizeX, m_fSizeY, m_fSizeZ);
}
int OctaTree::GetLeavesNum()
{
int n=0;
m_pRoot->GetLeavesNum(n);
return n;
}
void OctaTree::FitSubdomains(PointSet *ps, float *solution, int leavesNum, float* b)
{
int n = ps->GetPointNum();
m_pRoot->FitRBF(ps, solution, b);
// solution[2*n+1] /= leavesNum;
// solution[2*n+2] /= leavesNum;
// solution[2*n+3] /= leavesNum;
// solution[2*n+4] /= leavesNum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -