PSCalib/include/GeometryObject.h

Go to the documentation of this file.
00001 #ifndef PSCALIB_GEOMETRYOBJECT_H
00002 #define PSCALIB_GEOMETRYOBJECT_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: GeometryObject.h 10056 2015-05-12 00:21:09Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class GeometryObject.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 
00017 #include <string>
00018 #include <vector>
00019 #include <boost/shared_ptr.hpp>
00020 #include <math.h>      // sin, cos
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "PSCalib/SegGeometryStore.h"
00026 
00027 //------------------------------------
00028 // Collaborating Class Declarations --
00029 //------------------------------------
00030 
00031 //typedef PSCalib::PixCoords2x1V2 PC2X1;
00032 
00033 using namespace std;
00034 
00035 //              ---------------------
00036 //              -- Class Interface --
00037 //              ---------------------
00038 
00039 namespace PSCalib {
00040 
00041 /// @addtogroup PSCalib
00042 
00043 /**
00044  *  @ingroup PSCalib
00045  *
00046  *  @brief Class supports elementary building block for hierarchial geometry description
00047  *
00048  *  @note This software was developed for the LCLS project.  If you use all or 
00049  *  part of it, please give an appropriate acknowledgment.
00050  *
00051  *  @version $Id: GeometryObject.h 10056 2015-05-12 00:21:09Z dubrovin@SLAC.STANFORD.EDU $
00052  *
00053  *  @see GeometryObject, CalibFileFinder, PSCalib/test/ex_geometry_access.cpp
00054  *
00055  *  @author Mikhail S. Dubrovin
00056  *
00057  *  @anchor interface
00058  *  @par<interface> Interface Description
00059  * 
00060  *  @li  Include
00061  *  @code
00062  *  #include "PSCalib/GeometryObject.h"
00063  *  typedef boost::shared_ptr<GeometryObject> shpGO;
00064  *  @endcode
00065  *
00066  *  @li Instatiation
00067  *  \n
00068  *  @code
00069  *    PSCalib::GeometryObject* geo = new PSCalib::GeometryObject(pname, 
00070  *                                                               pindex,
00071  *                                                               oname, 
00072  *                                                               oindex,
00073  *                                                               x0,    
00074  *                                                               y0,    
00075  *                                                               z0,    
00076  *                                                               rot_z, 
00077  *                                                               rot_y, 
00078  *                                                               rot_x, 
00079  *                                                               tilt_z,
00080  *                                                               tilt_y,
00081  *                                                               tilt_x );
00082  *  @endcode
00083  *
00084  *  @li Access methods
00085  *  @code
00086  *    // get pixel coordinates
00087  *    const double* X;
00088  *    const double* Y;
00089  *    const double* Z;
00090  *    unsigned   size;
00091  *    bool       do_tilt=true;
00092  *    geo->get_pixel_coords(X, Y, Z, size, do_tilt);
00093  *
00094  *    // get pixel areas
00095  *    const double* A;
00096  *    unsigned   size;
00097  *    geo->get_pixel_areas(A, size);
00098  *
00099  *    // get pixel mask
00100  *    const int* mask;
00101  *    unsigned   size;
00102  *    unsigned   mbits = 377; // 1-edges; 2-wide central cols; 4-non-bound; 8-non-bound neighbours
00103  *    geo->get_pixel_mask(mask, size, mbits);
00104  *
00105  *    shpGO parobj = geo->get_parent();
00106  *    std::vector<shpGO> lst = geo->get_list_of_children();
00107  *
00108  *    std::string oname  = geo->get_geo_name();
00109  *    unsigned    oindex = geo->get_geo_index();
00110  *    std::string pname  = geo->get_parent_name();
00111  *    unsigned    pindex = geo->get_parent_index();
00112  *    double      pixsize= geo->get_pixel_scale_size();
00113  *
00114  *    double x, y, z, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x;     
00115  *    geo->get_geo_pars(x, y, z, rot_z, rot_y, rot_x, tilt_z, tilt_y, tilt_x);
00116  *  
00117  *    // Next methods are used in class GeometryAccess for building of hierarchial geometry structure.
00118  *    geo->set_parent(parent_geo);
00119  *    geo->add_child(child_geo);
00120  *  @endcode
00121  *
00122  *  @li Modification methods
00123  *  @code
00124  *    geo->set_geo_pars( 10, 11, 12, 90, 0, 0, 0, 0, 0)
00125  *    geo->move_geo(10, 11, 12);
00126  *    geo->tilt_geo(0, 0, 0.15);
00127  *  @endcode
00128  *  
00129  *  @li Print methods
00130  *  @code
00131  *    geo->print_geo();
00132  *    geo->print_geo_children();
00133  *    cout << "Size of geo: " << geo->get_size_geo_array(); 
00134  *  @endcode
00135  */
00136 
00137 //-------------------
00138 
00139 //typedef ndarray<double,1> NDA;
00140 //typedef ndarray<const double,1> CNDA;
00141 
00142 //-------------------
00143 
00144 class GeometryObject  {
00145 public:
00146 
00147   typedef PSCalib::SegGeometry SG;
00148 
00149   //typedef GeometryObject* shpGO;
00150   typedef boost::shared_ptr<GeometryObject> shpGO;
00151 
00152   /**
00153    *  @brief Class constructor accepts path to the calibration "geometry" file and verbosity control bit-word 
00154    *  
00155    *  @param[in] pname  - parent name
00156    *  @param[in] pindex - parent index
00157    *  @param[in] oname  - this object name
00158    *  @param[in] oindex - this object index
00159    *  @param[in] x0     - object origin coordinate x[um] in parent frame
00160    *  @param[in] y0     - object origin coordinate y[um] in parent frame
00161    *  @param[in] z0     - object origin coordinate z[um] in parent frame
00162    *  @param[in] rot_z  - object rotation/design angle [deg] around axis z of the parent frame
00163    *  @param[in] rot_y  - object rotation/design angle [deg] around axis y of the parent frame
00164    *  @param[in] rot_x  - object rotation/design angle [deg] around axis x of the parent frame
00165    *  @param[in] tilt_z - object tilt/deviation angle [deg] around axis z of the parent frame
00166    *  @param[in] tilt_y - object tilt/deviation angle [deg] around axis y of the parent frame
00167    *  @param[in] tilt_x - object tilt/deviation angle [deg] around axis x of the parent frame
00168    */
00169   GeometryObject (  std::string pname  = std::string(),
00170                     unsigned    pindex = 0,
00171                     std::string oname  = std::string(),
00172                     unsigned    oindex = 0,
00173                     double      x0     = 0,
00174                     double      y0     = 0,
00175                     double      z0     = 0,
00176                     double      rot_z  = 0,
00177                     double      rot_y  = 0,
00178                     double      rot_x  = 0,                  
00179                     double      tilt_z = 0,
00180                     double      tilt_y = 0,
00181                     double      tilt_x = 0
00182                   ) ;
00183 
00184   // Destructor
00185   virtual ~GeometryObject () ;
00186 
00187   std::string string_geo();
00188   std::string string_geo_children();
00189 
00190   /// Prints info about self object
00191   void print_geo();
00192 
00193   /// Prints info about children objects
00194   void print_geo_children();
00195 
00196   /// Sets shared pointer to the parent object
00197   void set_parent(shpGO parent) { m_parent = parent; }
00198 
00199   /// Adds shared pointer of the children geometry object to the vector
00200   void add_child (shpGO child) { v_list_of_children.push_back(child); }
00201 
00202   /// Returns shared pointer to the parent geometry object
00203   shpGO get_parent() { return m_parent; }
00204 
00205   /// Returns vector of shared pointers to children geometry objects
00206   std::vector<shpGO> get_list_of_children() { return v_list_of_children; }
00207 
00208   /// Returns self object name
00209   std::string get_geo_name()     { return m_oname; }
00210 
00211   /// Returns self object index
00212   unsigned    get_geo_index()    { return m_oindex; }
00213 
00214   /// Returns parent object name
00215   std::string get_parent_name()  { return m_pname; }
00216 
00217   /// Returns parent object index
00218   unsigned    get_parent_index() { return m_pindex; }
00219 
00220   /**
00221    *  @brief Re-evaluate pixel coordinates (useful if geo is changed)
00222    *  @param[in]  do_tilt - on/off tilt angle correction
00223    *  @param[in]  do_eval - enforce (re-)evaluation of pixel coordinates
00224    */
00225   void evaluate_pixel_coords(const bool do_tilt=true, const bool do_eval=false);
00226 
00227   /**
00228    *  @brief Returns pointers to pixel coordinate arrays
00229    *  @param[out] X - pointer to x pixel coordinate array
00230    *  @param[out] Y - pointer to y pixel coordinate array
00231    *  @param[out] Z - pointer to z pixel coordinate array
00232    *  @param[out] size - size of the pixel coordinate array (number of pixels)
00233    *  @param[in]  do_tilt - on/off tilt angle correction
00234    *  @param[in]  do_eval - enforce (re-)evaluation of pixel coordinates
00235    */
00236   void get_pixel_coords(const double*& X, const double*& Y, const double*& Z, unsigned& size, 
00237                         const bool do_tilt=true, const bool do_eval=false);
00238 
00239   /**
00240    *  @brief Returns pointers to pixel areas array
00241    *  @param[out] areas - pointer to pixel areas array
00242    *  @param[out] size - size of the pixel areas array (number of pixels)
00243    */
00244   void get_pixel_areas(const double*& areas, unsigned& size);
00245 
00246   /**
00247    *  @brief Returns pointers to pixel mask array
00248    *  @param[out] mask - pointer to pixel mask array
00249    *  @param[out] size - size of the pixel mask array (number of pixels)
00250    *  @param[in]  mbits - mask control bits; 
00251    *              + 1 - mask edges,
00252    *              + 2 - mask two central columns, 
00253    *              + 4 - mask non-bounded pixels,
00254    *              + 8 - mask nearest neighbours of nonbonded pixels.
00255    */
00256   void get_pixel_mask(const int*& mask, unsigned& size, const unsigned& mbits = 0377);
00257 
00258   /// Returns size of geometry object array - number of pixels
00259   unsigned get_size_geo_array();
00260 
00261   /// Returns pixel scale size of geometry object
00262   double get_pixel_scale_size();
00263 
00264   /// Returns string of data for output file
00265   std::string str_data();
00266 
00267   /// Gets self object geometry parameters
00268   void get_geo_pars( double& x0,
00269                      double& y0,
00270                      double& z0,
00271                      double& rot_z,
00272                      double& rot_y,
00273                      double& rot_x,                  
00274                      double& tilt_z,
00275                      double& tilt_y,
00276                      double& tilt_x 
00277                      );
00278 
00279   /// Sets self object geometry parameters
00280   void set_geo_pars( const double& x0 = 0,
00281                      const double& y0 = 0,
00282                      const double& z0 = 0,
00283                      const double& rot_z = 0,
00284                      const double& rot_y = 0,
00285                      const double& rot_x = 0,                  
00286                      const double& tilt_z = 0,
00287                      const double& tilt_y = 0,
00288                      const double& tilt_x = 0 
00289                      );
00290 
00291   /// Adds offset for origin of the self object w.r.t. current position
00292   void move_geo( const double& dx = 0,
00293                  const double& dy = 0,
00294                  const double& dz = 0
00295                  );
00296 
00297   /// Adds tilts to the self object w.r.t. current orientation
00298   void tilt_geo( const double& dt_x = 0,
00299                  const double& dt_y = 0,
00300                  const double& dt_z = 0 
00301                  );
00302 
00303   /// Delete arrays with allocated memory, reset pointers to 0
00304   void deallocate_memory();
00305 
00306 protected:
00307 
00308 private:
00309 
00310   // Data members
00311   std::string m_pname;
00312   unsigned    m_pindex;
00313 
00314   std::string m_oname;
00315   unsigned    m_oindex;
00316 
00317   double      m_x0;
00318   double      m_y0;
00319   double      m_z0;
00320 
00321   double      m_rot_z;
00322   double      m_rot_y;
00323   double      m_rot_x;
00324 
00325   double      m_tilt_z;
00326   double      m_tilt_y;
00327   double      m_tilt_x;
00328 
00329   bool        m_do_tilt;
00330   unsigned    m_mbits; // mask control bits
00331 
00332   SG* m_seggeom;
00333 
00334   shpGO m_parent;
00335   std::vector<shpGO> v_list_of_children;
00336 
00337   //ALGO_TYPE m_algo;
00338   //PC2X1* m_pix_coords_2x1;
00339 
00340   unsigned m_size;
00341   double*  p_xarr;
00342   double*  p_yarr;
00343   double*  p_zarr;
00344   double*  p_aarr; // pixel area array
00345   int*     p_marr; // pixel mask array
00346 
00347   void transform_geo_coord_arrays( const double* X, 
00348                                    const double* Y,  
00349                                    const double* Z, 
00350                                    const unsigned size,
00351                                    double*  Xt,  
00352                                    double*  Yt,  
00353                                    double*  Zt,
00354                                    const bool do_tilt=true
00355                                   );
00356 
00357   const static double DEG_TO_RAD = 3.141592653589793238463 / 180; 
00358 
00359   static void rotation(const double* X, const double* Y, const unsigned size,
00360                        const double C, const double S, 
00361                        double* Xrot, double* Yrot);
00362 
00363   static void rotation(const double* X, const double* Y, const unsigned size, const double angle_deg, 
00364                        double* Xrot, double* Yrot);
00365 
00366   /// Returns class name for MsgLogger
00367   static const std::string name() {return "PSCalib";}
00368 
00369   // Copy constructor and assignment are disabled by default
00370   GeometryObject ( const GeometryObject& ) ;
00371   GeometryObject& operator = ( const GeometryObject& ) ;
00372 };
00373 
00374 //-------------------
00375 
00376 } // namespace PSCalib
00377 
00378 #endif // PSCALIB_GEOMETRYOBJECT_H
00379 
00380 //-------------------
00381 //-------------------
00382 //-------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7