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

centraldiff.cpp

Go to the documentation of this file.
00001 // $Id: centraldiff.cpp,v 1.3 2003/03/13 17:32:14 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 #include <iostream>
00028 #include <queue>
00029 
00030 #include "vlvarlist.h"
00031 #include "vlvolume.h"
00032 #include "vlvoxelneighbors.h"
00033 #include "vlgenericfactory.h"
00034 
00035 #include "centraldiff.h"
00036 
00037 typedef vlGenericFactory<vlVolProcessorCentralDiff> vlVolProcessorCentralDiffFactory;
00038 VL_EXPORT_COMPONENT_FACTORY( centraldiffvol, vlVolProcessorCentralDiffFactory );
00039 
00043 vlVolProcessorCentralDiff::vlVolProcessorCentralDiff()
00044 {
00045   infoRef().setName("CentralDiff");
00046   infoRef().setVersion(0,0,1);
00047   infoRef().setService("CentralDiff", "Computes a central difference gradient volume.");
00048 }
00049 
00053 vlVolProcessorCentralDiff::~vlVolProcessorCentralDiff()
00054 {
00055 }
00056 
00057 
00058 void vlVolProcessorCentralDiff::init()
00059 {
00060   configRef().clear();
00061 }
00062 
00063 
00064 bool vlVolProcessorCentralDiff::run()
00065 {
00066   // Check all error conditions...
00067 
00068   if(!vol())
00069     return (false);
00070 
00071   m_cdVolume = new vlVolume(vol()->dim(), Float);
00072 
00073   if(!m_cdVolume->isValid()) {
00074     std::cout << "Unable to create float volume." << std::endl;
00075     return (false);
00076   }
00077 
00078   bool retValue(false);
00079 
00080   callFunctionOnDataTypeNoArgs(vol()->dataType(), retValue, runT);
00081 
00082   if(retValue) {
00084     resultsRef().add(m_cdVolume, "gradientVolume", "A volume of gradients (float)", true);
00085   }
00086   
00087   return (retValue);
00088 }
00089 
00090 
00091 template <class DataType>
00092 bool vlVolProcessorCentralDiff::runT(DataType & dummy)
00093 {
00094   vlVolIter<DataType> iter(vol());
00095 
00096   if(!iter.setVoxelOperation(vlVoxelOp::CentralDiff)) {
00097     std::cout << "Cannot set voxel operation to central diff." << std::endl;
00098     return (false);
00099   }
00100 
00101   vlVoxelOpValue value;
00102   vlVolIter<float> fiter(m_cdVolume);
00103   
00104   while(!iter.end()) {
00105     iter.getOp(value);
00106     fiter.set((float)value.dl());
00107     iter.nextXYZ();
00108     fiter.nextXYZ();
00109   }
00110   
00111   return (true);
00112 }
00113 
00114 
00115 

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