summaryrefslogtreecommitdiff
path: root/graphics/asymptote/drawsurface.cc
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-08-07 03:02:55 +0000
committerNorbert Preining <norbert@preining.info>2020-08-07 03:02:55 +0000
commit3710c23789342d9d88783cbe9ad23eb5263a7c33 (patch)
tree1c40b2bfb9f6b652f7877ad0991f5d6b44391154 /graphics/asymptote/drawsurface.cc
parentd99fea72e367e8d4d2809b43b3b0206b1bb526b8 (diff)
CTAN sync 202008070302
Diffstat (limited to 'graphics/asymptote/drawsurface.cc')
-rw-r--r--graphics/asymptote/drawsurface.cc162
1 files changed, 81 insertions, 81 deletions
diff --git a/graphics/asymptote/drawsurface.cc b/graphics/asymptote/drawsurface.cc
index a1cd5e7b07..ccb34cb970 100644
--- a/graphics/asymptote/drawsurface.cc
+++ b/graphics/asymptote/drawsurface.cc
@@ -63,7 +63,7 @@ void setcolors(bool colors,
glm::vec4(emissive.R,emissive.G,emissive.B,emissive.A),
glm::vec4(specular.R,specular.G,specular.B,specular.A),
shininess,metallic,fresnel0);
-
+
MaterialMap::iterator p=materialMap.find(m);
if(p != materialMap.end()) materialIndex=p->second;
else {
@@ -77,7 +77,7 @@ void setcolors(bool colors,
}
}
-#endif
+#endif
void drawBezierPatch::bounds(const double* t, bbox3& b)
{
@@ -146,7 +146,7 @@ void drawBezierPatch::bounds(const double* t, bbox3& b)
}
void drawBezierPatch::ratio(const double* t, pair &b, double (*m)(double, double),
- double fuzz, bool &first)
+ double fuzz, bool &first)
{
triple buf[16];
triple* Controls;
@@ -159,7 +159,7 @@ void drawBezierPatch::ratio(const double* t, pair &b, double (*m)(double, double
Controls[12]=t*controls[12];
Controls[15]=t*controls[15];
}
-
+
triple v=Controls[0];
double x=xratio(v);
double y=yratio(v);
@@ -193,7 +193,7 @@ void drawBezierPatch::ratio(const double* t, pair &b, double (*m)(double, double
b=pair(xratio(v),yratio(v));
first=false;
}
-
+
b=pair(bound(Controls,m,xratio,b.getx(),fuzz,maxdepth),
bound(Controls,m,yratio,b.gety(),fuzz,maxdepth));
}
@@ -216,7 +216,7 @@ bool drawBezierPatch::write(prcfile *out, unsigned int *, double, groupsmap&)
out->addRectangle(vertices,m);
} else
out->addPatch(controls,m);
-
+
return true;
}
@@ -230,9 +230,9 @@ bool drawBezierPatch::write(jsfile *out)
meshinit();
drawElement::centerIndex=centerIndex;
} else drawElement::centerIndex=0;
-
+
setcolors(colors,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
-
+
out->precision(digits);
if(straight) {
triple Controls[]={controls[0],controls[12],controls[15],controls[3]};
@@ -240,8 +240,8 @@ bool drawBezierPatch::write(jsfile *out)
} else
out->addPatch(controls,16,Min,Max,colors,4);
out->precision(getSetting<Int>("digits"));
-
-#endif
+
+#endif
return true;
}
@@ -249,12 +249,12 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
double perspective, bool remesh)
{
#ifdef HAVE_GL
- if(invisible) return;
+ if(invisible) return;
transparent=colors ? colors[0].A+colors[1].A+colors[2].A+colors[3].A < 4.0 :
diffuse.A < 1.0;
-
+
setcolors(colors,diffuse,emissive,specular,shininess,metallic,fresnel0);
-
+
if(transparent)
setMaterial(transparentData,drawTransparent);
else {
@@ -263,7 +263,7 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
else
setMaterial(materialData,drawMaterial);
}
-
+
bool offscreen;
if(billboard) {
drawElement::centerIndex=centerIndex;
@@ -271,7 +271,7 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
offscreen=bbox2(Min,Max,BB).offscreen();
} else
offscreen=bbox2(Min,Max).offscreen();
-
+
if(offscreen) { // Fully offscreen
S.Onscreen=false;
S.data.clear();
@@ -284,7 +284,7 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
if(billboard) {
Controls=Controls0;
for(size_t i=0; i < 16; i++) {
- Controls[i]=BB.transform(controls[i]);
+ Controls[i]=BB.transform(controls[i]);
}
} else {
Controls=controls;
@@ -295,7 +295,7 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
}
double s=perspective ? Min.getz()*perspective : 1.0; // Move to glrender
-
+
const pair size3(s*(B.getx()-b.getx()),s*(B.gety()-b.gety()));
if(gl::outlinemode) {
@@ -324,7 +324,7 @@ drawElement *drawBezierPatch::transformed(const double* t)
{
return new drawBezierPatch(t,this);
}
-
+
void drawBezierTriangle::bounds(const double* t, bbox3& b)
{
double x,y,z;
@@ -341,13 +341,13 @@ void drawBezierTriangle::bounds(const double* t, bbox3& b)
Vertices[1]=t*controls[6];
Vertices[2]=t*controls[9];
}
-
+
boundstriples(x,y,z,X,Y,Z,3,Vertices);
- } else {
+ } else {
double cx[10];
double cy[10];
double cz[10];
-
+
if(t == NULL) {
for(unsigned int i=0; i < 10; ++i) {
triple v=controls[i];
@@ -368,18 +368,18 @@ void drawBezierTriangle::bounds(const double* t, bbox3& b)
double fuzz=Fuzz*run::norm(cx,10);
x=boundtri(cx,min,b.empty ? c0 : min(c0,b.left),fuzz,maxdepth);
X=boundtri(cx,max,b.empty ? c0 : max(c0,b.right),fuzz,maxdepth);
-
+
c0=cy[0];
fuzz=Fuzz*run::norm(cy,10);
y=boundtri(cy,min,b.empty ? c0 : min(c0,b.bottom),fuzz,maxdepth);
Y=boundtri(cy,max,b.empty ? c0 : max(c0,b.top),fuzz,maxdepth);
-
+
c0=cz[0];
fuzz=Fuzz*run::norm(cz,10);
z=boundtri(cz,min,b.empty ? c0 : min(c0,b.near),fuzz,maxdepth);
Z=boundtri(cz,max,b.empty ? c0 : max(c0,b.far),fuzz,maxdepth);
}
-
+
b.add(x,y,z);
b.add(X,Y,Z);
@@ -403,7 +403,7 @@ void drawBezierTriangle::ratio(const double* t, pair &b,
Controls[6]=t*controls[6];
Controls[9]=t*controls[9];
}
-
+
triple v=Controls[0];
double x=xratio(v);
double y=yratio(v);
@@ -434,13 +434,13 @@ void drawBezierTriangle::ratio(const double* t, pair &b,
b=pair(xratio(v),yratio(v));
first=false;
}
-
+
b=pair(boundtri(Controls,m,xratio,b.getx(),fuzz,maxdepth),
boundtri(Controls,m,yratio,b.gety(),fuzz,maxdepth));
}
}
-bool drawBezierTriangle::write(prcfile *out, unsigned int *, double,
+bool drawBezierTriangle::write(prcfile *out, unsigned int *, double,
groupsmap&)
{
if(invisible || primitive)
@@ -448,7 +448,7 @@ bool drawBezierTriangle::write(prcfile *out, unsigned int *, double,
RGBAColour Black(0.0,0.0,0.0,diffuse.A);
PRCmaterial m(Black,diffuse,emissive,specular,opacity,shininess);
-
+
static const double third=1.0/3.0;
static const double third2=2.0/3.0;
triple Controls[]={controls[0],controls[0],controls[0],controls[0],
@@ -460,7 +460,7 @@ bool drawBezierTriangle::write(prcfile *out, unsigned int *, double,
controls[5],controls[6],controls[7],
controls[8],controls[9]};
out->addPatch(Controls,m);
-
+
return true;
}
@@ -474,9 +474,9 @@ bool drawBezierTriangle::write(jsfile *out)
meshinit();
drawElement::centerIndex=centerIndex;
} else drawElement::centerIndex=0;
-
+
setcolors(colors,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
-
+
out->precision(digits);
if(straight) {
triple Controls[]={controls[0],controls[6],controls[9]};
@@ -484,8 +484,8 @@ bool drawBezierTriangle::write(jsfile *out)
} else
out->addPatch(controls,10,Min,Max,colors,3);
out->precision(getSetting<Int>("digits"));
-
-#endif
+
+#endif
return true;
}
@@ -496,9 +496,9 @@ void drawBezierTriangle::render(double size2, const triple& b, const triple& B,
if(invisible) return;
transparent=colors ? colors[0].A+colors[1].A+colors[2].A < 3.0 :
diffuse.A < 1.0;
-
+
setcolors(colors,diffuse,emissive,specular,shininess,metallic,fresnel0);
-
+
if(transparent)
setMaterial(transparentData,drawTransparent);
else {
@@ -515,7 +515,7 @@ void drawBezierTriangle::render(double size2, const triple& b, const triple& B,
offscreen=bbox2(Min,Max,BB).offscreen();
} else
offscreen=bbox2(Min,Max).offscreen();
-
+
if(offscreen) { // Fully offscreen
S.Onscreen=false;
S.data.clear();
@@ -528,7 +528,7 @@ void drawBezierTriangle::render(double size2, const triple& b, const triple& B,
if(billboard) {
Controls=Controls0;
for(size_t i=0; i < 10; i++) {
- Controls[i]=BB.transform(controls[i]);
+ Controls[i]=BB.transform(controls[i]);
}
} else {
Controls=controls;
@@ -539,7 +539,7 @@ void drawBezierTriangle::render(double size2, const triple& b, const triple& B,
}
double s=perspective ? Min.getz()*perspective : 1.0; // Move to glrender
-
+
const pair size3(s*(B.getx()-b.getx()),s*(B.gety()-b.gety()));
if(gl::outlinemode) {
@@ -566,7 +566,7 @@ drawElement *drawBezierTriangle::transformed(const double* t)
{
return new drawBezierTriangle(t,this);
}
-
+
bool drawNurbs::write(prcfile *out, unsigned int *, double, groupsmap&)
{
if(invisible)
@@ -575,7 +575,7 @@ bool drawNurbs::write(prcfile *out, unsigned int *, double, groupsmap&)
RGBAColour Black(0.0,0.0,0.0,diffuse.A);
PRCmaterial m(Black,diffuse,emissive,specular,opacity,shininess);
out->addSurface(udegree,vdegree,nu,nv,controls,uknots,vknots,m,weights);
-
+
return true;
}
@@ -584,7 +584,7 @@ void drawNurbs::bounds(const double* t, bbox3& b)
{
double x,y,z;
double X,Y,Z;
-
+
const size_t n=nu*nv;
triple* Controls;
if(t == NULL) Controls=controls;
@@ -595,10 +595,10 @@ void drawNurbs::bounds(const double* t, bbox3& b)
}
boundstriples(x,y,z,X,Y,Z,n,Controls);
-
+
b.add(x,y,z);
b.add(X,Y,Z);
-
+
if(t == NULL) {
Min=triple(x,y,z);
Max=triple(X,Y,Z);
@@ -614,7 +614,7 @@ void drawNurbs::ratio(const double *t, pair &b, double (*m)(double, double),
double, bool &first)
{
const size_t n=nu*nv;
-
+
triple* Controls;
if(t == NULL) Controls=controls;
else {
@@ -628,7 +628,7 @@ void drawNurbs::ratio(const double *t, pair &b, double (*m)(double, double),
triple v=Controls[0];
b=pair(xratio(v),yratio(v));
}
-
+
double x=b.getx();
double y=b.gety();
for(size_t i=0; i < n; ++i) {
@@ -637,7 +637,7 @@ void drawNurbs::ratio(const double *t, pair &b, double (*m)(double, double),
y=m(y,yratio(v));
}
b=pair(x,y);
-
+
if(t != NULL)
delete[] Controls;
}
@@ -649,25 +649,25 @@ void drawNurbs::displacement()
size_t n=nu*nv;
size_t nuknots=udegree+nu+1;
size_t nvknots=vdegree+nv+1;
-
+
if(Controls == NULL) {
Controls=new(UseGC) GLfloat[(weights ? 4 : 3)*n];
uKnots=new(UseGC) GLfloat[nuknots];
vKnots=new(UseGC) GLfloat[nvknots];
}
-
+
if(weights)
for(size_t i=0; i < n; ++i)
store(Controls+4*i,controls[i],weights[i]);
else
for(size_t i=0; i < n; ++i)
store(Controls+3*i,controls[i]);
-
+
for(size_t i=0; i < nuknots; ++i)
uKnots[i]=uknots[i];
for(size_t i=0; i < nvknots; ++i)
vKnots[i]=vknots[i];
-#endif
+#endif
}
void drawNurbs::render(double size2, const triple& b, const triple& B,
@@ -686,7 +686,7 @@ void drawPRC::P(triple& t, double x, double y, double z)
double f=T[12]*x+T[13]*y+T[14]*z+T[15];
if(f == 0.0) run::dividebyzero();
f=1.0/f;
-
+
t=triple((T[0]*x+T[1]*y+T[2]*z+T[3])*f,(T[4]*x+T[5]*y+T[6]*z+T[7])*f,
(T[8]*x+T[9]*y+T[10]*z+T[11])*f);
}
@@ -706,11 +706,11 @@ bool drawSphere::write(prcfile *out, unsigned int *, double, groupsmap&)
RGBAColour Black(0.0,0.0,0.0,diffuse.A);
PRCmaterial m(Black,diffuse,emissive,specular,opacity,shininess);
-
+
switch(type) {
case 0: // PRCsphere
{
- if(half)
+ if(half)
out->addHemisphere(1.0,m,NULL,NULL,NULL,1.0,T);
else
out->addSphere(1.0,m,NULL,NULL,NULL,1.0,T);
@@ -726,9 +726,9 @@ bool drawSphere::write(prcfile *out, unsigned int *, double, groupsmap&)
// NURBS representation of a sphere using 10 distinct control points
// K. Qin, J. Comp. Sci. and Tech. 12, 210-216 (1997).
-
+
triple N,S,P1,P2,P3,P4,P5,P6,P7,P8;
-
+
P(N,0.0,0.0,1.0);
P(P1,-2.0,-2.0,1.0);
P(P2,-2.0,-2.0,-1.0);
@@ -739,27 +739,27 @@ bool drawSphere::write(prcfile *out, unsigned int *, double, groupsmap&)
P(P6,2.0,2.0,-1.0);
P(P7,-2.0,2.0,1.0);
P(P8,-2.0,2.0,-1.0);
-
+
triple p0[]={N,P1,P2,S,
N,P3,P4,S,
N,P5,P6,S,
N,P7,P8,S,
N,P1,P2,S,
N,P3,P4,S};
-
+
out->addSurface(2,3,3,4,p0,uknot,vknot,m,Weights);
out->addSurface(2,3,3,4,p0+4,uknot,vknot,m,Weights);
if(!half) {
out->addSurface(2,3,3,4,p0+8,uknot,vknot,m,Weights);
out->addSurface(2,3,3,4,p0+12,uknot,vknot,m,Weights);
}
-
+
break;
}
default:
reportError("Invalid sphere type");
}
-
+
return true;
}
@@ -784,7 +784,7 @@ bool drawSphere::write(jsfile *out)
else
out->addSphere(O,r);
-#endif
+#endif
return true;
}
@@ -795,12 +795,12 @@ bool drawCylinder::write(prcfile *out, unsigned int *, double, groupsmap&)
RGBAColour Black(0.0,0.0,0.0,diffuse.A);
PRCmaterial m(Black,diffuse,emissive,specular,opacity,shininess);
-
+
out->addCylinder(1.0,1.0,m,NULL,NULL,NULL,1.0,T);
-
+
return true;
}
-
+
bool drawCylinder::write(jsfile *out)
{
#ifdef HAVE_LIBGLM
@@ -808,7 +808,7 @@ bool drawCylinder::write(jsfile *out)
return true;
drawElement::centerIndex=0;
-
+
setcolors(false,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
triple E,H,O;
@@ -819,13 +819,13 @@ bool drawCylinder::write(jsfile *out)
triple Z=H-O;
double r=length(X);
double h=length(Z);
-
+
out->addCylinder(O,r,h,Z.polar(false),Z.azimuth(false),core);
-#endif
+#endif
return true;
}
-
+
bool drawDisk::write(prcfile *out, unsigned int *, double, groupsmap&)
{
if(invisible)
@@ -833,12 +833,12 @@ bool drawDisk::write(prcfile *out, unsigned int *, double, groupsmap&)
RGBAColour Black(0.0,0.0,0.0,diffuse.A);
PRCmaterial m(Black,diffuse,emissive,specular,opacity,shininess);
-
+
out->addDisk(1.0,m,NULL,NULL,NULL,1.0,T);
-
+
return true;
}
-
+
bool drawDisk::write(jsfile *out)
{
#ifdef HAVE_LIBGLM
@@ -846,9 +846,9 @@ bool drawDisk::write(jsfile *out)
return true;
drawElement::centerIndex=0;
-
+
setcolors(false,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
-
+
triple E,H,O;
P(E,1.0,0.0,0.0);
P(H,0.0,0.0,1.0);
@@ -856,13 +856,13 @@ bool drawDisk::write(jsfile *out)
triple X=E-O;
triple Z=H-O;
double r=length(X);
-
+
out->addDisk(O,r,Z.polar(false),Z.azimuth(false));
#endif
return true;
}
-
+
bool drawTube::write(jsfile *out)
{
#ifdef HAVE_LIBGLM
@@ -931,7 +931,7 @@ void drawBaseTriangles::ratio(const double* t, pair &b,
}
ratiotriples(b,m,first,nP,tP);
-
+
if(t != NULL)
delete[] tP;
}
@@ -940,7 +940,7 @@ bool drawTriangles::write(prcfile *out, unsigned int *, double, groupsmap&)
{
if(invisible)
return true;
-
+
if(nC) {
const RGBAColour white(1,1,1,opacity);
const RGBAColour black(0,0,0,opacity);
@@ -960,11 +960,11 @@ bool drawTriangles::write(jsfile *out)
#ifdef HAVE_LIBGLM
if(invisible)
return true;
-
+
setcolors(nC,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
-
+
out->addTriangles(nP,P,nN,N,nC,C,nI,PI,NI,CI,Min,Max);
-#endif
+#endif
return true;
}
@@ -974,7 +974,7 @@ void drawTriangles::render(double size2, const triple& b,
{
#ifdef HAVE_GL
if(invisible) return;
-
+
transparent=diffuse.A < 1.0;
if(bbox2(Min,Max).offscreen()) { // Fully offscreen
@@ -995,7 +995,7 @@ void drawTriangles::render(double size2, const triple& b,
R.append();
return;
}
-
+
R.queue(nP,P,nN,N,nC,C,nI,PI,NI,CI,transparent);
#endif
}