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