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

vlvoxelop_sobel.h

Go to the documentation of this file.
00001 // $Id: vlvoxelop_sobel.h,v 1.1 2003/08/12 04:18:55 sarang Exp $
00002 //
00003 // OpenVL - A Library for working with volumetric datasets.
00004 //          http://openvl.sf.net
00005 //
00006 // Copyright (C) 2000-2003  Sarang Lakare <sarang#users.sf.net>
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems to openvl-devel@lists.sf.net or
00024 // at the OpenVL website.
00025 //
00026 
00027 #ifndef _vlVoxelOpSobel_h
00028 #define _vlVoxelOpSobel_h
00029 
00030 #include "vlvoxeloperator.h"
00031 #include "vlvarlistadmin.h"
00032 #include "vloffset.h"
00033 
00040 template <typename DataType, vlLayoutType Layout>
00041 class vlVoxelOpSobel : public vlVoxelOperator<DataType, Layout>
00042 {
00043 public:
00044   vlVoxelOpSobel()
00045   {
00046     // for X direction
00047     m_offsetsX[0] = vlOffset(1,1,0);
00048     m_offsetsX[1] = vlOffset(1,-1,0);
00049     m_offsetsX[2] = vlOffset(1,0,1);
00050     m_offsetsX[3] = vlOffset(1,0,-1);
00051 
00052     m_offsetsX[4] = vlOffset(-1,1,0);
00053     m_offsetsX[5] = vlOffset(-1,-1,0);
00054     m_offsetsX[6] = vlOffset(-1,0,1);
00055     m_offsetsX[7] = vlOffset(-1,0,-1);
00056 
00057     // for Y direction
00058     m_offsetsY[0] = vlOffset(1,1,0);
00059     m_offsetsY[1] = vlOffset(-1,1,0);
00060     m_offsetsY[2] = vlOffset(0,1,1);
00061     m_offsetsY[3] = vlOffset(0,1,-1);
00062 
00063     m_offsetsY[4] = vlOffset(-1,-1,0);
00064     m_offsetsY[5] = vlOffset(1,-1,0);
00065     m_offsetsY[6] = vlOffset(0,-1,1);
00066     m_offsetsY[7] = vlOffset(0,-1,-1);
00067 
00068     // for Z direction
00069     m_offsetsZ[0] = vlOffset(1,0,1);
00070     m_offsetsZ[1] = vlOffset(-1,0,1);
00071     m_offsetsZ[2] = vlOffset(0,1,1);
00072     m_offsetsZ[3] = vlOffset(0,-1,1);
00073 
00074     m_offsetsZ[4] = vlOffset(-1,0,-1);
00075     m_offsetsZ[5] = vlOffset(1,0,-1);
00076     m_offsetsZ[6] = vlOffset(0,1,-1);
00077     m_offsetsZ[7] = vlOffset(0,-1,-1);
00078   }
00079 
00080   vlVoxelOpType type() { return vlVoxelOp::Sobel; };
00081 
00082   std::string name() { return ("Sobel"); };
00083 
00085   vlLayoutType layout() { return Layout; };
00086 
00088   vlVarList * config() { return (&m_varList); };
00089 
00094   bool getValue(vlVolIterConst<DataType, Layout> & iter, DataType & value)
00095   { return (false); };
00096 
00102   bool getValue(vlVolIterConst<DataType, Layout> & iter, vlVoxelOpValue & value)
00103   {
00104     double dx = iter.getRelativeX(1);
00105     dx += iter.getRelative(m_offsetsX[0]);
00106     dx += iter.getRelative(m_offsetsX[1]);
00107     dx += iter.getRelative(m_offsetsX[2]);
00108     dx += iter.getRelative(m_offsetsX[3]);
00109 
00110     dx -= iter.getRelativeX(-1);
00111     dx -= iter.getRelative(m_offsetsX[4]);
00112     dx -= iter.getRelative(m_offsetsX[5]);
00113     dx -= iter.getRelative(m_offsetsX[6]);
00114     dx -= iter.getRelative(m_offsetsX[7]);
00115 
00116     double dy = iter.getRelativeY(1);
00117     dy += iter.getRelative(m_offsetsY[0]);
00118     dy += iter.getRelative(m_offsetsY[1]);
00119     dy += iter.getRelative(m_offsetsY[2]);
00120     dy += iter.getRelative(m_offsetsY[3]);
00121 
00122     dy -= iter.getRelativeY(-1);
00123     dy -= iter.getRelative(m_offsetsY[4]);
00124     dy -= iter.getRelative(m_offsetsY[5]);
00125     dy -= iter.getRelative(m_offsetsY[6]);
00126     dy -= iter.getRelative(m_offsetsY[7]);
00127 
00128     double dz = iter.getRelativeZ(1);
00129     dz += iter.getRelative(m_offsetsZ[0]);
00130     dz += iter.getRelative(m_offsetsZ[1]);
00131     dz += iter.getRelative(m_offsetsZ[2]);
00132     dz += iter.getRelative(m_offsetsZ[3]);
00133 
00134     dz -= iter.getRelativeZ(-1);
00135     dz -= iter.getRelative(m_offsetsZ[4]);
00136     dz -= iter.getRelative(m_offsetsZ[5]);
00137     dz -= iter.getRelative(m_offsetsZ[6]);
00138     dz -= iter.getRelative(m_offsetsZ[7]);
00139 
00140 
00141     value.setNormal3f(vlNormal3f(dx, dy, dz));
00142 
00143     value.setDl(sqrt(dx*dx+dy*dy+dz*dz));
00144 
00145     return (true);
00146   };
00147 
00148 protected:
00150   vlVarListAdmin m_varList;
00151 
00152   vlOffset m_offsetsX[8], m_offsetsY[8], m_offsetsZ[8];
00153 
00154 };
00155 
00156 #endif // _vlVoxelOpSobel_h

Generated on Fri Mar 18 11:33:15 2005 for OpenVL by doxygen 1.3.3