Salome HOME
0f27af523f1cb4c82deb4ec11687ab535c64dc75
[modules/gui.git] / src / VTKViewer / VTKViewer_ArcBuilder.h
1 // Copyright (C) 2007-2012  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.
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
30 class vtkCell;
31 class vtkDataArray;
32 class vtkPoints;
33 class vtkPolyData;
34 class vtkUnstructuredGrid;
35
36 class Pnt;
37
38 typedef std::list<Pnt> PntList;
39
40 vtkIdType MergevtkPoints(const std::vector<vtkPoints*>& theCollection,
41                          const std::vector< std::vector<double> >& theScalarCollection,
42                          vtkPoints* thePoints,
43                          std::map<int, double>& thePntId2ScalarValue,
44                          vtkIdType* &theIds);
45
46 vtkIdType Build1DArc(vtkIdType cellId, 
47                      vtkUnstructuredGrid* input, 
48                      vtkPolyData *output,
49                      vtkIdType *pts, 
50                      double myMaxArcAngle);
51
52 Pnt CreatePnt(vtkCell* cell,
53               vtkDataArray* scalars,
54               vtkIdType index);
55
56 /*!
57  * Class for represenation coordinates X,Y,Z
58  */
59 class XYZ{
60  public:
61   
62   XYZ();
63   XYZ(double , double , double);
64   ~XYZ();
65   
66   double X()const {return x;}
67   double Y()const {return y;}
68   double Z()const {return z;}
69
70   void SetX(const double X) { x=X; }
71   void SetY(const double Y) { y=Y; }
72   void SetZ(const double Z) { z=Z; }
73   
74   void Coord (double& X, double& Y, double& Z) const { X = x; Y = y; Z = z; }
75
76   double Modulus () const;
77
78  private:
79   double x;
80   double y;
81   double z;
82 };
83
84 /*!
85   Class for the representation point in the 3D space.
86 */
87 class Pnt{
88  public:
89   Pnt();
90   Pnt(double, double, double, double);
91   ~Pnt();
92
93   void Coord (double& X, double& Y, double& Z) const {coord.Coord(X,Y,Z);}
94   XYZ GetXYZ() const {return coord;}
95   double GetScalarValue() const { return scalarValue; }
96
97  private:
98   XYZ coord;
99   double scalarValue;
100 };
101
102 /*!
103   Class for the representation Vector in the 3D space.
104 */
105 class Vec{
106  public:
107
108   Vec(const double Xv, const double Yv, const double Zv);
109   ~Vec();
110   
111   XYZ GetXYZ() const {return coord;}
112
113   double AngleBetween(const Vec & Other);
114   double AngleBetweenInGrad(const Vec & Other);
115
116   Vec VectMultiplication(const Vec & Other) const;
117   
118  private:
119   XYZ coord;
120 };
121
122 /*!
123   Class for the representation plane in the 3D.
124 */
125 class Plane{
126
127  public:
128   Plane(const Pnt& thePnt1, const Pnt& thePnt2, const Pnt& thePnt3);
129   ~Plane();
130
131   double A() const {return myA;}
132   double B() const {return myB;}
133   double C() const {return myC;} 
134
135   Vec GetNormale() const; 
136   
137  private:
138   void CalculatePlane(const Pnt& thePnt1, const Pnt& thePnt2, const Pnt& thePnt3);
139   
140  private:
141         double myA;
142         double myB;
143         double myC;
144 };
145
146
147 class VTKViewer_ArcBuilder{
148  public:
149   enum ArcStatus {Arc_Done=0, Arc_Error};
150   VTKViewer_ArcBuilder(const Pnt& thePnt1,
151                        const Pnt& thePnt2,
152                        const Pnt& thePnt3,
153                        double theAngle);
154   
155   ~VTKViewer_ArcBuilder();  
156
157   Vec GetNormale();
158   
159   ArcStatus GetStatus(){return myStatus;}
160
161   void GetAngle(const double theAngle);
162
163   static double GetPointAngleOnCircle(const double theXCenter, const double theYCenter,
164                                       const double theXPoint, const double theYPoint);
165
166   vtkPoints* GetPoints();
167   const std::vector<double>& GetScalarValues();
168
169  private:
170   
171   enum IncOrder{MINUS=0,PLUS};
172   
173   vtkUnstructuredGrid* BuildGrid(const PntList& theList) const;
174   vtkUnstructuredGrid* TransformGrid(vtkUnstructuredGrid* theGrid, const Vec& theAxis, const double angle) const;
175   vtkUnstructuredGrid* BuildArc(std::vector<double>& theScalarValues);
176   IncOrder GetArcAngle( const double& P1, const double& P2, const double& P3, double* Ang);
177   
178
179
180   private:
181   Pnt myPnt1;
182   Pnt myPnt2;
183   Pnt myPnt3;
184
185   double myAngle;
186   ArcStatus myStatus;
187   vtkPoints* myPoints;
188   std::vector<double> myScalarValues;
189 };
190
191 #endif //VTKVIEWER_ARCBUILDER_H