コード例 #1
0
void mitk::PointSetIndexToWorldTransformFilter::GenerateData()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::PointSet::Pointer output  = this->GetOutput();

  typedef std::vector<mitk::Point3D> PointContainer;
  PointContainer points;
  int pointNo = 0;

  while(pointNo!= input->GetSize())
  {
    mitk::Point3D current = input->GetPoint(pointNo);
    points.push_back(current);
    pointNo++;
  }
  output->GetGeometry()->SetIdentity();
  PointContainer::iterator pointsIter = points.begin();

  pointNo = 0;
  while(pointsIter != points.end())
  {
    output->SetPoint(pointNo,(*pointsIter));
    pointNo++;
    pointsIter++;
  }

}
コード例 #2
0
void add_simplices(SimplexVector& sv, int d, const PointContainer& points)
{
	PointIndex indices[d+1];
	for (int i = 0; i < d+1; ++i) 
		indices[i] = d - i;

	while(indices[d] < points.size() - d)
	{
		// Add simplex
		Miniball mb(points[indices[0]].dim());
		Simplex s;
		for (int i = 0; i < d+1; ++i)
		{
			s.add(indices[i]);
			mb.check_in(points[indices[i]]);
		}
		mb.build();
		s.set_value(mb.squared_radius());
		sv.push_back(s);

		
		// Advance indices
		for (int i = 0; i < d+1; ++i)
		{
			++indices[i];
			if (indices[i] < points.size() - i)
			{
				for (int j = i-1; j >= 0; --j)
					indices[j] = indices[j+1] + 1;
				break;
			}
		}
	}
}
コード例 #3
0
int main(int argc, char** argv) 
{
	// Read in the point set and compute its Delaunay triangulation
	std::istream& in = std::cin;
	int ambient_d, homology_d;	
	in >> ambient_d >> homology_d;
	
	std::cout << "Ambient dimension: " << ambient_d << std::endl;
	std::cout << "Will compute PD up to dimension: " << homology_d << std::endl;
	
	// Read points
	PointContainer points;
	while(in)
	{
		Point p(ambient_d);
		for (int i = 0; i < ambient_d; ++i)
			in >> p[i];
		points.push_back(p);
	}
	std::cout << "Points read: " << points.size() << std::endl;
   
	// Compute Cech values
	CechFiltration cf;
	{										// resource acquisition is initialization
		SimplexVector	sv;
		int num_simplices = 0;
		for (int i = 0; i <= homology_d + 1; ++i)
			num_simplices += choose(points.size(), i+1);
		sv.reserve(num_simplices);
		std::cout << "Reserved SimplexVector of size: " << num_simplices << std::endl;

		for (int i = 0; i <= homology_d + 1; ++i)
			add_simplices(sv, i, points);
		std::cout << "Size of SimplexVector: " << sv.size() << std::endl;
			
		std::sort(sv.begin(), sv.end(), DimensionValueComparison());
		
		for (SimplexVector::const_iterator cur = sv.begin(); cur != sv.end(); ++cur)
			cf.append(*cur);
	}

	// Compute persistence
	cf.fill_simplex_index_map();
	cf.pair_simplices(cf.begin(), cf.end());
	std::cout << "Simplices paired" << std::endl;

	for (CechFiltration::Index i = cf.begin(); i != cf.end(); ++i)
		if (i->is_paired())
		{
			if (i->sign())
				std::cout << i->dimension() << " " << i->get_value() << " " << i->pair()->get_value() << std::endl;
		} //else std::cout << i->value() << std::endl;

}
コード例 #4
0
ファイル: main.cpp プロジェクト: mbrucher/CoverTree
PointContainer knn(const PointContainer& container, const Point& data, int k)
{
  std::map<float, Point> point_map;
  for(PointContainer::const_iterator it = container.begin(); it != container.end(); ++it)
  {
    point_map[euclidian(data, *it)] = *it;
  }

  PointContainer result;
  std::map<float, Point>::const_iterator it = point_map.begin();
  for(int i = 0; i < k; ++i)
  {
    result.push_back(it->second);
    ++it;
  }
  return result;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: mbrucher/CoverTree
PointContainer generate(long size)
{
  PointContainer data;

  boost::mt19937 engine(static_cast<long unsigned int>(clock()));
  boost::normal_distribution<double> generator;
  boost::variate_generator<boost::mt19937, boost::normal_distribution<double> > binded(engine, generator);

  for(long i = 0; i < size; ++i)
  {
    Point point;
    for(long j = 0; j < POINTSIZE; ++j)
    {
      point.push_back(binded());
    }
    data.push_back(point);
  }

  return data;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: mbrucher/CoverTree
int main(int argc, char** argv)
{
  CoverTree<float, std::vector<float>, float (*const)(const std::vector<float>&, const std::vector<float>&)> tree(&euclidian);

  PointContainer data = generate(VECTORLENGTH);

  boost::posix_time::ptime time = boost::posix_time::microsec_clock::local_time();
  for(PointContainer::const_iterator it = data.begin(); it != data.end(); ++it)
  {
    tree.insert(*it);
  }
  std::cout << "Build time " << (boost::posix_time::microsec_clock::local_time() - time) << std::endl;

  std::ofstream stream("dump.txt");
  tree.dump(stream);

  Point zero(2, 0.f);
  time = boost::posix_time::microsec_clock::local_time();
  PointContainer result = knn(data, zero, KNNSIZE);
  std::cout << "Out time (linear) " << (boost::posix_time::microsec_clock::local_time() - time) << std::endl;

  time = boost::posix_time::microsec_clock::local_time();
  PointContainer result2 = tree.knn(zero, KNNSIZE);
  std::cout << "Out time (cover_tree) " << (boost::posix_time::microsec_clock::local_time() - time) << std::endl;

  bool boolean = true;
  for(int i = 0; i < std::min(result.size(), result2.size()); ++i)
  {
    for(int j = 0; j < POINTSIZE; ++j)
    {
      boolean = boolean && (result[i][j] == result2[i][j]);
    }
    std::cout << i << std::endl << result[i] << result2[i];
  }
  std::cout << "Result " << (boolean && (result.size() == result2.size())) << std::endl;
  return EXIT_SUCCESS;
}