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