Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

3d Arrays [resolved]

Recommended Posts

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.