CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxColorVariationFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXCOLORVARIATIONFILTER_H
13 #define CXCOLORVARIATIONFILTER_H
14 
15 #include <random>
16 #include "cxFilterImpl.h"
17 
18 namespace cx
19 {
20 
27 class cxResourceFilter_EXPORT ColorVariationFilter : public FilterImpl
28 {
29  Q_OBJECT
30 
31 public:
33  virtual ~ColorVariationFilter() {}
34 
35  virtual QString getType() const;
36  virtual QString getName() const;
37  virtual QString getHelp() const;
38  static QString getNameSuffixColorVariation();
39  MeshPtr getOutputMesh();
40 
41  virtual bool execute();
42  MeshPtr execute(MeshPtr inputMesh, double globaleVariance, double localeVariance, int smoothingIterations);
43  virtual bool postProcess();
44 
45 protected:
46  virtual void createOptions();
47  virtual void createInputTypes();
48  virtual void createOutputTypes();
49 
50 private:
51  DoublePropertyPtr getGlobalVarianceOption(QDomElement root);
52  DoublePropertyPtr getLocalVarianceOption(QDomElement root);
53  DoublePropertyPtr getSmoothingOption(QDomElement root);
54 
55  void sortPolyData(vtkPolyDataPtr polyData);
56  vtkUnsignedCharArrayPtr colorPolyData(MeshPtr mesh);
57  void applyColorToNeighbourPolys(int startIndex, double R, double G, double B);
58  std::vector<vtkIdType> applyColorAndFindNeighbours(int pointIndex, double R, double G, double B);
59  void generateColorDistribution();
60  std::vector<double> generateColor(double R, double G, double B);
61  void smoothColorsInMesh(int iterations = 1);
62 
63  MeshPtr mOutputMesh;
65  std::vector<std::vector<vtkIdType>> mPolyToPointsArray;
66  std::vector<std::vector<vtkIdType>> mPointToPolysArray;
67  std::vector<bool> mAssignedColorValues;
68  double mGlobalVariance;
69  double mLocalVariance;
70  double mR_mean;
71  double mG_mean;
72  double mB_mean;
73  std::normal_distribution<> mR_dist;
74  std::normal_distribution<> mG_dist;
75  std::normal_distribution<> mB_dist;
76  std::random_device m_rd{};
77  std::mt19937 m_gen{m_rd()};
78 };
79 
80 typedef boost::shared_ptr<ColorVariationFilter> ColorVariationFilterPtr;
81 
82 } // namespace cx
83 
84 
85 #endif // CXCOLORVARIATIONFILTER_H
boost::shared_ptr< ColorVariationFilter > ColorVariationFilterPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
vtkSmartPointer< class vtkUnsignedCharArray > vtkUnsignedCharArrayPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
boost::shared_ptr< class Mesh > MeshPtr
Namespace for all CustusX production code.