示例#1
0
Node* CylinderSurfaceModule::evaluate(Context* ctx)
{
	NumberValue* heightValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	decimal h=1.0;
	if(heightValue)
		h=heightValue->getNumber();

	NumberValue* rValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1));
	decimal r=1.0;
	if(rValue)
		r=rValue->getNumber();

	Value* centerValue=getParameterArgument(ctx,2);
	bool center=false;

	if(centerValue)
		center=centerValue->isTrue();

	decimal z1,z2;
	z1 = 0.0;
	z2 = h;

	Fragment* fg = Fragment::createFragment(ctx);
	int f = fg->getFragments(r);
	delete fg;

	QList<Point> c1=getCircle(r,f,z1);
	QList<Point> c2=getCircle(r,f,z2);

	PrimitiveNode* p=new PrimitiveNode(reporter);
	p->setChildren(ctx->getInputNodes());

	foreach(Point pt,c1) {
		p->createVertex(pt);
	}
示例#2
0
Node* CylinderModule::evaluate(Context* ctx)
{
	NumberValue* heightValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	decimal h=1.0;
	if(heightValue)
		h=heightValue->getNumber();

	NumberValue* r1Value = dynamic_cast<NumberValue*>(ctx->getArgument(1,"radius1"));
	NumberValue* r2Value = dynamic_cast<NumberValue*>(ctx->getArgument(2,"radius2"));
	BooleanValue* centerValue;

	decimal r1=1.0,r2=1.0;
	if(!r1Value) {
		NumberValue* rValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1));
		centerValue = dynamic_cast<BooleanValue*>(getParameterArgument(ctx,2));
		if(rValue) {
			r1=r2=rValue->getNumber();
		} else {
			NumberValue* dValue = dynamic_cast<NumberValue*>(ctx->getArgument(1,"diameter"));
			if(dValue)
				r1=r2=(dValue->getNumber()/2.0);
		}
	} else {
		if(r1Value)
			r1=r1Value->getNumber();
		if(r2Value)
			r2=r2Value->getNumber();
		else
			r2=r1;
		centerValue = dynamic_cast<BooleanValue*>(ctx->getArgument(3,"center"));
	}
	bool center = false;
	if(centerValue)
		center=centerValue->isTrue();

	decimal z1,z2;
	z1 = 0.0;
	z2 = h;

	decimal r=fmax(r1,r2);
	Fragment fg=getSpecialVariables(ctx);
	int f = fg.getFragments(r);

	QList<Point> c1=getCircle(r1,f,z1);
	QList<Point> c2=getCircle(r2,f,z2);

	PrimitiveNode* p = new PrimitiveNode();

	int n=0;
	Polygon* pg;
	if(r1>0) {
		pg=p->createPolygon();
		foreach(Point pt,c1) {
			p->createVertex(pt);
			pg->append(n++);
		}
Node* CylinderSurfaceModule::evaluate(Context* ctx)
{
	NumberValue* heightValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	double h=1.0;
	if(heightValue)
		h=heightValue->getNumber();

	NumberValue* rValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1));
	double r=1.0;
	if(rValue)
		r=rValue->getNumber();

	Value* centerValue=getParameterArgument(ctx,2);
	bool center=false;
	if(centerValue)
		center=centerValue->isTrue();

	double z1,z2;
	if(center) {
		z1 = -h/2;
		z2 = +h/2;
	} else {
		z1 = 0.0;
		z2 = h;
	}

	int f = getFragments(r,ctx);
	Polygon c1 = getCircle(r,f,z1);
	Polygon c2 = getCircle(r,f,z2);
	PrimitiveNode* p = new PrimitiveNode();

	for(int i=0; i<f; i++) {
		int j=(i+1)%f;
		p->createPolygon();
		p->appendVertex(c1.at(i));
		p->appendVertex(c2.at(i));
		p->appendVertex(c2.at(j));
		p->appendVertex(c1.at(j));
	}

	return p;
}
示例#4
0
文件: worker.cpp 项目: UIKit0/RapCAD
void Worker::generation()
{
	Script* s=parse("reprap.rcam",NULL,true);

	TreeEvaluator* e = new TreeEvaluator(reporter);
	decimal height=getBoundsHeight();
	QList<Argument*> args=getArgs(height);
	Callback* c = addCallback("layers",s,args);
	s->accept(*e);

	NumberValue* v = dynamic_cast<NumberValue*>(c->getResult());
	if(v) {
		reporter->reportMessage(tr("Layers: %1").arg(v->getValueString()));

		int itterations=v->getNumber();
		Instance* m=addProductInstance("manufacture",s);
		for(int i=0; i<=itterations; i++) {
			if(i>0) {
				e = new TreeEvaluator(reporter);
			}
			reporter->reportMessage(tr("Manufacturing layer: %1").arg(i));

			QList<Argument*> args=getArgs(i);
			m->setArguments(args);

			s->accept(*e);
			Node* n=e->getRootNode();

			NodeEvaluator* ne = new NodeEvaluator(reporter);
			n->accept(*ne);
			delete n;

			primitive=ne->getResult();
			delete ne;

			update();
		}
	}
	delete e;
	delete s;
}
示例#5
0
Node* SphereModule::evaluate(Context* ctx)
{
	NumberValue* rValue=dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	Value* centerValue=getParameterArgument(ctx,1);

	bool center=true;
	if(centerValue)
		center=centerValue->isTrue();

	double r=1.0;
	if(rValue) {
		r=rValue->getNumber();
	} else {
		NumberValue* dValue = dynamic_cast<NumberValue*>(ctx->getArgument(0,"diameter"));
		if(dValue)
			r=(dValue->getNumber()/2.0);
	}

	int f = getFragments(r,ctx);
	int ringCount=f/2;

	QList<Polygon> rings;
	for(int i=0; i<ringCount; i++) {
		double phi = (M_PI*(i+0.5)) / ringCount;
		double r2 = r*sin(phi);
		double z = r*cos(phi)+!center*r;
		Polygon c = getCircle(r2,f,z);
		rings.append(c);
	}

	PrimitiveNode* p = new PrimitiveNode();

	p->createPolygon();
	for(int i=0; i<f; i++)
		p->appendVertex(rings.at(0).at(i));

	for(int i = 0; i < ringCount-1; i++) {
		Polygon r1 = rings.at(i);
		Polygon r2 = rings.at(i+1);
		int r1i = 0, r2i = 0;
		while(r1i < f || r2i < f) {
			if(r1i >= f)
				goto next_r2;
			if(r2i >= f)
				goto next_r1;
			if((double)r1i / f <
					(double)r2i / f) {
next_r1:
				p->createPolygon();
				int r1j = (r1i+1) % f;
				p->prependVertex(r1.at(r1i));
				p->prependVertex(r1.at(r1j));
				p->prependVertex(r2.at(r2i % f));
				r1i++;
			} else {
next_r2:
				p->createPolygon();
				int r2j = (r2i+1) % f;
				p->appendVertex(r2.at(r2i));
				p->appendVertex(r2.at(r2j));
				p->appendVertex(r1.at(r1i % f));
				r2i++;
			}
		}
	}

	p->createPolygon();
	for(int i=0; i<f; i++)
		p->prependVertex(rings.at(ringCount-1).at(i));

	return p;
}
示例#6
0
Node* ConeModule::evaluate(Context* ctx)
{
	NumberValue* heightValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	NumberValue* r1Value = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1));
	NumberValue* r2Value = dynamic_cast<NumberValue*>(getParameterArgument(ctx,2));
	Value* centerValue = getParameterArgument(ctx,3);

	decimal h=1.0;
	if(heightValue)
		h=heightValue->getNumber();

	decimal r1=0,r2=0;
	if(r1Value)
		r1=r1Value->getNumber();
	if(r2Value)
		r2=r2Value->getNumber();

	bool center = false;
	if(centerValue)
		center=centerValue->isTrue();

	decimal z1,z2;
	z1 = 0.0;
	z2 = h;

	Fragment fg=getSpecialVariables(ctx);
	decimal r=fmax(r1,r2);
	int f = fg.getFragments(r);

	Polygon* p1 = getCircle(r1,f,z1);
	Polygon* p2 = getCircle(r2,f,z2);

	QList<Point> c1=p1->getPoints();
	QList<Point> c2=p2->getPoints();

	PrimitiveNode* p = new PrimitiveNode();

	if(r1 > 0) {
		p->createPolygon();
		foreach(Point pt, c1)
			p->appendVertex(pt);
	}

	if(h==0.0)
		return p;

	for(int i=0; i<f; i++) {
		int j=(i+1)%f;
		if(r1 > 0) {
			p->createPolygon();
			p->appendVertex(c1.at(i));
			p->appendVertex(c2.at(i));
			p->appendVertex(c1.at(j));
		}
		if(r2 > 0) {
			p->createPolygon();
			p->appendVertex(c2.at(i));
			p->appendVertex(c2.at(j));
			p->appendVertex(c1.at(j));
		}
	}

	if(r2 > 0) {
		p->createPolygon();
		foreach(Point pt,c2)
			p->prependVertex(pt);
	}

	if(center) {
		AlignNode* n=new AlignNode();
		n->setCenter(true);
		n->addChild(p);
		return n;
	}

	return p;
}
示例#7
0
Node* SphereModule::evaluate(Context* ctx)
{
	NumberValue* rValue=dynamic_cast<NumberValue*>(getParameterArgument(ctx,0));
	Value* centerValue=getParameterArgument(ctx,1);

	bool center=true;
	if(centerValue)
		center=centerValue->isTrue();

	decimal r=0.0;
	if(rValue) {
		r=rValue->getNumber();
	} else {
		NumberValue* dValue = dynamic_cast<NumberValue*>(ctx->getArgument(0,"diameter"));
		if(dValue)
			r=(dValue->getNumber()/2.0);
	}
	if(r==0.0)
		return new PointNode();

	Fragment fg=getSpecialVariables(ctx);
	int f = fg.getFragments(r);
	int ringCount=f/2;

	decimal h=center?0.0:r;
	QList<Polygon> rings;
	for(int i=0; i<ringCount; i++) {
		decimal phi = (M_PI*(i+0.5)) / ringCount;
		decimal r2 = r*sin(phi);
		decimal z = r*cos(phi)+h;
		Polygon* c = getCircle(r2,f,z);
		rings.append(*c);
	}

	PrimitiveNode* p = new PrimitiveNode();

	p->createPolygon();
	Polygon top=rings.at(0);
	foreach(Point pt, top.getPoints())
		p->appendVertex(pt);

	for(int i = 0; i < ringCount-1; i++) {
		QList<Point> r1 = rings.at(i).getPoints();
		QList<Point> r2 = rings.at(i+1).getPoints();
		int r1i = 0, r2i = 0;
		while(r1i < f || r2i < f) {
			if(r2i >= f||(decimal)r1i/f<(decimal)r2i/f) {
				p->createPolygon();
				int r1j = (r1i+1) % f;
				p->prependVertex(r1.at(r1i));
				p->prependVertex(r1.at(r1j));
				p->prependVertex(r2.at(r2i % f));
				r1i++;
			} else {
				p->createPolygon();
				int r2j = (r2i+1) % f;
				p->appendVertex(r2.at(r2i));
				p->appendVertex(r2.at(r2j));
				p->appendVertex(r1.at(r1i % f));
				r2i++;
			}
		}
	}

	p->createPolygon();
	Polygon bottom=rings.at(ringCount-1);
	foreach(Point pt, bottom.getPoints())
		p->prependVertex(pt);

	if(center) {
		AlignNode* n=new AlignNode();
		n->setCenter(true);
		n->addChild(p);
		return n;
	}

	return p;
}