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