2 # pragma warning (disable: 4005) // for VS8 + WX
5 #include <Gui/wxProjectionPanel.hh>
6 #include <Geometry/ProjectionParametersSpherical.hh>
7 #include <Gui/StringConv.hh>
26 ID_NormalizeQuaternion
53 const wxPoint& pos, const wxSize& size,
54 long style, const wxString& name,
bool createButtons)
55 : wxPanel(parent,
id, pos, size, style, name)
57 selfModifying_ =
false;
60 projectionPanel_->SetScrollRate(1, 1);
62 wxSizer* buttonSizer =
new wxBoxSizer(wxHORIZONTAL);
66 buttonSizer->Add(
new wxButton(
this, ID_New, wxT(
"New")));
67 buttonSizer->Add(
new wxButton(
this, ID_Load, wxT(
"Load")));
68 buttonSizer->Add(
new wxButton(
this, ID_Save, wxT(
"Save")));
71 wxSizer* mainSizer =
new wxBoxSizer(wxVERTICAL);
72 mainSizer->Add(buttonSizer, 0, wxALL, 5);
73 mainSizer->Add(projectionPanel_, 1, wxEXPAND | wxALL, 5);
78 void wxProjectionPanel::SetProjection(
const Projection& projection)
81 projectionPanel_->DestroyChildren();
82 notebookPages_.clear();
85 panelQuaternion_.clear();
86 panelRMatrix_.clear();
87 panelImageSize_.clear();
88 panelAspectRatio_.clear();
89 panelPrincipal_.clear();
90 panelKMatrix_.clear();
91 panelFocalLength_.clear();
92 panelUndistortion_.clear();
96 wxFlexGridSizer* sizer =
new wxFlexGridSizer(1, 5, 5);
98 sizer->AddGrowableCol(1);
99 projectionPanel_->SetSizer(sizer);
100 noteBook_ =
new wxNotebook(projectionPanel_, -1,
102 wxDefaultPosition,wxSize(-1,-1), wxNB_TOP);
103 sizer->Add(noteBook_, 0, wxALL, 5);
105 projection_ = projection;
107 for(
unsigned i=0;i<projection_.Size();i++){
110 wxDefaultPosition,wxSize(-1,-1)));
111 wxFlexGridSizer* sizerPage =
new wxFlexGridSizer(2, 1,1);
113 sizerPage->AddGrowableCol(1);
114 notebookPages_.back()->SetSizer(sizerPage);
119 sizerPage->Add(
new wxStaticText(notebookPages_.back(), -1,
120 wxT(
"Identifier:"),wxDefaultPosition,wxSize(-1,-1)));
121 sizerPage->Add(
new wxStaticText(notebookPages_.back(), -1,
124 panelCenter_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Center"), ID_Center,
true));
125 panelQuaternion_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Quaternion"), ID_Quaternion,
true));
127 sizerPage->AddSpacer(0);
128 sizerPage->Add(
new wxButton(notebookPages_.back(), ID_NormalizeQuaternion, wxT(
"Normalize Quaternion")));
130 panelRMatrix_.push_back(AddMatrixPanel(notebookPages_.back(),wxT(
"R Matrix"), ID_RMatrix,
false));
131 panelImageSize_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Image Size"), ID_ImageSize,
true));
132 panelAspectRatio_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Aspect Ratio"), ID_AspectRatio,
true));
133 panelPrincipal_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Principal"), ID_Principal,
true));
138 if (paramsPersp != NULL)
140 panelKMatrix_.push_back(AddMatrixPanel(notebookPages_.back(),wxT(
"K Matrix"), ID_KMatrix,
false));
141 panelFocalLength_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Focal Length"), ID_FocalLength,
true));
142 panelUndistortion_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Undistortion"), ID_Undistortion,
true));
146 panelKMatrix_.push_back(NULL);
147 panelFocalLength_.push_back(NULL);
148 panelUndistortion_.push_back(NULL);
154 if (paramsSpherical != NULL)
156 panelRadius_.push_back(AddVectorPanel(notebookPages_.back(),wxT(
"Radius"), ID_Radius,
true));
160 panelRadius_.push_back(NULL);
169 name.Printf(_T(
"%s %d"),wxT(
"Camera:"), i);
170 noteBook_->AddPage(notebookPages_.back(), name,
false);
185 const wxString& name,
186 wxWindowID
id,
bool editable)
189 panel->SetSize(wxSize(-1,-1));
190 wxSizer* sizer = parent->GetSizer();
191 sizer->Add(
new wxStaticText(parent, -1, name));
192 sizer->Add(panel, 1, wxEXPAND);
198 AddMatrixPanel(
wxWindow* parent,
const wxString& name,
199 wxWindowID
id,
bool editable)
202 panel->SetSize(wxSize(-1,-1));
203 wxSizer* sizer = parent->GetSizer();
204 sizer->Add(
new wxStaticText(parent, -1, name));
205 sizer->Add(panel, 1, wxEXPAND);
210 void wxProjectionPanel::UpdateGUI(
unsigned int cameraNr)
212 selfModifying_ =
true;
217 unsigned int imageWidth, imageHeight;
220 double principalX, principalY;
223 panelCenter_[cameraNr]->SetVector(paramsBase->
GetC());
226 panelCenter_[cameraNr]->SetVector(C);
228 if (paramsBase->
QValid()) {
229 panelQuaternion_[cameraNr]->SetVector(paramsBase->
GetQ());
236 panelRMatrix_[cameraNr]->SetMatrix(R);
238 panelImageSize_[cameraNr]->SetVector(
Vector2<double>(imageWidth, imageHeight));
240 panelPrincipal_[cameraNr]->SetVector(
Vector2<double>(principalX, principalY));
245 if (paramsPersp != NULL)
248 double kc1, kc2, kc3, kc4;
253 panelFocalLength_[cameraNr]->SetVector(
Vector<double>(1, focalLength));
254 panelUndistortion_[cameraNr]->SetVector(
Vector4<double>(kc1, kc2, kc3, kc4));
260 if (paramsSpherical != NULL)
265 selfModifying_ =
false;
268 void wxProjectionPanel::OnNormalizeQuaternion(wxCommandEvent& )
270 unsigned cameraNr = noteBook_->GetSelection();
278 void wxProjectionPanel::OnModified(wxCommandEvent& event)
280 cout <<
"Modifying" << endl;
285 unsigned cameraNr = noteBook_->GetSelection();
292 switch (event.GetId())
315 Vector<double> imageSize = panelImageSize_[cameraNr]->GetVector();
316 paramsBase->
SetImageSize((
int)imageSize[0], (
int)imageSize[1]);
321 Vector<double> aspectratio = panelAspectRatio_[cameraNr]->GetVector();
328 Vector<double> principal = panelPrincipal_[cameraNr]->GetVector();
339 Vector<double> focalLength = panelFocalLength_[cameraNr]->GetVector();
344 case ID_Undistortion:
346 Vector<double> undist = panelUndistortion_[cameraNr]->GetVector();
347 paramsPersp->
SetUndistortion(undist[0], undist[1], undist[2], undist[3]);
360 void wxProjectionPanel::OnNew(wxCommandEvent& )
362 wxString choices[] = { wxT(
"Perspective"), wxT(
"Spherical") };
365 wxSingleChoiceDialog dlg(NULL, wxT(
"Choose projection type:"),
366 wxT(
"New Projection"), numChoices, choices);
367 if (dlg.ShowModal() == wxID_OK)
369 switch (dlg.GetSelection())
381 void wxProjectionPanel::OnLoad(wxCommandEvent& )
383 #ifdef BIAS_HAVE_XML2
384 wxFileDialog dlg(NULL, wxT(
"Load Projection"), wxT(
""), wxT(
""), wxT(
"*.*"),
385 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
386 if (dlg.ShowModal() == wxID_OK)
389 if (loadedProjection.
Load(WxToAscii(dlg.GetPath())) != 0)
391 wxMessageDialog dlg(
this, wxT(
"Failed to load projection"), wxT(
"Error"));
396 SetProjection(loadedProjection);
400 BIASERR(
"XML2 missing");
404 void wxProjectionPanel::OnSave(wxCommandEvent& )
406 #ifdef BIAS_HAVE_XML2
407 wxFileDialog dlg(NULL, wxT(
"Save Projection"), wxT(
""), wxT(
""), wxT(
"*.*"), wxFD_SAVE);
408 if (dlg.ShowModal() == wxID_OK)
410 if (GetProjection().XMLWrite(WxToAscii(dlg.GetPath())) != 0)
412 wxMessageDialog dlg(
this, wxT(
"Failed to save projection"), wxT(
"Error"));
417 BIASERR(
"XML2 missing");
virtual BIAS::Vector3< double > GetC() const
Get projection center.
virtual void SetPrincipal(const double x, const double y)
Set principal point (in pixels relative to top left corner).
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
virtual void SetR(const BIAS::RMatrix &R)
Set orientation from rotation matrix R.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
virtual std::string GetIdentifier() const
void SetUndistortion(double kc1, double kc2)
void GetUndistortion(double &kc1, double &kc2, double &kc3, double &kc4) const
void Normalize()
Scales quaternion to unit length, i.e.
class Vector4 contains a Vector of dim.
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
Panel for displaying and editing projections.
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
virtual double GetAspectratio() const
Return aspectratio (i.e.
void GetFocalLength(double &f) const
Get the current camera focal length.
virtual bool QValid() const
Check if current orientation is valid.
virtual BIAS::RMatrix GetR() const
Get orientation as rotation matrix R.
virtual bool CValid() const
Check of current projection center is valid.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
virtual BIAS::KMatrix GetK() const
virtual void SetAspectratio(const double AspectRatio)
Set CCD aspect ratio (i.e.
Panel for displaying and editing vectors.
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
Panel for displaying and editing matrices.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual BIAS::Quaternion< double > GetQ() const
Get orientation as unit quaternion.
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...