Ignore:
Timestamp:
Jun 17, 2013 1:48:27 AM (11 years ago)
Author:
ldelgass
Message:

Use imroved Arc API (arc can only represent a circular section, and setting
two endpoints could cause problems with endpts and center colinear and radii
from center to two endpoints differing). New API uses a center, start point,
normal and sweep angle. Also change Line to support polylines: protocol is
changed to require a Tcl list for point coordinates instead of a fixed 2
endpoints.

Location:
trunk/packages/vizservers/vtkvis
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/Arc.cpp

    r3616 r3696  
    2828{
    2929    if (_arc == NULL) {
    30         _arc = vtkSmartPointer<vtkArcSource>::New();
     30        _arc = vtkSmartPointer<vtkArcSource>::New();
     31        _arc->SetResolution(4);
     32        _arc->UseNormalAndAngleOn();
    3133    }
    3234
  • trunk/packages/vizservers/vtkvis/Arc.h

    r3621 r3696  
    4242    }
    4343
    44     void setEndPoints(double pt1[3], double pt2[3])
     44    void setStartPoint(double pt[3])
    4545    {
    4646        if (_arc != NULL) {
    47             _arc->SetPoint1(pt1);
    48             _arc->SetPoint2(pt2);
     47            double polarVec[3];
     48            for (int i = 0; i < 3; i++) {
     49                polarVec[i] = pt[i] - _arc->GetCenter()[i];
     50            }
     51            setPolarVector(polarVec);
     52        }
     53    }
     54
     55    void setNormal(double norm[3])
     56    {
     57        if (_arc != NULL) {
     58            _arc->SetNormal(norm);
    4959        }
     60    }
     61
     62    void setPolarVector(double vec[3])
     63    {
     64        if (_arc != NULL) {
     65            _arc->SetPolarVector(vec);
     66        }
     67    }
     68
     69    void setAngle(double angle)
     70    {
     71        if (_arc != NULL) {
     72            _arc->SetAngle(angle);
     73        }
    5074    }
    5175
  • trunk/packages/vizservers/vtkvis/Glyphs.cpp

    r3695 r3696  
    2020#include <vtkArrowSource.h>
    2121#include <vtkConeSource.h>
     22#include <vtkCubeSource.h>
    2223#include <vtkCylinderSource.h>
    2324#include <vtkPlatonicSolidSource.h>
     
    110111    switch (_glyphShape) {
    111112    case LINE:
     113        // Length of 1, centered at origin
    112114        _glyphSource = vtkSmartPointer<vtkLineSource>::New();
    113115        break;
    114116    case ARROW: {
     117        // Height of 1, Tip radius .1, tip length .35, shaft radius .03
    115118        _glyphSource = vtkSmartPointer<vtkArrowSource>::New();
    116119        vtkSmartPointer<vtkArrowSource> arrow = vtkArrowSource::SafeDownCast(_glyphSource);
     
    121124        break;
    122125    case CONE: {
     126        // base length of 1, height 1, centered at origin
    123127        _glyphSource = vtkSmartPointer<vtkConeSource>::New();
    124128        vtkSmartPointer<vtkConeSource> cone = vtkConeSource::SafeDownCast(_glyphSource);
     
    128132        break;
    129133    case CUBE:
    130         _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    131         vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToCube();
     134        // Sides of length 1
     135        _glyphSource = vtkSmartPointer<vtkCubeSource>::New();
    132136        break;
    133137    case CYLINDER: {
     138        // base length of 1, height 1, centered at origin
    134139        vtkSmartPointer<vtkCylinderSource> csource = vtkSmartPointer<vtkCylinderSource>::New();
    135140        csource->SetResolution(8);
     
    142147        break;
    143148    case DODECAHEDRON:
     149        // Radius of 1
    144150        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    145151        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToDodecahedron();
     
    148154        break;
    149155    case ICOSAHEDRON:
     156        // Radius of 1
    150157        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    151158        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToIcosahedron();
     
    154161        break;
    155162    case OCTAHEDRON:
     163        // Radius of 1
    156164        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
    157165        vtkPlatonicSolidSource::SafeDownCast(_glyphSource)->SetSolidTypeToOctahedron();
     
    167175        break;
    168176    case SPHERE: {
     177        // Default radius 0.5
    169178        _glyphSource = vtkSmartPointer<vtkSphereSource>::New();
    170179        vtkSmartPointer<vtkSphereSource> sphere = vtkSphereSource::SafeDownCast(_glyphSource);
     
    174183        break;
    175184    case TETRAHEDRON:
     185        // Radius of 1
    176186        // FIXME: need to rotate inital orientation
    177187        _glyphSource = vtkSmartPointer<vtkPlatonicSolidSource>::New();
     
    205215void Glyphs::setQuality(double quality)
    206216{
     217    if (quality > 10.0)
     218        quality = 10.0;
     219
    207220    switch (_glyphShape) {
    208221    case ARROW: {
  • trunk/packages/vizservers/vtkvis/Line.h

    r3621 r3696  
    99#define VTKVIS_LINE_H
    1010
     11#include <vector>
     12
    1113#include <vtkSmartPointer.h>
    1214#include <vtkPolyDataMapper.h>
    1315#include <vtkActor.h>
    1416#include <vtkLineSource.h>
     17#include <vtkPoints.h>
    1518
    1619#include "Shape.h"
     
    2225 * \brief VTK PolyData Line
    2326 *
    24  * This class creates a line
     27 * This class creates a polyline
    2528 */
    2629class Line : public Shape
     
    3538    }
    3639
     40    /**
     41     * \brief This interface creates a single line
     42     */
    3743    void setEndPoints(double pt1[3], double pt2[3])
    3844    {
    3945        if (_line != NULL) {
    4046            _line->SetPoint1(pt1);
    41             _line->SetPoint2(pt2);
    42         }
     47            _line->SetPoint2(pt2);
     48            _line->SetPoints(NULL);
     49        }
     50    }
     51
     52    /**
     53     * \brief This interface creates a polyline
     54     */
     55    void setPoints(std::vector<double> pts)
     56    {
     57        if (_line == NULL)
     58            return;
     59        vtkPoints *points = vtkPoints::New();
     60        for (size_t i = 0; i < pts.size(); i+=3) {
     61            points->InsertNextPoint(pts[i], pts[i+1], pts[i+2]);
     62        }
     63        _line->SetPoints(points);
    4364    }
    4465
  • trunk/packages/vizservers/vtkvis/Renderer.h

    r3695 r3696  
    577577    // Arcs
    578578
    579     bool addArc(const DataSetId& id, double center[3], double pt1[3], double pt2[3]);
     579    bool addArc(const DataSetId& id, double center[3], double pt1[3],
     580                double normal[3], double angle);
    580581
    581582    void setArcResolution(const DataSetId& id, int res);
     
    583584    // Arrows
    584585
    585     bool addArrow(const DataSetId& id, double tipRadius, double shaftRadius, double tipLength, bool flipNormals = false);
     586    bool addArrow(const DataSetId& id, double tipRadius, double shaftRadius,
     587                  double tipLength, bool flipNormals = false);
    586588
    587589    void setArrowResolution(const DataSetId& id, int resTip, int resShaft);
     
    589591    // Boxes
    590592
    591     bool addBox(const DataSetId& id, double xLen, double yLen, double zLen, bool flipNormals = false);
     593    bool addBox(const DataSetId& id, double xLen, double yLen, double zLen,
     594                bool flipNormals = false);
    592595
    593596    // Cones
    594597
    595     bool addCone(const DataSetId& id, double radius, double height, bool cap, bool flipNormals = false);
     598    bool addCone(const DataSetId& id, double radius, double height, bool cap,
     599                 bool flipNormals = false);
    596600
    597601    void setConeResolution(const DataSetId& id, int res);
     
    741745
    742746    bool addLine(const DataSetId& id, double pt1[3], double pt2[3]);
     747
     748    bool addLine(const DataSetId& id, std::vector<double> points);
    743749
    744750    // Molecules
  • trunk/packages/vizservers/vtkvis/RendererCmd.cpp

    r3695 r3696  
    1313#include <string>
    1414#include <sstream>
     15#include <vector>
    1516#include <unistd.h>
    1617#include <sys/select.h>
     
    131132         Tcl_Obj *const *objv)
    132133{
    133     double center[3], pt1[3], pt2[3];
     134    double center[3], pt1[3], norm[3], angle;
    134135    if (Tcl_GetDoubleFromObj(interp, objv[2], &center[0]) != TCL_OK ||
    135136        Tcl_GetDoubleFromObj(interp, objv[3], &center[1]) != TCL_OK ||
     
    138139        Tcl_GetDoubleFromObj(interp, objv[6], &pt1[1]) != TCL_OK ||
    139140        Tcl_GetDoubleFromObj(interp, objv[7], &pt1[2]) != TCL_OK ||
    140         Tcl_GetDoubleFromObj(interp, objv[8], &pt2[0]) != TCL_OK ||
    141         Tcl_GetDoubleFromObj(interp, objv[9], &pt2[1]) != TCL_OK ||
    142         Tcl_GetDoubleFromObj(interp, objv[10], &pt2[2]) != TCL_OK) {
    143         return TCL_ERROR;
    144     }
    145     const char *name = Tcl_GetString(objv[11]);
    146     if (!g_renderer->addArc(name, center, pt1, pt2)) {
     141        Tcl_GetDoubleFromObj(interp, objv[8], &norm[0]) != TCL_OK ||
     142        Tcl_GetDoubleFromObj(interp, objv[9], &norm[1]) != TCL_OK ||
     143        Tcl_GetDoubleFromObj(interp, objv[10], &norm[2]) != TCL_OK ||
     144        Tcl_GetDoubleFromObj(interp, objv[11], &angle) != TCL_OK) {
     145        return TCL_ERROR;
     146    }
     147    const char *name = Tcl_GetString(objv[12]);
     148    if (!g_renderer->addArc(name, center, pt1, norm, angle)) {
    147149        Tcl_AppendResult(interp, "Failed to create arc", (char*)NULL);
    148150        return TCL_ERROR;
     
    329331
    330332static Rappture::CmdSpec arcOps[] = {
    331     {"add",       1, ArcAddOp, 12, 12, "centerX centerY centerZ x1 y1 z1 x2 y2 z2 name"},
     333    {"add",       1, ArcAddOp, 13, 13, "centerX centerY centerZ startX startY startZ normX normY normZ angle name"},
    332334    {"color",     1, ArcColorOp, 5, 6, "r g b ?name?"},
    333335    {"delete",    1, ArcDeleteOp, 2, 3, "?name?"},
     
    721723    {"orient",    4, ArrowOrientOp, 6, 7, "qw qx qy qz ?name?"},
    722724    {"origin",    4, ArrowOriginOp, 5, 6, "x y z ?name?"},
    723     {"pos",       2, ArrowPositionOp, 5, 6, "x y z ?name?"},
     725    {"pos",       1, ArrowPositionOp, 5, 6, "x y z ?name?"},
    724726    {"resolution",1, ArrowResolutionOp, 4, 5, "tipRes shaftRes ?name?"},
    725727    {"scale",     2, ArrowScaleOp, 5, 6, "sx sy sz ?name?"},
     
    70757077          Tcl_Obj *const *objv)
    70767078{
    7077     double pt1[3];
    7078     double pt2[3];
    7079     if (Tcl_GetDoubleFromObj(interp, objv[2], &pt1[0]) != TCL_OK ||
    7080         Tcl_GetDoubleFromObj(interp, objv[3], &pt1[1]) != TCL_OK ||
    7081         Tcl_GetDoubleFromObj(interp, objv[4], &pt1[2]) != TCL_OK ||
    7082         Tcl_GetDoubleFromObj(interp, objv[5], &pt2[0]) != TCL_OK ||
    7083         Tcl_GetDoubleFromObj(interp, objv[6], &pt2[1]) != TCL_OK ||
    7084         Tcl_GetDoubleFromObj(interp, objv[7], &pt2[2]) != TCL_OK) {
    7085         return TCL_ERROR;
    7086     }
    7087     const char *name = Tcl_GetString(objv[8]);
    7088     if (!g_renderer->addLine(name, pt1, pt2)) {
     7079    std::vector<double> points;
     7080    int ptlistc;
     7081    Tcl_Obj **ptlistv;
     7082    if (Tcl_ListObjGetElements(interp, objv[2], &ptlistc, &ptlistv) != TCL_OK) {
     7083        return TCL_ERROR;
     7084    }
     7085    if (ptlistc < 6 || ptlistc % 3 != 0) {
     7086        Tcl_AppendResult(interp, "Points list size must be 6 or more and a multiple of 3", (char*)NULL);
     7087        return TCL_ERROR;
     7088    }
     7089    for (int i = 0; i < ptlistc; i++) {
     7090        double val;
     7091        if (Tcl_GetDoubleFromObj(interp, ptlistv[i], &val) != TCL_OK) {
     7092            return TCL_ERROR;
     7093        }
     7094        points.push_back(val);
     7095    }
     7096    const char *name = Tcl_GetString(objv[3]);
     7097    if (!g_renderer->addLine(name, points)) {
    70897098        Tcl_AppendResult(interp, "Failed to create line", (char*)NULL);
    70907099        return TCL_ERROR;
     
    72547263
    72557264static Rappture::CmdSpec lineOps[] = {
    7256     {"add",       1, LineAddOp, 9, 9, "x1 y1 z1 x2 y2 z2 name"},
     7265    {"add",       1, LineAddOp, 4, 4, "points name"},
    72577266    {"color",     1, LineColorOp, 5, 6, "r g b ?name?"},
    72587267    {"delete",    1, LineDeleteOp, 2, 3, "?name?"},
  • trunk/packages/vizservers/vtkvis/RendererGraphicsObjs.cpp

    r3695 r3696  
    88#include <cstring>
    99#include <typeinfo>
     10#include <vector>
    1011
    1112#include <vtkVersion.h>
     
    394395 * \brief Create a new Arc and associate it with an ID
    395396 */
    396 bool Renderer::addArc(const DataSetId& id, double center[3],
    397                       double pt1[3], double pt2[3])
     397bool Renderer::addArc(const DataSetId& id,
     398                      double center[3],
     399                      double pt1[3],
     400                      double normal[3],
     401                      double angle)
    398402{
    399403    Arc *gobj;
     
    419423
    420424    gobj->setCenter(center);
    421     gobj->setEndPoints(pt1, pt2);
     425    gobj->setStartPoint(pt1);
     426    gobj->setNormal(normal);
     427    gobj->setAngle(angle);
    422428
    423429    getGraphicsObjectHashmap<Arc>()[id] = gobj;
     
    22992305
    23002306/**
     2307 * \brief Create a new Line and associate it with an ID
     2308 */
     2309bool Renderer::addLine(const DataSetId& id, std::vector<double> points)
     2310{
     2311    Line *gobj;
     2312    if ((gobj = getGraphicsObject<Line>(id)) != NULL) {
     2313        WARN("Replacing existing %s %s", gobj->getClassName(), id.c_str());
     2314        deleteGraphicsObject<Line>(id);
     2315    }
     2316
     2317    gobj = new Line();
     2318 
     2319    gobj->setDataSet(NULL, this);
     2320
     2321    if (gobj->getProp() == NULL &&
     2322        gobj->getOverlayProp() == NULL) {
     2323        delete gobj;
     2324        return false;
     2325    } else {
     2326        if (gobj->getProp())
     2327            _renderer->AddViewProp(gobj->getProp());
     2328        if (gobj->getOverlayProp())
     2329            _renderer->AddViewProp(gobj->getOverlayProp());
     2330    }
     2331
     2332    gobj->setPoints(points);
     2333
     2334    getGraphicsObjectHashmap<Line>()[id] = gobj;
     2335
     2336    sceneBoundsChanged();
     2337    _needsRedraw = true;
     2338    return true;
     2339}
     2340
     2341/**
    23012342 * \brief Set atom sphere resolution
    23022343 */
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r3693 r3696  
    258258== Graphics objects ==
    259259
    260 arc add <centerX> <centerY> <centerZ> <pt1X> <pt1Y> <pt1Z> <pt2X> <pt2Y> <pt2Z> <name>
     260arc add <centerX> <centerY> <centerZ> <startX> <startY> <startZ> <normX> <normY> <normZ> <angle> <name>
     261    Creates a circular arc given a center and starting point, a normal and a
     262    sweep angle.
    261263arc color <r> <g> <b> <?name?>
    262264arc delete <?name?>
     
    492494glyphs pos <x> <y> <z> <?dataSetName?>
    493495glyphs ptsize <size> <?dataSetName?>
     496glyphs quality <val> <?dataSetName?>
     497       Set glyph shape resolution quality val=[0,10], 1 is default
    494498glyphs scale <sx> <sy> <sz> <?dataSetName?>
    495499glyphs shape <arrow|cone|cube|cylinder|dodecahedron|icosahedron|line|octahedron|point|sphere|tetrahedron> <?datasetName?>
     
    577581lic visible <bool> <?datasetName?>
    578582
    579 line add <pt1X> <pt1Y> <pt1Z> <pt2X> <pt2Y> <pt2Z> <name>
     583line add <points> <name>
     584     Create a polyline from the list of point coordinates in <points>. The
     585     list size must be a multiple of 3 (each point's x,y,z coordinates)
    580586line color <r> <g> <b> <?name?>
    581587line delete <?name?>
Note: See TracChangeset for help on using the changeset viewer.