Skip to content

Commit

Permalink
make spot diagram faster
Browse files Browse the repository at this point in the history
  • Loading branch information
heterophyllus committed Sep 26, 2021
1 parent 0d5b011 commit 6a8dcdf
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 176 deletions.
14 changes: 8 additions & 6 deletions geopter/gui/Analysis/renderer_qcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void RendererQCP::set_current_cell(int row, int col)
}


void RendererQCP::draw_line(Eigen::Vector2d p1, Eigen::Vector2d p2, const Rgb& color, int line_style)
void RendererQCP::draw_line(const Eigen::Vector2d& p1, const Eigen::Vector2d& p2, const Rgb& color, int line_style)
{
QCPAxisRect *axisRect = customPlot_->axisRect(current_cell_index_);

Expand Down Expand Up @@ -84,7 +84,7 @@ void RendererQCP::draw_line(Eigen::Vector2d p1, Eigen::Vector2d p2, const Rgb& c
line->setVisible(true);
}

void RendererQCP::draw_polyline(std::vector<Eigen::Vector2d> &pts, const Rgb& color, int line_style)
void RendererQCP::draw_polyline(const std::vector<Eigen::Vector2d> &pts, const Rgb& color, int line_style)
{
QCPAxisRect *axisRect = customPlot_->axisRect(current_cell_index_);
//QCPCurve* polyline = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis);
Expand Down Expand Up @@ -116,7 +116,7 @@ void RendererQCP::draw_polyline(std::vector<Eigen::Vector2d> &pts, const Rgb& co

}

void RendererQCP::draw_polyline(std::vector<double> &x, std::vector<double> &y, const Rgb& color, int line_style)
void RendererQCP::draw_polyline(const std::vector<double> &x, const std::vector<double> &y, const Rgb& color, int line_style)
{
int pointCount = x.size();
QVector<QCPCurveData> curveData(pointCount);
Expand Down Expand Up @@ -148,7 +148,7 @@ void RendererQCP::draw_polyline(std::vector<double> &x, std::vector<double> &y,
polyline->setVisible(true);
}

void RendererQCP::draw_dots(std::vector<double> &x, std::vector<double> &y, const Rgb &color, double dot_size)
void RendererQCP::draw_dots(const std::vector<double> &x, const std::vector<double> &y, const Rgb &color, double dot_size)
{
int pointCount = x.size();
QVector<QCPCurveData> dotsData(pointCount);
Expand Down Expand Up @@ -197,9 +197,11 @@ void RendererQCP::set_y_axis_label(std::string label)

void RendererQCP::set_aspect_ratio(double h_per_v)
{
//_customPlot->yAxis->setScaleRatio(_customPlot->xAxis, h_per_v);
customPlot_->yAxis->setScaleRatio(customPlot_->xAxis, h_per_v);
QCPAxis *xAxis = customPlot_->axisRect(current_cell_index_)->axis(QCPAxis::atBottom);
customPlot_->axisRect(current_cell_index_)->axis(QCPAxis::atLeft)->setScaleRatio(xAxis, h_per_v);
QCPAxis *yAxis = customPlot_->axisRect(current_cell_index_)->axis(QCPAxis::atLeft);

xAxis->setScaleRatio(yAxis, h_per_v);
}

void RendererQCP::set_mouse_interaction(bool state)
Expand Down
8 changes: 4 additions & 4 deletions geopter/gui/Analysis/renderer_qcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class RendererQCP : public Renderer
void set_grid_layout(int rows, int cols) override;
void set_current_cell(int row, int col) override;

void draw_line(Eigen::Vector2d p1, Eigen::Vector2d p2, const Rgb& color, int line_style=0) override;
void draw_polyline(std::vector<Eigen::Vector2d>& pts, const Rgb& color, int line_style=0) override;
void draw_polyline(std::vector<double>& x, std::vector<double>& y, const Rgb& color, int line_style=0) override;
void draw_dots(std::vector<double>& x, std::vector<double>& y, const Rgb& color, double dot_size) override;
void draw_line(const Eigen::Vector2d& p1, const Eigen::Vector2d& p2, const Rgb& color, int line_style=0) override;
void draw_polyline(const std::vector<Eigen::Vector2d>& pts, const Rgb& color, int line_style=0) override;
void draw_polyline(const std::vector<double>& x, const std::vector<double>& y, const Rgb& color, int line_style=0) override;
void draw_dots(const std::vector<double>& x, const std::vector<double>& y, const Rgb& color, double dot_size) override;

void set_x_axis_range(double xmin, double xmax) override;
void set_y_axis_range(double ymin, double ymax) override;
Expand Down
1 change: 0 additions & 1 deletion geopter/optical/include/Assembly/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Surface : public Interface
Surface(double r);
~Surface();

void update() override;

/**
* @brief Compute intersect point and distance from the previous interface
Expand Down
2 changes: 0 additions & 2 deletions geopter/optical/include/Assembly/surface_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class SurfaceProfile
SurfaceProfile();
virtual ~SurfaceProfile();

virtual void update();

virtual std::string name() const;

virtual void set_cv(double c);
Expand Down
79 changes: 62 additions & 17 deletions geopter/optical/include/Paraxial/paraxial_ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,75 @@
namespace geopter {

/** Paraxial ray parameter at each surface */
struct ParaxialRayAtSurface
class ParaxialRayAtSurface
{
public:
ParaxialRayAtSurface(){
ht = 0.0;
slp = 0.0;
aoi = 0.0;
n = 1.0;
y_ = 0.0;
u_prime_ = 0.0;
i_ = 0.0;
n_prime_ = 0.0;
before_ = nullptr;
}

ParaxialRayAtSurface(double y, double u_prime, double i, double n_prime){
y_ = y;
u_prime_ = u_prime;
i_ = i;
n_prime_ = n_prime;
before_ = nullptr;
}

void set_before(ParaxialRayAtSurface* before){
before_ = before;
}

double y(){
return y_;
}

/** Returns incoming slope */
double u(){
if(before_){
return before_->u_prime();
}else{ // assume at object
return u_prime_;
}
}

/** Returns outgoing slope */
double u_prime(){
return u_prime_;
};

double i(){
return i_;
}

ParaxialRayAtSurface(double y, double u, double i, double ind){
ht = y;
slp = u;
aoi = i;
n = ind;
double n(){
if(before_){
return before_->n_prime();
}else{
return n_prime_;
}
}

double n_prime(){
return n_prime_;
}

/** Returns paraxial conjugate point distance */
double l_prime() {
return (- ht/slp);
return (- y_/u_prime_);
}

double ht;
double slp; // outgoing
double aoi; // incident
double n; // incident
private:
double y_;
double u_prime_; // outgoing
double i_; // incident
double n_prime_; // outgoing

ParaxialRayAtSurface *before_;
};


Expand All @@ -43,10 +88,10 @@ class ParaxialRay
~ParaxialRay();

void prepend(std::shared_ptr<ParaxialRayAtSurface> par_ray_at_srf);
void prepend(double ht, double slp, double aoi= 0, double n = 1.0);
void prepend(double y, double u_prime, double i= 0, double n_prime = 1.0);

void append(std::shared_ptr<ParaxialRayAtSurface> par_ray_at_srf);
void append(double ht, double slp, double aoi= 0, double n = 1.0);
void append(double y, double u_prime, double i= 0, double n_prime = 1.0);

void clear();

Expand Down
8 changes: 4 additions & 4 deletions geopter/optical/include/Renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class Renderer
virtual void set_grid_layout(int rows, int cols);
virtual void set_current_cell(int row, int col);

virtual void draw_line(Eigen::Vector2d p1, Eigen::Vector2d p2, const Rgb& color, int line_style=0);
virtual void draw_polyline(std::vector<Eigen::Vector2d>& pts, const Rgb& color, int line_style=0);
virtual void draw_polyline(std::vector<double>& x, std::vector<double>& y, const Rgb& color, int line_style=0);
virtual void draw_line(const Eigen::Vector2d& p1, const Eigen::Vector2d& p2, const Rgb& color, int line_style=0);
virtual void draw_polyline(const std::vector<Eigen::Vector2d>& pts, const Rgb& color, int line_style=0);
virtual void draw_polyline(const std::vector<double>& x, const std::vector<double>& y, const Rgb& color, int line_style=0);
virtual void draw_text(std::string str, const Rgb& color);
virtual void draw_dots(std::vector<double>& x, std::vector<double>& y, const Rgb& color, double dot_size);
virtual void draw_dots(const std::vector<double>& x, const std::vector<double>& y, const Rgb& color, double dot_size);

virtual void draw_x_axis(bool state= true);
virtual void draw_y_axis(bool state= true);
Expand Down
3 changes: 3 additions & 0 deletions geopter/optical/include/Sequential/ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ struct RayAtSurface

/** Ray height from the axis */
double height() const { return sqrt( pow(intersect_pt(0),2) + pow(intersect_pt(1),2) ); }

public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};


Expand Down
23 changes: 13 additions & 10 deletions geopter/optical/include/Sequential/sequential_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ class SequentialTrace
SequentialTrace(OpticalSystem* sys);
~SequentialTrace();

//std::shared_ptr<Ray> trace_pupil_ray(Eigen::Vector2d pupil_crd, int fi, int wi);

std::shared_ptr<Ray> trace_pupil_ray(const Eigen::Vector2d& pupil_crd, const Field* fld, double wvl);

/**
* @brief Trace patterned rays (grid, hexapolar, etc)
* @param rays Traced Ray vector
* @param pupils pupil coordinated list
* @param fld Field pointer
* @param wvl wavelength value
* @return number of valid rays
*/
int trace_pupil_pattern_rays(std::vector< std::shared_ptr<Ray> >& rays, const std::vector< Eigen::Vector2d >& pupils, const Field* fld, double wvl);

/** Trace a ray throughout the given sequantial path */
std::shared_ptr<Ray> trace_ray_throughout_path(const SequentialPath& seq_path, const Eigen::Vector3d& pt0, const Eigen::Vector3d& dir0);

Eigen::Vector2d trace_coddington(const Field* fld, double wvl);

//Eigen::Vector2d aim_chief_ray(int fi, int wi);

Eigen::Vector2d aim_chief_ray(const Field* fld, double wvl);

/**
Expand All @@ -41,18 +47,15 @@ class SequentialTrace
* @return Eigen::Vector2d aim point on paraxial entrance pupil plane
*/
Eigen::Vector2d search_aim_point(int srf_idx, const Eigen::Vector2d& xy_target, const Field* fld, double wvl);
//Eigen::Vector2d search_aim_point(int srf_idx, Eigen::Vector2d xy_target, int fi, int wi);

/** @brief Refract incoming direction, d_in, about normal
* @param d_in incident direction
* @param normal normal of the surface
* @return direction of refracted ray
*/
Eigen::Vector3d bend(Eigen::Vector3d d_in, Eigen::Vector3d normal, double n_in, double n_out);
Eigen::Vector3d bend(const Eigen::Vector3d& d_in, const Eigen::Vector3d& normal, double n_in, double n_out);

/** Get object coordinate for the given field */
//Eigen::Vector3d object_coord(int fi);

Eigen::Vector3d object_coord(const Field* fld);

/** Get sequential path between start and end */
Expand All @@ -71,9 +74,9 @@ class SequentialTrace
bool apply_vig_status() const;

private:
double y_stop_coordinate(double y1, int ifcx, Eigen::Vector3d pt0, double dist, double wvl, double y_target);
double y_stop_coordinate(double y1, int ifcx, const Eigen::Vector3d& pt0, double dist, double wvl, double y_target);

double compute_vignetting_factor_for_pupil(Eigen::Vector2d full_pupil, const Field& fld);
double compute_vignetting_factor_for_pupil(const Eigen::Vector2d& full_pupil, const Field& fld);

OpticalSystem *opt_sys_;

Expand Down
14 changes: 8 additions & 6 deletions geopter/optical/include/Spec/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Field
double vuy() const;
double weight() const;
Rgb render_color() const;
Eigen::Vector2d aim_pt() const;
Eigen::Vector3d object_coord() const;

void set_x(double x);
void set_y(double y);
Expand All @@ -34,26 +36,26 @@ class Field
void set_vuy(double vuy);
void set_weight(double wt);
void set_render_color(const Rgb& color);

Eigen::Vector2d aim_pt() const;
void set_aim_pt(PupilCrd aim_pt);
void set_object_coord(Eigen::Vector3d obj_crd);

PupilCrd apply_vignetting(PupilCrd pupil) const;

void update();
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

protected:
double x_;
double y_;
double wt_;
double vux_;
double vuy_;
double vlx_;
double vly_;
double wt_;

Eigen::Vector2d aim_pt_;

Eigen::Vector3d object_coord_;
Rgb render_color_;


};

} //namespace geopter
Expand Down
2 changes: 2 additions & 0 deletions geopter/optical/include/Spec/pupil_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class PupilSpec

void print(std::ostringstream& oss);

EIGEN_MAKE_ALIGNED_OPERATOR_NEW

private:
int pupil_type_;
double value_;
Expand Down
2 changes: 1 addition & 1 deletion geopter/optical/include/Spec/wvl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define WVL_H

#include "spectral_line.h"

#include "Renderer/rgb.h"

namespace geopter{
Expand Down Expand Up @@ -30,6 +29,7 @@ class Wvl

void set_render_color(Rgb color);

/** Returns render color */
Rgb render_color() const;

private:
Expand Down
1 change: 1 addition & 0 deletions geopter/optical/include/System/optical_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class OpticalSystem
void update_reference_rays();
void update_semi_diameters();
void update_paraxial_data();
void update_object_coords();

std::unique_ptr<OpticalAssembly> opt_assembly_;
std::unique_ptr<OpticalSpec> opt_spec_;
Expand Down
Loading

0 comments on commit 6a8dcdf

Please sign in to comment.