Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 
0003 #include <sstream>
0004 #include <string>
0005 #include <glm/glm.hpp>
0006 
0007 #include "scuda.h"
0008 #include "stran.h"
0009 #include "sstr.h"
0010 #include "NP.hh"
0011 
0012 #include "SPlaceRing.h"
0013 
0014 struct SPlaceSphere
0015 {
0016     double radius ; 
0017     double item_arclen ; 
0018     unsigned num_ring ; 
0019     SPlaceRing* ring ;
0020     unsigned tot_item ; 
0021  
0022     SPlaceSphere(double radius, double item_arclen, unsigned num_ring); 
0023     std::string desc() const ; 
0024 
0025     NP* transforms(const char* opts) const ; 
0026 };
0027 
0028 inline SPlaceSphere::SPlaceSphere(double radius_, double item_arclen_, unsigned num_ring_)
0029     :
0030     radius(radius_),
0031     item_arclen(item_arclen_),
0032     num_ring(num_ring_),
0033     ring(new SPlaceRing[num_ring]),
0034     tot_item(0)
0035 {
0036     for(unsigned i=0 ; i < num_ring ; i++) 
0037     {
0038         SPlaceRing& rr = ring[i] ; 
0039         rr.idx  = i ; 
0040         rr.z    = -radius + 2.*radius*double(i)/double(num_ring-1) ; 
0041          
0042         rr.costh = rr.z/radius ; 
0043         double theta = acos(rr.costh); 
0044 
0045         //rr.sinth = sqrt( 1. - rr.costh*rr.costh ) ;
0046         rr.sinth = sin(theta) ;
0047  
0048         rr.circ = 2.*glm::pi<double>()*radius*rr.sinth  ;
0049         rr.num  = rr.circ/item_arclen ; 
0050 
0051         tot_item += rr.num ; 
0052     }
0053 }
0054 
0055 inline std::string SPlaceSphere::desc() const 
0056 {
0057     std::stringstream ss ; 
0058     ss << SPlaceRing::Desc(ring, num_ring) << std::endl ; 
0059     std::string s = ss.str(); 
0060     return s ; 
0061 }
0062 
0063 
0064 
0065 /**
0066 SPlaceSphere::transforms
0067 ---------------------------
0068 
0069 The shape of the array returned is (tot_items, num_opts, 4, 4) 
0070 where num_opts depends on the number of comma delimted options
0071 in the opts string. For example "RT,R,T,D" would hav num_opts 4.
0072 
0073 **/
0074 
0075 inline NP* SPlaceSphere::transforms(const char* opts) const 
0076 {
0077     if( tot_item == 0 ) return nullptr ;
0078 
0079     std::cout << desc() << " opts " << opts << std::endl ; 
0080     std::vector<std::string> vopts ; 
0081     sstr::Split(opts, ',', vopts); 
0082     unsigned num_opt = vopts.size(); 
0083  
0084     NP* trs = NP::Make<double>( tot_item, num_opt, 4, 4 ); 
0085     double* tt = trs->values<double>();     
0086     unsigned item_values = 4*4*num_opt ; 
0087 
0088     glm::tvec3<double> a(0.,0.,1.); 
0089     unsigned count = 0 ; 
0090 
0091     for(unsigned i=0 ; i < num_ring ; i++)
0092     {
0093         SPlaceRing& rr = ring[i] ; 
0094 
0095         for(unsigned j=0 ; j < rr.num ; j++)
0096         {
0097             glm::tvec3<double> u = rr.upoint(j); 
0098             glm::tvec3<double> b = -u ; 
0099             glm::tvec3<double> c = radius*u ; 
0100 
0101             unsigned idx = count  ; 
0102             count += 1 ; 
0103 
0104             for(unsigned k=0 ; k < num_opt ; k++)
0105             { 
0106                 double* ttk = tt + item_values*idx + 16*k ; 
0107                 const char* opt = vopts[k].c_str();  
0108                 Tran<double>::AddTransform(ttk, opt, a, b, c ); 
0109             }    // k:over opt
0110         }        // j:over items in the ring 
0111     }            // i:over rings
0112  
0113     assert( count == tot_item );  
0114     return trs ; 
0115 }
0116 
0117 
0118 
0119 
0120