Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:47

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 flightpath.py : NOT IN ACTIVE USE, instead use flight.py flight.sh 
0023 ====================================================================
0024 
0025 * TODO: ELIMINATE THIS AFTER INTEGRATING PLOTTING INTO flight_plt.py 
0026 
0027 
0028 FlightPath not in active use, easier to directly create the eye-look-up array, 
0029 as done in mm0prim2.py  and use quiver plots to debug the path.
0030 
0031 
0032 """
0033 
0034 import numpy as np, logging, os
0035 log = logging.getLogger(__name__)
0036 from opticks.ana.view import View
0037 import matplotlib.pyplot as plt
0038 from mpl_toolkits.mplot3d import Axes3D
0039 
0040 from matplotlib.patches import FancyArrowPatch
0041 from mpl_toolkits.mplot3d import proj3d
0042 
0043 class Arrow3D(FancyArrowPatch):
0044     def __init__(self, xs, ys, zs, *args, **kwargs):
0045         FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
0046         self._verts3d = xs, ys, zs
0047 
0048     def draw(self, renderer):
0049         xs3d, ys3d, zs3d = self._verts3d
0050         xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
0051         self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
0052         FancyArrowPatch.draw(self, renderer)
0053 
0054 
0055 
0056 class FlightPath(object):
0057     """
0058     See optickscore/FlightPath.hh
0059     """
0060     FILENAME = "flightpath.npy"
0061     def __init__(self):
0062         self.views = []
0063   
0064     def as_array(self):
0065         log.info(" views %s " % len(self.views) )
0066         a = np.zeros( (len(self.views), 4, 4), dtype=np.float32 )
0067         for i, v in enumerate(self.views):
0068             a[i] = v.v
0069         pass
0070         return a 
0071 
0072     def save(self, dir_="/tmp"):
0073         path = os.path.join(dir_, self.FILENAME)
0074         a = fp.as_array()
0075         log.info("save %s to %s " % (repr(a.shape), path ))
0076         np.save(path, a ) 
0077         return a
0078 
0079 
0080 if __name__ == '__main__':
0081     logging.basicConfig(level=logging.INFO) 
0082     fp = FlightPath()
0083 
0084     dtype = np.float32
0085     f = np.linspace(0, 1, 10, dtype=dtype)[:-1]    # skip last to avoid repeating seam angle 
0086     t = f*2*np.pi 
0087     n = len(f)
0088 
0089     eye = np.zeros( [n,3], dtype=dtype)
0090     eye[:,0] = np.cos(t)  
0091     eye[:,1] = np.sin(t)  
0092     eye[:,2] = 2*f-1
0093 
0094     look = np.zeros( [n,3], dtype=dtype )
0095     look[:-1] = eye[1:]
0096     look[-1] = eye[0] 
0097 
0098     gaze = look - eye  
0099 
0100     up = np.zeros( [n,3], dtype=dtype )
0101     up[:] = [0,0,1] 
0102 
0103     v = np.zeros( (n,4,4), dtype=np.float32)
0104     v[:,0,:3] = eye
0105     v[:,1,:3] = look
0106     v[:,2,:3] = up
0107 
0108     np.save("/tmp/flightpath.npy", v )
0109 
0110     plt.ion()
0111     fig = plt.figure(figsize=(6,5.5))
0112     plt.title("flightpath")
0113     ax = fig.add_subplot(111, projection='3d')
0114     sz = 3 
0115     ax.set_ylim([-sz,sz])
0116     ax.set_xlim([-sz,sz])
0117 
0118     ax.plot( eye[:,0], eye[:,1], eye[:,2]  )
0119     fig.show()
0120 
0121 """
0122     for i in range(n):
0123         a = Arrow3D([eye[i,0], gaze[i,0]],
0124                     [eye[i,1], gaze[i,1]],
0125                     [eye[i,2], gaze[i,2]], mutation_scale=20,
0126                      lw=3, arrowstyle="-|>", color="r")
0127         ax.add_artist(a)
0128     pass
0129 """
0130 
0131 
0132