Ignore:
Timestamp:
Jan 27, 2011 10:03:13 AM (13 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/FlowCmd.cpp

    r1984 r2070  
     1#include <nvconf.h>
     2#if defined(HAVE_FFMPEG_AVFORMAT_H) || defined(HAVE_LIBAVFORMAT_AVFORMAT_H)
     3#define HAVE_FFMPEG 1
     4#endif
    15
    26#include <assert.h>
     
    1216#include <RpFieldPrism3D.h>
    1317#include <RpOutcome.h>
     18#ifdef HAVE_FFMPEG
    1419#include <RpAVTranslate.h>
     20#endif
    1521#include "Trace.h"
    1622#include "TransferFunction.h"
     
    13571363}
    13581364
     1365static int
     1366FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1367                Tcl_Obj *const *objv)
     1368{
     1369    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1370
     1371    if (flowPtr->ParseSwitches(interp, objc - 2, objv + 2) != TCL_OK) {
     1372        return TCL_ERROR;
     1373    }
     1374    NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
     1375    return TCL_OK;
     1376}
     1377
     1378static int
     1379FlowParticlesAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1380                   Tcl_Obj *const *objv)
     1381{
     1382    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1383
     1384    if (flowPtr->CreateParticles(interp, objv[3]) != TCL_OK) {
     1385        return TCL_ERROR;
     1386    }
     1387    FlowParticles *particlesPtr;
     1388    if (flowPtr->GetParticles(interp, objv[3], &particlesPtr) != TCL_OK) {
     1389        return TCL_ERROR;
     1390    }
     1391    if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     1392        delete particlesPtr;
     1393        return TCL_ERROR;
     1394    }
     1395    particlesPtr->Configure();
     1396    NanoVis::EventuallyRedraw();
     1397    Tcl_SetObjResult(interp, objv[3]);
     1398    return TCL_OK;
     1399}
     1400
     1401static int
     1402FlowParticlesConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1403                         Tcl_Obj *const *objv)
     1404{
     1405    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1406
     1407    FlowParticles *particlesPtr;
     1408    if (flowPtr->GetParticles(interp, objv[3], &particlesPtr) != TCL_OK) {
     1409        return TCL_ERROR;
     1410    }
     1411    if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     1412        return TCL_ERROR;
     1413    }
     1414    particlesPtr->Configure();
     1415    NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
     1416    return TCL_OK;
     1417}
     1418
     1419static int
     1420FlowParticlesDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1421                      Tcl_Obj *const *objv)
     1422{
     1423    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1424    int i;
     1425    for (i = 3; i < objc; i++) {
     1426        FlowParticles *particlesPtr;
     1427
     1428        if (flowPtr->GetParticles(NULL, objv[i], &particlesPtr) == TCL_OK) {
     1429            delete particlesPtr;
     1430        }
     1431    }
     1432    NanoVis::EventuallyRedraw();
     1433    return TCL_OK;
     1434}
     1435
     1436static int
     1437FlowParticlesNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1438                     Tcl_Obj *const *objv)
     1439{
     1440    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1441    Tcl_Obj *listObjPtr;
     1442    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     1443    FlowParticlesIterator iter;
     1444    FlowParticles *particlesPtr;
     1445    for (particlesPtr = flowPtr->FirstParticles(&iter); particlesPtr != NULL;
     1446         particlesPtr = flowPtr->NextParticles(&iter)) {
     1447        Tcl_Obj *objPtr;
     1448
     1449        objPtr = Tcl_NewStringObj(particlesPtr->name(), -1);
     1450        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     1451    }
     1452    Tcl_SetObjResult(interp, listObjPtr);
     1453    return TCL_OK;
     1454}
     1455
     1456/*
     1457 *---------------------------------------------------------------------------
     1458 *
     1459 * FlowParticlesObjCmd --
     1460 *
     1461 *      This procedure is invoked to process commands on behalf of the flow
     1462 *      object.
     1463 *
     1464 * Results:
     1465 *      A standard Tcl result.
     1466 *
     1467 * Side effects:
     1468 *      See the user documentation.
     1469 *
     1470 * $flow particles oper $name
     1471 *---------------------------------------------------------------------------
     1472 */
     1473static Rappture::CmdSpec flowParticlesOps[] = {
     1474    {"add",        1, FlowParticlesAddOp,        4, 0, "name ?switches?",},
     1475    {"configure",  1, FlowParticlesConfigureOp,  4, 0, "name ?switches?",},
     1476    {"delete",     1, FlowParticlesDeleteOp,     4, 0, "?name...?"},
     1477    {"names",      1, FlowParticlesNamesOp,      3, 4, "?pattern?"},
     1478};
     1479
     1480static int nFlowParticlesOps = NumCmdSpecs(flowParticlesOps);
     1481
     1482static int
     1483FlowParticlesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1484               Tcl_Obj *const *objv)
     1485{
     1486    Tcl_ObjCmdProc *proc;
     1487    proc = Rappture::GetOpFromObj(interp, nFlowParticlesOps, flowParticlesOps,
     1488        Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1489    if (proc == NULL) {
     1490        return TCL_ERROR;
     1491    }
     1492    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1493    Tcl_Preserve(flowPtr);
     1494    int result;
     1495    result = (*proc) (clientData, interp, objc, objv);
     1496    Tcl_Release(flowPtr);
     1497    return result;
     1498}
     1499
     1500static int
     1501FlowBoxAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1502               Tcl_Obj *const *objv)
     1503{
     1504    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1505
     1506    if (flowPtr->CreateBox(interp, objv[3]) != TCL_OK) {
     1507        return TCL_ERROR;
     1508    }
     1509    FlowBox *boxPtr;
     1510    if (flowPtr->GetBox(interp, objv[3], &boxPtr) != TCL_OK) {
     1511        return TCL_ERROR;
     1512    }
     1513    if (boxPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     1514        delete boxPtr;
     1515        return TCL_ERROR;
     1516    }
     1517    NanoVis::EventuallyRedraw();
     1518    Tcl_SetObjResult(interp, objv[3]);
     1519    return TCL_OK;
     1520}
     1521
     1522static int
     1523FlowBoxDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1524                   Tcl_Obj *const *objv)
     1525{
     1526    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1527    int i;
     1528    for (i = 3; i < objc; i++) {
     1529        FlowBox *boxPtr;
     1530
     1531        if (flowPtr->GetBox(NULL, objv[i], &boxPtr) == TCL_OK) {
     1532            delete boxPtr;
     1533        }
     1534    }
     1535    NanoVis::EventuallyRedraw();
     1536    return TCL_OK;
     1537}
     1538
     1539static int
     1540FlowBoxNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1541             Tcl_Obj *const *objv)
     1542{
     1543    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1544    Tcl_Obj *listObjPtr;
     1545    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     1546    FlowBoxIterator iter;
     1547    FlowBox *boxPtr;
     1548    for (boxPtr = flowPtr->FirstBox(&iter); boxPtr != NULL;
     1549         boxPtr = flowPtr->NextBox(&iter)) {
     1550        Tcl_Obj *objPtr;
     1551
     1552        objPtr = Tcl_NewStringObj(boxPtr->name(), -1);
     1553        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     1554    }
     1555    Tcl_SetObjResult(interp, listObjPtr);
     1556    return TCL_OK;
     1557}
     1558
     1559static int
     1560FlowBoxConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1561                        Tcl_Obj *const *objv)
     1562{
     1563    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1564
     1565    FlowBox *boxPtr;
     1566    if (flowPtr->GetBox(interp, objv[3], &boxPtr) != TCL_OK) {
     1567        return TCL_ERROR;
     1568    }
     1569    if (boxPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
     1570        return TCL_ERROR;
     1571    }
     1572    NanoVis::EventuallyRedraw();
     1573    return TCL_OK;
     1574}
     1575
     1576/*
     1577 *---------------------------------------------------------------------------
     1578 *
     1579 * FlowBoxOp--
     1580 *
     1581 *      This procedure is invoked to process commands on behalf of the flow
     1582 *      object.
     1583 *
     1584 * Results:
     1585 *      A standard Tcl result.
     1586 *
     1587 * Side effects:
     1588 *      See the user documentation.
     1589 *
     1590 *---------------------------------------------------------------------------
     1591 */
     1592static Rappture::CmdSpec flowBoxOps[] = {
     1593    {"add",        1, FlowBoxAddOp,        4, 0, "name ?switches?",},
     1594    {"configure",  1, FlowBoxConfigureOp,  4, 0, "name ?switches?",},
     1595    {"delete",     1, FlowBoxDeleteOp,     3, 0, "?name...?"},
     1596    {"names",      1, FlowBoxNamesOp,      3, 0, "?pattern?"},
     1597};
     1598
     1599static int nFlowBoxOps = NumCmdSpecs(flowBoxOps);
     1600
     1601static int
     1602FlowBoxOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1603               Tcl_Obj *const *objv)
     1604{
     1605    Tcl_ObjCmdProc *proc;
     1606    proc = Rappture::GetOpFromObj(interp, nFlowBoxOps, flowBoxOps,
     1607        Rappture::CMDSPEC_ARG2, objc, objv, 0);
     1608    if (proc == NULL) {
     1609        return TCL_ERROR;
     1610    }
     1611    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1612    Tcl_Preserve(flowPtr);
     1613    int result;
     1614    result = (*proc) (clientData, interp, objc, objv);
     1615    Tcl_Release(flowPtr);
     1616    return result;
     1617}
     1618
     1619/*
     1620 * ----------------------------------------------------------------------
     1621 * CLIENT COMMAND:
     1622 *   $flow legend <width> <height>
     1623 *
     1624 * Clients use this to generate a legend image for the specified
     1625 * transfer function.  The legend image is a color gradient from 0
     1626 * to one, drawn in the given transfer function.  The resulting image
     1627 * is returned in the size <width> x <height>.
     1628 * ----------------------------------------------------------------------
     1629 */
     1630static int
     1631FlowLegendOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1632          Tcl_Obj *const *objv)
     1633{
     1634    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1635   
     1636    const char *string = Tcl_GetString(objv[1]);
     1637    TransferFunction *tf;
     1638    tf = flowPtr->GetTransferFunction();
     1639    if (tf == NULL) {
     1640        Tcl_AppendResult(interp, "unknown transfer function \"", string, "\"",
     1641                             (char*)NULL);
     1642        return TCL_ERROR;
     1643    }
     1644    const char *label;
     1645    label = Tcl_GetString(objv[0]);
     1646    int w, h;
     1647    if ((Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK) ||
     1648        (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)) {
     1649        return TCL_ERROR;
     1650    }
     1651    if (NanoVis::flags & NanoVis::MAP_FLOWS) {
     1652        NanoVis::MapFlows();
     1653    }
     1654    NanoVis::render_legend(tf, NanoVis::magMin, NanoVis::magMax, w, h, label);
     1655    return TCL_OK;
     1656}
     1657
     1658/*
     1659 *---------------------------------------------------------------------------
     1660 *
     1661 * FlowInstObjCmd --
     1662 *
     1663 *      This procedure is invoked to process commands on behalf of the flow
     1664 *      object.
     1665 *
     1666 * Results:
     1667 *      A standard Tcl result.
     1668 *
     1669 * Side effects:
     1670 *      See the user documentation.
     1671 *
     1672 *---------------------------------------------------------------------------
     1673 */
     1674static Rappture::CmdSpec flowInstOps[] = {
     1675    {"box",         1, FlowBoxOp,        2, 0, "oper ?args?"},
     1676    {"configure",   1, FlowConfigureOp,  2, 0, "?switches?"},
     1677    {"data",        1, FlowDataOp,       2, 0, "oper ?args?"},
     1678    {"legend",      1, FlowLegendOp,     4, 4, "w h"},
     1679    {"particles",   1, FlowParticlesOp,  2, 0, "oper ?args?"}
     1680};
     1681static int nFlowInstOps = NumCmdSpecs(flowInstOps);
     1682
     1683static int
     1684FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     1685               Tcl_Obj *const *objv)
     1686{
     1687    Tcl_ObjCmdProc *proc;
     1688    proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps,
     1689        Rappture::CMDSPEC_ARG1, objc, objv, 0);
     1690    if (proc == NULL) {
     1691        return TCL_ERROR;
     1692    }
     1693    assert(CheckGL(AT));
     1694    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1695    Tcl_Preserve(flowPtr);
     1696    int result;
     1697    result = (*proc) (clientData, interp, objc, objv);
     1698    Tcl_Release(flowPtr);
     1699    return result;
     1700}
     1701
     1702/*
     1703 *---------------------------------------------------------------------------
     1704 *
     1705 * FlowInstDeleteProc --
     1706 *
     1707 *      Deletes the command associated with the tree.  This is called only
     1708 *      when the command associated with the tree is destroyed.
     1709 *
     1710 * Results:
     1711 *      None.
     1712 *
     1713 *---------------------------------------------------------------------------
     1714 */
     1715static void
     1716FlowInstDeleteProc(ClientData clientData)
     1717{
     1718    FlowCmd *flowPtr = (FlowCmd *)clientData;
     1719    delete flowPtr;
     1720}
     1721
     1722/*
     1723 *---------------------------------------------------------------------------
     1724 *
     1725 * FlowAddOp --
     1726 *
     1727 *---------------------------------------------------------------------------
     1728 */
     1729/*ARGSUSED*/
     1730static int
     1731FlowAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1732          Tcl_Obj *const *objv)
     1733{
     1734    if (NanoVis::CreateFlow(interp, objv[2]) != TCL_OK) {
     1735        return TCL_ERROR;
     1736    }
     1737    FlowCmd *flowPtr;
     1738    if (NanoVis::GetFlow(interp, objv[2], &flowPtr) != TCL_OK) {
     1739        return TCL_ERROR;
     1740    }
     1741    if (flowPtr->ParseSwitches(interp, objc - 3, objv + 3) != TCL_OK) {
     1742        Tcl_DeleteCommand(interp, flowPtr->name());
     1743        return TCL_ERROR;
     1744    }
     1745    Tcl_SetObjResult(interp, objv[2]);
     1746    NanoVis::EventuallyRedraw();
     1747    return TCL_OK;
     1748}
     1749
     1750/*
     1751 *---------------------------------------------------------------------------
     1752 *
     1753 * FlowDeleteOp --
     1754 *
     1755 *---------------------------------------------------------------------------
     1756 */
     1757/*ARGSUSED*/
     1758static int
     1759FlowDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1760             Tcl_Obj *const *objv)
     1761{
     1762    int i;
     1763
     1764    for (i = 2; i < objc; i++) {
     1765        FlowCmd *flowPtr;
     1766
     1767        if (NanoVis::GetFlow(interp, objv[i], &flowPtr) != TCL_OK) {
     1768            return TCL_ERROR;
     1769        }
     1770        Tcl_DeleteCommand(interp, flowPtr->name());
     1771    }
     1772    NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
     1773    return TCL_OK;
     1774}
     1775
     1776/*
     1777 *---------------------------------------------------------------------------
     1778 *
     1779 * FlowExistsOp --
     1780 *
     1781 *---------------------------------------------------------------------------
     1782 */
     1783/*ARGSUSED*/
     1784static int
     1785FlowExistsOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1786             Tcl_Obj *const *objv)
     1787{
     1788    bool value;
     1789    FlowCmd *flowPtr;
     1790
     1791    value = false;
     1792    if (NanoVis::GetFlow(NULL, objv[2], &flowPtr) == TCL_OK) {
     1793        value = true;
     1794    }
     1795    Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (int)value);
     1796    return TCL_OK;
     1797}
     1798
     1799/*
     1800 *---------------------------------------------------------------------------
     1801 *
     1802 * FlowGotoOp --
     1803 *
     1804 *      flow goto number
     1805 *
     1806 *---------------------------------------------------------------------------
     1807 */
     1808static int
     1809FlowGotoOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1810             Tcl_Obj *const *objv)
     1811{
     1812    int nSteps;
     1813    if (Tcl_GetIntFromObj(interp, objv[2], &nSteps) != TCL_OK) {
     1814        return TCL_ERROR;
     1815    }
     1816    if ((nSteps < 0) || (nSteps > SHRT_MAX)) {
     1817        Tcl_AppendResult(interp, "flow goto: bad # of steps \"",
     1818                         Tcl_GetString(objv[2]), "\"", (char *)NULL);
     1819        return TCL_ERROR;
     1820    }
     1821    NanoVis::ResetFlows();
     1822    if (NanoVis::flags & NanoVis::MAP_FLOWS) {
     1823        NanoVis::MapFlows();
     1824    }
     1825    int i;
     1826    NanoVis::AdvectFlows();
     1827    for (i = 0; i < nSteps; i++) {
     1828        if (NanoVis::licRenderer->active()) {
     1829            NanoVis::licRenderer->convolve();
     1830        }
     1831        NanoVis::AdvectFlows();
     1832    }
     1833    NanoVis::EventuallyRedraw();
     1834    return TCL_OK;
     1835}
     1836
     1837/*
     1838 *---------------------------------------------------------------------------
     1839 *
     1840 * FlowNamesOp --
     1841 *
     1842 *---------------------------------------------------------------------------
     1843 */
     1844/*ARGSUSED*/
     1845static int
     1846FlowNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1847            Tcl_Obj *const *objv)
     1848{
     1849    Tcl_Obj *listObjPtr;
     1850    listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
     1851    FlowCmd *flowPtr;
     1852    FlowIterator iter;
     1853    for (flowPtr = NanoVis::FirstFlow(&iter); flowPtr != NULL;
     1854         flowPtr = NanoVis::NextFlow(&iter)) {
     1855        Tcl_Obj *objPtr;
     1856
     1857        objPtr = Tcl_NewStringObj(flowPtr->name(), -1);
     1858        Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
     1859    }
     1860    Tcl_SetObjResult(interp, listObjPtr);
     1861    return TCL_OK;
     1862}
     1863
     1864static int
     1865FlowNextOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1866             Tcl_Obj *const *objv)
     1867{
     1868    assert(NanoVis::licRenderer != NULL);
     1869    if (NanoVis::flags & NanoVis::MAP_FLOWS) {
     1870        NanoVis::MapFlows();
     1871    }
     1872    NanoVis::EventuallyRedraw();
     1873    NanoVis::licRenderer->convolve();
     1874    NanoVis::AdvectFlows();
     1875    return TCL_OK;
     1876}
     1877
     1878static int
     1879FlowResetOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1880             Tcl_Obj *const *objv)
     1881{
     1882    NanoVis::ResetFlows();
     1883    return TCL_OK;
     1884}
     1885
     1886#ifdef HAVE_FFMPEG
     1887
    13591888/*
    13601889 *---------------------------------------------------------------------------
     
    13991928    }
    14001929    return TCL_ERROR;
    1401 }
    1402 
    1403 static int
    1404 FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1405                 Tcl_Obj *const *objv)
    1406 {
    1407     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1408 
    1409     if (flowPtr->ParseSwitches(interp, objc - 2, objv + 2) != TCL_OK) {
    1410         return TCL_ERROR;
    1411     }
    1412     NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
    1413     return TCL_OK;
    1414 }
    1415 
    1416 static int
    1417 FlowParticlesAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1418                    Tcl_Obj *const *objv)
    1419 {
    1420     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1421 
    1422     if (flowPtr->CreateParticles(interp, objv[3]) != TCL_OK) {
    1423         return TCL_ERROR;
    1424     }
    1425     FlowParticles *particlesPtr;
    1426     if (flowPtr->GetParticles(interp, objv[3], &particlesPtr) != TCL_OK) {
    1427         return TCL_ERROR;
    1428     }
    1429     if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
    1430         delete particlesPtr;
    1431         return TCL_ERROR;
    1432     }
    1433     particlesPtr->Configure();
    1434     NanoVis::EventuallyRedraw();
    1435     Tcl_SetObjResult(interp, objv[3]);
    1436     return TCL_OK;
    1437 }
    1438 
    1439 static int
    1440 FlowParticlesConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1441                          Tcl_Obj *const *objv)
    1442 {
    1443     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1444 
    1445     FlowParticles *particlesPtr;
    1446     if (flowPtr->GetParticles(interp, objv[3], &particlesPtr) != TCL_OK) {
    1447         return TCL_ERROR;
    1448     }
    1449     if (particlesPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
    1450         return TCL_ERROR;
    1451     }
    1452     particlesPtr->Configure();
    1453     NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
    1454     return TCL_OK;
    1455 }
    1456 
    1457 static int
    1458 FlowParticlesDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1459                       Tcl_Obj *const *objv)
    1460 {
    1461     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1462     int i;
    1463     for (i = 3; i < objc; i++) {
    1464         FlowParticles *particlesPtr;
    1465 
    1466         if (flowPtr->GetParticles(NULL, objv[i], &particlesPtr) == TCL_OK) {
    1467             delete particlesPtr;
    1468         }
    1469     }
    1470     NanoVis::EventuallyRedraw();
    1471     return TCL_OK;
    1472 }
    1473 
    1474 static int
    1475 FlowParticlesNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1476                      Tcl_Obj *const *objv)
    1477 {
    1478     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1479     Tcl_Obj *listObjPtr;
    1480     listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    1481     FlowParticlesIterator iter;
    1482     FlowParticles *particlesPtr;
    1483     for (particlesPtr = flowPtr->FirstParticles(&iter); particlesPtr != NULL;
    1484          particlesPtr = flowPtr->NextParticles(&iter)) {
    1485         Tcl_Obj *objPtr;
    1486 
    1487         objPtr = Tcl_NewStringObj(particlesPtr->name(), -1);
    1488         Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
    1489     }
    1490     Tcl_SetObjResult(interp, listObjPtr);
    1491     return TCL_OK;
    1492 }
    1493 
    1494 /*
    1495  *---------------------------------------------------------------------------
    1496  *
    1497  * FlowParticlesObjCmd --
    1498  *
    1499  *      This procedure is invoked to process commands on behalf of the flow
    1500  *      object.
    1501  *
    1502  * Results:
    1503  *      A standard Tcl result.
    1504  *
    1505  * Side effects:
    1506  *      See the user documentation.
    1507  *
    1508  * $flow particles oper $name
    1509  *---------------------------------------------------------------------------
    1510  */
    1511 static Rappture::CmdSpec flowParticlesOps[] = {
    1512     {"add",        1, FlowParticlesAddOp,        4, 0, "name ?switches?",},
    1513     {"configure",  1, FlowParticlesConfigureOp,  4, 0, "name ?switches?",},
    1514     {"delete",     1, FlowParticlesDeleteOp,     4, 0, "?name...?"},
    1515     {"names",      1, FlowParticlesNamesOp,      3, 4, "?pattern?"},
    1516 };
    1517 
    1518 static int nFlowParticlesOps = NumCmdSpecs(flowParticlesOps);
    1519 
    1520 static int
    1521 FlowParticlesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1522                Tcl_Obj *const *objv)
    1523 {
    1524     Tcl_ObjCmdProc *proc;
    1525     proc = Rappture::GetOpFromObj(interp, nFlowParticlesOps, flowParticlesOps,
    1526         Rappture::CMDSPEC_ARG2, objc, objv, 0);
    1527     if (proc == NULL) {
    1528         return TCL_ERROR;
    1529     }
    1530     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1531     Tcl_Preserve(flowPtr);
    1532     int result;
    1533     result = (*proc) (clientData, interp, objc, objv);
    1534     Tcl_Release(flowPtr);
    1535     return result;
    1536 }
    1537 
    1538 static int
    1539 FlowBoxAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1540                Tcl_Obj *const *objv)
    1541 {
    1542     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1543 
    1544     if (flowPtr->CreateBox(interp, objv[3]) != TCL_OK) {
    1545         return TCL_ERROR;
    1546     }
    1547     FlowBox *boxPtr;
    1548     if (flowPtr->GetBox(interp, objv[3], &boxPtr) != TCL_OK) {
    1549         return TCL_ERROR;
    1550     }
    1551     if (boxPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
    1552         delete boxPtr;
    1553         return TCL_ERROR;
    1554     }
    1555     NanoVis::EventuallyRedraw();
    1556     Tcl_SetObjResult(interp, objv[3]);
    1557     return TCL_OK;
    1558 }
    1559 
    1560 static int
    1561 FlowBoxDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1562                    Tcl_Obj *const *objv)
    1563 {
    1564     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1565     int i;
    1566     for (i = 3; i < objc; i++) {
    1567         FlowBox *boxPtr;
    1568 
    1569         if (flowPtr->GetBox(NULL, objv[i], &boxPtr) == TCL_OK) {
    1570             delete boxPtr;
    1571         }
    1572     }
    1573     NanoVis::EventuallyRedraw();
    1574     return TCL_OK;
    1575 }
    1576 
    1577 static int
    1578 FlowBoxNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1579              Tcl_Obj *const *objv)
    1580 {
    1581     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1582     Tcl_Obj *listObjPtr;
    1583     listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    1584     FlowBoxIterator iter;
    1585     FlowBox *boxPtr;
    1586     for (boxPtr = flowPtr->FirstBox(&iter); boxPtr != NULL;
    1587          boxPtr = flowPtr->NextBox(&iter)) {
    1588         Tcl_Obj *objPtr;
    1589 
    1590         objPtr = Tcl_NewStringObj(boxPtr->name(), -1);
    1591         Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
    1592     }
    1593     Tcl_SetObjResult(interp, listObjPtr);
    1594     return TCL_OK;
    1595 }
    1596 
    1597 static int
    1598 FlowBoxConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1599                         Tcl_Obj *const *objv)
    1600 {
    1601     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1602 
    1603     FlowBox *boxPtr;
    1604     if (flowPtr->GetBox(interp, objv[3], &boxPtr) != TCL_OK) {
    1605         return TCL_ERROR;
    1606     }
    1607     if (boxPtr->ParseSwitches(interp, objc - 4, objv + 4) != TCL_OK) {
    1608         return TCL_ERROR;
    1609     }
    1610     NanoVis::EventuallyRedraw();
    1611     return TCL_OK;
    1612 }
    1613 
    1614 /*
    1615  *---------------------------------------------------------------------------
    1616  *
    1617  * FlowBoxOp--
    1618  *
    1619  *      This procedure is invoked to process commands on behalf of the flow
    1620  *      object.
    1621  *
    1622  * Results:
    1623  *      A standard Tcl result.
    1624  *
    1625  * Side effects:
    1626  *      See the user documentation.
    1627  *
    1628  *---------------------------------------------------------------------------
    1629  */
    1630 static Rappture::CmdSpec flowBoxOps[] = {
    1631     {"add",        1, FlowBoxAddOp,        4, 0, "name ?switches?",},
    1632     {"configure",  1, FlowBoxConfigureOp,  4, 0, "name ?switches?",},
    1633     {"delete",     1, FlowBoxDeleteOp,     3, 0, "?name...?"},
    1634     {"names",      1, FlowBoxNamesOp,      3, 0, "?pattern?"},
    1635 };
    1636 
    1637 static int nFlowBoxOps = NumCmdSpecs(flowBoxOps);
    1638 
    1639 static int
    1640 FlowBoxOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1641                Tcl_Obj *const *objv)
    1642 {
    1643     Tcl_ObjCmdProc *proc;
    1644     proc = Rappture::GetOpFromObj(interp, nFlowBoxOps, flowBoxOps,
    1645         Rappture::CMDSPEC_ARG2, objc, objv, 0);
    1646     if (proc == NULL) {
    1647         return TCL_ERROR;
    1648     }
    1649     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1650     Tcl_Preserve(flowPtr);
    1651     int result;
    1652     result = (*proc) (clientData, interp, objc, objv);
    1653     Tcl_Release(flowPtr);
    1654     return result;
    1655 }
    1656 
    1657 /*
    1658  * ----------------------------------------------------------------------
    1659  * CLIENT COMMAND:
    1660  *   $flow legend <width> <height>
    1661  *
    1662  * Clients use this to generate a legend image for the specified
    1663  * transfer function.  The legend image is a color gradient from 0
    1664  * to one, drawn in the given transfer function.  The resulting image
    1665  * is returned in the size <width> x <height>.
    1666  * ----------------------------------------------------------------------
    1667  */
    1668 static int
    1669 FlowLegendOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1670           Tcl_Obj *const *objv)
    1671 {
    1672     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1673    
    1674     const char *string = Tcl_GetString(objv[1]);
    1675     TransferFunction *tf;
    1676     tf = flowPtr->GetTransferFunction();
    1677     if (tf == NULL) {
    1678         Tcl_AppendResult(interp, "unknown transfer function \"", string, "\"",
    1679                              (char*)NULL);
    1680         return TCL_ERROR;
    1681     }
    1682     const char *label;
    1683     label = Tcl_GetString(objv[0]);
    1684     int w, h;
    1685     if ((Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK) ||
    1686         (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)) {
    1687         return TCL_ERROR;
    1688     }
    1689     if (NanoVis::flags & NanoVis::MAP_FLOWS) {
    1690         NanoVis::MapFlows();
    1691     }
    1692     NanoVis::render_legend(tf, NanoVis::magMin, NanoVis::magMax, w, h, label);
    1693     return TCL_OK;
    1694 }
    1695 
    1696 /*
    1697  *---------------------------------------------------------------------------
    1698  *
    1699  * FlowInstObjCmd --
    1700  *
    1701  *      This procedure is invoked to process commands on behalf of the flow
    1702  *      object.
    1703  *
    1704  * Results:
    1705  *      A standard Tcl result.
    1706  *
    1707  * Side effects:
    1708  *      See the user documentation.
    1709  *
    1710  *---------------------------------------------------------------------------
    1711  */
    1712 static Rappture::CmdSpec flowInstOps[] = {
    1713     {"box",         1, FlowBoxOp,        2, 0, "oper ?args?"},
    1714     {"configure",   1, FlowConfigureOp,  2, 0, "?switches?"},
    1715     {"data",        1, FlowDataOp,       2, 0, "oper ?args?"},
    1716     {"legend",      1, FlowLegendOp,     4, 4, "w h"},
    1717     {"particles",   1, FlowParticlesOp,  2, 0, "oper ?args?"}
    1718 };
    1719 static int nFlowInstOps = NumCmdSpecs(flowInstOps);
    1720 
    1721 static int
    1722 FlowInstObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    1723                Tcl_Obj *const *objv)
    1724 {
    1725     Tcl_ObjCmdProc *proc;
    1726     proc = Rappture::GetOpFromObj(interp, nFlowInstOps, flowInstOps,
    1727         Rappture::CMDSPEC_ARG1, objc, objv, 0);
    1728     if (proc == NULL) {
    1729         return TCL_ERROR;
    1730     }
    1731     assert(CheckGL(AT));
    1732     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1733     Tcl_Preserve(flowPtr);
    1734     int result;
    1735     result = (*proc) (clientData, interp, objc, objv);
    1736     Tcl_Release(flowPtr);
    1737     return result;
    1738 }
    1739 
    1740 /*
    1741  *---------------------------------------------------------------------------
    1742  *
    1743  * FlowInstDeleteProc --
    1744  *
    1745  *      Deletes the command associated with the tree.  This is called only
    1746  *      when the command associated with the tree is destroyed.
    1747  *
    1748  * Results:
    1749  *      None.
    1750  *
    1751  *---------------------------------------------------------------------------
    1752  */
    1753 static void
    1754 FlowInstDeleteProc(ClientData clientData)
    1755 {
    1756     FlowCmd *flowPtr = (FlowCmd *)clientData;
    1757     delete flowPtr;
    1758 }
    1759 
    1760 /*
    1761  *---------------------------------------------------------------------------
    1762  *
    1763  * FlowAddOp --
    1764  *
    1765  *---------------------------------------------------------------------------
    1766  */
    1767 /*ARGSUSED*/
    1768 static int
    1769 FlowAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1770           Tcl_Obj *const *objv)
    1771 {
    1772     if (NanoVis::CreateFlow(interp, objv[2]) != TCL_OK) {
    1773         return TCL_ERROR;
    1774     }
    1775     FlowCmd *flowPtr;
    1776     if (NanoVis::GetFlow(interp, objv[2], &flowPtr) != TCL_OK) {
    1777         return TCL_ERROR;
    1778     }
    1779     if (flowPtr->ParseSwitches(interp, objc - 3, objv + 3) != TCL_OK) {
    1780         Tcl_DeleteCommand(interp, flowPtr->name());
    1781         return TCL_ERROR;
    1782     }
    1783     Tcl_SetObjResult(interp, objv[2]);
    1784     NanoVis::EventuallyRedraw();
    1785     return TCL_OK;
    1786 }
    1787 
    1788 /*
    1789  *---------------------------------------------------------------------------
    1790  *
    1791  * FlowDeleteOp --
    1792  *
    1793  *---------------------------------------------------------------------------
    1794  */
    1795 /*ARGSUSED*/
    1796 static int
    1797 FlowDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1798              Tcl_Obj *const *objv)
    1799 {
    1800     int i;
    1801 
    1802     for (i = 2; i < objc; i++) {
    1803         FlowCmd *flowPtr;
    1804 
    1805         if (NanoVis::GetFlow(interp, objv[i], &flowPtr) != TCL_OK) {
    1806             return TCL_ERROR;
    1807         }
    1808         Tcl_DeleteCommand(interp, flowPtr->name());
    1809     }
    1810     NanoVis::EventuallyRedraw(NanoVis::MAP_FLOWS);
    1811     return TCL_OK;
    1812 }
    1813 
    1814 /*
    1815  *---------------------------------------------------------------------------
    1816  *
    1817  * FlowExistsOp --
    1818  *
    1819  *---------------------------------------------------------------------------
    1820  */
    1821 /*ARGSUSED*/
    1822 static int
    1823 FlowExistsOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1824              Tcl_Obj *const *objv)
    1825 {
    1826     bool value;
    1827     FlowCmd *flowPtr;
    1828 
    1829     value = false;
    1830     if (NanoVis::GetFlow(NULL, objv[2], &flowPtr) == TCL_OK) {
    1831         value = true;
    1832     }
    1833     Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (int)value);
    1834     return TCL_OK;
    1835 }
    1836 
    1837 /*
    1838  *---------------------------------------------------------------------------
    1839  *
    1840  * FlowGotoOp --
    1841  *
    1842  *      flow goto number
    1843  *
    1844  *---------------------------------------------------------------------------
    1845  */
    1846 static int
    1847 FlowGotoOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1848              Tcl_Obj *const *objv)
    1849 {
    1850     int nSteps;
    1851     if (Tcl_GetIntFromObj(interp, objv[2], &nSteps) != TCL_OK) {
    1852         return TCL_ERROR;
    1853     }
    1854     if ((nSteps < 0) || (nSteps > SHRT_MAX)) {
    1855         Tcl_AppendResult(interp, "flow goto: bad # of steps \"",
    1856                          Tcl_GetString(objv[2]), "\"", (char *)NULL);
    1857         return TCL_ERROR;
    1858     }
    1859     NanoVis::ResetFlows();
    1860     if (NanoVis::flags & NanoVis::MAP_FLOWS) {
    1861         NanoVis::MapFlows();
    1862     }
    1863     int i;
    1864     NanoVis::AdvectFlows();
    1865     for (i = 0; i < nSteps; i++) {
    1866         if (NanoVis::licRenderer->active()) {
    1867             NanoVis::licRenderer->convolve();
    1868         }
    1869         NanoVis::AdvectFlows();
    1870     }
    1871     NanoVis::EventuallyRedraw();
    1872     return TCL_OK;
    1873 }
    1874 
    1875 /*
    1876  *---------------------------------------------------------------------------
    1877  *
    1878  * FlowNamesOp --
    1879  *
    1880  *---------------------------------------------------------------------------
    1881  */
    1882 /*ARGSUSED*/
    1883 static int
    1884 FlowNamesOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1885             Tcl_Obj *const *objv)
    1886 {
    1887     Tcl_Obj *listObjPtr;
    1888     listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
    1889     FlowCmd *flowPtr;
    1890     FlowIterator iter;
    1891     for (flowPtr = NanoVis::FirstFlow(&iter); flowPtr != NULL;
    1892          flowPtr = NanoVis::NextFlow(&iter)) {
    1893         Tcl_Obj *objPtr;
    1894 
    1895         objPtr = Tcl_NewStringObj(flowPtr->name(), -1);
    1896         Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
    1897     }
    1898     Tcl_SetObjResult(interp, listObjPtr);
    1899     return TCL_OK;
    1900 }
    1901 
    1902 static int
    1903 FlowNextOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1904              Tcl_Obj *const *objv)
    1905 {
    1906     assert(NanoVis::licRenderer != NULL);
    1907     if (NanoVis::flags & NanoVis::MAP_FLOWS) {
    1908         NanoVis::MapFlows();
    1909     }
    1910     NanoVis::EventuallyRedraw();
    1911     NanoVis::licRenderer->convolve();
    1912     NanoVis::AdvectFlows();
    1913     return TCL_OK;
    1914 }
    1915 
    1916 static int
    1917 FlowResetOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1918              Tcl_Obj *const *objv)
    1919 {
    1920     NanoVis::ResetFlows();
    1921     return TCL_OK;
    19221930}
    19231931
     
    20702078    return TCL_OK;
    20712079}
    2072 
     2080#else
     2081static int
     2082FlowVideoOp(ClientData clientData, Tcl_Interp *interp, int objc,
     2083            Tcl_Obj *const *objv)
     2084{
     2085    return TCL_OK;                      /* Not implemented */
     2086}
     2087#endif  /* HAVE_FFMPEG */
    20732088
    20742089/*
Note: See TracChangeset for help on using the changeset viewer.