summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/drawsurface.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/drawsurface.cc')
-rw-r--r--Build/source/utils/asymptote/drawsurface.cc191
1 files changed, 100 insertions, 91 deletions
diff --git a/Build/source/utils/asymptote/drawsurface.cc b/Build/source/utils/asymptote/drawsurface.cc
index 34ea0a4aa40..b491f20b0d5 100644
--- a/Build/source/utils/asymptote/drawsurface.cc
+++ b/Build/source/utils/asymptote/drawsurface.cc
@@ -31,6 +31,7 @@ size_t drawElement::lastcenterIndex=0;
const triple drawElement::zero;
using vm::array;
+using settings::getSetting;
#ifdef HAVE_LIBGLM
@@ -62,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 {
@@ -76,7 +77,7 @@ void setcolors(bool colors,
}
}
-#endif
+#endif
void drawBezierPatch::bounds(const double* t, bbox3& b)
{
@@ -104,14 +105,14 @@ void drawBezierPatch::bounds(const double* t, bbox3& b)
double cz[16];
if(t == NULL) {
- for(int i=0; i < 16; ++i) {
+ for(unsigned int i=0; i < 16; ++i) {
triple v=controls[i];
cx[i]=v.getx();
cy[i]=v.gety();
cz[i]=v.getz();
}
} else {
- for(int i=0; i < 16; ++i) {
+ for(unsigned int i=0; i < 16; ++i) {
triple v=t*controls[i];
cx[i]=v.getx();
cy[i]=v.gety();
@@ -127,7 +128,7 @@ void drawBezierPatch::bounds(const double* t, bbox3& b)
c0=cy[0];
fuzz=Fuzz*run::norm(cy,16);
y=bound(cy,min,b.empty ? c0 : min(c0,b.bottom),fuzz,maxdepth);
- Y=boundtri(cy,max,b.empty ? c0 : max(c0,b.top),fuzz,maxdepth);
+ Y=bound(cy,max,b.empty ? c0 : max(c0,b.top),fuzz,maxdepth);
c0=cz[0];
fuzz=Fuzz*run::norm(cz,16);
@@ -145,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;
@@ -158,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);
@@ -192,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));
}
@@ -215,7 +216,7 @@ bool drawBezierPatch::write(prcfile *out, unsigned int *, double, groupsmap&)
out->addRectangle(vertices,m);
} else
out->addPatch(controls,m);
-
+
return true;
}
@@ -229,16 +230,18 @@ 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]};
out->addPatch(Controls,4,Min,Max,colors,4);
} else
out->addPatch(controls,16,Min,Max,colors,4);
-
-#endif
+ out->precision(getSetting<Int>("digits"));
+
+#endif
return true;
}
@@ -246,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 {
@@ -260,11 +263,9 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
else
setMaterial(materialData,drawMaterial);
}
-
+
bool offscreen;
- if(gl::exporting)
- offscreen=false;
- else if(billboard) {
+ if(billboard) {
drawElement::centerIndex=centerIndex;
BB.init(center);
offscreen=bbox2(Min,Max,BB).offscreen();
@@ -274,6 +275,9 @@ void drawBezierPatch::render(double size2, const triple& b, const triple& B,
if(offscreen) { // Fully offscreen
S.Onscreen=false;
S.data.clear();
+ S.transparent=transparent;
+ S.color=colors;
+ S.notRendered();
return;
}
@@ -282,7 +286,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;
@@ -293,7 +297,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) {
@@ -322,7 +326,7 @@ drawElement *drawBezierPatch::transformed(const double* t)
{
return new drawBezierPatch(t,this);
}
-
+
void drawBezierTriangle::bounds(const double* t, bbox3& b)
{
double x,y,z;
@@ -339,13 +343,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];
@@ -361,23 +365,23 @@ void drawBezierTriangle::bounds(const double* t, bbox3& b)
cz[i]=v.getz();
}
}
-
+
double c0=cx[0];
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);
@@ -401,7 +405,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);
@@ -432,13 +436,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)
@@ -446,7 +450,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],
@@ -458,7 +462,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;
}
@@ -472,16 +476,18 @@ 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]};
out->addPatch(Controls,3,Min,Max,colors,3);
} else
out->addPatch(controls,10,Min,Max,colors,3);
-
-#endif
+ out->precision(getSetting<Int>("digits"));
+
+#endif
return true;
}
@@ -492,9 +498,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 {
@@ -505,18 +511,19 @@ void drawBezierTriangle::render(double size2, const triple& b, const triple& B,
}
bool offscreen;
- if(gl::exporting)
- offscreen=false;
- else if(billboard) {
+ if(billboard) {
drawElement::centerIndex=centerIndex;
BB.init(center);
offscreen=bbox2(Min,Max,BB).offscreen();
} else
offscreen=bbox2(Min,Max).offscreen();
-
+
if(offscreen) { // Fully offscreen
S.Onscreen=false;
S.data.clear();
+ S.transparent=transparent;
+ S.color=colors;
+ S.notRendered();
return;
}
@@ -525,7 +532,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;
@@ -536,7 +543,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) {
@@ -563,7 +570,7 @@ drawElement *drawBezierTriangle::transformed(const double* t)
{
return new drawBezierTriangle(t,this);
}
-
+
bool drawNurbs::write(prcfile *out, unsigned int *, double, groupsmap&)
{
if(invisible)
@@ -572,7 +579,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;
}
@@ -581,7 +588,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;
@@ -592,10 +599,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);
@@ -611,7 +618,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 {
@@ -625,7 +632,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) {
@@ -634,7 +641,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;
}
@@ -646,25 +653,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,
@@ -683,7 +690,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);
}
@@ -703,11 +710,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);
@@ -723,9 +730,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);
@@ -736,27 +743,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;
}
@@ -781,7 +788,7 @@ bool drawSphere::write(jsfile *out)
else
out->addSphere(O,r);
-#endif
+#endif
return true;
}
@@ -792,12 +799,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
@@ -805,7 +812,7 @@ bool drawCylinder::write(jsfile *out)
return true;
drawElement::centerIndex=0;
-
+
setcolors(false,diffuse,emissive,specular,shininess,metallic,fresnel0,out);
triple E,H,O;
@@ -816,13 +823,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)
@@ -830,12 +837,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
@@ -843,9 +850,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);
@@ -853,13 +860,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
@@ -928,7 +935,7 @@ void drawBaseTriangles::ratio(const double* t, pair &b,
}
ratiotriples(b,m,first,nP,tP);
-
+
if(t != NULL)
delete[] tP;
}
@@ -937,7 +944,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);
@@ -957,11 +964,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;
}
@@ -971,12 +978,14 @@ void drawTriangles::render(double size2, const triple& b,
{
#ifdef HAVE_GL
if(invisible) return;
-
+
transparent=diffuse.A < 1.0;
- if(!gl::exporting && bbox2(Min,Max).offscreen()) { // Fully offscreen
+ if(bbox2(Min,Max).offscreen()) { // Fully offscreen
R.Onscreen=false;
R.data.clear();
+ R.transparent=transparent;
+ R.notRendered();
return;
}
@@ -991,7 +1000,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
}