Changeset 2114 for trunk


Ignore:
Timestamp:
Mar 1, 2011 1:54:57 PM (13 years ago)
Author:
ldelgass
Message:

Add lighting toggle for graphics objects. Make camera pan/zoom commands work for image camera type (as alternative to setting rectangle), make camera rotate a no-op for image camera type.

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

Legend:

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

    r2112 r2114  
    199199    }
    200200}
     201
     202/**
     203 * \brief Turn on/off lighting of this object
     204 */
     205void Contour2D::setLighting(bool state)
     206{
     207    if (_contourActor != NULL)
     208        _contourActor->GetProperty()->SetLighting((state ? 1 : 0));
     209}
  • trunk/packages/vizservers/vtkvis/RpContour2D.h

    r2112 r2114  
    4949    void setClippingPlanes(vtkPlaneCollection *planes);
    5050
     51    void setLighting(bool state);
     52
    5153private:
    5254    void initActor();
  • trunk/packages/vizservers/vtkvis/RpPolyData.cpp

    r2112 r2114  
    1919PolyData::PolyData() :
    2020    _edgeWidth(1.0),
    21     _opacity(1.0)
     21    _opacity(1.0),
     22    _lighting(true)
    2223{
    2324    _color[0] = 0.0;
     
    5354        _pdActor->GetProperty()->SetLineWidth(_edgeWidth);
    5455        _pdActor->GetProperty()->SetOpacity(_opacity);
     56        if (!_lighting)
     57            _pdActor->GetProperty()->LightingOff();
    5558    }
    5659}
     
    141144        } else {
    142145            _pdActor->GetProperty()->SetRepresentationToSurface();
    143             _pdActor->GetProperty()->LightingOn();
     146            _pdActor->GetProperty()->SetLighting((_lighting ? 1 : 0));
    144147        }
    145148    }
     
    204207    }
    205208}
     209
     210/**
     211 * \brief Turn on/off lighting of this object
     212 */
     213void PolyData::setLighting(bool state)
     214{
     215    _lighting = state;
     216    if (_pdActor != NULL)
     217        _pdActor->GetProperty()->SetLighting((state ? 1 : 0));
     218}
  • trunk/packages/vizservers/vtkvis/RpPolyData.h

    r2112 r2114  
    5050    void setClippingPlanes(vtkPlaneCollection *planes);
    5151
     52    void setLighting(bool state);
     53
    5254private:
    5355    void initActor();
     
    6062    float _edgeWidth;
    6163    double _opacity;
     64    bool _lighting;
    6265    vtkSmartPointer<vtkPolyDataMapper> _pdMapper;
    6366    vtkSmartPointer<vtkActor> _pdActor;
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.cpp

    r2112 r2114  
    236236    }
    237237}
     238
     239/**
     240 * \brief Turn on/off lighting of this object
     241 */
     242void PseudoColor::setLighting(bool state)
     243{
     244    if (_dsActor != NULL)
     245        _dsActor->GetProperty()->SetLighting((state ? 1 : 0));
     246}
  • trunk/packages/vizservers/vtkvis/RpPseudoColor.h

    r2112 r2114  
    5252    void setClippingPlanes(vtkPlaneCollection *planes);
    5353
     54    void setLighting(bool state);
     55
    5456private:
    5557    void initActor();
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2113 r2114  
    368368
    369369/**
    370  * \brief Create a new PseudoColor rendering for the specified DataSet
    371  */
    372 void Renderer::addPseudoColor(DataSetId id)
    373 {
    374     DataSet *ds = getDataSet(id);
    375     if (ds == NULL)
    376         return;
    377 
    378     if (getPseudoColor(id)) {
    379         WARN("Replacing existing pseudocolor %s", id.c_str());
    380         deletePseudoColor(id);
    381     }
    382     PseudoColor *pc = new PseudoColor();
    383     _pseudoColors[id] = pc;
    384 
    385     pc->setDataSet(ds);
    386 
    387     _renderer->AddActor(pc->getActor());
    388 
    389     initCamera();
    390     _needsRedraw = true;
    391 }
    392 
    393 /**
    394  * \brief Get the PseudoColor associated with the specified DataSet
    395  */
    396 PseudoColor *Renderer::getPseudoColor(DataSetId id)
    397 {
    398     PseudoColorHashmap::iterator itr = _pseudoColors.find(id);
    399 
    400     if (itr == _pseudoColors.end()) {
    401         TRACE("PseudoColor not found: %s", id.c_str());
    402         return NULL;
    403     } else
    404         return itr->second;
    405 }
    406 
    407 /**
    408370 * \brief Turn on/off rendering of all axes gridlines
    409371 */
     
    630592
    631593/**
     594 * \brief Create a new PseudoColor rendering for the specified DataSet
     595 */
     596void Renderer::addPseudoColor(DataSetId id)
     597{
     598    DataSet *ds = getDataSet(id);
     599    if (ds == NULL)
     600        return;
     601
     602    if (getPseudoColor(id)) {
     603        WARN("Replacing existing pseudocolor %s", id.c_str());
     604        deletePseudoColor(id);
     605    }
     606    PseudoColor *pc = new PseudoColor();
     607    _pseudoColors[id] = pc;
     608
     609    pc->setDataSet(ds);
     610
     611    _renderer->AddActor(pc->getActor());
     612
     613    initCamera();
     614    _needsRedraw = true;
     615}
     616
     617/**
     618 * \brief Get the PseudoColor associated with the specified DataSet
     619 */
     620PseudoColor *Renderer::getPseudoColor(DataSetId id)
     621{
     622    PseudoColorHashmap::iterator itr = _pseudoColors.find(id);
     623
     624    if (itr == _pseudoColors.end()) {
     625        TRACE("PseudoColor not found: %s", id.c_str());
     626        return NULL;
     627    } else
     628        return itr->second;
     629}
     630
     631/**
    632632 * \brief Associate an existing named color map with a DataSet
    633633 */
     
    716716
    717717/**
     718 * \brief Turn mesh lighting on/off for the specified DataSet
     719 */
     720void Renderer::setPseudoColorLighting(DataSetId id, bool state)
     721{
     722    PseudoColor *pc = getPseudoColor(id);
     723    if (pc) {
     724        pc->setLighting(state);
     725        _needsRedraw = true;
     726    }
     727}
     728
     729/**
    718730 * \brief Create a new Contour2D and associate it with the named DataSet
    719731 */
     
    791803
    792804/**
     805 * \brief Set the RGB isoline color for the specified DataSet
     806 */
     807void Renderer::setContourEdgeColor(DataSetId id, float color[3])
     808{
     809    Contour2D *contour = getContour2D(id);
     810    if (contour) {
     811        contour->setEdgeColor(color);
     812        _needsRedraw = true;
     813    }
     814}
     815
     816/**
     817 * \brief Set the isoline width for the specified DataSet (may be a no-op)
     818 *
     819 * If the OpenGL implementation/hardware does not support wide lines,
     820 * this function may not have an effect.
     821 */
     822void Renderer::setContourEdgeWidth(DataSetId id, float edgeWidth)
     823{
     824    Contour2D *contour = getContour2D(id);
     825    if (contour) {
     826        contour->setEdgeWidth(edgeWidth);
     827        _needsRedraw = true;
     828    }
     829}
     830
     831/**
     832 * \brief Turn contour lighting on/off for the specified DataSet
     833 */
     834void Renderer::setContourLighting(DataSetId id, bool state)
     835{
     836    Contour2D *contour = getContour2D(id);
     837    if (contour) {
     838        contour->setLighting(state);
     839        _needsRedraw = true;
     840    }
     841}
     842
     843/**
    793844 * \brief Create a new PolyData and associate it with the named DataSet
    794845 */
     
    839890    if (polyData) {
    840891        polyData->setVisibility(state);
     892        _needsRedraw = true;
     893    }
     894}
     895
     896/**
     897 * \brief Set the RGB polygon face color for the specified DataSet
     898 */
     899void Renderer::setPolyDataColor(DataSetId id, float color[3])
     900{
     901    PolyData *polyData = getPolyData(id);
     902    if (polyData) {
     903        polyData->setColor(color);
     904        _needsRedraw = true;
     905    }
     906}
     907
     908/**
     909 * \brief Set the visibility of polygon edges for the specified DataSet
     910 */
     911void Renderer::setPolyDataEdgeVisibility(DataSetId id, bool state)
     912{
     913    PolyData *polyData = getPolyData(id);
     914    if (polyData) {
     915        polyData->setEdgeVisibility(state);
     916        _needsRedraw = true;
     917    }
     918}
     919
     920/**
     921 * \brief Set the RGB polygon edge color for the specified DataSet
     922 */
     923void Renderer::setPolyDataEdgeColor(DataSetId id, float color[3])
     924{
     925    PolyData *polyData = getPolyData(id);
     926    if (polyData) {
     927        polyData->setEdgeColor(color);
     928        _needsRedraw = true;
     929    }
     930}
     931
     932/**
     933 * \brief Set the polygon edge width for the specified DataSet (may be a no-op)
     934 *
     935 * If the OpenGL implementation/hardware does not support wide lines,
     936 * this function may not have an effect.
     937 */
     938void Renderer::setPolyDataEdgeWidth(DataSetId id, float edgeWidth)
     939{
     940    PolyData *polyData = getPolyData(id);
     941    if (polyData) {
     942        polyData->setEdgeWidth(edgeWidth);
     943        _needsRedraw = true;
     944    }
     945}
     946
     947/**
     948 * \brief Set wireframe rendering for the specified DataSet
     949 */
     950void Renderer::setPolyDataWireframe(DataSetId id, bool state)
     951{
     952    PolyData *polyData = getPolyData(id);
     953    if (polyData) {
     954        polyData->setWireframe(state);
     955        _needsRedraw = true;
     956    }
     957}
     958
     959/**
     960 * \brief Turn mesh lighting on/off for the specified DataSet
     961 */
     962void Renderer::setPolyDataLighting(DataSetId id, bool state)
     963{
     964    PolyData *polyData = getPolyData(id);
     965    if (polyData) {
     966        polyData->setLighting(state);
    841967        _needsRedraw = true;
    842968    }
     
    9561082void Renderer::rotateCamera(double yaw, double pitch, double roll)
    9571083{
     1084    if (_cameraMode == IMAGE)
     1085        return;
    9581086    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
    9591087    camera->Azimuth(yaw); // Rotate about object
     
    9751103void Renderer::panCamera(double x, double y)
    9761104{
     1105    if (_cameraMode == IMAGE) {
     1106        _imgWorldOrigin[0] += x;
     1107        _imgWorldOrigin[1] += y;
     1108        setCameraZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1],
     1109                            _imgWorldDims[0], _imgWorldDims[1]);
     1110        _needsRedraw = true;
     1111        return;
     1112    }
    9771113    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
    9781114    vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     
    9911127void Renderer::zoomCamera(double z)
    9921128{
     1129    if (_cameraMode == IMAGE) {
     1130        double dx = _imgWorldDims[0];
     1131        double dy = _imgWorldDims[1];
     1132        _imgWorldDims[0] /= z;
     1133        _imgWorldDims[1] /= z;
     1134        dx -= _imgWorldDims[0];
     1135        dy -= _imgWorldDims[1];
     1136        _imgWorldOrigin[0] += dx/2.0;
     1137        _imgWorldOrigin[1] += dy/2.0;
     1138        setCameraZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1],
     1139                            _imgWorldDims[0], _imgWorldDims[1]);
     1140        _needsRedraw = true;
     1141        return;
     1142    }
    9931143    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
    9941144    camera->Zoom(z); // Change perspective FOV angle or ortho parallel scale
     
    12081358    setContourVisibility(id, state);
    12091359    setPolyDataVisibility(id, state);
    1210 }
    1211 
    1212 /**
    1213  * \brief Set the RGB isoline color for the specified DataSet
    1214  */
    1215 void Renderer::setContourEdgeColor(DataSetId id, float color[3])
    1216 {
    1217     Contour2D *contour = getContour2D(id);
    1218     if (contour) {
    1219         contour->setEdgeColor(color);
    1220         _needsRedraw = true;
    1221     }
    1222 }
    1223 
    1224 /**
    1225  * \brief Set the isoline width for the specified DataSet (may be a no-op)
    1226  *
    1227  * If the OpenGL implementation/hardware does not support wide lines,
    1228  * this function may not have an effect.
    1229  */
    1230 void Renderer::setContourEdgeWidth(DataSetId id, float edgeWidth)
    1231 {
    1232     Contour2D *contour = getContour2D(id);
    1233     if (contour) {
    1234         contour->setEdgeWidth(edgeWidth);
    1235         _needsRedraw = true;
    1236     }
    1237 }
    1238 
    1239 /**
    1240  * \brief Set the RGB polygon face color for the specified DataSet
    1241  */
    1242 void Renderer::setPolyDataColor(DataSetId id, float color[3])
    1243 {
    1244     PolyData *polyData = getPolyData(id);
    1245     if (polyData) {
    1246         polyData->setColor(color);
    1247         _needsRedraw = true;
    1248     }
    1249 }
    1250 
    1251 /**
    1252  * \brief Set the visibility of polygon edges for the specified DataSet
    1253  */
    1254 void Renderer::setPolyDataEdgeVisibility(DataSetId id, bool state)
    1255 {
    1256     PolyData *polyData = getPolyData(id);
    1257     if (polyData) {
    1258         polyData->setEdgeVisibility(state);
    1259         _needsRedraw = true;
    1260     }
    1261 }
    1262 
    1263 /**
    1264  * \brief Set the RGB polygon edge color for the specified DataSet
    1265  */
    1266 void Renderer::setPolyDataEdgeColor(DataSetId id, float color[3])
    1267 {
    1268     PolyData *polyData = getPolyData(id);
    1269     if (polyData) {
    1270         polyData->setEdgeColor(color);
    1271         _needsRedraw = true;
    1272     }
    1273 }
    1274 
    1275 /**
    1276  * \brief Set the polygon edge width for the specified DataSet (may be a no-op)
    1277  *
    1278  * If the OpenGL implementation/hardware does not support wide lines,
    1279  * this function may not have an effect.
    1280  */
    1281 void Renderer::setPolyDataEdgeWidth(DataSetId id, float edgeWidth)
    1282 {
    1283     PolyData *polyData = getPolyData(id);
    1284     if (polyData) {
    1285         polyData->setEdgeWidth(edgeWidth);
    1286         _needsRedraw = true;
    1287     }
    1288 }
    1289 
    1290 /**
    1291  * \brief Set wireframe rendering for the specified DataSet
    1292  */
    1293 void Renderer::setPolyDataWireframe(DataSetId id, bool state)
    1294 {
    1295     PolyData *polyData = getPolyData(id);
    1296     if (polyData) {
    1297         polyData->setWireframe(state);
    1298         _needsRedraw = true;
    1299     }
    13001360}
    13011361
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2112 r2114  
    160160    void setPseudoColorEdgeWidth(DataSetId id, float edgeWidth);
    161161
     162    void setPseudoColorLighting(DataSetId id, bool state);
     163
    162164    // Contour plots
    163165
     
    177179
    178180    void setContourEdgeWidth(DataSetId id, float edgeWidth);
     181
     182    void setContourLighting(DataSetId id, bool state);
    179183
    180184    // Meshes
     
    197201
    198202    void setPolyDataWireframe(DataSetId id, bool state);
     203
     204    void setPolyDataLighting(DataSetId id, bool state);
    199205
    200206private:
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2112 r2114  
    481481
    482482static int
     483Contour2DLightingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     484                    Tcl_Obj *const *objv)
     485{
     486    const char *name = Tcl_GetString(objv[3]);
     487    bool state;
     488    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     489        return TCL_ERROR;
     490    }
     491    g_renderer->setContourLighting(name, state);
     492    return TCL_OK;
     493}
     494
     495static int
    483496Contour2DLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc,
    484497                     Tcl_Obj *const *objv)
     
    524537    {"add", 1, Contour2DAddOp, 5, 5, "oper value dataSetName"},
    525538    {"delete", 1, Contour2DDeleteOp, 3, 3, "dataSetName"},
     539    {"lighting", 3, Contour2DLightingOp, 4, 4, "bool dataSetName"},
    526540    {"linecolor", 5, Contour2DLineColorOp, 6, 6, "r g b dataSetName"},
    527541    {"linewidth", 5, Contour2DLineWidthOp, 4, 4, "width dataSetName"},
     
    817831
    818832static int
     833PseudoColorLightingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     834                      Tcl_Obj *const *objv)
     835{
     836    const char *name = Tcl_GetString(objv[3]);
     837    bool state;
     838    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     839        return TCL_ERROR;
     840    }
     841    g_renderer->setPseudoColorLighting(name, state);
     842    return TCL_OK;
     843}
     844
     845static int
    819846PseudoColorLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc,
    820847                       Tcl_Obj *const *objv)
     
    849876    {"delete", 1, PseudoColorDeleteOp, 3, 3, "dataSetName"},
    850877    {"edges", 1, PseudoColorEdgeVisibilityOp, 4, 4, "bool dataSetName"},
     878    {"lighting", 3, PseudoColorLightingOp, 4, 4, "bool dataSetName"},
    851879    {"linecolor", 5, PseudoColorLineColorOp, 6, 6, "r g b dataSetName"},
    852880    {"linewidth", 5, PseudoColorLineWidthOp, 4, 4, "width dataSetName"},
     
    916944
    917945static int
     946PolyDataLightingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     947                   Tcl_Obj *const *objv)
     948{
     949    const char *name = Tcl_GetString(objv[3]);
     950    bool state;
     951    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     952        return TCL_ERROR;
     953    }
     954    g_renderer->setPolyDataLighting(name, state);
     955    return TCL_OK;
     956}
     957
     958static int
    918959PolyDataLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc,
    919960                    Tcl_Obj *const *objv)
     
    9741015    {"delete", 1, PolyDataDeleteOp, 3, 3, "dataSetName"},
    9751016    {"edges", 1, PolyDataEdgeVisibilityOp, 4, 4, "bool dataSetName"},
     1017    {"lighting", 3, PolyDataLightingOp, 4, 4, "bool dataSetName"},
    9761018    {"linecolor", 5, PolyDataLineColorOp, 6, 6, "r g b dataSetName"},
    9771019    {"linewidth", 5, PolyDataLineWidthOp, 4, 4, "width dataSetName"},
Note: See TracChangeset for help on using the changeset viewer.