@@ -717,7 +717,7 @@ void SIFTMatchFilter::filterKeyPointMatchesDEBUG(unsigned int curFrame, SIFTImag
717717void SIFTMatchFilter::visualizeProjError (SIFTImageManager* siftManager,const vec2ui& imageIndices,const std::vector<CUDACachedFrame>& cachedFrames,
718718const float4x4& depthIntrinsics,const float4x4& transformCurToPrv,float depthMin,float depthMax)
719719{
720- #ifdef CUDACACHE_UCHAR_NORMALS
720+ #if defined( CUDACACHE_UCHAR_NORMALS) && !defined(CUDACACHE_FLOAT_NORMALS)
721721throw MLIB_EXCEPTION (" need to update to uchar4 normals" );
722722#else
723723const unsigned int numImages = siftManager->getNumImages ();
@@ -802,7 +802,7 @@ void SIFTMatchFilter::computeCorrespondencesDEBUG(unsigned int width, unsigned i
802802const float * modelDepth,const float4* model,const float4* modelNormals,const float * modelColor,const float4x4& transform,float distThres,float normalThres,float colorThresh,
803803const float4x4& depthIntrinsics,float depthMin,float depthMax,float & sumResidual,float & sumWeight,unsigned int & numCorr)
804804{
805- PointCloudf pcSrc, pcTgt;
805+ PointCloudf pcSrc, pcTgt, pcTransform; // debug vis
806806
807807s_debugCorr.allocate (width, height);
808808s_debugCorr.setPixels (-std::numeric_limits<float >::infinity ());
@@ -859,13 +859,14 @@ void SIFTMatchFilter::computeCorrespondencesDEBUG(unsigned int width, unsigned i
859859s_debugCorr (x, y) =length (pTransInput - pTarget);
860860pcSrc.m_points .push_back (vec3f (pTransInput.x , pTransInput.y , pTransInput.z ));
861861pcTgt.m_points .push_back (vec3f (pTarget.x , pTarget.y , pTarget.z ));
862+ vec4f debugColor =BaseImageHelper::convertDepthToRGBA (std::sqrt (x*x + y*y),0 .0f ,std::sqrt (width*width + height*height));// distance from top left
862863if (d > distThres) {
863- pcSrc.m_colors .push_back (vec4f (1 .0f ,0 .0f ,0 .0f ,1 .0f ));
864- pcTgt.m_colors .push_back (vec4f (0 .0f ,1 .0f ,0 .0f ,1 .0f ));
864+ pcSrc.m_colors .push_back (vec4f (0 . 5f , 0 . 5f , 0 . 5f , 1 . 0f )); // vec4f( 1.0f, 0.0f, 0.0f, 1.0f));
865+ pcTgt.m_colors .push_back (vec4f (0 .5f , 0 . 5f , 0 . 5f , 1 . 0f )); // (vec4f(0. 0f, 1.0f, 0.0f, 1.0f));
865866}
866867else {
867- pcSrc.m_colors .push_back (vec4f (cInput));
868- pcTgt.m_colors .push_back (vec4f (cTarget));
868+ pcSrc.m_colors .push_back (debugColor); // vec4f(cInput));
869+ pcTgt.m_colors .push_back (debugColor); // vec4f(cTarget));
869870}
870871}
871872}// target depth within depth min/max
@@ -882,3 +883,127 @@ void SIFTMatchFilter::computeCorrespondencesDEBUG(unsigned int width, unsigned i
882883// getchar();
883884int a =5 ;
884885}
886+
887+ void SIFTMatchFilter::debugVis (const SensorData& sd,const vec2ui& imageIndices,const mat4f& transform,unsigned int subsampleFactor/* = 4*/ )
888+ {
889+ const unsigned int width = sd.m_depthWidth ;
890+ const unsigned int height = sd.m_depthHeight ;
891+ const float distThres =0 .15f ;const float normalThres =0 .97f ;
892+ const float depthMin =0 .4f ;const float depthMax =4 .0f ;
893+
894+ PointCloudf pcSrc, pcTgt, pcTransform;// debug vis
895+ PointCloudf pcSrcColor, pcTgtColor, pcTransformColor;// debug vis
896+
897+ const mat4f depthIntrinsic = sd.m_calibrationDepth .m_intrinsic ;
898+ const mat4f depthIntrinsicInv = depthIntrinsic.getInverse ();
899+ DepthImage32 curDepth = sd.computeDepthImage (imageIndices.y );
900+ DepthImage32 prvDepth = sd.computeDepthImage (imageIndices.x );
901+ PointImage curCamPos = sd.computeCameraSpacePositions (depthIntrinsicInv, curDepth);
902+ PointImage prvCamPos = sd.computeCameraSpacePositions (depthIntrinsicInv, prvDepth);
903+ PointImage curNormal = sd.computeNormals (curCamPos);
904+ PointImage prvNormal = sd.computeNormals (prvCamPos);
905+
906+ ColorImageR8G8B8 curColor = sd.computeColorImage (imageIndices.y );
907+ ColorImageR8G8B8 prvColor = sd.computeColorImage (imageIndices.x );
908+
909+ Grid2<bool >marker (width, height); marker.setValues (false );
910+
911+ const float INVALID = -std::numeric_limits<float >::infinity ();
912+ for (unsigned int y =0 ; y < height; y += subsampleFactor) {
913+ for (unsigned int x =0 ; x < width; x += subsampleFactor) {
914+
915+ const vec3f pInput =curCamPos (x, y);
916+ const vec3f nInput =curNormal (x, y);
917+ float dInput =curDepth (x, y);
918+ const vec3uc& cInput =curColor (x, y);
919+
920+ if (pInput.x != INVALID && nInput.x != INVALID && dInput >= depthMin && dInput <= depthMax) {
921+ const vec3f pTransInput = transform * pInput;
922+ const vec3f nTransInput = transform.getRotation () * nInput;
923+
924+ vec2f screenPosf =cameraToDepth (depthIntrinsic, pTransInput);
925+ vec2i screenPos =math::round (screenPosf);
926+
927+ if (screenPos.x >=0 && screenPos.y >=0 && screenPos.x < (int )width && screenPos.y < (int )height) {
928+ vec3f pTarget; vec3f nTarget; vec3uc cTarget;
929+ getBestCorrespondence1x1 (screenPos, pTarget, nTarget, cTarget, prvCamPos, prvNormal, prvColor);
930+
931+ if (pTarget.x != INVALID && nTarget.x != INVALID) {
932+ float d =vec3f::dist (pTransInput, pTarget);
933+ float dNormal = nTransInput | nTarget;
934+
935+ float projInputDepth = pTransInput.z ;// cameraToDepthZ(pTransInput);
936+ float tgtDepth =prvDepth (screenPos.x , screenPos.y );
937+
938+ marker ((screenPos.x /subsampleFactor)*subsampleFactor, (screenPos.y /subsampleFactor)*subsampleFactor) =true ;
939+ if (tgtDepth >= depthMin && tgtDepth <= depthMax) {
940+ bool b = ((tgtDepth != INVALID && projInputDepth < tgtDepth) && d > distThres);// bad matches that are known
941+ if ((dNormal >= normalThres && d <= distThres/* && c <= colorThresh*/ ) || b) {// if normal/pos/color correspond or known bad match
942+
943+ pcSrc.m_points .push_back (pTransInput);
944+ pcTgt.m_points .push_back (pTarget);
945+ pcSrcColor.m_points .push_back (pTransInput);
946+ pcTgtColor.m_points .push_back (pTarget);
947+ vec4f debugColor =BaseImageHelper::convertDepthToRGBA (std::sqrt (x*x + y*y),0 .0f ,std::sqrt (width*width + height*height));// distance from top left
948+ if (d > distThres) {
949+ pcSrc.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));// vec4f(1.0f, 0.0f, 0.0f, 1.0f));
950+ pcTgt.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));// (vec4f(0.0f, 1.0f, 0.0f, 1.0f));
951+ pcSrcColor.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
952+ pcTgtColor.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
953+ }
954+ else {
955+ pcSrc.m_colors .push_back (debugColor);// vec4f(cInput));
956+ pcTgt.m_colors .push_back (debugColor);// vec4f(cTarget));
957+ pcSrcColor.m_colors .push_back (vec4f (vec3f (cInput)/255 .0f ));
958+ pcTgtColor.m_colors .push_back (vec4f (vec3f (cTarget)/255 .0f ));
959+ }
960+ }
961+ }// target depth within depth min/max
962+ }// projected to valid depth
963+ }// inside image
964+ else {
965+ pcSrc.m_points .push_back (pTransInput);
966+ pcSrc.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
967+ pcSrcColor.m_points .push_back (pTransInput);
968+ pcSrcColor.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
969+ }
970+ }
971+ }// x
972+ }// y
973+
974+ for (unsigned int y =0 ; y < height; y += subsampleFactor) {
975+ for (unsigned int x =0 ; x < width; x += subsampleFactor) {
976+ if (!marker (x, y)) {
977+ const vec3f& pTarget =prvCamPos (x, y);
978+ pcTgt.m_points .push_back (pTarget);
979+ pcTgt.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
980+ pcTgtColor.m_points .push_back (pTarget);
981+ pcTgtColor.m_colors .push_back (vec4f (0 .5f ,0 .5f ,0 .5f ,1 .0f ));
982+ }
983+ }
984+ }
985+
986+ // PointCloudIOf::saveToFile("debug/src.ply", pcSrc);
987+ // PointCloudIOf::saveToFile("debug/tgt.ply", pcTgt);
988+ // PointCloudIOf::saveToFile("debug/src-color.ply", pcSrcColor);
989+ // PointCloudIOf::saveToFile("debug/tgt-color.ply", pcTgtColor);
990+
991+ MeshDataf mdSrc, mdTgt, mdSrcColor, mdTgtColor;
992+ unsigned int numSlice =8 ;
993+ for (unsigned int i =0 ; i < pcSrc.m_points .size (); i++)
994+ mdSrc.merge (Shapesf::sphere (0 .01f , pcSrc.m_points [i], numSlice, numSlice, pcSrc.m_colors [i]).computeMeshData ());
995+ MeshIOf::saveToFile (" debug/m_src.ply" , mdSrc);
996+ for (unsigned int i =0 ; i < pcTgt.m_points .size (); i++)
997+ mdTgt.merge (Shapesf::sphere (0 .01f , pcTgt.m_points [i], numSlice, numSlice, pcTgt.m_colors [i]).computeMeshData ());
998+ MeshIOf::saveToFile (" debug/m_tgt.ply" , mdTgt);
999+ for (unsigned int i =0 ; i < pcSrcColor.m_points .size (); i++)
1000+ mdSrcColor.merge (Shapesf::sphere (0 .01f , pcSrcColor.m_points [i], numSlice, numSlice, pcSrcColor.m_colors [i]).computeMeshData ());
1001+ MeshIOf::saveToFile (" debug/m_src-color.ply" , mdSrcColor);
1002+ for (unsigned int i =0 ; i < pcTgtColor.m_points .size (); i++)
1003+ mdTgtColor.merge (Shapesf::sphere (0 .01f , pcTgtColor.m_points [i], numSlice, numSlice, pcTgtColor.m_colors [i]).computeMeshData ());
1004+ MeshIOf::saveToFile (" debug/m_tgt-color.ply" , mdTgtColor);
1005+
1006+ // std::cout << "press key" << std::endl;
1007+ // getchar();
1008+ int a =5 ;
1009+ }