VTK
vtkMomentInvariants.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMomentInvariants.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 Copyright (c) 2017, Los Alamos National Security, LLC
18 
19 All rights reserved.
20 
21 Copyright 2017. Los Alamos National Security, LLC.
22 This software was produced under U.S. Government contract DE-AC52-06NA25396
23 for Los Alamos National Laboratory (LANL), which is operated by
24 Los Alamos National Security, LLC for the U.S. Department of Energy.
25 The U.S. Government has rights to use, reproduce, and distribute this software.
26 NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY,
27 EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
28 If software is modified to produce derivative works, such modified software
29 should be clearly marked, so as not to confuse it with the version available
30 from LANL.
31 
32 Additionally, redistribution and use in source and binary forms, with or
33 without modification, are permitted provided that the following conditions
34 are met:
35 - Redistributions of source code must retain the above copyright notice,
36  this list of conditions and the following disclaimer.
37 - Redistributions in binary form must reproduce the above copyright notice,
38  this list of conditions and the following disclaimer in the documentation
39  and/or other materials provided with the distribution.
40 - Neither the name of Los Alamos National Security, LLC, Los Alamos National
41  Laboratory, LANL, the U.S. Government, nor the names of its contributors
42  may be used to endorse or promote products derived from this software
43  without specific prior written permission.
44 
45 THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
46 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
47 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
49 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
50 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
51 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
52 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
53 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
54 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
55 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 
57 =========================================================================*/
79 #ifndef vtkMomentInvariants_h
80 #define vtkMomentInvariants_h
81 
82 #include "vtkDataSetAlgorithm.h"
83 #include "vtkDataSetAttributes.h" // needed for vtkDataSetAttributes::FieldList
84 #include "vtkFiltersMomentInvariantsModule.h" // For export macro
85 #include "vtkTuple.h" // For internal API
86 #include <vector> // For internal API
87 
88 class vtkImageData;
89 class vtkMomentsTensor;
90 
91 class VTKFILTERSMOMENTINVARIANTS_EXPORT vtkMomentInvariants : public vtkDataSetAlgorithm
92 {
93 public:
94  static vtkMomentInvariants* New();
95 
97  void PrintSelf(ostream& os, vtkIndent indent) override;
98 
103  void SetPatternData(vtkDataObject* input) { this->SetInputData(0, input); };
104 
110  {
111  this->SetInputConnection(0, algOutput);
112  };
113 
120  void SetMomentData(vtkDataObject* input) { this->SetInputData(1, input); };
121 
129  {
130  this->SetInputConnection(1, algOutput);
131  };
132 
134 
137  vtkSetMacro(Order, unsigned int);
138  vtkGetMacro(Order, unsigned int);
140 
142 
145  vtkSetMacro(NumberOfIntegrationSteps, int);
146  vtkGetMacro(NumberOfIntegrationSteps, int);
148 
150 
153  vtkSetMacro(AngleResolution, int);
154  vtkGetMacro(AngleResolution, int);
156 
158 
161  vtkSetMacro(Eps, double);
162  vtkGetMacro(Eps, double);
164 
166 
169  vtkSetMacro(NameOfPointData, std::string);
170  vtkGetMacro(NameOfPointData, std::string);
172 
174 
178  vtkSetMacro(IsTranslation, bool);
179  vtkGetMacro(IsTranslation, bool);
181 
183 
187  vtkSetMacro(IsScaling, bool);
188  vtkGetMacro(IsScaling, bool);
190 
192 
195  vtkSetMacro(IsRotation, bool);
196  vtkGetMacro(IsRotation, bool);
198 
200 
203  vtkSetMacro(IsReflection, bool);
204  vtkGetMacro(IsReflection, bool);
206 
211  vtkGetMacro(NumberOfBasisFunctions, int);
212 
216  std::vector<double> GetRadii() { return this->Radii; }
217 
222  void GetRadiiArray(double radiiArray[10])
223  {
224  for (int i = 0; i < 10; ++i)
225  {
226  radiiArray[i] = 0;
227  }
228  for (size_t i = 0; i < this->Radii.size(); ++i)
229  {
230  radiiArray[i] = this->Radii.at(i);
231  }
232  };
233 
237  int GetNumberOfRadii() { return this->Radii.size(); };
238 
242  std::string GetStringRadii(int i) { return std::to_string(this->Radii.at(i)).c_str(); };
243 
247  double GetTranslationFactor(int radius, int p, int q, int r)
248  {
249  return this->TranslationFactor[radius + p * this->Radii.size() +
250  q * this->Radii.size() * (this->Order + 1) +
251  r * this->Radii.size() * (this->Order + 1) * (this->Order + 1)];
252  };
253 
257  void SetTranslationFactor(int radius, int p, int q, int r, double value)
258  {
259  this->TranslationFactor[radius + p * this->Radii.size() +
260  q * this->Radii.size() * (this->Order + 1) +
261  r * this->Radii.size() * (this->Order + 1) * (this->Order + 1)] = value;
262  };
263 
264 protected:
269 
273  ~vtkMomentInvariants() override;
274 
276 
283 
284 private:
285  vtkMomentInvariants(const vtkMomentInvariants&) = delete;
286  void operator=(const vtkMomentInvariants&) = delete;
287 
291  double RadiusPattern;
292 
296  double* CenterPattern;
297 
301  int Dimension;
302 
306  int FieldRank;
307 
311  unsigned int Order;
312 
316  std::vector<double> Radii;
317 
321  int NumberOfIntegrationSteps;
322 
327  std::string NameOfPointData;
328 
333  size_t NumberOfFields;
334 
339  size_t NumberOfBasisFunctions;
340 
345  bool IsTranslation;
346 
351  bool IsScaling;
352 
356  bool IsRotation;
357 
361  bool IsReflection;
362 
372  int AngleResolution;
373 
378  double Eps;
379 
383  std::vector<vtkMomentsTensor> MomentsPattern;
384 
389  std::vector<vtkMomentsTensor> MomentsPatternTNormal;
390 
395  std::vector<vtkMomentsTensor> MomentsPatternTSNormal;
396 
402  std::vector<std::vector<vtkMomentsTensor> > MomentsPatternNormal;
403 
408  double* TranslationFactor;
409 
415  int FillInputPortInformation(int port, vtkInformation* info) override;
416 
427 
432  void CheckValidity(vtkImageData* pattern);
433 
439  void InterpretPattern(vtkImageData* pattern);
440 
446  void InterpretField(vtkImageData* moments);
447 
460  void HandlePattern(std::vector<std::vector<vtkMomentsTensor> >& dominantContractions,
461  vtkImageData* pattern,
462  vtkImageData* originalMomentsPattern,
463  vtkImageData* normalizedMomentsPattern);
464 
478  void HandleField(std::vector<std::vector<vtkMomentsTensor> >& dominantContractions,
479  vtkImageData* moments,
480  vtkImageData* normalizedMoments,
481  vtkImageData* pattern,
482  vtkImageData* similarityFields);
483 
489  void BuildTranslationalFactorArray(vtkImageData* pattern);
490 
501  std::vector<vtkMomentsTensor> NormalizeT(std::vector<vtkMomentsTensor>& moments,
502  double radius,
503  bool isTranslation,
504  vtkImageData* stencil);
505 
516  std::vector<vtkMomentsTensor> NormalizeT(std::vector<vtkMomentsTensor>& moments,
517  int radiusIndex,
518  bool isTranslation);
519 
529  std::vector<vtkMomentsTensor> NormalizeTAnalytic(std::vector<vtkMomentsTensor>& moments,
530  double radius,
531  bool isTranslation);
532 
540  std::vector<vtkMomentsTensor> NormalizeS(std::vector<vtkMomentsTensor>& moments,
541  bool isScaling,
542  double radius);
543 
550  std::vector<vtkMomentsTensor> NormalizeR(std::vector<vtkMomentsTensor>& dominantContractions,
551  bool isRotation,
552  bool isReflection,
553  std::vector<vtkMomentsTensor>& moments);
554 
565  std::vector<std::vector<vtkMomentsTensor> > CalculateDominantContractions(
566  std::vector<vtkMomentsTensor>& momentsPattern);
567 
576  std::vector<vtkMomentsTensor> ReproduceContractions(
577  std::vector<vtkMomentsTensor>& dominantContractions,
578  std::vector<vtkMomentsTensor>& moments);
579 
592  void LookEverywhere(std::vector<std::vector<vtkMomentsTensor> >& momentsPatternNormal,
593  std::vector<vtkMomentsTensor>& momentsPatternTranslationalNormal);
594 
605  void LookEverywhere(std::vector<std::vector<vtkMomentsTensor> >& dominantContractions,
606  std::vector<std::vector<vtkMomentsTensor> >& momentsPatternNormal);
607 
617  template<size_t S>
618  vtkTuple<double, S> Reconstruct(double* p,
619  std::vector<vtkMomentsTensor>& moments,
620  double* center);
621 };
622 
623 #endif
Store vtkAlgorithm input/output information.
void GetRadiiArray(double radiiArray[10])
Get the different integration radii from the momentData as constant length array for python wrapping.
void SetPatternConnection(vtkAlgorithmOutput *algOutput)
standard pipeline input for port 1 This is the pattern, a vtkDataSet of scalar, vector,...
int FillOutputPortInformation(int port, vtkInformation *info) override
Fill the output port information objects for this algorithm.
std::vector< double > GetRadii()
Get the different integration radii from the momentData.
void SetInputData(vtkDataObject *)
Assign a data object as input.
void SetMomentConnection(vtkAlgorithmOutput *algOutput)
standard pipeline input for port 1 This is the vtkImageData field of which the moments are calculated...
Proxy object to connect input/output ports.
std::string GetStringRadii(int i)
Get the different integration radii from the momentData as string.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
templated base type for containers of constant size.
Definition: vtkTuple.h:35
a simple class to control print indentation
Definition: vtkIndent.h:33
rotation invariant pattern detetction
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
void SetPatternData(vtkDataObject *input)
standard pipeline input for port 1 This is the pattern, a vtkDataSet of scalar, vector,...
helper class that stores a tensor of arbitrary rank and dimension
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called within ProcessRequest when a request asks the algorithm to do its work.
double GetTranslationFactor(int radius, int p, int q, int r)
Get the translation factor.
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called within ProcessRequest when each filter in the pipeline decides what portion of its inp...
void SetMomentData(vtkDataObject *input)
standard pipeline input for port 1 This is the vtkImageData field of which the moments are calculated...
void SetTranslationFactor(int radius, int p, int q, int r, double value)
Get the translation factor.
Store zero or more vtkInformation instances.
Superclass for algorithms that produce output of the same type as input.
int GetNumberOfRadii()
Get the number of the different integration radii from the momentData.
general representation of visualization data
Definition: vtkDataObject.h:58
static vtkDataSetAlgorithm * New()
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.