contrib/oxl/osl/osl_edgel_chain.cxx
Go to the documentation of this file.
00001 // This is oxl/osl/osl_edgel_chain.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author fsm
00008 
00009 #include "osl_edgel_chain.h"
00010 
00011 #include <vcl_cstdlib.h>
00012 #include <vcl_iostream.h>
00013 #include <vcl_new.h>
00014 
00015 #include <osl/osl_hacks.h>
00016 
00017 //--------------------------------------------------------------------------------
00018 
00019 osl_edgel_chain::osl_edgel_chain() : n(0), x(0), y(0), grad(0), theta(0) { }
00020 
00021 osl_edgel_chain::osl_edgel_chain(unsigned int n_)
00022   : n(n_)
00023   , x(new float[n fsm_pad])
00024   , y(new float[n fsm_pad])
00025   , grad(new float[n fsm_pad])
00026   , theta(new float[n fsm_pad])
00027 {
00028 }
00029 
00030 osl_edgel_chain::osl_edgel_chain(osl_edgel_chain const &that)
00031   : n(that.n)
00032   , x(new float[n fsm_pad])
00033   , y(new float[n fsm_pad])
00034   , grad(new float[n fsm_pad])
00035   , theta(new float[n fsm_pad])
00036 {
00037   for (unsigned int i=0; i<n; ++i) {
00038     x[i] = that.x[i];
00039     y[i] = that.y[i];
00040     grad[i] = that.grad[i];
00041     theta[i] = that.theta[i];
00042   }
00043 }
00044 
00045 osl_edgel_chain& osl_edgel_chain::operator=(osl_edgel_chain const &that)
00046 {
00047   vcl_cerr << __FILE__ ": assignment to osl_edgel_chain\n";
00048   if (this != &that) {
00049     this->~osl_edgel_chain();
00050     new (this) osl_edgel_chain(that);
00051   }
00052   return *this;
00053 }
00054 
00055 osl_edgel_chain::~osl_edgel_chain()
00056 {
00057   n = 0;
00058   fsm_delete_array x; x = 0;
00059   fsm_delete_array y; y = 0;
00060   fsm_delete_array grad; grad = 0;
00061   fsm_delete_array theta; theta = 0;
00062 }
00063 
00064 float  osl_edgel_chain::GetGrad(unsigned int i) const { return grad[i]; }
00065 float *osl_edgel_chain::GetGrad() const { return grad; }
00066 float  osl_edgel_chain::GetTheta(unsigned int i) const { return theta[i]; }
00067 float *osl_edgel_chain::GetTheta() const { return theta; }
00068 float  osl_edgel_chain::GetX(unsigned int i) const { return x[i]; }
00069 float *osl_edgel_chain::GetX() const { return x; }
00070 float  osl_edgel_chain::GetY(unsigned int i) const { return y[i]; }
00071 float *osl_edgel_chain::GetY() const { return y; }
00072 void osl_edgel_chain::SetGrad(float v, unsigned int i) { grad[i] = v; }
00073 void osl_edgel_chain::SetTheta(float v, unsigned int i) { theta[i] = v; }
00074 void osl_edgel_chain::SetX(float v, unsigned int i) { x[i] = v; }
00075 void osl_edgel_chain::SetY(float v, unsigned int i) { y[i] = v; }
00076 unsigned int osl_edgel_chain::size() const { return n; }
00077 
00078 void osl_edgel_chain::SetLength(unsigned int nn)
00079 {
00080   if (nn <= n)
00081     n = nn;
00082   else
00083     vcl_abort();
00084 }
00085 
00086 void osl_edgel_chain::write_ascii(vcl_ostream &os) const
00087 {
00088   os << n << vcl_endl; // length
00089   for (unsigned int i=0; i<n; ++i)
00090     os << x[i] << ' ' << y[i] << ' ' << grad[i] << ' ' << theta[i] << vcl_endl;
00091 }
00092 
00093 void osl_edgel_chain::read_ascii(vcl_istream &is)
00094 {
00095   int n_ = -1;
00096   is >> vcl_ws >> n_;
00097   if (n_<0 || is.bad()) {
00098     vcl_cerr << __FILE__ ": failed to read length of osl_edgel_chain\n";
00099     return;
00100   }
00101   //SetLength(n_);
00102   this->~osl_edgel_chain();       // destruct
00103   new (this) osl_edgel_chain((unsigned int)n_); // construct
00104 
00105   for (unsigned int i=0; i<n; ++i)
00106     is >> vcl_ws >> x[i] >> y[i] >> grad[i] >> theta[i];
00107   if (is.bad()) {
00108     vcl_cerr << __FILE__ ": stream bad before end of osl_edgel_chain\n";
00109     return;
00110   }
00111 
00112   // if we get here, it's probably OK.
00113 }