Follow this link to skip to the main content

3d_object.cc

Go to the documentation of this file.
00001 // -*-c++-*-
00002 //---------------------------< /-/ CLARAty /-/ >------------------------------
00003 /**
00004  * @file  3d_object.cc
00005  *
00006  * The N_3D_object class is a base class for modeling 3D objects. These
00007  * objects may be used in 3D graphical or collision applications.
00008  *
00009  * <br>@b Designer(s):  Hari Das Nayar, Issa Nesnas
00010  * <br>@b Author(s):    Hari Das Nayar
00011  * <br>@b Date:         August 4, 2005
00012  *
00013  * <b>Software License:</b><br>
00014  * <code> http://claraty.jpl.nasa.gov/license/open_src/  or 
00015  *        file: license/open_src.txt </code> 
00016  *
00017  * &copy; 2006, Jet Propulsion Laboratory, California Institute of Technology<br>
00018  *
00019  * $Revision: 1.6 $
00020  */
00021 //-----------------------------------------------------------------------------
00022 
00023 using namespace std;
00024 #include "claraty/3d_object.h"
00025 #include "claraty/xml_out.h"
00026 #include <iostream>
00027 #include <string>
00028 
00029 namespace claraty {
00030 
00031 //-------------------------------------------------------------------------
00032 //--------------------------<< N_3D_Object Class >>--------------------------
00033 //-------------------------------------------------------------------------
00034 /**
00035  * Default constructor
00036  *
00037  * @ingroup N_3D_object_pkg
00038  */
00039 N_3D_Object::N_3D_Object()
00040 {
00041   _shape_type = OTHER;
00042   _number_of_dimensions = 0;
00043   _dimensions[0] = 0.0;
00044   _dimensions[1] = 0.0;
00045   _dimensions[2] = 0.0;
00046 }
00047 
00048 //-------------------------------------------------------------------------
00049 /**
00050  * Copy constructor
00051  *
00052  * @param[in] shape_object Reference to N_3D_Object to be copied.
00053  *
00054  * @ingroup N_3D_object_pkg
00055  */
00056 N_3D_Object::N_3D_Object(const N_3D_Object & shape_object)
00057 {
00058   _shape_type = shape_object._shape_type;
00059   _number_of_dimensions = shape_object._number_of_dimensions;
00060   _dimensions[0] = shape_object._dimensions[0];
00061   _dimensions[1] = shape_object._dimensions[1];
00062   _dimensions[2] = shape_object._dimensions[2];
00063 }
00064 
00065 //----------------------------------------------------------------------------
00066 /**
00067  * Get shape type. 
00068  *
00069  * @return The shape type.
00070  *
00071  * @ingroup N_3D_object_pkg
00072  */
00073 N_3D_Object::SHAPE_TYPE 
00074 N_3D_Object::get_shape_type()
00075 {
00076 #ifdef DEBUG
00077   cout << "Shape type is ";
00078   switch(_shape_type)
00079     {
00080     case N_3D_Object::BOX:
00081       cout << "box";
00082       break;
00083     case N_3D_Object::CYLINDER:
00084       cout << "cylinder";
00085       break;
00086     case N_3D_Object::SPHERE:
00087       cout << "sphere";
00088       break;
00089     case N_3D_Object::OTHER:
00090       cout << "other";
00091       break;
00092     }
00093   cout << endl;
00094 #endif
00095   return _shape_type;
00096 }
00097 
00098 //----------------------------------------------------------------------------
00099 /**
00100  * Set shape type. 
00101  *
00102  * @param[in] shape_type The string child name.
00103  *
00104  * @ingroup N_3D_object_pkg
00105  */
00106 void 
00107 N_3D_Object::set_shape_type(SHAPE_TYPE shape_type)
00108 {
00109   _shape_type = shape_type;
00110 #ifdef DEBUG
00111   cout << "Setting shape type to ";
00112   switch(_shape_type)
00113     {
00114     case N_3D_Object::BOX:
00115       cout << "box";
00116       break;
00117     case N_3D_Object::CYLINDER:
00118       cout << "cylinder";
00119       break;
00120     case N_3D_Object::SPHERE:
00121       cout << "sphere";
00122       break;
00123     case N_3D_Object::OTHER:
00124       cout << "other";
00125       break;
00126     }
00127   cout << endl;
00128 #endif
00129 }
00130 
00131 //----------------------------------------------------------------------------
00132 /**
00133  * Set number of shape dimensions. 
00134  *
00135  * @param[in] n_dimensions  Number of dimensions.
00136  *
00137  * @ingroup N_3D_object_pkg
00138  */
00139 void 
00140 N_3D_Object::set_number_of_dimensions(int n_dimensions)
00141 {
00142   _number_of_dimensions = n_dimensions;
00143 }
00144 //----------------------------------------------------------------------------
00145 /**
00146  * Get shape dimensions. 
00147  *
00148  * @return The number of dimensions.
00149  *
00150  * @ingroup N_3D_object_pkg
00151  */
00152 void 
00153 N_3D_Object::get_dimensions(double * dimensions)
00154 {
00155   for (int i=0; i<_number_of_dimensions; ++i)
00156     {
00157       dimensions[i] = _dimensions[i];
00158     }
00159 }
00160 
00161 //----------------------------------------------------------------------------
00162 /**
00163  * Set shape dimensions. 
00164  *
00165  * @param[in] dimensions
00166  *
00167  * @ingroup N_3D_object_pkg
00168  */
00169 void 
00170 N_3D_Object::set_dimensions(double * dimensions)
00171 {
00172   for (int i=0; i<_number_of_dimensions; ++i)
00173     {
00174       _dimensions[i] = dimensions[i];
00175     }
00176 }
00177 //----------------------------------------------------------------------------
00178 /**
00179  * Output to ostream
00180  *
00181  * @param[out] os  ostream to put output on.
00182  * @param[in]  n_3D_object  object to be output
00183  * @return ostream with output on it.
00184  *
00185  * @ingroup mechanism_model_io_pkg
00186  */
00187 std::ostream & 
00188 operator<< (std::ostream& os, N_3D_Object & n_3D_object)
00189 {
00190   std::string spacing = "";
00191   spacing.append(XML_Out::get_indentation_space(), ' ');
00192 
00193 #ifdef DEBUG
00194   cout << "In N_3D_Object_IO, about to output shape object_io of type ";
00195 #endif
00196   double dimensions[NUMBER_OF_3D_OBJECT_DIMENSIONS];
00197   n_3D_object.get_dimensions(dimensions);
00198 #ifdef DEBUG
00199   cout << "WHAT SHAPE: " << n_3D_object.get_shape_type() << "\n";
00200 #endif
00201   switch (n_3D_object.get_shape_type())
00202     {
00203     case N_3D_Object::BOX:
00204 #ifdef DEBUG
00205   cout << "Box" << n_3D_object.get_shape_type() << endl;
00206 #endif
00207       os << spacing;
00208       os << "<Box ";
00209       os << "x = \"" << dimensions[0] << "\" ";
00210       os << "y = \"" << dimensions[1] << "\" ";
00211       os << "z = \"" << dimensions[2] << "\" ";
00212       os << "/>\n";
00213       break;
00214     case N_3D_Object::CYLINDER:
00215 #ifdef DEBUG
00216   cout << "Cylinder" << n_3D_object.get_shape_type() << endl;
00217 #endif
00218       os << spacing;
00219       os << "<Cylinder ";
00220       os << "radius = \"" << dimensions[0] << "\" ";
00221       os << "height = \"" << dimensions[1] << "\" ";
00222       os << "/>\n";
00223       break;
00224     case N_3D_Object::SPHERE:
00225 #ifdef DEBUG
00226   cout << "Sphere" << n_3D_object.get_shape_type() << endl;
00227 #endif
00228       os << spacing;
00229       os << "<Sphere ";
00230       os << "radius = \"" << dimensions[0] << "\" ";
00231       os << "/>\n";
00232       break;
00233     case N_3D_Object::OTHER:
00234       os << "other ";
00235       break;
00236     }
00237   
00238 
00239   return os;
00240 }
00241 //----------------------------------------------------------------------------
00242 
00243 } // namespace claraty