1 #include <Base/Common/BIASpragma.hh>
3 #include <MathAlgo/SVD.hh>
4 #include <OpenCLFramework/Algorithm/clfTrimmedICP.hh>
6 #include <OpenCLFramework/Algorithm/clfRadixSort.hh>
25 clfTrimmedICP::clfTrimmedICP(
int w,
int h) : context_(true), radixsort_(&context_) {
53 cout <<
"Sizeof : " <<
sizeof( plainpair ) << endl;
96 PointVertex *vertices = (PointVertex*)buffer.
Map();
102 for (
int y=0;y<
h_;y++) {
103 for (
int x=0;x<
w_;x++) {
113 vertices[idx].position[0] = (float)p3dv[0];
114 vertices[idx].position[1] = (float)p3dv[1];
115 vertices[idx].position[2] = (float)p3dv[2];
117 vertices[idx].color[0] = (float)x/(
float)
w_;
118 vertices[idx].color[1] = (float)y/(
float)
h_;
119 vertices[idx].color[2] = (float)d/(
float)10000.0f;
120 vertices[idx].color[3] = 1.0f;
130 cout <<
"padding " << padval <<
" " << endl;
131 unsigned int start = ret;
132 for (
unsigned int idx=start;idx<start+padval;idx++) {
134 vertices[idx].position[0] = (float)0.0f;
135 vertices[idx].position[1] = (float)0.0f;
136 vertices[idx].position[2] = (float)16000.0f;
138 vertices[idx].color[0] = 0.0f;
139 vertices[idx].color[1] = 0.0f;
140 vertices[idx].color[2] = 16000.0f/10000.0f;
141 vertices[idx].color[3] = 1.0f;
144 cout <<
"padding " << padval <<
" full: " << ret << endl;
159 Compute(
float nearestDistance,
unsigned int numberOfPoints) {
162 if (res < 10e-3 && res>0) {
163 std::cout <<
"CONVERGENCE!!" << std::endl;
166 std::cout <<
"previous result was better than current, finishing" << std::endl;
169 std::cout <<
"max iterations reached" << std::endl;
183 if (diff.NormL2() < 0.1) {
184 std::cout <<
"optimum found" << std::endl;
198 BIASWARN (
"fuse function disabled");
296 cout <<
"release gl" << endl;
316 std::cout <<
"sort!" << std::endl;
322 pairs_[i].inputpoint.Set(pairs[i].data[0], pairs[i].data[1],pairs[i].data[2]);
323 pairs_[i].modelpoint.Set(pairs[i].model[0], pairs[i].model[1],pairs[i].model[2]);
324 pairs_[i].distance = pairs[i].distance;
330 std::cout <<
"copy done." << endl;
352 for (
int i=0;i<
w_*
h_;i++) {
359 std::cout <<
"sort finished!" << std::endl;
379 if (numberOfPoints_ == 0) {
381 std::cout <<
"no pairs?!" << std::endl;
384 sum /= double(numberOfPoints_);
385 std::cout <<
"current error: " << sqrt(sum) << std::endl;
404 for (
unsigned int x=0;x<3;x++) {
405 for (
unsigned int y=0;y<3;y++) {
411 unsigned int x=0, y=1, z=2;
412 S[0][0] = M[x][x] + M[y][y] + M[z][z];
413 S[0][1] = M[y][z] - M[z][y];
414 S[0][2] = M[z][x] - M[x][z];
415 S[0][3] = M[x][y] - M[y][x];
417 S[1][1] = M[x][x] - M[y][y] - M[z][z];
418 S[1][2] = M[x][y] + M[y][x];
419 S[1][3] = M[z][x] + M[x][z];
422 S[2][2] = -M[x][x] + M[y][y] - M[z][z];
423 S[2][3] = M[y][z] + M[z][y];
427 S[3][3] = -M[x][x] - M[y][y] + M[z][z];
432 std::vector<icpvecandval> eigValues(vt.
GetRows());
436 for (
unsigned int i=0; i<vt.
GetRows(); i++) {
439 eigenimage = S * eigenvector;
442 t.
value = (float)(eigenimage * eigenvector);
466 std::cout <<
" rot : " << q << std::endl;
467 std::cout <<
" trans : " << cmod << std::endl;
473 for (
int i=0;i<9;i++) {
474 tmat[i] = (float)turn.
GetData()[i];
476 for (
int i=0;i<3;i++) {
477 tmat[9+i] = (float)(
centerA_-centerB_)[i];
479 for (
int i=0;i<3;i++) {
480 tmat[12+i] = (float)(centerB_)[i];
485 cout <<
"move" << endl;
487 cout <<
"release gl" << endl;
virtual BIAS::Vector3< double > GetC() const
Get projection center.
unsigned int datapointcnt_
int Compute(float nearestDistance, unsigned int numberOfPoints)
void GetEuclidean(Vector3< HOMGPOINT3D_TYPE > &dest) const
calculate affine coordinates of this and write them to dest affine coordinates are projective coordin...
BIAS::Camera< float > inDepth_
clfBuffer * CreateBuffer()
create buffer object
std::string AddSource(std::string filename)
adds source code from a file
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
unsigned int sizeofvertex_
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
BIAS::glfVertexBuffer modelPoints_
void * MapBuffer(bool write=false, unsigned int offset=0, unsigned int size=0)
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
virtual void SetR(const BIAS::RMatrix &R)
Set orientation from rotation matrix R.
BIAS::glfVertexBuffer dataPoints_
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual HomgPoint3D UnProjectToPoint(const HomgPoint2D &pos, double depth, bool IgnoreDistortion=false) const
calculates a 3D point in the global (not the rig) coordinate system, which belongs to the image posit...
unsigned int iterationCounter_
BIAS::Vector< double > vector
void SetZero()
set all values to 0
void AllocateFromVertexBuffer(BIAS::glfVertexBuffer &vbo, bool readonly=false, bool writeonly=false)
Allocation of a memory buffer from a GL vertexBuffer (works only on shared context!) ...
BIAS::glfVertexFormat vertexFormat_
void SetData(int num, float *data, int scale=1)
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
A vertex buffer contains an array of vertices that can be used for rendering.
void Unmap()
Unmaps the vertex buffer.
void UnDistortDepth(HomgPoint2D const &pos, float &d, bool bIsInCartesianCoords=false)
UnDistort depth value d at image position pos.
void * Map()
Maps the vertex buffer to system memory, so it can be modified after creation.
int Fuse(float nearestDistance)
void Create(int numVertices, const glfVertexFormat &format, const void *data=NULL, bool useBufferIfPossible=true)
Creates the vertex buffer for the given number of vertices and vertex format.
void Build(int deviceNr=0, std::string options="")
builds the sources added by AddSource and AddSourceFromString
void AcquireGLObject(clfMemory &buffer)
acquire a buffer allocated from opengl, call glfinish first!
BIAS::Vector3< double > centerB_
const std::string & GetDetailedString() const
detailed combination of all info available
clfProgram * CreateProgram()
create program object
static bool compareVectorByValue(icpvecandval a, icpvecandval b)
static bool comparePairByDistance(icppair a, icppair b)
int ComputeOptimalMotion_(BIAS::Vector3< double > &c, BIAS::RMatrix &R)
unsigned int SetModelFromDepthMap(const BIAS::Camera< float > depthMap, const BIAS::Camera< unsigned char > ampImage)
unsigned int GetRows() const
clfDeviceInfo GetDeviceInfo(unsigned int device=0)
clf Exception wrapper, is thrown in case of most clf errors
void Finish()
force finishing the command queue
const Matrix< double > & GetVT() const
return VT (=transposed(V))
BIAS::Camera< unsigned char > inTex_
void Allocate(unsigned int bufsize, bool readonly=false, bool writeonly=false, void *hostptr=NULL, bool copy=false)
Allocation of a memory buffer A memory buffer can be created on device or host, it can be initialized...
virtual BIAS::RMatrix GetR() const
Get orientation as rotation matrix R.
Vector< T > GetRow(const int &row) const
return a copy of row "row" of this matrix, zero based counting
unsigned int numberOfPoints_
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
void KernelSetArgument(std::string kernelname, unsigned int argnumber, clfBuffer &buffer)
set kernel argument
BIAS::ProjectionParametersBase * modelParams_
unsigned int * sortedidx_
void AddKernel(std::string kernelname)
adds a kernel to the program.
unsigned int * GetPermutation(unsigned int num=0)
unsigned int modelpointcnt_
void ReleaseGLObject(clfMemory &buffer)
release a buffer allocated from opengl, call Finish first!
int ComputeNearestPoints_(float nearestDistance, unsigned int numberOfPoints, float &res)
int InvertIP()
In place matrix conversion.
BIAS::ProjectionParametersBase * dataParams_
void DivideIP(const T &scalar)
Division (in place) of an scalar.
void RunOn1DRange(clfProgram &program, std::string kernelname, unsigned int globalrange, unsigned int localrange=0)
run a kernel on a 1D memory range
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
set elementwise with given 2 euclidean scalar values.
const BIAS::Projection & GetProj() const
ProjectionParametersBase * GetParameterCloneWithAbsolutePose(unsigned int cam=0) const
Allocates memory for parameters base type and returns pointer to it!
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
unsigned int SetDataFromDepthMap(const BIAS::Camera< float > depthMap, const BIAS::Camera< unsigned char > ampImage)
unsigned int maxIterations_
std::vector< icppair > pairs_
BIAS::Vector3< double > centerA_
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
unsigned int setFromDepthMap_(BIAS::glfVertexBuffer &buffer, const BIAS::Camera< float > depthMap, const BIAS::Camera< unsigned char > ampImage, bool keep=false, bool padData=false)