Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkVolumeRendererRayCasting.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkVolumeRendererRayCasting_h
00012 #define __mitkVolumeRendererRayCasting_h
00013 
00014 #include "mitkVolumeRenderer.h"
00015 #include "mitkRCPtr.h"
00016 #include "mitkVolumeRayCastFunction.h"
00017 #include "mitkEncodedGradientEstimator.h"
00018 #include "mitkEncodedGradientShader.h"
00019 
00020 class mitkMatrix;
00021 
00027 class MITK_VISUALIZATION_API mitkVolumeRendererRayCasting : public mitkVolumeRenderer
00028 {
00029 public:
00030     MITK_TYPE(mitkVolumeRendererRayCasting,mitkVolumeRenderer)
00031         
00032     mitkVolumeRendererRayCasting(); 
00033 
00034     virtual void PrintSelf(ostream& os);            
00035     
00039     virtual int Render(mitkScene *scene, mitkVolumeModel *vol);
00040     
00045     void  SetSampleDistance(float fVal) {m_SampleDistance = fVal;}
00046 
00051     float GetSampleDistance(){return m_SampleDistance;}
00052 
00058     void SetVolumeRayCastFunction(mitkVolumeRayCastFunction* oVal)
00059     {
00060         m_VolumeRayCastFunction = oVal;
00061     }
00062 
00067     mitkVolumeRayCastFunction* GetVolumeRayCastFunction()
00068     {
00069         return m_VolumeRayCastFunction;
00070     }   
00071 
00072 
00077     void SetGradientEstimator(mitkEncodedGradientEstimator *gradest);
00078 
00083     mitkEncodedGradientEstimator* GetGradientEstimator(){return m_GradientEstimator;};
00084     
00089     mitkEncodedGradientShader* GetEncodedGradientShader() { return m_GradientShader; }
00090     
00095     float GetImageSampleDistanceMinValue() { return 0.1f; }
00096 
00101     float GetImageSampleDistanceMaxValue() { return 100.0f; }
00102 
00107     void SetImageSampleDistance(float fVal)
00108     {
00109         m_ImageSampleDistance = fVal < GetImageSampleDistanceMinValue()
00110             ? GetImageSampleDistanceMinValue()
00111             : (fVal > GetImageSampleDistanceMaxValue()
00112             ? GetImageSampleDistanceMaxValue() : fVal);
00113     }
00114 
00119     float GetImageSampleDistance() { return m_ImageSampleDistance; }
00120     
00125     float GetMinimumImageSampleDistanceMinValue() { return 0.1f; }
00126 
00131     float GetMinimumImageSampleDistanceMaxValue() { return 100.0f; }
00132 
00137     float GetMaximumImageSampleDistanceMinValue() { return 0.1f; }
00138 
00143     float GetMaximumImageSampleDistanceMaxValue() { return 100.0f; }
00144 
00149     void SetMinimumImageSampleDistance(float fVal)
00150     {
00151         m_MinimumImageSampleDistance = fVal < GetMinimumImageSampleDistanceMinValue()
00152             ? GetMinimumImageSampleDistanceMinValue()
00153             : (fVal > GetMinimumImageSampleDistanceMaxValue() 
00154             ? GetMinimumImageSampleDistanceMaxValue() : fVal);
00155     }
00156 
00161     void SetMaximumImageSampleDistance(float fVal)
00162     {
00163         m_MaximumImageSampleDistance = fVal < GetMaximumImageSampleDistanceMinValue()
00164             ? GetMaximumImageSampleDistanceMinValue()
00165             : (fVal > GetMaximumImageSampleDistanceMaxValue()
00166             ? GetMaximumImageSampleDistanceMaxValue() : fVal);
00167     }
00168 
00173     float GetMinimumImageSampleDistance() { return m_MinimumImageSampleDistance; }  
00174     
00179     float GetMaximumImageSampleDistance() { return m_MaximumImageSampleDistance; }  
00180     
00186     void SetAutoAdjustSampleDistances(int val)
00187     {
00188         m_AutoAdjustSampleDistances = val < 0 ? 0 : (val > 1 ? 1 : val);
00189     }
00190     
00196     int GetAutoAdjustSampleDistances() { return m_AutoAdjustSampleDistances; }
00197 
00201     void AutoAdjustSampleDistancesOn() { SetAutoAdjustSampleDistances(1); }
00202 
00206     void AutoAdjustSampleDistancesOff() { SetAutoAdjustSampleDistances(0); }
00207     
00213     void SetIntermixIntersectingGeometry(int fVal)
00214     {
00215         m_IntermixIntersectingGeometry = fVal < 0 ? 0 : (fVal > 1 ? 1 : fVal);
00216     }   
00217     
00222     int GetIntermixIntersectingGeometry(){ return m_IntermixIntersectingGeometry;}  
00223 
00227     void IntermixIntersectingGeometryOn() { SetIntermixIntersectingGeometry(1); }
00228 
00232     void IntermixIntersectingGeometryOff() { SetIntermixIntersectingGeometry(0); }  
00233 
00238     virtual float GetGradientMagnitudeScale();
00239     
00244     virtual float GetGradientMagnitudeBias();
00245 
00246 protected:
00247     mitkRCPtr<mitkVolumeRayCastFunction>     m_VolumeRayCastFunction;
00248     mitkRCPtr<mitkEncodedGradientEstimator>  m_GradientEstimator;
00249     mitkRCPtr<mitkEncodedGradientShader>     m_GradientShader;
00250 
00251     mitkVolumeModel **m_RenderVolumeTable;
00252     mitkScene        **m_RenderSceneTable;
00253     
00254     mitkMatrix *m_PerspectiveMatrix;
00255     mitkMatrix *m_ViewToWorldMatrix;
00256     mitkMatrix *m_ViewToVoxelsMatrix;
00257     mitkMatrix *m_VoxelsToViewMatrix;
00258     mitkMatrix *m_WorldToVoxelsMatrix;
00259     mitkMatrix *m_VoxelsToWorldMatrix;
00260     
00261     // This is how big the image would be if it covered the entire viewport
00262     int m_ImageViewportSize[2];
00263     
00264     // This is how big the allocated memory for image is. This may be bigger
00265     // or smaller than ImageFullSize - it will be bigger if necessary to 
00266     // ensure a power of 2, it will be smaller if the volume only covers a
00267     // small region of the viewport
00268     int m_ImageMemorySize[2];
00269     
00270     // This is the size of subregion in ImageSize image that we are using for
00271     // the current image. Since ImageSize is a power of 2, there is likely
00272     // wasted space in it. This number will be used for things such as clearing
00273     // the image if necessary.
00274     int m_ImageInUseSize[2];
00275     
00276     // This is the location in ImageFullSize image where our ImageSize image
00277     // is located.
00278     int m_ImageOrigin[2];
00279     
00280     // This is the allocated image
00281     unsigned char *m_Image;
00282     
00283     int *m_RowBounds;
00284     int *m_OldRowBounds;    
00285     
00286     int m_RenderTableSize;
00287     int m_RenderTableEntries;
00288     
00289     int m_IntermixIntersectingGeometry;
00290     
00291     float *m_ZBuffer;
00292     int   m_ZBufferSize[2];
00293     int   m_ZBufferOrigin[2];
00294     
00295     float m_MinimumViewDistance;
00296     
00297     // The distance between sample points along the ray
00298     float m_SampleDistance;
00299 
00300     float m_ImageSampleDistance;
00301     float m_MinimumImageSampleDistance;
00302     float m_MaximumImageSampleDistance;
00303     int   m_AutoAdjustSampleDistances;
00304     
00305     float m_WorldSampleDistance;
00306     int   m_ScalarDataType;
00307     void  *m_ScalarDataPointer;
00308     mitkRay *m_Ray;
00309     
00310     virtual ~mitkVolumeRendererRayCasting();
00311     void _updateShadingTables(mitkScene *scene, mitkVolumeModel *vol);  
00312     void _renderTexture(mitkVolumeModel *vol, mitkScene *scene);    
00313     int _computeRowBounds(mitkVolumeModel *vol, mitkScene *scene);
00314     int _computeClippingPlanes(float *planes);
00315     int _clipRayAgainstVolume(mitkRay *rayInfo, float bounds[6] );
00316     int _clipRayAgainstClippingPlanes(int planeCount, float *planeEqus, mitkRay *rayInfo);  
00317             
00318     // Get the ZBuffer value corresponding to location (x,y) where (x,y)
00319     // are indexing into the ImageInUse image. This must be converted to
00320     // the zbuffer image coordinates. Nearest neighbor value is returned.
00321     float _getZBufferValue(int x, int y);   
00322     
00323     void _castRaysClipOffCropOff(mitkScene *scene, mitkVolumeModel *vol); 
00324     void _castRaysClipOnCropOff(mitkScene *scene, mitkVolumeModel *vol); 
00325     void _castRaysClipOffCropSub(mitkScene *scene, mitkVolumeModel *vol); 
00326     void _castRaysClipOffCropNonSub(mitkScene *scene, mitkVolumeModel *vol); 
00327     void _castRaysClipOnCropSub(mitkScene *scene, mitkVolumeModel *vol); 
00328     void _castRaysClipOnCropNonSub(mitkScene *scene, mitkVolumeModel *vol); 
00329 
00330 private:
00331     mitkVolumeRendererRayCasting(const mitkVolumeRendererRayCasting&);
00332     void operator=(const mitkVolumeRendererRayCasting&);
00333 };
00334 
00335  
00336 //#define DEFINED_mitkVolumeRendererRayCasting
00337  
00338 
00339 
00340 #endif
00341 
00342 /*=========================================================================
00343 
00344   Program:   Visualization Toolkit
00345   Module:    $RCSfile$
00346   Language:  C++
00347   Date:      $Date: 2009-04-19 14:50:25 +0800 (ÐÇÆÚÈÕ, 19 ËÄÔÂ 2009) $
00348   Version:   $Revision: 231 $
00349 
00350 
00351 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00352 All rights reserved.
00353 
00354 Redistribution and use in source and binary forms, with or without
00355 modification, are permitted provided that the following conditions are met:
00356 
00357  * Redistributions of source code must retain the above copyright notice,
00358    this list of conditions and the following disclaimer.
00359 
00360  * Redistributions in binary form must reproduce the above copyright notice,
00361    this list of conditions and the following disclaimer in the documentation
00362    and/or other materials provided with the distribution.
00363 
00364  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00365    of any contributors may be used to endorse or promote products derived
00366    from this software without specific prior written permission.
00367 
00368  * Modified source versions must be plainly marked as such, and must not be
00369    misrepresented as being the original software.
00370 
00371 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00372 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00373 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00374 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00375 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00376 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00377 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00378 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00379 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00380 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00381 
00382 =========================================================================*/ 
00383 
00384 

Generated on Tue Feb 25 15:00:38 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3