Showing posts with label VTK. Show all posts
Showing posts with label VTK. Show all posts

Saturday, June 13, 2009

Cross compilation and string issues

Trying to keep the program I am currently working on up-to-date both on my WinXP box and on a Mac, I run into some cross-compilation pitfalls. While the project builds without warnings in vs2005, it seems that gcc on Mac has a lot to complain about.

First of all some deprecated headers apparently used by the macports VTK I'm using:
In file included from /usr/include/c++/4.0.0/backward/strstream:51,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkIOStream.h:112,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkSystemIncludes.h:40,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkIndent.h:24,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkObjectBase.h:43,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkObject.h:41,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkAlgorithm.h:32,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkPolyDataAlgorithm.h:37,
from
../../../../opt/local/var/macports/software/vtk-devel/5.4.0_3+boost+cocoa+darwin_9+data+doc+examples+java+py26+shared+tcl+testing+wrap/opt/local/include/vtk-5.4/vtkCubeSource.h:24,
from CamVtkView.h:14,
/usr/include/c++/4.0.0/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the
header for the header for C++ includes, or instead of
the deprecated header . To disable this warning use
-Wno-deprecated.

But other warnings allowed me to spot some bug of my own producing:
CamFrame.cpp:927: warning: cannot pass objects of non-POD type 'class
wxString' through '...'; call will abort at runtime
the line was :

curImg.sprintf("%s%04u.vtk", _vtkRecPrefix, m_nFrmRead);

while what I intended to do was:

curImg.Printf(wxT("%s%04u.vtk"), _vtkRecPrefix, m_nFrmRead);

And I found a link which summarizes well wxString usage:
http://wiki.wxwidgets.org/Converting_everything_to_and_from_wxString

Friday, June 12, 2009

Easy rotation with Eigen quaternions

Currently working on improving an alignment software for time-of-flight depth maps, I have to say I find the functions offered by Eigen quite useful.
Considering the two points clouds below (rendered with VTK), the first step to align them is to rotate them correctly.
















For this task, I use a simple RANSAC to find the largest plane in the point cloud. Then, having the plane normal vector nVec3, finding the rotation matrix mat that will align this plane with the Z-axis is 2 Eigen calls away :

Eigen::Vector3d nVecZ; nVecZ.UnitZ();
Eigen::Quaterniond qz; qz.setFromTwoVectors(nVec3, nVecZ);
Eigen::Matrix3d mat = qz.toRotationMatrix();

And here is the result for the dataset above:



That's 2 rotation DoF taken care of. Imposing the matched planes to have the same distance to origin takes care of one translation DoF. One rotation and 2 translations to go ;-)

Monday, June 8, 2009

wxEventHandler function do not support overloading

After some refactoring of some code I wrote to set the visibility and color of VTK objects with GUI controls from wxWidgets, I had two overloaded functions :


/* acting on visVTK checkbox*/
void MainWnd::SetVisVtk(wxCommandEvent& event)
{
SetVisVtk(_visVtk, m_camFrm,0);
SetVisVtk(_visBGVtk, m_camFrm,1);
SetVisVtk(_visFGVtk, m_camFrm,2);
SetVisVtk(_visSegmVtk, m_camFrm,3);
_vtkWin->Render();
}
/* acting on visVTK checkbox*/
void MainWnd::SetVisVtk(std::vector visChkBox, std::vector camFrm, int idx)
{
int i = 0;
std::vector::iterator itCtrl;
std::vector::iterator itCam;
for ( itCtrl = visChkBox.begin(), itCam = camFrm.begin();
itCtrl != visChkBox.end() , itCam != camFrm.end();
itCtrl++, itCam++, i++ )
{
if(!_vtkWin){return;};
(*itCam)->hideDataActVtk( !((*itCtrl)->IsChecked()) , idx);
}
}


The code compiled and ran fine on my windows box, but trying to compile on Mac revealed the error. Renaming the worker function to avoid overloading allowed a succesful compilation.


/* acting on visVTK checkbox*/
void MainWnd::SetVisVtk(wxCommandEvent& event)
{
SetVisVtkIdx(_visVtk, m_camFrm,0);
SetVisVtkIdx(_visBGVtk, m_camFrm,1);
SetVisVtkIdx(_visFGVtk, m_camFrm,2);
SetVisVtkIdx(_visSegmVtk, m_camFrm,3);
_vtkWin->Render();
}
/* acting on visVTK checkbox*/
void MainWnd::SetVisVtkIdx(std::vector visChkBox, std::vector camFrm, int idx)
{
int i = 0;
std::vector::iterator itCtrl;
std::vector::iterator itCam;
for ( itCtrl = visChkBox.begin(), itCam = camFrm.begin();
itCtrl != visChkBox.end() , itCam != camFrm.end();
itCtrl++, itCam++, i++ )
{
if(!_vtkWin){return;};
(*itCam)->hideDataActVtk( !((*itCtrl)->IsChecked()) , idx);
}
}


Of course this should have been obvious from the start, but this is why testing on multiple platform is such a pain. The faulty code compiled flawlessly in vs2005.