Skip to content

Commit

Permalink
use pointer instead of object for Ray and ParaxialRay
Browse files Browse the repository at this point in the history
  • Loading branch information
heterophyllus committed Sep 25, 2021
1 parent fe75710 commit 0d5b011
Show file tree
Hide file tree
Showing 39 changed files with 503 additions and 402 deletions.
6 changes: 3 additions & 3 deletions geopter/gui/Analysis/field_curvature_setting_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void FieldCurvatureSettingDialog::updateParentDockContent()

m_opticalSystem->update_model();

Longitudinal *lon = new Longitudinal(m_opticalSystem, m_renderer);
lon->plot_ast(scale);
delete lon;
Aberration *abr = new Aberration(m_opticalSystem, m_renderer);
abr->plot_astigmatism(scale);
delete abr;

m_renderer->update();
}
6 changes: 3 additions & 3 deletions geopter/gui/Analysis/longitudinal_setting_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void LongitudinalSettingDialog::updateParentDockContent()

m_opticalSystem->update_model();

Longitudinal *lon = new Longitudinal(m_opticalSystem, m_renderer);
lon->plot_lsa(scale);
delete lon;
Aberration *abr = new Aberration(m_opticalSystem, m_renderer);
abr->plot_longitudinal_spherical_aberration(scale);
delete abr;

m_renderer->update();
}
Expand Down
4 changes: 2 additions & 2 deletions geopter/gui/Analysis/paraxial_trace_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ void ParaxialTraceDialog::updateParentDockContent()
oss << std::endl;

oss << "Axial Ray..." << std::endl;
m_opticalSystem->axial_ray(wi).print(oss);
m_opticalSystem->axial_ray(wi)->print(oss);
oss << std::endl;

oss << "Principle Ray..." << std::endl;
m_opticalSystem->principle_ray(wi).print(oss);
m_opticalSystem->principle_ray(wi)->print(oss);
oss << std::endl;

m_parentDock->setStringStreamToText(oss);
Expand Down
12 changes: 7 additions & 5 deletions geopter/gui/Analysis/single_ray_trace_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ void SingleRayTraceDialog::doPupilRayTrace()
double px = ui->pupilXEdit->text().toDouble();
double py = ui->pupilYEdit->text().toDouble();
int fi = ui->fieldCombo->currentIndex();
Field* fld = m_opticalSystem->optical_spec()->field_of_view()->field(fi);
int wi = ui->wvlForPupilCombo->currentIndex();
double wvl = m_opticalSystem->optical_spec()->spectral_region()->wvl(wi)->value();

//Field *fld = opt_sys_->optical_spec()->field_of_view()->field(fi);
Eigen::Vector2d pupil_crd({px, py});
double wvl = m_opticalSystem->optical_spec()->spectral_region()->wvl(wi)->value();


// trace
SequentialTrace *tracer = new SequentialTrace(m_opticalSystem);
Ray ray_trace_result = tracer->trace_pupil_ray(pupil_crd, fi, wi);
std::shared_ptr<Ray> ray_trace_result = tracer->trace_pupil_ray(pupil_crd, fld, wvl);
delete tracer;

// construct output text
Expand All @@ -109,7 +111,7 @@ void SingleRayTraceDialog::doPupilRayTrace()
oss << "Field: " << fi << std::endl;
oss << "Wavelength: " << wi << " " << wvl << std::endl;

ray_trace_result.print(oss);
ray_trace_result->print(oss);
oss << std::endl;

// write to textview dock
Expand All @@ -136,7 +138,7 @@ void SingleRayTraceDialog::doObjectRayTrace()
double wvl = m_opticalSystem->optical_spec()->spectral_region()->wvl(wi)->value();

SequentialTrace *tracer = new SequentialTrace(m_opticalSystem);
Ray ray_trace_result = tracer->trace_ray_throughout_path(tracer->overall_sequential_path(wi), p0, dir0);
auto ray_trace_result = tracer->trace_ray_throughout_path(tracer->overall_sequential_path(wi), p0, dir0);
delete tracer;

std::ostringstream oss;
Expand All @@ -145,7 +147,7 @@ void SingleRayTraceDialog::doObjectRayTrace()
oss << "Object Space Direction : " << "(" << L << ", " << M << ", " << N << ")" << std::endl;
oss << "Wavelength: " << wi << " " << wvl << std::endl;

ray_trace_result.print(oss);
ray_trace_result->print(oss);
oss << std::endl;

m_parentDock->setStringStreamToText(oss);
Expand Down
9 changes: 7 additions & 2 deletions geopter/gui/Analysis/spot_diagram_setting_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ SpotDiagramSettingDialog::SpotDiagramSettingDialog(OpticalSystem* sys, PlotViewD
ui->setupUi(this);

m_renderer = new RendererQCP(m_parentDock->customPlot());

ui->rayPatternCombo->clear();
ui->rayPatternCombo->addItems(QStringList({"Grid", "Hexapolar"}));
ui->rayPatternCombo->setCurrentIndex(0);
ui->nrdEdit->setValidator(new QIntValidator(1,1000,this));
ui->nrdEdit->setText(QString::number(30));
ui->nrdEdit->setText(QString::number(20));
ui->scaleEdit->setValidator(new QDoubleValidator(0.0,1000.0,4,this));
ui->scaleEdit->setText(QString::number(0.1));
ui->dotSizeEdit->setValidator(new QDoubleValidator(0.0,1000.0,4,this));
Expand All @@ -31,14 +35,15 @@ void SpotDiagramSettingDialog::updateParentDockContent()
{
m_renderer->clear();

int pattern = ui->rayPatternCombo->currentIndex();
int nrd = ui->nrdEdit->text().toInt();
double scale = ui->scaleEdit->text().toDouble();
double dotSize = ui->dotSizeEdit->text().toDouble();

m_opticalSystem->update_model();

Aberration *abr = new Aberration(m_opticalSystem, m_renderer);
abr->plot_spot_diagram(nrd,scale,dotSize);
abr->plot_spot_diagram(pattern, nrd, scale, dotSize);
delete abr;

m_renderer->update();
Expand Down
68 changes: 39 additions & 29 deletions geopter/gui/Analysis/spot_diagram_setting_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Ray Density: </string>
</property>
</widget>
<item row="3" column="1">
<widget class="QLineEdit" name="dotSizeEdit"/>
</item>
<item row="1" column="2">
<item row="2" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -44,7 +30,7 @@
</property>
</spacer>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QLineEdit" name="nrdEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
Expand All @@ -54,14 +40,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Scale:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -74,7 +53,7 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="scaleEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
Expand All @@ -84,16 +63,47 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="dotSizeEdit"/>
<item row="4" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Scale:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Dot Size:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Ray Density: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="rayPatternCombo"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Pattern:</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
6 changes: 3 additions & 3 deletions geopter/gui/Analysis/transverse_ray_fan_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void TransverseRayFanDialog::updateParentDockContent()

m_opticalSystem->update_model();

RayFan *ray_fan = new RayFan(m_opticalSystem, m_renderer);
ray_fan->plot(scale, nrd);
delete ray_fan;
Aberration *abr = new Aberration(m_opticalSystem, m_renderer);
abr->plot_transverse_aberration(scale, nrd);
delete abr;

m_renderer->update();
}
2 changes: 1 addition & 1 deletion geopter/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void MainWindow::showSpotDiagram()
PlotViewDock *dock = new PlotViewDock("Spot Diagram", opt_sys_.get());
dock->createSettingDialog<SpotDiagramSettingDialog>();
m_dockManager->addDockWidgetFloating(dock);
dock->resize(300,200);
//dock->resize(300,200);
dock->updatePlot();
}

Expand Down
1 change: 0 additions & 1 deletion geopter/gui/plot_view_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ PlotViewDock::PlotViewDock(QString label, OpticalSystem* sys, QWidget *parent):
{
this->setFeature(CDockWidget::DockWidgetDeleteOnClose, true);
this->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
//this->resize(300,200);
this->setMinimumSize(300,200);

// QCustomPlot
Expand Down
10 changes: 9 additions & 1 deletion geopter/optical/include/Analysis/aberration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ class Aberration

void plot_chromatic_focus_shift(double lower_wvl, double higher_wvl);

void plot_spot_diagram(int nrd, double scale, double dot_size);
void plot_spot_diagram(int pattern, int nrd, double scale, double dot_size);

private:
std::vector<Eigen::Vector2d> create_grid_circle(int nrd);
std::vector<Eigen::Vector2d> create_hexapolar(int nrd);

enum SpotRayPattern{
Grid,
Hexapolar
};

OpticalSystem* opt_sys_;
Renderer* renderer_;
int num_fld_;
Expand Down
2 changes: 1 addition & 1 deletion geopter/optical/include/Analysis/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Layout
void draw_fan_rays(int nrd= 10);

/** Draw a single ray */
void draw_single_ray(const Ray& ray, const Rgb& color);
void draw_single_ray(const std::shared_ptr<Ray>& ray, const Rgb& color);

void update();

Expand Down
4 changes: 2 additions & 2 deletions geopter/optical/include/Assembly/even_polynomial.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class EvenPolynomial : public SurfaceProfile
int coef_count() const;

double sag(double x, double y) const override;
double f(Eigen::Vector3d p) const override;
Eigen::Vector3d df(Eigen::Vector3d p) const override;
double f(const Eigen::Vector3d& p) const override;
Eigen::Vector3d df(const Eigen::Vector3d& p) const override;

double deriv_1st(double h) const override;
double deriv_2nd(double h) const override;
Expand Down
2 changes: 1 addition & 1 deletion geopter/optical/include/Assembly/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Interface

/** Returns true if the given point(x,y) is inside of aperture */
bool point_inside(double x, double y) const;
bool point_inside(Eigen::Vector2d pt) const;
bool point_inside(const Eigen::Vector2d& pt) const;

void set_local_transform(Transformation tfrm);
void set_global_transform(Transformation tfrm);
Expand Down
6 changes: 3 additions & 3 deletions geopter/optical/include/Assembly/spherical.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Spherical : public SurfaceProfile
Spherical(double c=0.0);
~Spherical();

double f(Eigen::Vector3d p) const override;
Eigen::Vector3d df(Eigen::Vector3d p) const override;
double f(const Eigen::Vector3d& p) const override;
Eigen::Vector3d df(const Eigen::Vector3d& p) const override;
double sag(double x, double y) const override;

void intersect(Eigen::Vector3d& pt, double& s, Eigen::Vector3d p0, Eigen::Vector3d d, double eps=1.0e-12, int z_dir=1.0) override;
void intersect(Eigen::Vector3d& pt, double& s, const Eigen::Vector3d& p0, const Eigen::Vector3d& d, double eps=1.0e-12, int z_dir=1.0) override;

};

Expand Down
2 changes: 1 addition & 1 deletion geopter/optical/include/Assembly/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Surface : public Interface
* @param eps precision
* @param z_dir
*/
void intersect(Eigen::Vector3d& pt, double& s, Eigen::Vector3d p0, Eigen::Vector3d d, double eps=1.0e-12, double z_dir=1.0);
void intersect(Eigen::Vector3d& pt, double& s, const Eigen::Vector3d& p0, const Eigen::Vector3d& d, double eps=1.0e-12, double z_dir=1.0);

Eigen::Vector3d normal(Eigen::Vector3d p);

Expand Down
10 changes: 5 additions & 5 deletions geopter/optical/include/Assembly/surface_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class SurfaceProfile
virtual double radius() const;

/** Returns the value of the profile function at point @param{p} */
virtual double f(Eigen::Vector3d p) const;
virtual double f(const Eigen::Vector3d& p) const;

/** Returns the gradient of the profile function at point *p* */
virtual Eigen::Vector3d df(Eigen::Vector3d p) const;
virtual Eigen::Vector3d df(const Eigen::Vector3d& p) const;

/** Returns the unit normal of the profile at point *p* */
virtual Eigen::Vector3d normal(Eigen::Vector3d p) const;
virtual Eigen::Vector3d normal(const Eigen::Vector3d& p) const;

/** Returns the sagitta (z coordinate) of the surface at x, y */
virtual double sag(double x, double y) const;
Expand All @@ -57,7 +57,7 @@ class SurfaceProfile
* @param eps numeric tolerance for convergence of any iterative procedure
* @param z_dir +1 if propagation positive direction, -1 if otherwise
*/
virtual void intersect(Eigen::Vector3d& pt, double& s, Eigen::Vector3d p0, Eigen::Vector3d d, double eps=1.0e-12, int z_dir=1);
virtual void intersect(Eigen::Vector3d& pt, double& s, const Eigen::Vector3d& p0, const Eigen::Vector3d& d, double eps=1.0e-12, int z_dir=1);

/**
* @brief Intersect a profile, starting from an arbitrary point
Expand All @@ -69,7 +69,7 @@ class SurfaceProfile
* @param eps numeric tolerance for convergence of any iterative procedure
* @param z_dir +1 if propagation positive direction, -1 if otherwise
*/
virtual void intersect_spencer(Eigen::Vector3d& pt, double& s, Eigen::Vector3d p0, Eigen::Vector3d d, double eps=1.0e-12, int z_dir=1.0);
virtual void intersect_spencer(Eigen::Vector3d& pt, double& s, const Eigen::Vector3d& p0, const Eigen::Vector3d& d, double eps=1.0e-12, int z_dir=1.0);


protected:
Expand Down
Loading

0 comments on commit 0d5b011

Please sign in to comment.