cvgenericplane.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003 downloading, copying, installing or using the software you agree to this
00004 license. If you do not agree to this license, do not download, install, copy or
00005 use the software.
00006 
00007 Contributors License Agreement
00008 
00009 Copyright© 2007, Akhmed Umyarov. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification,
00012 are permitted provided that the following conditions are met:
00013 - Redistributions of source code must retain the above copyright notice, this
00014 list of conditions and the following disclaimer.
00015 - Redistributions in binary form must reproduce the above copyright notice, this
00016 list of conditions and the following disclaimer in the documentation and/or
00017 other materials provided with the distribution.
00018 - The name of Contributor may not be used to endorse or promote products derived
00019 from this software without specific prior written permission.
00020 
00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00029 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00030 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 All information provided related to future Intel products and plans is
00032 preliminary and subject to change at any time, without notice.
00033 *****************************************************************************/
00034 
00041 #include "cvgenericplane.h"
00042 #include <cassert>
00043 
00044 using namespace std;
00045 
00046 // Constructors/Destructors
00047 //  
00057 CvGenericPlane::CvGenericPlane ( std::string id, CvSize fmapsz, CvSize neurosz )
00058 {
00059         assert( fmapsz.width>0 && fmapsz.height>0 );
00060         assert( neurosz.width>=0 && neurosz.width>=0 );
00061 
00062         // Initialize parameters
00063         m_id = id;
00064 
00065         // Originally the plane is not connected to any other planes
00066         m_connected = 0;
00067 
00068         // Save plane topology 
00069         m_fmapsz = fmapsz;
00070         m_neurosz = neurosz;
00071         
00072         // Create null feature map
00073         m_fmap = cvCreateMat(fmapsz.height,fmapsz.width,CV_64FC1);
00074         assert( m_fmap != NULL );
00075 
00076         cvSetZero(m_fmap);
00077         
00078         m_weight = vector<double> ();
00079         m_pplane = vector<CvGenericPlane *> ();
00080 }
00081 
00082 CvGenericPlane::~CvGenericPlane ( ) 
00083 { 
00084         assert( m_fmap != NULL );
00085         cvReleaseMat( &m_fmap );
00086 }
00087 
00088 //  
00089 // Methods
00090 //  
00098 int CvGenericPlane::connto(vector<CvGenericPlane *> &pplane)
00099 {
00100         m_pplane = pplane;
00101         m_connected = 1;
00102 
00103         m_pfmap.resize(m_pplane.size());
00104         for (int i=0; i<m_pplane.size(); i++)
00105         {
00106                 // Cache pointer to parents' fmaps
00107                 m_pfmap[i] = m_pplane[i]->getfmap();
00108 
00109                 // Connect as a child to a parent
00110                 m_pplane[i]->connchild(this);                           
00111         }
00112 
00113         return 1;
00114 }
00115 
00123 int CvGenericPlane::connchild(CvGenericPlane *cplane)
00124 {
00125         m_cplane.push_back( cplane );
00126 
00127         return 1;
00128 }
00129 
00134 int CvGenericPlane::disconn()
00135 {
00136         m_connected = 0;
00137         m_pplane.clear();
00138         m_cplane.clear();
00139         m_pfmap.clear();
00140         return 1;
00141 }
00142 
00150 int CvGenericPlane::setfmap ( CvArr * source ) 
00151 {
00152         int width = cvGetSize(m_fmap).width;
00153         int height = cvGetSize(m_fmap).height;
00154 
00155         if ( (source == NULL) || !(cvGetSize(source).width == width 
00156                 && cvGetSize(source).height == height) )
00157                 return 0;
00158         
00159         // Copy the image into matrix (and convert from bytes to doubles).
00160         cvConvertScale(source,m_fmap);
00161                 
00162         return 1;
00163 }
00164 
00168 CvMat * CvGenericPlane::getfmap ( ) 
00169 {
00170         return m_fmap;
00171 }
00172 
00175 int CvGenericPlane::setweight(std::vector<double> &weights)
00176 {
00177         // Setting weights is only allowed when we are connected
00178         if (!m_connected) return 0;
00179 
00180         m_weight = weights;
00181         return 1;
00182 }
00183 
00187 string CvGenericPlane::getid()
00188 {
00189         return m_id;
00190 }

Generated on Fri Aug 3 16:17:27 2007 for ConvNet by  doxygen 1.5.0