コード例 #1
0
ファイル: Character.cpp プロジェクト: crcsaenz/shad
Character *Character::GenerateArms(std::string filePath) {
	Arms = (new PolyMesh())->LoadObj(filePath)->GenerateRigidBody()->Scale(OpenMesh::Vec3f(0.7f, 0.7f, 0.7f));

		/* Enable physics */
	btConvexHullShape *ConvexShape = new btConvexHullShape();
	for(VertexIter v_it = vertices_begin(); v_it != vertices_end(); ++v_it)
	{
		ConvexShape->addPoint(btVector3(point(v_it.handle())[0],point(v_it.handle())[1],point(v_it.handle())[2]));
	}
	btCollisionShape *ConvexHull = ConvexShape;
	btVector3 localInertia(0.0f,0.0f,0.0f);
	btScalar m(0);
	bool isDynamic = (m != 0.0f);
	if (isDynamic)
		ConvexHull->calculateLocalInertia(m,localInertia);
	btTransform transform;
	transform.setIdentity();
	btDefaultMotionState *myMotionState = new btDefaultMotionState(transform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(m,myMotionState,ConvexHull,localInertia);
	Arms->RigidBody = new btRigidBody(rbInfo);
	Arms->RigidBody->setContactProcessingThreshold(0.0f);
	Physics::DynamicsWorld->addRigidBody(Arms->RigidBody, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::DebrisFilter);
	Arms->RigidBody->setUserPointer(this);
	return this;
}
コード例 #2
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::compute_bounding_box()
{
	if (size_of_vertices()	== 0)
		return;

	float xmin, xmax, ymin, ymax, zmin, zmax;

	Vertex_iterator	pVertex	=	vertices_begin();
	xmin = xmax = pVertex->point().x;
	ymin = ymax = pVertex->point().y;
	zmin = zmax = pVertex->point().z;
	for(;pVertex !=	vertices_end();pVertex++)
	{
		const Vec3& p = pVertex->point();
		xmin	=	qMin(xmin,p.x);
		ymin	=	qMin(ymin,p.y);
		zmin	=	qMin(zmin,p.z);
		xmax	=	qMax(xmax,p.x);
		ymax	=	qMax(ymax,p.y);
		zmax	=	qMax(zmax,p.z);
	}

	m_min = Vec3(xmin, ymin, zmin);
	m_max = Vec3(xmax, ymax, zmax);
	m_diagLength = Vec3::distance(m_min, m_max);
	m_axisLength = Vec3(m_min, m_max);
	m_minMaxCenter = (m_min + m_max) / 2.0f;
}
コード例 #3
0
ファイル: Character.cpp プロジェクト: crcsaenz/shad
Character *Character::GenerateCharacter() {
	btConvexHullShape *ConvexShape = new btConvexHullShape();
	for(VertexIter v_it = vertices_begin(); v_it != vertices_end(); ++v_it)
	{
		ConvexShape->addPoint(btVector3(point(v_it.handle())[0],point(v_it.handle())[1],point(v_it.handle())[2]));
	}
	btCollisionShape *ConvexHull = ConvexShape;

	btPairCachingGhostObject * GO = new btPairCachingGhostObject();

	btTransform transform;
	transform.setIdentity();
	GO->setWorldTransform(transform);
	GO->setCollisionShape(ConvexHull);
	GO->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);

	RigidBody = new btKinematicCharacterController(GO, ConvexShape, 0.35);
	Physics::DynamicsWorld->addCollisionObject(GO, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
	Physics::DynamicsWorld->addAction(RigidBody);
	
	btVector3 localInertia(0.0f,0.0f,0.0f);
	btScalar m(0.0f);
	transform = RigidBody->getGhostObject()->getWorldTransform();
	btDefaultMotionState *myMotionState = new btDefaultMotionState(transform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo(m,myMotionState,ConvexHull,localInertia);
	Dummy = new btRigidBody(rbInfo);
	Dummy->setContactProcessingThreshold(0.05f);
	Physics::DynamicsWorld->addRigidBody(Dummy, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::DebrisFilter);
	Dummy->setUserPointer(this);
	return this;
}
コード例 #4
0
ファイル: Stroke.cpp プロジェクト: dfelinto/blender
int Stroke::qi() const
{
  const_vertex_iterator v = vertices_begin(), vend = vertices_end();
  int qi_ = (*v)->qi();
  for (; v != vend; ++v) {
    if ((*v)->qi() != qi_)
      Exception::raiseException();
  }
  return qi_;
}
コード例 #5
0
ファイル: Curve.cpp プロジェクト: diekev/blender
int Curve::shape_id() const
{
	const_vertex_iterator v = vertices_begin(), vend = vertices_end();
	Id id = (*v)->shape_id();
	for (; v != vend; ++v) {
		if ((*v)->shape_id() != id)
			Exception::raiseException();
	}
	return id.first;
}
コード例 #6
0
ファイル: Curve.cpp プロジェクト: diekev/blender
Material Curve::material() const
{
	const_vertex_iterator v = vertices_begin(), vend = vertices_end();
	const Material& mat = (*v)->material();
	for (; v != vend; ++v) {
		if ((*v)->material() != mat)
			Exception::raiseException();
	}
	return mat;
}
コード例 #7
0
ファイル: Stroke.cpp プロジェクト: dfelinto/blender
const bool Stroke::occludee_empty() const
{
  const_vertex_iterator v = vertices_begin(), vend = vertices_end();
  bool empty = (*v)->occludee_empty();
  for (; v != vend; ++v) {
    if ((*v)->occludee_empty() != empty)
      Exception::raiseException();
  }
  return empty;
}
コード例 #8
0
ファイル: Stroke.cpp プロジェクト: dfelinto/blender
const SShape *Stroke::shape() const
{
  const_vertex_iterator v = vertices_begin(), vend = vertices_end();
  const SShape *sshape = (*v)->shape();
  for (; v != vend; ++v) {
    if ((*v)->shape() != sshape)
      Exception::raiseException();
  }
  return sshape;
}
コード例 #9
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::commitRemove()
{
	// first go over all the points and tell them where they go
	int count = 0;
	for(int i = 0; i < numVtx(); ++i)
	{
		Vertex_handle v = find_vertex(i);
		if (v->m_tran == -1)
			v->m_index = count++;
		else
			v->m_index = -1; // to be removed
		v->m_tran = -1;
	}
	// no go over the faces and transfer their point references
	count = 0;
	for(int i = 0; i < numFaces(); ++i)
	{
		Face_handle f = find_facet(i);
		bool remove = false;
		for(int ii = 0; ii < f->size(); ++ii)
		{
			int newvi = find_vertex(f->m_pi[ii])->m_index;
			f->m_pi[ii] = newvi;
			remove |= (newvi == -1);
		}
		if (!remove)
			f->m_index = count++;
		else 
			f->m_index = -1;
	}
	// actually remove the vertices
	Vertex_iterator vit = vertices_begin();
	while(vit != vertices_end())
	{
		if (vit->m_index == -1)
			vit = m_vtx.erase(vit);
		else
			++vit;
	}

	// remove faces
	Face_iterator fit = faces_begin();
	while(fit != faces_end())
	{
		if (fit->m_index == -1)
			fit = m_face.erase(fit);
		else
			++fit;
	}
}
コード例 #10
0
ファイル: Surface_mesh.cpp プロジェクト: ShiYujin/zju_code
void
Surface_mesh::
update_vertex_normals()
{
    if (!vnormal_)
        vnormal_ = vertex_property<Normal>("v:normal");

    Vertex_iterator vit, vend=vertices_end();

    for (vit=vertices_begin(); vit!=vend; ++vit)
	{
        if (!is_deleted(vit))
            vnormal_[vit] = compute_vertex_normal(vit);
    }
}
コード例 #11
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::transformVertices(const TrMatrix& tr)
{
	for(Vertex_iterator it = vertices_begin(); it != vertices_end(); ++it)
	{
		Vec3& p = it->m_p;
		p = tr.multVec(Vec4(p)).toVec();
	}

	// do some of the things done in finalize since all points were changed.
	compute_normals_per_facet();
	compute_normals_per_vertex();
	compute_bounding_box();	
	compute_triangle_surfaces();	
	centerOfMass();
}
コード例 #12
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::reverseNormals()
{
	Mesh::Vertex_iterator vit = vertices_begin();
	Mesh::Vertex_iterator vit_end = vertices_end();

	for (;vit != vit_end; vit++) {
		vit->normal() *= -1.0f;
	}

	Mesh::Face_iterator fit = faces_begin();
	Mesh::Face_iterator fit_end = faces_end();

	for (;fit != fit_end; fit++) {
		fit->normal() *= -1.0f;
	}
}
コード例 #13
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::dijkstra(Mesh::Vertex_handle v)
{
	for (Mesh::Vertex_iterator it = vertices_begin(); it != vertices_end(); ++it)
	{
		it->distance(FLT_MAX);
		//it->m_visited = false;
	}

	TVertexDistanceHeap vdh;

	int sanityCounter = 0;

	v->distance(0.0);	
	vdh.push(v);
	do {
		Mesh::Vertex_handle t = vdh.top();
		vdh.pop();
		//t->visited = true;

		TIndexList vnei = t->neiVertices();

		for (int vii = 0; vii < vnei.size(); ++vii)
		{
			Mesh::Vertex_handle n = find_vertex(vnei[vii]);
			float alt = t->distance() + Vec3::distance(t->point(), n->point());
			if (alt < n->distance()) 
			{
				n->distance() = alt;
				// we don't have the edge
				// not using closeness.
				vdh.push(n);
			}
		}

		sanityCounter++;

// 		if (sanityCounter > size_of_vertices() * 2)
// 		{
// 			printf("dijkstra sanity failed!\n");
// 			break;
// 		}
	} while (!vdh.empty());
}
コード例 #14
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::normalizeByComponents()
{
	vertexSet_t allVertices;	

	for (Mesh::Vertex_iterator vit = vertices_begin(); vit != vertices_end(); vit++) {
		vit->tag(0);
		allVertices.insert(vit);
	}	

	do {
		Mesh::Vertex_handle v = *allVertices.begin();
		vertexSet_t connectedGroup;
		int groupSize = growFrom(v, connectedGroup);

		float featureMin = FLT_MAX;
		float featureMax = -FLT_MAX;

		for (vertexSet_t::iterator it = connectedGroup.begin(); it != connectedGroup.end(); it++)
		{
			allVertices.erase(*it);

			float val;
			if (m_feature == FEATURE_VOLUME) 
				val = (*it)->volume();
			else
				val = (*it)->centricity();

			if (val < featureMin) 
				featureMin = val;
			if (val > featureMax)
				featureMax = val;
		}

		for (vertexSet_t::iterator it = connectedGroup.begin(); it != connectedGroup.end(); it++)
		{
			if (m_feature == FEATURE_VOLUME) 
				(*it)->volume() = ((*it)->volume() - featureMin) / (featureMax - featureMin);
			else
				(*it)->centricity() = ((*it)->centricity() - featureMin) / (featureMax - featureMin);
		}
	} while (allVertices.size());
}
コード例 #15
0
ファイル: HepMCHistograms.cpp プロジェクト: cgracios/FCCSW
StatusCode HepMCHistograms::execute() {

	auto evt = m_hepmchandle.get();

	info() << "Processing event with " << evt->particles_size() << " particles" << endmsg;

	for (auto it = evt->particles_begin(); it != evt->particles_end(); ++it) {
		auto particle = *it;

		m_eta->Fill(particle->momentum().eta());
		m_pt->Fill(particle->momentum().perp());
	}

	for(auto it = evt->vertices_begin(); it != evt->vertices_end(); ++it) {
		auto vertex = *it;

		m_d0->Fill(vertex->position().perp());
		m_z0->Fill(vertex->position().z());
	}

	return StatusCode::SUCCESS;
}
コード例 #16
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::calcDotCurve()
{
	m_vtxDotCurve.resize(numVtx());
	for(Vertex_iterator it = vertices_begin(); it != vertices_end(); ++it)
	{
		Vertex_handle vh = &*it;
		TIndexList nei = vh->neiVertices();
		int negdot = 0;
		float dotsum = 0.0f;
		for(int i = 0; i < nei.size(); ++i)
		{
			Vertex_handle vc = find_vertex(nei[i]);
			Vec3 vv = vc->point() - vh->point();
			vv.unitize();
		//	if (Vec3::dotProd(vv, vh->normal()) < 0.0f)
		//		++negdot;
			dotsum += Vec3::dotProd(vv, vh->normal());
		}
		//vh->dotCurve() = (((float)nei.size() / 2.0) - negdot) / (float)nei.size();
		vh->dotCurve() = dotsum;
		
	}

}
コード例 #17
0
ファイル: utils.cpp プロジェクト: pvallet/CGA_interpreter
PwhPtr CstmCGAL::applyOffset(double offset, const Polygon_with_holes_2& poly) {

    // This code is inspired from the CGAL example Straight_skeleton_2/Low_level_API
    // As the offset can only produce an interior polygon, we need to produce a frame
    // that encloses the polygon and is big enough so that the offset of the contour
    // does not interfere with the one ot the polygon. See CGAL doc page for more info
    boost::optional<double> margin = CGAL::compute_outer_frame_margin(
                                         poly.outer_boundary().vertices_begin(),poly.outer_boundary().vertices_end(),offset);

    if ( margin ) {

        CGAL::Bbox_2 bbox = CGAL::bbox_2(poly.outer_boundary().vertices_begin(),poly.outer_boundary().vertices_end());

        double fxmin = bbox.xmin() - *margin ;
        double fxmax = bbox.xmax() + *margin ;
        double fymin = bbox.ymin() - *margin ;
        double fymax = bbox.ymax() + *margin ;

        // Create the rectangular frame
        Point_2 frame[4]= { Point_2(fxmin,fymin)
                            , Point_2(fxmax,fymin)
                            , Point_2(fxmax,fymax)
                            , Point_2(fxmin,fymax)
                          } ;

        SsBuilder ssb ;

        ssb.enter_contour(frame,frame+4);

        // We have to revert the orientation of the polygon
        std::vector<Point_2> outerBoundary = std::vector<Point_2>(
                poly.outer_boundary().vertices_begin(),poly.outer_boundary().vertices_end());

        ssb.enter_contour(outerBoundary.rbegin(), outerBoundary.rend());

        SsPtr ss = ssb.construct_skeleton();

        if ( ss ) {
            std::vector<Polygon_2Ptr> offset_contours ;

            OffsetBuilder ob(*ss);

            ob.construct_offset_contours(offset, std::back_inserter(offset_contours));

            // Locate the offset contour that corresponds to the frame
            // That must be the outmost offset contour, which in turn must be the one
            // with the largest unsigned area.
            std::vector<Polygon_2Ptr>::iterator f = offset_contours.end();
            double lLargestArea = 0.0 ;
            for (std::vector<Polygon_2Ptr>::iterator i = offset_contours.begin(); i != offset_contours.end(); ++ i) {
                double lArea = CGAL_NTS abs( (*i)->area() ) ; //Take abs() as  Polygon_2::area() is signed.
                if ( lArea > lLargestArea ) {
                    f = i ;
                    lLargestArea = lArea ;
                }
            }

            offset_contours.erase(f);

            // Construct result polygon

            std::vector<Point_2> newOuterBoundary = std::vector<Point_2>(
                    offset_contours.front()->vertices_begin(), offset_contours.front()->vertices_end());

            Polygon_with_holes_2 result = Polygon_with_holes_2(Polygon_2(newOuterBoundary.rbegin(), newOuterBoundary.rend()));

            // We have to handle the holes separately

            for (auto it = poly.holes_begin() ; it != poly.holes_end() ; it++) {
                std::vector<Point_2> hole = std::vector<Point_2>(it->vertices_begin(),it->vertices_end());

                std::vector<PwhPtr> holeOffsets =
                    CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2(offset,
                            Polygon_with_holes_2(Polygon_2(hole.begin(), hole.end())));

                for (auto it2 = holeOffsets.begin() ; it2 != holeOffsets.end() ; it++) {
                    std::vector<Point_2> revertNewHoles = std::vector<Point_2>(
                            (*it2)->outer_boundary().vertices_begin(),(*it2)->outer_boundary().vertices_end());

                    result.add_hole(Polygon_2(revertNewHoles.rbegin(), revertNewHoles.rend()));
                }
            }

            return boost::make_shared<Polygon_with_holes_2>(result);
        }
    }

    return NULL;
}
コード例 #18
0
void test( const std::string & meshFile )
{
   auto mesh = make_shared< MeshType >();
   mesh::readAndBroadcast( meshFile, *mesh);

   auto aabb = computeAABB( *mesh );

   using Scalar = typename MeshType::Scalar;

   Vector3<Scalar> translation( numeric_cast<Scalar>( aabb.xSize() ) * Scalar(2) * Scalar( MPIManager::instance()->rank() ), Scalar(0), Scalar(0) );
   translate( *mesh, translation );

   mesh->request_face_normals();
   mesh->request_vertex_normals();
   mesh->update_normals();

   mesh->request_face_status();

   bool b = true;
   for( auto it = mesh->faces_begin(); it != mesh->faces_end(); ++it )
   {
      mesh->status( *it ).set_tagged( b );
      b =  !b;
   }

   mesh->request_vertex_status();

   b = true;
   for( auto it = mesh->vertices_begin(); it != mesh->vertices_end(); ++it )
   {
      mesh->status( *it ).set_tagged( b );
      b = !b;
   }

   std::vector< typename MeshType::Color > colors;
   colors.push_back( typename MeshType::Color( 255,0,0 ) );
   colors.push_back( typename MeshType::Color( 0,255,0 ) );
   colors.push_back( typename MeshType::Color( 0,0,255 ) );
   auto colorIt = colors.begin();

   mesh->request_vertex_colors();
   for( auto it = mesh->vertices_begin(); it != mesh->vertices_end(); ++it )
   {
      mesh->set_color( *it, *colorIt );

      ++colorIt;
      if( colorIt == colors.end() )
         colorIt = colors.begin();
   }

   mesh->request_face_colors();
   for( auto it = mesh->faces_begin(); it != mesh->faces_end(); ++it )
   {
      mesh->set_color( *it, *colorIt );

      ++colorIt;
      if( colorIt == colors.end() )
         colorIt = colors.begin();
   }

   DistributedVTKMeshWriter< MeshType > meshWriter( mesh, "distributed_mesh_vtk_test_unfiltered", 1 );
   meshWriter.addDataSource( make_shared< NormalsVertexDataSource< MeshType > >() );
   meshWriter.addDataSource( make_shared< NormalsFaceDataSource  < MeshType > >() );

   meshWriter.addDataSource( make_shared< AreaFaceDataSource     < MeshType > >() );

   meshWriter.addDataSource( make_shared< StatusBitFaceDataSource  < MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );
   meshWriter.addDataSource( make_shared< StatusBitVertexDataSource< MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );

   meshWriter.addDataSource( make_shared< ColorFaceDataSource  < MeshType > >() );
   meshWriter.addDataSource( make_shared< ColorVertexDataSource< MeshType > >() );

   meshWriter.addDataSource( make_shared< IndexFaceDataSource  < MeshType > >() );
   meshWriter.addDataSource( make_shared< IndexVertexDataSource< MeshType > >() );

   meshWriter.addDataSource( make_shared< RankFaceDataSource  < MeshType > >() );
   meshWriter.addDataSource( make_shared< RankVertexDataSource< MeshType > >() );

   meshWriter();


   DistributedVTKMeshWriter< MeshType > meshWriterAABBfiltered( mesh, "distributed_mesh_vtk_test_aabb_filter", 1 );
   meshWriterAABBfiltered.addDataSource( make_shared< NormalsVertexDataSource< MeshType > >() );
   meshWriterAABBfiltered.addDataSource( make_shared< NormalsFaceDataSource  < MeshType > >() );

   meshWriterAABBfiltered.addDataSource( make_shared< AreaFaceDataSource     < MeshType > >() );

   meshWriterAABBfiltered.addDataSource( make_shared< StatusBitFaceDataSource  < MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );
   meshWriterAABBfiltered.addDataSource( make_shared< StatusBitVertexDataSource< MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );

   meshWriterAABBfiltered.addDataSource( make_shared< ColorFaceDataSource  < MeshType > >() );
   meshWriterAABBfiltered.addDataSource( make_shared< ColorVertexDataSource< MeshType > >() );

   meshWriterAABBfiltered.addDataSource( make_shared< IndexFaceDataSource  < MeshType > >() );
   meshWriterAABBfiltered.addDataSource( make_shared< IndexVertexDataSource< MeshType > >() );

   meshWriterAABBfiltered.addDataSource( make_shared< RankFaceDataSource  < MeshType > >() );
   meshWriterAABBfiltered.addDataSource( make_shared< RankVertexDataSource< MeshType > >() );

   meshWriterAABBfiltered.setFaceFilter( mesh::AABBFaceFilter< MeshType >(aabb) );

   meshWriterAABBfiltered();


   DistributedVTKMeshWriter< MeshType > meshWriterStatusfiltered( mesh, "distributed_mesh_vtk_test_status_filter", 1 );
   meshWriterStatusfiltered.addDataSource( make_shared< NormalsVertexDataSource< MeshType > >() );
   meshWriterStatusfiltered.addDataSource( make_shared< NormalsFaceDataSource  < MeshType > >() );

   meshWriterStatusfiltered.addDataSource( make_shared< AreaFaceDataSource     < MeshType > >() );

   meshWriterStatusfiltered.addDataSource( make_shared< StatusBitFaceDataSource  < MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );
   meshWriterStatusfiltered.addDataSource( make_shared< StatusBitVertexDataSource< MeshType > >( OpenMesh::Attributes::TAGGED, "tagged" ) );

   meshWriterStatusfiltered.addDataSource( make_shared< ColorFaceDataSource  < MeshType > >() );
   meshWriterStatusfiltered.addDataSource( make_shared< ColorVertexDataSource< MeshType > >() );

   meshWriterStatusfiltered.addDataSource( make_shared< IndexFaceDataSource  < MeshType > >() );
   meshWriterStatusfiltered.addDataSource( make_shared< IndexVertexDataSource< MeshType > >() );

   meshWriterStatusfiltered.addDataSource( make_shared< RankFaceDataSource  < MeshType > >() );
   meshWriterStatusfiltered.addDataSource( make_shared< RankVertexDataSource< MeshType > >() );

   meshWriterStatusfiltered.setFaceFilter( mesh::StatusFaceFilter< MeshType >( OpenMesh::Attributes::TAGGED ) );

   meshWriterStatusfiltered();
}
コード例 #19
0
ファイル: Curve.cpp プロジェクト: diekev/blender
occluder_container::const_iterator Curve::occluders_end() const
{
	const_vertex_iterator v = vertices_end();
	return (*v)->occluders_end();
}
コード例 #20
0
ファイル: Mesh.cpp プロジェクト: shooshx/kawaiigl
void Mesh::computeCentricity(QWidget* guiParent)
{
	//	float maxCentricity = -FLT_MAX;
	//	float minCentricity = FLT_MAX;

	QProgressDialog *prog = NULL;
	if (guiParent)
		prog = new QProgressDialog("Building centricity", "Stop", 0, numVtx(), guiParent);
		
	int counter = 0;
	int total = size_of_vertices();
	for (Mesh::Vertex_iterator it = vertices_begin(); it != vertices_end(); ++it)
	{
		if (guiParent)
		{
			prog->setValue(counter);
			QCoreApplication::processEvents();
			if (prog->wasCanceled())
				return;
		}


		counter++;

		double distanceSum = 0.0;
		int count = 0;

		dijkstra(&*it);

		for (Mesh::Vertex_iterator n = vertices_begin(); n != vertices_end(); ++n)
		{
			if (n->distance() != FLT_MAX) 
			{
				count++;
				distanceSum += n->distance();
			}
		}
		it->centricity(distanceSum/(double)count);

		//	if (it->centricity() > maxCentricity) maxCentricity = it->centricity();
		//	if (it->centricity() < minCentricity) minCentricity = it->centricity();
		//	printf("%d = %f\n", counter, it->centricity());
	}

	delete prog;


	//if (m_normalize ) 
	//{
	//report("normalizing values");
	/*for (Mesh::Vertex_iterator it = m_mesh->vertices_begin();
	it != m_mesh->vertices_end(); 
	it++)
	{
	if (it->centricity() != FLT_MAX)
	it->centricity() = (it->centricity() - minCentricity) / (maxCentricity - minCentricity);
	}*/
	//normalizeByComponents();
	//}

	// facet centricity is the average of the vertices.

	float featureMin = FLT_MAX;
	float featureMax = -FLT_MAX;

	for (Mesh::Face_iterator fit = faces_begin(); fit != faces_end(); ++fit)
	{
		Face_handle fh = &*fit;
		float val = 0.0;
		for(int fii = 0; fii < fh->size(); ++fii)
		{
			Vertex_handle cv = fh->vertex(fii);
			val += cv->centricity();
		}
		val /= fh->size();

		fh->centricity() = val;

		if (val < featureMin) 
			featureMin = val;
		if (val > featureMax)
			featureMax = val;
	}

	float divwith = 1.0 / (featureMax - featureMin);
	for (Mesh::Face_iterator fit = faces_begin(); fit != faces_end(); ++fit)
	{
		Face_handle fh = &*fit;
		fh->centricity() = (fh->centricity() - featureMin) * divwith;
	}

	m_hasCentricity = true;
}
コード例 #21
0
ファイル: Curve.cpp プロジェクト: diekev/blender
void Curve::computeCurvatureAndOrientation ()
{
	const_vertex_iterator v = vertices_begin(), vend = vertices_end(), v2, prevV, v0;
	Vec2d p0, p1, p2;
	Vec3r p;

	p = (*v)->point2d();
	p0 = Vec2d(p[0], p[1]);
	prevV = v;
	++v;
	p = (*v)->point2d();
	p1 = Vec2d(p[0], p[1]);
	Vec2d prevDir(p1 - p0);

	for (; v! = vend; ++v) {
		v2 = v;
		++v2;
		if (v2 == vend)
			break;
		Vec3r p2 = (*v2)->point2d();

		Vec2d BA = p0 - p1;
		Vec2d BC = p2 - p1;
		real lba = BA.norm(), lbc = BC.norm();
		BA.normalizeSafe();
		BC.normalizeSafe();
		Vec2d normalCurvature = BA + BC;
		Vec2d dir = Vec2d(BC - BA);
		Vec2d normal = Vec2d(-dir[1], dir[0]);

		normal.normalizeSafe();
		real curvature = normalCurvature * normal;
		if (lba + lbc > MY_EPSILON)
			curvature /= (0.5 * lba + lbc);
		if (dir.norm() < MY_EPSILON)
			dir = 0.1 * prevDir;
		(*v)->setCurvatureFredo(curvature);
		(*v)->setDirectionFredo(dir);

		prevV = v;
		p0 = p1;
		p1 = p2;
		prevDir = dir;
		prevDir.normalize();
	}
	(*v)->setCurvatureFredo((*prevV)->curvatureFredo());
	(*v)->setDirectionFredo((*v)->point2d() - (*prevV)->point2d());
	v0 = vertices_begin();
	v2 = v0;
	++v2;
	(*v0)->setCurvatureFredo((*v2)->curvatureFredo());
	(*v0)->setDirectionFredo((*v2)->point2d() - (*v0)->point2d());

	//closed curve case one day...

	//
	return;

	//numerical degeneracy verification... we'll see later
	const_vertex_iterator vLastReliable = vertices_begin();

	v = vertices_begin();
	p = (*v)->point2d();
	p0 = Vec2d(p[0], p[1]);
	prevV = v;
	++v;
	p = (*v)->point2d();
	p1 = Vec2d(p[0], p[1]);
	bool isReliable = false;
	if ((p1 - p0).norm > EPS_CURVA) {
		vLastReliable = v;
		isReliable = true;
	}

	for (; v != vend; ++v) {
		v2 = v;
		++v2;
		if (v2 == vend)
			break;
		Vec3r p2 = (*v2)->point2d();

		Vec2d BA = p0 - p1;
		Vec2d BC = p2 - p1;
		real lba = BA.norm(), lbc = BC.norm();

		if ((lba + lbc) < EPS_CURVA) {
			isReliable = false;
			cerr << "/";
		}
		else {
			if (!isReliable) {  //previous points were not reliable
				const_vertex_iterator vfix = vLastReliable;
				++vfix;
				for (; vfix != v; ++vfix) {
					(*vfix)->setCurvatureFredo((*v)->curvatureFredo());
					(*vfix)->setDirectionFredo((*v)->directionFredo());
				}
			}
			isReliable = true;
			vLastReliable = v;
		}
		prevV = v;
		p0 = p1;
		p1 = p2;
	}
}