Example #1
0
File: poly.c Project: endvroy/poly
Term *term_new(double coef, int expo)
{
	Term *elmt;
	elmt = list_elmt_new(malloc(sizeof(DataType)));
	poly_data(elmt)->coef = coef;
	poly_data(elmt)->expo = expo;
	return elmt;
}
Example #2
0
File: poly.c Project: endvroy/poly
void poly_prn(Poly *poly)
{
	int firstPrn = 1;
	Term *term;
	for (term = poly->head; term != NULL; term = term->next)
	{
		if (firstPrn == 1)
		{
			if (poly_data(term)->expo != 0)
			{
				printf("%.1fx%d ", poly_data(term)->coef, poly_data(term)->expo);
			}
			else
			{
				printf("%.1f ", poly_data(term)->coef);
			}
			firstPrn = 0;
		}
		else
		{
			if (poly_data(term)->expo != 0)
			{
				printf("%c %.1fx%d ", poly_data(term)->coef >= 0 ? '+' : '-', fabs(poly_data(term)->coef), poly_data(term)->expo);
			}
			else
			{
				printf("%c %.1f ", poly_data(term)->coef >= 0 ? '+' : '-', fabs(poly_data(term)->coef));
			}
		}
	}
	printf("\n");
}
Example #3
0
File: poly.c Project: endvroy/poly
Poly *poly_term_multi(Poly *poly, Term *term)
{
	Poly *retPoly;
	Term *iter;   //iterator
	retPoly = poly_new(); // the return polynomial
	for (iter = poly->head; iter != NULL; iter = iter->next)
	{
		poly_add_term(retPoly, term_new(poly_data(iter)->coef * poly_data(term)->coef, poly_data(iter)->expo + poly_data(term)->expo));
	}
	return retPoly;
}
Example #4
0
int
main()
{
  std::vector<Polyhedron> polys = poly_data();

  BOOST_FOREACH(Polyhedron p, polys){
    index_uniqueness_poly(p);
  }
Example #5
0
void DebugViewer::renderMeshset( const carve::mesh::MeshSet<3>* meshset, const osg::Vec4f& color, const bool wireframe )
{
	if( !meshset )
	{
		return;
	}
	if( meshset->meshes.size() < 1 )
	{
		return;
	}

	std::stringstream strs_err;
	ConverterOSG::checkMeshSet( meshset, strs_err, -1 );
	
	osg::ref_ptr<osg::Geode> geode = new osg::Geode();
	if( wireframe )
	{
		osg::ref_ptr<osg::PolygonMode> polygon_mode = new osg::PolygonMode();
		polygon_mode->setMode(  osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE );
		geode->getOrCreateStateSet()->setAttribute( polygon_mode );
	}
	osg::Material* material = new osg::Material();//(osg::Material *) geode->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL); 
	material->setColorMode(osg::Material::EMISSION); 
	material->setEmission(osg::Material::FRONT_AND_BACK, color ); 
	geode->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE); 

	ConverterOSG::drawMeshSet( meshset, geode );
	m_view_controller->getModelNode()->addChild(geode);

	osg::ref_ptr<osg::Geode> geode_vertex_numbers = new osg::Geode();
	m_view_controller->getModelNode()->addChild(geode_vertex_numbers);

	shared_ptr<carve::poly::Polyhedron> poly_from_mesh( carve::polyhedronFromMesh(meshset, -1) );
	if( poly_from_mesh )
	{
		shared_ptr<carve::input::PolyhedronData> poly_data( new carve::input::PolyhedronData() );
		for( int i=0; i<poly_from_mesh->vertices.size(); ++i )
		{
			poly_data->addVertex( poly_from_mesh->vertices[i].v );
		}
		for( int i=0; i<poly_from_mesh->faces.size(); ++i )
		{
			carve::poly::Face<3>& f = poly_from_mesh->faces[i];
			if( f.nVertices() == 3 )
			{
				poly_data->addFace( poly_from_mesh->vertexToIndex( f.vertex(0) ), poly_from_mesh->vertexToIndex( f.vertex(1) ), poly_from_mesh->vertexToIndex( f.vertex(2) ) );
			}
			else if( f.nVertices() == 4 )
			{
				poly_data->addFace( poly_from_mesh->vertexToIndex( f.vertex(0) ), poly_from_mesh->vertexToIndex( f.vertex(1) ), poly_from_mesh->vertexToIndex( f.vertex(2) ), poly_from_mesh->vertexToIndex( f.vertex(3) ) );
			}
		}

		drawVertexNumbers( poly_data.get(), color, geode_vertex_numbers );
	}

	m_viewer_widget->getViewer().frame();
}
Example #6
0
File: poly.c Project: endvroy/poly
Poly *poly_sub(Poly *poly1, Poly *poly2)    //return poly1-poly2
{
	Poly *poly;
	Term *term1, *term2;
	term1 = poly1->head;
	term2 = poly2->head;
	poly = poly_new();
	while (term1 != NULL && term2 != NULL)
	{
		if (poly_data(term1)->expo > poly_data(term2)->expo)
		{
			poly_add_term(poly, term_new(poly_data(term1)->coef, poly_data(term1)->expo));
			term1 = term1->next;
		}
		else if (poly_data(term1)->expo == poly_data(term2)->expo)
		{
			if (poly_data(term1)->coef - poly_data(term2)->coef != 0)
				poly_add_term(poly, term_new(poly_data(term1)->coef - poly_data(term2)->coef, poly_data(term1)->expo));
			term1 = term1->next;
			term2 = term2->next;
		}
		else
		{
			poly_add_term(poly, term_new(-poly_data(term2)->coef, poly_data(term2)->expo));
			term2 = term2->next;
		}
	}

	if (term1 == NULL)
	{
		while (term2 != NULL)
		{
			poly_add_term(poly, term_new(-poly_data(term2)->coef, poly_data(term2)->expo));
			term2 = term2->next;
		}
	}
	else if (term2 == NULL)
	{
		while (term1 != NULL)
		{
			poly_add_term(poly, term_new(poly_data(term1)->coef, poly_data(term1)->expo));
			term1 = term1->next;
		}
	}
	return poly;
}