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

VolRenBase.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     9-20-02
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2002 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 //volrenbase.h
00019 
00020 #include "VolRenBase.h"
00021 #include <volrenalg/VolRenAlgBase.h>
00022 #include <textureGlift.h>
00023 #include <volume/VolytopeStd.h>
00024 #include <GL/glUtil.h>
00025 
00026 
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030 
00031 #include <GL/gl.h>
00032 
00033 #include <iostream>
00034 
00035 using namespace std;
00036 using namespace gutz;
00037 using namespace glift;
00038 
00039 #define VRB_MAX_VERTS 9
00040 
00041 ///////////////////////////////////////////////////////////////////////////
00042 // Construct
00043 ///////////////////////////////////////////////////////////////////////////
00044 VolRenBase::VolRenBase()
00045 : _currentAlg(0), 
00046 _vsBuff(0),
00047 _v(new Volume())
00048 {
00049 
00050    //VolSamples *vs = new VolSamples(500000);
00051 
00052    _vsv.push_back(new VolSamples(500000));
00053    _vsv.push_back(new VolSamples(500000));
00054    _vsv.push_back(new VolSamples(500000));
00055 
00056    init();
00057 }
00058 
00059 VolRenBase::~VolRenBase()
00060 {
00061    _currentAlg = 0;
00062 }
00063 
00064 ///////////////////////////////////////////////////////////////////////////
00065 // initialize
00066 ///////////////////////////////////////////////////////////////////////////
00067 void VolRenBase::init()
00068 {
00069    if(!_currentAlg)
00070    {
00071       _currentAlg = new VolRenAlgBase();
00072    }
00073    _currentAlg->init();
00074 
00075    if(!_currentSlicer)
00076    {
00077       _currentSlicer = new VolSlicer();
00078    }
00079 
00080 }
00081 
00082 ///////////////////////////////////////////////////////////////////////////
00083 // draw the volume
00084 ///////////////////////////////////////////////////////////////////////////
00085 
00086 void VolRenBase::drawDef(const gutz::RenderEvent &re)
00087 {
00088    const CameraSP cam  = re.getCamera();
00089    const ManipSP manip = re.getManip();
00090 
00091    /// generate the slice axis
00092    _sliceDir = genSliceAxis(0, vec3f((cam->getViewMatrix() * manip->getMatrix()).trans()));
00093 
00094    /// tell the algorithm which way it is going
00095    _currentAlg->setSliceAxis(_sliceDir);
00096    //give the rendering algorithm some clues on how to render
00097    _currentAlg->setLightVec(_ltv);
00098    _currentAlg->enableLight(_lightOn);
00099    _currentAlg->enableLTHA(_lthaOn);
00100 
00101    /// construct the model view matrix
00102    mat4f mv = cam->getViewMatrix() * manip->getMatrix();
00103 
00104    /// get the sorted volytopes
00105    VolytopeVec vt = _v->volys.sortFromPoint(mv.inv() * gutz::vec4f_w);  
00106 
00107    //get ready to render
00108    glPushMatrix();
00109    {
00110       //use the default model matrix
00111       glMultMatrixf(manip->getWorldTransform().m);
00112 
00113       // swap brick order if back to front
00114       int inc = 1;
00115       int start = 0;
00116       int end  = vt.size();
00117       if(_sliceDir.dot(vec3f_neg_z) > 0.0f)
00118       {
00119          inc = -1;
00120          start = vt.size()-1;
00121          end = -1;
00122       }
00123 
00124       for(int i=start; i!=end; i+=inc)
00125       {
00126          _vt = vt[i];
00127          if(_vt.isNull()) continue;
00128 
00129          arrayw1v3f vo = _vt->getVerts();     
00130          arrayw1v3f tx = _vt->getTcoords();
00131 
00132          //make sure to apply volume model matrix
00133          glMultMatrixf(_vt->getMatrix().m);
00134 
00135          _currentAlg->setVolytope(_vt);
00136 
00137          /////////////////////////////////
00138          //slice up the volume's domain
00139          preSlice(re);
00140          _currentSlicer->slice(mv, _vt, _vsv[_vsBuff], _sliceDir);
00141          postSlice(re);
00142          ////////////////////////////////
00143 
00144          ////////////////////////////////
00145          //inform the algorithm that it will be rendering
00146          _currentAlg->bind();
00147          { 
00148             //let the algorithm draw it
00149             _currentAlg->drawTris(_vsv[_vsBuff]);
00150 
00151          }
00152          ////////////////////////////////
00153          //inform the algorithm that it is done
00154          _currentAlg->release();
00155       }
00156    }
00157    glPopMatrix();
00158 
00159    glErr(cerr, "VolRenBase:end-draw()");
00160 }
00161 
00162 ///////////////////////////////////////////////////////////////////////////
00163 // center
00164 ///////////////////////////////////////////////////////////////////////////
00165 gutz::vec3f VolRenBase::getCenter(const gutz::CameraEvent &ce) const
00166 {
00167    if(_v) 
00168    {
00169       return ce.getCamera()->getViewMatrix() * 
00170              ce.getManip()->getMatrix() * 
00171              _v->volys.getCenter();
00172    }
00173    return gutz::vec3f_max;
00174 }
00175 
00176 
00177 ///////////////////////////////////////////////////////////////////////////
00178 // Set the current rendering algorithm
00179 ///////////////////////////////////////////////////////////////////////////
00180 void VolRenBase::setAlg(VolRenAlgBase *vrab)
00181 { 
00182    _currentAlg = vrab; 
00183 }
00184 
00185 void VolRenBase::setSlicer(VolSlicer *vslice)
00186 {
00187    _currentSlicer = vslice;
00188 }
00189 
00190 void VolRenBase::err(char *when, float v, char *where)
00191 {
00192 #ifdef _DEBUG
00193    cout << "VolRenBase:" << when;
00194    if(where)
00195       cout << " - " << where;
00196    cout << "  " << v;
00197    cout << endl;
00198 #endif
00199 }

Send questions, comments, and bug reports to:
jmk