1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkRecursiveSphereDirectionEncoder.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 /**
17  * @class   vtkRecursiveSphereDirectionEncoder
18  * @brief   A direction encoder based on the recursive subdivision of an octahedron
19  *
20  * vtkRecursiveSphereDirectionEncoder is a direction encoder which uses the
21  * vertices of a recursive subdivision of an octahedron (with the vertices
22  * pushed out onto the surface of an enclosing sphere) to encode directions
23  * into a two byte value.
24  *
25  * @sa
26  * vtkDirectionEncoder
27  */
28 
29 #ifndef vtkRecursiveSphereDirectionEncoder_h
30 #define vtkRecursiveSphereDirectionEncoder_h
31 
32 #include "vtkDirectionEncoder.h"
33 #include "vtkRenderingVolumeModule.h" // For export macro
34 
35 class VTKRENDERINGVOLUME_EXPORT vtkRecursiveSphereDirectionEncoder : public vtkDirectionEncoder
36 {
37 public:
38   vtkTypeMacro(vtkRecursiveSphereDirectionEncoder, vtkDirectionEncoder);
39   void PrintSelf(ostream& os, vtkIndent indent) override;
40 
41   /**
42    * Construct the object. Initialize the index table which will be
43    * used to map the normal into a patch on the recursively subdivided
44    * sphere.
45    */
46   static vtkRecursiveSphereDirectionEncoder* New();
47 
48   /**
49    * Given a normal vector n, return the encoded direction
50    */
51   int GetEncodedDirection(float n[3]) override;
52 
53   /**
54    * / Given an encoded value, return a pointer to the normal vector
55    */
56   float* GetDecodedGradient(int value) VTK_SIZEHINT(3) override;
57 
58   /**
59    * Return the number of encoded directions
60    */
61   int GetNumberOfEncodedDirections(void) override;
62 
63   /**
64    * Get the decoded gradient table. There are
65    * this->GetNumberOfEncodedDirections() entries in the table, each
66    * containing a normal (direction) vector. This is a flat structure -
67    * 3 times the number of directions floats in an array.
68    */
69   float* GetDecodedGradientTable(void) override;
70 
71   ///@{
72   /**
73    * Set / Get the recursion depth for the subdivision. This
74    * indicates how many time one triangle on the initial 8-sided
75    * sphere model is replaced by four triangles formed by connecting
76    * triangle edge midpoints. A recursion level of 0 yields 8 triangles
77    * with 6 unique vertices. The normals are the vectors from the
78    * sphere center through the vertices. The number of directions
79    * will be 11 since the four normals with 0 z values will be
80    * duplicated in the table - once with +0 values and the other
81    * time with -0 values, and an addition index will be used to
82    * represent the (0,0,0) normal. If we instead choose a recursion
83    * level of 6 (the maximum that can fit within 2 bytes) the number
84    * of directions is 16643, with 16386 unique directions and a
85    * zero normal.
86    */
87   vtkSetClampMacro(RecursionDepth, int, 0, 6);
88   vtkGetMacro(RecursionDepth, int);
89   ///@}
90 
91 protected:
92   vtkRecursiveSphereDirectionEncoder();
93   ~vtkRecursiveSphereDirectionEncoder() override;
94 
95   // How far to recursively divide the sphere
96   int RecursionDepth;
97 
98   // The index table which maps (x,y) position in the rotated grid
99   // to an encoded normal
100   // int                   IndexTable[2*NORM_SQR_SIZE - 1][2*NORM_SQR_SIZE -1];
101   int* IndexTable;
102 
103   // This is a table that maps encoded normal (2 byte value) to a
104   // normal (dx, dy, dz)
105   // float                 DecodedNormal[3*(1 + 2*(NORM_SQR_SIZE*NORM_SQR_SIZE+
106   //                             (NORM_SQR_SIZE-1)*(NORM_SQR_SIZE-1)))];
107   float* DecodedNormal;
108 
109   // Method to initialize the index table and variable that
110   // stored the recursion depth the last time the table was
111   // built
112   void InitializeIndexTable(void);
113   int IndexTableRecursionDepth;
114 
115   int OuterSize;
116   int InnerSize;
117   int GridSize;
118 
119 private:
120   vtkRecursiveSphereDirectionEncoder(const vtkRecursiveSphereDirectionEncoder&) = delete;
121   void operator=(const vtkRecursiveSphereDirectionEncoder&) = delete;
122 };
123 
124 #endif
125