00001
00002 #include "vmal_refine_lines.h"
00003
00004 #include <vmal/vmal_operators.h>
00005 #include <vnl/vnl_inverse.h>
00006
00007 vmal_refine_lines::vmal_refine_lines()
00008 {
00009 }
00010
00011 vmal_refine_lines::~vmal_refine_lines()
00012 {
00013 }
00014
00015
00016 void vmal_refine_lines::refine_lines_f(vnl_double_3 &line0p, vnl_double_3 &line0q,
00017 vnl_double_3 &line1p, vnl_double_3 &line1q,
00018 const vnl_double_3x3 & F,
00019 vnl_double_3 &r_line0p, vnl_double_3 &r_line0q,
00020 vnl_double_3 &r_line1p, vnl_double_3 &r_line1q)
00021 {
00022 vnl_double_3 epi_line1p=F*line0p;
00023 vnl_double_3 epi_line1q=F*line0q;
00024 vnl_double_3 epi_line0p=(F.transpose()*line1p);
00025 vnl_double_3 epi_line0q=(F.transpose()*line1q);
00026
00027 r_line0p=line0p;
00028 r_line0q=line0q;
00029 r_line1p=line1p;
00030 r_line1q=line1q;
00031
00032 vnl_double_3 inter1p;
00033 vnl_double_3 inter1q;
00034
00035 double alpha,beta;
00036
00037 if (vmal_operators::line_cross_seg(line1p, line1q,
00038 epi_line1p, inter1p,alpha))
00039 if (vmal_operators::line_cross_seg(line1p, line1q,
00040 epi_line1q, inter1q,beta))
00041 {
00042
00043 vmal_operators::line_cross_seg(line0p, line0q,
00044 epi_line0p, r_line0p,alpha);
00045 vmal_operators::line_cross_seg(line0p, line0q,
00046 epi_line0q, r_line0q,beta);
00047 }
00048 else
00049 {
00050
00051 vmal_operators::line_cross_seg(line0p, line0q,
00052 epi_line0p, r_line0p, alpha);
00053 r_line1q=inter1q;
00054 }
00055 else
00056 if (vmal_operators::line_cross_seg(line1p, line1q,
00057 epi_line1q, inter1q, beta))
00058 {
00059
00060 vmal_operators::line_cross_seg(line0p, line0q,
00061 epi_line0q, r_line0q, beta);
00062 r_line1p=inter1p;
00063 }
00064 else
00065 {
00066
00067 r_line1p=inter1p;
00068 r_line1q=inter1q;
00069 }
00070 }
00071
00072
00073
00074 void vmal_refine_lines::refine_lines_max_h(vnl_double_3 &line0p, vnl_double_3 &line0q,
00075 vnl_double_3 &line1p, vnl_double_3 &line1q,
00076 const vnl_double_3x3 & H,
00077 vnl_double_3 &r_line0p, vnl_double_3 &r_line0q,
00078 vnl_double_3 &r_line1p, vnl_double_3 &r_line1q)
00079 {
00080 vnl_double_3x3 HI=vnl_inverse(H);
00081
00082 vnl_double_3 h_line1_p=H*line0p;
00083 vnl_double_3 h_line1_q=H*line0q;
00084 vnl_double_3 h_line0_p=HI*line1p;
00085 vnl_double_3 h_line0_q=HI*line1q;
00086
00087 r_line0p=line0p;
00088 r_line0q=line0q;
00089 r_line1p=line1p;
00090 r_line1q=line1q;
00091
00092 vnl_double_3 inter1p;
00093 vnl_double_3 inter1q;
00094
00095 if (vmal_operators::project_point(h_line1_p,line1p,line1q,inter1p))
00096 if (vmal_operators::project_point(h_line1_q,line1p,line1q,inter1q))
00097 {
00098
00099 vmal_operators::project_point(h_line0_p,line0p,line0q,r_line0p);
00100 vmal_operators::project_point(h_line0_q,line0p,line0q,r_line0q);
00101 }
00102 else
00103 {
00104
00105 vmal_operators::project_point(h_line0_p,line0p,line0q,r_line0p);
00106 r_line1q=inter1q;
00107 }
00108 else
00109 if (vmal_operators::project_point(h_line1_q,line1p,line1q,inter1q))
00110 {
00111
00112 r_line1p=inter1p;
00113 vmal_operators::project_point(h_line0_q,line0p,line0q,r_line0q);
00114 }
00115 else
00116 {
00117
00118 r_line1p=inter1p;
00119 r_line1q=inter1q;
00120 }
00121 }
00122
00123
00124
00125 void vmal_refine_lines::refine_lines_min_h(vnl_double_3 &line0p, vnl_double_3 &line0q,
00126 vnl_double_3 &line1p, vnl_double_3 &line1q,
00127 const vnl_double_3x3 &H,
00128 vnl_double_3 &r_line0p, vnl_double_3 &r_line0q,
00129 vnl_double_3 &r_line1p, vnl_double_3 &r_line1q)
00130 {
00131 vnl_double_3x3 HI=vnl_inverse(H);
00132
00133 r_line0p=line0p;
00134 r_line0q=line0q;
00135 r_line1p=line1p;
00136 r_line1q=line1q;
00137
00138 vnl_double_3 h_line1_p=H*line0p;
00139 vnl_double_3 h_line1_q=H*line0q;
00140 vnl_double_3 h_line0_p=HI*line1p;
00141 vnl_double_3 h_line0_q=HI*line1q;
00142
00143 vnl_double_3 inter1p;
00144 vnl_double_3 inter1q;
00145
00146 if (vmal_operators::project_point(h_line1_p,line1p,line1q,inter1p))
00147 {
00148 if (vmal_operators::project_point(h_line1_q,line1p,line1q,inter1q))
00149 {
00150
00151 r_line1p=inter1p;
00152 r_line1q=inter1q;
00153 }
00154 else
00155 {
00156
00157 vmal_operators::project_point(h_line0_q,line0p,line0q,r_line0q);
00158 r_line1p=inter1p;
00159 }
00160 }
00161 else
00162 {
00163 if (vmal_operators::project_point(h_line1_q,line1p,line1q,inter1q))
00164 {
00165
00166 vmal_operators::project_point(h_line0_p,line0p,line0q,r_line0p);
00167 r_line1q=inter1q;
00168 }
00169 else
00170 {
00171
00172 vmal_operators::project_point(h_line0_p,line0p,line0q,r_line0p);
00173 vmal_operators::project_point(h_line0_q,line0p,line0q,r_line0q);
00174 }
00175 }
00176 }