bounding_shape.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "claraty/bounding_shape.h"
00025
00026 using namespace std;
00027
00028 namespace claraty {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 Bounding_Shape::Bounding_Shape()
00039 : _name("root"),
00040 _parent_name(""),
00041 _is_container(false),
00042 _is_aligned(false),
00043 _ignore_collisions(false),
00044 _tol(0.0)
00045 {
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 Bounding_Shape::Bounding_Shape(const Bounding_Shape & bounding_shape)
00058 {
00059 _name = bounding_shape._name;
00060 _parent_name = bounding_shape._parent_name;
00061 _is_container = bounding_shape._is_container;
00062 _is_aligned = bounding_shape._is_aligned;
00063 _ignore_collisions = bounding_shape._ignore_collisions;
00064 _tol = bounding_shape._tol;
00065
00066 _transform = bounding_shape._transform;
00067 _three_d_object = bounding_shape._three_d_object;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077 Bounding_Shape::~Bounding_Shape()
00078 {
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 void
00091 Bounding_Shape::set_name(std::string name)
00092 {
00093 _name = name;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 std::string
00106 Bounding_Shape::get_name()
00107 {
00108 return _name;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 void
00120 Bounding_Shape::set_parent_name(std::string parent_name)
00121 {
00122 _parent_name = parent_name;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 std::string
00134 Bounding_Shape::get_parent_name()
00135 {
00136 return _parent_name;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 void
00150 Bounding_Shape::set_containment(bool containment)
00151 {
00152 _is_container = containment;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool
00164 Bounding_Shape::get_containment()
00165 {
00166 return _is_container;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 void
00178 Bounding_Shape::set_alignment(bool alignment)
00179 {
00180 _is_aligned = alignment;
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 bool
00192 Bounding_Shape::get_alignment()
00193 {
00194 return _is_aligned;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 void
00206 Bounding_Shape::set_collision(bool collision)
00207 {
00208 _ignore_collisions = collision;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 bool
00220 Bounding_Shape::get_collision()
00221 {
00222 return _ignore_collisions;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 void
00234 Bounding_Shape::set_tolerance(double tolerance)
00235 {
00236 _tol = tolerance;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 double &
00248 Bounding_Shape::get_tolerance()
00249 {
00250 return _tol;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 void
00262 Bounding_Shape::set(Transform & transform)
00263 {
00264 _transform = transform;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 Transform &
00276 Bounding_Shape::get_transform()
00277 {
00278 return _transform;
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 void
00290 Bounding_Shape::set(N_3D_Object & three_d_object)
00291 {
00292 _three_d_object = three_d_object;
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302 N_3D_Object &
00303 Bounding_Shape::get_3d_object()
00304 {
00305 return _three_d_object;
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 std::ostream& operator<< (std::ostream& os, Bounding_Shape & bounding_shape)
00319 {
00320 std::string spacing = "";
00321 std::string child_spacing = "";
00322 spacing.append(XML_Out::get_indentation_space(), ' ');
00323 child_spacing.append(XML_Out::get_indentation_space()
00324 + XML_Out::get_tab_space(), ' ');
00325
00326 os << spacing;
00327 os << "<Bounding_Shape ";
00328 os << "name = \"" << bounding_shape.get_name() << "\" ";
00329 os << "parent = \"" << bounding_shape.get_parent_name() << "\" ";
00330 os << "is_container = \""
00331 << (bounding_shape.get_containment() ? "true" : "false") << "\" ";;
00332 os << "is_aligned = \""
00333 << (bounding_shape.get_alignment() ? "true" : "false") << "\" ";;
00334 os << "ignore_collisions = \""
00335 << (bounding_shape.get_collision() ? "true" : "false") << "\" ";;
00336 os << "tol = \"" << bounding_shape.get_tolerance() << "\" ";
00337 os << ">\n";
00338
00339 #ifdef DEBUG
00340 cout << "In Bounding_Shape, about to output transform_io" << endl;
00341 #endif
00342 os << child_spacing;
00343 os << "<Transform>\n";
00344 XML_Out::increment_indentation_level();
00345 XML_Out::increment_indentation_level();
00346 os << XML_Out::enable << bounding_shape.get_transform() << XML_Out::disable;
00347 XML_Out::decrement_indentation_level();
00348 XML_Out::decrement_indentation_level();
00349 os << child_spacing;
00350 os << "</Transform>\n";
00351
00352 #ifdef DEBUG
00353 cout << "In Bounding_Shape, about to output bounding_shape_io" << endl;
00354 #endif
00355 XML_Out::increment_indentation_level();
00356 os << bounding_shape.get_3d_object();
00357 XML_Out::decrement_indentation_level();
00358
00359 os << spacing;
00360 os << "</Bounding_Shape> \n";
00361
00362 return os;
00363
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 void
00378 Composite_Bounding_Shape::insert(Bounding_Shape * bounding_shape)
00379 {
00380 bool attached_new_node = false;
00381
00382 Tree<Bounding_Shape>::Pre_Order_Iterator p_shape_tree_itr
00383 = _bounding_shape_tree.begin_pre_order();
00384 Tree<Bounding_Shape>::Pre_Order_Iterator p_end_shape_tree_itr
00385 = _bounding_shape_tree.end_pre_order();
00386 for (; p_shape_tree_itr < p_end_shape_tree_itr; ++p_shape_tree_itr)
00387 {
00388 if (p_shape_tree_itr->get_name() == bounding_shape->get_parent_name())
00389 {
00390 _bounding_shape_tree.append_child(p_shape_tree_itr, bounding_shape);
00391 attached_new_node = true;
00392 break;
00393 }
00394 }
00395 if ((!attached_new_node)||
00396 (bounding_shape->get_parent_name().length() == 0))
00397
00398 {
00399 Tree<Bounding_Shape>::Pre_Order_Iterator p_shape_tree_itr
00400 = _bounding_shape_tree.begin_pre_order();
00401 _bounding_shape_tree.append_child(p_shape_tree_itr, bounding_shape);
00402 attached_new_node = true;
00403 }
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413 void
00414 Composite_Bounding_Shape::insert_at_root(Bounding_Shape * bounding_shape)
00415 {
00416 Tree<Bounding_Shape>::Pre_Order_Iterator p_shape_tree_itr
00417 = _bounding_shape_tree.begin_pre_order();
00418 _bounding_shape_tree.append_child(p_shape_tree_itr, bounding_shape);
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 void
00430 Composite_Bounding_Shape::copy(Composite_Bounding_Shape & composite_bounding_shape)
00431 {
00432 _bounding_shape_tree.copy(composite_bounding_shape._bounding_shape_tree);
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 bool
00444 Composite_Bounding_Shape::empty()
00445 {
00446 return _bounding_shape_tree.empty();
00447 }
00448
00449
00450
00451
00452
00453
00454 void
00455 Composite_Bounding_Shape::clear_tree()
00456 {
00457 return _bounding_shape_tree.clear_tree();
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467 Tree<Bounding_Shape> &
00468 Composite_Bounding_Shape::get_shape_tree()
00469 {
00470 return _bounding_shape_tree;
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 std::ostream& operator<< (std::ostream& os,
00483 Composite_Bounding_Shape & composite_bounding_shape)
00484 {
00485 Tree<Bounding_Shape>::Pre_Order_Iterator p_shape_tree_itr
00486 = composite_bounding_shape.get_shape_tree().begin_pre_order();
00487 Tree<Bounding_Shape>::Pre_Order_Iterator p_end_shape_tree_itr
00488 = composite_bounding_shape.get_shape_tree().end_pre_order();
00489
00490 ++p_shape_tree_itr;
00491
00492 for (; p_shape_tree_itr < p_end_shape_tree_itr; ++p_shape_tree_itr)
00493 {
00494 os << *p_shape_tree_itr;
00495 }
00496 return os;
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506 Bounding_Shape & Composite_Bounding_Shape::_get_top_level_bounding_shape()
00507 {
00508 Tree<Bounding_Shape>::Pre_Order_Iterator p_shape_tree_itr
00509 = get_shape_tree().begin_pre_order();
00510
00511 ++p_shape_tree_itr;
00512 return *p_shape_tree_itr;
00513
00514 }
00515
00516
00517 }