/*
 * Implementation of class ImageVector
 *
 * $Date$
 * $Revision$
 *
 */

#include "WImage/debug.h"
#include "WImage/miscdefs.h"
#include "WImage/ImageVector.hh"
#ifndef _WIN32_WCE
#include <iostream>
#endif
#include <stdexcept>
#include <cmath>

#if !(defined __WATCOMC__ && __WATCOMC__ < 1230)
using namespace std;
#endif

ImageVector::ImageVector (ImageArray<coeff> *ar) : ReferenceVector ()
{
  this->m_array = ar;
  this->update ();
  this->go (0);
}

void
ImageVector::go (int root)
{
  if (root < 0)
    {
      throw invalid_argument ("go: root cannot have negative value.");
    }
  this->m_vroot = root;
}

bool
ImageVector::sanity (void)
{
  return (m_array->cols () == this->m_xsize 
          && m_array->rows () == this->m_ysize);
}

void
ImageVector::update (void)
{
  this->m_xsize = m_array->cols ();
  this->m_ysize = m_array->rows ();
}

coeff
ImageVector::weight(void)
 {
   coeff rc = 0;
   for (int i = 0; i < size(); i++) {
     rc += fabs (this->at(i));
   }
   return rc;
 }

