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

RegularGridVMatrix.cc

Go to the documentation of this file.
00001 00002 // -*- C++ -*- 00003 00004 // RegularGridVMatrix.cc 00005 // 00006 // Copyright (C) 2003 Pascal Vincent 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 /* ******************************************************* 00037 * $Id: RegularGridVMatrix.cc,v 1.5 2004/07/07 17:30:48 tihocan Exp $ 00038 ******************************************************* */ 00039 00041 #include "RegularGridVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00047 RegularGridVMatrix::RegularGridVMatrix() 00048 { 00049 // ... 00050 00051 // ### You may or may not want to call build_() to finish building the object 00052 // build_(); 00053 } 00054 00055 RegularGridVMatrix::RegularGridVMatrix(TVec<int> the_dimensions, TVec< pair<real,real> > the_range) 00056 :dimensions(the_dimensions.copy()), range(the_range.copy()) 00057 { 00058 build_(); 00059 } 00060 00061 00062 PLEARN_IMPLEMENT_OBJECT(RegularGridVMatrix, "ONE LINE DESCR", 00063 "RegularGridVMatrix represents the list of coordinates along a regularly spaced grid."); 00064 00065 void RegularGridVMatrix::getNewRow(int i, const Vec& v) const 00066 { 00067 int d = width(); 00068 if(v.length()!=d) 00069 PLERROR("In RegularGridVMatrix::getNewRow, size of v (%d) differs from vmat width (%d)",v.length(), d); 00070 if(i<0 || i>=length()) 00071 PLERROR("In RegularGridVMatrix::getNewRow, row %d out of range [0,%d]",i, length()-1); 00072 int idx = i; 00073 for(int k=d-1; k>=0; k--) 00074 { 00075 int idx_k = idx%dimensions[k]; 00076 idx = idx/dimensions[k]; 00077 v[k] = range[k].first + (range[k].second-range[k].first)/(dimensions[k]-1)*idx_k; 00078 } 00079 } 00080 00081 void RegularGridVMatrix::declareOptions(OptionList& ol) 00082 { 00083 // ### Declare all of this object's options here 00084 // ### For the "flags" of each option, you should typically specify 00085 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00086 // ### OptionBase::tuningoption. Another possible flag to be combined with 00087 // ### is OptionBase::nosave 00088 00089 // ### ex: 00090 // declareOption(ol, "myoption", &RegularGridVMatrix::myoption, OptionBase::buildoption, 00091 // "Help text describing this option"); 00092 // ... 00093 declareOption(ol, "dimensions", &RegularGridVMatrix::dimensions, OptionBase::buildoption, 00094 "A vector of integers giving the number of sample coordinates\n" 00095 "for each dimension of the grid. Ex for a 100x100 2D grid: [ 100 100 ]\n"); 00096 declareOption(ol, "range", &RegularGridVMatrix::range, OptionBase::buildoption, 00097 "A vector of low:high pairs with as many dimensions as the grid\n" 00098 "ex for 2D: [ -10:10 -3:4 ] \n"); 00099 00100 // Now call the parent class' declareOptions 00101 inherited::declareOptions(ol); 00102 } 00103 00104 void RegularGridVMatrix::build_() 00105 { 00106 width_ = dimensions.length(); 00107 length_ = (width_ ? product(dimensions) : 0); 00108 if(inputsize_<0) 00109 { 00110 inputsize_ = width_; 00111 targetsize_ = 0; 00112 weightsize_ = 0; 00113 } 00114 } 00115 00116 // ### Nothing to add here, simply calls build_ 00117 void RegularGridVMatrix::build() 00118 { 00119 inherited::build(); 00120 build_(); 00121 } 00122 00123 void RegularGridVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00124 { 00125 inherited::makeDeepCopyFromShallowCopy(copies); 00126 deepCopyField(dimensions, copies); 00127 deepCopyField(range, copies); 00128 } 00129 00130 } // end of namespace PLearn 00131

Generated on Tue Aug 17 16:03:50 2004 for PLearn by doxygen 1.3.7