1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkEllipticalButtonSource.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  * @class   vtkEllipticalButtonSource
17  * @brief   create a ellipsoidal-shaped button
18  *
19  * vtkEllipticalButtonSource creates a ellipsoidal shaped button with
20  * texture coordinates suitable for application of a texture map. This
21  * provides a way to make nice looking 3D buttons. The buttons are
22  * represented as vtkPolyData that includes texture coordinates and
23  * normals. The button lies in the x-y plane.
24  *
25  * To use this class you must define the major and minor axes lengths of an
26  * ellipsoid (expressed as width (x), height (y) and depth (z)). The button
27  * has a rectangular mesh region in the center with texture coordinates that
28  * range smoothly from (0,1). (This flat region is called the texture
29  * region.) The outer, curved portion of the button (called the shoulder) has
30  * texture coordinates set to a user specified value (by default (0,0).
31  * (This results in coloring the button curve the same color as the (s,t)
32  * location of the texture map.) The resolution in the radial direction, the
33  * texture region, and the shoulder region must also be set. The button can
34  * be moved by specifying an origin.
35  *
36  * @sa
37  * vtkButtonSource vtkRectangularButtonSource
38 */
39 
40 #ifndef vtkEllipticalButtonSource_h
41 #define vtkEllipticalButtonSource_h
42 
43 #include "vtkFiltersSourcesModule.h" // For export macro
44 #include "vtkButtonSource.h"
45 
46 class vtkCellArray;
47 class vtkFloatArray;
48 class vtkPoints;
49 
50 class VTKFILTERSSOURCES_EXPORT vtkEllipticalButtonSource : public vtkButtonSource
51 {
52 public:
53   void PrintSelf(ostream& os, vtkIndent indent) override;
54   vtkTypeMacro(vtkEllipticalButtonSource,vtkButtonSource);
55 
56   /**
57    * Construct a circular button with depth 10% of its height.
58    */
59   static vtkEllipticalButtonSource *New();
60 
61   //@{
62   /**
63    * Set/Get the width of the button (the x-ellipsoid axis length * 2).
64    */
65   vtkSetClampMacro(Width,double,0.0,VTK_DOUBLE_MAX);
66   vtkGetMacro(Width,double);
67   //@}
68 
69   //@{
70   /**
71    * Set/Get the height of the button (the y-ellipsoid axis length * 2).
72    */
73   vtkSetClampMacro(Height,double,0.0,VTK_DOUBLE_MAX);
74   vtkGetMacro(Height,double);
75   //@}
76 
77   //@{
78   /**
79    * Set/Get the depth of the button (the z-eliipsoid axis length).
80    */
81   vtkSetClampMacro(Depth,double,0.0,VTK_DOUBLE_MAX);
82   vtkGetMacro(Depth,double);
83   //@}
84 
85   //@{
86   /**
87    * Specify the resolution of the button in the circumferential direction.
88    */
89   vtkSetClampMacro(CircumferentialResolution,int,4,VTK_INT_MAX);
90   vtkGetMacro(CircumferentialResolution,int);
91   //@}
92 
93   //@{
94   /**
95    * Specify the resolution of the texture in the radial direction in the
96    * texture region.
97    */
98   vtkSetClampMacro(TextureResolution,int,1,VTK_INT_MAX);
99   vtkGetMacro(TextureResolution,int);
100   //@}
101 
102   //@{
103   /**
104    * Specify the resolution of the texture in the radial direction in the
105    * shoulder region.
106    */
107   vtkSetClampMacro(ShoulderResolution,int,1,VTK_INT_MAX);
108   vtkGetMacro(ShoulderResolution,int);
109   //@}
110 
111   //@{
112   /**
113    * Set/Get the radial ratio. This is the measure of the radius of the
114    * outer ellipsoid to the inner ellipsoid of the button. The outer
115    * ellipsoid is the boundary of the button defined by the height and
116    * width. The inner ellipsoid circumscribes the texture region. Larger
117    * RadialRatio's cause the button to be more rounded (and the texture
118    * region to be smaller); smaller ratios produce sharply curved shoulders
119    * with a larger texture region.
120    */
121   vtkSetClampMacro(RadialRatio,double,1.0,VTK_DOUBLE_MAX);
122   vtkGetMacro(RadialRatio,double);
123   //@}
124 
125   //@{
126   /**
127    * Set/get the desired precision for the output points.
128    * vtkAlgorithm::SINGLE_PRECISION - Output single-precision floating point.
129    * vtkAlgorithm::DOUBLE_PRECISION - Output double-precision floating point.
130    */
131   vtkSetMacro(OutputPointsPrecision,int);
132   vtkGetMacro(OutputPointsPrecision,int);
133   //@}
134 
135 protected:
136   vtkEllipticalButtonSource();
~vtkEllipticalButtonSource()137   ~vtkEllipticalButtonSource() override {}
138 
139   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
140 
141   double Width;
142   double Height;
143   double Depth;
144   int    CircumferentialResolution;
145   int    TextureResolution;
146   int    ShoulderResolution;
147   int    OutputPointsPrecision;
148   double RadialRatio;
149 
150 private:
151   //internal variable related to axes of ellipsoid
152   double A;
153   double A2;
154   double B;
155   double B2;
156   double C;
157   double C2;
158 
159   double ComputeDepth(int inTextureRegion, double x, double y, double n[3]);
160   void InterpolateCurve(int inTextureRegion, vtkPoints *newPts, int numPts,
161                         vtkFloatArray *normals, vtkFloatArray *tcoords,
162                         int res, int c1StartPoint,int c1Incr,
163                         int c2StartPoint,int s2Incr, int startPoint,int incr);
164   void CreatePolygons(vtkCellArray *newPolys, int num, int res, int startIdx);
165   void IntersectEllipseWithLine(double a2, double b2, double dX, double dY,
166                                 double& xe, double& ye);
167 
168   vtkEllipticalButtonSource(const vtkEllipticalButtonSource&) = delete;
169   void operator=(const vtkEllipticalButtonSource&) = delete;
170 };
171 
172 #endif
173 
174 
175