예제 #1
0
TEST(Mesh,CompareRealSpace) {
  alps::gf::real_space_index_mesh::container_type points1(boost::extents[20][3]);
  alps::gf::real_space_index_mesh::container_type points2(boost::extents[20][3]);
  alps::gf::real_space_index_mesh::container_type points3(boost::extents[20][3]);
  alps::gf::real_space_index_mesh::container_type points4(boost::extents[3][20]);
  for (int i=0; i<points1.num_elements(); ++i) {
    *(points1.origin()+i)=i;
    *(points2.origin()+i)=i;
    *(points3.origin()+i)=i+1;
    *(points4.origin()+i)=i;
  }

  alps::gf::real_space_index_mesh mesh1(points1);
  alps::gf::real_space_index_mesh mesh2(points2);
  alps::gf::real_space_index_mesh mesh3(points3);
  alps::gf::real_space_index_mesh mesh4(points4);

  EXPECT_TRUE(mesh1==mesh2);
  EXPECT_TRUE(mesh1!=mesh3);
  EXPECT_TRUE(mesh1!=mesh4);

  EXPECT_FALSE(mesh1==mesh3);
  EXPECT_FALSE(mesh1!=mesh2);
  EXPECT_FALSE(mesh1==mesh4);
}
예제 #2
0
TEST(Estimator,EssentialFivePoint) {
    auto estimator=GSLAM::Estimator::create();
    if(!estimator.get())
    {
        LOG(WARNING)<<"Test aborded since estimator not created.";
        return ;
    }

    const double points1_raw[] = {
        0.4964, 1.0577, 0.3650,  -0.0919, -0.5412, 0.0159, -0.5239, 0.9467,
        0.3467, 0.5301, 0.2797,  0.0012,  -0.1986, 0.0460, -0.1622, 0.5347,
        0.0796, 0.2379, -0.3946, 0.7969,  0.2,     0.7,    0.6,     0.3};

    const double points2_raw[] = {
        0.7570, 2.7340, 0.3961,  0.6981, -0.6014, 0.7110, -0.7385, 2.2712,
        0.4177, 1.2132, 0.3052,  0.4835, -0.2171, 0.5057, -0.2059, 1.1583,
        0.0946, 0.7013, -0.6236, 3.0253, 0.5,     0.9,    0.9,     0.2};

    const size_t kNumPoints = 12;

    std::vector<GSLAM::Point2d> points1(kNumPoints);
    std::vector<GSLAM::Point2d> points2(kNumPoints);
    for (size_t i = 0; i < kNumPoints; ++i) {
        points1[i] = GSLAM::Point2d(points1_raw[2 * i], points1_raw[2 * i + 1]);
        points2[i] = GSLAM::Point2d(points2_raw[2 * i], points2_raw[2 * i + 1]);
    }

    double F[9];
    std::vector<uchar> inlier_mask;
    if(!estimator->findEssentialMatrix(F,points1,points2,GSLAM::RANSAC,0.02,0.9999,&inlier_mask)) return ;


    EXPECT_FALSE(inlier_mask[10]);
    EXPECT_FALSE(inlier_mask[11]);
}
예제 #3
0
TEST(Estimator,FundamentalEightPoint)
{
    auto estimator=GSLAM::Estimator::create();
    if(!estimator.get())
    {
        LOG(WARNING)<<"Test aborded since estimator not created.";
        return ;
    }

    const double points1_raw[] = {1.839035, 1.924743, 0.543582,  0.375221,
                                  0.473240, 0.142522, 0.964910,  0.598376,
                                  0.102388, 0.140092, 15.994343, 9.622164,
                                  0.285901, 0.430055, 0.091150,  0.254594};

    const double points2_raw[] = {
        1.002114, 1.129644, 1.521742, 1.846002, 1.084332, 0.275134,
        0.293328, 0.588992, 0.839509, 0.087290, 1.779735, 1.116857,
        0.878616, 0.602447, 0.642616, 1.028681,
    };

    const size_t kNumPoints = 8;

    std::vector<GSLAM::Point2d> points1(kNumPoints);
    std::vector<GSLAM::Point2d> points2(kNumPoints);
    for (size_t i = 0; i < kNumPoints; ++i) {
      points1[i] = GSLAM::Point2d(points1_raw[2 * i], points1_raw[2 * i + 1]);
      points2[i] = GSLAM::Point2d(points2_raw[2 * i], points2_raw[2 * i + 1]);
    }

    double F[9];
    EXPECT_TRUE(estimator->findFundamental(F,points1,points2,GSLAM::FM_8POINT));

    // Reference values obtained from Matlab.
    for(int i=0;i<9;i++) F[i]*=0.0221019;
    EXPECT_LE(fabs(-0.217859-F[0]), 2e-2);
    EXPECT_LE(fabs(0.419282-F[1]), 2e-2);// TODO : why opencv impementation not pass <1-5
    EXPECT_LE(fabs(-0.0343075-F[2]), 1e-2);
    EXPECT_LE(fabs(-0.0717941-F[3]), 1e-2);
    EXPECT_LE(fabs(0.0451643-F[4]), 1e-2);
    EXPECT_LE(fabs(0.0216073-F[5]), 1e-2);
    EXPECT_LE(fabs(0.248062-F[6]), 2e-2);
    EXPECT_LE(fabs(-0.429478-F[7]), 2e-2);
    EXPECT_LE(fabs(0.0221019-F[8]), 1e-2);
}
예제 #4
0
TEST(Estimator,FundamentalSevenPoint)
{
    auto estimator=GSLAM::Estimator::create();
    if(!estimator.get())
    {
        LOG(WARNING)<<"Test aborded since estimator not created.";
        return ;
    }

    const double points1_raw[] = {0.4964, 1.0577,  0.3650,  -0.0919, -0.5412,
                                  0.0159, -0.5239, 0.9467,  0.3467,  0.5301,
                                  0.2797, 0.0012,  -0.1986, 0.0460};

    const double points2_raw[] = {0.7570, 2.7340,  0.3961,  0.6981, -0.6014,
                                  0.7110, -0.7385, 2.2712,  0.4177, 1.2132,
                                  0.3052, 0.4835,  -0.2171, 0.5057};

    const size_t kNumPoints = 7;

    std::vector<GSLAM::Point2d> points1(kNumPoints);
    std::vector<GSLAM::Point2d> points2(kNumPoints);
    for (size_t i = 0; i < kNumPoints; ++i) {
      points1[i] = GSLAM::Point2d(points1_raw[2 * i], points1_raw[2 * i + 1]);
      points2[i] = GSLAM::Point2d(points2_raw[2 * i], points2_raw[2 * i + 1]);
    }

    double F[9];
    EXPECT_TRUE(estimator->findFundamental(F,points1,points2,GSLAM::FM_7POINT));

    // Reference values obtained from Matlab.
    EXPECT_LE(fabs(F[0]-4.81441976), 1e-6);
    EXPECT_LE(fabs(F[1]+8.16978909), 1e-6);
    EXPECT_LE(fabs(F[2]-6.73133404), 1e-6);
    EXPECT_LE(fabs(5.16247992-F[3]), 1e-6);
    EXPECT_LE(fabs(0.19325606-F[4]), 1e-6);
    EXPECT_LE(fabs(-2.87239381-F[5]), 1e-6);
    EXPECT_LE(fabs(-9.92570126-F[6]), 1e-6);
    EXPECT_LE(fabs(3.64159554-F[7]), 1e-6);
    EXPECT_LE(fabs(1.-F[8]), 1e-6);
}
예제 #5
0
void prob2a(){
  std::cout << "Problem 2 Part A ======== " << std::endl;

  Matrix points1(10000,std::vector<double>(2));
  Matrix points2(10000,std::vector<double>(2));
  loadFile(points1, "sample_data/output1");
  loadFile(points2, "sample_data/output3");

  std::vector<double> mean1 = getSampleMean(points1);
  std::vector<double> mean2 = getSampleMean(points2);

  std::cout << "sample_mean1 = ";
  print_vec(mean1);
  std::cout << "sample_mean2 = ";
  print_vec(mean2);

  Matrix cov1 = getSampleVar(points1, mean1);
  Matrix cov2 = getSampleVar(points2, mean2);

  std::cout << "sample_cov1 = ";
  print_matrix(cov1);
  std::cout << "sample_cov2 = ";
  print_matrix(cov2);

  std::cout << "With estimated params: " << std::endl;
  QuadraticDiscriminant classifier1(mean1, mean2, cov1, cov2);
  calcError(classifier1,points1,points2, "sample_data/labels1");

  std::cout << "Given params: " << std::endl;
  mean1 = {1.0,1.0};
  mean2 = {6.0,6.0};
  cov1 = {{2.0,0},{0,2.0}};
  cov2 = {{4.0,0},{0,8.0}};

  QuadraticDiscriminant classifier2(mean1, mean2, cov1, cov2);
  calcError(classifier2,points1,points2, "sample_data/labels1");
  std::cout << std::endl;
}
예제 #6
0
void create_curve_rebar(IfcHierarchyHelper& file)
{
	int dia = 24;
	int R = 3 * dia;
	int length = 12 * dia;

	double crossSectionarea = M_PI * (dia / 2) * 2;
	IfcSchema::IfcReinforcingBar* rebar = new IfcSchema::IfcReinforcingBar(
		guid(), 0, S("test"), null,
		null, 0, 0,
		null, S("SR24"),		//SteelGrade
		dia,						//diameter
		crossSectionarea,		//crossSectionarea = math.pi*(12.0/2)**2
		0,
		IfcSchema::IfcReinforcingBarRoleEnum::IfcReinforcingBarRoleEnum::IfcReinforcingBarRole_LIGATURE,
		IfcSchema::IfcReinforcingBarSurfaceEnum::IfcReinforcingBarSurfaceEnum::IfcReinforcingBarSurface_PLAIN	//PLAIN or TEXTURED
		);

	file.addBuildingProduct(rebar);
	rebar->setOwnerHistory(file.getSingle<IfcSchema::IfcOwnerHistory>());

	IfcSchema::IfcCompositeCurveSegment::list::ptr segments(new IfcSchema::IfcCompositeCurveSegment::list());

	IfcSchema::IfcCartesianPoint* p1 = file.addTriplet<IfcSchema::IfcCartesianPoint>(0, 0, 1000.);
	IfcSchema::IfcCartesianPoint* p2 = file.addTriplet<IfcSchema::IfcCartesianPoint>(0, 0, 0);
	IfcSchema::IfcCartesianPoint* p3 = file.addTriplet<IfcSchema::IfcCartesianPoint>(0, R, 0);
	IfcSchema::IfcCartesianPoint* p4 = file.addTriplet<IfcSchema::IfcCartesianPoint>(0, R, -R);
	IfcSchema::IfcCartesianPoint* p5 = file.addTriplet<IfcSchema::IfcCartesianPoint>(0, R + length, -R);

	/*first segment - line */
	IfcSchema::IfcCartesianPoint::list::ptr points1(new IfcSchema::IfcCartesianPoint::list());
	points1->push(p1);
	points1->push(p2);
	file.addEntities(points1->generalize());
	IfcSchema::IfcPolyline* poly1 = new IfcSchema::IfcPolyline(points1);
	file.addEntity(poly1);

	IfcSchema::IfcCompositeCurveSegment* segment1 = new IfcSchema::IfcCompositeCurveSegment(IfcSchema::IfcTransitionCode::IfcTransitionCode_CONTINUOUS, true, poly1);
	file.addEntity(segment1);
	segments->push(segment1);

	/*second segment - arc */
	IfcSchema::IfcAxis2Placement3D* axis1 = new IfcSchema::IfcAxis2Placement3D(p3, file.addTriplet<IfcSchema::IfcDirection>(1, 0, 0), file.addTriplet<IfcSchema::IfcDirection>(0, 1, 0));
	file.addEntity(axis1);
	IfcSchema::IfcCircle* circle = new IfcSchema::IfcCircle(axis1, R);
	file.addEntity(circle);

	IfcEntityList::ptr trim1(new IfcEntityList);
	IfcEntityList::ptr trim2(new IfcEntityList);

	trim1->push(new IfcSchema::IfcParameterValue(180));
	trim1->push(p2);

	trim2->push(new IfcSchema::IfcParameterValue(270));
	trim2->push(p4);
	IfcSchema::IfcTrimmedCurve* trimmed_curve = new IfcSchema::IfcTrimmedCurve(circle, trim1, trim2, false, IfcSchema::IfcTrimmingPreference::IfcTrimmingPreference_PARAMETER);
	file.addEntity(trimmed_curve);

	IfcSchema::IfcCompositeCurveSegment* segment2 = new IfcSchema::IfcCompositeCurveSegment(IfcSchema::IfcTransitionCode::IfcTransitionCode_CONTSAMEGRADIENT, false, trimmed_curve);
	file.addEntity(segment2);
	segments->push(segment2);

	/*third segment - line */
	IfcSchema::IfcCartesianPoint::list::ptr points2(new IfcSchema::IfcCartesianPoint::list());
	points2->push(p4);
	points2->push(p5);
	file.addEntities(points2->generalize());
	IfcSchema::IfcPolyline* poly2 = new IfcSchema::IfcPolyline(points2);
	file.addEntity(poly2);

	IfcSchema::IfcCompositeCurveSegment* segment3 = new IfcSchema::IfcCompositeCurveSegment(IfcSchema::IfcTransitionCode::IfcTransitionCode_CONTINUOUS, true, poly2);
	file.addEntity(segment3);
	segments->push(segment3);

	IfcSchema::IfcCompositeCurve* curve = new IfcSchema::IfcCompositeCurve(segments, false);
	file.addEntity(curve);

	IfcSchema::IfcSweptDiskSolid* solid = new IfcSchema::IfcSweptDiskSolid(curve, dia / 2, null, 0, 1);

	IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list());
	IfcSchema::IfcRepresentationItem::list::ptr items(new IfcSchema::IfcRepresentationItem::list());
	items->push(solid);
	IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
		file.getSingle<IfcSchema::IfcRepresentationContext>(), S("Body"), S("AdvancedSweptSolid"), items);
	reps->push(rep);

	IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(null, null, reps);
	file.addEntity(shape);

	rebar->setRepresentation(shape);

	IfcSchema::IfcObjectPlacement* storey_placement = file.getSingle<IfcSchema::IfcBuildingStorey>()->ObjectPlacement();
	rebar->setObjectPlacement(file.addLocalPlacement(storey_placement, 0, 0, 0));
}
예제 #7
0
		// Linked list chromosomes crossover
		void GaListMultipointCrossover::operator ()(GaCrossoverBuffer& crossoverBuffer,
			const GaCrossoverParams& parameters) const
		{
			// get chromosomes' representations
			Common::Data::GaListBase* source1 = &( (Representation::GaListStructureChromosome&)*crossoverBuffer.GetParentChromosome( 0 ) ).GetStructure();
			Common::Data::GaListBase* source2 = &( (Representation::GaListStructureChromosome&)*crossoverBuffer.GetParentChromosome( 1 ) ).GetStructure();

			// reserve memory for storing crossover points
			int maxCount = ( (const GaCrossoverPointParams&)parameters ).GetNumberOfCrossoverPoints() + 1;
			Common::Memory::GaAutoPtr<int> points1( new int[ maxCount ], Common::Memory::GaArrayDeletionPolicy<int>::GetInstance() );
			Common::Memory::GaAutoPtr<int> points2( new int[ maxCount ], Common::Memory::GaArrayDeletionPolicy<int>::GetInstance() );

			// create required number of offspring chromosomes
			for( int i = ( (const GaCrossoverPointParams&)parameters ).GetNumberOfOffspring() - 1; i >= 0; i -= 2 )
			{
				// create the first offspring chromosome
				GaChromosomePtr offspring2, offspring1 = crossoverBuffer.CreateOffspringFromPrototype();
				Common::Data::GaListBase* destination1 = &( (Representation::GaListStructureChromosome&)*offspring1 ).GetStructure();

				// create the second offspring chromosome if required
				Common::Data::GaListBase* destination2 = NULL;
				if( i > 0 )
				{
					offspring2 = crossoverBuffer.CreateOffspringFromPrototype();
					destination2 = &( (Representation::GaListStructureChromosome&)*offspring2 ).GetStructure();
				}

				// number of crossover points cannot be larger then smallest chromosome
				int count = maxCount;
				if( count > source1->GetCount() )
					count = source1->GetCount();
				if( count > source2->GetCount() )
					count = source2->GetCount();

				// generate crossover points
				if( count > 1 )
				{
					Common::Random::GaGenerateRandomSequenceAsc( 1, source1->GetCount() - 1, count - 1, true, points1.GetRawPtr() );
					Common::Random::GaGenerateRandomSequenceAsc( 1, source2->GetCount() - 1, count - 1, true, points2.GetRawPtr() );
				}

				Common::Data::GaListNodeBase* sourceNode1 = source1->GetHead();
				Common::Data::GaListNodeBase* sourceNode2 = source2->GetHead();

				points1[ count - 1 ] = source1->GetCount();
				points2[ count - 1 ] = source2->GetCount();

				// alternately copy genes from parents to offspring chromosomes
				for( int j = 0, s1 = 0, s2 = 0; j < count ; j++ )
				{
					int e1 = points1[ j ];
					int e2 = points2[ j ];

					// copy portion of the first parent to destination offspring if it exists
					if( destination1 )
					{
						for( int k = s1; k < e1; k++, sourceNode1 = sourceNode1->GetNext() )
							destination1->InsertTail( (Common::Data::GaListNodeBase*)sourceNode1->Clone() );
					}

					// copy portion of the second parent to destination offspring if it exists
					if( destination2 )
					{
						for( int k = s2; k < e2; k++, sourceNode2 = sourceNode2->GetNext() )
							destination2->InsertTail( (Common::Data::GaListNodeBase*)sourceNode2->Clone() );
					}

					// swap destination chromosomes
					Common::Data::GaListBase* t = destination1;
					destination1 = destination2;
					destination2 = t;

					s1 = e1;
					s2 = e2;
				}

				if( destination1->GetCount() == 0 || destination2->GetCount() == 0 )
				{
					destination1 = destination1;
				}

				// store the first offspring
				crossoverBuffer.StoreOffspringChromosome( offspring1, 0 );

				// store the second offspring if it was created
				if( !offspring2.IsNull() )
					crossoverBuffer.StoreOffspringChromosome( offspring2, 1 );
			}
		}