osg::BrickSet Struct Reference

#include <OSGBrick.h>

List of all members.

Public Types

enum  Orientation { XY = 0, XZ = 1, YZ = 2, UNDEF = 3 }

Public Member Functions

 BrickSet (void)
 ~BrickSet (void)
BricksortBricks3D (const Matrix &modelMat, const Vec3f &eyePoint)
 Return sorted brick list.
BricksortBricks2D (bool backToFront)
 Return sorted brick list.
void buildBrickTextures (ChunkMaterialPtr &material, TextureSet &textures, TextureManager::TextureMode mode)
 Build textures for bricks.
void reloadBrickTextures (DrawActionBase *action, UInt32 texStage)
 Reload brick textures.
void clearBrickTextures (ChunkMaterialPtr &material)
 Clear brick textures.
void buildBricks3D (DVRVolume *volume, Vec3f brickSubdivision, Int32 overlap=1, Orientation ori=UNDEF)
 Build 3D bricks.
void buildBricks2D (DVRVolume *volume, Orientation ori)
 Build 2D bricks.

Static Public Member Functions

static TextureChunkPtr makeTexture (UInt32 internalFormat, UInt32 externalFormat, ImagePtr image)
 Create texture chunk for image.

Public Attributes

Brickm_pBricks
int m_nNumBricks
Orientation m_nOrientation

Detailed Description

Definition at line 31 of file OSGBrick.h.


Member Enumeration Documentation

Enumerator:
XY 
XZ 
YZ 
UNDEF 

Definition at line 35 of file OSGBrick.h.

00036     {
00037         XY    = 0,
00038         XZ    = 1,
00039         YZ    = 2,
00040         UNDEF = 3   // especially for 3D textures
00041     };


Constructor & Destructor Documentation

osg::BrickSet::BrickSet ( void   )  [inline]

Definition at line 5 of file OSGBrick.inl.

00005                        : 
00006     m_pBricks(0), 
00007     m_nNumBricks(0), 
00008     m_nOrientation(UNDEF) 
00009 {
00010 }

osg::BrickSet::~BrickSet ( void   ) 

Definition at line 22 of file OSGBrick.cpp.

References m_pBricks.

00023 {
00024     delete [] m_pBricks;
00025 }


Member Function Documentation

Brick * osg::BrickSet::sortBricks3D ( const Matrix modelMat,
const Vec3f eyePoint 
)

Definition at line 492 of file OSGBrick.cpp.

References osg::Brick::center, osg::Brick::distance, m_nNumBricks, m_pBricks, osg::TransformationMatrix< ValueTypeT >::mult(), osg::Brick::next, and osg::Brick::prev.

Referenced by osg::TextureManager::sortBricks().

00493 {
00494     
00495     Brick  *BrickList = m_pBricks;
00496 
00497     Int32   nBrick;
00498     Real32  distance;
00499     Brick  *previous, *current, *incoming;
00500     
00501     Vec3f transformedCenter;
00502 
00503     m_pBricks[0].prev = NULL;
00504     m_pBricks[0].next = NULL;
00505 
00506     modelMat.mult(m_pBricks[0].center, transformedCenter);
00507 
00508     m_pBricks[0].distance = (eyePoint - transformedCenter).length();
00509     
00510 
00511     for(nBrick = 1; nBrick < m_nNumBricks; nBrick++) 
00512     {
00513         incoming = &(m_pBricks[nBrick]);
00514 
00515         modelMat.mult(incoming->center, transformedCenter);
00516 
00517         distance = (eyePoint - transformedCenter).length();
00518 
00519         incoming->distance = distance;
00520         incoming->next     = NULL;
00521         incoming->prev     = NULL;
00522 
00523         current  = BrickList;
00524         previous = NULL;
00525 
00526         while((current != NULL) && (current->distance > distance)) 
00527         {
00528             previous = current;
00529             current = current->next;
00530         }
00531 
00532         // insert 
00533         if (current == NULL) 
00534         {
00535             // insert at the end of the list;
00536             previous->next = incoming;
00537             incoming->prev = previous;
00538             
00539         }
00540         else
00541         {
00542             incoming->next = current;
00543             incoming->prev = current->prev;
00544             current->prev  = incoming;
00545 
00546             if (incoming->prev == NULL) 
00547             {
00548                 BrickList = incoming;
00549             } 
00550             else
00551             {
00552                 incoming->prev->next = incoming;
00553             }
00554         }
00555     }
00556     
00557     return BrickList;
00558 }

Brick * osg::BrickSet::sortBricks2D ( bool  backToFront  ) 

Definition at line 562 of file OSGBrick.cpp.

References m_nNumBricks, m_pBricks, osg::Brick::next, and osg::Brick::prev.

Referenced by osg::TextureManager::sortBricks().

00563 {
00564     Brick *brickList = m_pBricks;
00565     
00566     if(brickList) 
00567     {
00568         if(backToFront) 
00569         {
00570             for(int i = m_nNumBricks - 1; i >= 0; i--) 
00571             {
00572                 m_pBricks[i].prev = &(m_pBricks[i + 1]);
00573                 m_pBricks[i].next = &(m_pBricks[i - 1]);
00574             }
00575             
00576             m_pBricks[0].next                = NULL;
00577             m_pBricks[m_nNumBricks - 1].prev = NULL;
00578             
00579             brickList = &(m_pBricks[m_nNumBricks - 1]);
00580         } 
00581         else 
00582         {
00583             for (int i = 0; i < m_nNumBricks; i++) 
00584             {
00585                 m_pBricks[i].prev = &(m_pBricks[i - 1]);
00586                 m_pBricks[i].next = &(m_pBricks[i + 1]);
00587             }
00588             
00589             m_pBricks[0].prev                = NULL;
00590             m_pBricks[m_nNumBricks - 1].next = NULL;
00591             
00592             brickList = &(m_pBricks[0]);
00593         }
00594     }
00595     
00596     return brickList;
00597 }

void osg::BrickSet::buildBrickTextures ( ChunkMaterialPtr material,
TextureSet textures,
TextureManager::TextureMode  mode 
)

Definition at line 314 of file OSGBrick.cpp.

References osg::beginEditCP(), osg::ImageBase::create(), osg::endEditCP(), m_nNumBricks, m_pBricks, makeTexture(), osg::Brick::minVox, osg::Brick::numTextures, osg::Brick::texStage, osg::Brick::texture, osg::TextureManager::TM_2D, osg::TextureManager::TM_2D_Multi, osg::TextureManager::TM_3D, and osg::Brick::voxSize.

Referenced by osg::TextureManager::buildTextures().

00317 {
00318     // overall number of textures
00319     UInt32 numTextures = textures.size();
00320     
00321     if(mode == TextureManager::TM_2D_Multi)
00322         numTextures *= 2;
00323     
00324     beginEditCP(material);
00325     {
00326         // build all texture chunks
00327         for(Int32 index = 0; index < m_nNumBricks; index++)
00328         {
00329             Int32 &resX  = m_pBricks[index].voxSize[0];
00330             Int32 &resY  = m_pBricks[index].voxSize[1];
00331             Int32 &resZ  = m_pBricks[index].voxSize[2];
00332             
00333             Int32 &nXMin = m_pBricks[index].minVox[0];
00334             Int32 &nYMin = m_pBricks[index].minVox[1];
00335             Int32 &nZMin = m_pBricks[index].minVox[2];
00336             
00337             int texCounter = 0;
00338             
00339             m_pBricks[index].texture     = new TextureChunkPtr[numTextures];
00340             m_pBricks[index].texStage    = new UInt32[numTextures];
00341             m_pBricks[index].numTextures = numTextures;
00342             
00343             // create texture chunks
00344             for(UInt32 tch = 0; tch < textures.size(); tch++) 
00345             { 
00346                 ImagePtr img = Image::create();
00347                 
00348                 switch (mode)
00349                 {
00350                     case TextureManager::TM_2D_Multi: // 2D multi textures
00351                     {
00352                         // first texture
00353                         textures[tch]->_image->slice(resX == 2 ? nXMin : -1,
00354                                                      resY == 2 ? nYMin : -1,
00355                                                      resZ == 2 ? nZMin : -1,
00356                                                      img);
00357                         if (index == 0)
00358                         {
00359                             m_pBricks[index].texture[texCounter] = 
00360                                 makeTexture(textures[tch]->_internalFormat,
00361                                             textures[tch]->_externalFormat,
00362                                             img                           );
00363                         }
00364                         else
00365                         {
00366                             // each but first brick can reuse texture 
00367                             // chunks of previous brick
00368 
00369                             m_pBricks[index].texture[texCounter] = 
00370                                 m_pBricks[index-1].texture[texCounter+1];
00371                         }
00372                         
00373                         m_pBricks[index].texStage[texCounter] = 
00374                             textures[tch]->_textureStage0;
00375 
00376                         material->addChunk(
00377                             m_pBricks[index].texture[texCounter]);
00378 
00379                         texCounter++;
00380                         
00381                         // second texture
00382                         img = Image::create();
00383 
00384                         textures[tch]->_image->slice(
00385                             resX == 2 ? nXMin + 1 : -1,
00386                             resY == 2 ? nYMin + 1 : -1,
00387                             resZ == 2 ? nZMin + 1 : -1,
00388                             img                       );
00389 
00390                         m_pBricks[index].texture[texCounter] = 
00391                             makeTexture(textures[tch]->_internalFormat,
00392                                         textures[tch]->_externalFormat,
00393                                         img                           );
00394 
00395                         m_pBricks[index].texStage[texCounter] = 
00396                             textures[tch]->_textureStage1;
00397 
00398                         material->addChunk(
00399                             m_pBricks[index].texture[texCounter]);
00400 
00401                         texCounter++;
00402                         
00403                         break;
00404                     }
00405                     
00406                     case TextureManager::TM_2D: // 2D ordinary textures
00407                     {
00408                         textures[tch]->_image->slice(resX == 1 ? nXMin : -1,
00409                                                      resY == 1 ? nYMin : -1,
00410                                                      resZ == 1 ? nZMin : -1,
00411                                                      img);
00412 
00413                         m_pBricks[index].texture[texCounter] = 
00414                             makeTexture(textures[tch]->_internalFormat,
00415                                         textures[tch]->_externalFormat,
00416                                         img                           );
00417 
00418                         m_pBricks[index].texStage[texCounter] = 
00419                             textures[tch]->_textureStage0;
00420 
00421                         material->addChunk(
00422                             m_pBricks[index].texture[texCounter]);
00423 
00424                         texCounter++;
00425                         
00426                         break;
00427                     }
00428                     
00429                     case TextureManager::TM_3D: // 3D ordinary textures
00430                     default:
00431                     {
00432                         textures[tch]->_image->subImage(nXMin, nYMin, nZMin,
00433                                                         resX, resY, resZ,
00434                                                         img                );
00435 
00436                         m_pBricks[index].texture[texCounter] = 
00437                             makeTexture(textures[tch]->_internalFormat,
00438                                         textures[tch]->_externalFormat,
00439                                         img                           );
00440 
00441                         m_pBricks[index].texStage[texCounter] = 
00442                             textures[texCounter]->_textureStage0;
00443 
00444                         material->addChunk(
00445                             m_pBricks[index].texture[texCounter]);
00446 
00447                         texCounter++;
00448                         
00449                         break;
00450                     }
00451                 }
00452                 
00453             } // for all registered textures
00454             
00455         } // for all bricks
00456     }
00457     endEditCP(material);
00458 }

void osg::BrickSet::reloadBrickTextures ( DrawActionBase action,
UInt32  texStage 
)

Definition at line 462 of file OSGBrick.cpp.

References osg::DrawActionBase::getWindow(), m_nNumBricks, m_pBricks, osg::Brick::numTextures, and osg::Window::refreshGLObject().

Referenced by osg::TextureManager::reloadTexture().

00463 {
00464     for(Int32 i = 0; i < m_nNumBricks; i++)
00465     {
00466         for(Int32 j = 0; j < m_pBricks[i].numTextures; j++)
00467         {
00468             if(m_pBricks[i].texStage[j] == texStage)
00469             {
00470                 action->getWindow()->refreshGLObject(
00471                     m_pBricks[i].texture[j]->getGLId());
00472             }
00473         }
00474     }
00475 }

void osg::BrickSet::clearBrickTextures ( ChunkMaterialPtr material  ) 

Definition at line 479 of file OSGBrick.cpp.

References m_nNumBricks, m_pBricks, and osg::Brick::numTextures.

Referenced by osg::TextureManager::clearTextures().

00480 {
00481     for(Int32 i = 0; i < m_nNumBricks; i++)
00482     {
00483         for(Int32 j = 0; j < m_pBricks[i].numTextures; j++)
00484         {
00485             material->subChunk(m_pBricks[i].texture[j]);
00486         }
00487     }
00488 }

void osg::BrickSet::buildBricks3D ( DVRVolume volume,
Vec3f  brickSubdivision,
Int32  overlap = 1,
Orientation  ori = UNDEF 
)

Definition at line 27 of file OSGBrick.cpp.

References DVRVOLUME_PARAMETER, FDEBUG, osg::Brick::init(), m_nNumBricks, m_nOrientation, m_pBricks, osg::NullFC, SFATAL, SINFO, and SWARNING.

Referenced by osg::TextureManager::buildTextures().

00031 {
00032     FDEBUG(("BrickSet::buildBricks3D %d %d %d\n", 
00033             brickSize[0],
00034             brickSize[1], 
00035             brickSize[2]));
00036 
00037     SINFO << "BrickSet::buildBricks3D (size)" 
00038           << brickSize[0] << ", " 
00039           << brickSize[1] << ","
00040           << brickSize[2] << std::endl;
00041     
00042     m_nOrientation = ori;
00043     
00044     DVRVolumeTexturePtr vT = DVRVOLUME_PARAMETER(volume, DVRVolumeTexture);
00045 
00046     if(vT == NullFC) 
00047     {
00048         SWARNING << "BrickSet::buildTextures3D - No Volume" << std::endl;
00049         return;
00050     }
00051 
00052     if((brickSize[0] <= overlap) || 
00053        (brickSize[1] <= overlap) || 
00054        (brickSize[2] <= overlap)  )
00055     {
00056         SFATAL << "BrickSet::buildBricks3D - brickSize too small: "
00057                << brickSize[0] << ","
00058                << brickSize[1] << "," 
00059                << brickSize[2] << "for overlap " 
00060                << overlap << std::endl;
00061 
00062         return;
00063     }
00064     
00065     Vec3f vox  = vT->getSliceThickness();
00066     Vec3f res  = vT->getResolution();
00067     Int32 resX = Int32(res[0]);
00068     Int32 resY = Int32(res[1]);
00069     Int32 resZ = Int32(res[2]);
00070 
00071     Int32 nNumBricksX = Int32((resX - overlap) / (brickSize[0] - overlap));
00072     Int32 nNumBricksY = Int32((resY - overlap) / (brickSize[1] - overlap));
00073     Int32 nNumBricksZ = Int32((resZ - overlap) / (brickSize[2] - overlap));
00074 
00075     SINFO << "BrickSet::buildBricks3D (num)" 
00076           << nNumBricksX << ", " 
00077           << nNumBricksY << ","
00078           << nNumBricksZ << std::endl;
00079     
00080     m_nNumBricks = nNumBricksX * nNumBricksY * nNumBricksZ; 
00081 
00082     m_pBricks = new Brick[m_nNumBricks];
00083     
00084     Int32 nBrickSizeX = Int32(brickSize[0]);
00085     Int32 nBrickSizeY = Int32(brickSize[1]);
00086     Int32 nBrickSizeZ = Int32(brickSize[2]);
00087 
00088     Int32 nXMin = 0;
00089     Int32 nYMin = 0;
00090     Int32 nZMin = 0;
00091 
00092     Real32 xmin = (overlap - 1 + 0.5f - resX / 2) * vox[0];
00093     Real32 ymin = (overlap - 1 + 0.5f - resY / 2) * vox[1];
00094     Real32 zmin = (overlap - 1 + 0.5f - resZ / 2) * vox[2];
00095 
00096     Real32 xmax = 0, ymax = 0, zmax = 0;
00097     
00098     Int32 index = 0;
00099     
00100     for(Int32 z = 0; z < nNumBricksZ; z++) 
00101     {
00102         nYMin = 0;
00103         ymin  = (overlap - 1 + 0.5f - resY / 2) * vox[1];
00104         
00105         for(Int32 y = 0; y < nNumBricksY; y++) 
00106         {
00107             nXMin = 0;
00108             xmin  = (overlap - 1 + 0.5f - resX / 2) * vox[0];
00109             
00110             for(Int32 x = 0; x < nNumBricksX; x++) 
00111             {
00112                 xmax = xmin + (nBrickSizeX - (2 * (overlap - 1) + 1)) * vox[0];
00113                 ymax = ymin + (nBrickSizeY - (2 * (overlap - 1) + 1)) * vox[1];
00114                 zmax = zmin + (nBrickSizeZ - (2 * (overlap - 1) + 1)) * vox[2];
00115                 
00116                 m_pBricks[index].init(nXMin,       nYMin,       nZMin,
00117                                       nBrickSizeX, nBrickSizeY, nBrickSizeZ,
00118                                       xmin,        ymin,        zmin,
00119                                       xmax,        ymax,        zmax,
00120                                       overlap, 
00121                                       ori                                  );
00122                 
00123                 index++;
00124 
00125                 nXMin += nBrickSizeX - (2 * overlap - 1);
00126                 xmin   = xmax; 
00127             }
00128 
00129             nYMin += nBrickSizeY - (2 * overlap - 1);
00130             ymin   = ymax;
00131         }
00132         
00133         nZMin += nBrickSizeZ - (2 * overlap - 1);
00134         zmin   = zmax;
00135     }
00136 }

void osg::BrickSet::buildBricks2D ( DVRVolume volume,
Orientation  ori 
)

Definition at line 139 of file OSGBrick.cpp.

References DVRVOLUME_PARAMETER, osg::Brick::init(), m_nNumBricks, m_nOrientation, m_pBricks, osg::NullFC, SFATAL, UNDEF, XY, XZ, and YZ.

Referenced by osg::TextureManager::buildTextures().

00140 {
00141     m_nOrientation = ori;
00142     
00143     DVRVolumeTexturePtr vT = DVRVOLUME_PARAMETER(volume, DVRVolumeTexture);
00144 
00145     if(vT == NullFC) 
00146         return;
00147     
00148     Vec3f  vox = vT->getSliceThickness();
00149     Vec3f  res = vT->getResolution();
00150 
00151     Int32  resX = 0, resY= 0, resZ= 0;
00152     Real32 xmin = 0, ymin = 0, zmin = 0;             
00153     Real32 xmax = 0, ymax = 0, zmax = 0;          
00154     Real32 xinc = 0, yinc = 0, zinc = 0;
00155     
00156     switch(ori) 
00157     {
00158         case XY: 
00159         {
00160             // XY stack of textures
00161             resX  = Int32(res[0]);
00162             resY  = Int32(res[1]);
00163             resZ  = 1;
00164             
00165             xinc = 0;
00166             yinc = 0;
00167             zinc = 1;
00168 
00169             // "geometrical" size of the brick
00170             xmin = (-(res[0] - 1) / 2) * vox[0];  
00171             ymin = (-(res[1] - 1) / 2) * vox[1];
00172             zmin = (-(res[2]    ) / 2) * vox[2];
00173             
00174             xmax = -xmin;
00175             ymax = -ymin;
00176             zmax =  zmin + zinc * vox[2];
00177 
00178             m_nNumBricks = int(res[2]);
00179             m_pBricks    = new Brick[m_nNumBricks];
00180 
00181             break;
00182         }
00183 
00184         case XZ: 
00185         {
00186             // XZ stack of textures
00187             resX  = Int32(res[0]);
00188             resY  = 1;
00189             resZ  = Int32(res[2]);
00190             
00191             xinc = 0;
00192             yinc = 1;
00193             zinc = 0;
00194             
00195             // "geometrical" size of the brick
00196             xmin = (-(res[0] - 1) / 2) * vox[0];  
00197             ymin = (-(res[1]    ) / 2) * vox[1];
00198             zmin = (-(res[2] - 1) / 2) * vox[2];
00199             
00200             xmax = -xmin;
00201             ymax =  ymin + yinc * vox[1];
00202             zmax = -zmin;
00203             
00204             m_nNumBricks = int(res[1]);
00205             m_pBricks    = new Brick[m_nNumBricks];
00206 
00207             break;
00208         }
00209 
00210         case YZ: 
00211         {
00212             // YZ stack of textures
00213             resX  = 1;
00214             resY  = Int32(res[1]);
00215             resZ  = Int32(res[2]);
00216             
00217             xinc = 1;
00218             yinc = 0;
00219             zinc = 0;
00220             
00221             // "geometrical" size of the brick
00222             xmin = (-(res[0]    ) / 2) * vox[0];  
00223             ymin = (-(res[1] - 1) / 2) * vox[1];
00224             zmin = (-(res[2] - 1) / 2) * vox[2];
00225             
00226             xmax =  xmin + xinc * vox[0];
00227             ymax = -ymin;
00228             zmax = -zmin;
00229             
00230             m_nNumBricks = int(res[0]);
00231             m_pBricks    = new Brick[m_nNumBricks];
00232 
00233             break;
00234         }
00235 
00236         case UNDEF: 
00237         {
00238             SFATAL << "BrickSet::buildBricks2D called with unspecified "
00239                    << "orientation" 
00240                    << std::endl;
00241             break;
00242         }
00243     }
00244     
00245     for(Int32 index = 0; index < m_nNumBricks; index++) 
00246     {
00247         m_pBricks[index].init(resX == 1 ? index : 0,
00248                               resY == 1 ? index : 0,
00249                               resZ == 1 ? index : 0,
00250                               resX, resY, resZ,
00251                               xmin, ymin, zmin,
00252                               xmax, ymax, zmax, 
00253                               1, 
00254                               ori);
00255         
00256         xmin += xinc * vox[0];
00257         xmax += xinc * vox[0];
00258         
00259         ymin += yinc * vox[1];
00260         ymax += yinc * vox[1];
00261         
00262         zmin += zinc * vox[2];
00263         zmax += zinc * vox[2];
00264     }
00265 }

TextureChunkPtr osg::BrickSet::makeTexture ( UInt32  internalFormat,
UInt32  externalFormat,
ImagePtr  image 
) [static]

! FIXME: this is required by the PreIntegration shader but ! may not be supported on all OpenSG platforms - so we must ! add a way that the shader can specify the wrapping

Definition at line 269 of file OSGBrick.cpp.

References osg::beginEditCP(), osg::TextureChunkBase::create(), osg::endEditCP(), and FDEBUG.

Referenced by buildBrickTextures().

00272 {
00273     TextureChunkPtr chunk = TextureChunk::create();
00274 
00275     beginEditCP(chunk);
00276     {
00277         chunk->setImage         (img           );
00278         chunk->setInternalFormat(internalFormat);
00279         chunk->setExternalFormat(externalFormat);
00280 
00281         FDEBUG(("TextureManager - makeTexture: intern %d - extern %d\n",
00282                 internalFormat, externalFormat));
00283 
00287 #if defined GL_ARB_texture_border_clamp
00288         chunk->setWrapS(GL_CLAMP_TO_BORDER);
00289         chunk->setWrapT(GL_CLAMP_TO_BORDER);
00290         chunk->setWrapR(GL_CLAMP_TO_BORDER);
00291 #else
00292 //      chunk->setWrapS(GL_CLAMP_TO_EDGE);
00293 //      chunk->setWrapT(GL_CLAMP_TO_EDGE);
00294 //      chunk->setWrapR(GL_CLAMP_TO_EDGE);
00295         
00296         chunk->setWrapS(GL_CLAMP);
00297         chunk->setWrapT(GL_CLAMP);
00298         chunk->setWrapR(GL_CLAMP);
00299 #endif
00300 
00301         chunk->setMinFilter(GL_LINEAR);
00302         chunk->setMagFilter(GL_LINEAR);
00303     
00304 //      chunk->setEnvMode(GL_REPLACE);
00305         chunk->setEnvMode(GL_MODULATE);
00306     }
00307     endEditCP(chunk);
00308 
00309     return chunk;
00310 }


Member Data Documentation

Definition at line 45 of file OSGBrick.h.

Referenced by buildBricks2D(), and buildBricks3D().


The documentation for this struct was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1