Salome HOME
updated copyright message
[modules/gui.git] / src / VTKViewer / VTKViewer_ArcBuilder.h
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef VTKVIEWER_ARCBUILDER_H
21 #define VTKVIEWER_ARCBUILDER_H
22
23 #include "VTKViewer.h"
24 #include <list>
25 #include <map>
26 #include <vector>
27
28 #include <vtkType.h>
29 #include <vtkSmartPointer.h>
30
31 class vtkCell;
32 class vtkDataArray;
33 class vtkPoints;
34 class vtkPolyData;
35 class vtkUnstructuredGrid;
36
37 class Pnt;
38
39 typedef std::list<Pnt> PntList;
40
41 vtkIdType MergevtkPoints(const std::vector< vtkSmartPointer< vtkPoints > >& theCollection,
42                          const std::vector< std::vector<double> >& theScalarCollection,
43                          vtkPoints* thePoints,
44                          std::map<vtkIdType, double>& thePntId2ScalarValue,
45                          vtkIdType* &theIds);
46
47 vtkIdType Build1DArc(vtkIdType cellId, 
48                      vtkUnstructuredGrid* input, 
49                      vtkPolyData *output,
50                      vtkIdType *pts, 
51                      double myMaxArcAngle);
52
53 Pnt CreatePnt(vtkCell* cell,
54               vtkDataArray* scalars,
55               vtkIdType index);
56
57 /*!
58  * Class for represenation coordinates X,Y,Z
59  */
60 class XYZ{
61  public:
62   
63   XYZ();
64   XYZ(double , double , double);
65   ~XYZ();
66   
67   double X()const {return x;}
68   double Y()const {return y;}
69   double Z()const {return z;}
70
71   void SetX(const double X) { x=X; }
72   void SetY(const double Y) { y=Y; }
73   void SetZ(const double Z) { z=Z; }
74   
75   void Coord (double& X, double& Y, double& Z) const { X = x; Y = y; Z = z; }
76
77   double Modulus () const;
78
79  private:
80   double x;
81   double y;
82   double z;
83 };
84
85 /*!
86   Class for the representation point in the 3D space.
87 */
88 class Pnt{
89  public:
90   Pnt();
91   Pnt(double, double, double, double);
92   ~Pnt();
93
94   void Coord (double& X, double& Y, double& Z) const {coord.Coord(X,Y,Z);}
95   XYZ GetXYZ() const {return coord;}
96   double GetScalarValue() const { return scalarValue; }
97
98  private:
99   XYZ coord;
100   double scalarValue;
101 };
102
103 /*!
104   Class for the representation Vector in the 3D space.
105 */
106 class Vec{
107  public:
108
109   Vec(const double Xv, const double Yv, const double Zv);
110   ~Vec();
111   
112   XYZ GetXYZ() const {return coord;}
113
114   double AngleBetween(const Vec & Other);
115   double AngleBetweenInGrad(const Vec & Other);
116
117   Vec VectMultiplication(const Vec & Other) const;
118   
119  private:
120   XYZ coord;
121 };
122
123 /*!
124   Class for the representation plane in the 3D.
125 */
126 class Plane{
127
128  public:
129   Plane(const Pnt& thePnt1, const Pnt& thePnt2, const Pnt& thePnt3);
130   ~Plane();
131
132   double A() const {return myA;}
133   double B() const {return myB;}
134   double C() const {return myC;} 
135
136   Vec GetNormale() const; 
137   
138  private:
139   void CalculatePlane(const Pnt& thePnt1, const Pnt& thePnt2, const Pnt& thePnt3);
140   
141  private:
142         double myA;
143         double myB;
144         double myC;
145 };
146
147
148 class VTKViewer_ArcBuilder{
149  public:
150   enum ArcStatus {Arc_Done=0, Arc_Error};
151   VTKViewer_ArcBuilder(const Pnt& thePnt1,
152                        const Pnt& thePnt2,
153                        const Pnt& thePnt3,
154                        double theAngle);
155   
156   ~VTKViewer_ArcBuilder();  
157
158   Vec GetNormale();
159   
160   ArcStatus GetStatus(){return myStatus;}
161
162   void GetAngle(const double theAngle);
163
164   static double GetPointAngleOnCircle(const double theXCenter, const double theYCenter,
165                                       const double theXPoint, const double theYPoint);
166
167   vtkPoints* GetPoints();
168   const std::vector<double>& GetScalarValues();
169
170  private:
171   
172   enum IncOrder{MINUS=0,PLUS};
173   
174   vtkUnstructuredGrid* BuildGrid(const PntList& theList) const;
175   vtkUnstructuredGrid* TransformGrid(vtkUnstructuredGrid* theGrid, const Vec& theAxis, const double angle) const;
176   vtkUnstructuredGrid* BuildArc(std::vector<double>& theScalarValues);
177   IncOrder GetArcAngle( const double& P1, const double& P2, const double& P3, double* Ang);
178   
179
180
181   private:
182   Pnt myPnt1;
183   Pnt myPnt2;
184   Pnt myPnt3;
185
186   double myAngle;
187   ArcStatus myStatus;
188   vtkSmartPointer<vtkPoints> myPoints;
189   std::vector<double> myScalarValues;
190 };
191
192 #endif //VTKVIEWER_ARCBUILDER_H