Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:43

0001 #pragma once
0002 
0003 #include <glm/glm.hpp>
0004 
0005 #include "scuda.h"
0006 #include "stran.h"
0007 #include "sstr.h"
0008 #include "NP.hh"
0009 
0010 
0011 struct SPlaceCircle
0012 {
0013     static constexpr const double TWOPI = glm::pi<double>()*2.0 ;  
0014     double radius ; 
0015     unsigned num_in_ring ; 
0016     double frac_phase ; 
0017 
0018     SPlaceCircle(double radius, unsigned num_in_ring, double frac_phase ); 
0019     std::string desc() const ; 
0020 
0021     NP* transforms(const char* opts) const ; 
0022 };
0023 
0024  
0025 inline SPlaceCircle::SPlaceCircle(double radius_, unsigned num_in_ring_, double frac_phase_)
0026     :
0027     radius(radius_),
0028     num_in_ring(num_in_ring_),
0029     frac_phase(frac_phase_)
0030 {
0031 }
0032 
0033 inline std::string SPlaceCircle::desc() const 
0034 {
0035     std::stringstream ss ; 
0036     ss << "SPlaceCircle::desc" 
0037        << " radius " << radius 
0038        << " num_in_ring " << num_in_ring 
0039        << " frac_phase " << frac_phase 
0040        << std::endl 
0041        ; 
0042     std::string s = ss.str(); 
0043     return s ; 
0044 }
0045 
0046 /**
0047 
0048 
0049                Z
0050                |
0051                |
0052                | 
0053          ------+-------> X
0054 
0055 
0056 **/
0057 
0058 inline NP* SPlaceCircle::transforms(const char* opts) const 
0059 {
0060     std::vector<std::string> vopts ; 
0061     sstr::Split(opts, ',', vopts); 
0062     unsigned num_opt = vopts.size(); 
0063     bool dump = false ; 
0064  
0065     NP* trs = NP::Make<double>( num_in_ring, num_opt, 4, 4 ); 
0066     double* tt = trs->values<double>();     
0067     unsigned item_values = num_opt*4*4 ; 
0068     
0069     if(dump) std::cout 
0070         << "SPlaceCircle::transforms"
0071         << " num_opt " << num_opt
0072         << " tt " << tt
0073         << " item_values " << item_values
0074         << std::endl 
0075         ; 
0076 
0077     double phi[num_in_ring] ; 
0078     for(unsigned j=0 ; j < num_in_ring ; j++) 
0079     {
0080         double frac = double(j)/double(num_in_ring) ; 
0081         phi[j] = TWOPI*(frac_phase + frac ) ; 
0082     }
0083     // not num_in_ring-1 as do not want to have both 0. and 2.pi 
0084 
0085     glm::tvec3<double> a(0.,0.,1.);   // +Z axis 
0086 
0087     for(unsigned j=0 ; j < num_in_ring ; j++)
0088     {
0089         glm::tvec3<double> u(cos(phi[j]),0, sin(phi[j])); // u: point stepping around unit circle in XZ plane 
0090         glm::tvec3<double> b = -u ;                       // b: where to rotate the z axis too, inwards  
0091         glm::tvec3<double> c = u*radius ;                 // c: translation 
0092 
0093         for(unsigned k=0 ; k < num_opt ; k++)
0094         { 
0095             unsigned offset = item_values*j+16*k ; 
0096             const char* opt = vopts[k].c_str();  
0097 
0098             if(dump) std::cout 
0099                 << "SPlace::AroundCircle" 
0100                 << " opt " << opt
0101                 << " offset " << offset 
0102                 << std::endl 
0103                 ;
0104 
0105             Tran<double>::AddTransform(tt+offset, opt, a, b, c );   // rotate a->b and translate by c 
0106         }
0107     }
0108     return trs ; 
0109 }
0110 
0111 
0112