|
|
|
|
![]() ![]() |
Feb 14 2005, 10:28 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
I'm making an oct tree to divide up a colour space.
Each tree has 3 upperbounds, and 3 lowerbounds, 1 pair for each axis. I store it's children in a 3D array. 2 by 2 by 2. m_pChildren is of type pointer to a pointer, and is initilized like this: Code: void COctTree::CreateChildren(void) { m_pChildren = new COctTree*[2,2,2]; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { for(int k=0;k<2;k++) { m_pChildren[i,j,k] = new COctTree(); //Setup boundaries m_pChildren[i,j,k]->m_pLowBounds[0] = m_pLowBounds[0] + i * ((m_pHighBounds[0] - m_pLowBounds[0])>>1); m_pChildren[i,j,k]->m_pHighBounds[0] = m_pLowBounds[0] + (1+i) * ((m_pHighBounds[0] - m_pLowBounds[0])>>1); m_pChildren[i,j,k]->m_pLowBounds[1] = m_pLowBounds[1] + (j * ((m_pHighBounds[1] - m_pLowBounds[1])>>1)); m_pChildren[i,j,k]->m_pHighBounds[1] = m_pLowBounds[1] + (1+j) * ((m_pHighBounds[1] - m_pLowBounds[1])>>1); m_pChildren[i,j,k]->m_pLowBounds[2] = m_pLowBounds[2] + k * ((m_pHighBounds[2] - m_pLowBounds[2])>>1); m_pChildren[i,j,k]->m_pHighBounds[2] = m_pLowBounds[2] + (1+k) * ((m_pHighBounds[2] - m_pLowBounds[2])>>1); } } } } From stepping through the code it appears to work fine. However when i access the values i get strange results. Here's how i'm using the children: Code: if(!m_pChildren) CreateChildren(); //Now insert the pixel into the appropriate child for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { for(int k=0;k<2;k++) { //Loop through each child bool IsInSector = true; for(int l=0;l<3;l++) { //Loop through each dimension int tmpInt; if(!Colour[0] && !Colour[1] && !Colour[2]) cout << (tmpInt = m_pChildren[i,j,k]->m_pLowBounds[l]); if( (Colour[l] > m_pChildren[i,j,k]->m_pHighBounds[l]) || (Colour[l] < m_pChildren[i,j,k]->m_pLowBounds[l])) { IsInSector = false; } } if(IsInSector) { //The pixel can go in this (child) sector in the colour space m_pChildren[i,j,k]->InsertPixel(Pixel,Colour); return; } } } } cout << "Pixel Not Placed in Oct Tree!!!" << endl; Here it loops through each child checking the bounds to see if we can place the pixel in it. If so it does, if not it moves to the next one. Now, every pixel should get placed, in one child, but that's not the case. Can anyone see anything wrong with what i'm doing? |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 13th October 2008 - 02:50 AM |