- Timestamp:
- Feb 28, 2011, 2:57:29 AM (13 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/Makefile.in
r2107 r2112 62 62 SERVER_SRCS = \ 63 63 CmdProc.cpp \ 64 ColorMap.cpp \ 64 65 PPMWriter.cpp \ 65 66 RpContour2D.cpp \ 67 RpPolyData.cpp \ 66 68 RpPseudoColor.cpp \ 67 69 RpVtkDataSet.cpp \ … … 100 102 $(RM) *~ *.o $(SERVER) 101 103 102 clean-doc :104 clean-docs: 103 105 $(RM) -r docs 104 106 105 distclean: clean clean-doc 106 $(RM) Makefile 107 distclean: clean clean-docs 108 $(RM) Makefile Doxyfile 107 109 108 110 CmdProc.o: CmdProc.h 111 ColorMap.o: ColorMap.h Trace.h 109 112 PPMWriter.o: PPMWriter.h Trace.h 110 RpContour2D.o: RpContour2D.h RpVtkDataSet.h 111 RpPseudoColor.o: RpPseudoColor.h RpVtkDataSet.h 112 RpVtkDataSet.o: RpVtkDataSet.h 113 RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpPseudoColor.h RpContour2D.h 114 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpPseudoColor.h RpContour2D.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h 113 RpContour2D.o: RpContour2D.h RpVtkDataSet.h Trace.h 114 RpPolyData.o: RpPolyData.h RpVtkDataSet.h Trace.h 115 RpPseudoColor.o: RpPseudoColor.h RpVtkDataSet.h Trace.h 116 RpVtkDataSet.o: RpVtkDataSet.h Trace.h 117 RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpPolyData.h RpPseudoColor.h RpContour2D.h ColorMap.h Trace.h 118 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpPseudoColor.h RpContour2D.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h ColorMap.h 115 119 RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRenderer.h RpVtkDataSet.h RpPseudoColor.h RpContour2D.h Trace.h 116 120 Trace.o: Trace.h 117 121 TGAWriter.o: TGAWriter.h Trace.h 118 contourPlotter.o: RpVtkRenderer.h119 122 vtkRpCubeAxesActor2D.o: vtkRpCubeAxesActor2D.h -
trunk/packages/vizservers/vtkvis/RpContour2D.cpp
r2100 r2112 140 140 141 141 /** 142 * \brief Get visibility state of the contour set 143 * 144 * \return Is contour set visible? 145 */ 146 bool Contour2D::getVisibility() 147 { 148 if (_contourActor == NULL) { 149 return false; 150 } else { 151 return (_contourActor->GetVisibility() != 0); 152 } 153 } 154 155 /** 142 156 * \brief Set opacity used to render contour lines 143 157 */ … … 173 187 /** 174 188 * \brief Set a group of world coordinate planes to clip rendering 189 * 190 * Passing NULL for planes will remove all cliping planes 175 191 */ 176 192 void Contour2D::setClippingPlanes(vtkPlaneCollection *planes) 177 193 { 178 if (_contourMapper != NULL) 179 _contourMapper->SetClippingPlanes(planes); 180 } 194 if (_contourMapper != NULL) { 195 if (planes == NULL) 196 _contourMapper->RemoveAllClippingPlanes(); 197 else 198 _contourMapper->SetClippingPlanes(planes); 199 } 200 } -
trunk/packages/vizservers/vtkvis/RpContour2D.h
r2100 r2112 39 39 void setVisibility(bool state); 40 40 41 bool getVisibility(); 42 41 43 void setOpacity(double opacity); 42 44 -
trunk/packages/vizservers/vtkvis/RpPseudoColor.cpp
r2100 r2112 19 19 PseudoColor::PseudoColor() : 20 20 _dataSet(NULL), 21 _opacity(1.0) 22 { 21 _opacity(1.0), 22 _edgeWidth(1.0) 23 { 24 _edgeColor[0] = 0.0; 25 _edgeColor[1] = 0.0; 26 _edgeColor[2] = 0.0; 23 27 } 24 28 … … 58 62 _dsMapper->StaticOff(); 59 63 60 vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable(); 61 TRACE("Data set scalars lookup table: %p\n", lut); 62 if (_lut == NULL) { 63 if (lut) 64 _lut = lut; 65 else 64 if (ds->GetPointData() == NULL || 65 ds->GetPointData()->GetScalars() == NULL) { 66 ERROR("No scalar point data in dataset %s", _dataSet->getName().c_str()); 67 if (_lut == NULL) { 66 68 _lut = vtkSmartPointer<vtkLookupTable>::New(); 69 } 67 70 } else { 68 69 } 71 vtkLookupTable *lut = ds->GetPointData()->GetScalars()->GetLookupTable(); 72 TRACE("Data set scalars lookup table: %p\n", lut); 73 if (_lut == NULL) { 74 if (lut) 75 _lut = lut; 76 else 77 _lut = vtkSmartPointer<vtkLookupTable>::New(); 78 } 79 } 80 70 81 _lut->SetRange(dataRange); 71 82 … … 81 92 82 93 /** 83 * \brief Get the VTK Actor for the colormap iamge94 * \brief Get the VTK Actor for the colormapped dataset 84 95 */ 85 96 vtkActor *PseudoColor::getActor() … … 89 100 90 101 /** 91 * \brief Create and initialize a VTK actor to render the colormap image102 * \brief Create and initialize a VTK actor to render the colormapped dataset 92 103 */ 93 104 void PseudoColor::initActor() … … 96 107 _dsActor = vtkSmartPointer<vtkActor>::New(); 97 108 _dsActor->GetProperty()->SetOpacity(_opacity); 109 _dsActor->GetProperty()->SetEdgeColor(_edgeColor[0], _edgeColor[1], _edgeColor[2]); 110 _dsActor->GetProperty()->SetLineWidth(_edgeWidth); 111 _dsActor->GetProperty()->EdgeVisibilityOff(); 98 112 } 99 113 } … … 118 132 } 119 133 134 double dataRange[2]; 120 135 if (_dataSet != NULL) { 121 double dataRange[2];122 136 _dataSet->getDataRange(dataRange); 123 137 _lut->SetRange(dataRange); 124 125 if (_dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable()) { 138 #ifdef notdef 139 if (_dataSet->getVtkDataSet()->GetPointData() && 140 _dataSet->getVtkDataSet()->GetPointData()->GetScalars() && 141 _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable()) { 126 142 TRACE("Change scalar table: %p %p\n", 127 143 _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable(), … … 130 146 TRACE("Scalar Table: %p\n", _dataSet->getVtkDataSet()->GetPointData()->GetScalars()->GetLookupTable()); 131 147 } 148 #endif 132 149 } 133 150 if (_dsMapper != NULL) { 134 151 _dsMapper->SetLookupTable(_lut); 135 } 136 } 137 138 /** 139 * \brief Turn on/off rendering of this colormap image 152 if (_dataSet != NULL) { 153 _dsMapper->SetScalarRange(dataRange); 154 } 155 } 156 } 157 158 /** 159 * \brief Turn on/off rendering of this colormapped dataset 140 160 */ 141 161 void PseudoColor::setVisibility(bool state) … … 147 167 148 168 /** 149 * \brief Set opacity used to render the colormap image 169 * \brief Get visibility state of the colormapped dataset 170 * 171 * \return Is PseudoColor visible? 172 */ 173 bool PseudoColor::getVisibility() 174 { 175 if (_dsActor == NULL) { 176 return false; 177 } else { 178 return (_dsActor->GetVisibility() != 0); 179 } 180 } 181 182 /** 183 * \brief Set opacity used to render the colormapped dataset 150 184 */ 151 185 void PseudoColor::setOpacity(double opacity) … … 157 191 158 192 /** 193 * \brief Turn on/off rendering of mesh edges 194 */ 195 void PseudoColor::setEdgeVisibility(bool state) 196 { 197 if (_dsActor != NULL) { 198 _dsActor->GetProperty()->SetEdgeVisibility((state ? 1 : 0)); 199 } 200 } 201 202 /** 203 * \brief Set RGB color of polygon edges 204 */ 205 void PseudoColor::setEdgeColor(float color[3]) 206 { 207 _edgeColor[0] = color[0]; 208 _edgeColor[1] = color[1]; 209 _edgeColor[2] = color[2]; 210 if (_dsActor != NULL) 211 _dsActor->GetProperty()->SetEdgeColor(_edgeColor[0], _edgeColor[1], _edgeColor[2]); 212 } 213 214 /** 215 * \brief Set pixel width of polygon edges (may be a no-op) 216 */ 217 void PseudoColor::setEdgeWidth(float edgeWidth) 218 { 219 _edgeWidth = edgeWidth; 220 if (_dsActor != NULL) 221 _dsActor->GetProperty()->SetLineWidth(_edgeWidth); 222 } 223 224 /** 159 225 * \brief Set a group of world coordinate planes to clip rendering 226 * 227 * Passing NULL for planes will remove all cliping planes 160 228 */ 161 229 void PseudoColor::setClippingPlanes(vtkPlaneCollection *planes) 162 230 { 163 if (_dsMapper != NULL) 164 _dsMapper->SetClippingPlanes(planes); 165 } 231 if (_dsMapper != NULL) { 232 if (planes == NULL) 233 _dsMapper->RemoveAllClippingPlanes(); 234 else 235 _dsMapper->SetClippingPlanes(planes); 236 } 237 } -
trunk/packages/vizservers/vtkvis/RpPseudoColor.h
r2100 r2112 40 40 void setVisibility(bool state); 41 41 42 bool getVisibility(); 43 42 44 void setOpacity(double opacity); 45 46 void setEdgeVisibility(bool state); 47 48 void setEdgeColor(float color[3]); 49 50 void setEdgeWidth(float edgeWidth); 43 51 44 52 void setClippingPlanes(vtkPlaneCollection *planes); … … 51 59 52 60 double _opacity; 61 float _edgeColor[3]; 62 float _edgeWidth; 53 63 vtkSmartPointer<vtkLookupTable> _lut; 54 64 vtkSmartPointer<vtkDataSetMapper> _dsMapper; -
trunk/packages/vizservers/vtkvis/RpVtkDataSet.cpp
r2100 r2112 18 18 using namespace Rappture::VtkVis; 19 19 20 DataSet::DataSet( )20 DataSet::DataSet(const std::string& name) 21 21 { 22 _name = name; 22 23 _dataRange[0] = 0.0; 23 24 _dataRange[1] = 1.0; … … 52 53 } 53 54 55 /** 56 * \brief Read dataset using supplied reader 57 */ 54 58 bool DataSet::setData(vtkDataSetReader *reader) 55 59 { … … 62 66 TRACE("Scalar Range: %.12e, %.12e", _dataRange[0], _dataRange[1]); 63 67 return true; 68 } 69 70 /** 71 * \brief Get the name/id of this dataset 72 */ 73 const std::string& DataSet::getName() 74 { 75 return _name; 64 76 } 65 77 -
trunk/packages/vizservers/vtkvis/RpVtkDataSet.h
r2100 r2112 13 13 #include <vtkDataSetReader.h> 14 14 15 #include <string> 15 16 #include <vector> 16 17 … … 23 24 class DataSet { 24 25 public: 25 DataSet( );26 DataSet(const std::string& name); 26 27 virtual ~DataSet(); 27 28 … … 29 30 30 31 bool setDataFile(const char *filename); 32 33 const std::string& getName(); 31 34 32 35 vtkDataSet *getVtkDataSet(); … … 37 40 38 41 private: 42 DataSet(); 43 39 44 bool setData(vtkDataSetReader *reader); 40 45 46 std::string _name; 41 47 vtkSmartPointer<vtkDataSet> _dataSet; 42 48 double _dataRange[2]; -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp
r2100 r2112 6 6 */ 7 7 8 #include <cfloat> 9 8 10 #include <vtkCamera.h> 9 11 #include <vtkCoordinate.h> 12 #include <vtkTransform.h> 10 13 #include <vtkCharArray.h> 11 14 #include <vtkAxisActor2D.h> … … 13 16 #include <vtkRpCubeAxesActor2D.h> 14 17 #else 18 #include <vtkCubeAxesActor.h> 15 19 #include <vtkCubeAxesActor2D.h> 16 20 #endif … … 30 34 31 35 Renderer::Renderer() : 32 _needsRedraw( false),36 _needsRedraw(true), 33 37 _windowWidth(320), 34 38 _windowHeight(320) … … 60 64 _clippingPlanes->AddItem(plane3); 61 65 _renderer = vtkSmartPointer<vtkRenderer>::New(); 62 initAxes(); 66 _renderer->LightFollowCameraOn(); 67 storeCameraOrientation(); 68 _cameraMode = PERSPECTIVE; 69 initAxes(); 70 initCamera(); 63 71 _renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); 64 72 _renderWindow->DoubleBufferOff(); … … 67 75 _renderWindow->OffScreenRenderingOn(); 68 76 _renderWindow->AddRenderer(_renderer); 69 addColorMap("default", vtkLookupTable::New());77 addColorMap("default", ColorMap::createDefault()); 70 78 } 71 79 72 80 Renderer::~Renderer() 73 81 { 82 for (ColorMapHashmap::iterator itr = _colorMaps.begin(); 83 itr != _colorMaps.end(); ++itr) { 84 delete itr->second; 85 } 86 _colorMaps.clear(); 74 87 for (DataSetHashmap::iterator itr = _dataSets.begin(); 75 88 itr != _dataSets.end(); ++itr) { … … 87 100 } 88 101 _contours.clear(); 102 for (PolyDataHashmap::iterator itr = _polyDatas.begin(); 103 itr != _polyDatas.end(); ++itr) { 104 delete itr->second; 105 } 106 _polyDatas.clear(); 89 107 } 90 108 … … 98 116 void Renderer::addDataSet(DataSetId id) 99 117 { 100 _dataSets[id] = new DataSet; 118 if (getDataSet(id) != NULL) { 119 WARN("Replacing existing dataset %s", id.c_str()); 120 deleteDataSet(id); 121 } 122 _dataSets[id] = new DataSet(id); 101 123 } 102 124 … … 109 131 { 110 132 PseudoColorHashmap::iterator itr = _pseudoColors.find(id); 111 if (itr == _pseudoColors.end()) 133 if (itr == _pseudoColors.end()) { 134 ERROR("PseudoColor not found: %s", id.c_str()); 112 135 return; 136 } 137 138 TRACE("Deleting PseudoColors for %s", id.c_str()); 113 139 114 140 PseudoColor *ps = itr->second; … … 129 155 { 130 156 Contour2DHashmap::iterator itr = _contours.find(id); 131 if (itr == _contours.end()) 157 if (itr == _contours.end()) { 158 ERROR("Contour2D not found: %s", id.c_str()); 132 159 return; 160 } 161 162 TRACE("Deleting Contour2Ds for %s", id.c_str()); 133 163 134 164 Contour2D *contour = itr->second; … … 142 172 143 173 /** 174 * \brief Remove the PolyData mesh for the specified DataSet 175 * 176 * The underlying PolyData is deleted, freeing its memory 177 */ 178 void Renderer::deletePolyData(DataSetId id) 179 { 180 PolyDataHashmap::iterator itr = _polyDatas.find(id); 181 if (itr == _polyDatas.end()) { 182 ERROR("PolyData not found: %s", id.c_str()); 183 return; 184 } 185 186 TRACE("Deleting PolyDatas for %s", id.c_str()); 187 188 PolyData *polyData = itr->second; 189 if (polyData->getActor()) 190 _renderer->RemoveActor(polyData->getActor()); 191 delete polyData; 192 193 _polyDatas.erase(itr); 194 _needsRedraw = true; 195 } 196 197 /** 144 198 * \brief Remove the specified DataSet and associated rendering objects 145 199 * … … 149 203 void Renderer::deleteDataSet(DataSetId id) 150 204 { 151 deletePseudoColor(id); 152 deleteContour2D(id); 153 154 DataSet *ds = getDataSet(id); 155 if (ds) { 156 delete ds; 157 _needsRedraw = true; 205 DataSetHashmap::iterator itr = _dataSets.find(id); 206 if (itr == _dataSets.end()) { 207 ERROR("Unknown dataset %s", id.c_str()); 208 return; 209 } else { 210 TRACE("Deleting dataset %s", id.c_str()); 211 212 deletePseudoColor(id); 213 deleteContour2D(id); 214 deletePolyData(id); 215 216 TRACE("After deleting graphics objects"); 217 218 delete itr->second; 219 _dataSets.erase(itr); 220 _needsRedraw = true; 158 221 } 159 222 } … … 167 230 { 168 231 DataSetHashmap::iterator itr = _dataSets.find(id); 169 if (itr == _dataSets.end()) 232 if (itr == _dataSets.end()) { 233 TRACE("DataSet not found: %s", id.c_str()); 170 234 return NULL; 171 else235 } else 172 236 return itr->second; 173 237 } … … 204 268 } 205 269 270 void Renderer::resetAxes() 271 { 272 TRACE("Resetting axes"); 273 if (_cubeAxesActor == NULL || 274 _cubeAxesActor2D == NULL) { 275 initAxes(); 276 } 277 if (_cameraMode == IMAGE) { 278 if (_renderer->HasViewProp(_cubeAxesActor)) { 279 TRACE("Removing 3D axes"); 280 _renderer->RemoveActor(_cubeAxesActor); 281 } 282 if (!_renderer->HasViewProp(_cubeAxesActor2D)) { 283 TRACE("Adding 2D axes"); 284 _renderer->AddActor(_cubeAxesActor2D); 285 } 286 } else { 287 if (_renderer->HasViewProp(_cubeAxesActor2D)) { 288 TRACE("Removing 2D axes"); 289 _renderer->RemoveActor(_cubeAxesActor2D); 290 } 291 if (!_renderer->HasViewProp(_cubeAxesActor)) { 292 TRACE("Adding 3D axes"); 293 _renderer->AddActor(_cubeAxesActor); 294 } 295 double bounds[6]; 296 collectBounds(bounds, true); 297 _cubeAxesActor->SetBounds(bounds); 298 } 299 } 300 206 301 /** 207 302 * \brief Set inital properties on the 2D Axes … … 209 304 void Renderer::initAxes() 210 305 { 306 TRACE("Initializing axes"); 307 if (_cubeAxesActor == NULL) 308 _cubeAxesActor = vtkSmartPointer<vtkCubeAxesActor>::New(); 309 _cubeAxesActor->SetCamera(_renderer->GetActiveCamera()); 310 // Don't offset labels at origin 311 _cubeAxesActor->SetCornerOffset(0); 312 _cubeAxesActor->SetFlyModeToClosestTriad(); 313 211 314 #ifdef USE_CUSTOM_AXES 212 _axesActor = vtkSmartPointer<vtkRpCubeAxesActor2D>::New(); 315 if (_cubeAxesActor2D == NULL) 316 _cubeAxesActor2D = vtkSmartPointer<vtkRpCubeAxesActor2D>::New(); 213 317 #else 214 _axesActor = vtkSmartPointer<vtkCubeAxesActor2D>::New(); 318 if (_cubeAxesActor2D == NULL) 319 _cubeAxesActor2D = vtkSmartPointer<vtkCubeAxesActor2D>::New(); 215 320 #endif 216 _axesActor->SetCamera(_renderer->GetActiveCamera()); 217 _renderer->AddActor(_axesActor); 218 219 _axesActor->ZAxisVisibilityOff(); 220 // Don't offset labels at origin 221 _axesActor->SetCornerOffset(0); 222 _axesActor->SetFlyModeToClosestTriad(); 223 _axesActor->ScalingOff(); 224 //_axesActor->SetShowActualBounds(0); 225 226 _axesActor->SetFontFactor(2); 227 321 _cubeAxesActor2D->SetCamera(_renderer->GetActiveCamera()); 322 _cubeAxesActor2D->ZAxisVisibilityOff(); 323 _cubeAxesActor2D->SetCornerOffset(0); 324 _cubeAxesActor2D->SetFlyModeToClosestTriad(); 325 326 _cubeAxesActor2D->ScalingOff(); 327 //_cubeAxesActor2D->SetShowActualBounds(0); 328 _cubeAxesActor2D->SetFontFactor(2); 228 329 // Use "nice" range and number of ticks/labels 229 _ axesActor->GetXAxisActor2D()->AdjustLabelsOn();230 _ axesActor->GetYAxisActor2D()->AdjustLabelsOn();330 _cubeAxesActor2D->GetXAxisActor2D()->AdjustLabelsOn(); 331 _cubeAxesActor2D->GetYAxisActor2D()->AdjustLabelsOn(); 231 332 232 333 #ifdef USE_CUSTOM_AXES 233 _ axesActor->SetAxisTitleTextProperty(NULL);234 _ axesActor->SetAxisLabelTextProperty(NULL);235 //_ axesActor->GetXAxisActor2D()->SizeFontRelativeToAxisOn();236 _ axesActor->GetXAxisActor2D()->GetTitleTextProperty()->BoldOn();237 _ axesActor->GetXAxisActor2D()->GetTitleTextProperty()->ItalicOff();238 _ axesActor->GetXAxisActor2D()->GetTitleTextProperty()->ShadowOn();239 _ axesActor->GetXAxisActor2D()->GetLabelTextProperty()->BoldOff();240 _ axesActor->GetXAxisActor2D()->GetLabelTextProperty()->ItalicOff();241 _ axesActor->GetXAxisActor2D()->GetLabelTextProperty()->ShadowOff();242 243 //_ axesActor->GetYAxisActor2D()->SizeFontRelativeToAxisOn();244 _ axesActor->GetYAxisActor2D()->GetTitleTextProperty()->BoldOn();245 _ axesActor->GetYAxisActor2D()->GetTitleTextProperty()->ItalicOff();246 _ axesActor->GetYAxisActor2D()->GetTitleTextProperty()->ShadowOn();247 _ axesActor->GetYAxisActor2D()->GetLabelTextProperty()->BoldOff();248 _ axesActor->GetYAxisActor2D()->GetLabelTextProperty()->ItalicOff();249 _ axesActor->GetYAxisActor2D()->GetLabelTextProperty()->ShadowOff();334 _cubeAxesActor2D->SetAxisTitleTextProperty(NULL); 335 _cubeAxesActor2D->SetAxisLabelTextProperty(NULL); 336 //_cubeAxesActor2D->GetXAxisActor2D()->SizeFontRelativeToAxisOn(); 337 _cubeAxesActor2D->GetXAxisActor2D()->GetTitleTextProperty()->BoldOn(); 338 _cubeAxesActor2D->GetXAxisActor2D()->GetTitleTextProperty()->ItalicOff(); 339 _cubeAxesActor2D->GetXAxisActor2D()->GetTitleTextProperty()->ShadowOn(); 340 _cubeAxesActor2D->GetXAxisActor2D()->GetLabelTextProperty()->BoldOff(); 341 _cubeAxesActor2D->GetXAxisActor2D()->GetLabelTextProperty()->ItalicOff(); 342 _cubeAxesActor2D->GetXAxisActor2D()->GetLabelTextProperty()->ShadowOff(); 343 344 //_cubeAxesActor2D->GetYAxisActor2D()->SizeFontRelativeToAxisOn(); 345 _cubeAxesActor2D->GetYAxisActor2D()->GetTitleTextProperty()->BoldOn(); 346 _cubeAxesActor2D->GetYAxisActor2D()->GetTitleTextProperty()->ItalicOff(); 347 _cubeAxesActor2D->GetYAxisActor2D()->GetTitleTextProperty()->ShadowOn(); 348 _cubeAxesActor2D->GetYAxisActor2D()->GetLabelTextProperty()->BoldOff(); 349 _cubeAxesActor2D->GetYAxisActor2D()->GetLabelTextProperty()->ItalicOff(); 350 _cubeAxesActor2D->GetYAxisActor2D()->GetLabelTextProperty()->ShadowOff(); 250 351 #else 251 _ axesActor->GetAxisTitleTextProperty()->BoldOn();252 _ axesActor->GetAxisTitleTextProperty()->ItalicOff();253 _ axesActor->GetAxisTitleTextProperty()->ShadowOn();254 _ axesActor->GetAxisLabelTextProperty()->BoldOff();255 _ axesActor->GetAxisLabelTextProperty()->ItalicOff();256 _ axesActor->GetAxisLabelTextProperty()->ShadowOff();352 _cubeAxesActor2D->GetAxisTitleTextProperty()->BoldOn(); 353 _cubeAxesActor2D->GetAxisTitleTextProperty()->ItalicOff(); 354 _cubeAxesActor2D->GetAxisTitleTextProperty()->ShadowOn(); 355 _cubeAxesActor2D->GetAxisLabelTextProperty()->BoldOff(); 356 _cubeAxesActor2D->GetAxisLabelTextProperty()->ItalicOff(); 357 _cubeAxesActor2D->GetAxisLabelTextProperty()->ShadowOff(); 257 358 #endif 359 360 if (_cameraMode == IMAGE) { 361 if (!_renderer->HasViewProp(_cubeAxesActor2D)) 362 _renderer->AddActor(_cubeAxesActor2D); 363 } else { 364 if (!_renderer->HasViewProp(_cubeAxesActor)) 365 _renderer->AddActor(_cubeAxesActor); 366 } 258 367 } 259 368 … … 268 377 269 378 if (getPseudoColor(id)) { 379 WARN("Replacing existing pseudocolor %s", id.c_str()); 270 380 deletePseudoColor(id); 271 381 } … … 277 387 _renderer->AddActor(pc->getActor()); 278 388 279 double actorBounds[6]; 280 pc->getActor()->GetBounds(actorBounds); 281 282 #ifdef DEBUG 283 TRACE("Actor Bounds: %.6e, %.6e, %.6e, %.6e, %.6e, %.6e", 284 actorBounds[0], 285 actorBounds[1], 286 actorBounds[2], 287 actorBounds[3], 288 actorBounds[4], 289 actorBounds[5]); 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 /** 408 * \brief Turn on/off rendering of all axes gridlines 409 */ 410 void Renderer::setAxesGridVisibility(bool state) 411 { 412 if (_cubeAxesActor != NULL) { 413 _cubeAxesActor->SetDrawXGridlines((state ? 1 : 0)); 414 _cubeAxesActor->SetDrawYGridlines((state ? 1 : 0)); 415 _cubeAxesActor->SetDrawZGridlines((state ? 1 : 0)); 416 _needsRedraw = true; 417 } 418 } 419 420 /** 421 * \brief Turn on/off rendering of single axis gridlines 422 */ 423 void Renderer::setAxisGridVisibility(Axis axis, bool state) 424 { 425 if (_cubeAxesActor != NULL) { 426 if (axis == X_AXIS) { 427 _cubeAxesActor->SetDrawXGridlines((state ? 1 : 0)); 428 } else if (axis == Y_AXIS) { 429 _cubeAxesActor->SetDrawYGridlines((state ? 1 : 0)); 430 } else if (axis == Z_AXIS) { 431 _cubeAxesActor->SetDrawZGridlines((state ? 1 : 0)); 432 } 433 _needsRedraw = true; 434 } 435 } 436 437 /** 438 * \brief Turn on/off rendering of all axes 439 */ 440 void Renderer::setAxesVisibility(bool state) 441 { 442 if (_cubeAxesActor != NULL) { 443 _cubeAxesActor->SetVisibility((state ? 1 : 0)); 444 _needsRedraw = true; 445 } 446 if (_cubeAxesActor2D != NULL) { 447 _cubeAxesActor2D->SetVisibility((state ? 1 : 0)); 448 _needsRedraw = true; 449 } 450 setAxisVisibility(X_AXIS, state); 451 setAxisVisibility(Y_AXIS, state); 452 setAxisVisibility(Z_AXIS, state); 453 } 454 455 /** 456 * \brief Turn on/off rendering of the specified axis 457 */ 458 void Renderer::setAxisVisibility(Axis axis, bool state) 459 { 460 if (_cubeAxesActor != NULL) { 461 if (axis == X_AXIS) { 462 _cubeAxesActor->SetXAxisVisibility((state ? 1 : 0)); 463 } else if (axis == Y_AXIS) { 464 _cubeAxesActor->SetYAxisVisibility((state ? 1 : 0)); 465 } else if (axis == Z_AXIS) { 466 _cubeAxesActor->SetZAxisVisibility((state ? 1 : 0)); 467 } 468 _needsRedraw = true; 469 } 470 if (_cubeAxesActor2D != NULL) { 471 if (axis == X_AXIS) { 472 _cubeAxesActor2D->SetXAxisVisibility((state ? 1 : 0)); 473 } else if (axis == Y_AXIS) { 474 _cubeAxesActor2D->SetYAxisVisibility((state ? 1 : 0)); 475 } 476 _needsRedraw = true; 477 } 478 } 479 480 /** 481 * \brief Set title of the specified axis 482 */ 483 void Renderer::setAxisTitle(Axis axis, const char *title) 484 { 485 if (_cubeAxesActor != NULL) { 486 if (axis == X_AXIS) { 487 _cubeAxesActor->SetXTitle(title); 488 } else if (axis == Y_AXIS) { 489 _cubeAxesActor->SetYTitle(title); 490 } else if (axis == Z_AXIS) { 491 _cubeAxesActor->SetZTitle(title); 492 } 493 _needsRedraw = true; 494 } 495 if (_cubeAxesActor2D != NULL) { 496 if (axis == X_AXIS) { 497 _cubeAxesActor2D->SetXLabel(title); 498 } else if (axis == Y_AXIS) { 499 _cubeAxesActor2D->SetYLabel(title); 500 } 501 _needsRedraw = true; 502 } 503 } 504 505 /** 506 * \brief Set units of the specified axis 507 */ 508 void Renderer::setAxisUnits(Axis axis, const char *units) 509 { 510 if (_cubeAxesActor != NULL) { 511 if (axis == X_AXIS) { 512 _cubeAxesActor->SetXUnits(units); 513 } else if (axis == Y_AXIS) { 514 _cubeAxesActor->SetYUnits(units); 515 } else if (axis == Z_AXIS) { 516 _cubeAxesActor->SetZUnits(units); 517 } 518 _needsRedraw = true; 519 } 520 #ifdef notdef 521 if (_cubeAxesActor2D != NULL) { 522 if (axis == X_AXIS) { 523 _cubeAxesActor2D->SetXUnits(units); 524 } else if (axis == Y_AXIS) { 525 _cubeAxesActor2D->SetYUnits(units); 526 } 527 _needsRedraw = true; 528 } 290 529 #endif 291 initCamera(actorBounds);292 _needsRedraw = true;293 }294 295 /**296 * \brief Get the PseudoColor associated with the specified DataSet297 */298 PseudoColor *Renderer::getPseudoColor(DataSetId id)299 {300 PseudoColorHashmap::iterator itr = _pseudoColors.find(id);301 302 if (itr == _pseudoColors.end())303 return NULL;304 else305 return itr->second;306 }307 308 /**309 * \brief Turn on/off rendering of all axes310 */311 void Renderer::setAxesVisibility(bool state)312 {313 if (_axesActor != NULL) {314 _axesActor->SetVisibility((state ? 1 : 0));315 _needsRedraw = true;316 }317 }318 319 /**320 * \brief Turn on/off rendering of the specified axis321 */322 void Renderer::setAxisVisibility(Axis axis, bool state)323 {324 if (_axesActor != NULL) {325 if (axis == X_AXIS) {326 _axesActor->SetXAxisVisibility((state ? 1 : 0));327 } else if (axis == Y_AXIS) {328 _axesActor->SetYAxisVisibility((state ? 1 : 0));329 } else if (axis == Z_AXIS) {330 _axesActor->SetZAxisVisibility((state ? 1 : 0));331 }332 _needsRedraw = true;333 }334 530 } 335 531 … … 337 533 * \brief Add a color map for use in the Renderer 338 534 */ 339 void Renderer::addColorMap(ColorMapId id, vtkLookupTable *lut) 340 { 341 if (lut == NULL) { 342 lut = vtkLookupTable::New(); 343 } 344 _colorMaps[id] = lut; 345 } 346 347 /** 348 * \brief Return the vtkLookupTable associated with the colormap key given 349 */ 350 vtkLookupTable *Renderer::getColorMap(ColorMapId id) 535 void Renderer::addColorMap(ColorMapId id, ColorMap *colorMap) 536 { 537 if (colorMap != NULL) { 538 colorMap->build(); 539 if (getColorMap(id) != NULL) { 540 WARN("Replacing existing colormap %s", id.c_str()); 541 deleteColorMap(id); 542 } 543 _colorMaps[id] = colorMap; 544 } else { 545 ERROR("NULL ColorMap"); 546 } 547 } 548 549 /** 550 * \brief Return the ColorMap associated with the colormap key given 551 */ 552 ColorMap *Renderer::getColorMap(ColorMapId id) 351 553 { 352 554 ColorMapHashmap::iterator itr = _colorMaps.find(id); … … 371 573 372 574 // TODO: Check if color map is used in PseudoColors? 373 575 delete itr->second; 374 576 _colorMaps.erase(itr); 375 577 } … … 400 602 if (_scalarBarActor == NULL) { 401 603 _scalarBarActor = vtkSmartPointer<vtkScalarBarActor>::New(); 604 _scalarBarActor->UseOpacityOn(); 402 605 _legendRenderer->AddActor(_scalarBarActor); 403 606 } 404 _scalarBarActor->SetLookupTable(getColorMap(id) );607 _scalarBarActor->SetLookupTable(getColorMap(id)->getLookupTable()); 405 608 // Set viewport-relative width/height/pos 406 609 if (width > height) { … … 433 636 PseudoColor *pc = getPseudoColor(id); 434 637 if (pc) { 435 pc->setLookupTable(getColorMap(colorMapId)); 436 _needsRedraw = true; 638 ColorMap *cmap = getColorMap(colorMapId); 639 if (cmap) { 640 TRACE("Set color map: %s for dataset %s", colorMapId.c_str(), 641 id.c_str()); 642 pc->setLookupTable(cmap->getLookupTable()); 643 _needsRedraw = true; 644 } else { 645 ERROR("Unknown colormap: %s", colorMapId.c_str()); 646 } 647 } else { 648 ERROR("No pseudocolor for dataset %s", id.c_str()); 437 649 } 438 650 } … … 465 677 466 678 /** 679 * \brief Set the visibility of polygon edges for the specified DataSet 680 */ 681 void Renderer::setPseudoColorEdgeVisibility(DataSetId id, bool state) 682 { 683 PseudoColor *pc = getPseudoColor(id); 684 if (pc) { 685 pc->setEdgeVisibility(state); 686 _needsRedraw = true; 687 } 688 } 689 690 /** 691 * \brief Set the RGB polygon edge color for the specified DataSet 692 */ 693 void Renderer::setPseudoColorEdgeColor(DataSetId id, float color[3]) 694 { 695 PseudoColor *pc = getPseudoColor(id); 696 if (pc) { 697 pc->setEdgeColor(color); 698 _needsRedraw = true; 699 } 700 } 701 702 /** 703 * \brief Set the polygon edge width for the specified DataSet (may be a no-op) 704 * 705 * If the OpenGL implementation/hardware does not support wide lines, 706 * this function may not have an effect. 707 */ 708 void Renderer::setPseudoColorEdgeWidth(DataSetId id, float edgeWidth) 709 { 710 PseudoColor *pc = getPseudoColor(id); 711 if (pc) { 712 pc->setEdgeWidth(edgeWidth); 713 _needsRedraw = true; 714 } 715 } 716 717 /** 467 718 * \brief Create a new Contour2D and associate it with the named DataSet 468 719 */ … … 473 724 return; 474 725 475 if (getContour2D(id)) 726 if (getContour2D(id)) { 727 WARN("Replacing existing contour2d %s", id.c_str()); 476 728 deleteContour2D(id); 729 } 477 730 478 731 Contour2D *contour = new Contour2D(); … … 482 735 483 736 _renderer->AddActor(contour->getActor()); 737 738 initCamera(); 739 _needsRedraw = true; 484 740 } 485 741 … … 491 747 Contour2DHashmap::iterator itr = _contours.find(id); 492 748 493 if (itr == _contours.end()) 749 if (itr == _contours.end()) { 750 TRACE("Contour2D not found: %s", id.c_str()); 494 751 return NULL; 495 else752 } else 496 753 return itr->second; 497 754 } … … 529 786 if (contour) { 530 787 contour->setVisibility(state); 788 _needsRedraw = true; 789 } 790 } 791 792 /** 793 * \brief Create a new PolyData and associate it with the named DataSet 794 */ 795 void Renderer::addPolyData(DataSetId id) 796 { 797 DataSet *ds = getDataSet(id); 798 if (ds == NULL) 799 return; 800 801 if (getPolyData(id)) { 802 WARN("Replacing existing polydata %s", id.c_str()); 803 deletePolyData(id); 804 } 805 806 PolyData *polyData = new PolyData(); 807 _polyDatas[id] = polyData; 808 809 polyData->setDataSet(ds); 810 811 _renderer->AddActor(polyData->getActor()); 812 813 if (_cameraMode == IMAGE) 814 setCameraMode(PERSPECTIVE); 815 initCamera(); 816 _needsRedraw = true; 817 } 818 819 /** 820 * \brief Get the PolyData associated with a named DataSet 821 */ 822 PolyData *Renderer::getPolyData(DataSetId id) 823 { 824 PolyDataHashmap::iterator itr = _polyDatas.find(id); 825 826 if (itr == _polyDatas.end()) { 827 TRACE("PolyData not found: %s", id.c_str()); 828 return NULL; 829 } else 830 return itr->second; 831 } 832 833 /** 834 * \brief Turn on/off rendering of the PolyData mapper for the given DataSet 835 */ 836 void Renderer::setPolyDataVisibility(DataSetId id, bool state) 837 { 838 PolyData *polyData = getPolyData(id); 839 if (polyData) { 840 polyData->setVisibility(state); 531 841 _needsRedraw = true; 532 842 } … … 542 852 _renderWindow->SetSize(_windowWidth, _windowHeight); 543 853 #ifdef notdef 544 set ZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1],545 _imgWorldDims[0], _imgWorldDims[1]);854 setCameraZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1], 855 _imgWorldDims[0], _imgWorldDims[1]); 546 856 #endif 547 857 _needsRedraw = true; … … 549 859 550 860 /** 861 * \brief Change the camera type: perspective, orthographic or image view 862 * 863 * Perspective mode is a normal 3D camera. 864 * 865 * Orthogrphic mode is parallel projection. 866 * 867 * Image mode is an orthographic camera with fixed axes and a clipping region 868 * around the plot area, use setCameraZoomRegion to control the displayed area 869 * 870 * \param[in] mode Enum specifying camera type 871 */ 872 void Renderer::setCameraMode(CameraMode mode) 873 { 874 if (_cameraMode == mode) return; 875 876 CameraMode origMode = _cameraMode; 877 _cameraMode = mode; 878 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 879 switch (mode) { 880 case ORTHO: { 881 TRACE("Set camera to Ortho mode"); 882 camera->ParallelProjectionOn(); 883 if (origMode == IMAGE) { 884 resetCamera(false); 885 } 886 break; 887 } 888 case PERSPECTIVE: { 889 TRACE("Set camera to Perspective mode"); 890 camera->ParallelProjectionOff(); 891 if (origMode == IMAGE) { 892 resetCamera(false); 893 } 894 break; 895 } 896 case IMAGE: { 897 camera->ParallelProjectionOn(); 898 setCameraZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1], 899 _imgWorldDims[0],_imgWorldDims[1]); 900 TRACE("Set camera to Image mode"); 901 break; 902 } 903 default: 904 ERROR("Unkown camera mode: %d", mode); 905 } 906 resetAxes(); 907 _needsRedraw = true; 908 } 909 910 void Renderer::storeCameraOrientation() 911 { 912 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 913 camera->GetPosition(_cameraPos); 914 camera->GetFocalPoint(_cameraFocalPoint); 915 camera->GetViewUp(_cameraUp); 916 } 917 918 void Renderer::restoreCameraOrientation() 919 { 920 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 921 camera->SetPosition(_cameraPos); 922 camera->SetFocalPoint(_cameraFocalPoint); 923 camera->SetViewUp(_cameraUp); 924 } 925 926 /** 927 * \brief Reset pan, zoom, clipping planes and optionally rotation 928 * 929 * \param[in] resetOrientation Reset the camera rotation/orientation also 930 */ 931 void Renderer::resetCamera(bool resetOrientation) 932 { 933 if (_cameraMode == IMAGE) { 934 initCamera(); 935 } else { 936 if (resetOrientation) { 937 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 938 camera->SetPosition(0, 0, 1); 939 camera->SetFocalPoint(0, 0, 0); 940 camera->SetViewUp(0, 1, 0); 941 storeCameraOrientation(); 942 } else { 943 restoreCameraOrientation(); 944 } 945 _renderer->ResetCamera(); 946 _renderer->ResetCameraClippingRange(); 947 } 948 _needsRedraw = true; 949 } 950 951 /** 952 * \brief Perform a relative rotation to current camera orientation 953 * 954 * Angles are in degrees, rotation is about focal point 955 */ 956 void Renderer::rotateCamera(double yaw, double pitch, double roll) 957 { 958 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 959 camera->Azimuth(yaw); // Rotate about object 960 //camera->SetYaw(yaw); // Rotate about camera 961 camera->Elevation(pitch); // Rotate about object 962 //camera->SetPitch(pitch); // Rotate about camera 963 camera->Roll(roll); // Roll about camera view axis 964 _renderer->ResetCameraClippingRange(); 965 storeCameraOrientation(); 966 _needsRedraw = true; 967 } 968 969 /** 970 * \brief Perform a relative 2D translation of the camera 971 * 972 * \param[in] x World coordinate horizontal panning 973 * \param[in] y World coordinate vertical panning 974 */ 975 void Renderer::panCamera(double x, double y) 976 { 977 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 978 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 979 trans->Translate(x, y, 0); 980 camera->ApplyTransform(trans); 981 _renderer->ResetCameraClippingRange(); 982 storeCameraOrientation(); 983 _needsRedraw = true; 984 } 985 986 /** 987 * \brief Change the FOV of the camera 988 * 989 * \param[in] z Ratio to change zoom (greater than 1 is zoom in, less than 1 is zoom out) 990 */ 991 void Renderer::zoomCamera(double z) 992 { 993 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 994 camera->Zoom(z); // Change perspective FOV angle or ortho parallel scale 995 //camera->Dolly(z); // Move camera forward/back 996 _renderer->ResetCameraClippingRange(); 997 storeCameraOrientation(); 998 _needsRedraw = true; 999 } 1000 1001 /** 551 1002 * \brief Set the pan/zoom using a corner and dimensions in world coordinates 552 1003 * 553 * x,y - bottom left corner in world coords 554 */ 555 void Renderer::setZoomRegion(double x, double y, double width, double height) 1004 * \param[in] x left world coordinate 1005 * \param[in] y bottom world coordinate 1006 * \param[in] width Width of zoom region in world coordinates 1007 * \param[in] height Height of zoom region in world coordinates 1008 */ 1009 void Renderer::setCameraZoomRegion(double x, double y, double width, double height) 556 1010 { 557 1011 double camPos[2]; … … 570 1024 TRACE("pxToWorld: %g", pxToWorld); 571 1025 TRACE("offset: %g %g", offsetX, offsetY); 1026 1027 setCameraMode(IMAGE); 572 1028 573 1029 _imgWorldOrigin[0] = x; … … 597 1053 _clippingPlanes->GetItem(3)->SetOrigin(_imgWorldOrigin[0] + _imgWorldDims[0], 0, 0); 598 1054 599 _ axesActor->SetBounds(_imgWorldOrigin[0], _imgWorldOrigin[0] + _imgWorldDims[0],600 _imgWorldOrigin[1], _imgWorldOrigin[1] + _imgWorldDims[1], 0, 0);1055 _cubeAxesActor2D->SetBounds(_imgWorldOrigin[0], _imgWorldOrigin[0] + _imgWorldDims[0], 1056 _imgWorldOrigin[1], _imgWorldOrigin[1] + _imgWorldDims[1], 0, 0); 601 1057 602 1058 #ifdef DEBUG … … 607 1063 } 608 1064 1065 void Renderer::mergeBounds(double *boundsDest, 1066 const double *bounds1, const double *bounds2) 1067 { 1068 for (int i = 0; i < 6; i++) { 1069 if (i % 2 == 0) 1070 boundsDest[i] = min2(bounds1[i], bounds2[i]); 1071 else 1072 boundsDest[i] = max2(bounds1[i], bounds2[i]); 1073 } 1074 } 1075 1076 /** 1077 * \brief Collect bounds of all graphics objects 1078 * 1079 * \param[out] bounds Bounds of all scene objects 1080 * \param[in] onlyVisible Only collect bounds of visible objects 1081 */ 1082 void Renderer::collectBounds(double *bounds, bool onlyVisible) 1083 { 1084 bounds[0] = DBL_MAX; 1085 bounds[1] = -DBL_MAX; 1086 bounds[2] = DBL_MAX; 1087 bounds[3] = -DBL_MAX; 1088 bounds[4] = DBL_MAX; 1089 bounds[5] = -DBL_MAX; 1090 1091 for (PseudoColorHashmap::iterator itr = _pseudoColors.begin(); 1092 itr != _pseudoColors.end(); ++itr) { 1093 if (!onlyVisible || itr->second->getVisibility()) 1094 mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds()); 1095 } 1096 for (Contour2DHashmap::iterator itr = _contours.begin(); 1097 itr != _contours.end(); ++itr) { 1098 if (!onlyVisible || itr->second->getVisibility()) 1099 mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds()); 1100 } 1101 for (PolyDataHashmap::iterator itr = _polyDatas.begin(); 1102 itr != _polyDatas.end(); ++itr) { 1103 if (!onlyVisible || itr->second->getVisibility()) 1104 mergeBounds(bounds, bounds, itr->second->getActor()->GetBounds()); 1105 } 1106 for (int i = 0; i < 6; i++) { 1107 if (i % 2 == 0) { 1108 if (bounds[i] == DBL_MAX) 1109 bounds[i] = 0; 1110 } else { 1111 if (bounds[i] == -DBL_MAX) 1112 bounds[i] = 1; 1113 } 1114 } 1115 } 1116 1117 #ifdef notdef 1118 void Renderer::setPerspectiveCameraByBounds(double bounds[6]) 1119 { 1120 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 1121 camera->ParallelProjectionOff(); 1122 camera->Reset(); 1123 } 1124 #endif 1125 609 1126 /** 610 1127 * \brief Initialize the camera zoom region to include the bounding volume given 611 1128 */ 612 void Renderer::initCamera(double bounds[6]) 613 { 614 _renderer->ResetCamera(); 615 setZoomRegion(bounds[0], bounds[2], bounds[1] - bounds[0], bounds[3] - bounds[2]); 1129 void Renderer::initCamera() 1130 { 1131 double bounds[6]; 1132 collectBounds(bounds, true); 1133 _imgWorldOrigin[0] = bounds[0]; 1134 _imgWorldOrigin[1] = bounds[2]; 1135 _imgWorldDims[0] = bounds[1] - bounds[0]; 1136 _imgWorldDims[1] = bounds[3] - bounds[2]; 1137 1138 if (_cameraMode == IMAGE) { 1139 _renderer->ResetCamera(); 1140 setCameraZoomRegion(_imgWorldOrigin[0], _imgWorldOrigin[1], 1141 _imgWorldDims[0], _imgWorldDims[1]); 1142 resetAxes(); 1143 } else if (_cameraMode == ORTHO) { 1144 _renderer->GetActiveCamera()->ParallelProjectionOn(); 1145 resetAxes(); 1146 _renderer->ResetCamera(); 1147 } else if (_cameraMode == PERSPECTIVE) { 1148 _renderer->GetActiveCamera()->ParallelProjectionOff(); 1149 resetAxes(); 1150 _renderer->ResetCamera(); 1151 } 616 1152 } 617 1153 … … 657 1193 _needsRedraw = true; 658 1194 } 1195 PolyData *polyData = getPolyData(id); 1196 if (polyData) { 1197 polyData->setOpacity(opacity); 1198 _needsRedraw = true; 1199 } 659 1200 } 660 1201 … … 666 1207 setPseudoColorVisibility(id, state); 667 1208 setContourVisibility(id, state); 1209 setPolyDataVisibility(id, state); 668 1210 } 669 1211 … … 696 1238 697 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 } 1300 } 1301 1302 /** 698 1303 * \brief Cause the rendering to render a new image if needed 699 1304 * … … 704 1309 { 705 1310 if (_needsRedraw) { 706 for (PseudoColorHashmap::iterator itr = _pseudoColors.begin(); 707 itr != _pseudoColors.end(); ++itr) { 708 itr->second->setClippingPlanes(_clippingPlanes); 709 } 710 for (Contour2DHashmap::iterator itr = _contours.begin(); 711 itr != _contours.end(); ++itr) { 712 itr->second->setClippingPlanes(_clippingPlanes); 713 } 714 1311 if (_cameraMode == IMAGE) { 1312 for (PseudoColorHashmap::iterator itr = _pseudoColors.begin(); 1313 itr != _pseudoColors.end(); ++itr) { 1314 itr->second->setClippingPlanes(_clippingPlanes); 1315 } 1316 for (Contour2DHashmap::iterator itr = _contours.begin(); 1317 itr != _contours.end(); ++itr) { 1318 itr->second->setClippingPlanes(_clippingPlanes); 1319 } 1320 } else { 1321 for (PseudoColorHashmap::iterator itr = _pseudoColors.begin(); 1322 itr != _pseudoColors.end(); ++itr) { 1323 itr->second->setClippingPlanes(NULL); 1324 } 1325 for (Contour2DHashmap::iterator itr = _contours.begin(); 1326 itr != _contours.end(); ++itr) { 1327 itr->second->setClippingPlanes(NULL); 1328 } 1329 } 715 1330 _renderWindow->Render(); 716 1331 _needsRedraw = false; -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.h
r2100 r2112 11 11 #include <vtkSmartPointer.h> 12 12 #include <vtkLookupTable.h> 13 #include <vtkCubeAxesActor.h> 13 14 #ifdef USE_CUSTOM_AXES 14 15 #include <vtkRpCubeAxesActor2D.h> … … 25 26 #include <tr1/unordered_map> 26 27 28 #include "ColorMap.h" 27 29 #include "RpVtkDataSet.h" 28 30 #include "RpPseudoColor.h" 29 31 #include "RpContour2D.h" 32 #include "RpPolyData.h" 30 33 31 34 namespace Rappture { … … 47 50 }; 48 51 52 enum CameraMode { 53 PERSPECTIVE, 54 ORTHO, 55 IMAGE 56 }; 57 49 58 typedef std::string DataSetId; 50 59 typedef std::string ColorMapId; 51 60 typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap; 52 typedef std::tr1::unordered_map<ColorMapId, vtkSmartPointer<vtkLookupTable>> ColorMapHashmap;61 typedef std::tr1::unordered_map<ColorMapId, ColorMap *> ColorMapHashmap; 53 62 typedef std::tr1::unordered_map<DataSetId, PseudoColor *> PseudoColorHashmap; 54 63 typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap; 64 typedef std::tr1::unordered_map<DataSetId, PolyData *> PolyDataHashmap; 65 66 // Data sets 55 67 56 68 void addDataSet(DataSetId id); … … 68 80 double getDataValue(DataSetId id, double x, double y, double z); 69 81 82 void setOpacity(DataSetId id, double opacity); 83 84 void setVisibility(DataSetId id, bool state); 85 86 // Render window 87 70 88 void setWindowSize(int width, int height); 71 89 72 void setZoomRegion(double x, double y, double width, double height); 90 int getWindowWidth() const; 91 92 int getWindowHeight() const; 93 94 // Camera controls 95 96 void setCameraMode(CameraMode mode); 97 98 void resetCamera(bool resetOrientation = true); 99 100 void setCameraZoomRegion(double x, double y, double width, double height); 101 102 void rotateCamera(double yaw, double pitch, double roll); 103 104 void panCamera(double x, double y); 105 106 void zoomCamera(double z); 107 108 // Rendering an image 73 109 74 110 void setBackgroundColor(float color[3]); … … 76 112 bool render(); 77 113 78 int getWindowWidth() const;79 80 int getWindowHeight() const;81 82 114 void getRenderedFrame(vtkUnsignedCharArray *imgData); 83 115 84 // 116 // Axes 117 118 void setAxesGridVisibility(bool state); 85 119 86 120 void setAxesVisibility(bool state); 87 121 122 void setAxisGridVisibility(Axis axis, bool state); 123 88 124 void setAxisVisibility(Axis axis, bool state); 89 125 90 // 91 92 void addColorMap(ColorMapId id, vtkLookupTable *lut); 126 void setAxisTitle(Axis axis, const char *title); 127 128 void setAxisUnits(Axis axis, const char *units); 129 130 // Colormaps 131 132 void addColorMap(ColorMapId id, ColorMap *colorMap); 93 133 94 134 void deleteColorMap(ColorMapId id); 95 135 96 vtkLookupTable*getColorMap(ColorMapId id);136 ColorMap *getColorMap(ColorMapId id); 97 137 98 138 void renderColorMap(ColorMapId id, const char *title, … … 100 140 vtkUnsignedCharArray *imgData); 101 141 102 void setOpacity(DataSetId id, double opacity); 103 104 void setVisibility(DataSetId id, bool state); 105 106 // 142 // Color-mapped surfaces 107 143 108 144 void addPseudoColor(DataSetId id); … … 118 154 void setPseudoColorVisibility(DataSetId id, bool state); 119 155 120 // 156 void setPseudoColorEdgeVisibility(DataSetId id, bool state); 157 158 void setPseudoColorEdgeColor(DataSetId id, float color[3]); 159 160 void setPseudoColorEdgeWidth(DataSetId id, float edgeWidth); 161 162 // Contour plots 121 163 122 164 void addContour2D(DataSetId id); … … 135 177 136 178 void setContourEdgeWidth(DataSetId id, float edgeWidth); 179 180 // Meshes 181 182 void addPolyData(DataSetId id); 183 184 void deletePolyData(DataSetId id); 185 186 PolyData *getPolyData(DataSetId id); 187 188 void setPolyDataVisibility(DataSetId id, bool state); 189 190 void setPolyDataColor(DataSetId id, float color[3]); 191 192 void setPolyDataEdgeVisibility(DataSetId id, bool state); 193 194 void setPolyDataEdgeColor(DataSetId id, float color[3]); 195 196 void setPolyDataEdgeWidth(DataSetId id, float edgeWidth); 197 198 void setPolyDataWireframe(DataSetId id, bool state); 137 199 138 200 private: 139 201 static void printCameraInfo(vtkCamera *camera); 140 141 void initCamera(double bounds[6]); 202 static inline double min2(double a, double b) 203 { 204 return ((a < b) ? a : b); 205 } 206 static inline double max2(double a, double b) 207 { 208 return ((a > b) ? a : b); 209 } 210 static void mergeBounds(double *boundsDest, const double *bounds1, const double *bounds2); 211 212 void collectBounds(double *bounds, bool onlyVisible); 213 214 void storeCameraOrientation(); 215 void restoreCameraOrientation(); 216 void initCamera(); 142 217 void initAxes(); 218 void resetAxes(); 143 219 144 220 bool _needsRedraw; … … 146 222 double _imgWorldOrigin[2]; 147 223 double _imgWorldDims[2]; 224 double _cameraPos[3]; 225 double _cameraFocalPoint[3]; 226 double _cameraUp[3]; 148 227 float _bgColor[3]; 149 228 … … 152 231 PseudoColorHashmap _pseudoColors; 153 232 Contour2DHashmap _contours; 233 PolyDataHashmap _polyDatas; 234 235 CameraMode _cameraMode; 154 236 155 237 vtkSmartPointer<vtkPlaneCollection> _clippingPlanes; 238 vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor; // For 3D view 156 239 #ifdef USE_CUSTOM_AXES 157 vtkSmartPointer<vtkRpCubeAxesActor2D> _ axesActor;240 vtkSmartPointer<vtkRpCubeAxesActor2D> _cubeAxesActor2D; // For 2D view 158 241 #else 159 vtkSmartPointer<vtkCubeAxesActor2D> _ axesActor;242 vtkSmartPointer<vtkCubeAxesActor2D> _cubeAxesActor2D; // For 2D view 160 243 #endif 161 244 vtkSmartPointer<vtkScalarBarActor> _scalarBarActor; -
trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp
r2106 r2112 60 60 61 61 static int 62 AxisCmd(ClientData clientData, Tcl_Interp *interp, int objc, 63 Tcl_Obj *const *objv) 64 { 65 if (objc < 3) { 66 Tcl_AppendResult(interp, "wrong # args: should be \"", 67 Tcl_GetString(objv[0]), " visible bool\"", (char*)NULL); 68 return TCL_ERROR; 69 } 70 const char *string = Tcl_GetString(objv[1]); 62 AxisGridOp(ClientData clientData, Tcl_Interp *interp, int objc, 63 Tcl_Obj *const *objv) 64 { 65 bool visible; 66 if (GetBooleanFromObj(interp, objv[3], &visible) != TCL_OK) { 67 return TCL_ERROR; 68 } 69 const char *string = Tcl_GetString(objv[2]); 71 70 char c = string[0]; 72 if ((c == 'v') && (strcmp(string, "visible") == 0)) { 73 bool visible; 74 75 if (GetBooleanFromObj(interp, objv[2], &visible) != TCL_OK) { 76 return TCL_ERROR; 77 } 78 71 if ((c == 'x') && (strcmp(string, "x") == 0)) { 72 g_renderer->setAxisGridVisibility(Renderer::X_AXIS, visible); 73 } else if ((c == 'y') && (strcmp(string, "y") == 0)) { 74 g_renderer->setAxisGridVisibility(Renderer::Y_AXIS, visible); 75 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 76 g_renderer->setAxisGridVisibility(Renderer::Z_AXIS, visible); 77 } else if ((c == 'a') && (strcmp(string, "all") == 0)) { 78 g_renderer->setAxesGridVisibility(visible); 79 } else { 80 Tcl_AppendResult(interp, "bad axis option \"", string, 81 "\": should be axisName visible", (char*)NULL); 82 return TCL_ERROR; 83 } 84 return TCL_OK; 85 } 86 87 static int 88 AxisNameOp(ClientData clientData, Tcl_Interp *interp, int objc, 89 Tcl_Obj *const *objv) 90 { 91 const char *title = Tcl_GetString(objv[3]); 92 const char *string = Tcl_GetString(objv[2]); 93 char c = string[0]; 94 if ((c == 'x') && (strcmp(string, "x") == 0)) { 95 g_renderer->setAxisTitle(Renderer::X_AXIS, title); 96 } else if ((c == 'y') && (strcmp(string, "y") == 0)) { 97 g_renderer->setAxisTitle(Renderer::Y_AXIS, title); 98 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 99 g_renderer->setAxisTitle(Renderer::Z_AXIS, title); 100 } else { 101 Tcl_AppendResult(interp, "bad axis option \"", string, 102 "\": should be axisName title", (char*)NULL); 103 return TCL_ERROR; 104 } 105 return TCL_OK; 106 } 107 108 static int 109 AxisUnitsOp(ClientData clientData, Tcl_Interp *interp, int objc, 110 Tcl_Obj *const *objv) 111 { 112 const char *units = Tcl_GetString(objv[3]); 113 const char *string = Tcl_GetString(objv[2]); 114 char c = string[0]; 115 if ((c == 'x') && (strcmp(string, "x") == 0)) { 116 g_renderer->setAxisUnits(Renderer::X_AXIS, units); 117 } else if ((c == 'y') && (strcmp(string, "y") == 0)) { 118 g_renderer->setAxisUnits(Renderer::Y_AXIS, units); 119 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 120 g_renderer->setAxisUnits(Renderer::Z_AXIS, units); 121 } else { 122 Tcl_AppendResult(interp, "bad axis option \"", string, 123 "\": should be axisName units", (char*)NULL); 124 return TCL_ERROR; 125 } 126 return TCL_OK; 127 } 128 129 static int 130 AxisVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 131 Tcl_Obj *const *objv) 132 { 133 bool visible; 134 if (GetBooleanFromObj(interp, objv[3], &visible) != TCL_OK) { 135 return TCL_ERROR; 136 } 137 const char *string = Tcl_GetString(objv[2]); 138 char c = string[0]; 139 if ((c == 'x') && (strcmp(string, "x") == 0)) { 140 g_renderer->setAxisVisibility(Renderer::X_AXIS, visible); 141 } else if ((c == 'y') && (strcmp(string, "y") == 0)) { 142 g_renderer->setAxisVisibility(Renderer::Y_AXIS, visible); 143 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 144 g_renderer->setAxisVisibility(Renderer::Z_AXIS, visible); 145 } else if ((c == 'a') && (strcmp(string, "all") == 0)) { 79 146 g_renderer->setAxesVisibility(visible); 80 147 } else { 81 148 Tcl_AppendResult(interp, "bad axis option \"", string, 82 "\": should be visible", (char*)NULL); 83 return TCL_ERROR; 84 } 85 return TCL_OK; 86 } 149 "\": should be axisName visible", (char*)NULL); 150 return TCL_ERROR; 151 } 152 return TCL_OK; 153 } 154 155 static Rappture::CmdSpec axisOps[] = { 156 {"grid", 1, AxisGridOp, 4, 4, "axis bool"}, 157 {"name", 1, AxisNameOp, 4, 4, "axis title"}, 158 {"units", 1, AxisUnitsOp, 4, 4, "axis units"}, 159 {"visible", 1, AxisVisibleOp, 4, 4, "axis bool"}, 160 }; 161 static int nAxisOps = NumCmdSpecs(axisOps); 162 163 static int 164 AxisCmd(ClientData clientData, Tcl_Interp *interp, int objc, 165 Tcl_Obj *const *objv) 166 { 167 Tcl_ObjCmdProc *proc; 168 169 proc = Rappture::GetOpFromObj(interp, nAxisOps, axisOps, 170 Rappture::CMDSPEC_ARG1, objc, objv, 0); 171 if (proc == NULL) { 172 return TCL_ERROR; 173 } 174 return (*proc) (clientData, interp, objc, objv); 175 } 176 177 static int 178 CameraModeOp(ClientData clientData, Tcl_Interp *interp, int objc, 179 Tcl_Obj *const *objv) 180 { 181 Renderer::CameraMode mode; 182 const char *string = Tcl_GetString(objv[2]); 183 if ((strcmp(string, "persp") == 0)) { 184 mode = Renderer::PERSPECTIVE; 185 } else if ((strcmp(string, "ortho") == 0)) { 186 mode = Renderer::ORTHO; 187 } else if ((strcmp(string, "image") == 0)) { 188 mode = Renderer::IMAGE; 189 } else { 190 Tcl_AppendResult(interp, "bad camera mode option \"", string, 191 "\": should be perspective, ortho or image", (char*)NULL); 192 return TCL_ERROR; 193 } 194 g_renderer->setCameraMode(mode); 195 return TCL_OK; 196 } 197 198 static int 199 CameraOrthoOp(ClientData clientData, Tcl_Interp *interp, int objc, 200 Tcl_Obj *const *objv) 201 { 202 float x, y, width, height; 203 204 if (GetFloatFromObj(interp, objv[2], &x) != TCL_OK || 205 GetFloatFromObj(interp, objv[3], &y) != TCL_OK || 206 GetFloatFromObj(interp, objv[4], &width) != TCL_OK || 207 GetFloatFromObj(interp, objv[5], &height) != TCL_OK) { 208 return TCL_ERROR; 209 } 210 211 g_renderer->setCameraZoomRegion(x, y, width, height); 212 return TCL_OK; 213 } 214 215 static int 216 CameraPanOp(ClientData clientData, Tcl_Interp *interp, int objc, 217 Tcl_Obj *const *objv) 218 { 219 float x, y; 220 221 if (GetFloatFromObj(interp, objv[2], &x) != TCL_OK || 222 GetFloatFromObj(interp, objv[3], &y) != TCL_OK) { 223 return TCL_ERROR; 224 } 225 226 g_renderer->panCamera(x, y); 227 return TCL_OK; 228 } 229 230 static int 231 CameraResetOp(ClientData clientData, Tcl_Interp *interp, int objc, 232 Tcl_Obj *const *objv) 233 { 234 if (objc == 3) { 235 const char *string = Tcl_GetString(objv[2]); 236 char c = string[0]; 237 if ((c != 'a') || (strcmp(string, "all") != 0)) { 238 Tcl_AppendResult(interp, "bad camera reset option \"", string, 239 "\": should be all", (char*)NULL); 240 return TCL_ERROR; 241 } 242 g_renderer->resetCamera(true); 243 } else { 244 g_renderer->resetCamera(false); 245 } 246 return TCL_OK; 247 } 248 249 static int 250 CameraRotateOp(ClientData clientData, Tcl_Interp *interp, int objc, 251 Tcl_Obj *const *objv) 252 { 253 float yaw, pitch, roll; 254 255 if (GetFloatFromObj(interp, objv[2], &yaw) != TCL_OK || 256 GetFloatFromObj(interp, objv[3], &pitch) != TCL_OK || 257 GetFloatFromObj(interp, objv[4], &roll) != TCL_OK) { 258 return TCL_ERROR; 259 } 260 261 g_renderer->rotateCamera(yaw, pitch, roll); 262 return TCL_OK; 263 } 264 265 static int 266 CameraZoomOp(ClientData clientData, Tcl_Interp *interp, int objc, 267 Tcl_Obj *const *objv) 268 { 269 float z; 270 271 if (GetFloatFromObj(interp, objv[2], &z) != TCL_OK) { 272 return TCL_ERROR; 273 } 274 275 g_renderer->zoomCamera(z); 276 return TCL_OK; 277 } 278 279 static Rappture::CmdSpec cameraOps[] = { 280 {"mode", 1, CameraModeOp, 3, 3, "mode"}, 281 {"ortho", 1, CameraOrthoOp, 6, 6, "x y width height"}, 282 {"pan", 1, CameraPanOp, 4, 4, "panX panY"}, 283 {"reset", 2, CameraResetOp, 2, 3, "?all?"}, 284 {"rotate", 2, CameraRotateOp, 5, 5, "angle angle angle"}, 285 {"zoom", 1, CameraZoomOp, 3, 3, "zoomAmount"}, 286 }; 287 static int nCameraOps = NumCmdSpecs(cameraOps); 87 288 88 289 static int … … 90 291 Tcl_Obj *const *objv) 91 292 { 92 if (objc < 6) { 93 Tcl_AppendResult(interp, "wrong # args: should be \"", 94 Tcl_GetString(objv[0]), " ortho x y width height\"", (char*)NULL); 95 return TCL_ERROR; 96 } 97 const char *string = Tcl_GetString(objv[1]); 98 char c = string[0]; 99 if ((c == 'o') && (strcmp(string, "ortho") == 0)) { 100 float x, y, width, height; 101 102 if (GetFloatFromObj(interp, objv[2], &x) != TCL_OK || 103 GetFloatFromObj(interp, objv[3], &y) != TCL_OK || 104 GetFloatFromObj(interp, objv[4], &width) != TCL_OK || 105 GetFloatFromObj(interp, objv[5], &height) != TCL_OK) { 106 return TCL_ERROR; 107 } 108 109 g_renderer->setZoomRegion(x, y, width, height); 110 } else { 111 Tcl_AppendResult(interp, "bad camera option \"", string, 112 "\": should be ortho", (char*)NULL); 113 return TCL_ERROR; 114 } 115 return TCL_OK; 293 Tcl_ObjCmdProc *proc; 294 295 proc = Rappture::GetOpFromObj(interp, nCameraOps, cameraOps, 296 Rappture::CMDSPEC_ARG1, objc, objv, 0); 297 if (proc == NULL) { 298 return TCL_ERROR; 299 } 300 return (*proc) (clientData, interp, objc, objv); 116 301 } 117 302 … … 121 306 { 122 307 const char *name = Tcl_GetString(objv[2]); 123 int cmapc ;308 int cmapc, omapc; 124 309 Tcl_Obj **cmapv = NULL; 310 Tcl_Obj **omapv = NULL; 125 311 126 312 if (Tcl_ListObjGetElements(interp, objv[3], &cmapc, &cmapv) != TCL_OK) { … … 128 314 } 129 315 if ((cmapc % 4) != 0) { 130 Tcl_AppendResult(interp, "wrong # elements is colormap: should be ", 131 "{ r g b a ... }", (char*)NULL); 132 return TCL_ERROR; 133 } 134 int numEntries = cmapc / 4; 135 vtkLookupTable *lut = vtkLookupTable::New(); 136 lut->Allocate(numEntries, numEntries); 316 Tcl_AppendResult(interp, "wrong # elements in colormap: should be ", 317 "{ value r g b ... }", (char*)NULL); 318 return TCL_ERROR; 319 } 320 321 ColorMap *colorMap = new ColorMap(name); 322 colorMap->setNumberOfTableEntries(256); 323 137 324 for (int i = 0; i < cmapc; i += 4) { 138 325 double val[4]; 139 326 for (int j = 0; j < 4; j++) { 140 327 if (Tcl_GetDoubleFromObj(interp, cmapv[i+j], &val[j]) != TCL_OK) { 328 delete colorMap; 141 329 return TCL_ERROR; 142 330 } … … 145 333 Tcl_GetString(cmapv[i+j]), 146 334 "\": should be in the range [0,1]", (char*)NULL); 335 delete colorMap; 147 336 return TCL_ERROR; 148 337 } 149 338 } 150 lut->SetTableValue(i/4, val); 151 } 152 g_renderer->addColorMap(name, lut); 339 ColorMap::ControlPoint cp; 340 cp.value = val[0]; 341 for (int c = 0; c < 3; c++) { 342 cp.color[c] = val[c+1]; 343 } 344 colorMap->addControlPoint(cp); 345 } 346 347 if (Tcl_ListObjGetElements(interp, objv[4], &omapc, &omapv) != TCL_OK) { 348 delete colorMap; 349 return TCL_ERROR; 350 } 351 if ((omapc % 2) != 0) { 352 Tcl_AppendResult(interp, "wrong # elements in opacitymap: should be ", 353 "{ value alpha ... }", (char*)NULL); 354 delete colorMap; 355 return TCL_ERROR; 356 } 357 for (int i = 0; i < omapc; i += 2) { 358 double val[2]; 359 for (int j = 0; j < 2; j++) { 360 if (Tcl_GetDoubleFromObj(interp, omapv[i+j], &val[j]) != TCL_OK) { 361 delete colorMap; 362 return TCL_ERROR; 363 } 364 if ((val[j] < 0.0) || (val[j] > 1.0)) { 365 Tcl_AppendResult(interp, "bad opacitymap value \"", 366 Tcl_GetString(omapv[i+j]), 367 "\": should be in the range [0,1]", (char*)NULL); 368 delete colorMap; 369 return TCL_ERROR; 370 } 371 } 372 ColorMap::OpacityControlPoint ocp; 373 ocp.value = val[0]; 374 ocp.alpha = val[1]; 375 colorMap->addOpacityControlPoint(ocp); 376 } 377 378 colorMap->build(); 379 g_renderer->addColorMap(name, colorMap); 153 380 return TCL_OK; 154 381 } … … 164 391 165 392 static Rappture::CmdSpec colorMapOps[] = { 166 {"add", 1, ColorMapAddOp, 4, 4, "colorMapNamemap"},393 {"add", 1, ColorMapAddOp, 5, 5, "colorMapName colormap alphamap"}, 167 394 {"delete", 1, ColorMapDeleteOp, 3, 3, "colorMapName"} 168 395 }; … … 372 599 { 373 600 const char *name = Tcl_GetString(objv[2]); 601 TRACE("Deleting dataset %s", name); 374 602 g_renderer->deleteDataSet(name); 375 603 return TCL_OK; … … 501 729 502 730 static int 503 GridCmd(ClientData clientData, Tcl_Interp *interp, int objc,504 Tcl_Obj *const *objv)505 {506 if (objc < 3) {507 Tcl_AppendResult(interp, "wrong # args: should be \"",508 Tcl_GetString(objv[0]), " visible bool\"", (char*)NULL);509 return TCL_ERROR;510 }511 const char *string = Tcl_GetString(objv[1]);512 char c = string[0];513 if ((c == 'v') && (strcmp(string, "visible") == 0)) {514 bool visible;515 516 if (GetBooleanFromObj(interp, objv[2], &visible) != TCL_OK) {517 return TCL_ERROR;518 }519 Tcl_AppendResult(interp, "Command not yet implemented", (char*)NULL);520 return TCL_ERROR; // TODO: handle command521 } else {522 Tcl_AppendResult(interp, "bad grid option \"", string,523 "\": should be visible", (char*)NULL);524 return TCL_ERROR;525 }526 return TCL_OK;527 }528 529 static int530 731 LegendCmd(ClientData clientData, Tcl_Interp *interp, int objc, 531 732 Tcl_Obj *const *objv) … … 602 803 } 603 804 805 static int 806 PseudoColorEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 807 Tcl_Obj *const *objv) 808 { 809 const char *name = Tcl_GetString(objv[3]); 810 bool state; 811 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 812 return TCL_ERROR; 813 } 814 g_renderer->setPseudoColorEdgeVisibility(name, state); 815 return TCL_OK; 816 } 817 818 static int 819 PseudoColorLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc, 820 Tcl_Obj *const *objv) 821 { 822 const char *name = Tcl_GetString(objv[5]); 823 float color[3]; 824 if (GetFloatFromObj(interp, objv[2], &color[0]) != TCL_OK || 825 GetFloatFromObj(interp, objv[3], &color[1]) != TCL_OK || 826 GetFloatFromObj(interp, objv[4], &color[2]) != TCL_OK) { 827 return TCL_ERROR; 828 } 829 g_renderer->setPseudoColorEdgeColor(name, color); 830 return TCL_OK; 831 } 832 833 static int 834 PseudoColorLineWidthOp(ClientData clientData, Tcl_Interp *interp, int objc, 835 Tcl_Obj *const *objv) 836 { 837 const char *name = Tcl_GetString(objv[3]); 838 float width; 839 if (GetFloatFromObj(interp, objv[2], &width) != TCL_OK) { 840 return TCL_ERROR; 841 } 842 g_renderer->setPseudoColorEdgeWidth(name, width); 843 return TCL_OK; 844 } 845 604 846 static Rappture::CmdSpec pseudoColorOps[] = { 605 847 {"add", 1, PseudoColorAddOp, 3, 3, "dataSetName"}, 606 848 {"colormap", 1, PseudoColorColorMapOp, 4, 4, "colorMapName dataSetName"}, 607 849 {"delete", 1, PseudoColorDeleteOp, 3, 3, "dataSetName"}, 850 {"edges", 1, PseudoColorEdgeVisibilityOp, 4, 4, "bool dataSetName"}, 851 {"linecolor", 5, PseudoColorLineColorOp, 6, 6, "r g b dataSetName"}, 852 {"linewidth", 5, PseudoColorLineWidthOp, 4, 4, "width dataSetName"}, 608 853 {"visible", 1, PseudoColorVisibleOp, 4, 4, "bool dataSetName"} 609 854 }; … … 617 862 618 863 proc = Rappture::GetOpFromObj(interp, nPseudoColorOps, pseudoColorOps, 864 Rappture::CMDSPEC_ARG1, objc, objv, 0); 865 if (proc == NULL) { 866 return TCL_ERROR; 867 } 868 return (*proc) (clientData, interp, objc, objv); 869 } 870 871 static int 872 PolyDataAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 873 Tcl_Obj *const *objv) 874 { 875 const char *name = Tcl_GetString(objv[2]); 876 g_renderer->addPolyData(name); 877 return TCL_OK; 878 } 879 880 static int 881 PolyDataDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 882 Tcl_Obj *const *objv) 883 { 884 const char *name = Tcl_GetString(objv[2]); 885 g_renderer->deletePolyData(name); 886 return TCL_OK; 887 } 888 889 static int 890 PolyDataColorOp(ClientData clientData, Tcl_Interp *interp, int objc, 891 Tcl_Obj *const *objv) 892 { 893 const char *name = Tcl_GetString(objv[5]); 894 float color[3]; 895 if (GetFloatFromObj(interp, objv[2], &color[0]) != TCL_OK || 896 GetFloatFromObj(interp, objv[3], &color[1]) != TCL_OK || 897 GetFloatFromObj(interp, objv[4], &color[2]) != TCL_OK) { 898 return TCL_ERROR; 899 } 900 g_renderer->setPolyDataColor(name, color); 901 return TCL_OK; 902 } 903 904 static int 905 PolyDataEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 906 Tcl_Obj *const *objv) 907 { 908 const char *name = Tcl_GetString(objv[3]); 909 bool state; 910 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 911 return TCL_ERROR; 912 } 913 g_renderer->setPolyDataEdgeVisibility(name, state); 914 return TCL_OK; 915 } 916 917 static int 918 PolyDataLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc, 919 Tcl_Obj *const *objv) 920 { 921 const char *name = Tcl_GetString(objv[5]); 922 float color[3]; 923 if (GetFloatFromObj(interp, objv[2], &color[0]) != TCL_OK || 924 GetFloatFromObj(interp, objv[3], &color[1]) != TCL_OK || 925 GetFloatFromObj(interp, objv[4], &color[2]) != TCL_OK) { 926 return TCL_ERROR; 927 } 928 g_renderer->setPolyDataEdgeColor(name, color); 929 return TCL_OK; 930 } 931 932 static int 933 PolyDataLineWidthOp(ClientData clientData, Tcl_Interp *interp, int objc, 934 Tcl_Obj *const *objv) 935 { 936 const char *name = Tcl_GetString(objv[3]); 937 float width; 938 if (GetFloatFromObj(interp, objv[2], &width) != TCL_OK) { 939 return TCL_ERROR; 940 } 941 g_renderer->setPolyDataEdgeWidth(name, width); 942 return TCL_OK; 943 } 944 945 static int 946 PolyDataVisibleOp(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->setPolyDataVisibility(name, state); 955 return TCL_OK; 956 } 957 958 static int 959 PolyDataWireframeOp(ClientData clientData, Tcl_Interp *interp, int objc, 960 Tcl_Obj *const *objv) 961 { 962 const char *name = Tcl_GetString(objv[3]); 963 bool state; 964 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 965 return TCL_ERROR; 966 } 967 g_renderer->setPolyDataWireframe(name, state); 968 return TCL_OK; 969 } 970 971 static Rappture::CmdSpec polyDataOps[] = { 972 {"add", 1, PolyDataAddOp, 3, 3, "dataSetName"}, 973 {"color", 1, PolyDataColorOp, 6, 6, "r g b dataSetName"}, 974 {"delete", 1, PolyDataDeleteOp, 3, 3, "dataSetName"}, 975 {"edges", 1, PolyDataEdgeVisibilityOp, 4, 4, "bool dataSetName"}, 976 {"linecolor", 5, PolyDataLineColorOp, 6, 6, "r g b dataSetName"}, 977 {"linewidth", 5, PolyDataLineWidthOp, 4, 4, "width dataSetName"}, 978 {"visible", 1, PolyDataVisibleOp, 4, 4, "bool dataSetName"}, 979 {"wireframe", 1, PolyDataWireframeOp, 4, 4, "bool dataSetName"} 980 }; 981 static int nPolyDataOps = NumCmdSpecs(polyDataOps); 982 983 static int 984 PolyDataCmd(ClientData clientData, Tcl_Interp *interp, int objc, 985 Tcl_Obj *const *objv) 986 { 987 Tcl_ObjCmdProc *proc; 988 989 proc = Rappture::GetOpFromObj(interp, nPolyDataOps, polyDataOps, 619 990 Rappture::CMDSPEC_ARG1, objc, objv, 0); 620 991 if (proc == NULL) { … … 739 1110 nBytes = strlen(string); 740 1111 struct iovec iov[3]; 741 iov[0].iov_base = (char *)" NanoVis Server Error: ";1112 iov[0].iov_base = (char *)"VtkVis Server Error: "; 742 1113 iov[0].iov_len = strlen((char *)iov[0].iov_base); 743 1114 iov[1].iov_base = (char *)string; … … 772 1143 Tcl_CreateObjCommand(interp, "contour2d", Contour2DCmd, NULL, NULL); 773 1144 Tcl_CreateObjCommand(interp, "dataset", DataSetCmd, NULL, NULL); 774 Tcl_CreateObjCommand(interp, "grid", GridCmd, NULL, NULL);775 1145 Tcl_CreateObjCommand(interp, "legend", LegendCmd, NULL, NULL); 1146 Tcl_CreateObjCommand(interp, "polydata", PolyDataCmd, NULL, NULL); 776 1147 Tcl_CreateObjCommand(interp, "pseudocolor", PseudoColorCmd, NULL, NULL); 777 1148 Tcl_CreateObjCommand(interp, "screen", ScreenCmd, NULL, NULL); -
trunk/packages/vizservers/vtkvis/protocol.txt
r2100 r2112 6 6 7 7 screen bgcolor <r> <g> <b> 8 screen <width> <height>8 screen size <width> <height> 9 9 10 axis visible <bool> 11 Affects both x/y axes 10 axis grid <bool> 11 axis name <axis> <title> 12 axis units <axis> <units> 13 Currently only supported when camera mode is not image mode 14 axis visible <axis> <bool> 15 <axis> = x|y|z|all 12 16 13 grid visible <bool> 14 Currently unimplemented 15 17 camera mode <mode> 18 <mode> = persp|ortho|image 16 19 camera ortho <x> <y> <width> <height> 17 Supply world coordinate bounds of plot area 20 Supply world coordinate bounds of plot area for image camera mode 21 Data is assumed to lie in XY plane (z = 0) 22 camera pan <x> <y> 23 <x,y> world coordinates 24 camera reset <?all?> 25 Option all resets orientation/rotation as well as pan/zoom/clip range 26 camera rotate <yaw> <pitch> <roll> 27 Specify relative rotation in Euler angles (FIXME) 28 camera zoom <z> 29 Specify zoom ratio 18 30 19 31 dataset add <datasetName> data follows <nbytes> 20 32 dataset delete <datasetName> 21 dataset visible <bool> <datasetName>22 dataset opacity <val> <datasetName>23 33 dataset getvalue world <x> <y> <z> <datasetName> 24 34 dataset getvalue pixel <x> <y> <datasetName> 35 Use pixel for image camera mode 36 dataset opacity <val> <datasetName> 37 dataset visible <bool> <datasetName> 25 38 26 colormap add <colorMapName> < map>27 map = Tcl list of rgba values (currently no ramp is used, so supply28 as many values as needed for lookup table)39 colormap add <colorMapName> <colorMap> <opacityMap> 40 colorMap = Tcl list of {value r g b} control points 41 opacityMap = Tcl list of {value alpha} control points 29 42 colormap delete <colorMapName> 30 43 31 44 legend <colormapName> <legendTitle> <width> <height> 45 Causes legend to be rendered and written back with labels and title 32 46 33 47 pseudocolor add <datasetName> 48 pseudocolor colormap <colormapName> <datasetName> 34 49 pseudocolor delete <datasetName> 35 pseudocolor colormap <colormapName> <datasetName> 50 pseudocolor edges <bool> <datasetName> 51 pseudocolor linecolor <r> <g> <b> <datasetName> 52 pseudocolor linewidth <val> <datasetName> 36 53 pseudocolor visible <bool> <datasetName> 37 54 … … 39 56 contour2d add contourlist <list> <datasetName> 40 57 list = {isoval1 isoval2 isoval3...} 58 contour2d delete <datasetName> 41 59 contour2d linecolor <r> <g> <b> <datasetName> 42 60 contour2d linewidth <val> <datasetName> 43 contour2d delete <datasetName>44 61 contour2d visible <bool> <datasetName> 62 63 polydata add <datasetName> 64 polydata color <r> <g> <b> <datasetName> 65 polydata delete <datasetName> 66 polydata edges <bool> <datasetName> 67 polydata linecolor <r> <g> <b> <datasetName> 68 polydata linewidth <val> <datasetName> 69 polydata visible <bool> <datasetName> 70 polydata wireframe <bool> <datasetName> 45 71 46 72 ================================================================================ … … 57 83 Errors: 58 84 59 Prefixed with " NanoVis Server Error: "85 Prefixed with "VtkVis Server Error: " 60 86 Currently not guaranteed to be on a single line
Note: See TracChangeset
for help on using the changeset viewer.