contrib/brl/bbas/bsta/io/bsta_io_histogram.cxx
Go to the documentation of this file.
00001 #include "bsta_io_histogram.h"
00002 //
00003 //==============  histogram ==========================
00004 //
00005 void vsl_b_write(vsl_b_ostream& os, const bsta_histogram_base* hptr)
00006 {
00007   if (hptr ==0)
00008     vsl_b_write(os, false);
00009   else
00010     vsl_b_write(os, true);
00011   if (hptr->type_ == bsta_histogram_base::HIST_TYPE_FLOAT) {
00012    const bsta_histogram<float>* hf =
00013      static_cast<const bsta_histogram<float>*>(hptr);
00014     vsl_b_write(os, *hf);
00015   }
00016   else if (hptr->type_ == bsta_histogram_base::HIST_TYPE_DOUBLE) {
00017     const bsta_histogram<double>* hf =
00018       static_cast<const bsta_histogram<double>*>(hptr);
00019     vsl_b_write(os, *hf);
00020   }
00021 }
00022 
00023 void vsl_b_read(vsl_b_istream &is, bsta_histogram_base*& hptr)
00024 {
00025   delete hptr; hptr = 0;
00026   bool not_null_ptr;
00027   vsl_b_read(is, not_null_ptr);
00028   if (not_null_ptr)
00029   {
00030     short ver;
00031     vsl_b_read(is, ver);
00032     if (ver != 1)
00033       return;
00034     int itype = 0;
00035     vsl_b_read(is, itype);
00036     bsta_histogram_base::bsta_hist_type type =
00037       static_cast<bsta_histogram_base::bsta_hist_type>(itype);
00038     if (type == bsta_histogram_base::HIST_TYPE_FLOAT)
00039     {
00040       bsta_histogram<float> h;
00041       vsl_b_read(is, h, true);
00042       hptr = new bsta_histogram<float>(h);
00043     }
00044     else if (type == bsta_histogram_base::HIST_TYPE_DOUBLE)
00045     {
00046       bsta_histogram<double> h;
00047       vsl_b_read(is, h, true);
00048       hptr = new bsta_histogram<double>(h);
00049     }
00050 //  else if (type == bsta_histogram_base::HIST_TYPE_UNKNOWN) ; // do nothing
00051   }
00052 }
00053 
00054 void vsl_b_write(vsl_b_ostream& os, const bsta_histogram_base_sptr& hptr)
00055 {
00056   vsl_b_write(os, hptr.ptr());
00057 }
00058 
00059 void vsl_b_read(vsl_b_istream &is, bsta_histogram_base_sptr& hptr)
00060 {
00061   bsta_histogram_base* ptr = 0;
00062   vsl_b_read(is, ptr);
00063   hptr = ptr;
00064 }
00065 
00066 //
00067 //============== joint_histogram ==========================
00068 //
00069 
00070 void vsl_b_write(vsl_b_ostream &os, const bsta_joint_histogram_base* hptr)
00071 {
00072   if (hptr==0)
00073     vsl_b_write(os, false);
00074   else
00075     vsl_b_write(os, true);
00076   if (hptr->type_ == bsta_joint_histogram_base::HIST_TYPE_FLOAT) {
00077    const bsta_joint_histogram<float>* hf =
00078      static_cast<const bsta_joint_histogram<float>*>(hptr);
00079     vsl_b_write(os, *hf);
00080   }
00081   else if (hptr->type_ == bsta_joint_histogram_base::HIST_TYPE_DOUBLE) {
00082     const bsta_joint_histogram<double>* hf =
00083       static_cast<const bsta_joint_histogram<double>*>(hptr);
00084     vsl_b_write(os, *hf);
00085   }
00086 }
00087 
00088 void vsl_b_read(vsl_b_istream &is, bsta_joint_histogram_base*& hptr)
00089 {
00090   delete hptr; hptr = 0;
00091   bool not_null_ptr;
00092   vsl_b_read(is, not_null_ptr);
00093   if (not_null_ptr)
00094   {
00095     short ver;
00096     vsl_b_read(is, ver);
00097     if (ver != 1)
00098       return;
00099     int itype = 0;
00100     vsl_b_read(is, itype);
00101     bsta_joint_histogram_base::bsta_joint_hist_type type =
00102       static_cast<bsta_joint_histogram_base::bsta_joint_hist_type>(itype);
00103     if (type == bsta_joint_histogram_base::HIST_TYPE_FLOAT)
00104     {
00105       bsta_joint_histogram<float> h;
00106       vsl_b_read(is, h, true);
00107       hptr = new bsta_joint_histogram<float>(h);
00108     }
00109     else if (type == bsta_joint_histogram_base::HIST_TYPE_DOUBLE)
00110     {
00111       bsta_joint_histogram<double> h;
00112       vsl_b_read(is, h, true);
00113       hptr = new bsta_joint_histogram<double>(h);
00114     }
00115 //  else if (type == bsta_joint_histogram_base::HIST_TYPE_UNKNOWN) ;// do nothing
00116   }
00117 }
00118 void vsl_b_write(vsl_b_ostream& os, const bsta_joint_histogram_base_sptr& hptr)
00119 {
00120   vsl_b_write(os, hptr.ptr());
00121 }
00122 
00123 void vsl_b_read(vsl_b_istream &is, bsta_joint_histogram_base_sptr& hptr)
00124 {
00125   bsta_joint_histogram_base* ptr = 0;
00126   vsl_b_read(is, ptr);
00127   hptr = ptr;
00128 }
00129 //
00130 //============== joint_histogram_3d ==========================
00131 //
00132 
00133 void vsl_b_write(vsl_b_ostream &os, const bsta_joint_histogram_3d_base* hptr)
00134 {
00135   if (hptr==0)
00136     vsl_b_write(os, false);
00137   else
00138     vsl_b_write(os, true);
00139   if (hptr->type_ == bsta_joint_histogram_3d_base::HIST_TYPE_FLOAT) {
00140    const bsta_joint_histogram_3d<float>* hf =
00141      static_cast<const bsta_joint_histogram_3d<float>*>(hptr);
00142     vsl_b_write(os, *hf);
00143   }
00144   else if (hptr->type_ == bsta_joint_histogram_3d_base::HIST_TYPE_DOUBLE) {
00145     const bsta_joint_histogram_3d<double>* hf =
00146       static_cast<const bsta_joint_histogram_3d<double>*>(hptr);
00147     vsl_b_write(os, *hf);
00148   }
00149 }
00150 
00151 void vsl_b_read(vsl_b_istream &is, bsta_joint_histogram_3d_base*& hptr)
00152 {
00153   delete hptr; hptr = 0;
00154   bool not_null_ptr;
00155   vsl_b_read(is, not_null_ptr);
00156   if (not_null_ptr)
00157   {
00158     short ver = 0;
00159     int itype = 0;
00160     vsl_b_read(is, ver);
00161     if (ver != 1)
00162       return;
00163     vsl_b_read(is, itype);
00164     bsta_joint_histogram_3d_base::bsta_joint_hist_3d_type type =
00165       static_cast<bsta_joint_histogram_3d_base::bsta_joint_hist_3d_type>(itype);
00166     if (type == bsta_joint_histogram_3d_base::HIST_TYPE_FLOAT)
00167     {
00168       bsta_joint_histogram_3d<float> h;
00169       vsl_b_read(is, h, true);
00170       hptr = new bsta_joint_histogram_3d<float>(h);
00171     }
00172     if (type == bsta_joint_histogram_3d_base::HIST_TYPE_DOUBLE)
00173     {
00174       bsta_joint_histogram_3d<double> h;
00175       vsl_b_read(is, h, true);
00176       hptr = new bsta_joint_histogram_3d<double>(h);
00177     }
00178 //  else if (type == bsta_joint_histogram_3d_base::HIST_TYPE_UNKNOWN) ; // do nothing
00179   }
00180 }
00181 
00182 void vsl_b_write(vsl_b_ostream& os, const bsta_joint_histogram_3d_base_sptr& hptr)
00183 {
00184   vsl_b_write(os, hptr.ptr());
00185 }
00186 
00187 void vsl_b_read(vsl_b_istream &is, bsta_joint_histogram_3d_base_sptr& hptr)
00188 {
00189   bsta_joint_histogram_3d_base* ptr=0;
00190   vsl_b_read(is, ptr);
00191   hptr = ptr;
00192 }