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* 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; }
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; }