Changeset 3683
- Timestamp:
- Jun 12, 2013, 2:51:11 AM (11 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/Arrow.cpp
r3616 r3683 9 9 #include <vtkActor.h> 10 10 #include <vtkArrowSource.h> 11 #include <vtkPolyDataNormals.h> 12 #include <vtkReverseSense.h> 11 13 12 14 #include "Arrow.h" … … 37 39 } 38 40 41 vtkSmartPointer<vtkPolyDataNormals> normalFilter = vtkSmartPointer<vtkPolyDataNormals>::New(); 42 normalFilter->SetInputConnection(_arrow->GetOutputPort()); 43 normalFilter->AutoOrientNormalsOff(); 44 39 45 _pdMapper->SetInputConnection(_arrow->GetOutputPort()); 40 46 … … 44 50 _pdMapper->Update(); 45 51 } 52 53 void Arrow::flipNormals(bool state) 54 { 55 if (_arrow == NULL || _pdMapper == NULL) 56 return; 57 58 if (state) { 59 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 60 filter->ReverseCellsOn(); 61 filter->ReverseNormalsOn(); 62 filter->SetInputConnection(_arrow->GetOutputPort()); 63 64 _pdMapper->SetInputConnection(filter->GetOutputPort()); 65 } else { 66 _pdMapper->SetInputConnection(_arrow->GetOutputPort()); 67 } 68 } -
trunk/packages/vizservers/vtkvis/Arrow.h
r3621 r3683 58 58 } 59 59 60 /** 61 * \brief Invert head/tail of arrow 62 */ 60 63 void setInvert(bool state) 61 64 { … … 64 67 } 65 68 } 69 70 void flipNormals(bool state); 66 71 67 72 private: -
trunk/packages/vizservers/vtkvis/Box.cpp
r3616 r3683 15 15 #include <vtkTransform.h> 16 16 #include <vtkCubeSource.h> 17 #include <vtkReverseSense.h> 17 18 18 19 #include "Box.h" … … 50 51 _pdMapper->Update(); 51 52 } 53 54 void Box::flipNormals(bool state) 55 { 56 if (_box == NULL || _pdMapper == NULL) 57 return; 58 59 if (state) { 60 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 61 filter->ReverseCellsOn(); 62 filter->ReverseNormalsOn(); 63 filter->SetInputConnection(_box->GetOutputPort()); 64 65 _pdMapper->SetInputConnection(filter->GetOutputPort()); 66 } else { 67 _pdMapper->SetInputConnection(_box->GetOutputPort()); 68 } 69 } -
trunk/packages/vizservers/vtkvis/Box.h
r3621 r3683 44 44 } 45 45 46 void flipNormals(bool state); 47 46 48 private: 47 49 virtual void update(); -
trunk/packages/vizservers/vtkvis/Cone.cpp
r3616 r3683 9 9 #include <vtkActor.h> 10 10 #include <vtkConeSource.h> 11 #include <vtkPolyDataNormals.h> 12 #include <vtkReverseSense.h> 11 13 12 14 #include "Cone.h" … … 37 39 } 38 40 41 vtkSmartPointer<vtkPolyDataNormals> normalFilter = vtkSmartPointer<vtkPolyDataNormals>::New(); 42 normalFilter->SetInputConnection(_cone->GetOutputPort()); 43 normalFilter->AutoOrientNormalsOff(); 44 39 45 _pdMapper->SetInputConnection(_cone->GetOutputPort()); 40 46 … … 44 50 _pdMapper->Update(); 45 51 } 52 53 void Cone::flipNormals(bool state) 54 { 55 if (_cone == NULL || _pdMapper == NULL) 56 return; 57 58 if (state) { 59 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 60 filter->ReverseCellsOn(); 61 filter->ReverseNormalsOn(); 62 filter->SetInputConnection(_cone->GetOutputPort()); 63 64 _pdMapper->SetInputConnection(filter->GetOutputPort()); 65 } else { 66 _pdMapper->SetInputConnection(_cone->GetOutputPort()); 67 } 68 } -
trunk/packages/vizservers/vtkvis/Cone.h
r3621 r3683 77 77 } 78 78 79 void flipNormals(bool state); 80 79 81 private: 80 82 virtual void update(); -
trunk/packages/vizservers/vtkvis/Cylinder.cpp
r3680 r3683 53 53 if (state) { 54 54 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 55 filter->ReverseCellsOn(); 56 filter->ReverseNormalsOn(); 55 57 filter->SetInputConnection(_cylinder->GetOutputPort()); 56 58 … … 59 61 _pdMapper->SetInputConnection(_cylinder->GetOutputPort()); 60 62 } 63 _pdMapper->Update(); 61 64 } -
trunk/packages/vizservers/vtkvis/Disk.cpp
r3680 r3683 10 10 #include <vtkDiskSource.h> 11 11 #include <vtkPolyDataNormals.h> 12 #include <vtkReverseSense.h> 12 13 13 14 #include "Disk.h" … … 17 18 18 19 Disk::Disk() : 19 Shape(), 20 _flipNormals(false) 20 Shape() 21 21 { 22 22 } … … 42 42 normalFilter->SetInputConnection(_disk->GetOutputPort()); 43 43 normalFilter->AutoOrientNormalsOff(); 44 normalFilter->SetFlipNormals(_flipNormals ? 1 : 0);45 44 46 45 _pdMapper->SetInputConnection(normalFilter->GetOutputPort()); … … 54 53 void Disk::flipNormals(bool state) 55 54 { 56 if (_flipNormals != state) { 57 _flipNormals = state; 58 update(); 55 if (_disk == NULL || _pdMapper == NULL) 56 return; 57 58 if (state) { 59 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 60 filter->ReverseCellsOn(); 61 filter->ReverseNormalsOn(); 62 filter->SetInputConnection(_disk->GetOutputPort()); 63 64 _pdMapper->SetInputConnection(filter->GetOutputPort()); 65 } else { 66 _pdMapper->SetInputConnection(_disk->GetOutputPort()); 59 67 } 68 _pdMapper->Update(); 60 69 } -
trunk/packages/vizservers/vtkvis/Disk.h
r3680 r3683 56 56 virtual void update(); 57 57 58 bool _flipNormals;59 58 vtkSmartPointer<vtkDiskSource> _disk; 60 59 }; -
trunk/packages/vizservers/vtkvis/GraphicsObject.h
r3621 r3683 41 41 CULL_BACK, 42 42 CULL_FRONT_AND_BACK 43 }; 44 enum ShadingModel { 45 SHADE_FLAT = VTK_FLAT, 46 SHADE_GOURAUD = VTK_GOURAUD, 47 SHADE_PHONG = VTK_PHONG 43 48 }; 44 49 … … 701 706 } else if (vtkVolume::SafeDownCast(prop) != NULL) { 702 707 vtkVolume::SafeDownCast(prop)->GetProperty()->SetShade((state ? 1 : 0)); 708 } 709 } 710 } 711 } 712 713 /** 714 * \brief Set shading interpolation model of the prop 715 */ 716 virtual void setShadingModel(ShadingModel state) 717 { 718 if (getActor() != NULL) { 719 getActor()->GetProperty()->SetInterpolation(state); 720 } else if (getAssembly() != NULL) { 721 vtkProp3DCollection *props = getAssembly()->GetParts(); 722 vtkProp3D *prop; 723 props->InitTraversal(); 724 while ((prop = props->GetNextProp3D()) != NULL) { 725 if (vtkActor::SafeDownCast(prop) != NULL) { 726 vtkActor::SafeDownCast(prop)->GetProperty()->SetInterpolation(state); 703 727 } 704 728 } -
trunk/packages/vizservers/vtkvis/Group.cpp
r3621 r3683 54 54 } 55 55 56 voidGroup::removeChild(const NodeId& name)56 GraphicsObject *Group::removeChild(const NodeId& name) 57 57 { 58 58 NodeHashmap::iterator itr = _nodes.find(name); 59 59 if (itr == _nodes.end()) { 60 60 ERROR("Node not found: '%s'", name.c_str()); 61 return ;61 return NULL; 62 62 } 63 63 GraphicsObject *obj = itr->second; … … 66 66 } 67 67 _nodes.erase(itr); 68 return obj; 68 69 } 69 70 -
trunk/packages/vizservers/vtkvis/Group.h
r3621 r3683 54 54 } 55 55 56 voidremoveChild(const NodeId& name);56 GraphicsObject *removeChild(const NodeId& name); 57 57 58 58 private: -
trunk/packages/vizservers/vtkvis/Polygon.cpp
r3616 r3683 9 9 #include <vtkActor.h> 10 10 #include <vtkRegularPolygonSource.h> 11 #include <vtkPolyDataNormals.h> 12 #include <vtkReverseSense.h> 11 13 12 14 #include "Polygon.h" … … 37 39 } 38 40 41 vtkSmartPointer<vtkPolyDataNormals> normalFilter = vtkSmartPointer<vtkPolyDataNormals>::New(); 42 normalFilter->SetInputConnection(_polygon->GetOutputPort()); 43 normalFilter->AutoOrientNormalsOff(); 44 39 45 _pdMapper->SetInputConnection(_polygon->GetOutputPort()); 40 46 … … 44 50 _pdMapper->Update(); 45 51 } 52 53 void Polygon::flipNormals(bool state) 54 { 55 if (_polygon == NULL || _pdMapper == NULL) 56 return; 57 58 if (state) { 59 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 60 filter->ReverseCellsOn(); 61 filter->ReverseNormalsOn(); 62 filter->SetInputConnection(_polygon->GetOutputPort()); 63 64 _pdMapper->SetInputConnection(filter->GetOutputPort()); 65 } else { 66 _pdMapper->SetInputConnection(_polygon->GetOutputPort()); 67 } 68 _pdMapper->Update(); 69 } 70 -
trunk/packages/vizservers/vtkvis/Polygon.h
r3621 r3683 63 63 } 64 64 65 void flipNormals(bool state); 66 65 67 private: 66 68 virtual void update(); -
trunk/packages/vizservers/vtkvis/RenderServer.h
r3621 r3683 16 16 class Renderer; 17 17 18 #define VTKVIS_VERSION_STRING "1. 3"18 #define VTKVIS_VERSION_STRING "1.4" 19 19 20 20 #define MSECS_ELAPSED(t1, t2) \ -
trunk/packages/vizservers/vtkvis/Renderer.cpp
r3680 r3683 20 20 #include <vtkCamera.h> 21 21 #include <vtkLight.h> 22 #include <vtkLightCollection.h> 22 23 #include <vtkCoordinate.h> 23 24 #include <vtkTransform.h> … … 124 125 //_renderer->SetAmbient(.2, .2, .2); 125 126 127 _renderer->AutomaticLightCreationOff(); 128 126 129 vtkSmartPointer<vtkLight> headlight = vtkSmartPointer<vtkLight>::New(); 127 130 headlight->SetLightTypeToHeadlight(); … … 130 133 //headlight->SetAmbientColor(1, 1, 1); 131 134 _renderer->AddLight(headlight); 135 132 136 vtkSmartPointer<vtkLight> skylight = vtkSmartPointer<vtkLight>::New(); 133 137 skylight->SetLightTypeToCameraLight(); … … 138 142 //skylight->SetAmbientColor(1, 1, 1); 139 143 _renderer->AddLight(skylight); 144 140 145 _renderer->LightFollowCameraOn(); 141 146 _renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); … … 3177 3182 mergeGraphicsObjectBounds<Disk>(bounds, onlyVisible); 3178 3183 mergeGraphicsObjectBounds<Glyphs>(bounds, onlyVisible); 3184 mergeGraphicsObjectBounds<Group>(bounds, onlyVisible); 3179 3185 mergeGraphicsObjectBounds<HeightMap>(bounds, onlyVisible); 3180 3186 mergeGraphicsObjectBounds<LIC>(bounds, onlyVisible); … … 3818 3824 } 3819 3825 3826 int Renderer::addLight(float pos[3]) 3827 { 3828 vtkSmartPointer<vtkLight> light = vtkSmartPointer<vtkLight>::New(); 3829 light->SetLightTypeToCameraLight(); 3830 light->SetPosition(pos[0], pos[1], pos[2]); 3831 light->SetFocalPoint(0, 0, 0); 3832 light->PositionalOff(); 3833 _renderer->AddLight(light); 3834 _needsRedraw = true; 3835 return (_renderer->GetLights()->GetNumberOfItems()-1); 3836 } 3837 3838 vtkLight *Renderer::getLight(int lightIdx) 3839 { 3840 vtkLightCollection *lights = _renderer->GetLights(); 3841 if (lights->GetNumberOfItems() < lightIdx+1) 3842 return NULL; 3843 lights->InitTraversal(); 3844 vtkLight *light = NULL; 3845 int i = 0; 3846 do { 3847 light = lights->GetNextItem(); 3848 } while (i++ < lightIdx); 3849 return light; 3850 } 3851 3852 void Renderer::setLightSwitch(int lightIdx, bool state) 3853 { 3854 vtkLight *light = getLight(lightIdx); 3855 if (light == NULL) { 3856 ERROR("Unknown light %d", lightIdx); 3857 return; 3858 } 3859 light->SetSwitch((state ? 1 : 0)); 3860 _needsRedraw = true; 3861 } 3862 3820 3863 /** 3821 3864 * \brief Initialize the camera zoom region to include the bounding volume given -
trunk/packages/vizservers/vtkvis/Renderer.h
r3682 r3683 174 174 int getWindowHeight() const; 175 175 176 // Lights 177 178 int addLight(float pos[3]); 179 180 vtkLight *getLight(int lightIdx); 181 182 void setLightSwitch(int lightIdx, bool state); 183 176 184 // Camera controls 177 185 … … 448 456 // Generic GraphicsObject methods 449 457 458 GraphicsObject *getGenericGraphicsObject(const DataSetId& id); 459 450 460 template<class T> 451 461 T *getGraphicsObject(const DataSetId& id); … … 499 509 500 510 template<class T> 511 void setGraphicsObjectOrigin(const DataSetId& id, double origin[3]); 512 513 template<class T> 501 514 void setGraphicsObjectPosition(const DataSetId& id, double pos[3]); 502 515 … … 519 532 520 533 template<class T> 534 void setGraphicsObjectCullFace(const DataSetId& id, GraphicsObject::CullFace state); 535 536 template<class T> 537 void setGraphicsObjectCulling(const DataSetId& id, bool state); 538 539 template<class T> 521 540 void setGraphicsObjectEdgeVisibility(const DataSetId& id, bool state); 522 541 … … 534 553 535 554 template<class T> 555 void setGraphicsObjectShadingModel(const DataSetId& id, GraphicsObject::ShadingModel state); 556 557 template<class T> 536 558 void setGraphicsObjectSpecular(const DataSetId& id, double coeff, double power); 537 559 … … 548 570 void setGraphicsObjectWireframe(const DataSetId& id, bool state); 549 571 572 // For Shapes: 573 574 template<class T> 575 void setGraphicsObjectFlipNormals(const DataSetId& id, bool state); 576 550 577 // Arcs 551 578 552 bool addArc(const DataSetId& id, double pt1[3], double pt2[3]);579 bool addArc(const DataSetId& id, double center[3], double pt1[3], double pt2[3]); 553 580 554 581 void setArcResolution(const DataSetId& id, int res); … … 556 583 // Arrows 557 584 558 bool addArrow(const DataSetId& id, double tipRadius, double shaftRadius, double tipLength );585 bool addArrow(const DataSetId& id, double tipRadius, double shaftRadius, double tipLength, bool flipNormals = false); 559 586 560 587 void setArrowResolution(const DataSetId& id, int resTip, int resShaft); 561 588 589 // Boxes 590 591 bool addBox(const DataSetId& id, double xLen, double yLen, double zLen, bool flipNormals = false); 592 562 593 // Cones 563 594 564 bool addCone(const DataSetId& id, double radius, double height, bool cap );595 bool addCone(const DataSetId& id, double radius, double height, bool cap, bool flipNormals = false); 565 596 566 597 void setConeResolution(const DataSetId& id, int res); … … 628 659 // Cylinders 629 660 630 bool addCylinder(const DataSetId& id, double radius, double height, bool cap); 661 bool addCylinder(const DataSetId& id, double radius, double height, bool cap, bool flipNormals = false); 662 663 void setCylinderCapping(const DataSetId& id, bool state); 631 664 632 665 void setCylinderResolution(const DataSetId& id, int res); … … 634 667 // Disks 635 668 636 bool addDisk(const DataSetId& id, double innerRadius, double outerRadius );669 bool addDisk(const DataSetId& id, double innerRadius, double outerRadius, bool flipNormals = false); 637 670 638 671 void setDiskResolution(const DataSetId& id, int resRadial, int resCircum); … … 660 693 void setGlyphsScaleFactor(const DataSetId& id, double scale); 661 694 695 // Groups 696 697 bool addGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList); 698 699 void addChildrenToGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList); 700 701 void removeChildrenFromGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList); 702 662 703 // Height maps 663 704 … … 732 773 // N-sided Regular Polygons 733 774 734 bool addPolygon(const DataSetId& id, int numSides );775 bool addPolygon(const DataSetId& id, int numSides, double center[3], double normal[3], double radius); 735 776 736 777 // PolyData meshes … … 755 796 // Spheres 756 797 757 void setSphereSection(const DataSetId& id, double thetaStart, double thetaEnd, 798 bool addSphere(const DataSetId& id, double center[3], double radius, bool flipNormals = false); 799 800 void setSphereSection(const DataSetId& id, 801 double thetaStart, double thetaEnd, 758 802 double phiStart, double phiEnd); 759 803 -
trunk/packages/vizservers/vtkvis/RendererCmd.cpp
r3682 r3683 131 131 Tcl_Obj *const *objv) 132 132 { 133 double pt1[3]; 134 double pt2[3]; 135 if (Tcl_GetDoubleFromObj(interp, objv[2], &pt1[0]) != TCL_OK || 136 Tcl_GetDoubleFromObj(interp, objv[3], &pt1[1]) != TCL_OK || 137 Tcl_GetDoubleFromObj(interp, objv[4], &pt1[2]) != TCL_OK || 138 Tcl_GetDoubleFromObj(interp, objv[5], &pt2[0]) != TCL_OK || 139 Tcl_GetDoubleFromObj(interp, objv[6], &pt2[1]) != TCL_OK || 140 Tcl_GetDoubleFromObj(interp, objv[7], &pt2[2]) != TCL_OK) { 141 return TCL_ERROR; 142 } 143 const char *name = Tcl_GetString(objv[8]); 144 if (!g_renderer->addArc(name, pt1, pt2)) { 133 double center[3], pt1[3], pt2[3]; 134 if (Tcl_GetDoubleFromObj(interp, objv[2], ¢er[0]) != TCL_OK || 135 Tcl_GetDoubleFromObj(interp, objv[3], ¢er[1]) != TCL_OK || 136 Tcl_GetDoubleFromObj(interp, objv[4], ¢er[2]) != TCL_OK || 137 Tcl_GetDoubleFromObj(interp, objv[5], &pt1[0]) != TCL_OK || 138 Tcl_GetDoubleFromObj(interp, objv[6], &pt1[1]) != TCL_OK || 139 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)) { 145 147 Tcl_AppendResult(interp, "Failed to create arc", (char*)NULL); 146 148 return TCL_ERROR; … … 236 238 237 239 static int 240 ArcOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 241 Tcl_Obj *const *objv) 242 { 243 double origin[3]; 244 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 245 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 246 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 247 return TCL_ERROR; 248 } 249 if (objc == 6) { 250 const char *name = Tcl_GetString(objv[5]); 251 g_renderer->setGraphicsObjectOrigin<Arc>(name, origin); 252 } else { 253 g_renderer->setGraphicsObjectOrigin<Arc>("all", origin); 254 } 255 return TCL_OK; 256 } 257 258 static int 238 259 ArcPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 239 260 Tcl_Obj *const *objv) … … 308 329 309 330 static Rappture::CmdSpec arcOps[] = { 310 {"add", 1, ArcAddOp, 9, 9, "x1 y1 z1 x2 y2 z2 name"},331 {"add", 1, ArcAddOp, 12, 12, "centerX centerY centerZ x1 y1 z1 x2 y2 z2 name"}, 311 332 {"color", 1, ArcColorOp, 5, 6, "r g b ?name?"}, 312 333 {"delete", 1, ArcDeleteOp, 2, 3, "?name?"}, … … 314 335 {"linewidth", 5, ArcLineWidthOp, 3, 4, "width ?name?"}, 315 336 {"opacity", 2, ArcOpacityOp, 3, 4, "value ?name?"}, 316 {"orient", 2, ArcOrientOp, 6, 7, "qw qx qy qz ?name?"}, 337 {"orient", 4, ArcOrientOp, 6, 7, "qw qx qy qz ?name?"}, 338 {"origin", 4, ArcOriginOp, 5, 6, "x y z ?name?"}, 317 339 {"pos", 2, ArcPositionOp, 5, 6, "x y z ?name?"}, 318 340 {"resolution",1, ArcResolutionOp, 3, 4, "res ?name?"}, … … 387 409 388 410 static int 411 ArrowCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 412 Tcl_Obj *const *objv) 413 { 414 bool state; 415 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 416 return TCL_ERROR; 417 } 418 if (objc == 4) { 419 const char *name = Tcl_GetString(objv[3]); 420 g_renderer->setGraphicsObjectCulling<Arrow>(name, state); 421 } else { 422 g_renderer->setGraphicsObjectCulling<Arrow>("all", state); 423 } 424 return TCL_OK; 425 } 426 427 static int 389 428 ArrowEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 390 429 Tcl_Obj *const *objv) … … 399 438 } else { 400 439 g_renderer->setGraphicsObjectEdgeVisibility<Arrow>("all", state); 440 } 441 return TCL_OK; 442 } 443 444 static int 445 ArrowFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 446 Tcl_Obj *const *objv) 447 { 448 bool state; 449 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 450 return TCL_ERROR; 451 } 452 if (objc == 4) { 453 const char *name = Tcl_GetString(objv[3]); 454 g_renderer->setGraphicsObjectFlipNormals<Arrow>(name, state); 455 } else { 456 g_renderer->setGraphicsObjectFlipNormals<Arrow>("all", state); 401 457 } 402 458 return TCL_OK; … … 519 575 520 576 static int 577 ArrowOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 578 Tcl_Obj *const *objv) 579 { 580 double origin[3]; 581 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 582 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 583 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 584 return TCL_ERROR; 585 } 586 if (objc == 6) { 587 const char *name = Tcl_GetString(objv[5]); 588 g_renderer->setGraphicsObjectOrigin<Arrow>(name, origin); 589 } else { 590 g_renderer->setGraphicsObjectOrigin<Arrow>("all", origin); 591 } 592 return TCL_OK; 593 } 594 595 static int 521 596 ArrowPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 522 597 Tcl_Obj *const *objv) … … 575 650 576 651 static int 652 ArrowShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 653 Tcl_Obj *const *objv) 654 { 655 GraphicsObject::ShadingModel shadeModel; 656 const char *str = Tcl_GetString(objv[2]); 657 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 658 shadeModel = GraphicsObject::SHADE_FLAT; 659 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 660 shadeModel = GraphicsObject::SHADE_GOURAUD; 661 } else { 662 Tcl_AppendResult(interp, "bad shading option \"", str, 663 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 664 return TCL_ERROR; 665 } 666 if (objc == 4) { 667 const char *name = Tcl_GetString(objv[3]); 668 g_renderer->setGraphicsObjectShadingModel<Arrow>(name, shadeModel); 669 } else { 670 g_renderer->setGraphicsObjectShadingModel<Arrow>("all", shadeModel); 671 } 672 return TCL_OK; 673 } 674 675 static int 577 676 ArrowVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 578 677 Tcl_Obj *const *objv) … … 610 709 static Rappture::CmdSpec arrowOps[] = { 611 710 {"add", 1, ArrowAddOp, 6, 6, "tipRadius shaftRadius tipLength name"}, 612 {"color", 1, ArrowColorOp, 5, 6, "r g b ?name?"}, 711 {"color", 2, ArrowColorOp, 5, 6, "r g b ?name?"}, 712 {"culling", 2, ArrowCullingOp, 3, 4, "bool ?name?"}, 613 713 {"delete", 1, ArrowDeleteOp, 2, 3, "?name?"}, 614 714 {"edges", 1, ArrowEdgeVisibilityOp, 3, 4, "bool ?name?"}, 715 {"flipnorms", 1, ArrowFlipNormalsOp, 3, 4, "bool ?name?"}, 615 716 {"lighting", 3, ArrowLightingOp, 3, 4, "bool ?name?"}, 616 717 {"linecolor", 5, ArrowLineColorOp, 5, 6, "r g b ?name?"}, … … 618 719 {"material", 1, ArrowMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 619 720 {"opacity", 2, ArrowOpacityOp, 3, 4, "value ?name?"}, 620 {"orient", 2, ArrowOrientOp, 6, 7, "qw qx qy qz ?name?"}, 721 {"orient", 4, ArrowOrientOp, 6, 7, "qw qx qy qz ?name?"}, 722 {"origin", 4, ArrowOriginOp, 5, 6, "x y z ?name?"}, 621 723 {"pos", 2, ArrowPositionOp, 5, 6, "x y z ?name?"}, 622 724 {"resolution",1, ArrowResolutionOp, 4, 5, "tipRes shaftRes ?name?"}, 623 {"scale", 1, ArrowScaleOp, 5, 6, "sx sy sz ?name?"}, 725 {"scale", 2, ArrowScaleOp, 5, 6, "sx sy sz ?name?"}, 726 {"shading", 2, ArrowShadingOp, 3, 4, "val ?name?"}, 624 727 {"visible", 1, ArrowVisibleOp, 3, 4, "bool ?name?"}, 625 728 {"wireframe", 1, ArrowWireframeOp, 3, 4, "bool ?name?"} … … 1603 1706 Tcl_Obj *const *objv) 1604 1707 { 1605 const char *name = Tcl_GetString(objv[2]); 1606 if (!g_renderer->addGraphicsObject<Box>(name)) { 1708 double xLen, yLen, zLen; 1709 if (Tcl_GetDoubleFromObj(interp, objv[2], &xLen) != TCL_OK || 1710 Tcl_GetDoubleFromObj(interp, objv[3], &yLen) != TCL_OK || 1711 Tcl_GetDoubleFromObj(interp, objv[4], &zLen) != TCL_OK) { 1712 return TCL_ERROR; 1713 } 1714 const char *name = Tcl_GetString(objv[5]); 1715 if (!g_renderer->addBox(name, xLen, yLen, zLen)) { 1607 1716 Tcl_AppendResult(interp, "Failed to create box", (char*)NULL); 1608 1717 return TCL_ERROR; … … 1644 1753 1645 1754 static int 1755 BoxCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 1756 Tcl_Obj *const *objv) 1757 { 1758 bool state; 1759 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 1760 return TCL_ERROR; 1761 } 1762 if (objc == 4) { 1763 const char *name = Tcl_GetString(objv[3]); 1764 g_renderer->setGraphicsObjectCulling<Box>(name, state); 1765 } else { 1766 g_renderer->setGraphicsObjectCulling<Box>("all", state); 1767 } 1768 return TCL_OK; 1769 } 1770 1771 static int 1646 1772 BoxEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 1647 1773 Tcl_Obj *const *objv) … … 1656 1782 } else { 1657 1783 g_renderer->setGraphicsObjectEdgeVisibility<Box>("all", state); 1784 } 1785 return TCL_OK; 1786 } 1787 1788 static int 1789 BoxFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 1790 Tcl_Obj *const *objv) 1791 { 1792 bool state; 1793 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 1794 return TCL_ERROR; 1795 } 1796 if (objc == 4) { 1797 const char *name = Tcl_GetString(objv[3]); 1798 g_renderer->setGraphicsObjectFlipNormals<Box>(name, state); 1799 } else { 1800 g_renderer->setGraphicsObjectFlipNormals<Box>("all", state); 1658 1801 } 1659 1802 return TCL_OK; … … 1776 1919 1777 1920 static int 1921 BoxOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 1922 Tcl_Obj *const *objv) 1923 { 1924 double origin[3]; 1925 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 1926 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 1927 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 1928 return TCL_ERROR; 1929 } 1930 if (objc == 6) { 1931 const char *name = Tcl_GetString(objv[5]); 1932 g_renderer->setGraphicsObjectOrigin<Box>(name, origin); 1933 } else { 1934 g_renderer->setGraphicsObjectOrigin<Box>("all", origin); 1935 } 1936 return TCL_OK; 1937 } 1938 1939 static int 1778 1940 BoxPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 1779 1941 Tcl_Obj *const *objv) … … 1814 1976 1815 1977 static int 1978 BoxShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 1979 Tcl_Obj *const *objv) 1980 { 1981 GraphicsObject::ShadingModel shadeModel; 1982 const char *str = Tcl_GetString(objv[2]); 1983 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 1984 shadeModel = GraphicsObject::SHADE_FLAT; 1985 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 1986 shadeModel = GraphicsObject::SHADE_GOURAUD; 1987 } else { 1988 Tcl_AppendResult(interp, "bad shading option \"", str, 1989 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 1990 return TCL_ERROR; 1991 } 1992 if (objc == 4) { 1993 const char *name = Tcl_GetString(objv[3]); 1994 g_renderer->setGraphicsObjectShadingModel<Box>(name, shadeModel); 1995 } else { 1996 g_renderer->setGraphicsObjectShadingModel<Box>("all", shadeModel); 1997 } 1998 return TCL_OK; 1999 } 2000 2001 static int 1816 2002 BoxVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 1817 2003 Tcl_Obj *const *objv) … … 1848 2034 1849 2035 static Rappture::CmdSpec boxOps[] = { 1850 {"add", 1, BoxAddOp, 3, 3, "name"}, 1851 {"color", 1, BoxColorOp, 5, 6, "r g b ?name?"}, 2036 {"add", 1, BoxAddOp, 6, 6, "xLen yLen zLen name"}, 2037 {"color", 2, BoxColorOp, 5, 6, "r g b ?name?"}, 2038 {"culling", 2, BoxCullingOp, 3, 4, "bool ?name?"}, 1852 2039 {"delete", 1, BoxDeleteOp, 2, 3, "?name?"}, 1853 2040 {"edges", 1, BoxEdgeVisibilityOp, 3, 4, "bool ?name?"}, 2041 {"flipnorms", 1, BoxFlipNormalsOp, 3, 4, "bool ?name?"}, 1854 2042 {"lighting", 3, BoxLightingOp, 3, 4, "bool ?name?"}, 1855 2043 {"linecolor", 5, BoxLineColorOp, 5, 6, "r g b ?name?"}, … … 1857 2045 {"material", 1, BoxMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 1858 2046 {"opacity", 2, BoxOpacityOp, 3, 4, "value ?name?"}, 1859 {"orient", 2, BoxOrientOp, 6, 7, "qw qx qy qz ?name?"}, 2047 {"orient", 4, BoxOrientOp, 6, 7, "qw qx qy qz ?name?"}, 2048 {"origin", 4, BoxOriginOp, 5, 6, "x y z ?name?"}, 1860 2049 {"pos", 2, BoxPositionOp, 5, 6, "x y z ?name?"}, 1861 {"scale", 1, BoxScaleOp, 5, 6, "sx sy sz ?name?"}, 2050 {"scale", 2, BoxScaleOp, 5, 6, "sx sy sz ?name?"}, 2051 {"shading", 2, BoxShadingOp, 3, 4, "val ?name?"}, 1862 2052 {"visible", 1, BoxVisibleOp, 3, 4, "bool ?name?"}, 1863 2053 {"wireframe", 1, BoxWireframeOp, 3, 4, "bool ?name?"} … … 2388 2578 2389 2579 static int 2580 ConeCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 2581 Tcl_Obj *const *objv) 2582 { 2583 bool state; 2584 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 2585 return TCL_ERROR; 2586 } 2587 if (objc == 4) { 2588 const char *name = Tcl_GetString(objv[3]); 2589 g_renderer->setGraphicsObjectCulling<Cone>(name, state); 2590 } else { 2591 g_renderer->setGraphicsObjectCulling<Cone>("all", state); 2592 } 2593 return TCL_OK; 2594 } 2595 2596 static int 2390 2597 ConeEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 2391 2598 Tcl_Obj *const *objv) … … 2400 2607 } else { 2401 2608 g_renderer->setGraphicsObjectEdgeVisibility<Cone>("all", state); 2609 } 2610 return TCL_OK; 2611 } 2612 2613 static int 2614 ConeFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 2615 Tcl_Obj *const *objv) 2616 { 2617 bool state; 2618 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 2619 return TCL_ERROR; 2620 } 2621 if (objc == 4) { 2622 const char *name = Tcl_GetString(objv[3]); 2623 g_renderer->setGraphicsObjectFlipNormals<Cone>(name, state); 2624 } else { 2625 g_renderer->setGraphicsObjectFlipNormals<Cone>("all", state); 2402 2626 } 2403 2627 return TCL_OK; … … 2520 2744 2521 2745 static int 2746 ConeOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 2747 Tcl_Obj *const *objv) 2748 { 2749 double origin[3]; 2750 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 2751 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 2752 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 2753 return TCL_ERROR; 2754 } 2755 if (objc == 6) { 2756 const char *name = Tcl_GetString(objv[5]); 2757 g_renderer->setGraphicsObjectOrigin<Cone>(name, origin); 2758 } else { 2759 g_renderer->setGraphicsObjectOrigin<Cone>("all", origin); 2760 } 2761 return TCL_OK; 2762 } 2763 2764 static int 2522 2765 ConePositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 2523 2766 Tcl_Obj *const *objv) … … 2575 2818 2576 2819 static int 2820 ConeShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 2821 Tcl_Obj *const *objv) 2822 { 2823 GraphicsObject::ShadingModel shadeModel; 2824 const char *str = Tcl_GetString(objv[2]); 2825 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 2826 shadeModel = GraphicsObject::SHADE_FLAT; 2827 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 2828 shadeModel = GraphicsObject::SHADE_GOURAUD; 2829 } else { 2830 Tcl_AppendResult(interp, "bad shading option \"", str, 2831 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 2832 return TCL_ERROR; 2833 } 2834 if (objc == 4) { 2835 const char *name = Tcl_GetString(objv[3]); 2836 g_renderer->setGraphicsObjectShadingModel<Cone>(name, shadeModel); 2837 } else { 2838 g_renderer->setGraphicsObjectShadingModel<Cone>("all", shadeModel); 2839 } 2840 return TCL_OK; 2841 } 2842 2843 static int 2577 2844 ConeVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 2578 2845 Tcl_Obj *const *objv) … … 2610 2877 static Rappture::CmdSpec coneOps[] = { 2611 2878 {"add", 1, ConeAddOp, 6, 6, "radius height cap name"}, 2612 {"color", 1, ConeColorOp, 5, 6, "r g b ?name?"}, 2879 {"color", 2, ConeColorOp, 5, 6, "r g b ?name?"}, 2880 {"culling", 2, ConeCullingOp, 3, 4, "bool ?name?"}, 2613 2881 {"delete", 1, ConeDeleteOp, 2, 3, "?name?"}, 2614 2882 {"edges", 1, ConeEdgeVisibilityOp, 3, 4, "bool ?name?"}, 2883 {"flipnorms", 1, ConeFlipNormalsOp, 3, 4, "bool ?name?"}, 2615 2884 {"lighting", 3, ConeLightingOp, 3, 4, "bool ?name?"}, 2616 2885 {"linecolor", 5, ConeLineColorOp, 5, 6, "r g b ?name?"}, … … 2618 2887 {"material", 1, ConeMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 2619 2888 {"opacity", 2, ConeOpacityOp, 3, 4, "value ?name?"}, 2620 {"orient", 2, ConeOrientOp, 6, 7, "qw qx qy qz ?name?"}, 2889 {"orient", 4, ConeOrientOp, 6, 7, "qw qx qy qz ?name?"}, 2890 {"origin", 4, ConeOriginOp, 5, 6, "x y z ?name?"}, 2621 2891 {"pos", 2, ConePositionOp, 5, 6, "x y z ?name?"}, 2622 2892 {"resolution",1, ConeResolutionOp, 3, 4, "res ?name?"}, 2623 {"scale", 1, ConeScaleOp, 5, 6, "sx sy sz ?name?"}, 2893 {"scale", 2, ConeScaleOp, 5, 6, "sx sy sz ?name?"}, 2894 {"shading", 2, ConeShadingOp, 3, 4, "val ?name?"}, 2624 2895 {"visible", 1, ConeVisibleOp, 3, 4, "bool ?name?"}, 2625 2896 {"wireframe", 1, ConeWireframeOp, 3, 4, "bool ?name?"} … … 3934 4205 3935 4206 static int 4207 CylinderCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 4208 Tcl_Obj *const *objv) 4209 { 4210 bool state; 4211 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 4212 return TCL_ERROR; 4213 } 4214 if (objc == 4) { 4215 const char *name = Tcl_GetString(objv[3]); 4216 g_renderer->setGraphicsObjectCulling<Cylinder>(name, state); 4217 } else { 4218 g_renderer->setGraphicsObjectCulling<Cylinder>("all", state); 4219 } 4220 return TCL_OK; 4221 } 4222 4223 static int 3936 4224 CylinderEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 3937 4225 Tcl_Obj *const *objv) … … 3946 4234 } else { 3947 4235 g_renderer->setGraphicsObjectEdgeVisibility<Cylinder>("all", state); 4236 } 4237 return TCL_OK; 4238 } 4239 4240 static int 4241 CylinderFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 4242 Tcl_Obj *const *objv) 4243 { 4244 bool state; 4245 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 4246 return TCL_ERROR; 4247 } 4248 if (objc == 4) { 4249 const char *name = Tcl_GetString(objv[3]); 4250 g_renderer->setGraphicsObjectFlipNormals<Cylinder>(name, state); 4251 } else { 4252 g_renderer->setGraphicsObjectFlipNormals<Cylinder>("all", state); 3948 4253 } 3949 4254 return TCL_OK; … … 4066 4371 4067 4372 static int 4373 CylinderOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 4374 Tcl_Obj *const *objv) 4375 { 4376 double origin[3]; 4377 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 4378 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 4379 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 4380 return TCL_ERROR; 4381 } 4382 if (objc == 6) { 4383 const char *name = Tcl_GetString(objv[5]); 4384 g_renderer->setGraphicsObjectOrigin<Cylinder>(name, origin); 4385 } else { 4386 g_renderer->setGraphicsObjectOrigin<Cylinder>("all", origin); 4387 } 4388 return TCL_OK; 4389 } 4390 4391 static int 4068 4392 CylinderPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 4069 4393 Tcl_Obj *const *objv) … … 4121 4445 4122 4446 static int 4447 CylinderShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 4448 Tcl_Obj *const *objv) 4449 { 4450 GraphicsObject::ShadingModel shadeModel; 4451 const char *str = Tcl_GetString(objv[2]); 4452 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 4453 shadeModel = GraphicsObject::SHADE_FLAT; 4454 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 4455 shadeModel = GraphicsObject::SHADE_GOURAUD; 4456 } else { 4457 Tcl_AppendResult(interp, "bad shading option \"", str, 4458 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 4459 return TCL_ERROR; 4460 } 4461 if (objc == 4) { 4462 const char *name = Tcl_GetString(objv[3]); 4463 g_renderer->setGraphicsObjectShadingModel<Cylinder>(name, shadeModel); 4464 } else { 4465 g_renderer->setGraphicsObjectShadingModel<Cylinder>("all", shadeModel); 4466 } 4467 return TCL_OK; 4468 } 4469 4470 static int 4123 4471 CylinderVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 4124 4472 Tcl_Obj *const *objv) … … 4155 4503 4156 4504 static Rappture::CmdSpec cylinderOps[] = { 4157 {"add", 1, CylinderAddOp, 6, 6, " radius height cap name"}, 4158 {"color", 1, CylinderColorOp, 5, 6, "r g b ?name?"}, 4505 {"add", 1, CylinderAddOp, 6, 6, "radius height cap name"}, 4506 {"color", 2, CylinderColorOp, 5, 6, "r g b ?name?"}, 4507 {"culling", 2, CylinderCullingOp, 3, 4, "bool ?name?"}, 4159 4508 {"delete", 1, CylinderDeleteOp, 2, 3, "?name?"}, 4160 4509 {"edges", 1, CylinderEdgeVisibilityOp, 3, 4, "bool ?name?"}, 4510 {"flipnorms", 1, CylinderFlipNormalsOp, 3, 4, "bool ?name?"}, 4161 4511 {"lighting", 3, CylinderLightingOp, 3, 4, "bool ?name?"}, 4162 4512 {"linecolor", 5, CylinderLineColorOp, 5, 6, "r g b ?name?"}, … … 4164 4514 {"material", 1, CylinderMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 4165 4515 {"opacity", 2, CylinderOpacityOp, 3, 4, "value ?name?"}, 4166 {"orient", 2, CylinderOrientOp, 6, 7, "qw qx qy qz ?name?"}, 4516 {"orient", 4, CylinderOrientOp, 6, 7, "qw qx qy qz ?name?"}, 4517 {"origin", 4, CylinderOriginOp, 5, 6, "x y z ?name?"}, 4167 4518 {"pos", 2, CylinderPositionOp, 5, 6, "x y z ?name?"}, 4168 4519 {"resolution",1, CylinderResolutionOp, 3, 4, "res ?name?"}, 4169 {"scale", 1, CylinderScaleOp, 5, 6, "sx sy sz ?name?"}, 4520 {"scale", 2, CylinderScaleOp, 5, 6, "sx sy sz ?name?"}, 4521 {"shading", 2, CylinderShadingOp, 3, 4, "val ?name?"}, 4170 4522 {"visible", 1, CylinderVisibleOp, 3, 4, "bool ?name?"}, 4171 4523 {"wireframe", 1, CylinderWireframeOp, 3, 4, "bool ?name?"} … … 4668 5020 4669 5021 static int 5022 DiskCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 5023 Tcl_Obj *const *objv) 5024 { 5025 bool state; 5026 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 5027 return TCL_ERROR; 5028 } 5029 if (objc == 4) { 5030 const char *name = Tcl_GetString(objv[3]); 5031 g_renderer->setGraphicsObjectCulling<Disk>(name, state); 5032 } else { 5033 g_renderer->setGraphicsObjectCulling<Disk>("all", state); 5034 } 5035 return TCL_OK; 5036 } 5037 5038 static int 4670 5039 DiskEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 4671 5040 Tcl_Obj *const *objv) … … 4680 5049 } else { 4681 5050 g_renderer->setGraphicsObjectEdgeVisibility<Disk>("all", state); 5051 } 5052 return TCL_OK; 5053 } 5054 5055 static int 5056 DiskFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 5057 Tcl_Obj *const *objv) 5058 { 5059 bool state; 5060 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 5061 return TCL_ERROR; 5062 } 5063 if (objc == 4) { 5064 const char *name = Tcl_GetString(objv[3]); 5065 g_renderer->setGraphicsObjectFlipNormals<Disk>(name, state); 5066 } else { 5067 g_renderer->setGraphicsObjectFlipNormals<Disk>("all", state); 4682 5068 } 4683 5069 return TCL_OK; … … 4800 5186 4801 5187 static int 5188 DiskOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 5189 Tcl_Obj *const *objv) 5190 { 5191 double origin[3]; 5192 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 5193 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 5194 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 5195 return TCL_ERROR; 5196 } 5197 if (objc == 6) { 5198 const char *name = Tcl_GetString(objv[5]); 5199 g_renderer->setGraphicsObjectOrigin<Disk>(name, origin); 5200 } else { 5201 g_renderer->setGraphicsObjectOrigin<Disk>("all", origin); 5202 } 5203 return TCL_OK; 5204 } 5205 5206 static int 4802 5207 DiskPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 4803 5208 Tcl_Obj *const *objv) … … 4856 5261 4857 5262 static int 5263 DiskShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 5264 Tcl_Obj *const *objv) 5265 { 5266 GraphicsObject::ShadingModel shadeModel; 5267 const char *str = Tcl_GetString(objv[2]); 5268 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 5269 shadeModel = GraphicsObject::SHADE_FLAT; 5270 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 5271 shadeModel = GraphicsObject::SHADE_GOURAUD; 5272 } else { 5273 Tcl_AppendResult(interp, "bad shading option \"", str, 5274 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 5275 return TCL_ERROR; 5276 } 5277 if (objc == 4) { 5278 const char *name = Tcl_GetString(objv[3]); 5279 g_renderer->setGraphicsObjectShadingModel<Disk>(name, shadeModel); 5280 } else { 5281 g_renderer->setGraphicsObjectShadingModel<Disk>("all", shadeModel); 5282 } 5283 return TCL_OK; 5284 } 5285 5286 static int 4858 5287 DiskVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 4859 5288 Tcl_Obj *const *objv) … … 4891 5320 static Rappture::CmdSpec diskOps[] = { 4892 5321 {"add", 1, DiskAddOp, 5, 5, "innerRadius outerRadius name"}, 4893 {"color", 1, DiskColorOp, 5, 6, "r g b ?name?"}, 5322 {"color", 2, DiskColorOp, 5, 6, "r g b ?name?"}, 5323 {"culling", 2, DiskCullingOp, 3, 4, "bool ?name?"}, 4894 5324 {"delete", 1, DiskDeleteOp, 2, 3, "?name?"}, 4895 5325 {"edges", 1, DiskEdgeVisibilityOp, 3, 4, "bool ?name?"}, 5326 {"flipnorms", 1, DiskFlipNormalsOp, 3, 4, "bool ?name?"}, 4896 5327 {"lighting", 3, DiskLightingOp, 3, 4, "bool ?name?"}, 4897 5328 {"linecolor", 5, DiskLineColorOp, 5, 6, "r g b ?name?"}, … … 4899 5330 {"material", 1, DiskMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 4900 5331 {"opacity", 2, DiskOpacityOp, 3, 4, "value ?name?"}, 4901 {"orient", 2, DiskOrientOp, 6, 7, "qw qx qy qz ?name?"}, 5332 {"orient", 4, DiskOrientOp, 6, 7, "qw qx qy qz ?name?"}, 5333 {"origin", 4, DiskOriginOp, 5, 6, "x y z ?name?"}, 4902 5334 {"pos", 2, DiskPositionOp, 5, 6, "x y z ?name?"}, 4903 5335 {"resolution",1, DiskResolutionOp, 4, 5, "resRadial resCircum ?name?"}, 4904 {"scale", 1, DiskScaleOp, 5, 6, "sx sy sz ?name?"}, 5336 {"scale", 2, DiskScaleOp, 5, 6, "sx sy sz ?name?"}, 5337 {"shading", 2, DiskShadingOp, 3, 4, "val ?name?"}, 4905 5338 {"visible", 1, DiskVisibleOp, 3, 4, "bool ?name?"}, 4906 5339 {"wireframe", 1, DiskWireframeOp, 3, 4, "bool ?name?"} … … 5407 5840 5408 5841 proc = Rappture::GetOpFromObj(interp, nGlyphsOps, glyphsOps, 5842 Rappture::CMDSPEC_ARG1, objc, objv, 0); 5843 if (proc == NULL) { 5844 return TCL_ERROR; 5845 } 5846 return (*proc) (clientData, interp, objc, objv); 5847 } 5848 5849 static int 5850 GroupAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 5851 Tcl_Obj *const *objv) 5852 { 5853 int numNodes; 5854 Tcl_Obj **nodes = NULL; 5855 if (Tcl_ListObjGetElements(interp, objv[2], &numNodes, &nodes) != TCL_OK) { 5856 return TCL_ERROR; 5857 } 5858 std::vector<Group::NodeId> nodeList; 5859 for (int i = 0; i < numNodes; i++) { 5860 nodeList.push_back(Tcl_GetString(nodes[i])); 5861 } 5862 const char *name = Tcl_GetString(objv[3]); 5863 if (!g_renderer->addGroup(name, nodeList)) { 5864 Tcl_AppendResult(interp, "Failed to create group", (char*)NULL); 5865 return TCL_ERROR; 5866 } 5867 return TCL_OK; 5868 } 5869 5870 static int 5871 GroupDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 5872 Tcl_Obj *const *objv) 5873 { 5874 if (objc == 3) { 5875 const char *name = Tcl_GetString(objv[2]); 5876 g_renderer->deleteGraphicsObject<Group>(name); 5877 } else { 5878 g_renderer->deleteGraphicsObject<Group>("all"); 5879 } 5880 return TCL_OK; 5881 } 5882 5883 static int 5884 GroupOrientOp(ClientData clientData, Tcl_Interp *interp, int objc, 5885 Tcl_Obj *const *objv) 5886 { 5887 double quat[4]; 5888 if (Tcl_GetDoubleFromObj(interp, objv[2], &quat[0]) != TCL_OK || 5889 Tcl_GetDoubleFromObj(interp, objv[3], &quat[1]) != TCL_OK || 5890 Tcl_GetDoubleFromObj(interp, objv[4], &quat[2]) != TCL_OK || 5891 Tcl_GetDoubleFromObj(interp, objv[5], &quat[3]) != TCL_OK) { 5892 return TCL_ERROR; 5893 } 5894 if (objc == 7) { 5895 const char *name = Tcl_GetString(objv[6]); 5896 g_renderer->setGraphicsObjectOrientation<Group>(name, quat); 5897 } else { 5898 g_renderer->setGraphicsObjectOrientation<Group>("all", quat); 5899 } 5900 return TCL_OK; 5901 } 5902 5903 static int 5904 GroupOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 5905 Tcl_Obj *const *objv) 5906 { 5907 double origin[3]; 5908 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 5909 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 5910 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 5911 return TCL_ERROR; 5912 } 5913 if (objc == 6) { 5914 const char *name = Tcl_GetString(objv[5]); 5915 g_renderer->setGraphicsObjectOrigin<Group>(name, origin); 5916 } else { 5917 g_renderer->setGraphicsObjectOrigin<Group>("all", origin); 5918 } 5919 return TCL_OK; 5920 } 5921 5922 static int 5923 GroupPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 5924 Tcl_Obj *const *objv) 5925 { 5926 double pos[3]; 5927 if (Tcl_GetDoubleFromObj(interp, objv[2], &pos[0]) != TCL_OK || 5928 Tcl_GetDoubleFromObj(interp, objv[3], &pos[1]) != TCL_OK || 5929 Tcl_GetDoubleFromObj(interp, objv[4], &pos[2]) != TCL_OK) { 5930 return TCL_ERROR; 5931 } 5932 if (objc == 6) { 5933 const char *name = Tcl_GetString(objv[5]); 5934 g_renderer->setGraphicsObjectPosition<Group>(name, pos); 5935 } else { 5936 g_renderer->setGraphicsObjectPosition<Group>("all", pos); 5937 } 5938 return TCL_OK; 5939 } 5940 5941 static int 5942 GroupRemoveChildOp(ClientData clientData, Tcl_Interp *interp, int objc, 5943 Tcl_Obj *const *objv) 5944 { 5945 int numNodes; 5946 Tcl_Obj **nodes = NULL; 5947 if (Tcl_ListObjGetElements(interp, objv[2], &numNodes, &nodes) != TCL_OK) { 5948 return TCL_ERROR; 5949 } 5950 std::vector<Group::NodeId> nodeList; 5951 for (int i = 0; i < numNodes; i++) { 5952 nodeList.push_back(Tcl_GetString(nodes[i])); 5953 } 5954 if (objc == 4) { 5955 const char *name = Tcl_GetString(objv[3]); 5956 g_renderer->removeChildrenFromGroup(name, nodeList); 5957 } else { 5958 g_renderer->removeChildrenFromGroup("all", nodeList); 5959 } 5960 return TCL_OK; 5961 } 5962 5963 static int 5964 GroupScaleOp(ClientData clientData, Tcl_Interp *interp, int objc, 5965 Tcl_Obj *const *objv) 5966 { 5967 double scale[3]; 5968 if (Tcl_GetDoubleFromObj(interp, objv[2], &scale[0]) != TCL_OK || 5969 Tcl_GetDoubleFromObj(interp, objv[3], &scale[1]) != TCL_OK || 5970 Tcl_GetDoubleFromObj(interp, objv[4], &scale[2]) != TCL_OK) { 5971 return TCL_ERROR; 5972 } 5973 if (objc == 6) { 5974 const char *name = Tcl_GetString(objv[5]); 5975 g_renderer->setGraphicsObjectScale<Group>(name, scale); 5976 } else { 5977 g_renderer->setGraphicsObjectScale<Group>("all", scale); 5978 } 5979 return TCL_OK; 5980 } 5981 5982 static int 5983 GroupVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 5984 Tcl_Obj *const *objv) 5985 { 5986 bool state; 5987 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 5988 return TCL_ERROR; 5989 } 5990 if (objc == 4) { 5991 const char *name = Tcl_GetString(objv[3]); 5992 g_renderer->setGraphicsObjectVisibility<Group>(name, state); 5993 } else { 5994 g_renderer->setGraphicsObjectVisibility<Group>("all", state); 5995 } 5996 return TCL_OK; 5997 } 5998 5999 static Rappture::CmdSpec groupOps[] = { 6000 {"add", 1, GroupAddOp, 4, 4, "nodeList groupName"}, 6001 {"delete", 1, GroupDeleteOp, 2, 3, "?name?"}, 6002 {"orient", 4, GroupOrientOp, 6, 7, "qw qx qy qz ?name?"}, 6003 {"origin", 4, GroupOriginOp, 5, 6, "x y z ?name?"}, 6004 {"pos", 1, GroupPositionOp, 5, 6, "x y z ?name?"}, 6005 {"remove", 1, GroupRemoveChildOp, 3, 4, "nodeList ?name?"}, 6006 {"scale", 2, GroupScaleOp, 5, 6, "sx sy sz ?name?"}, 6007 {"visible", 1, GroupVisibleOp, 3, 4, "bool ?name?"}, 6008 }; 6009 static int nGroupOps = NumCmdSpecs(groupOps); 6010 6011 static int 6012 GroupCmd(ClientData clientData, Tcl_Interp *interp, int objc, 6013 Tcl_Obj *const *objv) 6014 { 6015 Tcl_ObjCmdProc *proc; 6016 6017 proc = Rappture::GetOpFromObj(interp, nGroupOps, groupOps, 5409 6018 Rappture::CMDSPEC_ARG1, objc, objv, 0); 5410 6019 if (proc == NULL) { … … 6553 7162 6554 7163 static int 7164 LineOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 7165 Tcl_Obj *const *objv) 7166 { 7167 double origin[3]; 7168 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 7169 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 7170 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 7171 return TCL_ERROR; 7172 } 7173 if (objc == 6) { 7174 const char *name = Tcl_GetString(objv[5]); 7175 g_renderer->setGraphicsObjectOrigin<Line>(name, origin); 7176 } else { 7177 g_renderer->setGraphicsObjectOrigin<Line>("all", origin); 7178 } 7179 return TCL_OK; 7180 } 7181 7182 static int 6555 7183 LinePositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 6556 7184 Tcl_Obj *const *objv) … … 6614 7242 {"linewidth", 5, LineLineWidthOp, 3, 4, "width ?name?"}, 6615 7243 {"opacity", 2, LineOpacityOp, 3, 4, "value ?name?"}, 6616 {"orient", 2, LineOrientOp, 6, 7, "qw qx qy qz ?name?"}, 7244 {"orient", 4, LineOrientOp, 6, 7, "qw qx qy qz ?name?"}, 7245 {"origin", 4, LineOriginOp, 5, 6, "x y z ?name?"}, 6617 7246 {"pos", 2, LinePositionOp, 5, 6, "x y z ?name?"}, 6618 7247 {"scale", 2, LineScaleOp, 5, 6, "sx sy sz ?name?"}, … … 7392 8021 7393 8022 static int 7394 PolyDataDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,7395 Tcl_Obj *const *objv)7396 {7397 if (objc == 3) {7398 const char *name = Tcl_GetString(objv[2]);7399 g_renderer->deleteGraphicsObject<PolyData>(name);7400 } else {7401 g_renderer->deleteGraphicsObject<PolyData>("all");7402 }7403 return TCL_OK;7404 }7405 7406 static int7407 8023 PolyDataColorOp(ClientData clientData, Tcl_Interp *interp, int objc, 7408 8024 Tcl_Obj *const *objv) … … 7419 8035 } else { 7420 8036 g_renderer->setGraphicsObjectColor<PolyData>("all", color); 8037 } 8038 return TCL_OK; 8039 } 8040 8041 static int 8042 PolyDataCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 8043 Tcl_Obj *const *objv) 8044 { 8045 bool state; 8046 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 8047 return TCL_ERROR; 8048 } 8049 if (objc == 4) { 8050 const char *name = Tcl_GetString(objv[3]); 8051 g_renderer->setGraphicsObjectCulling<PolyData>(name, state); 8052 } else { 8053 g_renderer->setGraphicsObjectCulling<PolyData>("all", state); 8054 } 8055 return TCL_OK; 8056 } 8057 8058 static int 8059 PolyDataDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 8060 Tcl_Obj *const *objv) 8061 { 8062 if (objc == 3) { 8063 const char *name = Tcl_GetString(objv[2]); 8064 g_renderer->deleteGraphicsObject<PolyData>(name); 8065 } else { 8066 g_renderer->deleteGraphicsObject<PolyData>("all"); 7421 8067 } 7422 8068 return TCL_OK; … … 7556 8202 7557 8203 static int 8204 PolyDataOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 8205 Tcl_Obj *const *objv) 8206 { 8207 double origin[3]; 8208 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 8209 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 8210 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 8211 return TCL_ERROR; 8212 } 8213 if (objc == 6) { 8214 const char *name = Tcl_GetString(objv[5]); 8215 g_renderer->setGraphicsObjectOrigin<PolyData>(name, origin); 8216 } else { 8217 g_renderer->setGraphicsObjectOrigin<PolyData>("all", origin); 8218 } 8219 return TCL_OK; 8220 } 8221 8222 static int 7558 8223 PolyDataPointSizeOp(ClientData clientData, Tcl_Interp *interp, int objc, 7559 8224 Tcl_Obj *const *objv) … … 7611 8276 7612 8277 static int 8278 PolyDataShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 8279 Tcl_Obj *const *objv) 8280 { 8281 GraphicsObject::ShadingModel shadeModel; 8282 const char *str = Tcl_GetString(objv[2]); 8283 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 8284 shadeModel = GraphicsObject::SHADE_FLAT; 8285 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 8286 shadeModel = GraphicsObject::SHADE_GOURAUD; 8287 } else { 8288 Tcl_AppendResult(interp, "bad shading option \"", str, 8289 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 8290 return TCL_ERROR; 8291 } 8292 if (objc == 4) { 8293 const char *name = Tcl_GetString(objv[3]); 8294 g_renderer->setGraphicsObjectShadingModel<PolyData>(name, shadeModel); 8295 } else { 8296 g_renderer->setGraphicsObjectShadingModel<PolyData>("all", shadeModel); 8297 } 8298 return TCL_OK; 8299 } 8300 8301 static int 7613 8302 PolyDataVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 7614 8303 Tcl_Obj *const *objv) … … 7648 8337 {"cloudstyle",2, PolyDataCloudStyleOp, 3, 4, "style ?dataSetName?"}, 7649 8338 {"color", 2, PolyDataColorOp, 5, 6, "r g b ?dataSetName?"}, 8339 {"culling", 2, PolyDataCullingOp, 3, 4, "bool ?name?"}, 7650 8340 {"delete", 1, PolyDataDeleteOp, 2, 3, "?dataSetName?"}, 7651 8341 {"edges", 1, PolyDataEdgeVisibilityOp, 3, 4, "bool ?dataSetName?"}, … … 7655 8345 {"material", 1, PolyDataMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?dataSetName?"}, 7656 8346 {"opacity", 2, PolyDataOpacityOp, 3, 4, "value ?dataSetName?"}, 7657 {"orient", 2, PolyDataOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"}, 8347 {"orient", 4, PolyDataOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"}, 8348 {"origin", 4, PolyDataOriginOp, 5, 6, "x y z ?name?"}, 7658 8349 {"pos", 2, PolyDataPositionOp, 5, 6, "x y z ?dataSetName?"}, 7659 8350 {"ptsize", 2, PolyDataPointSizeOp, 3, 4, "size ?dataSetName?"}, 7660 {"scale", 1, PolyDataScaleOp, 5, 6, "sx sy sz ?dataSetName?"}, 8351 {"scale", 2, PolyDataScaleOp, 5, 6, "sx sy sz ?dataSetName?"}, 8352 {"shading", 2, PolyDataShadingOp, 3, 4, "val ?name?"}, 7661 8353 {"visible", 1, PolyDataVisibleOp, 3, 4, "bool ?dataSetName?"}, 7662 8354 {"wireframe", 1, PolyDataWireframeOp, 3, 4, "bool ?dataSetName?"} … … 7683 8375 { 7684 8376 int numSides; 7685 if (Tcl_GetIntFromObj(interp, objv[2], &numSides) != TCL_OK) { 7686 return TCL_ERROR; 7687 } 7688 const char *name = Tcl_GetString(objv[3]); 7689 if (!g_renderer->addPolygon(name, numSides)) { 8377 double center[3], normal[3], radius; 8378 if (Tcl_GetIntFromObj(interp, objv[2], &numSides) != TCL_OK || 8379 Tcl_GetDoubleFromObj(interp, objv[3], ¢er[0]) != TCL_OK || 8380 Tcl_GetDoubleFromObj(interp, objv[4], ¢er[1]) != TCL_OK || 8381 Tcl_GetDoubleFromObj(interp, objv[5], ¢er[2]) != TCL_OK || 8382 Tcl_GetDoubleFromObj(interp, objv[6], &normal[0]) != TCL_OK || 8383 Tcl_GetDoubleFromObj(interp, objv[7], &normal[1]) != TCL_OK || 8384 Tcl_GetDoubleFromObj(interp, objv[8], &normal[2]) != TCL_OK || 8385 Tcl_GetDoubleFromObj(interp, objv[9], &radius) != TCL_OK) { 8386 return TCL_ERROR; 8387 } 8388 const char *name = Tcl_GetString(objv[10]); 8389 if (!g_renderer->addPolygon(name, numSides, center, normal, radius)) { 7690 8390 Tcl_AppendResult(interp, "Failed to create polygon", (char*)NULL); 7691 8391 return TCL_ERROR; … … 7727 8427 7728 8428 static int 8429 PolygonCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 8430 Tcl_Obj *const *objv) 8431 { 8432 bool state; 8433 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 8434 return TCL_ERROR; 8435 } 8436 if (objc == 4) { 8437 const char *name = Tcl_GetString(objv[3]); 8438 g_renderer->setGraphicsObjectCulling<Polygon>(name, state); 8439 } else { 8440 g_renderer->setGraphicsObjectCulling<Polygon>("all", state); 8441 } 8442 return TCL_OK; 8443 } 8444 8445 static int 7729 8446 PolygonEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 7730 8447 Tcl_Obj *const *objv) … … 7739 8456 } else { 7740 8457 g_renderer->setGraphicsObjectEdgeVisibility<Polygon>("all", state); 8458 } 8459 return TCL_OK; 8460 } 8461 8462 static int 8463 PolygonFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 8464 Tcl_Obj *const *objv) 8465 { 8466 bool state; 8467 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 8468 return TCL_ERROR; 8469 } 8470 if (objc == 4) { 8471 const char *name = Tcl_GetString(objv[3]); 8472 g_renderer->setGraphicsObjectFlipNormals<Polygon>(name, state); 8473 } else { 8474 g_renderer->setGraphicsObjectFlipNormals<Polygon>("all", state); 7741 8475 } 7742 8476 return TCL_OK; … … 7859 8593 7860 8594 static int 8595 PolygonOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 8596 Tcl_Obj *const *objv) 8597 { 8598 double origin[3]; 8599 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 8600 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 8601 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 8602 return TCL_ERROR; 8603 } 8604 if (objc == 6) { 8605 const char *name = Tcl_GetString(objv[5]); 8606 g_renderer->setGraphicsObjectOrigin<Polygon>(name, origin); 8607 } else { 8608 g_renderer->setGraphicsObjectOrigin<Polygon>("all", origin); 8609 } 8610 return TCL_OK; 8611 } 8612 8613 static int 7861 8614 PolygonPositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 7862 8615 Tcl_Obj *const *objv) … … 7897 8650 7898 8651 static int 8652 PolygonShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 8653 Tcl_Obj *const *objv) 8654 { 8655 GraphicsObject::ShadingModel shadeModel; 8656 const char *str = Tcl_GetString(objv[2]); 8657 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 8658 shadeModel = GraphicsObject::SHADE_FLAT; 8659 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 8660 shadeModel = GraphicsObject::SHADE_GOURAUD; 8661 } else { 8662 Tcl_AppendResult(interp, "bad shading option \"", str, 8663 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 8664 return TCL_ERROR; 8665 } 8666 if (objc == 4) { 8667 const char *name = Tcl_GetString(objv[3]); 8668 g_renderer->setGraphicsObjectShadingModel<Polygon>(name, shadeModel); 8669 } else { 8670 g_renderer->setGraphicsObjectShadingModel<Polygon>("all", shadeModel); 8671 } 8672 return TCL_OK; 8673 } 8674 8675 static int 7899 8676 PolygonVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 7900 8677 Tcl_Obj *const *objv) … … 7931 8708 7932 8709 static Rappture::CmdSpec polygonOps[] = { 7933 {"add", 1, PolygonAddOp, 4, 4, "numSides name"},8710 {"add", 1, PolygonAddOp, 11, 11, "numSides centerX centerY centerZ normalX normalY normalZ radius name"}, 7934 8711 {"color", 1, PolygonColorOp, 5, 6, "r g b ?name?"}, 8712 {"culling", 2, PolygonCullingOp, 3, 4, "bool ?name?"}, 7935 8713 {"delete", 1, PolygonDeleteOp, 2, 3, "?name?"}, 7936 8714 {"edges", 1, PolygonEdgeVisibilityOp, 3, 4, "bool ?name?"}, 8715 {"flipnorms", 1, PolygonFlipNormalsOp, 3, 4, "bool ?name?"}, 7937 8716 {"lighting", 3, PolygonLightingOp, 3, 4, "bool ?name?"}, 7938 8717 {"linecolor", 5, PolygonLineColorOp, 5, 6, "r g b ?name?"}, … … 7940 8719 {"material", 1, PolygonMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 7941 8720 {"opacity", 2, PolygonOpacityOp, 3, 4, "value ?name?"}, 7942 {"orient", 2, PolygonOrientOp, 6, 7, "qw qx qy qz ?name?"}, 8721 {"orient", 4, PolygonOrientOp, 6, 7, "qw qx qy qz ?name?"}, 8722 {"origin", 4, PolygonOriginOp, 5, 6, "x y z ?name?"}, 7943 8723 {"pos", 2, PolygonPositionOp, 5, 6, "x y z ?name?"}, 7944 {"scale", 1, PolygonScaleOp, 5, 6, "sx sy sz ?name?"}, 8724 {"scale", 2, PolygonScaleOp, 5, 6, "sx sy sz ?name?"}, 8725 {"shading", 2, PolygonShadingOp, 3, 4, "val ?name?"}, 7945 8726 {"visible", 1, PolygonVisibleOp, 3, 4, "bool ?name?"}, 7946 8727 {"wireframe", 1, PolygonWireframeOp, 3, 4, "bool ?name?"} … … 8382 9163 8383 9164 static int 9165 RendererLightsOp(ClientData clientData, Tcl_Interp *interp, int objc, 9166 Tcl_Obj *const *objv) 9167 { 9168 int idx; 9169 bool state; 9170 if (Tcl_GetIntFromObj(interp, objv[2], &idx) != TCL_OK) { 9171 return TCL_ERROR; 9172 } 9173 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 9174 return TCL_ERROR; 9175 } 9176 g_renderer->setLightSwitch(idx, state); 9177 return TCL_OK; 9178 } 9179 9180 static int 8384 9181 RendererTwoSidedLightingOp(ClientData clientData, Tcl_Interp *interp, int objc, 8385 9182 Tcl_Obj *const *objv) … … 8404 9201 {"clipplane", 1, RendererClipPlaneOp, 5, 5, "axis ratio direction"}, 8405 9202 {"depthpeel", 1, RendererDepthPeelingOp, 3, 3, "bool"}, 8406 {"light2side", 1, RendererTwoSidedLightingOp, 3, 3, "bool"}, 9203 {"light2side", 6, RendererTwoSidedLightingOp, 3, 3, "bool"}, 9204 {"lights", 6, RendererLightsOp, 4, 4, "idx bool"}, 8407 9205 {"render", 1, RendererRenderOp, 2, 2, ""} 8408 9206 }; … … 8478 9276 Tcl_Obj *const *objv) 8479 9277 { 8480 const char *name = Tcl_GetString(objv[2]); 8481 if (!g_renderer->addGraphicsObject<Sphere>(name)) { 9278 double center[3], radius; 9279 if (Tcl_GetDoubleFromObj(interp, objv[2], ¢er[0]) != TCL_OK || 9280 Tcl_GetDoubleFromObj(interp, objv[3], ¢er[1]) != TCL_OK || 9281 Tcl_GetDoubleFromObj(interp, objv[4], ¢er[2]) != TCL_OK || 9282 Tcl_GetDoubleFromObj(interp, objv[5], &radius) != TCL_OK) { 9283 return TCL_ERROR; 9284 } 9285 const char *name = Tcl_GetString(objv[6]); 9286 if (!g_renderer->addSphere(name, center, radius)) { 8482 9287 Tcl_AppendResult(interp, "Failed to create sphere", (char*)NULL); 8483 9288 return TCL_ERROR; … … 8519 9324 8520 9325 static int 9326 SphereCullingOp(ClientData clientData, Tcl_Interp *interp, int objc, 9327 Tcl_Obj *const *objv) 9328 { 9329 bool state; 9330 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 9331 return TCL_ERROR; 9332 } 9333 if (objc == 4) { 9334 const char *name = Tcl_GetString(objv[3]); 9335 g_renderer->setGraphicsObjectCulling<Sphere>(name, state); 9336 } else { 9337 g_renderer->setGraphicsObjectCulling<Sphere>("all", state); 9338 } 9339 return TCL_OK; 9340 } 9341 9342 static int 8521 9343 SphereEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 8522 9344 Tcl_Obj *const *objv) … … 8531 9353 } else { 8532 9354 g_renderer->setGraphicsObjectEdgeVisibility<Sphere>("all", state); 9355 } 9356 return TCL_OK; 9357 } 9358 9359 static int 9360 SphereFlipNormalsOp(ClientData clientData, Tcl_Interp *interp, int objc, 9361 Tcl_Obj *const *objv) 9362 { 9363 bool state; 9364 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 9365 return TCL_ERROR; 9366 } 9367 if (objc == 4) { 9368 const char *name = Tcl_GetString(objv[3]); 9369 g_renderer->setGraphicsObjectFlipNormals<Sphere>(name, state); 9370 } else { 9371 g_renderer->setGraphicsObjectFlipNormals<Sphere>("all", state); 8533 9372 } 8534 9373 return TCL_OK; … … 8651 9490 8652 9491 static int 9492 SphereOriginOp(ClientData clientData, Tcl_Interp *interp, int objc, 9493 Tcl_Obj *const *objv) 9494 { 9495 double origin[3]; 9496 if (Tcl_GetDoubleFromObj(interp, objv[2], &origin[0]) != TCL_OK || 9497 Tcl_GetDoubleFromObj(interp, objv[3], &origin[1]) != TCL_OK || 9498 Tcl_GetDoubleFromObj(interp, objv[4], &origin[2]) != TCL_OK) { 9499 return TCL_ERROR; 9500 } 9501 if (objc == 6) { 9502 const char *name = Tcl_GetString(objv[5]); 9503 g_renderer->setGraphicsObjectOrigin<Sphere>(name, origin); 9504 } else { 9505 g_renderer->setGraphicsObjectOrigin<Sphere>("all", origin); 9506 } 9507 return TCL_OK; 9508 } 9509 9510 static int 8653 9511 SpherePositionOp(ClientData clientData, Tcl_Interp *interp, int objc, 8654 9512 Tcl_Obj *const *objv) … … 8727 9585 8728 9586 static int 9587 SphereShadingOp(ClientData clientData, Tcl_Interp *interp, int objc, 9588 Tcl_Obj *const *objv) 9589 { 9590 GraphicsObject::ShadingModel shadeModel; 9591 const char *str = Tcl_GetString(objv[2]); 9592 if (str[0] == 'f' && strcmp(str, "flat") == 0) { 9593 shadeModel = GraphicsObject::SHADE_FLAT; 9594 } else if (str[0] == 's' && strcmp(str, "smooth") == 0) { 9595 shadeModel = GraphicsObject::SHADE_GOURAUD; 9596 } else { 9597 Tcl_AppendResult(interp, "bad shading option \"", str, 9598 "\": should be one of: 'flat', 'smooth'", (char*)NULL); 9599 return TCL_ERROR; 9600 } 9601 if (objc == 4) { 9602 const char *name = Tcl_GetString(objv[3]); 9603 g_renderer->setGraphicsObjectShadingModel<Sphere>(name, shadeModel); 9604 } else { 9605 g_renderer->setGraphicsObjectShadingModel<Sphere>("all", shadeModel); 9606 } 9607 return TCL_OK; 9608 } 9609 9610 static int 8729 9611 SphereVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 8730 9612 Tcl_Obj *const *objv) … … 8761 9643 8762 9644 static Rappture::CmdSpec sphereOps[] = { 8763 {"add", 1, SphereAddOp, 3, 3, "name"}, 8764 {"color", 1, SphereColorOp, 5, 6, "r g b ?name?"}, 9645 {"add", 1, SphereAddOp, 7, 7, "centerX centerY centerZ radius name"}, 9646 {"color", 2, SphereColorOp, 5, 6, "r g b ?name?"}, 9647 {"culling", 2, SphereCullingOp, 3, 4, "bool ?name?"}, 8765 9648 {"delete", 1, SphereDeleteOp, 2, 3, "?name?"}, 8766 9649 {"edges", 1, SphereEdgeVisibilityOp, 3, 4, "bool ?name?"}, 9650 {"flipnorms", 1, SphereFlipNormalsOp, 3, 4, "bool ?name?"}, 8767 9651 {"lighting", 3, SphereLightingOp, 3, 4, "bool ?name?"}, 8768 9652 {"linecolor", 5, SphereLineColorOp, 5, 6, "r g b ?name?"}, … … 8770 9654 {"material", 1, SphereMaterialOp, 6, 7, "ambientCoeff diffuseCoeff specularCoeff specularPower ?name?"}, 8771 9655 {"opacity", 2, SphereOpacityOp, 3, 4, "value ?name?"}, 8772 {"orient", 2, SphereOrientOp, 6, 7, "qw qx qy qz ?name?"}, 9656 {"orient", 4, SphereOrientOp, 6, 7, "qw qx qy qz ?name?"}, 9657 {"origin", 4, SphereOriginOp, 5, 6, "x y z ?name?"}, 8773 9658 {"pos", 2, SpherePositionOp, 5, 6, "x y z ?name?"}, 8774 9659 {"resolution",1, SphereResolutionOp, 4, 5, "thetaRes phiRes ?name?"}, 8775 9660 {"scale", 2, SphereScaleOp, 5, 6, "sx sy sz ?name?"}, 8776 9661 {"section", 2, SphereSectionOp, 6, 7, "thetaStart thetaEnd phiStart phiEnd ?name?"}, 9662 {"shading", 2, SphereShadingOp, 3, 4, "val ?name?"}, 8777 9663 {"visible", 1, SphereVisibleOp, 3, 4, "bool ?name?"}, 8778 9664 {"wireframe", 1, SphereWireframeOp, 3, 4, "bool ?name?"} … … 10389 11275 Tcl_CreateObjCommand(interp, "disk", DiskCmd, clientData, NULL); 10390 11276 Tcl_CreateObjCommand(interp, "glyphs", GlyphsCmd, clientData, NULL); 11277 Tcl_CreateObjCommand(interp, "group", GroupCmd, clientData, NULL); 10391 11278 Tcl_CreateObjCommand(interp, "heightmap", HeightMapCmd, clientData, NULL); 10392 11279 Tcl_CreateObjCommand(interp, "imgflush", ImageFlushCmd, clientData, NULL); … … 10427 11314 Tcl_DeleteCommand(interp, "disk"); 10428 11315 Tcl_DeleteCommand(interp, "glyphs"); 11316 Tcl_DeleteCommand(interp, "group"); 10429 11317 Tcl_DeleteCommand(interp, "heightmap"); 10430 11318 Tcl_DeleteCommand(interp, "imgflush"); -
trunk/packages/vizservers/vtkvis/RendererGraphicsObjs.cpp
r3682 r3683 165 165 166 166 template <> 167 void Renderer::deleteGraphicsObject<Group>(const DataSetId& id) 168 { 169 GroupHashmap& hashmap = getGraphicsObjectHashmap<Group>(); 170 GroupHashmap::iterator itr; 171 172 bool doAll = false; 173 174 if (id.compare("all") == 0) { 175 itr = hashmap.begin(); 176 doAll = true; 177 } else { 178 itr = hashmap.find(id); 179 } 180 if (itr == hashmap.end()) { 181 ERROR("Group not found: %s", id.c_str()); 182 return; 183 } 184 185 TRACE("Deleting Group: %s", id.c_str()); 186 187 do { 188 Group *gobj = itr->second; 189 if (gobj->getProp()) 190 _renderer->RemoveViewProp(gobj->getProp()); 191 if (gobj->getOverlayProp()) 192 _renderer->RemoveViewProp(gobj->getOverlayProp()); 193 194 std::vector<GraphicsObject *> children; 195 gobj->getChildren(children); 196 197 // Un-grouping children 198 for (std::vector<GraphicsObject *>::iterator citr = children.begin(); 199 citr != children.end(); ++citr) { 200 if ((*citr)->getProp()) 201 _renderer->AddViewProp((*citr)->getProp()); 202 if ((*citr)->getOverlayProp()) 203 _renderer->AddViewProp((*citr)->getOverlayProp()); 204 } 205 206 delete gobj; 207 208 itr = hashmap.erase(itr); 209 } while (doAll && itr != hashmap.end()); 210 211 sceneBoundsChanged(); 212 _needsRedraw = true; 213 } 214 215 template <> 167 216 bool Renderer::addGraphicsObject<Box>(const DataSetId& id) 168 217 { … … 262 311 using namespace VtkVis; 263 312 313 GraphicsObject * 314 Renderer::getGenericGraphicsObject(const DataSetId& id) 315 { 316 GraphicsObject *gobj = NULL; 317 318 if ((gobj = getGraphicsObject<Arc>(id)) != NULL) { 319 return gobj; 320 } 321 if ((gobj = getGraphicsObject<Arrow>(id)) != NULL) { 322 return gobj; 323 } 324 if ((gobj = getGraphicsObject<Box>(id)) != NULL) { 325 return gobj; 326 } 327 if ((gobj = getGraphicsObject<Cone>(id)) != NULL) { 328 return gobj; 329 } 330 if ((gobj = getGraphicsObject<Cylinder>(id)) != NULL) { 331 return gobj; 332 } 333 if ((gobj = getGraphicsObject<Disk>(id)) != NULL) { 334 return gobj; 335 } 336 if ((gobj = getGraphicsObject<Line>(id)) != NULL) { 337 return gobj; 338 } 339 if ((gobj = getGraphicsObject<Polygon>(id)) != NULL) { 340 return gobj; 341 } 342 if ((gobj = getGraphicsObject<Sphere>(id)) != NULL) { 343 return gobj; 344 } 345 // 346 if ((gobj = getGraphicsObject<Contour2D>(id)) != NULL) { 347 return gobj; 348 } 349 if ((gobj = getGraphicsObject<Contour3D>(id)) != NULL) { 350 return gobj; 351 } 352 if ((gobj = getGraphicsObject<Cutplane>(id)) != NULL) { 353 return gobj; 354 } 355 if ((gobj = getGraphicsObject<Glyphs>(id)) != NULL) { 356 return gobj; 357 } 358 if ((gobj = getGraphicsObject<HeightMap>(id)) != NULL) { 359 return gobj; 360 } 361 if ((gobj = getGraphicsObject<LIC>(id)) != NULL) { 362 return gobj; 363 } 364 if ((gobj = getGraphicsObject<Molecule>(id)) != NULL) { 365 return gobj; 366 } 367 if ((gobj = getGraphicsObject<Outline>(id)) != NULL) { 368 return gobj; 369 } 370 if ((gobj = getGraphicsObject<PolyData>(id)) != NULL) { 371 return gobj; 372 } 373 if ((gobj = getGraphicsObject<PseudoColor>(id)) != NULL) { 374 return gobj; 375 } 376 if ((gobj = getGraphicsObject<Streamlines>(id)) != NULL) { 377 return gobj; 378 } 379 if ((gobj = getGraphicsObject<Volume>(id)) != NULL) { 380 return gobj; 381 } 382 if ((gobj = getGraphicsObject<Warp>(id)) != NULL) { 383 return gobj; 384 } 385 // 386 if ((gobj = getGraphicsObject<Group>(id)) != NULL) { 387 return gobj; 388 } 389 390 return NULL; 391 } 392 264 393 /** 265 394 * \brief Create a new Arc and associate it with an ID 266 395 */ 267 bool Renderer::addArc(const DataSetId& id, double pt1[3], double pt2[3]) 396 bool Renderer::addArc(const DataSetId& id, double center[3], 397 double pt1[3], double pt2[3]) 268 398 { 269 399 Arc *gobj; … … 288 418 } 289 419 420 gobj->setCenter(center); 290 421 gobj->setEndPoints(pt1, pt2); 291 422 … … 330 461 * \brief Create a new Arrow and associate it with an ID 331 462 */ 332 bool Renderer::addArrow(const DataSetId& id, double tipRadius, double shaftRadius, double tipLength) 463 bool Renderer::addArrow(const DataSetId& id, double tipRadius, 464 double shaftRadius, double tipLength, 465 bool flipNormals) 333 466 { 334 467 Arrow *gobj; … … 355 488 gobj->setRadii(tipRadius, shaftRadius); 356 489 gobj->setTipLength(tipLength); 490 if (flipNormals) 491 gobj->flipNormals(flipNormals); 357 492 358 493 getGraphicsObjectHashmap<Arrow>()[id] = gobj; … … 394 529 395 530 /** 531 * \brief Create a new Box and associate it with an ID 532 */ 533 bool Renderer::addBox(const DataSetId& id, 534 double xLen, double yLen, double zLen, 535 bool flipNormals) 536 { 537 Box *gobj; 538 if ((gobj = getGraphicsObject<Box>(id)) != NULL) { 539 WARN("Replacing existing %s %s", gobj->getClassName(), id.c_str()); 540 deleteGraphicsObject<Box>(id); 541 } 542 543 gobj = new Box(); 544 545 gobj->setDataSet(NULL, this); 546 547 if (gobj->getProp() == NULL && 548 gobj->getOverlayProp() == NULL) { 549 delete gobj; 550 return false; 551 } else { 552 if (gobj->getProp()) 553 _renderer->AddViewProp(gobj->getProp()); 554 if (gobj->getOverlayProp()) 555 _renderer->AddViewProp(gobj->getOverlayProp()); 556 } 557 558 gobj->setSize(xLen, yLen, zLen); 559 if (flipNormals) 560 gobj->flipNormals(flipNormals); 561 562 getGraphicsObjectHashmap<Box>()[id] = gobj; 563 564 sceneBoundsChanged(); 565 _needsRedraw = true; 566 return true; 567 } 568 569 /** 396 570 * \brief Create a new Cone and associate it with an ID 397 571 */ 398 bool Renderer::addCone(const DataSetId& id, double radius, double height, bool cap) 572 bool Renderer::addCone(const DataSetId& id, double radius, double height, 573 bool cap, bool flipNormals) 399 574 { 400 575 Cone *gobj; … … 422 597 gobj->setHeight(height); 423 598 gobj->setCapping(cap); 599 if (flipNormals) 600 gobj->flipNormals(flipNormals); 424 601 425 602 getGraphicsObjectHashmap<Cone>()[id] = gobj; … … 1100 1277 * \brief Create a new Cylinder and associate it with an ID 1101 1278 */ 1102 bool Renderer::addCylinder(const DataSetId& id, double radius, double height, bool cap) 1279 bool Renderer::addCylinder(const DataSetId& id, double radius, double height, 1280 bool cap, bool flipNormals) 1103 1281 { 1104 1282 Cylinder *gobj; … … 1126 1304 gobj->setHeight(height); 1127 1305 gobj->setCapping(cap); 1306 if (flipNormals) 1307 gobj->flipNormals(flipNormals); 1128 1308 1129 1309 getGraphicsObjectHashmap<Cylinder>()[id] = gobj; … … 1135 1315 1136 1316 /** 1137 * \brief Set Cylinder resolution1138 */ 1139 void Renderer::setCylinder Resolution(const DataSetId& id, int res)1317 * \brief Set Cylinder capping 1318 */ 1319 void Renderer::setCylinderCapping(const DataSetId& id, bool state) 1140 1320 { 1141 1321 CylinderHashmap::iterator itr; … … 1157 1337 1158 1338 do { 1339 itr->second->setCapping(state); 1340 } while (doAll && ++itr != _cylinders.end()); 1341 1342 sceneBoundsChanged(); 1343 _needsRedraw = true; 1344 } 1345 1346 /** 1347 * \brief Set Cylinder resolution 1348 */ 1349 void Renderer::setCylinderResolution(const DataSetId& id, int res) 1350 { 1351 CylinderHashmap::iterator itr; 1352 1353 bool doAll = false; 1354 1355 if (id.compare("all") == 0) { 1356 itr = _cylinders.begin(); 1357 if (itr == _cylinders.end()) 1358 return; 1359 doAll = true; 1360 } else { 1361 itr = _cylinders.find(id); 1362 } 1363 if (itr == _cylinders.end()) { 1364 ERROR("Cylinder not found: %s", id.c_str()); 1365 return; 1366 } 1367 1368 do { 1159 1369 itr->second->setResolution(res); 1160 1370 } while (doAll && ++itr != _cylinders.end()); … … 1167 1377 * \brief Create a new Disk and associate it with an ID 1168 1378 */ 1169 bool Renderer::addDisk(const DataSetId& id, double innerRadius, double outerRadius) 1379 bool Renderer::addDisk(const DataSetId& id, 1380 double innerRadius, 1381 double outerRadius, 1382 bool flipNormals) 1170 1383 { 1171 1384 Disk *gobj; … … 1191 1404 1192 1405 gobj->setRadii(innerRadius, outerRadius); 1406 if (flipNormals) 1407 gobj->flipNormals(flipNormals); 1193 1408 1194 1409 getGraphicsObjectHashmap<Disk>()[id] = gobj; … … 1462 1677 } 1463 1678 1679 bool Renderer::addGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList) 1680 { 1681 if (id.compare("all") == 0) { 1682 addChildrenToGroup(id, nodeList); 1683 return true; 1684 } 1685 1686 Group *gobj; 1687 if ((gobj = getGraphicsObject<Group>(id)) != NULL) { 1688 // Group exists, so add nodes to it 1689 addChildrenToGroup(id, nodeList); 1690 return true; 1691 } 1692 1693 gobj = new Group(); 1694 1695 gobj->setDataSet(NULL, this); 1696 1697 if (gobj->getProp() == NULL && 1698 gobj->getOverlayProp() == NULL) { 1699 delete gobj; 1700 return false; 1701 } else { 1702 if (gobj->getProp()) 1703 _renderer->AddViewProp(gobj->getProp()); 1704 if (gobj->getOverlayProp()) 1705 _renderer->AddViewProp(gobj->getOverlayProp()); 1706 } 1707 1708 for (std::vector<Group::NodeId>::const_iterator itr = nodeList.begin(); 1709 itr != nodeList.end(); ++itr) { 1710 GraphicsObject *node = getGenericGraphicsObject(*itr); 1711 if (node != NULL) { 1712 if (node->getProp()) 1713 _renderer->RemoveViewProp(node->getProp()); 1714 if (node->getOverlayProp()) 1715 _renderer->RemoveViewProp(node->getOverlayProp()); 1716 gobj->addChild(*itr, node); 1717 } else { 1718 ERROR("Can't find node: %s", itr->c_str()); 1719 } 1720 } 1721 1722 getGraphicsObjectHashmap<Group>()[id] = gobj; 1723 1724 sceneBoundsChanged(); 1725 _needsRedraw = true; 1726 return true; 1727 } 1728 1729 void Renderer::addChildrenToGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList) 1730 { 1731 GroupHashmap::iterator itr; 1732 1733 bool doAll = false; 1734 1735 if (id.compare("all") == 0) { 1736 itr = _groups.begin(); 1737 if (itr == _groups.end()) 1738 return; 1739 doAll = true; 1740 } else { 1741 itr = _groups.find(id); 1742 } 1743 1744 if (itr == _groups.end()) { 1745 ERROR("Group not found: %s", id.c_str()); 1746 return; 1747 } 1748 1749 do { 1750 for (std::vector<Group::NodeId>::const_iterator citr = nodeList.begin(); 1751 citr != nodeList.end(); ++citr) { 1752 GraphicsObject *node = getGenericGraphicsObject(*citr); 1753 if (node != NULL) { 1754 if (node->getProp()) 1755 _renderer->RemoveViewProp(node->getProp()); 1756 if (node->getOverlayProp()) 1757 _renderer->RemoveViewProp(node->getOverlayProp()); 1758 itr->second->addChild(*citr, node); 1759 } else { 1760 ERROR("Can't find node: %s", citr->c_str()); 1761 } 1762 } 1763 } while (doAll && ++itr != _groups.end()); 1764 1765 sceneBoundsChanged(); 1766 _needsRedraw = true; 1767 } 1768 1769 void Renderer::removeChildrenFromGroup(const DataSetId& id, const std::vector<Group::NodeId>& nodeList) 1770 { 1771 GroupHashmap::iterator itr; 1772 1773 bool doAll = false; 1774 1775 if (id.compare("all") == 0) { 1776 itr = _groups.begin(); 1777 if (itr == _groups.end()) 1778 return; 1779 doAll = true; 1780 } else { 1781 itr = _groups.find(id); 1782 } 1783 1784 if (itr == _groups.end()) { 1785 ERROR("Group not found: %s", id.c_str()); 1786 return; 1787 } 1788 1789 do { 1790 for (std::vector<Group::NodeId>::const_iterator citr = nodeList.begin(); 1791 citr != nodeList.end(); ++citr) { 1792 GraphicsObject *node = getGenericGraphicsObject(*citr); 1793 if (node != NULL) { 1794 if (node->getProp()) 1795 _renderer->AddViewProp(node->getProp()); 1796 if (node->getOverlayProp()) 1797 _renderer->AddViewProp(node->getOverlayProp()); 1798 assert(node == itr->second->removeChild(*citr)); 1799 } else { 1800 ERROR("Can't find node: %s", citr->c_str()); 1801 } 1802 } 1803 } while (doAll && ++itr != _groups.end()); 1804 1805 sceneBoundsChanged(); 1806 _needsRedraw = true; 1807 } 1808 1464 1809 /** 1465 1810 * \brief Create a new HeightMap and associate it with the named DataSet … … 2286 2631 * \brief Create a new n-sided regular Polygon and associate it with an ID 2287 2632 */ 2288 bool Renderer::addPolygon(const DataSetId& id, int numSides) 2633 bool Renderer::addPolygon(const DataSetId& id, int numSides, 2634 double center[3], double normal[3], double radius) 2289 2635 { 2290 2636 Polygon *gobj; … … 2310 2656 2311 2657 gobj->setNumberOfSides(numSides); 2658 gobj->setCenter(center); 2659 gobj->setNormal(normal); 2660 gobj->setRadius(radius); 2312 2661 2313 2662 getGraphicsObjectHashmap<Polygon>()[id] = gobj; … … 2439 2788 2440 2789 _needsRedraw = true; 2790 } 2791 2792 /** 2793 * \brief Create a new Sphere and associate it with an ID 2794 */ 2795 bool Renderer::addSphere(const DataSetId& id, double center[3], double radius, bool flipNormals) 2796 { 2797 Sphere *gobj; 2798 if ((gobj = getGraphicsObject<Sphere>(id)) != NULL) { 2799 WARN("Replacing existing %s %s", gobj->getClassName(), id.c_str()); 2800 deleteGraphicsObject<Sphere>(id); 2801 } 2802 2803 gobj = new Sphere(); 2804 2805 gobj->setDataSet(NULL, this); 2806 2807 if (gobj->getProp() == NULL && 2808 gobj->getOverlayProp() == NULL) { 2809 delete gobj; 2810 return false; 2811 } else { 2812 if (gobj->getProp()) 2813 _renderer->AddViewProp(gobj->getProp()); 2814 if (gobj->getOverlayProp()) 2815 _renderer->AddViewProp(gobj->getOverlayProp()); 2816 } 2817 2818 gobj->setCenter(center); 2819 gobj->setRadius(radius); 2820 if (flipNormals) 2821 gobj->flipNormals(flipNormals); 2822 2823 getGraphicsObjectHashmap<Sphere>()[id] = gobj; 2824 2825 sceneBoundsChanged(); 2826 _needsRedraw = true; 2827 return true; 2441 2828 } 2442 2829 -
trunk/packages/vizservers/vtkvis/RendererGraphicsObjs.h
r3621 r3683 277 277 278 278 /** 279 * \brief Set the prop origin (center of rotation) 280 */ 281 template<class T> 282 void Renderer::setGraphicsObjectOrigin(const DataSetId& id, double origin[3]) 283 { 284 std::tr1::unordered_map<DataSetId, T *>& hashmap = 285 getGraphicsObjectHashmap<T>(); 286 typename std::tr1::unordered_map<DataSetId, T *>::iterator itr; 287 288 bool doAll = false; 289 290 if (id.compare("all") == 0) { 291 itr = hashmap.begin(); 292 if (itr == hashmap.end()) 293 return; 294 doAll = true; 295 } else { 296 itr = hashmap.find(id); 297 } 298 if (itr == hashmap.end()) { 299 GO_ERROR(T, "not found: %s", id.c_str()); 300 return; 301 } 302 303 do { 304 itr->second->setOrigin(origin); 305 } while (doAll && ++itr != hashmap.end()); 306 307 sceneBoundsChanged(); 308 _needsRedraw = true; 309 } 310 311 /** 279 312 * \brief Set the prop position in world coords 280 313 */ … … 479 512 480 513 /** 514 * \brief Set cull face for graphics object 515 */ 516 template<class T> 517 void Renderer::setGraphicsObjectCullFace(const DataSetId& id, 518 GraphicsObject::CullFace state) 519 { 520 std::tr1::unordered_map<DataSetId, T *>& hashmap = 521 getGraphicsObjectHashmap<T>(); 522 typename std::tr1::unordered_map<DataSetId, T *>::iterator itr; 523 524 bool doAll = false; 525 526 if (id.compare("all") == 0) { 527 itr = hashmap.begin(); 528 if (itr == hashmap.end()) 529 return; 530 doAll = true; 531 } else { 532 itr = hashmap.find(id); 533 } 534 535 if (itr == hashmap.end()) { 536 GO_ERROR(T, "not found: %s", id.c_str()); 537 return; 538 } 539 540 do { 541 itr->second->setCullFace(state); 542 } while (doAll && ++itr != hashmap.end()); 543 544 _needsRedraw = true; 545 } 546 547 /** 548 * \brief Set face culling for graphics object 549 */ 550 template<class T> 551 void Renderer::setGraphicsObjectCulling(const DataSetId& id, bool state) 552 { 553 std::tr1::unordered_map<DataSetId, T *>& hashmap = 554 getGraphicsObjectHashmap<T>(); 555 typename std::tr1::unordered_map<DataSetId, T *>::iterator itr; 556 557 bool doAll = false; 558 559 if (id.compare("all") == 0) { 560 itr = hashmap.begin(); 561 if (itr == hashmap.end()) 562 return; 563 doAll = true; 564 } else { 565 itr = hashmap.find(id); 566 } 567 568 if (itr == hashmap.end()) { 569 GO_ERROR(T, "not found: %s", id.c_str()); 570 return; 571 } 572 573 do { 574 itr->second->setCulling(state); 575 } while (doAll && ++itr != hashmap.end()); 576 577 _needsRedraw = true; 578 } 579 580 /** 481 581 * \brief Turn on/off edges for the given DataSet 482 582 */ … … 580 680 581 681 /** 682 * \brief Flip normals and front/back faces of the shape geometry 683 */ 684 template<class T> 685 void Renderer::setGraphicsObjectFlipNormals(const DataSetId& id, bool state) 686 { 687 std::tr1::unordered_map<DataSetId, T *>& hashmap = 688 getGraphicsObjectHashmap<T>(); 689 typename std::tr1::unordered_map<DataSetId, T *>::iterator itr; 690 691 bool doAll = false; 692 693 if (id.compare("all") == 0) { 694 itr = hashmap.begin(); 695 if (itr == hashmap.end()) 696 return; 697 doAll = true; 698 } else { 699 itr = hashmap.find(id); 700 } 701 if (itr == hashmap.end()) { 702 GO_ERROR(T, "not found: %s", id.c_str()); 703 return; 704 } 705 706 do { 707 itr->second->flipNormals(state); 708 } while (doAll && ++itr != hashmap.end()); 709 710 _needsRedraw = true; 711 } 712 713 /** 582 714 * \brief Set ambient lighting/shading coefficient for the specified DataSet 583 715 */ … … 638 770 do { 639 771 itr->second->setDiffuse(coeff); 772 } while (doAll && ++itr != hashmap.end()); 773 774 _needsRedraw = true; 775 } 776 777 /** 778 * \brief Set the shading of the object (flat or smooth) 779 * 780 * Currently Phong shading is not implemented 781 */ 782 template<class T> 783 void Renderer::setGraphicsObjectShadingModel(const DataSetId& id, 784 GraphicsObject::ShadingModel state) 785 { 786 std::tr1::unordered_map<DataSetId, T *>& hashmap = 787 getGraphicsObjectHashmap<T>(); 788 typename std::tr1::unordered_map<DataSetId, T *>::iterator itr; 789 790 bool doAll = false; 791 792 if (id.compare("all") == 0) { 793 itr = hashmap.begin(); 794 if (itr == hashmap.end()) 795 return; 796 doAll = true; 797 } else { 798 itr = hashmap.find(id); 799 } 800 if (itr == hashmap.end()) { 801 GO_ERROR(T, "not found: %s", id.c_str()); 802 return; 803 } 804 805 do { 806 itr->second->setShadingModel(state); 640 807 } while (doAll && ++itr != hashmap.end()); 641 808 -
trunk/packages/vizservers/vtkvis/Sphere.cpp
r3616 r3683 15 15 #include <vtkTransform.h> 16 16 #include <vtkSphereSource.h> 17 #include <vtkReverseSense.h> 17 18 18 19 #include "Sphere.h" … … 50 51 _pdMapper->Update(); 51 52 } 53 54 void Sphere::flipNormals(bool state) 55 { 56 if (_sphere == NULL || _pdMapper == NULL) 57 return; 58 59 if (state) { 60 vtkSmartPointer<vtkReverseSense> filter = vtkSmartPointer<vtkReverseSense>::New(); 61 filter->ReverseCellsOn(); 62 filter->ReverseNormalsOn(); 63 filter->SetInputConnection(_sphere->GetOutputPort()); 64 65 _pdMapper->SetInputConnection(filter->GetOutputPort()); 66 } else { 67 _pdMapper->SetInputConnection(_sphere->GetOutputPort()); 68 } 69 } -
trunk/packages/vizservers/vtkvis/Sphere.h
r3621 r3683 77 77 } 78 78 79 void setCenter(double center[3]) 80 { 81 if (_sphere != NULL) 82 _sphere->SetCenter(center); 83 } 84 79 85 void setRadius(double radius) 80 86 { … … 82 88 _sphere->SetRadius(radius); 83 89 } 90 91 void flipNormals(bool state); 84 92 85 93 private: -
trunk/packages/vizservers/vtkvis/protocol.txt
r3682 r3683 248 248 Toggle use of two-sided lighting (controls if backfaces are lit with a 249 249 flipped normal) 250 renderer lights <lightNum> <bool> 251 Toggle lights on/off. Light 0 is the headlight, light 1 the skylight 250 252 renderer render 251 253 Force a new image to be rendered - use for advancing animation … … 256 258 == Graphics objects == 257 259 258 arc add < pt1X> <pt1Y> <pt1Z> <pt2X> <pt2Y> <pt2Z> <name>260 arc add <centerX> <centerY> <centerZ> <pt1X> <pt1Y> <pt1Z> <pt2X> <pt2Y> <pt2Z> <name> 259 261 arc color <r> <g> <b> <?name?> 260 262 arc delete <?name?> … … 263 265 arc opacity <val> <?name?> 264 266 arc orient <qw> <qx> <qy> <qz> <?name?> 267 arc origin <x> <y> <z> <?name?> 265 268 arc pos <x> <y> <z> <?name?> 266 269 arc resolution <res> <?name?> … … 271 274 Arrow will have base at 0,0,0 and tip at 1, 0, 0 272 275 arrow color <r> <g> <b> <?name?> 276 arrow culling <bool> <?name?> 273 277 arrow delete <?name?> 274 278 arrow edges <bool> <?name?> 279 arrow flipnorm <bool> <?name?> 275 280 arrow lighting <bool> <?name?> 276 281 arrow linecolor <r> <g> <b> <?name?> … … 279 284 arrow opacity <val> <?name?> 280 285 arrow orient <qw> <qx> <qy> <qz> <?name?> 286 arrow origin <x> <y> <z> <?name?> 281 287 arrow pos <x> <y> <z> <?name?> 282 288 arrow resolution <tipRes> <shaftRes> <?name?> 283 289 arrow scale <sx> <sy> <sz> <?name?> 290 arrow shading <val> <?name?> 291 val = flat|smooth 284 292 arrow visible <bool> <?name?> 285 293 arrow wireframe <bool> <?name?> 286 294 287 box add < name>295 box add <xLen> <yLen> <zLen> <name> 288 296 box color <r> <g> <b> <?name?> 297 box culling <bool> <?name?> 289 298 box delete <?name?> 290 299 box edges <bool> <?name?> 300 box flipnorm <bool> <?name?> 291 301 box lighting <bool> <?name?> 292 302 box linecolor <r> <g> <b> <?name?> … … 295 305 box opacity <val> <?name?> 296 306 box orient <qw> <qx> <qy> <qz> <?name?> 307 box origin <x> <y> <z> <?name?> 297 308 box pos <x> <y> <z> <?name?> 298 309 box scale <sx> <sy> <sz> <?name?> 310 box shading <val> <?name?> 311 val = flat|smooth 299 312 box visible <bool> <?name?> 300 313 box wireframe <bool> <?name?> … … 303 316 <cap> = boolean flag for cap disks 304 317 cone color <r> <g> <b> <?name?> 318 cone culling <bool> <?name?> 305 319 cone delete <?name?> 306 320 cone edges <bool> <?name?> 321 cone flipnorm <bool> <?name?> 307 322 cone lighting <bool> <?name?> 308 323 cone linecolor <r> <g> <b> <?name?> … … 311 326 cone opacity <val> <?name?> 312 327 cone orient <qw> <qx> <qy> <qz> <?name?> 328 cone origin <x> <y> <z> <?name?> 313 329 cone pos <x> <y> <z> <?name?> 314 330 cone resolution <res> <?name?> 315 331 cone scale <sx> <sy> <sz> <?name?> 332 cone shading <val> <?name?> 333 val = flat|smooth 316 334 cone visible <bool> <?name?> 317 335 cone wireframe <bool> <?name?> … … 409 427 <cap> = boolean flag for cap disks 410 428 cylinder color <r> <g> <b> <?name?> 429 cylinder culling <bool> <?name?> 411 430 cylinder delete <?name?> 412 431 cylinder edges <bool> <?name?> 432 cylinder flipnorm <bool> <?name?> 413 433 cylinder lighting <bool> <?name?> 414 434 cylinder linecolor <r> <g> <b> <?name?> … … 417 437 cylinder opacity <val> <?name?> 418 438 cylinder orient <qw> <qx> <qy> <qz> <?name?> 439 cylinder origin <x> <y> <z> <?name?> 419 440 cylinder pos <x> <y> <z> <?name?> 420 441 cylinder resolution <res> <?name?> 421 442 cylinder scale <sx> <sy> <sz> <?name?> 443 cylinder shading <val> <?name?> 444 val = flat|smooth 422 445 cylinder visible <bool> <?name?> 423 446 cylinder wireframe <bool> <?name?> … … 425 448 disk add <innerRadius> <outerRadius> <name> 426 449 disk color <r> <g> <b> <?name?> 450 disk culling <bool> <?name?> 427 451 disk delete <?name?> 428 452 disk edges <bool> <?name?> 453 disk flipnorm <bool> <?name?> 429 454 disk lighting <bool> <?name?> 430 455 disk linecolor <r> <g> <b> <?name?> … … 433 458 disk opacity <val> <?name?> 434 459 disk orient <qw> <qx> <qy> <qz> <?name?> 460 disk origin <x> <y> <z> <?name?> 435 461 disk pos <x> <y> <z> <?name?> 436 462 disk resolution <resRadial> <resCircum> <?name?> 437 463 disk scale <sx> <sy> <sz> <?name?> 464 disk shading <val> <?name?> 465 val = flat|smooth 438 466 disk visible <bool> <?name?> 439 467 disk wireframe <bool> <?name?> … … 471 499 glyphs visible <bool> <?datasetName?> 472 500 glyphs wireframe <bool> <?datasetName?> 501 502 group add <nodeList> <name> 503 group delete <?name?> 504 group orient <qw> <qx> <qy> <qz> <?name?> 505 group origin <x> <y> <z> <?name?> 506 group pos <x> <y> <z> <?name?> 507 group remove <nodeList> <name> 508 group scale <sx> <sy> <sz> <?name?> 509 group visible <bool> <?name?> 473 510 474 511 heightmap add numcontours <n> <heightScale> <?dataSetName?> … … 548 585 line opacity <val> <?name?> 549 586 line orient <qw> <qx> <qy> <qz> <?name?> 587 line origin <x> <y> <z> <?name?> 550 588 line pos <x> <y> <z> <?name?> 551 589 line scale <sx> <sy> <sz> <?name?> … … 610 648 <style> = mesh | points 611 649 polydata color <r> <g> <b> <?datasetName?> 650 polydata culling <bool> <?name?> 612 651 polydata delete <?datasetName?> 613 652 polydata edges <bool> <?datasetName?> … … 618 657 polydata opacity <val> <?datasetName?> 619 658 polydata orient <qw> <qx> <qy> <qz> <?dataSetName?> 659 polydata origin <x> <y> <z> <?name?> 620 660 polydata pos <x> <y> <z> <?dataSetName?> 621 661 polydata ptsize <size> <?dataSetName?> 622 662 polydata scale <sx> <sy> <sz> <?dataSetName?> 663 polydata shading <val> <?name?> 664 val = flat|smooth 623 665 polydata visible <bool> <?datasetName?> 624 666 polydata wireframe <bool> <?datasetName?> 625 667 626 polygon add <numSides> < name>668 polygon add <numSides> <centerX> <centerY> <centerZ> <normX> <normY> <normZ> <radius> <name> 627 669 polygon color <r> <g> <b> <?name?> 670 polygon culling <bool> <?name?> 628 671 polygon delete <?name?> 629 672 polygon edges <bool> <?name?> 673 polygon flipnorm <bool> <?name?> 630 674 polygon lighting <bool> <?name?> 631 675 polygon linecolor <r> <g> <b> <?name?> … … 634 678 polygon opacity <val> <?name?> 635 679 polygon orient <qw> <qx> <qy> <qz> <?name?> 680 polygon origin <x> <y> <z> <?name?> 636 681 polygon pos <x> <y> <z> <?name?> 637 682 polygon scale <sx> <sy> <sz> <?name?> 683 polygon shading <val> <?name?> 684 val = flat|smooth 638 685 polygon visible <bool> <?name?> 639 686 polygon wireframe <bool> <?name?> … … 668 715 pseudocolor wireframe <bool> <?datasetName?> 669 716 670 sphere add < name>717 sphere add <centerX> <centerY> <centerZ> <radius> <name> 671 718 sphere color <r> <g> <b> <?name?> 719 sphere culling <bool> <?name?> 672 720 sphere delete <?name?> 673 721 sphere edges <bool> <?name?> 722 sphere flipnorm <bool> <?name?> 674 723 sphere lighting <bool> <?name?> 675 724 sphere linecolor <r> <g> <b> <?name?> … … 678 727 sphere opacity <val> <?name?> 679 728 sphere orient <qw> <qx> <qy> <qz> <?name?> 729 sphere origin <x> <y> <z> <?name?> 680 730 sphere pos <x> <y> <z> <?name?> 681 731 sphere resolution <thetaRes> <phiRes> <?name?> … … 683 733 sphere section <thetaStart> <thetaEnd> <phiStart> <phiEnd> <?name?> 684 734 Angles are in degrees 735 sphere shading <val> <?name?> 736 val = flat|smooth 685 737 sphere visible <bool> <?name?> 686 738 sphere wireframe <bool> <?name?> … … 785 837 warp pos <x> <y> <z> <?dataSetName?> 786 838 warp preinterp <bool> <?dataSetName?> 787 ontrols if VTK's InterpolateScalarsBeforeMapping option is set.839 Controls if VTK's InterpolateScalarsBeforeMapping option is set. 788 840 Setting this on will give more correct colors, as the interpolation 789 841 is done on texture coordinates that lookup into a 1D texture instead
Note: See TracChangeset
for help on using the changeset viewer.