当前位置: 首页>>代码示例>>C++>>正文


C++ Polyhedron类代码示例

本文整理汇总了C++中Polyhedron的典型用法代码示例。如果您正苦于以下问题:C++ Polyhedron类的具体用法?C++ Polyhedron怎么用?C++ Polyhedron使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Polyhedron类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test

void test(std::string fname, std::size_t expected_duplicated_vertices)
{
  std::vector<K::Point_3> points;
  std::vector< std::vector<std::size_t> > polygons;
  std::ifstream input(fname.c_str());
  if (!input)
  {
    std::cerr << "Cannot open file " << fname << "\n";
    exit(EXIT_FAILURE);
  }
  
  if (!CGAL::read_OFF(input, points, polygons))
  {
    std::cerr << "Error parsing the OFF file " << fname << "\n";
    exit(EXIT_FAILURE);
  }
  
  std::size_t initial_nb_points = points.size();
  CGAL::orient_polygon_soup(points, polygons);

  assert(expected_duplicated_vertices == points.size()-initial_nb_points);

  Polyhedron P;
  CGAL::polygon_soup_to_polyhedron_3(P, points, polygons);
  assert(P.is_valid());
  std::cout << fname << " OK\n";
}
开发者ID:Fox-Heracles,项目名称:cgal,代码行数:27,代码来源:test_orient_polygon_soup.cpp

示例2: transformMesh

void transformMesh( Polyhedron & poly, Transformation3 & map )
{
    for ( Vertex_iterator vi = poly.vertices_begin(); vi != poly.vertices_end(); ++vi ) {
	Point3 store = vi->point().transform( map );
	vi->point() = store;
    }
}
开发者ID:tohyongcheng,项目名称:Paper3D,代码行数:7,代码来源:dual.cpp

示例3: float3

/// See http://paulbourke.net/geometry/platonic/
Polyhedron Polyhedron::Tetrahedron(const float3 &centerPos, float scale, bool ccwIsFrontFacing)
{
	const float3 vertices[4] = { float3(1,1,1),
	                             float3(-1,1,-1),
	                             float3(1,-1,-1),
	                             float3(-1,-1,1) };
	const int faces[4][3] = { { 0, 1, 2 },
	                          { 1, 3, 2 },
	                          { 0, 2, 3 },
	                          { 0, 3, 1 } };

	scale /= 2.f;
	Polyhedron p;

	for(int i = 0; i < 4; ++i)
		p.v.push_back(vertices[i]*scale + centerPos);

	for(int i = 0; i < 4; ++i)
	{
		Face f;
		for(int j = 0; j < 3; ++j)
			f.v.push_back(faces[i][j]);
		p.f.push_back(f);
	}

	if (!ccwIsFrontFacing)
		p.FlipWindingOrder();

	return p;
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:31,代码来源:Polyhedron.cpp

示例4: main

int main()
{
 // Generated points are in that vector
  std::vector<Point> points;
  // Create input polyhedron
  Polyhedron polyhedron;
  polyhedron.make_tetrahedron(Point(-1,0,0), Point(0,1,0), Point(1,0,0), Point(0,0,-1));
  // Create domain
  Mesh_domain domain(polyhedron);
   using namespace CGAL::parameters;
  // Mesh criteria (no cell_size set)
  Mesh_criteria criteria(facet_angle=25, facet_size=0.15, facet_distance=0.008,
                         cell_radius_edge_ratio=3);
  // Mesh generation
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_perturb(), no_exude());

  // Create the generator, input is the C3t3 c3t3
  Random_points_in_tetrahedral_mesh_3<C3t3>
      g(c3t3);
  // Get 100 random points in cdt
  CGAL::cpp11::copy_n( g, 100, std::back_inserter(points));

  // Check that we have really created 100 points.
  assert( points.size() == 100);

  // test if the generated points are close
  std::cout << points[0] << std::endl;

  return 0;
}
开发者ID:MaelRL,项目名称:cgal,代码行数:30,代码来源:random_points_in_tetrahedral_mesh_3.cpp

示例5: minkowski

/// Computes the Minkowski sum of two convex polyhedra
PolyhedronPtr Polyhedron::minkowski(Polyhedron& p1, const Matrix4& T1, Polyhedron& p2, const Matrix4& T2, bool reflect_p2)
{
  // verify that both polyhedra are convex
  if (!p1.is_convex() || !p2.is_convex())
    throw std::runtime_error("Polyhedron::minkowski() only operates on convex polyhedra");

  // we'll transform p2 to p1's frame
  Matrix4 T2_to_T1 = Matrix4::inverse_transform(T1) * T2;
  Polyhedron p2_copy = p2;
  p2_copy.transform(T2_to_T1);

  // compute the minkowski sum
  std::list<Vector3> points;
  for (unsigned i=0; i< p1.get_vertices().size(); i++)
    for (unsigned j=0; j< p2_copy.get_vertices().size(); j++)
    {
      // add vertex from p1 to vertex from p2
      Vector3 v = p1.get_vertices()[i];
      if (reflect_p2)
        v -= p2_copy.get_vertices()[j];
      else
        v += p2_copy.get_vertices()[j];
      points.push_back(v);
    }

  // compute the convex hull of the points
  return CompGeom::calc_convex_hull(points.begin(), points.end()); 
}
开发者ID:erwincoumans,项目名称:Moby,代码行数:29,代码来源:Polyhedron.cpp

示例6: move

void Polyhedron::move(Polyhedron** polyhedronArray, int size)
{
	for(int i = 0; i < size; i++)
	{
		Polyhedron* other = polyhedronArray[i];

		if(this != other)
		{
			//Check to see if the polyhedrons collided using AABB
			bool isCollided = aabb.checkAABB(other->getAABB());
			//If collided then set the velocity to its inverse
			if(isCollided)
			{
				this->setVelocity(-1 * (this->getVelocity().x), -1 * (this->getVelocity().y),  -1 * (this->getVelocity().z));
				acceleration.x *= -1;
				acceleration.y *= -1;
			}
		}
	}
	//Update the position using euler integration
	eulerIntegrationUpdatePosition();

	//Update AABB
	aabb.centerPoint = vec3(centerX + offsetX, centerY + offsetY, centerZ + offsetZ);
}
开发者ID:rbVessal,项目名称:GeometryWarz,代码行数:25,代码来源:Polyhedron.cpp

示例7: PolyhedronIntersectsAABB_OBB

bool PolyhedronIntersectsAABB_OBB(const Polyhedron &p, const T &obj)
{
	if (p.Contains(obj.CenterPoint()))
		return true;
	if (obj.Contains(p.Centroid()))
		return true;

	// Test for each edge of the AABB/OBB whether this polyhedron intersects it.
	for(int i = 0; i < obj.NumEdges(); ++i)
		if (p.Intersects(obj.Edge(i)))
			return true;

	// Test for each edge of this polyhedron whether the AABB/OBB intersects it.
	for(size_t i = 0; i < p.f.size(); ++i)
	{
		assert(!p.f[i].v.empty()); // Cannot have degenerate faces here, and for performance reasons, don't start checking for this condition in release mode!
		int v0 = p.f[i].v.back();
		float3 l0 = p.v[v0];
		for(size_t j = 0; j < p.f[i].v.size(); ++j)
		{
			int v1 = p.f[i].v[j];
			float3 l1 = p.v[v1];
			if (v0 < v1 && obj.Intersects(LineSegment(l0, l1))) // If v0 < v1, then this line segment is the canonical one.
				return true;
			l0 = l1;
			v0 = v1;
		}
	}

	return false;
}
开发者ID:360degrees-fi,项目名称:tundra,代码行数:31,代码来源:Polyhedron.cpp

示例8: to_vrml

/// Sends this polyhedron to the specified stream using VRML
void Polyhedron::to_vrml(std::ostream& out, const Polyhedron& p, Vector3 diffuse_color, bool wireframe)
{
  const unsigned X = 0, Y = 1, Z = 2;
  
  // get the vertices and the facets
  const std::vector<Vector3>& vertices = p.get_vertices();
  const std::vector<IndexedTri>& facets = p.get_facets();

  out << "Shape {" << std::endl;
  out << "  appearance Appearance { material Material { diffuseColor " << diffuse_color[0] << " " << diffuse_color[1] << " " << diffuse_color[2] << " } }" << std::endl;
  out << "  geometry ";
  if (!wireframe)
    out << "IndexedFaceSet {" << std::endl;
  else
    out << "IndexedLineSet {" << std::endl;
  out << "    coord Coordinate { point [ ";
  for (unsigned i=0; i< vertices.size(); i++)
    out << vertices[i][X] << " " << vertices[i][Y] << " " << vertices[i][Z] << ", ";
  out << " ] }" << std::endl;
  out << "    coordIndex [ ";
  if (!wireframe)
    for (unsigned i=0; i< facets.size(); i++)
      out << facets[i].a << " " << facets[i].b << " " << facets[i].c << " -1, ";
  else
    for (unsigned i=0; i< facets.size(); i++)
      out << facets[i].a << " " << facets[i].b << " " << facets[i].c << " " << facets[i].a << " -1, ";  
  out << " ] } }" << std::endl;
}
开发者ID:erwincoumans,项目名称:Moby,代码行数:29,代码来源:Polyhedron.cpp

示例9: test_extraPlane

   void test_extraPlane()
   {
      Vector< PlaneF > planes;

      // Build planes for a unit cube centered at the origin.
      // Note that the normals must be facing inwards.

      planes.push_back( PlaneF( Point3F( -0.5f, 0.f, 0.f ), Point3F( 1.f, 0.f, 0.f ) ) );
      planes.push_back( PlaneF( Point3F( 0.5f, 0.f, 0.f ), Point3F( -1.f, 0.f, 0.f ) ) );
      planes.push_back( PlaneF( Point3F( 0.f, -0.5f, 0.f ), Point3F( 0.f, 1.f, 0.f ) ) );
      planes.push_back( PlaneF( Point3F( 0.f, 0.5f, 0.f ), Point3F( 0.f, -1.f, 0.f ) ) );
      planes.push_back( PlaneF( Point3F( 0.f, 0.f, -0.5f ), Point3F( 0.f, 0.f, 1.f ) ) );
      planes.push_back( PlaneF( Point3F( 0.f, 0.f, 0.5f ), Point3F( 0.f, 0.f, -1.f ) ) );

      // Add extra plane that doesn't contribute a new edge.

      planes.push_back( PlaneF( Point3F( 0.5f, 0.5f, 0.5f ), Point3F( -1.f, -1.f, -1.f ) ) );

      // Turn it into a polyhedron.

      Polyhedron polyhedron;
      polyhedron.buildFromPlanes(
         PlaneSetF( planes.address(), planes.size() )
      );

      // Check if we got a cube back.

      TEST( polyhedron.getNumPoints() == 8 );
      TEST( polyhedron.getNumPlanes() == 6 );
      TEST( polyhedron.getNumEdges() == 12 );
   }
开发者ID:Adrellias,项目名称:Torque3D-DaveWork,代码行数:31,代码来源:testPolyhedron.cpp

示例10: cos

Polyhedron* Polyhedron::Translate( float OffsetX, float OffsetY, int FlipX, float Rotation )
{
	float cosR = cos(-Rotation * (M_PI / 180.0f));
	float sinR = sin(-Rotation * (M_PI / 180.0f));

	Polyhedron* newPoly = new Polyhedron;
	for( int idx = 0; idx < Points->count; idx++ )
	{
		Vector2* working = new Vector2( Points->ItemAt<Vector2*>(idx)->X * ( FlipX != 0 ? -1 : 1 ), Points->ItemAt<Vector2*>(idx)->Y );

		if( Rotation != 0.0f )
		{
			float vx = (cosR * working->X) - (sinR * working->Y);
			float vy = (sinR * working->X) + (cosR * working->Y);
			working->X = vx;
			working->Y = vy;
		}
		working->X += OffsetX;
		working->Y += OffsetY;

		newPoly->Points->AddToEnd( (void*)working );
	}
	newPoly->Compute();

	return newPoly;
}
开发者ID:pmprog,项目名称:JANE.v4,代码行数:26,代码来源:polygon.cpp

示例11: main

int main() {
    Polyhedron P;
    Build_triangle<HalfedgeDS> triangle;
    P.delegate( triangle);
    CGAL_assertion( P.is_triangle( P.halfedges_begin()));
    return 0;
}
开发者ID:Asuzer,项目名称:cgal,代码行数:7,代码来源:polyhedron_prog_incr_builder.cpp

示例12: is_weakly_convex

bool is_weakly_convex(Polyhedron const& p) {
  for (typename Polyhedron::Edge_const_iterator i = p.edges_begin(); i != p.edges_end(); ++i) {
    typename Polyhedron::Plane_3 p(i->opposite()->vertex()->point(), i->vertex()->point(), i->next()->vertex()->point());
    if (p.has_on_positive_side(i->opposite()->next()->vertex()->point()) &&
        CGAL::squared_distance(p, i->opposite()->next()->vertex()->point()) > 1e-8) {
      return false;
    }
  }
  // Also make sure that there is only one shell:
  boost::unordered_set<typename Polyhedron::Facet_const_handle, typename CGAL::Handle_hash_function> visited;
  // c++11
  // visited.reserve(p.size_of_facets());
  
  std::queue<typename Polyhedron::Facet_const_handle> to_explore;
  to_explore.push(p.facets_begin()); // One arbitrary facet
  visited.insert(to_explore.front());
  
  while (!to_explore.empty()) {
    typename Polyhedron::Facet_const_handle f = to_explore.front();
    to_explore.pop();
    typename Polyhedron::Facet::Halfedge_around_facet_const_circulator he, end;
    end = he = f->facet_begin();
    CGAL_For_all(he,end) {
      typename Polyhedron::Facet_const_handle o = he->opposite()->facet();
      
      if (!visited.count(o)) {
        visited.insert(o);
        to_explore.push(o);
      }
    }
  }
开发者ID:ChristianECooper,项目名称:openscad,代码行数:31,代码来源:decompose.cpp

示例13: flip_edge

void flip_edge( Polyhedron& P, Halfedge_handle e) {
    if ( e->is_border_edge())
        return;
    Halfedge_handle h = e->next();
    P.join_facet( e);
    P.split_facet( h, h->next()->next());
}
开发者ID:lrineau,项目名称:cgal,代码行数:7,代码来源:polyhedron_prog_subdiv_with_boundary.cpp

示例14: initWeights

void initWeights( Polyhedron & poly )
{
    // assign the same IDs to the identical/ opposite halfedges
    for ( Halfedge_iterator hi = poly.halfedges_begin(); hi != poly.halfedges_end(); ++hi ) {
	hi->fixed()		= false;
    }
}
开发者ID:tohyongcheng,项目名称:Paper3D,代码行数:7,代码来源:dual.cpp

示例15: remove_edge

static void remove_edge(Polyhedron& p, typename
                        Polyhedron::Halfedge_handle& edge)
{

  // // FIXME: Is it possible to do this in a smarter way than a linear scan
  // for (csg::Polyhedron_3::Facet_iterator facet = p.facets_begin();
  //      facet != p.facets_end(); facet++)
  // {
  //   if ( facet_is_degenerate<csg::Polyhedron_3>(facet, threshold) )
  //   {
  //     //print_facet(facet);

  //     // Find a short edge
  //     csg::Polyhedron_3::Halfedge::Halfedge_handle shortest_edge = facet->facet_begin();
  //     csg::Polyhedron_3::Facet::Halfedge_around_facet_circulator current_edge = facet->facet_begin();
  //     double min_length = get_edge_length(current_edge);

  //     for (int i = 0; i < 2; i++)
  //     {
  // 	current_edge++;
  // 	if (get_edge_length(current_edge) < min_length)
  // 	{
  // 	  shortest_edge = current_edge;
  // 	  min_length = get_edge_length(current_edge);
  // 	}
  //     }

  // Join small triangles with neighbor facets
  edge = p.join_facet(edge->next());
  p.join_facet(edge->opposite()->prev());

  // The joined facets are now quads
  // Join the two close vertices
  p.join_vertex(edge);
}
开发者ID:YannCobigo,项目名称:dolfin,代码行数:35,代码来源:PolyhedronUtils.cpp


注:本文中的Polyhedron类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。