Go to the documentation of this file.00001
00002 #ifndef vsol_spatial_object_2d_h_
00003 #define vsol_spatial_object_2d_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <vcl_string.h>
00046 #include <vcl_iostream.h>
00047 #include <vsol/vsol_spatial_object.h>
00048 #include <vsl/vsl_fwd.h>
00049 #include <vsol/vsol_spatial_object_2d_sptr.h>
00050 #include <vsol/vsol_box_2d_sptr.h>
00051 class vtol_topology_object;
00052 class vsol_spatial_object_2d;
00053 class vsol_point_2d;
00054 class vsol_curve_2d;
00055 class vsol_region_2d;
00056 class vsol_group_2d;
00057
00058 class vsol_spatial_object_2d : public vsol_spatial_object
00059 {
00060 protected:
00061
00062
00063 private:
00064 mutable vsol_box_2d_sptr bounding_box_;
00065
00066 public:
00067 enum vsol_spatial_object_2d_type
00068 {
00069 SPATIAL_NO_TYPE=0,
00070 TOPOLOGYOBJECT,
00071 POINT,
00072 CURVE,
00073 REGION,
00074 SPATIALGROUP,
00075 VOLUME,
00076 NUM_SPATIALOBJECT_TYPES
00077 };
00078
00079 static const char *SpatialTypes[];
00080 static const float eps;
00081
00082
00083 virtual ~vsol_spatial_object_2d();
00084
00085 protected:
00086
00087
00088 vsol_spatial_object_2d();
00089 vsol_spatial_object_2d(vsol_spatial_object_2d const& other);
00090 void not_applicable(vcl_string const& message) const
00091 {
00092 vcl_cerr <<message<<"() function call not applicable\tfor 2d spatial object "
00093 <<get_name()<<" !\n";
00094 }
00095
00096 public:
00097
00098
00099
00100 virtual vsol_spatial_object_2d_type spatial_type() const=0;
00101
00102 const char *get_name() const;
00103
00104
00105 void un_protect() { this->unref(); }
00106
00107
00108
00109
00110
00111 virtual vsol_spatial_object_2d* clone() const=0;
00112
00113
00114
00115
00116 virtual vcl_string is_a() const=0;
00117
00118
00119 short version() const;
00120
00121
00122 virtual void b_write(vsl_b_ostream &os) const;
00123
00124
00125 virtual void b_read(vsl_b_istream &is);
00126
00127 virtual void print(vcl_ostream &strm=vcl_cout) const { describe(strm); }
00128 virtual void describe(vcl_ostream& =vcl_cout, int =0) const { not_applicable("describe"); }
00129
00130 friend inline vcl_ostream &operator<<(vcl_ostream &, vsol_spatial_object_2d const&);
00131 friend inline vcl_ostream &operator<<(vcl_ostream &, vsol_spatial_object_2d const*);
00132
00133
00134 virtual bool operator==(vsol_spatial_object_2d const& obj) const { return this==&obj; }
00135 bool operator!=(vsol_spatial_object_2d const& obj) { return !(*this==obj); }
00136
00137
00138
00139 vsol_box_2d_sptr get_bounding_box() const { check_update_bounding_box(); return bounding_box_; }
00140
00141 double get_min_x() const;
00142 double get_max_x() const;
00143 double get_min_y() const;
00144 double get_max_y() const;
00145
00146 protected:
00147
00148 void empty_bounding_box() const;
00149
00150 void set_bounding_box(vsol_box_2d_sptr const& box) const;
00151
00152
00153
00154 void set_bounding_box(double x, double y) const;
00155
00156
00157
00158 void add_to_bounding_box(double x, double y) const;
00159
00160 void add_to_bounding_box(vsol_box_2d_sptr const& box) const;
00161
00162 void grow_minmax_bounds(vsol_box_2d_sptr const& b) const{ add_to_bounding_box(b); }
00163
00164 virtual void compute_bounding_box() const;
00165
00166 void check_update_bounding_box() const;
00167
00168 public:
00169
00170
00171
00172
00173 virtual vsol_spatial_object_2d* cast_to_spatial_object() { return this; }
00174 virtual vsol_spatial_object_2d const* cast_to_spatial_object() const{return this;}
00175
00176 virtual vtol_topology_object* cast_to_topology_object() {return 0;}
00177 virtual vtol_topology_object const* cast_to_topology_object()const{return 0;}
00178
00179 virtual vsol_spatial_object_2d* cast_to_vsol_spatial_object() { return 0; }
00180 virtual vsol_spatial_object_2d const* cast_to_vsol_spatial_object() const { return 0; }
00181 virtual vsol_point_2d* cast_to_point() { return 0; }
00182 virtual vsol_point_2d const* cast_to_point() const { return 0; }
00183 virtual vsol_curve_2d *cast_to_curve() { return 0; }
00184 virtual vsol_curve_2d const* cast_to_curve() const { return 0; }
00185 virtual vsol_region_2d* cast_to_region() { return 0; }
00186 virtual vsol_region_2d const* cast_to_region() const { return 0; }
00187 virtual vsol_group_2d *cast_to_group() { return 0; }
00188 virtual vsol_group_2d const* cast_to_group() const { return 0; }
00189 };
00190
00191
00192
00193 inline vcl_ostream &operator<<(vcl_ostream &strm, vsol_spatial_object_2d const& so)
00194 {
00195 so.print(strm);
00196 return strm;
00197 }
00198
00199 inline vcl_ostream &operator<<(vcl_ostream &strm, vsol_spatial_object_2d const* so)
00200 {
00201 if (so)
00202 so->print(strm);
00203 else
00204 strm << "NULL Spatial Object.\n";
00205 return strm;
00206 }
00207
00208
00209 inline void vsl_print_summary(vcl_ostream& os, vsol_spatial_object_2d const* so)
00210 {
00211 os << so;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 void vsl_add_to_binary_loader(vsol_spatial_object_2d const& b);
00224
00225 #endif // vsol_spatial_object_2d_h_