int tenGlyphGen(limnObject *glyphsLimn, echoScene *glyphsEcho, tenGlyphParm *parm, const Nrrd *nten, const Nrrd *npos, const Nrrd *nslc) { static const char me[]="tenGlyphGen"; gageShape *shape; airArray *mop; float *tdata, eval[3], evec[9], *cvec, rotEvec[9], mA_f[16], absEval[3], glyphScl[3]; double pI[3], pW[3], cl, cp, sRot[16], mA[16], mB[16], msFr[9], tmpvec[3], R, G, B, qA, qB, qC, glyphAniso, sliceGray; unsigned int duh; int slcCoord[3], idx, glyphIdx, axis, numGlyphs, svRGBAfl=AIR_FALSE; limnLook *look; int lookIdx; echoObject *eglyph, *inst, *list=NULL, *split, *esquare; echoPos_t eM[16], originOffset[3], edge0[3], edge1[3]; char stmp[AIR_STRLEN_SMALL]; /* int eret; double tmp1[3], tmp2[3]; */ if (!( (glyphsLimn || glyphsEcho) && nten && parm)) { biffAddf(TEN, "%s: got NULL pointer", me); return 1; } mop = airMopNew(); shape = gageShapeNew(); shape->defaultCenter = nrrdCenterCell; airMopAdd(mop, shape, (airMopper)gageShapeNix, airMopAlways); if (npos) { if (!( 2 == nten->dim && 7 == nten->axis[0].size )) { biffAddf(TEN, "%s: nten isn't 2-D 7-by-N array", me); airMopError(mop); return 1; } if (!( 2 == npos->dim && 3 == npos->axis[0].size && nten->axis[1].size == npos->axis[1].size )) { biffAddf(TEN, "%s: npos isn't 2-D 3-by-%s array", me, airSprintSize_t(stmp, nten->axis[1].size)); airMopError(mop); return 1; } if (!( nrrdTypeFloat == nten->type && nrrdTypeFloat == npos->type )) { biffAddf(TEN, "%s: nten and npos must be %s, not %s and %s", me, airEnumStr(nrrdType, nrrdTypeFloat), airEnumStr(nrrdType, nten->type), airEnumStr(nrrdType, npos->type)); airMopError(mop); return 1; } } else { if (tenTensorCheck(nten, nrrdTypeFloat, AIR_TRUE, AIR_TRUE)) { biffAddf(TEN, "%s: didn't get a valid DT volume", me); airMopError(mop); return 1; } } if (tenGlyphParmCheck(parm, nten, npos, nslc)) { biffAddf(TEN, "%s: trouble", me); airMopError(mop); return 1; } if (!npos) { if (gageShapeSet(shape, nten, tenGageKind->baseDim)) { biffMovef(TEN, GAGE, "%s: trouble", me); airMopError(mop); return 1; } } if (parm->doSlice) { ELL_3V_COPY(edge0, shape->spacing); ELL_3V_COPY(edge1, shape->spacing); edge0[parm->sliceAxis] = edge1[parm->sliceAxis] = 0.0; switch(parm->sliceAxis) { case 0: edge0[1] = edge1[2] = 0; ELL_4M_ROTATE_Y_SET(sRot, AIR_PI/2); break; case 1: edge0[0] = edge1[2] = 0; ELL_4M_ROTATE_X_SET(sRot, AIR_PI/2); break; case 2: default: edge0[0] = edge1[1] = 0; ELL_4M_IDENTITY_SET(sRot); break; } ELL_3V_COPY(originOffset, shape->spacing); ELL_3V_SCALE(originOffset, -0.5, originOffset); originOffset[parm->sliceAxis] *= -2*parm->sliceOffset; } if (glyphsLimn) { /* create limnLooks for diffuse and ambient-only shading */ /* ??? */ /* hack: save old value of setVertexRGBAFromLook, and set to true */ svRGBAfl = glyphsLimn->setVertexRGBAFromLook; glyphsLimn->setVertexRGBAFromLook = AIR_TRUE; } if (glyphsEcho) { list = echoObjectNew(glyphsEcho, echoTypeList); } if (npos) { numGlyphs = AIR_UINT(nten->axis[1].size); } else { numGlyphs = shape->size[0] * shape->size[1] * shape->size[2]; } /* find measurement frame transform */ if (3 == nten->spaceDim && AIR_EXISTS(nten->measurementFrame[0][0])) { /* msFr nten->measurementFrame ** 0 1 2 [0][0] [1][0] [2][0] ** 3 4 5 [0][1] [1][1] [2][1] ** 6 7 8 [0][2] [1][2] [2][2] */ msFr[0] = nten->measurementFrame[0][0]; msFr[3] = nten->measurementFrame[0][1]; msFr[6] = nten->measurementFrame[0][2]; msFr[1] = nten->measurementFrame[1][0]; msFr[4] = nten->measurementFrame[1][1]; msFr[7] = nten->measurementFrame[1][2]; msFr[2] = nten->measurementFrame[2][0]; msFr[5] = nten->measurementFrame[2][1]; msFr[8] = nten->measurementFrame[2][2]; } else { ELL_3M_IDENTITY_SET(msFr); } for (idx=0; idx<numGlyphs; idx++) { tdata = (float*)(nten->data) + 7*idx; if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: hello %g %g %g %g %g %g %g\n", me, idx, numGlyphs, tdata[0], tdata[1], tdata[2], tdata[3], tdata[4], tdata[5], tdata[6]); } if (!( TEN_T_EXISTS(tdata) )) { /* there's nothing we can do here */ if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: non-existent data\n", me, idx, numGlyphs); } continue; } if (npos) { ELL_3V_COPY(pW, (float*)(npos->data) + 3*idx); if (!( AIR_EXISTS(pW[0]) && AIR_EXISTS(pW[1]) && AIR_EXISTS(pW[2]) )) { /* position doesn't exist- perhaps because its from the push library, which might kill points by setting coords to nan */ continue; } } else { NRRD_COORD_GEN(pI, shape->size, 3, idx); /* this does take into account full orientation */ gageShapeItoW(shape, pW, pI); if (parm->nmask) { if (!( nrrdFLookup[parm->nmask->type](parm->nmask->data, idx) >= parm->maskThresh )) { if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: doesn't meet mask thresh\n", me, idx, numGlyphs); } continue; } } } tenEigensolve_f(eval, evec, tdata); /* transform eigenvectors by measurement frame */ ELL_3MV_MUL(tmpvec, msFr, evec + 0); ELL_3V_COPY_TT(evec + 0, float, tmpvec); ELL_3MV_MUL(tmpvec, msFr, evec + 3); ELL_3V_COPY_TT(evec + 3, float, tmpvec); ELL_3MV_MUL(tmpvec, msFr, evec + 6); ELL_3V_COPY_TT(evec + 6, float, tmpvec); ELL_3V_CROSS(tmpvec, evec + 0, evec + 3); if (0 > ELL_3V_DOT(tmpvec, evec + 6)) { ELL_3V_SCALE(evec + 6, -1, evec + 6); } ELL_3M_TRANSPOSE(rotEvec, evec); if (parm->doSlice && pI[parm->sliceAxis] == parm->slicePos) { /* set sliceGray */ if (nslc) { /* we aren't masked by confidence, as anisotropy slice is */ for (duh=0; duh<parm->sliceAxis; duh++) { slcCoord[duh] = (int)(pI[duh]); } for (duh=duh<parm->sliceAxis; duh<2; duh++) { slcCoord[duh] = (int)(pI[duh+1]); } /* HEY: GLK has no idea what's going here */ slcCoord[0] = (int)(pI[0]); slcCoord[1] = (int)(pI[1]); slcCoord[2] = (int)(pI[2]); sliceGray = nrrdFLookup[nslc->type](nslc->data, slcCoord[0] + nslc->axis[0].size*slcCoord[1]); } else { if (!( tdata[0] >= parm->confThresh )) { if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d (slice): conf %g < thresh %g\n", me, idx, numGlyphs, tdata[0], parm->confThresh); } continue; } sliceGray = tenAnisoEval_f(eval, parm->sliceAnisoType); } if (parm->sliceGamma > 0) { sliceGray = AIR_AFFINE(0, sliceGray, 1, parm->sliceBias, 1); sliceGray = pow(sliceGray, 1.0/parm->sliceGamma); } else { sliceGray = AIR_AFFINE(0, sliceGray, 1, 0, 1-parm->sliceBias); sliceGray = 1.0 - pow(sliceGray, -1.0/parm->sliceGamma); } /* make slice contribution */ /* HEY: this is *NOT* aware of shape->fromOrientation */ if (glyphsLimn) { lookIdx = limnObjectLookAdd(glyphsLimn); look = glyphsLimn->look + lookIdx; ELL_4V_SET_TT(look->rgba, float, sliceGray, sliceGray, sliceGray, 1); ELL_3V_SET(look->kads, 1, 0, 0); look->spow = 0; glyphIdx = limnObjectSquareAdd(glyphsLimn, lookIdx); ELL_4M_IDENTITY_SET(mA); ell_4m_post_mul_d(mA, sRot); if (!npos) { ELL_4M_SCALE_SET(mB, shape->spacing[0], shape->spacing[1], shape->spacing[2]); } ell_4m_post_mul_d(mA, mB); ELL_4M_TRANSLATE_SET(mB, pW[0], pW[1], pW[2]); ell_4m_post_mul_d(mA, mB); ELL_4M_TRANSLATE_SET(mB, originOffset[0], originOffset[1], originOffset[2]); ell_4m_post_mul_d(mA, mB); ELL_4M_COPY_TT(mA_f, float, mA); limnObjectPartTransform(glyphsLimn, glyphIdx, mA_f); } if (glyphsEcho) { esquare = echoObjectNew(glyphsEcho,echoTypeRectangle); ELL_3V_ADD2(((echoRectangle*)esquare)->origin, pW, originOffset); ELL_3V_COPY(((echoRectangle*)esquare)->edge0, edge0); ELL_3V_COPY(((echoRectangle*)esquare)->edge1, edge1); echoColorSet(esquare, AIR_CAST(echoCol_t, sliceGray), AIR_CAST(echoCol_t, sliceGray), AIR_CAST(echoCol_t, sliceGray), 1); /* this is pretty arbitrary- but I want shadows to have some effect. Previously, the material was all ambient: (A,D,S) = (1,0,0), which avoided all shadow effects. */ echoMatterPhongSet(glyphsEcho, esquare, 0.4f, 0.6f, 0, 40); echoListAdd(list, esquare); } } if (parm->onlyPositive) { if (eval[2] < 0) { /* didn't have all positive eigenvalues, its outta here */ if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: not all evals %g %g %g > 0\n", me, idx, numGlyphs, eval[0], eval[1], eval[2]); } continue; } } if (!( tdata[0] >= parm->confThresh )) { if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: conf %g < thresh %g\n", me, idx, numGlyphs, tdata[0], parm->confThresh); } continue; } if (!( tenAnisoEval_f(eval, parm->anisoType) >= parm->anisoThresh )) { if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: aniso[%d] %g < thresh %g\n", me, idx, numGlyphs, parm->anisoType, tenAnisoEval_f(eval, parm->anisoType), parm->anisoThresh); } continue; } glyphAniso = tenAnisoEval_f(eval, parm->colAnisoType); /* fprintf(stderr, "%s: eret = %d; evals = %g %g %g\n", me, eret, eval[0], eval[1], eval[2]); ELL_3V_CROSS(tmp1, evec+0, evec+3); tmp2[0] = ELL_3V_LEN(tmp1); ELL_3V_CROSS(tmp1, evec+0, evec+6); tmp2[1] = ELL_3V_LEN(tmp1); ELL_3V_CROSS(tmp1, evec+3, evec+6); tmp2[2] = ELL_3V_LEN(tmp1); fprintf(stderr, "%s: crosses = %g %g %g\n", me, tmp2[0], tmp2[1], tmp2[2]); */ /* set transform (in mA) */ ELL_3V_ABS(absEval, eval); ELL_4M_IDENTITY_SET(mA); /* reset */ ELL_3V_SCALE(glyphScl, parm->glyphScale, absEval); /* scale by evals */ ELL_4M_SCALE_SET(mB, glyphScl[0], glyphScl[1], glyphScl[2]); ell_4m_post_mul_d(mA, mB); ELL_43M_INSET(mB, rotEvec); /* rotate by evecs */ ell_4m_post_mul_d(mA, mB); ELL_4M_TRANSLATE_SET(mB, pW[0], pW[1], pW[2]); /* translate */ ell_4m_post_mul_d(mA, mB); /* set color (in R,G,B) */ cvec = evec + 3*(AIR_CLAMP(0, parm->colEvec, 2)); R = AIR_ABS(cvec[0]); /* standard mapping */ G = AIR_ABS(cvec[1]); B = AIR_ABS(cvec[2]); /* desaturate by colMaxSat */ R = AIR_AFFINE(0.0, parm->colMaxSat, 1.0, parm->colIsoGray, R); G = AIR_AFFINE(0.0, parm->colMaxSat, 1.0, parm->colIsoGray, G); B = AIR_AFFINE(0.0, parm->colMaxSat, 1.0, parm->colIsoGray, B); /* desaturate some by anisotropy */ R = AIR_AFFINE(0.0, parm->colAnisoModulate, 1.0, R, AIR_AFFINE(0.0, glyphAniso, 1.0, parm->colIsoGray, R)); G = AIR_AFFINE(0.0, parm->colAnisoModulate, 1.0, G, AIR_AFFINE(0.0, glyphAniso, 1.0, parm->colIsoGray, G)); B = AIR_AFFINE(0.0, parm->colAnisoModulate, 1.0, B, AIR_AFFINE(0.0, glyphAniso, 1.0, parm->colIsoGray, B)); /* clamp and do gamma */ R = AIR_CLAMP(0.0, R, 1.0); G = AIR_CLAMP(0.0, G, 1.0); B = AIR_CLAMP(0.0, B, 1.0); R = pow(R, parm->colGamma); G = pow(G, parm->colGamma); B = pow(B, parm->colGamma); /* find axis, and superquad exponents qA and qB */ if (eval[2] > 0) { /* all evals positive */ cl = AIR_MIN(0.99, tenAnisoEval_f(eval, tenAniso_Cl1)); cp = AIR_MIN(0.99, tenAnisoEval_f(eval, tenAniso_Cp1)); if (cl > cp) { axis = 0; qA = pow(1-cp, parm->sqdSharp); qB = pow(1-cl, parm->sqdSharp); } else { axis = 2; qA = pow(1-cl, parm->sqdSharp); qB = pow(1-cp, parm->sqdSharp); } qC = qB; } else if (eval[0] < 0) { /* all evals negative */ float aef[3]; aef[0] = absEval[2]; aef[1] = absEval[1]; aef[2] = absEval[0]; cl = AIR_MIN(0.99, tenAnisoEval_f(aef, tenAniso_Cl1)); cp = AIR_MIN(0.99, tenAnisoEval_f(aef, tenAniso_Cp1)); if (cl > cp) { axis = 2; qA = pow(1-cp, parm->sqdSharp); qB = pow(1-cl, parm->sqdSharp); } else { axis = 0; qA = pow(1-cl, parm->sqdSharp); qB = pow(1-cp, parm->sqdSharp); } qC = qB; } else { #define OOSQRT2 0.70710678118654752440 #define OOSQRT3 0.57735026918962576451 /* double poleA[3]={OOSQRT3, OOSQRT3, OOSQRT3}; */ double poleB[3]={1, 0, 0}; double poleC[3]={OOSQRT2, OOSQRT2, 0}; double poleD[3]={OOSQRT3, -OOSQRT3, -OOSQRT3}; double poleE[3]={OOSQRT2, 0, -OOSQRT2}; double poleF[3]={OOSQRT3, OOSQRT3, -OOSQRT3}; double poleG[3]={0, -OOSQRT2, -OOSQRT2}; double poleH[3]={0, 0, -1}; /* double poleI[3]={-OOSQRT3, -OOSQRT3, -OOSQRT3}; */ double funk[3]={0,4,2}, thrn[3]={1,4,4}; double octa[3]={0,2,2}, cone[3]={1,2,2}; double evalN[3], tmp, bary[3]; double qq[3]; ELL_3V_NORM(evalN, eval, tmp); if (eval[1] >= -eval[2]) { /* inside B-F-C */ ell_3v_barycentric_spherical_d(bary, poleB, poleF, poleC, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], octa, bary[1], thrn, bary[2], cone); axis = 2; } else if (eval[0] >= -eval[2]) { /* inside B-D-F */ if (eval[1] >= 0) { /* inside B-E-F */ ell_3v_barycentric_spherical_d(bary, poleB, poleE, poleF, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], octa, bary[1], funk, bary[2], thrn); axis = 2; } else { /* inside B-D-E */ ell_3v_barycentric_spherical_d(bary, poleB, poleD, poleE, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], cone, bary[1], thrn, bary[2], funk); axis = 0; } } else if (eval[0] < -eval[1]) { /* inside D-G-H */ ell_3v_barycentric_spherical_d(bary, poleD, poleG, poleH, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], thrn, bary[1], cone, bary[2], octa); axis = 0; } else if (eval[1] < 0) { /* inside E-D-H */ ell_3v_barycentric_spherical_d(bary, poleE, poleD, poleH, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], funk, bary[1], thrn, bary[2], octa); axis = 0; } else { /* inside F-E-H */ ell_3v_barycentric_spherical_d(bary, poleF, poleE, poleH, evalN); ELL_3V_SCALE_ADD3(qq, bary[0], thrn, bary[1], funk, bary[2], cone); axis = 2; } qA = qq[0]; qB = qq[1]; qC = qq[2]; #undef OOSQRT2 #undef OOSQRT3 } /* add the glyph */ if (parm->verbose >= 2) { fprintf(stderr, "%s: glyph %d/%d: the glyph stays!\n", me, idx, numGlyphs); } if (glyphsLimn) { lookIdx = limnObjectLookAdd(glyphsLimn); look = glyphsLimn->look + lookIdx; ELL_4V_SET_TT(look->rgba, float, R, G, B, 1); ELL_3V_SET(look->kads, parm->ADSP[0], parm->ADSP[1], parm->ADSP[2]); look->spow = 0; switch(parm->glyphType) { case tenGlyphTypeBox: glyphIdx = limnObjectCubeAdd(glyphsLimn, lookIdx); break; case tenGlyphTypeSphere: glyphIdx = limnObjectPolarSphereAdd(glyphsLimn, lookIdx, axis, 2*parm->facetRes, parm->facetRes); break; case tenGlyphTypeCylinder: glyphIdx = limnObjectCylinderAdd(glyphsLimn, lookIdx, axis, parm->facetRes); break; case tenGlyphTypeSuperquad: default: glyphIdx = limnObjectPolarSuperquadFancyAdd(glyphsLimn, lookIdx, axis, AIR_CAST(float, qA), AIR_CAST(float, qB), AIR_CAST(float, qC), 0, 2*parm->facetRes, parm->facetRes); break; } ELL_4M_COPY_TT(mA_f, float, mA); limnObjectPartTransform(glyphsLimn, glyphIdx, mA_f); } if (glyphsEcho) { switch(parm->glyphType) { case tenGlyphTypeBox: eglyph = echoObjectNew(glyphsEcho, echoTypeCube); /* nothing else to set */ break; case tenGlyphTypeSphere: eglyph = echoObjectNew(glyphsEcho, echoTypeSphere); echoSphereSet(eglyph, 0, 0, 0, 1); break; case tenGlyphTypeCylinder: eglyph = echoObjectNew(glyphsEcho, echoTypeCylinder); echoCylinderSet(eglyph, axis); break; case tenGlyphTypeSuperquad: default: eglyph = echoObjectNew(glyphsEcho, echoTypeSuperquad); echoSuperquadSet(eglyph, axis, qA, qB); break; } echoColorSet(eglyph, AIR_CAST(echoCol_t, R), AIR_CAST(echoCol_t, G), AIR_CAST(echoCol_t, B), 1); echoMatterPhongSet(glyphsEcho, eglyph, parm->ADSP[0], parm->ADSP[1], parm->ADSP[2], parm->ADSP[3]); inst = echoObjectNew(glyphsEcho, echoTypeInstance); ELL_4M_COPY(eM, mA); echoInstanceSet(inst, eM, eglyph); echoListAdd(list, inst); } } if (glyphsLimn) { glyphsLimn->setVertexRGBAFromLook = svRGBAfl; } if (glyphsEcho) { split = echoListSplit3(glyphsEcho, list, 10); echoObjectAdd(glyphsEcho, split); } airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { const char *me; char *err, *outS; double eval[3], matA[9], matB[9], sval[3], uu[9], vv[9], escl[5], view[3]; float matAf[9], matBf[16]; float pp[3], qq[4], mR[9], len, gamma; float os, vs, rad, AB[2], ten[7]; hestOpt *hopt=NULL; airArray *mop; limnObject *obj; limnLook *look; int lookRod, lookSoid; float kadsRod[3], kadsSoid[3]; int gtype, partIdx=-1; /* sssh */ int res; FILE *file; me = argv[0]; hestOptAdd(&hopt, "sc", "evals", airTypeDouble, 3, 3, eval, "1 1 1", "original eigenvalues of tensor to be visualized"); hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan", "Directly set the A, B parameters to the superquadric surface, " "over-riding the default behavior of determining them from the " "scalings \"-sc\" as superquadric tensor glyphs"); hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1", "over-all scaling (multiplied by scalings)"); hestOptAdd(&hopt, "vs", "view-dir scaling", airTypeFloat, 1, 1, &vs, "1", "scaling along view-direction (to show off bas-relief " "ambibuity of ellipsoids versus superquads)"); hestOptAdd(&hopt, "es", "extra scaling", airTypeDouble, 5, 5, escl, "2 1 0 0 1", "extra scaling specified with five values " "0:tensor|1:geometry|2:none vx vy vz scaling"); hestOptAdd(&hopt, "fr", "from (eye) point", airTypeDouble, 3, 3, &view, "4 4 4", "eye point, needed for non-unity \"-vs\""); hestOptAdd(&hopt, "gamma", "superquad sharpness", airTypeFloat, 1, 1, &gamma, "0", "how much to sharpen edges as a " "function of differences between eigenvalues"); hestOptAdd(&hopt, "g", "glyph shape", airTypeEnum, 1, 1, >ype, "sqd", "glyph to use; not all are implemented here", NULL, tenGlyphType); hestOptAdd(&hopt, "pp", "x y z", airTypeFloat, 3, 3, pp, "0 0 0", "transform: rotation identified by" "location in quaternion quotient space"); hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015", "black axis cylinder radius (or 0.0 to not drawn these)"); hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25", "tesselation resolution for both glyph and axis cylinders"); hestOptAdd(&hopt, "pg", "ka kd ks", airTypeFloat, 3, 3, kadsSoid, "0.2 0.8 0.0", "phong coefficients for glyph"); hestOptAdd(&hopt, "pr", "ka kd ks", airTypeFloat, 3, 3, kadsRod, "1 0 0", "phong coefficients for black rods (if being drawn)"); hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off", "output file to save OFF into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); obj = limnObjectNew(1000, AIR_TRUE); airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways); if (!( 0 == escl[0] || 1 == escl[0] || 2 == escl[0] )) { fprintf(stderr, "%s: escl[0] %g not 0, 1 or 2\n", me, escl[0]); airMopError(mop); return 1; } if (!(tenGlyphTypeBox == gtype || tenGlyphTypeSphere == gtype || tenGlyphTypeSuperquad == gtype)) { fprintf(stderr, "%s: got %s %s, but here only do %s, %s, or %s\n", me, tenGlyphType->name, airEnumStr(tenGlyphType, gtype), airEnumStr(tenGlyphType, tenGlyphTypeBox), airEnumStr(tenGlyphType, tenGlyphTypeSphere), airEnumStr(tenGlyphType, tenGlyphTypeSuperquad)); airMopError(mop); return 1; } /* create limnLooks for glyph and for rods */ lookSoid = limnObjectLookAdd(obj); look = obj->look + lookSoid; ELL_4V_SET(look->rgba, 1, 1, 1, 1); ELL_3V_COPY(look->kads, kadsSoid); look->spow = 0; lookRod = limnObjectLookAdd(obj); look = obj->look + lookRod; ELL_4V_SET(look->rgba, 0, 0, 0, 1); ELL_3V_COPY(look->kads, kadsRod); look->spow = 0; ELL_3M_IDENTITY_SET(matA); /* A = I */ ELL_3V_SCALE(eval, os, eval); ELL_3M_SCALE_SET(matB, eval[0], eval[1], eval[2]); /* B = diag(eval) */ ell_3m_post_mul_d(matA, matB); /* A = B*A = diag(eval) */ if (0 == escl[0]) { scalingMatrix(matB, escl + 1, escl[4]); ell_3m_post_mul_d(matA, matB); } if (1 != vs) { if (!ELL_3V_LEN(view)) { fprintf(stderr, "%s: need non-zero view for vs %g != 1\n", me, vs); airMopError(mop); return 1; } scalingMatrix(matB, view, vs); /* the scaling along the view direction is a symmetric matrix, but applying that scaling to the symmetric input tensor is not necessarily symmetric */ ell_3m_post_mul_d(matA, matB); /* A = B*A */ } /* so we do an SVD to get rotation U and the scalings sval[] */ /* U * diag(sval) * V */ ell_3m_svd_d(uu, sval, vv, matA, AIR_TRUE); /* fprintf(stderr, "%s: ____________________________________\n", me); fprintf(stderr, "%s: mat = \n", me); ell_3m_print_d(stderr, matA); fprintf(stderr, "%s: uu = \n", me); ell_3m_print_d(stderr, uu); ELL_3M_TRANSPOSE(matC, uu); ELL_3M_MUL(matB, uu, matC); fprintf(stderr, "%s: uu * uu^T = \n", me); ell_3m_print_d(stderr, matB); fprintf(stderr, "%s: sval = %g %g %g\n", me, sval[0], sval[1], sval[2]); fprintf(stderr, "%s: vv = \n", me); ell_3m_print_d(stderr, vv); ELL_3M_MUL(matB, vv, vv); fprintf(stderr, "%s: vv * vv^T = \n", me); ELL_3M_TRANSPOSE(matC, vv); ELL_3M_MUL(matB, vv, matC); ell_3m_print_d(stderr, matB); ELL_3M_IDENTITY_SET(matA); ell_3m_pre_mul_d(matA, uu); ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]); ell_3m_pre_mul_d(matA, matB); ell_3m_pre_mul_d(matA, vv); fprintf(stderr, "%s: uu * diag(sval) * vv = \n", me); ell_3m_print_d(stderr, matA); fprintf(stderr, "%s: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", me); */ /* now create symmetric matrix out of U and sval */ /* A = I */ ELL_3M_IDENTITY_SET(matA); ell_3m_pre_mul_d(matA, uu); /* A = A*U = I*U = U */ ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]); /* B = diag(sval) */ ell_3m_pre_mul_d(matA, matB); /* A = U*diag(sval) */ ELL_3M_TRANSPOSE(matB, uu); ell_3m_pre_mul_d(matA, matB); /* A = U*diag(sval)*U^T */ TEN_M2T(ten, matA); partIdx = soidDoit(obj, lookSoid, gtype, gamma, res, (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) ? AB : NULL, ten); if (1 == escl[0]) { scalingMatrix(matB, escl + 1, escl[4]); ELL_43M_INSET(matBf, matB); limnObjectPartTransform(obj, partIdx, matBf); } /* this is a rotate on the geomtry; nothing to do with the tensor */ ELL_4V_SET(qq, 1, pp[0], pp[1], pp[2]); ELL_4V_NORM(qq, qq, len); ell_q_to_3m_f(mR, qq); ELL_43M_INSET(matBf, mR); limnObjectPartTransform(obj, partIdx, matBf); if (rad) { partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, (1-eval[0])/2, rad, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, (1+eval[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, (1-eval[0])/2, rad, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, -(1+eval[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, (1-eval[1])/2, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, (1+eval[1])/2, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, (1-eval[1])/2, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, -(1+eval[1])/2, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, rad, (1-eval[2])/2); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, (1+eval[2])/2); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, rad, (1-eval[2])/2); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, -(1+eval[2])/2); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); } file = airFopen(outS, stdout, "w"); airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (limnObjectWriteOFF(file, obj)) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { const char *me; char *err, *outS; float p[3], q[4], mR[9], eval[3]={0,0,0}, scale[3], len, sh, cl, cp, qA, qB; float matA[16], matB[16], os, rad, AB[2]; hestOpt *hopt=NULL; airArray *mop; limnObject *obj; limnLook *look; int lookRod, lookSoid; int partIdx=-1; /* sssh */ int res, axis, sphere; FILE *file; me = argv[0]; hestOptAdd(&hopt, "sc", "scalings", airTypeFloat, 3, 3, scale, "1 1 1", "axis-aligned scaling to do on ellipsoid"); hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan", "Directly set the A, B parameters to the superquadric surface, " "over-riding the default behavior of determining them from the " "scalings \"-sc\" as superquadric tensor glyphs"); hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1", "over-all scaling (multiplied by scalings)"); hestOptAdd(&hopt, "sh", "superquad sharpness", airTypeFloat, 1, 1, &sh, "0", "how much to sharpen edges as a " "function of differences between eigenvalues"); hestOptAdd(&hopt, "sphere", NULL, airTypeInt, 0, 0, &sphere, NULL, "use a sphere instead of a superquadric"); hestOptAdd(&hopt, "p", "x y z", airTypeFloat, 3, 3, p, "0 0 0", "location in quaternion quotient space"); hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015", "black axis cylinder radius (or 0.0 to not drawn these)"); hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25", "tesselation resolution for both glyph and axis cylinders"); hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off", "output file to save OFF into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); obj = limnObjectNew(100, AIR_FALSE); airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways); /* create limnLooks for ellipsoid and for rods */ lookSoid = limnObjectLookAdd(obj); look = obj->look + lookSoid; ELL_4V_SET(look->rgba, 1, 1, 1, 1); ELL_3V_SET(look->kads, 0.2, 0.8, 0); look->spow = 0; lookRod = limnObjectLookAdd(obj); look = obj->look + lookRod; ELL_4V_SET(look->rgba, 0, 0, 0, 1); ELL_3V_SET(look->kads, 1, 0, 0); look->spow = 0; ELL_4V_SET(q, 1, p[0], p[1], p[2]); ELL_4V_NORM(q, q, len); ell_q_to_3m_f(mR, q); if (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) { qA = AB[0]; qB = AB[1]; axis = 2; } else { ELL_3V_SCALE(scale, os, scale); ELL_3V_COPY(eval, scale); ELL_SORT3(eval[0], eval[1], eval[2], cl); cl = (eval[0] - eval[1])/(eval[0] + eval[1] + eval[2]); cp = 2*(eval[1] - eval[2])/(eval[0] + eval[1] + eval[2]); if (cl > cp) { axis = ELL_MAX3_IDX(scale[0], scale[1], scale[2]); qA = pow(1-cp, sh); qB = pow(1-cl, sh); } else { axis = ELL_MIN3_IDX(scale[0], scale[1], scale[2]); qA = pow(1-cl, sh); qB = pow(1-cp, sh); } /* fprintf(stderr, "eval = %g %g %g -> cl=%g %s cp=%g -> axis = %d\n", eval[0], eval[1], eval[2], cl, cl > cp ? ">" : "<", cp, axis); */ } if (sphere) { partIdx = limnObjectPolarSphereAdd(obj, lookSoid, 0, 2*res, res); } else { partIdx = limnObjectPolarSuperquadAdd(obj, lookSoid, axis, qA, qB, 2*res, res); } ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, scale[0], scale[1], scale[2]); ell_4m_post_mul_f(matA, matB); ELL_43M_INSET(matB, mR); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); if (rad) { partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, (1-eval[0])/2, rad, rad); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, (1+eval[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, (1-eval[0])/2, rad, rad); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, -(1+eval[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, rad, (1-eval[1])/2, rad); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, (1+eval[1])/2, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, rad, (1-eval[1])/2, rad); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, -(1+eval[1])/2, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, rad, rad, (1-eval[2])/2); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, (1+eval[2])/2); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, rad, rad, (1-eval[2])/2); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, -(1+eval[2])/2); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); } file = airFopen(outS, stdout, "w"); airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (limnObjectWriteOFF(file, obj)) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
/* ******** limnCameraUpdate() ** ** sets in cam: W2V, V2W, U, V, N, vspNeer, vspFaar, vspDist ** and, if fov and aspect are set, this also sets uRange and vRange ** ** This does use biff to describe problems with camera settings */ int limnCameraUpdate(limnCamera *cam) { static const char me[] = "limnCameraUpdate"; double len, bb[4], uu[4], vv[4], nn[4], TT[16], RR[16]; if (!cam) { biffAddf(LIMN, "%s: got NULL pointer", me); return 1; } ELL_4V_SET(uu, 0, 0, 0, 0); ELL_4V_SET(vv, 0, 0, 0, 0); ELL_4V_SET(nn, 0, 0, 0, 0); ELL_4V_SET(bb, 0, 0, 0, 1); ELL_3V_SUB(nn, cam->at, cam->from); len = ELL_3V_LEN(nn); if (!len) { biffAddf(LIMN, "%s: cam->at (%g,%g,%g) == cam->from", me, cam->at[0], cam->at[1], cam->at[2]); return 1; } if (cam->atRelative) { /* ctx->cam->{neer,dist} are "at" relative */ cam->vspNeer = cam->neer + len; cam->vspFaar = cam->faar + len; cam->vspDist = cam->dist + len; } else { /* ctx->cam->{neer,dist} are eye relative */ cam->vspNeer = cam->neer; cam->vspFaar = cam->faar; cam->vspDist = cam->dist; } if (!(cam->vspNeer > 0 && cam->vspDist > 0 && cam->vspFaar > 0)) { biffAddf(LIMN, "%s: eye-relative near (%g), dist (%g), or far (%g) <= 0", me, cam->vspNeer, cam->vspDist, cam->vspFaar); return 1; } if (!(cam->vspNeer <= cam->vspFaar)) { biffAddf(LIMN, "%s: eye-relative near (%g) further than far (%g)", me, cam->vspNeer, cam->vspFaar); return 1 ; } if (AIR_EXISTS(cam->fov)) { if (!( AIR_IN_OP(0.0, cam->fov, 180.0) )) { biffAddf(LIMN, "%s: cam->fov (%g) not in valid range between 0 and 180", me, cam->fov); return 1 ; } if (!AIR_EXISTS(cam->aspect)) { biffAddf(LIMN, "%s: cam->fov set, but cam->aspect isn't", me); return 1; } /* "fov" is half vertical angle */ cam->vRange[0] = -tan(cam->fov*AIR_PI/360)*(cam->vspDist); cam->vRange[1] = -cam->vRange[0]; cam->uRange[0] = cam->vRange[0]*(cam->aspect); cam->uRange[1] = -cam->uRange[0]; } /* else cam->fov isn't set, but we're not going to complain if uRange and vRange aren't both set ... */ ELL_3V_SCALE(nn, 1.0/len, nn); ELL_3V_CROSS(uu, nn, cam->up); len = ELL_3V_LEN(uu); if (!len) { biffAddf(LIMN, "%s: cam->up is co-linear with view direction", me); return 1 ; } ELL_3V_SCALE(uu, 1.0/len, uu); if (cam->rightHanded) { ELL_3V_CROSS(vv, nn, uu); } else { ELL_3V_CROSS(vv, uu, nn); } ELL_4V_COPY(cam->U, uu); ELL_4V_COPY(cam->V, vv); ELL_4V_COPY(cam->N, nn); ELL_4M_TRANSLATE_SET(TT, -cam->from[0], -cam->from[1], -cam->from[2]); ELL_4M_ROWS_SET(RR, uu, vv, nn, bb); ELL_4M_MUL(cam->W2V, RR, TT); ell_4m_inv_d(cam->V2W, cam->W2V); return 0; }
int main(int argc, const char *argv[]) { const char *me; char *err, *outS; double scale[3], matA[9], matB[9], matC[9], sval[3], uu[9], vv[9]; float matAf[9], matBf[16]; float p[3], q[4], mR[9], len, gamma; float os, vs, rad, AB[2], ten[7], view[3]; hestOpt *hopt=NULL; airArray *mop; limnObject *obj; limnLook *look; int lookRod, lookSoid; int partIdx=-1; /* sssh */ int res, sphere; FILE *file; me = argv[0]; hestOptAdd(&hopt, "sc", "scalings", airTypeDouble, 3, 3, scale, "1 1 1", "axis-aligned scaling to do on ellipsoid"); hestOptAdd(&hopt, "AB", "A, B exponents", airTypeFloat, 2, 2, AB, "nan nan", "Directly set the A, B parameters to the superquadric surface, " "over-riding the default behavior of determining them from the " "scalings \"-sc\" as superquadric tensor glyphs"); hestOptAdd(&hopt, "os", "over-all scaling", airTypeFloat, 1, 1, &os, "1", "over-all scaling (multiplied by scalings)"); hestOptAdd(&hopt, "vs", "over-all scaling", airTypeFloat, 1, 1, &vs, "1", "scaling along view-direction (to show off bas-relief " "ambibuity of ellipsoids versus superquads)"); hestOptAdd(&hopt, "fr", "from (eye) point", airTypeFloat, 3, 3, &view, "4 4 4", "eye point, needed for non-unity \"-vs\""); hestOptAdd(&hopt, "gamma", "superquad sharpness", airTypeFloat, 1, 1, &gamma, "0", "how much to sharpen edges as a " "function of differences between eigenvalues"); hestOptAdd(&hopt, "sphere", NULL, airTypeInt, 0, 0, &sphere, NULL, "use a sphere instead of a superquadric"); hestOptAdd(&hopt, "p", "x y z", airTypeFloat, 3, 3, p, "0 0 0", "location in quaternion quotient space"); hestOptAdd(&hopt, "r", "radius", airTypeFloat, 1, 1, &rad, "0.015", "black axis cylinder radius (or 0.0 to not drawn these)"); hestOptAdd(&hopt, "res", "resolution", airTypeInt, 1, 1, &res, "25", "tesselation resolution for both glyph and axis cylinders"); hestOptAdd(&hopt, "o", "output OFF", airTypeString, 1, 1, &outS, "out.off", "output file to save OFF into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); obj = limnObjectNew(1000, AIR_TRUE); airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways); /* create limnLooks for ellipsoid and for rods */ lookSoid = limnObjectLookAdd(obj); look = obj->look + lookSoid; ELL_4V_SET(look->rgba, 1, 1, 1, 1); ELL_3V_SET(look->kads, 0.2, 0.8, 0); look->spow = 0; lookRod = limnObjectLookAdd(obj); look = obj->look + lookRod; ELL_4V_SET(look->rgba, 0, 0, 0, 1); ELL_3V_SET(look->kads, 1, 0, 0); look->spow = 0; ELL_3M_IDENTITY_SET(matA); ELL_3V_SCALE(scale, os, scale); ELL_3M_SCALE_SET(matB, scale[0], scale[1], scale[2]); ell_3m_post_mul_d(matA, matB); if (1 != vs) { ELL_3V_NORM(view, view, len); if (!len) { /* HEY: perhaps do more diplomatic error message here */ fprintf(stderr, "%s: stupido!\n", me); exit(1); } ELL_3MV_OUTER(matB, view, view); ELL_3M_SCALE(matB, vs-1, matB); ELL_3M_IDENTITY_SET(matC); ELL_3M_ADD2(matB, matC, matB); ell_3m_post_mul_d(matA, matB); } ell_3m_svd_d(uu, sval, vv, matA, AIR_TRUE); /* fprintf(stderr, "%s: ____________________________________\n", me); fprintf(stderr, "%s: mat = \n", me); ell_3m_print_d(stderr, matA); fprintf(stderr, "%s: uu = \n", me); ell_3m_print_d(stderr, uu); ELL_3M_TRANSPOSE(matC, uu); ELL_3M_MUL(matB, uu, matC); fprintf(stderr, "%s: uu * uu^T = \n", me); ell_3m_print_d(stderr, matB); fprintf(stderr, "%s: sval = %g %g %g\n", me, sval[0], sval[1], sval[2]); fprintf(stderr, "%s: vv = \n", me); ell_3m_print_d(stderr, vv); ELL_3M_MUL(matB, vv, vv); fprintf(stderr, "%s: vv * vv^T = \n", me); ELL_3M_TRANSPOSE(matC, vv); ELL_3M_MUL(matB, vv, matC); ell_3m_print_d(stderr, matB); ELL_3M_IDENTITY_SET(matA); ell_3m_pre_mul_d(matA, uu); ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]); ell_3m_pre_mul_d(matA, matB); ell_3m_pre_mul_d(matA, vv); fprintf(stderr, "%s: uu * diag(sval) * vv = \n", me); ell_3m_print_d(stderr, matA); fprintf(stderr, "%s: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", me); */ ELL_3M_IDENTITY_SET(matA); ell_3m_pre_mul_d(matA, uu); ELL_3M_SCALE_SET(matB, sval[0], sval[1], sval[2]); ell_3m_pre_mul_d(matA, matB); ELL_3M_TRANSPOSE(matB, uu); ell_3m_pre_mul_d(matA, matB); TEN_M2T(ten, matA); partIdx = soidDoit(obj, lookSoid, sphere, gamma, res, (AIR_EXISTS(AB[0]) && AIR_EXISTS(AB[1])) ? AB : NULL, ten); ELL_4V_SET(q, 1, p[0], p[1], p[2]); ELL_4V_NORM(q, q, len); ell_q_to_3m_f(mR, q); ELL_43M_INSET(matBf, mR); limnObjectPartTransform(obj, partIdx, matBf); if (rad) { partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, (1-scale[0])/2, rad, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, (1+scale[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 0, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, (1-scale[0])/2, rad, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, -(1+scale[0])/2, 0.0, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, (1-scale[1])/2, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, (1+scale[1])/2, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 1, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, (1-scale[1])/2, rad); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, -(1+scale[1])/2, 0.0); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, rad, (1-scale[2])/2); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, (1+scale[2])/2); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); partIdx = limnObjectCylinderAdd(obj, lookRod, 2, res); ELL_4M_IDENTITY_SET(matAf); ELL_4M_SCALE_SET(matBf, rad, rad, (1-scale[2])/2); ell_4m_post_mul_f(matAf, matBf); ELL_4M_TRANSLATE_SET(matBf, 0.0, 0.0, -(1+scale[2])/2); ell_4m_post_mul_f(matAf, matBf); limnObjectPartTransform(obj, partIdx, matAf); } file = airFopen(outS, stdout, "w"); airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (limnObjectWriteOFF(file, obj)) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *err, *outS; limnCamera *cam; float matA[16], matB[16], winscale, edgeWidth[5]; hestOpt *hopt=NULL; airArray *mop; limnObject *obj; limnLook *look; int lookIdx; limnWindow *win; int partIdx, wire, concave; Nrrd *nmap; mop = airMopNew(); cam = limnCameraNew(); airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways); me = argv[0]; hestOptAdd(&hopt, "fr", "from point", airTypeDouble, 3, 3, cam->from,"4 4 4", "position of camera, used to determine view vector"); hestOptAdd(&hopt, "at", "at point", airTypeDouble, 3, 3, cam->at, "0 0 0", "camera look-at point, used to determine view vector"); hestOptAdd(&hopt, "up", "up vector", airTypeDouble, 3, 3, cam->up, "0 0 1", "camera pseudo-up vector, used to determine view coordinates"); hestOptAdd(&hopt, "rh", NULL, airTypeInt, 0, 0, &(cam->rightHanded), NULL, "use a right-handed UVN frame (V points down)"); hestOptAdd(&hopt, "or", NULL, airTypeInt, 0, 0, &(cam->orthographic), NULL, "use orthogonal projection"); hestOptAdd(&hopt, "ur", "uMin uMax", airTypeDouble, 2, 2, cam->uRange, "-1 1", "range in U direction of image plane"); hestOptAdd(&hopt, "vr", "vMin vMax", airTypeDouble, 2, 2, cam->vRange, "-1 1", "range in V direction of image plane"); hestOptAdd(&hopt, "e", "envmap", airTypeOther, 1, 1, &nmap, NULL, "16checker-based environment map", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "ws", "winscale", airTypeFloat, 1, 1, &winscale, "200", "world to points (PostScript) scaling"); hestOptAdd(&hopt, "wire", NULL, airTypeInt, 0, 0, &wire, NULL, "just do wire-frame rendering"); hestOptAdd(&hopt, "concave", NULL, airTypeInt, 0, 0, &concave, NULL, "use slightly buggy rendering method suitable for " "concave or self-occluding objects"); hestOptAdd(&hopt, "wd", "5 widths", airTypeFloat, 5, 5, edgeWidth, "0.0 0.0 3.0 2.0 0.0", "width of edges drawn for five kinds of " "edges: back non-crease, back crease, " "silohuette, front crease, front non-crease"); hestOptAdd(&hopt, "o", "output PS", airTypeString, 1, 1, &outS, "out.ps", "output file to render postscript into"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); cam->neer = -0.000000001; cam->dist = 0; cam->faar = 0.0000000001; cam->atRelative = AIR_TRUE; if (limnCameraUpdate(cam)) { fprintf(stderr, "%s: trouble:\n%s\n", me, err = biffGet(LIMN)); free(err); return 1; } obj = limnObjectNew(10, AIR_TRUE); airMopAdd(mop, obj, (airMopper)limnObjectNix, airMopAlways); /* create limnLooks for diffuse (#0) and flat (#1) shading */ lookIdx = airArrayLenIncr(obj->lookArr, 2); look = obj->look + lookIdx + 0; ELL_4V_SET(look->rgba, 1, 1, 1, 1); ELL_3V_SET(look->kads, 0, 1, 0); look->spow = 0; look = obj->look + lookIdx + 1; ELL_4V_SET(look->rgba, 1, 1, 1, 1); ELL_3V_SET(look->kads, 1, 0, 0); look->spow = 0; /* X axis: rod */ partIdx = limnObjectCylinderAdd(obj, 0, 0, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 1, 0.2, 0.2); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 1.3, 0.0, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); /* Y axis: rod + ball */ partIdx = limnObjectCylinderAdd(obj, 0, 1, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 0.2, 1, 0.2); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 1.3, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectPolarSphereAdd(obj, 0, 0, 32, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 2.6, 0.0); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); /* Z axis: rod + ball + ball */ partIdx = limnObjectCylinderAdd(obj, 0, 2, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 0.2, 0.2, 1); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 1.3); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectPolarSphereAdd(obj, 0, 1, 32, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 2.6); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); partIdx = limnObjectPolarSphereAdd(obj, 0, 2, 32, 16); ELL_4M_IDENTITY_SET(matA); ELL_4M_SCALE_SET(matB, 0.28, 0.28, 0.28); ell_4m_post_mul_f(matA, matB); ELL_4M_TRANSLATE_SET(matB, 0.0, 0.0, 3.2); ell_4m_post_mul_f(matA, matB); limnObjectPartTransform(obj, partIdx, matA); win = limnWindowNew(limnDevicePS); win->scale = winscale; win->ps.wireFrame = wire; win->ps.lineWidth[limnEdgeTypeBackFacet] = edgeWidth[0]; win->ps.lineWidth[limnEdgeTypeBackCrease] = edgeWidth[1]; win->ps.lineWidth[limnEdgeTypeContour] = edgeWidth[2]; win->ps.lineWidth[limnEdgeTypeFrontCrease] = edgeWidth[3]; win->ps.lineWidth[limnEdgeTypeFrontFacet] = edgeWidth[4]; win->file = fopen(outS, "w"); airMopAdd(mop, win, (airMopper)limnWindowNix, airMopAlways); if (limnObjectRender(obj, cam, win) || (concave ? limnObjectPSDrawConcave(obj, cam, nmap, win) : limnObjectPSDraw(obj, cam, nmap, win))) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } fclose(win->file); airMopOkay(mop); return 0; }
void makeSceneGlassTest(limnCamera *cam, echoRTParm *parm, echoScene *scene) { echoObject *cube, *rect, *inst; echoCol_t r, g, b; Nrrd *ntext; int i, N; echoPos_t ma[16], mb[16]; ELL_3V_SET(cam->from, 0, 0, 10); ELL_3V_SET(cam->at, 0, 0, 0); ELL_3V_SET(cam->up, 1, 0, 0); cam->uRange[0] = -1.1; cam->uRange[1] = 1.1; cam->vRange[0] = -1.1; cam->vRange[1] = 1.1; parm->jitterType = echoJitterNone; parm->numSamples = 1; parm->imgResU = 220; parm->imgResV = 220; parm->aperture = 0.0; parm->renderLights = AIR_FALSE; parm->seedRand = AIR_FALSE; ELL_3V_SET(scene->bkgr, 0.2, 0.3, 0.4); /* parm->shadow = 0.0; */ /* create scene */ N = 11; for (i=0; i<N; i++) { cube = echoObjectNew(scene, echoTypeCube); _dyeHSVtoRGB(&r, &g, &b, AIR_AFFINE(0, i, N, 0.0, 1.0), 1.0, 1.0); echoColorSet(cube, r, g, b, 1); echoMatterGlassSet(scene, cube, 1.1, 0.0, 0.0, 0); inst = echoObjectNew(scene, echoTypeInstance); ELL_4M_IDENTITY_SET(ma); ELL_4M_SCALE_SET(mb, 1.0/(N+2), 0.8, 3.0/(N+2)); ell_4m_POST_MUL(ma, mb); ELL_4M_ROTATE_X_SET(mb, AIR_AFFINE(0, i, N-1, -AIR_PI/2, AIR_PI/2)); ell_4m_POST_MUL(ma, mb); ELL_4M_TRANSLATE_SET(mb, AIR_AFFINE(0, i, N-1, -0.8, 0.8), 0, 1); ell_4m_POST_MUL(ma, mb); echoInstanceSet(inst, ma, cube); echoObjectAdd(scene, inst); } rect = echoObjectNew(scene, echoTypeRectangle); echoRectangleSet(rect, -1, 1, 0, 0, -2, 0, 2, 0, 0); echoColorSet(rect, 1.0, 1.0, 1.0, 1.0); echoMatterPhongSet(scene, rect, 1.0, 0.0, 0.0, 40); nrrdLoad(ntext=nrrdNew(), "pot.png", NULL); echoMatterTextureSet(scene, rect, ntext); echoObjectAdd(scene, rect); rect = echoObjectNew(scene, echoTypeRectangle); echoRectangleSet(rect, -0.25, -0.25, 10, 0.5, 0, 0, 0, 0.5, 0); echoColorSet(rect, 1, 1, 1, 1); echoMatterLightSet(scene, rect, 1, 0); return; }
void makeSceneInstance(limnCamera *cam, echoRTParm *parm, echoScene *scene) { echoObject *trim, *rect, *inst; echoPos_t matx[16], A[16], B[16]; ELL_3V_SET(cam->from, 9*1.3, 9*1.3, 11*1.3); ELL_3V_SET(cam->at, 0, 0, 0); ELL_3V_SET(cam->up, 0, 0, 1); cam->uRange[0] = -5; cam->uRange[1] = 5; cam->vRange[0] = -5; cam->vRange[1] = 5; parm->jitterType = echoJitterNone; parm->numSamples = 1; parm->imgResU = 300; parm->imgResV = 300; parm->aperture = 0.0; parm->renderLights = AIR_TRUE; parm->renderBoxes = AIR_FALSE; parm->seedRand = AIR_FALSE; parm->maxRecDepth = 10; parm->shadow = 1.0; ELL_4M_IDENTITY_SET(matx); ELL_4M_SCALE_SET(B, 2.5, 1.5, 0.8); ELL_4M_MUL(A, B, matx); ELL_4M_COPY(matx, A); ELL_4M_ROTATE_X_SET(B, 0.2); ELL_4M_MUL(A, B, matx); ELL_4M_COPY(matx, A); ELL_4M_ROTATE_Y_SET(B, 0.2); ELL_4M_MUL(A, B, matx); ELL_4M_COPY(matx, A); ELL_4M_ROTATE_Y_SET(B, 0.2); ELL_4M_MUL(A, B, matx); ELL_4M_COPY(matx, A); ELL_4M_TRANSLATE_SET(B, 0, 0, 1); ELL_4M_MUL(A, B, matx); ELL_4M_COPY(matx, A); /* trim = echoRoughSphere(50, 25, matx); */ /* trim = echoRoughSphere(8, 4, matx); echoMatterGlassSet(trim, 0.8, 0.8, 0.8, 1.3, 0.0, 0.0); echoMatterPhongSet(trim, 1, 1, 1, 1.0, 0.1, 0.5, 0.9, 50); echoObjectAdd(scene, trim); */ trim = echoObjectNew(scene, echoTypeSphere); echoSphereSet(trim, 0, 0, 0, 1); echoColorSet(trim, 0.8, 0.8, 0.8, 1.0); echoMatterGlassSet(scene, trim, 1.3, 0.0, 0.0, 0.0); echoMatterPhongSet(scene, trim, 0.1, 0.5, 0.9, 50); inst = echoObjectNew(scene, echoTypeInstance); echoInstanceSet(inst, matx, trim); echoObjectAdd(scene, inst); rect = echoObjectNew(scene, echoTypeRectangle); echoRectangleSet(rect, -3.5, -3.5, -3.5, 7, 0, 0, 0, 7, 0); echoColorSet(trim, 1.0, 1.0, 1.0, 1.0); echoMatterPhongSet(scene, rect, 0.1, 0.5, 0.9, 50); echoObjectAdd(scene, rect); rect = echoObjectNew(scene, echoTypeRectangle); echoRectangleSet(rect, -3.5, -3.5, -3.5, 0, 7, 0, 0, 0, 7); echoColorSet(rect, 1.0, 1.0, 1.0, 1.0); echoMatterPhongSet(scene, rect, 0.1, 0.5, 0.9, 50); echoObjectAdd(scene, rect); /* rect = echoObjectNew(scene, echoTypeRectangle); echoRectangleSet(rect, -3.5, -3.5, -3.5, 0, 0, 7, 7, 0, 0); */ rect = echoObjectNew(scene, echoTypeSphere); echoSphereSet(rect, 0, 0, 0, 1); echoColorSet(rect, 1.0, 1.0, 1.0, 1.0); echoMatterPhongSet(scene, rect, 0.1, 0.5, 0.9, 50); inst = echoObjectNew(scene, echoTypeInstance); ELL_4M_SCALE_SET(A, 20, 20, 20); ELL_4M_TRANSLATE_SET(B, 0, -(20+3.5), 0); ELL_4M_MUL(matx, B, A); echoInstanceSet(inst, matx, rect); echoObjectAdd(scene, inst); /* light = echoLightNew(echoLightDirectional); echoLightDirectionalSet(light, 1, 0, 0, 1, 0.001, 0.001); echoLightArrayAdd(lightArr, light); light = echoLightNew(echoLightDirectional); echoLightDirectionalSet(light, 0, 1, 0, 0.001, 1, 0.001); echoLightArrayAdd(lightArr, light); light = echoLightNew(echoLightDirectional); echoLightDirectionalSet(light, 0, 0, 1, 0.001, 0.001, 1); echoLightArrayAdd(lightArr, light); */ return; }