Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDVRVolumeTexture.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000,2001 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <OSGConfig.h>
00047 
00048 #include "OSGDVRVolumeTexture.h"
00049 
00050 #include <OSGImage.h>
00051 
00052 OSG_USING_NAMESPACE
00053 
00059 /*----------------------- constructors & destructors ----------------------*/
00060 
00062 
00063 DVRVolumeTexture::DVRVolumeTexture(void) :
00064     Inherited()
00065 {
00066 }
00067 
00069 
00070 DVRVolumeTexture::DVRVolumeTexture(const DVRVolumeTexture &source) :
00071     Inherited(source)
00072 {
00073 }
00074 
00076 
00077 DVRVolumeTexture::~DVRVolumeTexture(void)
00078 {
00079     if (getImage() != NullFC)
00080     {
00081         setImage(NullFC);
00082     }
00083 }
00084 
00085 /*----------------------------- class specific ----------------------------*/
00086 
00088 
00089 void DVRVolumeTexture::initMethod (void)
00090 {
00091 }
00092 
00094 
00095 void DVRVolumeTexture::changed(BitVector whichField, UInt32 origin)
00096 {
00097     DVRVolumeTexturePtr thisP(*this);
00098   
00099     FDEBUG(("DVRVolumeTexture::changed - \n"));
00100   
00101     if (whichField & ImageFieldMask) 
00102     {
00103         FINFO(("DVRVolumeTexture::changed - new Image\n"));
00104 
00105         if(origin & ChangedOrigin::Abstract)
00106         {
00107             if(origin & ChangedOrigin::AbstrIncRefCount)
00108             {
00109                 addRefCP(_sfImage.getValue());
00110             }
00111             else
00112             {
00113                 ImagePtr pImage = _sfImage.getValue();
00114                 
00115                 _sfImage.setValue(NullFC);
00116                 
00117                 setImage(pImage);
00118             }
00119         }
00120         
00121         _mfHistogram.resize(256);
00122         
00123         // update histogram
00124         Real32 *hist   = &(_mfHistogram[0]);
00125         UChar8 *img    = getImage()->getData();
00126         Real32  maxVal = 0;
00127         
00128         for(UInt32 i = 0; i < 256; i++)
00129             hist[i] = 0;
00130 
00131         if(img == NULL) 
00132             return;
00133     
00134         FDEBUG(("Image: %d %d %d\n",
00135                 getImage()->getWidth(), 
00136                 getImage()->getHeight(), 
00137                 getImage()->getDepth()));
00138 
00139         // need to fix this for compressed textures!
00140         for(Int32 j = 0;j < getImage()->getSize();j++)
00141         {
00142 //          cerr << j << ": " << (int) img[j] << std::endl ;
00143             hist[img[j]]++;
00144         }
00145         
00146         for(UInt32 k = 0; k < 256; k++)
00147             maxVal = (hist[k] > maxVal) ? hist[k] : maxVal;
00148         
00149         _sfMaxVal.setValue(maxVal);
00150 
00151         // update sliceThickness
00152         const std::string * sTatt = 
00153             getImage()->findAttachmentField("SliceThickness");
00154 
00155         if(sTatt) 
00156         {
00157             Real64 sT[3];
00158 
00159             sscanf(sTatt->c_str(), "%lf %lf %lf", &sT[0], &sT[1], &sT[2]);
00160 
00161             _sfSliceThickness.setValue(
00162                 Vec3f(Real32(sT[0]), 
00163                       Real32(sT[1]), 
00164                       Real32(sT[2])));
00165         } 
00166         else 
00167         {
00168             SWARNING << "DVRVolumeTexture::changed - No SliceThickness found"
00169                      << std::endl;
00170         }
00171         
00172         // update resolution
00173         const std::string * resAtt = 
00174             getImage()->findAttachmentField("Resolution");
00175 
00176         if (resAtt) 
00177         {
00178             Real64 sT[3];
00179 
00180             sscanf(resAtt->c_str(), "%lf %lf %lf", &sT[0], &sT[1], &sT[2]);
00181 
00182             _sfResolution.setValue(
00183                 Vec3f(Real32(sT[0]), 
00184                       Real32(sT[1]), 
00185                       Real32(sT[2])));
00186         } 
00187         else 
00188         {
00189             _sfResolution.setValue(Vec3f(getImage()->getWidth (), 
00190                                          getImage()->getHeight(), 
00191                                          getImage()->getDepth ()));
00192         }
00193 
00196         whichField &= ~FileNameFieldMask;
00197     }
00198     
00199     if (whichField & FileNameFieldMask)
00200     {
00201         FINFO(("DVRVolumeTexture::changed - new fileName\n"));
00202         
00203         ImagePtr datImage = Image::create();
00204     
00205         datImage->read(_sfFileName.getValue().c_str());
00206 
00207         datImage->dump();
00208 
00209         beginEditCP(thisP, ImageFieldMask);
00210         {
00211             setImage(datImage);
00212         }
00213         endEditCP  (thisP, ImageFieldMask);
00214     }
00215 
00216     Inherited::changed(whichField, origin);
00217 }
00218 
00220 
00221 void DVRVolumeTexture::dump(      UInt32    , 
00222                             const BitVector ) const
00223 {
00224     SLOG << "Dump DVRVolumeTexture NI" << std::endl;
00225 }
00226 
00227 
00228 /*-------------------------------------------------------------------------*/
00229 /*                              cvs id's                                   */
00230 
00231 #ifdef __sgi
00232 #pragma set woff 1174
00233 #endif
00234 
00235 #ifdef OSG_LINUX_ICC
00236 #pragma warning( disable : 177 )
00237 #endif
00238 
00239 namespace
00240 {
00241     static char cvsid_cpp[] = "@(#)$Id: $";
00242     static char cvsid_hpp[] = OSGDVRVOLUMETEXTURE_HEADER_CVSID;
00243     static char cvsid_inl[] = OSGDVRVOLUMETEXTURE_INLINE_CVSID;
00244 }
00245 

Generated on Thu Aug 25 04:04:31 2005 for OpenSG by  doxygen 1.4.3