1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkTensorGlyph.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 vtkTensorGlyph 17 * @brief scale and orient glyph(s) according to eigenvalues and eigenvectors of symmetrical part of tensor 18 * 19 * vtkTensorGlyph is a filter that copies a geometric representation 20 * (specified as polygonal data) to every input point. The geometric 21 * representation, or glyph, can be scaled and/or rotated according to 22 * the tensor at the input point. Scaling and rotation is controlled 23 * by the eigenvalues/eigenvectors of the symmetrical part of the tensor 24 * as follows: 25 * For each tensor, the eigenvalues (and associated eigenvectors) are sorted 26 * to determine the major, medium, and minor eigenvalues/eigenvectors. 27 * The eigenvalue decomposition only makes sense for symmetric tensors, 28 * hence the need to only consider the symmetric part of the tensor, which is 29 * 1/2 (T + T.transposed()). 30 * 31 * If the boolean variable ThreeGlyphs is not set the major eigenvalue 32 * scales the glyph in the x-direction, the medium in the y-direction, 33 * and the minor in the z-direction. Then, the glyph is rotated so 34 * that the glyph's local x-axis lies along the major eigenvector, 35 * y-axis along the medium eigenvector, and z-axis along the minor. 36 * 37 * If the boolean variable ThreeGlyphs is set three glyphs are produced, 38 * each of them oriented along an eigenvector and scaled according to the 39 * corresponding eigenvector. 40 * 41 * If the boolean variable Symmetric is set each glyph is mirrored (2 or 6 42 * glyphs will be produced) 43 * 44 * The x-axis of the source glyph will correspond to the eigenvector 45 * on output. Point (0,0,0) in the source will be placed in the data point. 46 * Variable Length will normally correspond to the distance from the 47 * origin to the tip of the source glyph along the x-axis, 48 * but can be changed to produce other results when Symmetric is on, 49 * e.g. glyphs that do not touch or that overlap. 50 * 51 * Please note that when Symmetric is false it will generally be better 52 * to place the source glyph from (-0.5,0,0) to (0.5,0,0), i.e. centred 53 * at the origin. When symmetric is true the placement from (0,0,0) to 54 * (1,0,0) will generally be more convenient. 55 * 56 * A scale factor is provided to control the amount of scaling. Also, you 57 * can turn off scaling completely if desired. The boolean variable 58 * ClampScaling controls the maximum scaling (in conjunction with 59 * MaxScaleFactor.) This is useful in certain applications where 60 * singularities or large order of magnitude differences exist in 61 * the eigenvalues. 62 * 63 * If the boolean variable ColorGlyphs is set to true the glyphs are 64 * colored. The glyphs can be colored using the input scalars 65 * (SetColorModeToScalars), which is the default, or colored using the 66 * eigenvalues (SetColorModeToEigenvalues). 67 * 68 * Another instance variable, ExtractEigenvalues, has been provided to 69 * control extraction of eigenvalues/eigenvectors. If this boolean is 70 * false, then eigenvalues/eigenvectors are not extracted, and the 71 * columns of the tensor are taken as the eigenvectors (the norm of 72 * column, always positive, is the eigenvalue). This allows 73 * additional capability over the vtkGlyph3D object. That is, the 74 * glyph can be oriented in three directions instead of one. 75 * 76 * @par Thanks: 77 * Thanks to Jose Paulo Moitinho de Almeida for enhancements. 78 * 79 * @sa 80 * vtkGlyph3D vtkPointLoad vtkHyperStreamline 81 */ 82 83 #ifndef vtkTensorGlyph_h 84 #define vtkTensorGlyph_h 85 86 #include "vtkFiltersCoreModule.h" // For export macro 87 #include "vtkPolyDataAlgorithm.h" 88 89 class VTKFILTERSCORE_EXPORT vtkTensorGlyph : public vtkPolyDataAlgorithm 90 { 91 public: 92 vtkTypeMacro(vtkTensorGlyph,vtkPolyDataAlgorithm); 93 void PrintSelf(ostream& os, vtkIndent indent) override; 94 95 /** 96 * Construct object with scaling on and scale factor 1.0. Eigenvalues are 97 * extracted, glyphs are colored with input scalar data, and logarithmic 98 * scaling is turned off. 99 */ 100 static vtkTensorGlyph *New(); 101 102 //@{ 103 /** 104 * Specify the geometry to copy to each point. 105 * Note that this method does not connect the pipeline. The algorithm will 106 * work on the input data as it is without updating the producer of the data. 107 * See SetSourceConnection for connecting the pipeline. 108 */ 109 void SetSourceData(vtkPolyData *source); 110 vtkPolyData *GetSource(); 111 //@} 112 113 //@{ 114 /** 115 * Specify a source object at a specified table location. New style. 116 * Source connection is stored in port 1. This method is equivalent 117 * to SetInputConnection(1, id, outputPort). 118 */ 119 void SetSourceConnection(int id, vtkAlgorithmOutput* algOutput); SetSourceConnection(vtkAlgorithmOutput * algOutput)120 void SetSourceConnection(vtkAlgorithmOutput* algOutput) 121 { 122 this->SetSourceConnection(0, algOutput); 123 } 124 //@} 125 126 //@{ 127 /** 128 * Turn on/off scaling of glyph with eigenvalues. 129 */ 130 vtkSetMacro(Scaling,vtkTypeBool); 131 vtkGetMacro(Scaling,vtkTypeBool); 132 vtkBooleanMacro(Scaling,vtkTypeBool); 133 //@} 134 135 //@{ 136 /** 137 * Specify scale factor to scale object by. (Scale factor always affects 138 * output even if scaling is off.) 139 */ 140 vtkSetMacro(ScaleFactor,double); 141 vtkGetMacro(ScaleFactor,double); 142 //@} 143 144 //@{ 145 /** 146 * Turn on/off drawing three glyphs 147 */ 148 vtkSetMacro(ThreeGlyphs,vtkTypeBool); 149 vtkGetMacro(ThreeGlyphs,vtkTypeBool); 150 vtkBooleanMacro(ThreeGlyphs,vtkTypeBool); 151 //@} 152 153 //@{ 154 /** 155 * Turn on/off drawing a mirror of each glyph 156 */ 157 vtkSetMacro(Symmetric,vtkTypeBool); 158 vtkGetMacro(Symmetric,vtkTypeBool); 159 vtkBooleanMacro(Symmetric,vtkTypeBool); 160 //@} 161 162 //@{ 163 /** 164 * Set/Get the distance, along x, from the origin to the end of the 165 * source glyph. It is used to draw the symmetric glyphs. 166 */ 167 vtkSetMacro(Length,double); 168 vtkGetMacro(Length,double); 169 //@} 170 171 //@{ 172 /** 173 * Turn on/off extraction of eigenvalues from tensor. 174 */ 175 vtkSetMacro(ExtractEigenvalues,vtkTypeBool); 176 vtkBooleanMacro(ExtractEigenvalues,vtkTypeBool); 177 vtkGetMacro(ExtractEigenvalues,vtkTypeBool); 178 //@} 179 180 //@{ 181 /** 182 * Turn on/off coloring of glyph with input scalar data or 183 * eigenvalues. If false, or input scalar data not present, then the 184 * scalars from the source object are passed through the filter. 185 */ 186 vtkSetMacro(ColorGlyphs,vtkTypeBool); 187 vtkGetMacro(ColorGlyphs,vtkTypeBool); 188 vtkBooleanMacro(ColorGlyphs,vtkTypeBool); 189 //@} 190 191 enum 192 { 193 COLOR_BY_SCALARS, 194 COLOR_BY_EIGENVALUES 195 }; 196 197 //@{ 198 /** 199 * Set the color mode to be used for the glyphs. This can be set to 200 * use the input scalars (default) or to use the eigenvalues at the 201 * point. If ThreeGlyphs is set and the eigenvalues are chosen for 202 * coloring then each glyph is colored by the corresponding 203 * eigenvalue and if not set the color corresponding to the largest 204 * eigenvalue is chosen. The recognized values are: 205 * COLOR_BY_SCALARS = 0 (default) 206 * COLOR_BY_EIGENVALUES = 1 207 */ 208 vtkSetClampMacro(ColorMode, int, COLOR_BY_SCALARS, COLOR_BY_EIGENVALUES); 209 vtkGetMacro(ColorMode, int); SetColorModeToScalars()210 void SetColorModeToScalars() 211 {this->SetColorMode(COLOR_BY_SCALARS);}; SetColorModeToEigenvalues()212 void SetColorModeToEigenvalues() 213 {this->SetColorMode(COLOR_BY_EIGENVALUES);}; 214 //@} 215 216 //@{ 217 /** 218 * Turn on/off scalar clamping. If scalar clamping is on, the ivar 219 * MaxScaleFactor is used to control the maximum scale factor. (This is 220 * useful to prevent uncontrolled scaling near singularities.) 221 */ 222 vtkSetMacro(ClampScaling,vtkTypeBool); 223 vtkGetMacro(ClampScaling,vtkTypeBool); 224 vtkBooleanMacro(ClampScaling,vtkTypeBool); 225 //@} 226 227 //@{ 228 /** 229 * Set/Get the maximum allowable scale factor. This value is compared to the 230 * combination of the scale factor times the eigenvalue. If less, the scale 231 * factor is reset to the MaxScaleFactor. The boolean ClampScaling has to 232 * be "on" for this to work. 233 */ 234 vtkSetMacro(MaxScaleFactor,double); 235 vtkGetMacro(MaxScaleFactor,double); 236 //@} 237 238 protected: 239 vtkTensorGlyph(); 240 ~vtkTensorGlyph() override; 241 242 int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override; 243 int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override; 244 int FillInputPortInformation(int port, vtkInformation *info) override; 245 246 vtkTypeBool Scaling; // Determine whether scaling of geometry is performed 247 double ScaleFactor; // Scale factor to use to scale geometry 248 vtkTypeBool ExtractEigenvalues; // Boolean controls eigenfunction extraction 249 vtkTypeBool ColorGlyphs; // Boolean controls coloring with input scalar data 250 int ColorMode; // The coloring mode to use for the glyphs. 251 vtkTypeBool ClampScaling; // Boolean controls whether scaling is clamped. 252 double MaxScaleFactor; // Maximum scale factor (ScaleFactor*eigenvalue) 253 vtkTypeBool ThreeGlyphs; // Boolean controls drawing 1 or 3 glyphs 254 vtkTypeBool Symmetric; // Boolean controls drawing a "mirror" of each glyph 255 double Length; // Distance, in x, from the origin to the end of the glyph 256 private: 257 vtkTensorGlyph(const vtkTensorGlyph&) = delete; 258 void operator=(const vtkTensorGlyph&) = delete; 259 }; 260 261 #endif 262