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 void 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 }
00053 
00054 osl_edgel_chain::~osl_edgel_chain()
00055 {
00056   n = 0;
00057   fsm_delete_array x; x = 0;
00058   fsm_delete_array y; y = 0;
00059   fsm_delete_array grad; grad = 0;
00060   fsm_delete_array theta; theta = 0;
00061 }
00062 
00063 float  osl_edgel_chain::GetGrad(unsigned int i) const { return grad[i]; }
00064 float *osl_edgel_chain::GetGrad() const { return grad; }
00065 float  osl_edgel_chain::GetTheta(unsigned int i) const { return theta[i]; }
00066 float *osl_edgel_chain::GetTheta() const { return theta; }
00067 float  osl_edgel_chain::GetX(unsigned int i) const { return x[i]; }
00068 float *osl_edgel_chain::GetX() const { return x; }
00069 float  osl_edgel_chain::GetY(unsigned int i) const { return y[i]; }
00070 float *osl_edgel_chain::GetY() const { return y; }
00071 void osl_edgel_chain::SetGrad(float v, unsigned int i) { grad[i] = v; }
00072 void osl_edgel_chain::SetTheta(float v, unsigned int i) { theta[i] = v; }
00073 void osl_edgel_chain::SetX(float v, unsigned int i) { x[i] = v; }
00074 void osl_edgel_chain::SetY(float v, unsigned int i) { y[i] = v; }
00075 unsigned int osl_edgel_chain::size() const { return n; }
00076 
00077 void osl_edgel_chain::SetLength(unsigned int nn)
00078 {
00079   if (nn <= n)
00080     n = nn;
00081   else
00082     vcl_abort();
00083 }
00084 
00085 void osl_edgel_chain::write_ascii(vcl_ostream &os) const
00086 {
00087   os << n << vcl_endl; // length
00088   for (unsigned int i=0; i<n; ++i)
00089     os << x[i] << ' ' << y[i] << ' ' << grad[i] << ' ' << theta[i] << vcl_endl;
00090 }
00091 
00092 void osl_edgel_chain::read_ascii(vcl_istream &is)
00093 {
00094   int n_ = -1;
00095   is >> vcl_ws >> n_;
00096   if (n_<0 || is.bad()) {
00097     vcl_cerr << __FILE__ ": failed to read length of osl_edgel_chain\n";
00098     return;
00099   }
00100   //SetLength(n_);
00101   this->~osl_edgel_chain();       // destruct
00102   new (this) osl_edgel_chain((unsigned int)n_); // construct
00103 
00104   for (unsigned int i=0; i<n; ++i)
00105     is >> vcl_ws >> x[i] >> y[i] >> grad[i] >> theta[i];
00106   if (is.bad()) {
00107     vcl_cerr << __FILE__ ": stream bad before end of osl_edgel_chain\n";
00108     return;
00109   }
00110 
00111   // if we get here, it's probably OK.
00112 }