Go to the documentation of this file.00001
00002 #include "vsol_spatial_object_2d.h"
00003
00004
00005
00006 #include <vcl_iostream.h>
00007 #include <vsol/vsol_box_2d.h>
00008 #include <vsl/vsl_binary_loader.h>
00009
00010 const float vsol_spatial_object_2d::eps=1.0e-3f;
00011
00012
00013 const char * vsol_spatial_object_2d::SpatialTypes[] =
00014 {
00015 "NO_TYPE ",
00016 "TOPOLOGYOBJECT ",
00017 "POINT ",
00018 "CURVE ",
00019 "REGION ",
00020 "SPATIALGROUP ",
00021 "NUM_SPATIALOBJECT_TYPES"
00022 };
00023
00024 vsol_spatial_object_2d::vsol_spatial_object_2d()
00025 : bounding_box_(0)
00026 {
00027 this->tag_ = 0;
00028 this->id_ = 0;
00029 set_tag_id(++tagcount_);
00030 }
00031
00032 vsol_spatial_object_2d::vsol_spatial_object_2d(vsol_spatial_object_2d const& s)
00033 : bounding_box_(0)
00034 {
00035 this->tag_ = 0;
00036 this->id_ = s.get_id();
00037 set_tag_id(++tagcount_);
00038 }
00039
00040 const char * vsol_spatial_object_2d::get_name() const
00041 {
00042 vsol_spatial_object_2d_type type =spatial_type();
00043 if (type > 0 && type < vsol_spatial_object_2d::NUM_SPATIALOBJECT_TYPES)
00044 return SpatialTypes[type];
00045 else
00046 return SpatialTypes[0];
00047 }
00048
00049 vsol_spatial_object_2d::~vsol_spatial_object_2d()
00050 {
00051 }
00052
00053
00054 short vsol_spatial_object_2d::version() const
00055 {
00056 return 1;
00057 }
00058
00059 void vsol_spatial_object_2d::compute_bounding_box() const
00060 {
00061 if (!bounding_box_) bounding_box_=new vsol_box_2d; bounding_box_->touch();
00062 }
00063
00064 void vsol_spatial_object_2d::empty_bounding_box() const
00065 {
00066 bounding_box_=new vsol_box_2d;
00067 }
00068
00069 void vsol_spatial_object_2d::set_bounding_box(double x, double y) const
00070 {
00071 bounding_box_=new vsol_box_2d; bounding_box_->add_point(x,y);
00072 }
00073
00074 void vsol_spatial_object_2d::set_bounding_box(vsol_box_2d_sptr const& box) const
00075 {
00076 bounding_box_=new vsol_box_2d(*box);
00077 }
00078
00079 void vsol_spatial_object_2d::add_to_bounding_box(double x, double y) const
00080 {
00081 if (!bounding_box_) bounding_box_=new vsol_box_2d; bounding_box_->add_point(x,y);
00082 }
00083
00084 void vsol_spatial_object_2d::add_to_bounding_box(vsol_box_2d_sptr const& comp_box) const
00085 {
00086 if (!bounding_box_)
00087 bounding_box_=new vsol_box_2d;
00088 bounding_box_->grow_minmax_bounds(comp_box);
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 void vsol_spatial_object_2d::check_update_bounding_box() const
00098 {
00099 if (!bounding_box_)
00100 {
00101 bounding_box_ = new vsol_box_2d;
00102 this->compute_bounding_box();
00103 bounding_box_->touch();
00104 return;
00105 }
00106 if (bounding_box_->older(this))
00107 {
00108 bounding_box_->touch();
00109 this->compute_bounding_box();
00110 }
00111 }
00112
00113 double vsol_spatial_object_2d::get_min_x() const
00114 {
00115 check_update_bounding_box(); return bounding_box_->get_min_x();
00116 }
00117
00118 double vsol_spatial_object_2d::get_max_x() const
00119 {
00120 check_update_bounding_box(); return bounding_box_->get_max_x();
00121 }
00122
00123 double vsol_spatial_object_2d::get_min_y() const
00124 {
00125 check_update_bounding_box(); return bounding_box_->get_min_y();
00126 }
00127
00128 double vsol_spatial_object_2d::get_max_y() const
00129 {
00130 check_update_bounding_box(); return bounding_box_->get_max_y();
00131 }
00132
00133
00134 void
00135 vsol_spatial_object_2d::b_write(vsl_b_ostream &os) const
00136 {
00137 vsl_b_write(os, this->version());
00138 vsl_b_write(os, this->tag_);
00139 vsl_b_write(os, this->id_);
00140 }
00141
00142
00143 void
00144 vsol_spatial_object_2d::b_read(vsl_b_istream &is)
00145 {
00146 if (!is) return;
00147
00148 short ver;
00149 vsl_b_read(is, ver);
00150 switch (ver)
00151 {
00152 case 1:
00153 vsl_b_read(is, this->tag_);
00154 vsl_b_read(is, this->id_);
00155 break;
00156
00157 default:
00158 vcl_cerr << "I/O ERROR: vsol_spatial_object_2d::b_read(vsl_b_istream&)\n"
00159 << " Unknown version number "<< ver << '\n';
00160 is.is().clear(vcl_ios::badbit);
00161 return;
00162 }
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 void vsl_add_to_binary_loader(vsol_spatial_object_2d const& b)
00176 {
00177 vsl_binary_loader<vsol_spatial_object_2d>::instance().add(b);
00178 }