arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Volume.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     3-22-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 ///Volume.cpp
00019 
00020 #include "Volume.h"
00021 #include "VolytopeStd.h"
00022 
00023 using namespace gutz;
00024 
00025 //-------------------------------------------------------------------------
00026 /// Construction
00027 //-------------------------------------------------------------------------
00028 Volume::Volume()
00029 :SimBase(),
00030 _valid(false),
00031 _vtype(RECTLIN),
00032 _texqual(SIMT_BEST),
00033 _brickDims(128,128,128),
00034 _size(-1),
00035 _centered(false)
00036 {
00037    update();
00038 }
00039 
00040 //-------------------------------------------------------------------------
00041 /// update - main dispatch
00042 //-------------------------------------------------------------------------
00043 void Volume::update()
00044 {
00045    switch(_vtype)
00046    {
00047    case RECTLIN:
00048       updateRectLin();
00049       break;
00050    default:
00051       derr("Volume::update(), WARNING::volType not supported");
00052    }
00053 }
00054 
00055 //-------------------------------------------------------------------------
00056 /// update Recti-linear
00057 //-------------------------------------------------------------------------
00058 void Volume::updateRectLin()
00059 {
00060    ///////////////////////////////////////////////////////////
00061    /// only for un-configured volumes, this is just a
00062    /// convenience thing, so we don't crash when we forget
00063    /// to set the volume.
00064    if(0 == fields.size()) /// need to create a default volytope?
00065    {
00066       setDefault(); /// we don't want to crash.
00067       derr("updateRectLin(), no fields, going default");
00068       return;
00069    }
00070 
00071    ///////////////////////////////////////////////////////////
00072    /// ditch old setup if previously un-configured
00073    /// or something changed
00074    if( (!isValid()) || fields.needUpdate())
00075    {
00076       clearVolytopes();
00077    }
00078    else
00079    {
00080       derr("updateRectLin(), nothing to do");
00081       return; /// nothing to do???
00082    }
00083    ///////////////////////////////////////////////////////////
00084 
00085    if(!fields.checkFields())
00086    {
00087       setDefault();
00088       derr("updateRectLin(), field check failed! going to default mode");
00089       return;  /// make sure the fields are valid
00090    }
00091 
00092    fields.update();
00093    fields.brickData(_brickDims);
00094    updateVolytopesRL();
00095    if(_size != -1)
00096    {
00097       volys.setSize(_size);
00098    }
00099    if(_centered)
00100    {
00101       volys.center();
00102    }
00103 
00104    /// made it this far must be good!
00105    _valid = true;
00106 }
00107 
00108 
00109 //-------------------------------------------------------------------------
00110 /// Clear Volytopes
00111 //-------------------------------------------------------------------------
00112 void Volume::clearVolytopes()
00113 {
00114    volys = VolytopeVec();
00115 }
00116 
00117 //-------------------------------------------------------------------------
00118 /// Update Volytopes
00119 //-------------------------------------------------------------------------
00120 void Volume::updateVolytopesRL()
00121 {
00122    if(volys.size() != 0) /// um they should be!
00123    {
00124       derr("updateVolytopesRL(), volytopes exist! badness");
00125       return;
00126    }
00127 
00128    VolFieldSP f = fields.getField(0);
00129    if(!f)
00130    {
00131       derr("updateVolytopesRL(), ERROR: 0th field invalid!!!");
00132       derr("updateVolytopesRL(), setting default()");
00133       setDefault();
00134       return;
00135    }
00136 
00137    /// initiallize it using the first field
00138    volys = genVolyCubes(f);
00139 
00140    /// for each additional field,
00141    /// add it's data to the volytopes
00142    for(unsigned int i=1; i<fields.size(); ++i)
00143    {
00144       volys.setField(f);
00145    }
00146 
00147 }
00148 
00149 //-------------------------------------------------------------------------
00150 /// Set Default, what to do if we have an invalid volume
00151 //-------------------------------------------------------------------------
00152 void Volume::setDefault()
00153 {
00154    if(0 == volys.size()) /// yep, creat one
00155    {
00156       volys.push_back(VolytopeSP(new VolyCube()));
00157    }
00158    _valid = false; /// still not setup properly
00159 }
00160 
00161 //-------------------------------------------------------------------------
00162 /// Set Size
00163 //-------------------------------------------------------------------------
00164 void Volume::setSize(float size)
00165 {
00166    _size = size;
00167    _valid = false;
00168 }
00169 

Send questions, comments, and bug reports to:
jmk