/** sort the edges into left and right edge lists, then evaluate edge lists */ void SceneCuller::setVisibleExtrema() { // find indices of lowest & hightest y value // and therefor indices of first right edge and first left edge const size_t &n = visiblePoly.size(); int ndx_min_y = -1, min_y = numeric_limits<int>::max(), ndx_max_y = -1, max_y = -1; int i; for (i=0; i < n; ++i) { Vec2i pt((int)visiblePoly[i].x, (int)visiblePoly[i].y); if (pt.y < min_y) { min_y = pt.y; ndx_min_y = i; } if (pt.y > max_y) { max_y = pt.y; ndx_max_y = i; } } // build left and right edge lists vector<Edge> leftEdges, rightEdges; for (i = ndx_min_y; i != ndx_max_y; ++i, i %= n) { Vec2i pt0((int)visiblePoly[i % n].x, (int)visiblePoly[i % n].y); Vec2i pt1((int)visiblePoly[(i + 1) % n].x, (int)visiblePoly[(i + 1) % n].y); if (pt0.y < pt1.y) { rightEdges.push_back(Edge(pt0, pt1)); } } for ( ; i != ndx_min_y; ++i, i %= n) { Vec2i pt0((int)visiblePoly[i % n].x, (int)visiblePoly[i % n].y); Vec2i pt1((int)visiblePoly[(i + 1) % n].x, (int)visiblePoly[(i + 1) % n].y); if (pt0.y > pt1.y) { // edge from pt1 to pt0 ... leftEdges.push_back(Edge(pt1, pt0)); // line algorithm needs first.y < second.y } } if (leftEdges.empty() || rightEdges.empty()) { // invalidate and bail, nothing visible cellExtrema.invalidate(); tileExtrema.invalidate(); return; } // assert sanity assert(leftEdges.back().first.y == rightEdges.front().first.y); assert(leftEdges.front().second.y == rightEdges.back().second.y); // set extrema cellExtrema.reset(min_y, max_y); tileExtrema.reset(min_y / 2,max_y / 2); activeEdge = Left; setVisibleExtrema(leftEdges.rbegin(), leftEdges.rend()); activeEdge = Right; setVisibleExtrema(rightEdges.begin(), rightEdges.end()); }
TEST_F(CreatePolygonTreesTest, P0AndP1AndP2AndP3) { GeoLib::SimplePolygonTree *pt0(new GeoLib::SimplePolygonTree(_p0, nullptr)); GeoLib::SimplePolygonTree *pt1(new GeoLib::SimplePolygonTree(_p1, nullptr)); GeoLib::SimplePolygonTree *pt2(new GeoLib::SimplePolygonTree(_p2, nullptr)); GeoLib::SimplePolygonTree *pt3(new GeoLib::SimplePolygonTree(_p3, nullptr)); std::list<GeoLib::SimplePolygonTree*> pt_list; pt_list.push_back(pt0); pt_list.push_back(pt1); pt_list.push_back(pt2); pt_list.push_back(pt3); ASSERT_EQ(4u, pt_list.size()); ASSERT_FALSE(_p0->isPolylineInPolygon(*_p1)); ASSERT_FALSE(_p0->isPolylineInPolygon(*_p2)); ASSERT_FALSE(_p1->isPolylineInPolygon(*_p0)); ASSERT_FALSE(_p1->isPolylineInPolygon(*_p2)); ASSERT_TRUE(_p2->isPolylineInPolygon(*_p0)); ASSERT_TRUE(_p2->isPolylineInPolygon(*_p1)); ASSERT_TRUE(_p2->isPolylineInPolygon(*_p3)); ASSERT_TRUE(_p1->isPolylineInPolygon(*_p3)); createPolygonTrees(pt_list); ASSERT_EQ(1u, pt_list.size()); ASSERT_EQ(2u, (*(pt_list.begin()))->getNChilds()); std::for_each(pt_list.begin(), pt_list.end(), std::default_delete<GeoLib::SimplePolygonTree>()); }
void CatmullRomCurveEvaluator::pushPoints(std::vector<Point>& ptvEvaluatedCurvePts, std::vector<Point>& pts, const float& fAniLength) const { // contruct the P vectors const Vec4d Px(pts[0].x, pts[1].x, pts[2].x, pts[3].x); const Vec4d Py(pts[0].y, pts[1].y, pts[2].y, pts[3].y); // pushing the points ptvEvaluatedCurvePts.push_back(pts[0]); ptvEvaluatedCurvePts.push_back(pts[3]); for (int j = 0; j < 50; j++) { // draw 50 points double t = j / 50.0; Vec4d T0(1, t - 0.01, (t - 0.01) * (t - 0.01), (t - 0.01) * (t - 0.01) * (t - 0.01)); Point pt0(T0 * M * Px, T0 * M * Py); Vec4d T(1, t, t * t, t * t * t); Point ptOnCurve(T * M * Px, T * M * Py); Vec4d T1(1, t + 0.01, (t + 0.01) * (t + 0.01), (t + 0.01) * (t + 0.01) * (t + 0.01)); Point pt1(T1 * M * Px, T1 * M * Py); if (fAniLength > 0.001f) { if (ptOnCurve.x > fAniLength) // point out of screen ptOnCurve.x = ptOnCurve.x - fAniLength; ptvEvaluatedCurvePts.push_back(ptOnCurve); } else { if (ptOnCurve.x < pts[3].x && ptOnCurve.x > pts[0].x && ((ptOnCurve.x - pt0.x) > 0.01) && ((pt1.x - ptOnCurve.x) > 0.01)) ptvEvaluatedCurvePts.push_back(ptOnCurve); } } }
TEST_F(CreatePolygonTreesTest, P0AndP1) { GeoLib::SimplePolygonTree *pt0(new GeoLib::SimplePolygonTree(_p0, nullptr)); GeoLib::SimplePolygonTree *pt1(new GeoLib::SimplePolygonTree(_p1, nullptr)); std::list<GeoLib::SimplePolygonTree*> pt_list; pt_list.push_back(pt0); pt_list.push_back(pt1); ASSERT_EQ(2u, pt_list.size()); createPolygonTrees(pt_list); ASSERT_EQ(2u, pt_list.size()); std::for_each(pt_list.begin(), pt_list.end(), std::default_delete<GeoLib::SimplePolygonTree>()); }
double SurfaceOverlapFacet::perimeter() { CubitVector pt0( t.b.x, t.b.y, t.b.z ); CubitVector pt1( t.b.x + t.e0.x, t.b.y + t.e0.y, t.b.z + t.e0.z ); CubitVector pt2( t.b.x + t.e1.x, t.b.y + t.e1.y, t.b.z + t.e1.z ); double total_dist = pt0.distance_between(pt1); total_dist += pt1.distance_between( pt2 ); total_dist += pt2.distance_between( pt0 ); return total_dist; }
void CGuideRectODL::GetTopPointList( std::vector<gp_Pnt>& arrPoint ) { m_arrTopPoint.clear(); //如果开始点大于结束点 Gdiplus::REAL fX0 = m_rtArea.GetLeft(); Gdiplus::REAL fY0 = m_rtArea.GetTop(); Gdiplus::REAL fX1 = m_rtArea.GetRight(); Gdiplus::REAL fY1 = m_rtArea.GetBottom(); gp_Pnt pt0(fX0, 0, fY0); gp_Pnt pt1(fX1, 0, fY0); gp_Pnt pt2(fX1, 0, fY1); gp_Pnt pt3(fX0, 0, fY1); m_arrTopPoint.push_back(pt0); m_arrTopPoint.push_back(pt1); m_arrTopPoint.push_back(pt2); m_arrTopPoint.push_back(pt3); m_arrTopPoint.push_back(pt0); arrPoint = m_arrTopPoint; }
// protected: BOOL COXSplashWnd::BuildRegion(POINT ptStart) // --- In : ptStart, the starting point to search for region boundary // --- Out : // --- Returns : TRUE if successful; FALSE otherwise // --- Effect : calculate the region to be visible in a bitmap { CArray<CPoint, CPoint&> vertexs; CPoint ptMax(0,0); CPoint pt0(0,0); CPoint pt1(0,0); CPoint pt(0,0); CPoint ptPrev(0,0); CSize sizeInc(0,0); int i = 0; int iFirst = 0; int iLast = 0; int iPrev = 0; // move directions: index (xInc, yInc) alternate_index // 0 (-1,-1) 8 1 ( 0,-1) 9 2 ( 1,-1) 10 // 7 (-1, 0) 15 3 ( 1, 0) 11 // 6 (-1, 1) 14 5 ( 0, 1) 13 4 ( 1, 1) 12 const int xd[] = {-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1}; const int yd[] = {-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0}; const int nextdir[] = {6,0,0,2,2,4,4,6,6,0,0,2,2,4,4,6}; BITMAP bm; m_dib.GetBitmapInfo(bm); ptMax = CPoint(bm.bmWidth - 1, bm.bmHeight - 1); // find a start point that's outside the region UNREFERENCED_PARAMETER(ptStart); pt0 = CPoint(0,0); if (!IsBorder(pt0)) pt0 = CPoint(-1,-1); // search diagonally for first point that's within the region sizeInc.cx = (pt0.x > (ptMax.x / 2)) ? -1 : 1; sizeInc.cy = (pt0.y > (ptMax.y / 2)) ? -1 : 1; for (pt1 = pt0 + sizeInc; IsBorder(pt1, FALSE); pt1 += sizeInc) ; pt0 = pt1 - sizeInc; // if not found after hitting the boundary, search by scan lines if (m_dib.GetPixel(pt1) == CLR_INVALID) { for (pt1.y = 0; pt1.y <= ptMax.y; pt1.y++) { for (pt1.x = 0; pt1.x <= ptMax.x && IsBorder(pt1); pt1.x++) ; if (pt1.x <= ptMax.x) break; } if (ptMax.y < pt1.y) return FALSE; pt0 = pt1 - CSize(0, 1); } // now pt1 should be the starting point that's within the region // and pt0 should be a neigboring point that's outside the region ASSERT(IsBorder(pt0) && !IsBorder(pt1)); // clockwise find border/region boundary for (i = 0; i <= 7; i++) { pt = pt1 + CSize(xd[i], yd[i]); if (!IsBorder(pt)) break; } if (i == 8) return FALSE; // important: assign second point as the start point to prevent // diagonal circumvent pt1 = pt; vertexs.Add(pt); // cycle until the most beginning point is found back again do { iPrev = i; ptPrev = pt; iFirst = nextdir[i]; iLast = iFirst + 6; for (i = iFirst; i <= iLast; i++) { pt = ptPrev + CSize(xd[i], yd[i]); if (!IsBorder(pt)) break; } if (i == iPrev) { // moving forward on the same direction // replace the last point with this new one, so that region // definition could be simpler vertexs[vertexs.GetSize()-1] = pt; } else { // direction changed, has to add a new vertex vertexs.Add(pt); } if(vertexs.GetSize()%3000==0) TRACE(_T("Add point: %d,%d, number %d\n"),pt.x,pt.y,vertexs.GetSize()); } while (pt != pt1); m_rgn.DeleteObject(); if (!m_rgn.CreatePolygonRgn(vertexs.GetData(), PtrToInt(vertexs.GetSize()), ALTERNATE)) { ASSERT((HRGN)m_rgn == NULL); return FALSE; } return TRUE; }
int main(int argc, char* argv[]) { DPOINT pt0(0, 0), pt1(0, 1); double dx = pt0.x - pt1.x; double dy = pt0.y - pt1.y; double alfa = atan2(dx, dy); double alf1 = atan2(dy, dx); double alf2 = pt0.angdir(pt1); double alf3 = pt0.angdir2(pt1); DSM_Factory* df = new DSM_Factory; if ( df->Open("C:/Google_drive/Regione Toscana Tools/Dati_test/prova2/cast-pescaia_50.asc", false) ) { std::cout << "start 2\n"; DSM* ds = df->GetDsm(); std::cout << "start 3 \n"; std::cout << "start 4 " << ds->Npt() << "\n"; } //test_orto("586000-4883000"); std::cout << "fatto\n"; ProjTransform pjt(_utm32_, _igm249_); double x = 586075; //679057.013 double y = 4883013; //4851590.576 double z = 445.54; //399.850 //99.326 pjt.transform(&x, &y, &z); //test_overground("586000-4883000"); //test_mds("586000-4883000"); //long d1 = GetTickCount(); //DSM_Factory df1; //df1.SetEcho(0); // c'è un solo impulso //df1.SetMask(File_Mask(5, 1, 2, 3, 0, 0)); //if ( !df1.Open("I:/2012Lidar/2Consegnato-da-cgr/OVERGROUND/overground586000-4883000.xyzic", false) ) // return 0; //DSM* ds1 = df1.GetDsm(); //unsigned int n1 = ds1->Npt(); //long d2 = GetTickCount(); //printf("Lettura overground : %.3ld\n", (d2 - d1) ); //DSM_Factory df2; //df2.SetEcho(1); // primo impulso //df2.SetMask(File_Mask(11, 3, 4, 5, 9, 10)); //if ( !df2.Open("I:/2012Lidar/2Consegnato-da-cgr/DATI_GREZZI/dati_grezzi586000-4883000.all", false) ) // return 0; //DSM* ds2 = df2.GetDsm(); //unsigned int n2 = ds2->Npt(); //long d3 = GetTickCount(); //printf("Lettura raw %.3ld\n", (d3 - d2) ); //long count_in = 0; //long count_out = 0; //for (int i = 0; i < n1; i++ ) { // double x = ds1->GetX(i); // double y = ds1->GetY(i); // double z = ds1->GetZ(i); // double dz = ds2->GetQuota(x, y) - z; // if ( dz > 0.5 ) // count_out++; // else // count_in++; //} //printf("raw=%ld punti\n", n2); //printf("overgrounf=%ld punti\n", n1); //printf("entro 0.5 %ld\n", count_in); //printf("oltre 0.5 %ld\n", count_out); //int a = 1; return 0; }
//vectormath makes a difference between point and vector. void VectormathTest() { printf("Vectormath\n"); Vectormath::Aos::Transform3 tr; tr = Vectormath::Aos::Transform3::identity(); tr.setTranslation(Vectormath::Aos::Vector3(10,0,0)); //initialization Vectormath::Aos::Point3 pointA(0,0,0); Vectormath::Aos::Point3 pointB,pointC,pointE; Vectormath::Aos::Vector3 pointD; //assignment pointB = pointA; //in-place initialization pointB = Vectormath::Aos::Point3(1,2,3); //or pointB.setElem(0,1); //or pointB.setX(1); //transform over tr pointB = tr * pointA; printf("pointB = tr * pointA = (%f,%f,%f)\n",(float)pointB.getX(),(float)pointB.getY(),(float)pointB.getZ()); //transform over tr //pointE = tr(pointA); //inverse transform pointC = Vectormath::Aos::inverse(tr) * pointA; printf("Vectormath::Aos::inverse(tr) * pointA = (%f,%f,%f)\n",(float)pointC.getX(),(float)pointC.getY(),(float)pointC.getZ()); btScalar x; //dot product x = Vectormath::Aos::dot(Vectormath::Aos::Vector3(pointD),Vectormath::Aos::Vector3(pointE)); //square length x = Vectormath::Aos::lengthSqr(Vectormath::Aos::Vector3(pointD)); //length x = Vectormath::Aos::length(Vectormath::Aos::Vector3(pointD)); const Vectormath::Aos::Vector3& constPointD = (Vectormath::Aos::Vector3&)pointD; //get a normalized vector from constPointD, without changing constPointD Vectormath::Aos::Vector3 norm = Vectormath::Aos::normalize(constPointD); //in-place normalize pointD pointD = Vectormath::Aos::normalize(Vectormath::Aos::Vector3(pointD)); //quaternions & matrices Vectormath::Aos::Quat quat(0,0,0,1); Vectormath::Aos::Quat quat1; quat1 = Vectormath::Aos::Quat::rotationY(90.f * SIMD_RADS_PER_DEG); Vectormath::Aos::Matrix3 mat0(quat1); Vectormath::Aos::Matrix3 mat1 = Vectormath::Aos::inverse(mat0); Vectormath::Aos::Matrix3 mat2 = Vectormath::Aos::transpose(mat0); Vectormath::Aos::Transform3 tr1(mat2,Vectormath::Aos::Vector3(0,10,0)); Vectormath::Aos::Transform3 tr2 = Vectormath::Aos::inverse(tr1); Vectormath::Aos::Point3 pt0(1,1,1); Vectormath::Aos::Point3 pt1 = tr2 * pt0; printf("Vectormath::Aos::Vector3 pt1 = tr2 * pt0; = (%f,%f,%f)\n",(float)pt1.getX(),(float)pt1.getY(),(float)pt1.getZ()); Vectormath::Aos::Vector3 pt2 = tr2.getUpper3x3() * Vectormath::Aos::Vector3(pt0); //Vectormath::Aos::Vector3 pt3 = pt0 * tr2.getUpper3x3(); Vectormath::Aos::Vector3 pt3 = Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0); Vectormath::Aos::Vector3 pt4 = Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0); Vectormath::Aos::Transform3 tr3 = Vectormath::Aos::inverse(tr2) * tr2; }
//Bullet, a btVector can be used for both points and vectors. //it is up to the user/developer to use the right multiplication: btTransform for points, and btQuaternion or btMatrix3x3 for vectors. void BulletTest() { printf("Bullet Linearmath\n"); btTransform tr; tr.setIdentity(); tr.setOrigin(btVector3(10,0,0)); //initialization btVector3 pointA(0,0,0); btVector3 pointB,pointC,pointD,pointE; //assignment pointB = pointA; //in-place initialization pointB.setValue(1,2,3); //transform over tr pointB = tr * pointA; printf("pointB = tr * pointA = (%f,%f,%f)\n",pointB.getX(),pointB.getY(),pointB.getZ()); //transform over tr pointE = tr(pointA); //inverse transform pointC = tr.inverse() * pointA; printf("pointC = tr.inverse() * pointA = (%f,%f,%f)\n",pointC.getX(),pointC.getY(),pointC.getZ()); //inverse transform pointD = tr.invXform( pointA ); btScalar x; //dot product x = pointD.dot(pointE); //square length x = pointD.length2(); //length x = pointD.length(); const btVector3& constPointD = pointD; //get a normalized vector from constPointD, without changing constPointD btVector3 norm = constPointD.normalized(); //in-place normalize pointD pointD.normalize(); //quaternions & matrices btQuaternion quat(0,0,0,1); btQuaternion quat1(btVector3(0,1,0),90.f * SIMD_RADS_PER_DEG); btMatrix3x3 mat0(quat1); btMatrix3x3 mat1 = mat0.inverse(); btMatrix3x3 mat2 = mat0.transpose(); btTransform tr1(mat2,btVector3(0,10,0)); btTransform tr2 =tr1.inverse(); btVector3 pt0(1,1,1); btVector3 pt1 = tr2 * pt0; printf("btVector3 pt1 = tr2 * pt0 = (%f,%f,%f)\n",pt1.getX(),pt1.getY(),pt1.getZ()); btVector3 pt2 = tr2.getBasis() * pt0; btVector3 pt3 = pt0 * tr2.getBasis(); btVector3 pt4 = tr2.getBasis().inverse() * pt0; btTransform tr3 = tr2.inverseTimes(tr2); }
void test_RT() { typedef RT Cls; // _test_cls_regular_3( Cls() ); typedef traits::Bare_point Point; typedef traits::Weighted_point Weighted_point; typedef typename Cls::Vertex_handle Vertex_handle; typedef typename Cls::Cell_handle Cell_handle; typedef typename Cls::Facet Facet; typedef typename Cls::Edge Edge; typedef std::list<Weighted_point> list_point; typedef typename Cls::Finite_cells_iterator Finite_cells_iterator; // temporary version int n, m; int count = 0; // For dimension 0, we need to check that the point of highest weight is the // one that finally ends up in the vertex. std::cout << " test dimension 0 " << std::endl; Cls T0; T0.insert(Weighted_point( Point (0,0,0), 0) ); T0.insert(Weighted_point( Point (0,0,0), 1) ); T0.insert(Weighted_point( Point (0,0,0), -1) ); assert(T0.dimension() == 0); assert(T0.number_of_vertices() == 1); assert(T0.finite_vertices_begin()->point().weight() == 1); std::cout << " test dimension 1 " << std::endl; Cls T1; std::cout << " number of inserted points : " ; Weighted_point p[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) p[m] = Weighted_point( Point( 2*m,0,0 ), 2 ); else p[m] = Weighted_point( Point( -2*m+1,0,0 ), 2 ); T1.insert( p[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point q[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) q[m] = Weighted_point( Point( 2*m+1,0,0 ), 5 ); else q[m] = Weighted_point( Point( -2*m+1,0,0 ), 5 ); T1.insert( q[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point r[10]; for ( m=0; m<10; m++) { if ( (m%2)== 0 ) r[m] = Weighted_point( Point( m,0,0 ), 1 ); else r[m] = Weighted_point( Point( -m,0,0 ), 1 ); T1.insert( r[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; assert( T1.dimension()==1 ); // The following is distilled from a bug report by Wulue Zhao // ([email protected]), a student of Tamal Dey. Point pt0(0,0,0); Point pt1( 1,0,0), pt2(2,0,0), pt3(3,0,0); Point pt4(-1,0,0), pt5(-2,0,0), pt6(-3,0,0); Weighted_point wp0(pt0,10.0); Weighted_point wp1(pt1,0.0), wp2(pt2,0.0), wp3(pt3,0.0); Weighted_point wp4(pt4,0.0), wp5(pt5,0.0), wp6(pt6,0.0); Cls T11; T11.insert(wp0); T11.insert(wp1); T11.insert(wp2); T11.insert(wp3); T11.insert(wp4); T11.insert(wp5); T11.insert(wp6); assert(T11.is_valid()); // And another distilled bug report from the same guy. { Point p1(-0.07, 0.04, 0.04); Point p2(0.09, 0.04, 0.04); Point p3(0.09, -0.05, 0.04); Point p4(0.05, -0.05, 0.04); Point p5(0.05, 0.0, 0.04); Point p6(-0.07, 0.0, 0.04); Point p7(-0.07, 0.04, -0.04); Point p8(0.09, 0.04, -0.04); Point p9(0.09, -0.05, -0.04); Point p10(0.05, -0.05, -0.04); Point p11(0.05, 0.0, -0.04); Point p12(-0.07, 0.0, -0.04); Weighted_point wp1(p1,0); Weighted_point wp2(p2,0); Weighted_point wp3(p3,0); Weighted_point wp4(p4,0); Weighted_point wp5(p5,0); Weighted_point wp6(p6,0); Weighted_point wp7(p7,0); Weighted_point wp8(p8,0); Weighted_point wp9(p9,0); Weighted_point wp10(p10,0); Weighted_point wp11(p11,0); Weighted_point wp12(p12,0); Weighted_point wp13(p3,0.3); // wp13 has the same coordinates with wp3 Cls T111; T111.insert(wp1); T111.insert(wp2); T111.insert(wp3); T111.insert(wp13); // it doesnot work inserting wp13 here T111.insert(wp4); T111.insert(wp5); T111.insert(wp6); T111.insert(wp7); T111.insert(wp8); T111.insert(wp9); T111.insert(wp10); T111.insert(wp11); T111.insert(wp12); assert(T111.is_valid()); } std::cout << " test dimension 2 " << std::endl; std::cout << " number of inserted points : " ; Cls T2; count = 0 ; int px=1, py=1; int qx=-1, qy=2; Weighted_point s[400]; for (m=0; m<10; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=0; m<10; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -2 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 5 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } std::cout << std::endl << " number of vertices : " << T2.number_of_vertices() << std::endl; assert( T2.dimension()==2 ); assert( T2.is_valid() ); // dimension 3 std::cout << " test dimension 3" << std::endl; Cls T; list_point lp; int a, b, d; for (a=0;a!=10;a++) // for (b=0;b!=10;b++) for (b=0;b!=5;b++) // for (d=0;d!=10;d++) for (d=0;d!=5;d++) lp.push_back(Weighted_point( Point(a*b-d*a + (a-b)*10 +a , a-b+d +5*b, a*a-d*d+b), a*b-a*d) ); list_point::iterator it; count = 0 ; std::cout << " number of inserted points : " ; for (it=lp.begin(); it!=lp.end(); ++it){ count++; T.insert(*it); if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else if (count < 1000) std::cout << count << '\b' << '\b' << '\b' ; else std::cout << count << std::endl; std::cout.flush(); } std::cout << std::endl; std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); T.clear(); std::cout << " test iterator range insert" << std::endl; T.insert (lp.begin(), lp.end()); std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); //test nearest_power_vertex std::cout << " test nearest_power_vertex " << std::endl; Point pp1(0.0, 0.0, 0.0); Point pp2(1.0, 0.0, 0.0); Point pp3(0.0, 1.0, 0.0); Point pp4(0.0, 0.0, 1.0); Point pp5(1.0, 1.0, 0.0); Point pp6(0.0, 1.0, 1.0); Point pp7(1.0, 0.0, 1.0); Point pp8(1.0, 1.0, 1.0); Weighted_point wpp1(pp1, 1.0); Weighted_point wpp2(pp2, 2.0); Weighted_point wpp3(pp3, 1.0); Weighted_point wpp4(pp4, 4.0); Weighted_point wpp5(pp5, 1.0); Weighted_point wpp6(pp6, 1.0); Weighted_point wpp7(pp7, 1.0); Weighted_point wpp8(pp8, 8.0); Cls T3; T3.insert(wpp1); Vertex_handle v2 = T3.insert(wpp2); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v2); T3.insert(wpp3); Vertex_handle v4 = T3.insert(wpp4); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v4); T3.insert(wpp5); T3.insert(wpp6); T3.insert(wpp7); // Avoid inserting the same point twice, now that hidden points are handled, // insert (existing_point) returns Vertex_handle(). // T3.insert(wpp8); Vertex_handle v8 = T3.insert(wpp8); Point query(0.5,0.5,0.5); assert(T3.nearest_power_vertex(query) == v8); assert(T3.nearest_power_vertex(Weighted_point(query,1.0)) == v8 ); assert(T3.nearest_power_vertex_in_cell(query ,v8->cell()) == v8); // test dual std::cout << " test dual member functions" << std::endl; Finite_cells_iterator fcit = T3.finite_cells_begin(); for( ; fcit != T3.finite_cells_end(); ++fcit) { Point cc = T3.dual(fcit); Vertex_handle ncc = T3.nearest_power_vertex(cc); assert(fcit->has_vertex(ncc)); } // test Gabriel std::cout << " test is_Gabriel " << std::endl; Point q0(0.,0.,0.); Point q1(2.,0.,0.); Point q2(0.,2.,0.); Point q3(0.,0.,2.); Weighted_point wq0(q0,0.); Weighted_point wq1(q1,0.); Weighted_point wq2(q2,0.); Weighted_point wq3(q3,0.); Weighted_point wq01(q0,2.); Cls T4; Vertex_handle v0 = T4.insert(wq0); Vertex_handle v1 = T4.insert(wq1); v2 = T4.insert(wq2); Vertex_handle v3 = T4.insert(wq3); Cell_handle c; int i,j,k,l; assert(T4.is_facet(v0,v1,v2,c,j,k,l)); i = 6 - (j+k+l); Facet f = std::make_pair(c,i); assert(T4.is_Gabriel(c,i)); assert(T4.is_Gabriel(f)); assert(T4.is_facet(v1,v2,v3,c,j,k,l)); i = 6 - (j+k+l); assert(!T4.is_Gabriel(c,i)); assert(T4.is_edge(v0,v1,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Edge e = make_triple(c,i,j); assert(T4.is_Gabriel(e)); assert(T4.is_edge(v2,v3,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Vertex_handle v01 = T4.insert(wq01); (void) v01; // kill warning assert(T4.is_edge(v2,v3,c,i,j)); assert(!T4.is_Gabriel(c,i,j)); Weighted_point wwq0(q0,0.); Weighted_point wwq1(q1,0.); Weighted_point wwq2(q2,0.); Weighted_point wwq3(q3,5.); Cls T5; v0 = T5.insert(wwq0); v1 = T5.insert(wwq1); v2 = T5.insert(wwq2); v3 = T5.insert(wwq3); assert(T5.nearest_power_vertex(v3->point().point()) == v3); assert(T5.nearest_power_vertex(v0->point().point()) == v3); assert(T5.is_Gabriel(v3)); assert(!T5.is_Gabriel(v0)); }
void LALRParser::build() { LR0ItemCollectionFamily LR0Family; LR0Family.build(); map<LR1Point, set<int> > point2Terms; map<LR1Point, set<LR1Point> > point2Points; set<LR1Point> unhandled; for (int state = 0; state < (int)LR0Family.ID2Collection.size(); ++state) { for (auto item : LR0Family.ID2Collection[state]) { LR1Point pt0(state, item.productID, item.pos); LR1ItemCollection col; closureLR1Item(LR1Item(item.productID, item.pos, ESS_Term_End), col); for (auto _item : col) { if (isImportantLR0Item(_item.productID, _item.pos)) { LR1Point pt1(state, _item.productID, _item.pos); if (_item.term == ESS_Term_End) { point2Points[pt0].insert(pt1); } else { point2Terms[pt1].insert(_item.term); unhandled.insert(pt1); } auto &body = getProductBody(_item.productID); if (_item.pos >= body.size()) continue; LR1Point pt2(LR0Family.transMap[state][body[_item.pos]], _item.productID, _item.pos + 1); point2Points[pt1].insert(pt2); } else { auto &body = getProductBody(_item.productID); if (_item.pos >= body.size()) continue; LR1Point pt2(LR0Family.transMap[state][body[_item.pos]], _item.productID, _item.pos + 1); if (_item.term == ESS_Term_End) { point2Points[pt0].insert(pt2); } else { point2Terms[pt2].insert(_item.term); unhandled.insert(pt2); } } } } } while (!unhandled.empty()) { LR1Point point = *unhandled.begin(); unhandled.erase(unhandled.begin()); auto& terms = point2Terms[point]; for (auto ditem : point2Points[point]) { auto& dterms = point2Terms[ditem]; auto osize = dterms.size(); dterms.insert(terms.begin(), terms.end()); if (dterms.size() != osize) { unhandled.insert(ditem); } } } m_gotoTable.setStateCount((int)LR0Family.ID2Collection.size()); m_actionTable.setStateCount((int)LR0Family.ID2Collection.size()); for (int state = 0; state < (int)LR0Family.ID2Collection.size(); ++state) { for (auto term : g_termList) { Action act; { auto &m = LR0Family.transMap[state]; if (m.count(term)) { mergeAction(act, Action(Action::T_Shift, m[term]), LR0Family); } } for (auto item : LR0Family.ID2Collection[state]) { auto& body = getProductBody(item.productID); if (item.pos != body.size()) continue; auto& terms = point2Terms[LR1Point(state, item.productID, item.pos)]; if (terms.count(term) == 0) continue; mergeAction(act, Action(Action::T_Reduce, item.productID), LR0Family); } m_actionTable.setAction(state, term, act); } for (auto nonTerm : g_nonTermList) { auto &m = LR0Family.transMap[state]; if (m.count(nonTerm)) { m_gotoTable.setNextState(state, nonTerm, m[nonTerm]); } } } }
void ImageMatcherHammingRansac::process_binary(const unsigned char *input, int size, BinaryCollector *collector) { std::string features0, features1; std::vector<double> vec0, vec1; std::vector<int> shape0, shape1; std::pair<std::string, std::string> val; string_pair_fromstring(input, size, &val); binary_feature2d_fromstring((const unsigned char*) val.first.c_str(), val.first.size(), &features0, &vec0, &shape0); binary_feature2d_fromstring((const unsigned char*) val.second.c_str(), val.second.size(), &features1, &vec1, &shape1); int num_pts0 = shape0[0]; int num_pts1 = shape1[0]; int *dists = new int[num_pts0 * num_pts1]; // TODO: Check that shape0[1] == shape1[1] memset(dists, 0, sizeof(int) * num_pts0 * num_pts1); hamdist_cmap_lut16((const unsigned char *)features0.c_str(), (const unsigned char *)features1.c_str(), dists, shape0[1], num_pts0, num_pts1); std::vector<cv::Point2f> match0; std::vector<cv::Point2f> match1; for (int i = 0; i < num_pts0; ++i) { int min_ind = 0; int min_dist = 100000; for (int j = 0; j < num_pts1; ++j) { if (dists[num_pts1 * i + j] < min_dist) { min_dist = dists[num_pts1 * i + j]; min_ind = j; } } if (max_dist < min_dist) continue; int save_point = 1; for (int k = 0; k < num_pts0; ++k) { if (dists[num_pts1 * k + min_ind] <= min_dist && k != i) { save_point = 0; break; } } if (save_point) { cv::Point2f pt0(vec0[i * 6 + 1], vec0[i * 6]), pt1(vec1[min_ind * 6 + 1], vec1[min_ind * 6]); match0.push_back(pt0); match1.push_back(pt1); } } bool matched = false; std::cout << "Matched " << match0.size() << std::endl; if (match0.size() > 4) { cv::Mat mask(match0.size(), 1, CV_8U); cv::Mat H = findHomography(match0, match1, CV_RANSAC, reproj_thresh, mask); int num_inliers = 0; for (int i = 0; i < match0.size(); ++i) num_inliers += ((unsigned char *)mask.data)[i] > 0; std::cout << H << std::endl; matched = num_inliers >= min_inliers; std::cout << "Ransac ran - Inliers " << num_inliers << std::endl; } delete [] dists; if (matched) std::cout << "C:Matched" << std::endl; else std::cout << "C:UnMatched" << std::endl; bool_tostring(matched, collector); }