Changeset 2575 for trunk/packages/vizservers/vtkvis
- Timestamp:
- Sep 23, 2011, 6:54:41 PM (13 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/ReadBuffer.cpp
r2573 r2575 17 17 using namespace Rappture::VtkVis; 18 18 19 ReadBuffer::ReadBuffer(int f, size_t bufferSize) : 19 /** 20 * \param[in] fd File descriptor to read 21 * \param[in] bufferSize Block size to use in internal buffer 22 */ 23 ReadBuffer::ReadBuffer(int fd, size_t bufferSize) : 20 24 _bufferSize(bufferSize), 21 _fd(f ),25 _fd(fd), 22 26 _lastStatus(OK) 23 27 { … … 33 37 34 38 /** 35 * Checks if a new line is currently in the buffer. It returns 36 * the index of the character past the new line. 39 * \brief Checks if a new line is currently in the buffer. 40 * 41 * \return the index of the character past the new line. 37 42 */ 38 43 size_t … … 49 54 50 55 /** 51 * Fills the buffer with available data. Any existing data in the buffer 52 * is moved to the front of the buffer, then the channel is read to fill 53 * the rest of the buffer. 56 * \brief Fills the buffer with available data. 57 * 58 * Any existing data in the buffer is moved to the front of the buffer, 59 * then the channel is read to fill the rest of the buffer. 54 60 * 55 61 * \return If an error occur when reading the channel, then ERROR is … … 98 104 99 105 /** 100 * Read the requested number of bytes from the buffer. Fails if 101 * the requested number of bytes are not immediately available. 102 * Never should be short. 106 * \brief Read the requested number of bytes from the buffer. 107 108 * Fails if the requested number of bytes are not immediately 109 * available. Never should be short. 103 110 */ 104 111 ReadBuffer::BufferStatus … … 135 142 136 143 /** 137 * Returns the next available line (terminated by a newline). 144 * \brief Returns the next available line (terminated by a newline) 145 * 138 146 * If insufficient data is in the buffer, then the channel is 139 147 * read for more data. If reading the channel results in a 140 * short read, CONTINUE is returned and *numBytesPtr is set to 141 * 0. 148 * short read, CONTINUE is returned and *numBytesPtr is set to 0. 142 149 */ 143 150 ReadBuffer::BufferStatus -
trunk/packages/vizservers/vtkvis/ReadBuffer.h
r2573 r2575 14 14 namespace VtkVis { 15 15 16 /** 17 * \brief Buffered input for reading socket 18 */ 16 19 class ReadBuffer 17 20 { … … 24 27 }; 25 28 26 ReadBuffer(int f , size_t bufferSize);29 ReadBuffer(int fd, size_t bufferSize); 27 30 28 31 virtual ~ReadBuffer(); … … 32 35 BufferStatus followingData(unsigned char *out, size_t numBytes); 33 36 37 /** 38 * \brief Check if buffer contains data ending in a newline 39 * 40 * \return bool indicating if getLine can be called without blocking 41 */ 34 42 bool isLineAvailable() 35 43 { … … 37 45 } 38 46 47 /** 48 * \brief Get the file descriptor this object reads from 49 */ 39 50 int file() 40 51 { … … 42 53 } 43 54 55 /** 56 * \brief Get the status of the last read 57 */ 44 58 BufferStatus status() 45 59 { -
trunk/packages/vizservers/vtkvis/ResponseQueue.h
r2573 r2575 17 17 namespace VtkVis { 18 18 19 /** 20 * \brief Holds data for a response to be sent to client 21 */ 19 22 class Response 20 23 { … … 47 50 } 48 51 52 /// Get the ResponseType 49 53 ResponseType type() 50 54 { … … 52 56 } 53 57 58 /// Get the Response data 54 59 unsigned char *message() 55 60 { … … 57 62 } 58 63 64 /// Get the number of bytes in the Response data 59 65 size_t length() 60 66 { … … 62 68 } 63 69 70 /// Set the message/data making up the Response 71 /** 72 * If the AllocationType is DYNAMIC, the message data will be free()d 73 * by the destructor. If the AllocationType is VOLATILE, a copy of 74 * the message data will be made. 75 * 76 * \param[in] mesg The Response data, can be a command and/or binary data 77 * \param[in] length The number of bytes in mesg 78 * \param[in] type Specify how the memory was allocated for mesg 79 */ 64 80 void setMessage(unsigned char *mesg, size_t length, AllocationType type) 65 81 { … … 86 102 }; 87 103 104 /** 105 * \brief Queue to hold pending Responses to be sent to the client 106 * 107 * A semaphore and mutex are used to control access to the 108 * queue by a reader and writer thread 109 */ 88 110 class ResponseQueue 89 111 { … … 93 115 virtual ~ResponseQueue(); 94 116 117 /// A place to store a data pointer. Not used internally. 118 /* XXX: This probably doesn't belong here */ 95 119 void *clientData() 96 120 { … … 98 122 } 99 123 124 /// Add a response to the end of the queue 100 125 void enqueue(Response *response); 101 126 127 /// Remove a response from the front of the queue 102 128 Response *dequeue(); 103 129 -
trunk/packages/vizservers/vtkvis/RpCutplane.cpp
r2514 r2575 34 34 VtkGraphicsObject(), 35 35 _colorMode(COLOR_BY_SCALAR), 36 _colorMap(NULL), 37 _sliceAxis(Z_AXIS) 36 _colorMap(NULL) 38 37 { 39 38 } … … 79 78 } 80 79 80 /** 81 * \brief Create and initialize a VTK Prop to render the object 82 */ 83 void Cutplane::initProp() 84 { 85 if (_prop == NULL) { 86 _prop = vtkSmartPointer<vtkAssembly>::New(); 87 88 for (int i = 0; i < 3; i++) { 89 _actor[i] = vtkSmartPointer<vtkActor>::New(); 90 //_actor[i]->VisibilityOff(); 91 vtkProperty *property = _actor[i]->GetProperty(); 92 property->SetColor(_color[0], _color[1], _color[2]); 93 property->SetEdgeColor(_edgeColor[0], _edgeColor[1], _edgeColor[2]); 94 property->SetLineWidth(_edgeWidth); 95 property->SetPointSize(_pointSize); 96 property->EdgeVisibilityOff(); 97 property->SetOpacity(_opacity); 98 property->SetAmbient(.2); 99 if (!_lighting) 100 property->LightingOff(); 101 if (_faceCulling && _opacity == 1.0) { 102 setCulling(property, true); 103 } 104 getAssembly()->AddPart(_actor[i]); 105 } 106 } 107 } 108 81 109 void Cutplane::update() 82 110 { … … 86 114 vtkDataSet *ds = _dataSet->getVtkDataSet(); 87 115 116 double bounds[6]; 117 _dataSet->getBounds(bounds); 88 118 // Mapper, actor to render color-mapped data set 89 if (_mapper == NULL) { 90 _mapper = vtkSmartPointer<vtkDataSetMapper>::New(); 91 // Map scalars through lookup table regardless of type 92 _mapper->SetColorModeToMapScalars(); 93 //_mapper->InterpolateScalarsBeforeMappingOn(); 94 } 119 for (int i = 0; i < 3; i++) { 120 if (_mapper[i] == NULL) { 121 _mapper[i] = vtkSmartPointer<vtkDataSetMapper>::New(); 122 // Map scalars through lookup table regardless of type 123 _mapper[i]->SetColorModeToMapScalars(); 124 //_mapper->InterpolateScalarsBeforeMappingOn(); 125 } 126 _cutPlane[i] = vtkSmartPointer<vtkPlane>::New(); 127 switch (i) { 128 case 0: 129 _cutPlane[i]->SetNormal(1, 0, 0); 130 _cutPlane[i]->SetOrigin(bounds[0] + (bounds[1]-bounds[0])/2., 131 0, 132 0); 133 break; 134 case 1: 135 _cutPlane[i]->SetNormal(0, 1, 0); 136 _cutPlane[i]->SetOrigin(0, 137 bounds[2] + (bounds[3]-bounds[2])/2., 138 0); 139 break; 140 case 2: 141 default: 142 _cutPlane[i]->SetNormal(0, 0, 1); 143 _cutPlane[i]->SetOrigin(0, 144 0, 145 bounds[4] + (bounds[5]-bounds[4])/2.); 146 break; 147 } 148 _cutter[i] = vtkSmartPointer<vtkCutter>::New(); 149 _cutter[i]->SetCutFunction(_cutPlane[i]); 150 } 151 152 initProp(); 95 153 96 154 vtkPolyData *pd = vtkPolyData::SafeDownCast(ds); 97 if (pd) { 98 // DataSet is a vtkPolyData 99 if (pd->GetNumberOfLines() == 0 && 100 pd->GetNumberOfPolys() == 0 && 101 pd->GetNumberOfStrips() == 0) { 102 // DataSet is a point cloud 103 DataSet::PrincipalPlane plane; 104 double offset; 105 if (_dataSet->is2D(&plane, &offset)) { 106 // DataSet is a 2D point cloud 155 if (pd && 156 pd->GetNumberOfLines() == 0 && 157 pd->GetNumberOfPolys() == 0 && 158 pd->GetNumberOfStrips() == 0) { 159 // DataSet is a point cloud 160 DataSet::PrincipalPlane plane; 161 double offset; 162 if (_dataSet->is2D(&plane, &offset)) { 163 // DataSet is a 2D point cloud 107 164 #ifdef MESH_POINT_CLOUDS 108 vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New(); 109 if (plane == DataSet::PLANE_ZY) { 110 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 111 trans->RotateWXYZ(90, 0, 1, 0); 112 if (offset != 0.0) { 113 trans->Translate(-offset, 0, 0); 114 } 115 mesher->SetTransform(trans); 116 _sliceAxis = X_AXIS; 117 } else if (plane == DataSet::PLANE_XZ) { 118 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 119 trans->RotateWXYZ(-90, 1, 0, 0); 120 if (offset != 0.0) { 121 trans->Translate(0, -offset, 0); 122 } 123 mesher->SetTransform(trans); 124 _sliceAxis = Y_AXIS; 125 } else if (offset != 0.0) { 126 // XY with Z offset 127 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 128 trans->Translate(0, 0, -offset); 129 mesher->SetTransform(trans); 165 vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New(); 166 if (plane == DataSet::PLANE_ZY) { 167 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 168 trans->RotateWXYZ(90, 0, 1, 0); 169 if (offset != 0.0) { 170 trans->Translate(-offset, 0, 0); 130 171 } 131 mesher->SetInput(pd); 132 _mapper->SetInputConnection(mesher->GetOutputPort()); 172 mesher->SetTransform(trans); 173 _actor[1]->VisibilityOff(); 174 _actor[2]->VisibilityOff(); 175 } else if (plane == DataSet::PLANE_XZ) { 176 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 177 trans->RotateWXYZ(-90, 1, 0, 0); 178 if (offset != 0.0) { 179 trans->Translate(0, -offset, 0); 180 } 181 mesher->SetTransform(trans); 182 _actor[0]->VisibilityOff(); 183 _actor[2]->VisibilityOff(); 184 } else if (offset != 0.0) { 185 // XY with Z offset 186 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 187 trans->Translate(0, 0, -offset); 188 mesher->SetTransform(trans); 189 _actor[0]->VisibilityOff(); 190 _actor[1]->VisibilityOff(); 191 } 192 mesher->SetInput(pd); 193 for (int i = 0; i < 3; i++) { 194 _mapper[i]->SetInputConnection(mesher->GetOutputPort()); 195 } 133 196 #else 134 vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New(); 135 splatter->SetInput(pd); 136 int dims[3]; 137 splatter->GetSampleDimensions(dims); 138 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]); 197 vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New(); 198 splatter->SetInput(pd); 199 int dims[3]; 200 splatter->GetSampleDimensions(dims); 201 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]); 202 if (plane == DataSet::PLANE_ZY) { 203 dims[0] = 3; 204 } else if (plane == DataSet::PLANE_XZ) { 205 dims[1] = 3; 206 } else { 139 207 dims[2] = 3; 140 splatter->SetSampleDimensions(dims); 141 double bounds[6]; 142 splatter->Update(); 143 splatter->GetModelBounds(bounds); 144 TRACE("Model bounds: %g %g %g %g %g %g", 145 bounds[0], bounds[1], 146 bounds[2], bounds[3], 147 bounds[4], bounds[5]); 148 vtkSmartPointer<vtkExtractVOI> slicer = vtkSmartPointer<vtkExtractVOI>::New(); 149 slicer->SetInputConnection(splatter->GetOutputPort()); 150 slicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, 1, 1); 151 slicer->SetSampleRate(1, 1, 1); 208 } 209 splatter->SetSampleDimensions(dims); 210 for (int i = 0; i < 3; i++) { 211 _cutter[i]->SetInputConnection(splatter->GetOutputPort()); 152 212 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 153 213 gf->UseStripsOn(); 154 gf->SetInputConnection(slicer->GetOutputPort()); 155 _mapper->SetInputConnection(gf->GetOutputPort()); 214 gf->SetInputConnection(_cutter[i]->GetOutputPort()); 215 _mapper[i]->SetInputConnection(gf->GetOutputPort()); 216 } 156 217 #endif 157 218 } else { 158 219 #ifdef MESH_POINT_CLOUDS 159 // Data Set is a 3D point cloud 160 // Result of Delaunay3D mesher is unstructured grid 161 vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New(); 162 mesher->SetInput(pd); 163 // Run the mesher 164 mesher->Update(); 165 // Get bounds of resulting grid 166 double bounds[6]; 167 mesher->GetOutput()->GetBounds(bounds); 168 // Sample a plane within the grid bounding box 169 vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New(); 170 cutter->SetInputConnection(mesher->GetOutputPort()); 171 if (_cutPlane == NULL) { 172 _cutPlane = vtkSmartPointer<vtkPlane>::New(); 173 } 174 _cutPlane->SetNormal(0, 0, 1); 175 _cutPlane->SetOrigin(0, 176 0, 177 bounds[4] + (bounds[5]-bounds[4])/2.); 178 cutter->SetCutFunction(_cutPlane); 220 // Data Set is a 3D point cloud 221 // Result of Delaunay3D mesher is unstructured grid 222 vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New(); 223 mesher->SetInput(pd); 224 // Sample a plane within the grid bounding box 225 for (int i = 0; i < 3; i++) { 226 _cutter[i]->SetInputConnection(mesher->GetOutputPort()); 179 227 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 180 228 gf->UseStripsOn(); 181 gf->SetInputConnection(cutter->GetOutputPort()); 229 gf->SetInputConnection(_cutter[i]->GetOutputPort()); 230 _mapper[i]->SetInputConnection(gf->GetOutputPort()); 231 } 182 232 #else 183 if (_pointSplatter == NULL) 184 _pointSplatter = vtkSmartPointer<vtkGaussianSplatter>::New(); 185 _pointSplatter->SetInput(pd); 186 int dims[3]; 187 _pointSplatter->GetSampleDimensions(dims); 188 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]); 189 dims[2] = 3; 190 _pointSplatter->SetSampleDimensions(dims); 191 double bounds[6]; 192 _pointSplatter->Update(); 193 _pointSplatter->GetModelBounds(bounds); 194 TRACE("Model bounds: %g %g %g %g %g %g", 195 bounds[0], bounds[1], 196 bounds[2], bounds[3], 197 bounds[4], bounds[5]); 198 if (_volumeSlicer == NULL) 199 _volumeSlicer = vtkSmartPointer<vtkExtractVOI>::New(); 200 _volumeSlicer->SetInputConnection(_pointSplatter->GetOutputPort()); 201 _volumeSlicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, 1, 1); 202 _volumeSlicer->SetSampleRate(1, 1, 1); 233 vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New(); 234 splatter->SetInput(pd); 235 int dims[3]; 236 splatter->GetSampleDimensions(dims); 237 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]); 238 for (int i = 0; i < 3; i++) { 239 _cutter[i]->SetInputConnection(splatter->GetOutputPort()); 203 240 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 204 241 gf->UseStripsOn(); 205 gf->SetInputConnection(_volumeSlicer->GetOutputPort()); 242 gf->SetInputConnection(_cutter[i]->GetOutputPort()); 243 _mapper[i]->SetInputConnection(gf->GetOutputPort()); 244 } 206 245 #endif 207 _mapper->SetInputConnection(gf->GetOutputPort());208 }209 } else {210 // DataSet is a vtkPolyData with lines and/or polygons211 _mapper->SetInput(ds);212 246 } 213 247 } else { 214 // DataSet is NOT a vtkPolyData 215 // Can be: image/volume/uniform grid, structured grid, unstructured grid, rectilinear grid 216 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 217 gf->UseStripsOn(); 218 vtkImageData *imageData = vtkImageData::SafeDownCast(ds); 219 if (!_dataSet->is2D() && imageData != NULL) { 220 // 3D image/volume/uniform grid 221 if (_volumeSlicer == NULL) 222 _volumeSlicer = vtkSmartPointer<vtkExtractVOI>::New(); 223 int dims[3]; 224 imageData->GetDimensions(dims); 225 TRACE("Image data dimensions: %d %d %d", dims[0], dims[1], dims[2]); 226 _volumeSlicer->SetInput(ds); 227 _volumeSlicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, (dims[2]-1)/2, (dims[2]-1)/2); 228 _volumeSlicer->SetSampleRate(1, 1, 1); 229 gf->SetInputConnection(_volumeSlicer->GetOutputPort()); 230 } else if (!_dataSet->is2D() && imageData == NULL) { 231 // 3D structured grid, unstructured grid, or rectilinear grid 232 double bounds[6]; 233 ds->GetBounds(bounds); 248 // DataSet can be: image/volume/uniform grid, structured grid, unstructured grid, rectilinear grid, or 249 // PolyData with cells other than points 250 DataSet::PrincipalPlane plane; 251 double offset; 252 if (!_dataSet->is2D(&plane, &offset)) { 234 253 // Sample a plane within the grid bounding box 235 vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New(); 236 cutter->SetInput(ds); 237 if (_cutPlane == NULL) { 238 _cutPlane = vtkSmartPointer<vtkPlane>::New(); 239 } 240 _cutPlane->SetNormal(0, 0, 1); 241 _cutPlane->SetOrigin(0, 242 0, 243 bounds[4] + (bounds[5]-bounds[4])/2.); 244 cutter->SetCutFunction(_cutPlane); 245 gf->SetInputConnection(cutter->GetOutputPort()); 254 for (int i = 0; i < 3; i++) { 255 _cutter[i]->SetInput(ds); 256 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 257 gf->UseStripsOn(); 258 gf->SetInputConnection(_cutter[i]->GetOutputPort()); 259 _mapper[i]->SetInputConnection(gf->GetOutputPort()); 260 } 246 261 } else { 247 262 // 2D data 248 gf->SetInput(ds); 249 } 250 _mapper->SetInputConnection(gf->GetOutputPort()); 263 if (plane == DataSet::PLANE_ZY) { 264 _actor[1]->VisibilityOff(); 265 _actor[2]->VisibilityOff(); 266 } else if (plane == DataSet::PLANE_XZ) { 267 _actor[0]->VisibilityOff(); 268 _actor[2]->VisibilityOff(); 269 } else if (offset != 0.0) { 270 // XY with Z offset 271 _actor[0]->VisibilityOff(); 272 _actor[1]->VisibilityOff(); 273 } 274 for (int i = 0; i < 3; i++) { 275 vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); 276 gf->UseStripsOn(); 277 gf->SetInput(ds); 278 _mapper[i]->SetInputConnection(gf->GetOutputPort()); 279 } 280 } 251 281 } 252 282 … … 255 285 } 256 286 257 initProp(); 258 getActor()->SetMapper(_mapper); 259 _mapper->Update(); 287 for (int i = 0; i < 3; i++) { 288 if (_mapper[i] != NULL) { 289 _actor[i]->SetMapper(_mapper[i]); 290 _mapper[i]->Update(); 291 } 292 } 260 293 } 261 294 … … 274 307 } 275 308 276 if (_volumeSlicer == NULL && 277 _cutPlane == NULL) { 309 if ((axis == X_AXIS &&_cutPlane[0] == NULL) || 310 (axis == Y_AXIS &&_cutPlane[1] == NULL) || 311 (axis == Z_AXIS &&_cutPlane[2] == NULL)) { 278 312 WARN("Called before update() or DataSet is not a volume"); 279 313 return; 280 314 } 281 315 282 _sliceAxis = axis; 283 284 if (_cutPlane != NULL) { 285 double bounds[6]; 286 _dataSet->getBounds(bounds); 287 switch (axis) { 288 case X_AXIS: 289 _cutPlane->SetNormal(1, 0, 0); 290 _cutPlane->SetOrigin(bounds[0] + (bounds[1]-bounds[0]) * ratio, 291 0, 292 0); 293 break; 294 case Y_AXIS: 295 _cutPlane->SetNormal(0, 1, 0); 296 _cutPlane->SetOrigin(0, 297 bounds[2] + (bounds[3]-bounds[2]) * ratio, 298 0); 299 break; 300 case Z_AXIS: 301 _cutPlane->SetNormal(0, 0, 1); 302 _cutPlane->SetOrigin(0, 303 0, 304 bounds[4] + (bounds[5]-bounds[4]) * ratio); 305 break; 306 default: 307 ERROR("Invalid Axis"); 308 return; 309 } 310 } else { 311 int dims[3]; 312 if (_pointSplatter != NULL) { 313 _pointSplatter->GetSampleDimensions(dims); 314 } else { 315 vtkImageData *imageData = vtkImageData::SafeDownCast(_dataSet->getVtkDataSet()); 316 if (imageData == NULL) { 317 ERROR("Not a volume data set"); 318 return; 319 } 320 imageData->GetDimensions(dims); 321 } 322 int voi[6]; 323 324 switch (axis) { 325 case X_AXIS: 326 voi[0] = voi[1] = (int)((dims[0]-1) * ratio); 327 voi[2] = 0; 328 voi[3] = dims[1]-1; 329 voi[4] = 0; 330 voi[5] = dims[2]-1; 331 break; 332 case Y_AXIS: 333 voi[0] = 0; 334 voi[1] = dims[0]-1; 335 voi[2] = voi[3] = (int)((dims[1]-1) * ratio); 336 voi[4] = 0; 337 voi[5] = dims[2]-1; 338 break; 339 case Z_AXIS: 340 voi[0] = 0; 341 voi[1] = dims[0]-1; 342 voi[2] = 0; 343 voi[3] = dims[1]-1; 344 voi[4] = voi[5] = (int)((dims[2]-1) * ratio); 345 break; 346 default: 347 ERROR("Invalid Axis"); 348 return; 349 } 350 351 _volumeSlicer->SetVOI(voi); 352 } 353 354 if (_mapper != NULL) 355 _mapper->Update(); 316 double bounds[6]; 317 _dataSet->getBounds(bounds); 318 switch (axis) { 319 case X_AXIS: 320 _cutPlane[0]->SetOrigin(bounds[0] + (bounds[1]-bounds[0]) * ratio, 321 0, 322 0); 323 if (_mapper[0] != NULL) 324 _mapper[0]->Update(); 325 break; 326 case Y_AXIS: 327 _cutPlane[1]->SetOrigin(0, 328 bounds[2] + (bounds[3]-bounds[2]) * ratio, 329 0); 330 if (_mapper[1] != NULL) 331 _mapper[1]->Update(); 332 break; 333 case Z_AXIS: 334 _cutPlane[2]->SetOrigin(0, 335 0, 336 bounds[4] + (bounds[5]-bounds[4]) * ratio); 337 if (_mapper[2] != NULL) 338 _mapper[2]->Update(); 339 break; 340 default: 341 ERROR("Invalid Axis"); 342 return; 343 } 356 344 } 357 345 … … 385 373 { 386 374 _colorMode = mode; 387 if (_dataSet == NULL || _mapper == NULL) 375 if (_dataSet == NULL || 376 _mapper[0] == NULL || 377 _mapper[1] == NULL || 378 _mapper[2] == NULL) 388 379 return; 389 380 … … 392 383 switch (mode) { 393 384 case COLOR_BY_SCALAR: { 394 _mapper->ScalarVisibilityOn(); 395 _mapper->SetScalarModeToDefault(); 385 for (int i = 0; i < 3; i++) { 386 _mapper[i]->ScalarVisibilityOn(); 387 _mapper[i]->SetScalarModeToDefault(); 388 } 396 389 if (_lut != NULL) { 397 390 _lut->SetRange(_dataRange); … … 400 393 break; 401 394 case COLOR_BY_VECTOR_MAGNITUDE: { 402 _mapper->ScalarVisibilityOn(); 395 for (int i = 0; i < 3; i++) { 396 _mapper[i]->ScalarVisibilityOn(); 397 } 403 398 if (ds->GetPointData() != NULL && 404 399 ds->GetPointData()->GetVectors() != NULL) { 405 _mapper->SetScalarModeToUsePointFieldData(); 406 _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 400 for (int i = 0; i < 3; i++) { 401 _mapper[i]->SetScalarModeToUsePointFieldData(); 402 _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 403 } 407 404 } else if (ds->GetCellData() != NULL && 408 405 ds->GetCellData()->GetVectors() != NULL) { 409 _mapper->SetScalarModeToUseCellFieldData(); 410 _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 406 for (int i = 0; i < 3; i++) { 407 _mapper[i]->SetScalarModeToUseCellFieldData(); 408 _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 409 } 411 410 } 412 411 if (_lut != NULL) { … … 417 416 break; 418 417 case COLOR_BY_VECTOR_X: 419 _mapper->ScalarVisibilityOn(); 418 for (int i = 0; i < 3; i++) { 419 _mapper[i]->ScalarVisibilityOn(); 420 } 420 421 if (ds->GetPointData() != NULL && 421 422 ds->GetPointData()->GetVectors() != NULL) { 422 _mapper->SetScalarModeToUsePointFieldData(); 423 _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 423 for (int i = 0; i < 3; i++) { 424 _mapper[i]->SetScalarModeToUsePointFieldData(); 425 _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 426 } 424 427 } else if (ds->GetCellData() != NULL && 425 428 ds->GetCellData()->GetVectors() != NULL) { 426 _mapper->SetScalarModeToUseCellFieldData(); 427 _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 429 for (int i = 0; i < 3; i++) { 430 _mapper[i]->SetScalarModeToUseCellFieldData(); 431 _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 432 } 428 433 } 429 434 if (_lut != NULL) { … … 434 439 break; 435 440 case COLOR_BY_VECTOR_Y: 436 _mapper->ScalarVisibilityOn(); 441 for (int i = 0; i < 3; i++) { 442 _mapper[i]->ScalarVisibilityOn(); 443 } 437 444 if (ds->GetPointData() != NULL && 438 445 ds->GetPointData()->GetVectors() != NULL) { 439 _mapper->SetScalarModeToUsePointFieldData(); 440 _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 446 for (int i = 0; i < 3; i++) { 447 _mapper[i]->SetScalarModeToUsePointFieldData(); 448 _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 449 } 441 450 } else if (ds->GetCellData() != NULL && 442 451 ds->GetCellData()->GetVectors() != NULL) { 443 _mapper->SetScalarModeToUseCellFieldData(); 444 _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 452 for (int i = 0; i < 3; i++) { 453 _mapper[i]->SetScalarModeToUseCellFieldData(); 454 _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 455 } 445 456 } 446 457 if (_lut != NULL) { … … 451 462 break; 452 463 case COLOR_BY_VECTOR_Z: 453 _mapper->ScalarVisibilityOn(); 464 for (int i = 0; i < 3; i++) { 465 _mapper[i]->ScalarVisibilityOn(); 466 } 454 467 if (ds->GetPointData() != NULL && 455 468 ds->GetPointData()->GetVectors() != NULL) { 456 _mapper->SetScalarModeToUsePointFieldData(); 457 _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 469 for (int i = 0; i < 3; i++) { 470 _mapper[i]->SetScalarModeToUsePointFieldData(); 471 _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName()); 472 } 458 473 } else if (ds->GetCellData() != NULL && 459 474 ds->GetCellData()->GetVectors() != NULL) { 460 _mapper->SetScalarModeToUseCellFieldData(); 461 _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 475 for (int i = 0; i < 3; i++) { 476 _mapper[i]->SetScalarModeToUseCellFieldData(); 477 _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName()); 478 } 462 479 } 463 480 if (_lut != NULL) { … … 468 485 break; 469 486 default: 470 _mapper->ScalarVisibilityOff(); 487 for (int i = 0; i < 3; i++) { 488 _mapper[i]->ScalarVisibilityOff(); 489 } 471 490 break; 472 491 } … … 493 512 if (_lut == NULL) { 494 513 _lut = vtkSmartPointer<vtkLookupTable>::New(); 495 if (_mapper != NULL) { 496 _mapper->UseLookupTableScalarRangeOn(); 497 _mapper->SetLookupTable(_lut); 514 for (int i = 0; i < 3; i++) { 515 if (_mapper[i] != NULL) { 516 _mapper[i]->UseLookupTableScalarRangeOn(); 517 _mapper[i]->SetLookupTable(_lut); 518 } 498 519 } 499 520 } … … 530 551 531 552 /** 553 * \brief Set visibility of cutplane on specified axis 554 */ 555 void Cutplane::setSliceVisibility(Axis axis, bool state) 556 { 557 switch (axis) { 558 case X_AXIS: 559 if (_actor[0] != NULL) 560 _actor[0]->SetVisibility((state ? 1 : 0)); 561 break; 562 case Y_AXIS: 563 if (_actor[1] != NULL) 564 _actor[1]->SetVisibility((state ? 1 : 0)); 565 break; 566 case Z_AXIS: 567 default: 568 if (_actor[2] != NULL) 569 _actor[2]->SetVisibility((state ? 1 : 0)); 570 break; 571 } 572 } 573 574 /** 532 575 * \brief Set a group of world coordinate planes to clip rendering 533 576 * … … 536 579 void Cutplane::setClippingPlanes(vtkPlaneCollection *planes) 537 580 { 538 if (_mapper != NULL) { 539 _mapper->SetClippingPlanes(planes); 540 } 541 } 581 for (int i = 0; i < 3; i++) { 582 if (_mapper[i] != NULL) { 583 _mapper[i]->SetClippingPlanes(planes); 584 } 585 } 586 } -
trunk/packages/vizservers/vtkvis/RpCutplane.h
r2514 r2575 14 14 #include <vtkActor.h> 15 15 #include <vtkPlaneCollection.h> 16 #include <vtkGaussianSplatter.h> 17 #include <vtkExtractVOI.h> 16 #include <vtkCutter.h> 18 17 #include <vtkPlane.h> 19 18 … … 62 61 void selectVolumeSlice(Axis axis, double ratio); 63 62 63 void setSliceVisibility(Axis axis, bool state); 64 64 65 void setColorMode(ColorMode mode); 65 66 … … 82 83 83 84 private: 85 virtual void initProp(); 84 86 virtual void update(); 85 87 86 88 ColorMode _colorMode; 87 89 ColorMap *_colorMap; 88 Axis _sliceAxis;89 90 double _vectorMagnitudeRange[2]; 90 91 double _vectorComponentRange[3][2]; 91 92 92 93 vtkSmartPointer<vtkLookupTable> _lut; 93 vtkSmartPointer<vtk DataSetMapper> _mapper;94 vtkSmartPointer<vtk GaussianSplatter> _pointSplatter;95 vtkSmartPointer<vtk ExtractVOI> _volumeSlicer;96 vtkSmartPointer<vtkPlane> _cutPlane ;94 vtkSmartPointer<vtkActor> _actor[3]; 95 vtkSmartPointer<vtkDataSetMapper> _mapper[3]; 96 vtkSmartPointer<vtkCutter> _cutter[3]; 97 vtkSmartPointer<vtkPlane> _cutPlane[3]; 97 98 }; 98 99 -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp
r2533 r2575 2776 2776 } while (doAll && ++itr != _dataSets.end()); 2777 2777 2778 initCamera(); 2778 2779 _needsRedraw = true; 2779 2780 return true; … … 2959 2960 do { 2960 2961 itr->second->selectVolumeSlice(axis, ratio); 2962 } while (doAll && ++itr != _cutplanes.end()); 2963 2964 _renderer->ResetCameraClippingRange(); 2965 _needsRedraw = true; 2966 } 2967 2968 /** 2969 * \brief Set the visibility of slices in one of the three axes 2970 */ 2971 void Renderer::setCutplaneSliceVisibility(const DataSetId& id, Cutplane::Axis axis, bool state) 2972 { 2973 CutplaneHashmap::iterator itr; 2974 2975 bool doAll = false; 2976 2977 if (id.compare("all") == 0) { 2978 itr = _cutplanes.begin(); 2979 doAll = true; 2980 } else { 2981 itr = _cutplanes.find(id); 2982 } 2983 2984 if (itr == _cutplanes.end()) { 2985 ERROR("Cutplane not found: %s", id.c_str()); 2986 return; 2987 } 2988 2989 do { 2990 itr->second->setSliceVisibility(axis, state); 2961 2991 } while (doAll && ++itr != _cutplanes.end()); 2962 2992 -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.h
r2514 r2575 376 376 377 377 void setCutplaneVolumeSlice(const DataSetId& id, Cutplane::Axis axis, double ratio); 378 379 void setCutplaneSliceVisibility(const DataSetId& id, Cutplane::Axis axis, bool state); 378 380 379 381 void setCutplaneColorMap(const DataSetId& id, const ColorMapId& colorMapId); -
trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp
r2573 r2575 1512 1512 1513 1513 static int 1514 Cutplane VisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,1515 Tcl_Obj *const *objv)1514 CutplaneSliceVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc, 1515 Tcl_Obj *const *objv) 1516 1516 { 1517 1517 bool state; 1518 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 1519 return TCL_ERROR; 1520 } 1521 if (objc == 4) { 1522 const char *name = Tcl_GetString(objv[3]); 1523 g_renderer->setCutplaneVisibility(name, state); 1524 } else { 1525 g_renderer->setCutplaneVisibility("all", state); 1526 } 1527 return TCL_OK; 1528 } 1529 1530 static int 1531 CutplaneVolumeSliceOp(ClientData clientData, Tcl_Interp *interp, int objc, 1532 Tcl_Obj *const *objv) 1533 { 1534 double ratio; 1535 if (Tcl_GetDoubleFromObj(interp, objv[3], &ratio) != TCL_OK) { 1518 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 1536 1519 return TCL_ERROR; 1537 1520 } … … 1547 1530 } else { 1548 1531 Tcl_AppendResult(interp, "bad axis option \"", string, 1532 "\": should be axisName bool", (char*)NULL); 1533 return TCL_ERROR; 1534 } 1535 if (objc == 5) { 1536 const char *name = Tcl_GetString(objv[4]); 1537 g_renderer->setCutplaneSliceVisibility(name, axis, state); 1538 } else { 1539 g_renderer->setCutplaneSliceVisibility("all", axis, state); 1540 } 1541 return TCL_OK; 1542 } 1543 1544 static int 1545 CutplaneVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc, 1546 Tcl_Obj *const *objv) 1547 { 1548 bool state; 1549 if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) { 1550 return TCL_ERROR; 1551 } 1552 if (objc == 4) { 1553 const char *name = Tcl_GetString(objv[3]); 1554 g_renderer->setCutplaneVisibility(name, state); 1555 } else { 1556 g_renderer->setCutplaneVisibility("all", state); 1557 } 1558 return TCL_OK; 1559 } 1560 1561 static int 1562 CutplaneVolumeSliceOp(ClientData clientData, Tcl_Interp *interp, int objc, 1563 Tcl_Obj *const *objv) 1564 { 1565 double ratio; 1566 if (Tcl_GetDoubleFromObj(interp, objv[3], &ratio) != TCL_OK) { 1567 return TCL_ERROR; 1568 } 1569 const char *string = Tcl_GetString(objv[2]); 1570 char c = string[0]; 1571 Cutplane::Axis axis; 1572 if ((c == 'x') && (strcmp(string, "x") == 0)) { 1573 axis = Cutplane::X_AXIS; 1574 } else if ((c == 'y') && (strcmp(string, "y") == 0)) { 1575 axis = Cutplane::Y_AXIS; 1576 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 1577 axis = Cutplane::Z_AXIS; 1578 } else { 1579 Tcl_AppendResult(interp, "bad axis option \"", string, 1549 1580 "\": should be axisName ratio", (char*)NULL); 1550 1581 return TCL_ERROR; … … 1577 1608 1578 1609 static Rappture::CmdSpec cutplaneOps[] = { 1579 {"add", 1, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"}, 1610 {"add", 2, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"}, 1611 {"axis", 2, CutplaneSliceVisibilityOp, 4, 5, "axis bool ?dataSetName?"}, 1580 1612 {"colormap", 7, CutplaneColorMapOp, 3, 4, "colorMapName ?dataSetName?"}, 1581 1613 {"colormode", 7, CutplaneColorModeOp, 3, 4, "mode ?dataSetNme?"}, -
trunk/packages/vizservers/vtkvis/protocol.txt
r2514 r2575 145 145 146 146 cutplane add <?dataSetName?> 147 cutplane axis <axis> <bool> <?dataSetName?> 148 Toggle visibility of the 3 principal axis cutplanes 147 149 cutplane colormap <colorMapName> <?dataSetName?> 148 150 cutplane colormode <scalar|vmag|vx|vy|vz> <?datasetName?>
Note: See TracChangeset
for help on using the changeset viewer.