VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkFixedPointVolumeRayCastMapper.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00061 #ifndef __vtkFixedPointVolumeRayCastMapper_h 00062 #define __vtkFixedPointVolumeRayCastMapper_h 00063 00064 #include "vtkVolumeMapper.h" 00065 00066 #define VTKKW_FP_SHIFT 15 00067 #define VTKKW_FPMM_SHIFT 17 00068 #define VTKKW_FP_MASK 0x7fff 00069 #define VTKKW_FP_SCALE 32767.0 00070 00071 class vtkMatrix4x4; 00072 class vtkMultiThreader; 00073 class vtkPlaneCollection; 00074 class vtkRenderer; 00075 class vtkTimerLog; 00076 class vtkVolume; 00077 class vtkTransform; 00078 class vtkRenderWindow; 00079 class vtkColorTransferFunction; 00080 class vtkPiecewiseFunction; 00081 class vtkFixedPointVolumeRayCastMIPHelper; 00082 class vtkFixedPointVolumeRayCastCompositeHelper; 00083 class vtkFixedPointVolumeRayCastCompositeGOHelper; 00084 class vtkFixedPointVolumeRayCastCompositeGOShadeHelper; 00085 class vtkFixedPointVolumeRayCastCompositeShadeHelper; 00086 class vtkDirectionEncoder; 00087 class vtkEncodedGradientShader; 00088 class vtkFiniteDifferenceGradientEstimator; 00089 class vtkRayCastImageDisplayHelper; 00090 class vtkFixedPointRayCastImage; 00091 class vtkDataArray; 00092 00093 //BTX 00094 // Forward declaration needed for use by friend declaration below. 00095 VTK_THREAD_RETURN_TYPE FixedPointVolumeRayCastMapper_CastRays( void *arg ); 00096 VTK_THREAD_RETURN_TYPE vtkFPVRCMSwitchOnDataType( void *arg ); 00097 //ETX 00098 00099 class VTK_VOLUMERENDERING_EXPORT vtkFixedPointVolumeRayCastMapper : public vtkVolumeMapper 00100 { 00101 public: 00102 static vtkFixedPointVolumeRayCastMapper *New(); 00103 vtkTypeMacro(vtkFixedPointVolumeRayCastMapper,vtkVolumeMapper); 00104 void PrintSelf( ostream& os, vtkIndent indent ); 00105 00107 00110 vtkSetMacro( SampleDistance, float ); 00111 vtkGetMacro( SampleDistance, float ); 00113 00115 00121 vtkSetMacro( InteractiveSampleDistance, float ); 00122 vtkGetMacro( InteractiveSampleDistance, float ); 00124 00126 00131 vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f ); 00132 vtkGetMacro( ImageSampleDistance, float ); 00134 00136 00138 vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f ); 00139 vtkGetMacro( MinimumImageSampleDistance, float ); 00141 00143 00145 vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f ); 00146 vtkGetMacro( MaximumImageSampleDistance, float ); 00148 00150 00157 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 00158 vtkGetMacro( AutoAdjustSampleDistances, int ); 00159 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 00161 00163 00170 vtkSetClampMacro( LockSampleDistanceToInputSpacing, int, 0, 1 ); 00171 vtkGetMacro( LockSampleDistanceToInputSpacing, int ); 00172 vtkBooleanMacro( LockSampleDistanceToInputSpacing, int ); 00174 00176 00178 void SetNumberOfThreads( int num ); 00179 int GetNumberOfThreads(); 00181 00183 00185 vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 ); 00186 vtkGetMacro( IntermixIntersectingGeometry, int ); 00187 vtkBooleanMacro( IntermixIntersectingGeometry, int ); 00189 00191 00197 float ComputeRequiredImageSampleDistance( float desiredTime, 00198 vtkRenderer *ren ); 00199 float ComputeRequiredImageSampleDistance( float desiredTime, 00200 vtkRenderer *ren, 00201 vtkVolume *vol ); 00203 00204 //BTX 00207 void Render( vtkRenderer *, vtkVolume * ); 00208 00209 unsigned int ToFixedPointPosition( float val ); 00210 void ToFixedPointPosition( float in[3], unsigned int out[3] ); 00211 unsigned int ToFixedPointDirection( float dir ); 00212 void ToFixedPointDirection( float in[3], unsigned int out[3] ); 00213 void FixedPointIncrement( unsigned int position[3], unsigned int increment[3] ); 00214 void GetFloatTripleFromPointer( float v[3], float *ptr ); 00215 void GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr ); 00216 void ShiftVectorDown( unsigned int in[3], unsigned int out[3] ); 00217 int CheckMinMaxVolumeFlag( unsigned int pos[3], int c ); 00218 int CheckMIPMinMaxVolumeFlag( unsigned int pos[3], int c, unsigned short maxIdx, int flip ); 00219 00220 void LookupColorUC( unsigned short *colorTable, 00221 unsigned short *scalarOpacityTable, 00222 unsigned short index, 00223 unsigned char color[4] ); 00224 void LookupDependentColorUC( unsigned short *colorTable, 00225 unsigned short *scalarOpacityTable, 00226 unsigned short index[4], 00227 int components, 00228 unsigned char color[4] ); 00229 void LookupAndCombineIndependentColorsUC( 00230 unsigned short *colorTable[4], 00231 unsigned short *scalarOpacityTable[4], 00232 unsigned short index[4], 00233 float weights[4], 00234 int components, 00235 unsigned char color[4] ); 00236 int CheckIfCropped( unsigned int pos[3] ); 00237 00238 //ETX 00239 00240 vtkGetObjectMacro( RenderWindow, vtkRenderWindow ); 00241 vtkGetObjectMacro( MIPHelper, vtkFixedPointVolumeRayCastMIPHelper ); 00242 vtkGetObjectMacro( CompositeHelper, vtkFixedPointVolumeRayCastCompositeHelper ); 00243 vtkGetObjectMacro( CompositeGOHelper, vtkFixedPointVolumeRayCastCompositeGOHelper ); 00244 vtkGetObjectMacro( CompositeGOShadeHelper, vtkFixedPointVolumeRayCastCompositeGOShadeHelper ); 00245 vtkGetObjectMacro( CompositeShadeHelper, vtkFixedPointVolumeRayCastCompositeShadeHelper ); 00246 vtkGetVectorMacro( TableShift, float, 4 ); 00247 vtkGetVectorMacro( TableScale, float, 4 ); 00248 vtkGetMacro( ShadingRequired, int ); 00249 vtkGetMacro( GradientOpacityRequired, int ); 00250 00251 vtkGetObjectMacro( CurrentScalars, vtkDataArray ); 00252 vtkGetObjectMacro( PreviousScalars, vtkDataArray ); 00253 00254 00255 int *GetRowBounds() {return this->RowBounds;} 00256 unsigned short *GetColorTable(int c) {return this->ColorTable[c];} 00257 unsigned short *GetScalarOpacityTable(int c) {return this->ScalarOpacityTable[c];} 00258 unsigned short *GetGradientOpacityTable(int c) {return this->GradientOpacityTable[c];} 00259 vtkVolume *GetVolume() {return this->Volume;} 00260 unsigned short **GetGradientNormal() {return this->GradientNormal;} 00261 unsigned char **GetGradientMagnitude() {return this->GradientMagnitude;} 00262 unsigned short *GetDiffuseShadingTable(int c) {return this->DiffuseShadingTable[c];} 00263 unsigned short *GetSpecularShadingTable(int c) {return this->SpecularShadingTable[c];} 00264 00265 void ComputeRayInfo( int x, int y, 00266 unsigned int pos[3], 00267 unsigned int dir[3], 00268 unsigned int *numSteps ); 00269 00270 void InitializeRayInfo( vtkVolume *vol ); 00271 00272 int ShouldUseNearestNeighborInterpolation( vtkVolume *vol ); 00273 00275 00278 void SetRayCastImage( vtkFixedPointRayCastImage * ); 00279 vtkGetObjectMacro( RayCastImage, vtkFixedPointRayCastImage ); 00281 00282 int PerImageInitialization( vtkRenderer *, vtkVolume *, int, 00283 double *, double *, int * ); 00284 void PerVolumeInitialization( vtkRenderer *, vtkVolume * ); 00285 void PerSubVolumeInitialization( vtkRenderer *, vtkVolume *, int ); 00286 void RenderSubVolume(); 00287 void DisplayRenderedImage( vtkRenderer *, vtkVolume * ); 00288 void AbortRender(); 00289 00290 void CreateCanonicalView( vtkVolume *volume, 00291 vtkImageData *image, 00292 int blend_mode, 00293 double viewDirection[3], 00294 double viewUp[3] ); 00295 00297 00301 float GetEstimatedRenderTime( vtkRenderer *ren, 00302 vtkVolume *vol ) 00303 { return this->RetrieveRenderTime( ren, vol ); } 00304 float GetEstimatedRenderTime( vtkRenderer *ren ) 00305 { return this->RetrieveRenderTime( ren ); } 00307 00308 00310 00316 vtkSetMacro( FinalColorWindow, float ); 00317 vtkGetMacro( FinalColorWindow, float ); 00318 vtkSetMacro( FinalColorLevel, float ); 00319 vtkGetMacro( FinalColorLevel, float ); 00321 00322 00323 // Here to be used by the mapper to tell the helper 00324 // to flip the MIP comparison in order to support 00325 // minimum intensity blending 00326 vtkGetMacro( FlipMIPComparison, int ); 00327 00328 protected: 00329 vtkFixedPointVolumeRayCastMapper(); 00330 ~vtkFixedPointVolumeRayCastMapper(); 00331 00332 // The helper class that displays the image 00333 vtkRayCastImageDisplayHelper *ImageDisplayHelper; 00334 00335 // The distance between sample points along the ray 00336 float SampleDistance; 00337 float InteractiveSampleDistance; 00338 00339 // The distance between rays in the image 00340 float ImageSampleDistance; 00341 float MinimumImageSampleDistance; 00342 float MaximumImageSampleDistance; 00343 int AutoAdjustSampleDistances; 00344 int LockSampleDistanceToInputSpacing; 00345 00346 // Saved values used to restore 00347 float OldSampleDistance; 00348 float OldImageSampleDistance; 00349 00350 // Internal method for computing matrices needed during 00351 // ray casting 00352 void ComputeMatrices( double volumeOrigin[3], 00353 double volumeSpacing[3], 00354 int volumeExtent[6], 00355 vtkRenderer *ren, 00356 vtkVolume *vol ); 00357 00358 int ComputeRowBounds( vtkRenderer *ren, 00359 int imageFlag, int rowBoundsFlag, 00360 int volumeExtent[6]); 00361 00362 void CaptureZBuffer( vtkRenderer *ren ); 00363 00364 friend VTK_THREAD_RETURN_TYPE FixedPointVolumeRayCastMapper_CastRays( void *arg ); 00365 friend VTK_THREAD_RETURN_TYPE vtkFPVRCMSwitchOnDataType( void *arg ); 00366 00367 vtkMultiThreader *Threader; 00368 00369 vtkMatrix4x4 *PerspectiveMatrix; 00370 vtkMatrix4x4 *ViewToWorldMatrix; 00371 vtkMatrix4x4 *ViewToVoxelsMatrix; 00372 vtkMatrix4x4 *VoxelsToViewMatrix; 00373 vtkMatrix4x4 *WorldToVoxelsMatrix; 00374 vtkMatrix4x4 *VoxelsToWorldMatrix; 00375 00376 vtkMatrix4x4 *VolumeMatrix; 00377 00378 vtkTransform *PerspectiveTransform; 00379 vtkTransform *VoxelsTransform; 00380 vtkTransform *VoxelsToViewTransform; 00381 00382 // This object encapsulated the image and all related information 00383 vtkFixedPointRayCastImage *RayCastImage; 00384 00385 int *RowBounds; 00386 int *OldRowBounds; 00387 00388 float *RenderTimeTable; 00389 vtkVolume **RenderVolumeTable; 00390 vtkRenderer **RenderRendererTable; 00391 int RenderTableSize; 00392 int RenderTableEntries; 00393 00394 void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t ); 00395 float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol ); 00396 float RetrieveRenderTime( vtkRenderer *ren ); 00397 00398 int IntermixIntersectingGeometry; 00399 00400 float MinimumViewDistance; 00401 00402 vtkColorTransferFunction *SavedRGBFunction[4]; 00403 vtkPiecewiseFunction *SavedGrayFunction[4]; 00404 vtkPiecewiseFunction *SavedScalarOpacityFunction[4]; 00405 vtkPiecewiseFunction *SavedGradientOpacityFunction[4]; 00406 int SavedColorChannels[4]; 00407 float SavedScalarOpacityDistance[4]; 00408 int SavedBlendMode; 00409 vtkImageData *SavedParametersInput; 00410 vtkTimeStamp SavedParametersMTime; 00411 00412 vtkImageData *SavedGradientsInput; 00413 vtkTimeStamp SavedGradientsMTime; 00414 00415 float SavedSampleDistance; 00416 00417 00418 unsigned short ColorTable[4][32768*3]; 00419 unsigned short ScalarOpacityTable[4][32768]; 00420 unsigned short GradientOpacityTable[4][256]; 00421 int TableSize[4]; 00422 float TableScale[4]; 00423 float TableShift[4]; 00424 00425 float GradientMagnitudeScale[4]; 00426 float GradientMagnitudeShift[4]; 00427 00428 unsigned short **GradientNormal; 00429 unsigned char **GradientMagnitude; 00430 unsigned short *ContiguousGradientNormal; 00431 unsigned char *ContiguousGradientMagnitude; 00432 00433 int NumberOfGradientSlices; 00434 00435 vtkDirectionEncoder *DirectionEncoder; 00436 00437 vtkEncodedGradientShader *GradientShader; 00438 00439 vtkFiniteDifferenceGradientEstimator *GradientEstimator; 00440 00441 unsigned short DiffuseShadingTable [4][65536*3]; 00442 unsigned short SpecularShadingTable[4][65536*3]; 00443 00444 int ShadingRequired; 00445 int GradientOpacityRequired; 00446 00447 vtkDataArray *CurrentScalars; 00448 vtkDataArray *PreviousScalars; 00449 00450 vtkRenderWindow *RenderWindow; 00451 vtkVolume *Volume; 00452 00453 int ClipRayAgainstVolume( float rayStart[3], 00454 float rayEnd[3], 00455 float rayDirection[3], 00456 double bounds[6] ); 00457 00458 int UpdateColorTable( vtkVolume *vol ); 00459 int UpdateGradients( vtkVolume *vol ); 00460 int UpdateShadingTable( vtkRenderer *ren, 00461 vtkVolume *vol ); 00462 void UpdateCroppingRegions(); 00463 00464 void ComputeGradients( vtkVolume *vol ); 00465 00466 int ClipRayAgainstClippingPlanes( float rayStart[3], 00467 float rayEnd[3], 00468 int numClippingPlanes, 00469 float *clippingPlanes ); 00470 00471 unsigned int FixedPointCroppingRegionPlanes[6]; 00472 unsigned int CroppingRegionMask[27]; 00473 00474 // Get the ZBuffer value corresponding to location (x,y) where (x,y) 00475 // are indexing into the ImageInUse image. This must be converted to 00476 // the zbuffer image coordinates. Nearest neighbor value is returned. 00477 float GetZBufferValue( int x, int y ); 00478 00479 vtkFixedPointVolumeRayCastMIPHelper *MIPHelper; 00480 vtkFixedPointVolumeRayCastCompositeHelper *CompositeHelper; 00481 vtkFixedPointVolumeRayCastCompositeGOHelper *CompositeGOHelper; 00482 vtkFixedPointVolumeRayCastCompositeShadeHelper *CompositeShadeHelper; 00483 vtkFixedPointVolumeRayCastCompositeGOShadeHelper *CompositeGOShadeHelper; 00484 00485 // Some variables used for ray computation 00486 float ViewToVoxelsArray[16]; 00487 float WorldToVoxelsArray[16]; 00488 float VoxelsToWorldArray[16]; 00489 00490 double CroppingBounds[6]; 00491 00492 int NumTransformedClippingPlanes; 00493 float *TransformedClippingPlanes; 00494 00495 double SavedSpacing[3]; 00496 00497 00498 // Min Max structured used to do space leaping 00499 unsigned short *MinMaxVolume; 00500 int MinMaxVolumeSize[4]; 00501 vtkImageData *SavedMinMaxInput; 00502 vtkTimeStamp SavedMinMaxBuildTime; 00503 vtkTimeStamp SavedMinMaxGradientTime; 00504 vtkTimeStamp SavedMinMaxFlagTime; 00505 00506 void UpdateMinMaxVolume( vtkVolume *vol ); 00507 void FillInMaxGradientMagnitudes( int fullDim[3], 00508 int smallDim[3] ); 00509 00510 float FinalColorWindow; 00511 float FinalColorLevel; 00512 00513 int FlipMIPComparison; 00514 00515 void ApplyFinalColorWindowLevel(); 00516 00517 00518 private: 00519 vtkFixedPointVolumeRayCastMapper(const vtkFixedPointVolumeRayCastMapper&); // Not implemented. 00520 void operator=(const vtkFixedPointVolumeRayCastMapper&); // Not implemented. 00521 }; 00522 00523 00524 inline unsigned int vtkFixedPointVolumeRayCastMapper::ToFixedPointPosition( float val ) 00525 { 00526 return static_cast<unsigned int>(val * VTKKW_FP_SCALE + 0.5); 00527 } 00528 00529 inline void vtkFixedPointVolumeRayCastMapper::ToFixedPointPosition( float in[3], unsigned int out[3] ) 00530 { 00531 out[0] = static_cast<unsigned int>(in[0] * VTKKW_FP_SCALE + 0.5); 00532 out[1] = static_cast<unsigned int>(in[1] * VTKKW_FP_SCALE + 0.5); 00533 out[2] = static_cast<unsigned int>(in[2] * VTKKW_FP_SCALE + 0.5); 00534 } 00535 00536 inline unsigned int vtkFixedPointVolumeRayCastMapper::ToFixedPointDirection( float dir ) 00537 { 00538 return ((dir<0.0)? 00539 (static_cast<unsigned int>(-dir * VTKKW_FP_SCALE + 0.5)): 00540 (0x80000000+static_cast<unsigned int>(dir*VTKKW_FP_SCALE + 0.5))); 00541 } 00542 00543 inline void vtkFixedPointVolumeRayCastMapper::ToFixedPointDirection( float in[3], unsigned int out[3] ) 00544 { 00545 out[0] = ((in[0]<0.0)? 00546 (static_cast<unsigned int>(-in[0] * VTKKW_FP_SCALE + 0.5)): 00547 (0x80000000+ 00548 static_cast<unsigned int>(in[0]*VTKKW_FP_SCALE + 0.5))); 00549 out[1] = ((in[1]<0.0)? 00550 (static_cast<unsigned int>(-in[1] * VTKKW_FP_SCALE + 0.5)): 00551 (0x80000000+ 00552 static_cast<unsigned int>(in[1]*VTKKW_FP_SCALE + 0.5))); 00553 out[2] = ((in[2]<0.0)? 00554 (static_cast<unsigned int>(-in[2] * VTKKW_FP_SCALE + 0.5)): 00555 (0x80000000+ 00556 static_cast<unsigned int>(in[2]*VTKKW_FP_SCALE + 0.5))); 00557 } 00558 00559 inline void vtkFixedPointVolumeRayCastMapper::FixedPointIncrement( unsigned int position[3], unsigned int increment[3] ) 00560 { 00561 if ( increment[0]&0x80000000 ) 00562 { 00563 position[0] += (increment[0]&0x7fffffff); 00564 } 00565 else 00566 { 00567 position[0] -= increment[0]; 00568 } 00569 if ( increment[1]&0x80000000 ) 00570 { 00571 position[1] += (increment[1]&0x7fffffff); 00572 } 00573 else 00574 { 00575 position[1] -= increment[1]; 00576 } 00577 if ( increment[2]&0x80000000 ) 00578 { 00579 position[2] += (increment[2]&0x7fffffff); 00580 } 00581 else 00582 { 00583 position[2] -= increment[2]; 00584 } 00585 } 00586 00587 00588 inline void vtkFixedPointVolumeRayCastMapper::GetFloatTripleFromPointer( float v[3], float *ptr ) 00589 { 00590 v[0] = *(ptr); 00591 v[1] = *(ptr+1); 00592 v[2] = *(ptr+2); 00593 } 00594 00595 inline void vtkFixedPointVolumeRayCastMapper::GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr ) 00596 { 00597 v[0] = *(ptr); 00598 v[1] = *(ptr+1); 00599 v[2] = *(ptr+2); 00600 } 00601 00602 inline void vtkFixedPointVolumeRayCastMapper::ShiftVectorDown( unsigned int in[3], 00603 unsigned int out[3] ) 00604 { 00605 out[0] = in[0] >> VTKKW_FP_SHIFT; 00606 out[1] = in[1] >> VTKKW_FP_SHIFT; 00607 out[2] = in[2] >> VTKKW_FP_SHIFT; 00608 } 00609 00610 inline int vtkFixedPointVolumeRayCastMapper::CheckMinMaxVolumeFlag( unsigned int mmpos[3], int c ) 00611 { 00612 unsigned int offset = 00613 static_cast<unsigned int>(this->MinMaxVolumeSize[3]) * 00614 ( mmpos[2]*static_cast<unsigned int>( 00615 this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1]) + 00616 mmpos[1]*static_cast<unsigned int>(this->MinMaxVolumeSize[0]) + 00617 mmpos[0] ) + static_cast<unsigned int>(c); 00618 00619 return ((*(this->MinMaxVolume + 3*offset + 2))&0x00ff); 00620 } 00621 00622 inline int vtkFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned int mmpos[3], int c, 00623 unsigned short maxIdx, int flip ) 00624 { 00625 unsigned int offset = 00626 static_cast<unsigned int>(this->MinMaxVolumeSize[3]) * 00627 ( mmpos[2]*static_cast<unsigned int>( 00628 this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1]) + 00629 mmpos[1]*static_cast<unsigned int>(this->MinMaxVolumeSize[0]) + 00630 mmpos[0] ) + static_cast<unsigned int>(c); 00631 00632 if ( (*(this->MinMaxVolume + 3*offset + 2)&0x00ff) ) 00633 { 00634 if (flip) 00635 { 00636 return ( *(this->MinMaxVolume + 3*offset) < maxIdx ); 00637 } 00638 else 00639 { 00640 return ( *(this->MinMaxVolume + 3*offset + 1) > maxIdx ); 00641 } 00642 } 00643 else 00644 { 00645 return 0; 00646 } 00647 } 00648 00649 inline void vtkFixedPointVolumeRayCastMapper::LookupColorUC( unsigned short *colorTable, 00650 unsigned short *scalarOpacityTable, 00651 unsigned short index, 00652 unsigned char color[4] ) 00653 { 00654 unsigned short alpha = scalarOpacityTable[index]; 00655 color[0] = static_cast<unsigned char> 00656 ((colorTable[3*index ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00657 color[1] = static_cast<unsigned char> 00658 ((colorTable[3*index+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00659 color[2] = static_cast<unsigned char> 00660 ((colorTable[3*index+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00661 color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8)); 00662 } 00663 00664 inline void vtkFixedPointVolumeRayCastMapper::LookupDependentColorUC( unsigned short *colorTable, 00665 unsigned short *scalarOpacityTable, 00666 unsigned short index[4], 00667 int components, 00668 unsigned char color[4] ) 00669 { 00670 unsigned short alpha; 00671 switch ( components ) 00672 { 00673 case 2: 00674 alpha = scalarOpacityTable[index[1]]; 00675 color[0] = static_cast<unsigned char> 00676 ((colorTable[3*index[0] ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00677 color[1] = static_cast<unsigned char> 00678 ((colorTable[3*index[0]+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00679 color[2] = static_cast<unsigned char> 00680 ((colorTable[3*index[0]+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00681 color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8)); 00682 break; 00683 case 4: 00684 alpha = scalarOpacityTable[index[3]]; 00685 color[0] = static_cast<unsigned char>((index[0]*alpha + 0x7fff)>>VTKKW_FP_SHIFT ); 00686 color[1] = static_cast<unsigned char>((index[1]*alpha + 0x7fff)>>VTKKW_FP_SHIFT ); 00687 color[2] = static_cast<unsigned char>((index[2]*alpha + 0x7fff)>>VTKKW_FP_SHIFT ); 00688 color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8)); 00689 break; 00690 } 00691 } 00692 00693 00694 inline void vtkFixedPointVolumeRayCastMapper::LookupAndCombineIndependentColorsUC( unsigned short *colorTable[4], 00695 unsigned short *scalarOpacityTable[4], 00696 unsigned short index[4], 00697 float weights[4], 00698 int components, 00699 unsigned char color[4] ) 00700 { 00701 unsigned int tmp[4] = {0,0,0,0}; 00702 00703 for ( int i = 0; i < components; i++ ) 00704 { 00705 unsigned short alpha = static_cast<unsigned short>(static_cast<float>(scalarOpacityTable[i][index[i]])*weights[i]); 00706 tmp[0] += static_cast<unsigned char>(((colorTable[i][3*index[i] ])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00707 tmp[1] += static_cast<unsigned char>(((colorTable[i][3*index[i]+1])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00708 tmp[2] += static_cast<unsigned char>(((colorTable[i][3*index[i]+2])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8)); 00709 tmp[3] += static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8)); 00710 } 00711 00712 color[0] = static_cast<unsigned char>((tmp[0]>255)?(255):(tmp[0])); 00713 color[1] = static_cast<unsigned char>((tmp[1]>255)?(255):(tmp[1])); 00714 color[2] = static_cast<unsigned char>((tmp[2]>255)?(255):(tmp[2])); 00715 color[3] = static_cast<unsigned char>((tmp[3]>255)?(255):(tmp[3])); 00716 00717 } 00718 00719 inline int vtkFixedPointVolumeRayCastMapper::CheckIfCropped( unsigned int pos[3] ) 00720 { 00721 int idx; 00722 00723 if ( pos[2] < this->FixedPointCroppingRegionPlanes[4] ) 00724 { 00725 idx = 0; 00726 } 00727 else if ( pos[2] > this->FixedPointCroppingRegionPlanes[5] ) 00728 { 00729 idx = 18; 00730 } 00731 else 00732 { 00733 idx = 9; 00734 } 00735 00736 if ( pos[1] >= this->FixedPointCroppingRegionPlanes[2] ) 00737 { 00738 if ( pos[1] > this->FixedPointCroppingRegionPlanes[3] ) 00739 { 00740 idx += 6; 00741 } 00742 else 00743 { 00744 idx += 3; 00745 } 00746 } 00747 00748 if ( pos[0] >= this->FixedPointCroppingRegionPlanes[0] ) 00749 { 00750 if ( pos[0] > this->FixedPointCroppingRegionPlanes[1] ) 00751 { 00752 idx += 2; 00753 } 00754 else 00755 { 00756 idx += 1; 00757 } 00758 } 00759 00760 return !(static_cast<unsigned int>(this->CroppingRegionFlags) 00761 &this->CroppingRegionMask[idx]); 00762 } 00763 00764 #endif