1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkVolumeOutlineSource.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   vtkVolumeOutlineSource
17  * @brief   outline of volume cropping region
18  *
19  * vtkVolumeOutlineSource generates a wireframe outline that corresponds
20  * to the cropping region of a vtkVolumeMapper.  It requires a
21  * vtkVolumeMapper as input.  The GenerateFaces option turns on the
22  * solid faces of the outline, and the GenerateScalars option generates
23  * color scalars.  When GenerateScalars is on, it is possible to set
24  * an "ActivePlaneId" value in the range [0..6] to highlight one of the
25  * six cropping planes.
26  * @par Thanks:
27  * Thanks to David Gobbi for contributing this class to VTK.
28 */
29 
30 #ifndef vtkVolumeOutlineSource_h
31 #define vtkVolumeOutlineSource_h
32 
33 #include "vtkRenderingVolumeModule.h" // For export macro
34 #include "vtkPolyDataAlgorithm.h"
35 
36 class vtkVolumeMapper;
37 
38 class VTKRENDERINGVOLUME_EXPORT vtkVolumeOutlineSource : public vtkPolyDataAlgorithm
39 {
40 public:
41   static vtkVolumeOutlineSource *New();
42   vtkTypeMacro(vtkVolumeOutlineSource,vtkPolyDataAlgorithm);
43   void PrintSelf(ostream& os, vtkIndent indent) override;
44 
45   //@{
46   /**
47    * Set the mapper that has the cropping region that the outline will
48    * be generated for.  The mapper must have an input, because the
49    * bounds of the data must be computed in order to generate the
50    * outline.
51    */
52   virtual void SetVolumeMapper(vtkVolumeMapper *mapper);
GetVolumeMapper()53   vtkVolumeMapper *GetVolumeMapper() { return this->VolumeMapper; };
54   //@}
55 
56   //@{
57   /**
58    * Set whether to generate color scalars for the output.  By default,
59    * the output has no scalars and the color must be set in the
60    * property of the actor.
61    */
62   vtkSetMacro(GenerateScalars, vtkTypeBool);
63   vtkBooleanMacro(GenerateScalars, vtkTypeBool);
64   vtkGetMacro(GenerateScalars, vtkTypeBool);
65   //@}
66 
67   //@{
68   /**
69    * Set whether to generate an outline wherever an input face was
70    * cut by a plane.  This is on by default.
71    */
72   vtkSetMacro(GenerateOutline, vtkTypeBool);
73   vtkBooleanMacro(GenerateOutline, vtkTypeBool);
74   vtkGetMacro(GenerateOutline, vtkTypeBool);
75   //@}
76 
77   //@{
78   /**
79    * Set whether to generate polygonal faces for the output.  By default,
80    * only lines are generated.  The faces will form a closed, watertight
81    * surface.
82    */
83   vtkSetMacro(GenerateFaces, vtkTypeBool);
84   vtkBooleanMacro(GenerateFaces, vtkTypeBool);
85   vtkGetMacro(GenerateFaces, vtkTypeBool);
86   //@}
87 
88   //@{
89   /**
90    * Set the color of the outline.  This has no effect unless GenerateScalars
91    * is On.  The default color is red.
92    */
93   vtkSetVector3Macro(Color, double);
94   vtkGetVector3Macro(Color, double);
95   //@}
96 
97   //@{
98   /**
99    * Set the active plane, e.g. to display which plane is currently being
100    * modified by an interaction.  Set this to -1 if there is no active plane.
101    * The default value is -1.
102    */
103   vtkSetMacro(ActivePlaneId, int);
104   vtkGetMacro(ActivePlaneId, int);
105   //@}
106 
107   //@{
108   /**
109    * Set the color of the active cropping plane.  This has no effect unless
110    * GenerateScalars is On and ActivePlaneId is non-negative.  The default
111    * color is yellow.
112    */
113   vtkSetVector3Macro(ActivePlaneColor, double);
114   vtkGetVector3Macro(ActivePlaneColor, double);
115   //@}
116 
117 protected:
118   vtkVolumeOutlineSource();
119   ~vtkVolumeOutlineSource() override;
120 
121   vtkVolumeMapper *VolumeMapper;
122   vtkTypeBool GenerateScalars;
123   vtkTypeBool GenerateOutline;
124   vtkTypeBool GenerateFaces;
125   int ActivePlaneId;
126   double Color[3];
127   double ActivePlaneColor[3];
128 
129   int Cropping;
130   int CroppingRegionFlags;
131   double Bounds[6];
132   double CroppingRegionPlanes[6];
133 
134   static int ComputeCubePlanes(double planes[3][4],
135                                double croppingPlanes[6],
136                                double bounds[6]);
137 
138   static void GeneratePolys(vtkCellArray *polys,
139                             vtkUnsignedCharArray *scalars,
140                             unsigned char colors[2][3],
141                             int activePlane,
142                             int flags,
143                             int tolPtId[3][4]);
144 
145   static void GenerateLines(vtkCellArray *lines,
146                             vtkUnsignedCharArray *scalars,
147                             unsigned char colors[2][3],
148                             int activePlane,
149                             int flags,
150                             int tolPtId[3][4]);
151 
152   static void GeneratePoints(vtkPoints *points,
153                              vtkCellArray *lines,
154                              vtkCellArray *polys,
155                              double planes[3][4],
156                              double tol);
157 
158   static void NudgeCropPlanesToBounds(int tolPtId[3][4],
159                                       double planes[3][4],
160                                       double tol);
161 
162   static void CreateColorValues(unsigned char colors[2][3],
163                                 double color1[3], double color2[3]);
164 
165   int ComputePipelineMTime(vtkInformation* request,
166                                    vtkInformationVector** inputVector,
167                                    vtkInformationVector* outputVector,
168                                    int requestFromOutputPort,
169                                    vtkMTimeType* mtime) override;
170 
171   int RequestInformation(vtkInformation* request,
172                                  vtkInformationVector** inputVector,
173                                  vtkInformationVector* outputVector) override;
174 
175   int RequestData(vtkInformation* request,
176                           vtkInformationVector** inputVector,
177                           vtkInformationVector* outputVector) override;
178 
179 private:
180   vtkVolumeOutlineSource(const vtkVolumeOutlineSource&) = delete;
181   void operator=(const vtkVolumeOutlineSource&) = delete;
182 };
183 
184 #endif
185