Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[modules/hydro.git] / src / HYDROData / HYDROData_Image.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROData_Image_HeaderFile
20 #define HYDROData_Image_HeaderFile
21
22 #include <HYDROData_Entity.h>
23
24 #ifdef WIN32
25   #pragma warning ( disable: 4251 )
26 #endif
27
28 #include <QImage>
29 #include <QTransform>
30
31 #ifdef WIN32
32   #pragma warning ( default: 4251 )
33 #endif
34
35 /**\class HYDROData_Image
36  * \brief Class that stores/retreives information about the image.
37  *
38  * Keeps image as binary array, transformation and other properties
39  * of image with correspondent API for forkind wit hthese properties.
40  */
41 class HYDROData_Image : public HYDROData_Entity
42 {
43
44 public:
45
46   enum TransformationMode
47   {
48     ManualGeodesic = 0,
49     ManualCartesian,
50     CartesianFromFile,
51     ReferenceImage
52   };
53
54   enum ECW_CellUnits
55   {
56     ECW_CellUnits_Meters = 1,
57     ECW_CellUnits_Deg = 2,
58     ECW_CellUnits_Feet = 3,
59     ECW_CellUnits_Unknown = -1
60   };
61
62   struct ECW_FileInfo
63   {
64     ECW_CellUnits myCellSizeUnits;
65     double myCellIncrementX;
66     double myCellIncrementY;
67     double myOriginX;
68     double myOriginY;
69     int myXSize;
70     int myYSize;
71   };
72
73 protected:
74   /**
75    * Enumeration of tags corresponding to the persistent object parameters.
76    */
77   enum DataTag
78   {
79     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
80     DataTag_Operator,        ///< name of the operator that must be executed for image update
81     DataTag_TrsfMode,        ///< transformation mode (0 - Lambert93, 1 - Cartesian, 2 - on other Image)
82     DataTag_TrsfPoints,      ///< image transformation points 
83     DataTag_TrsfImage,      ///< reference transformation image
84     DataTag_FilePath         ///< image imported file path
85   };
86
87 public:
88   DEFINE_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity);
89
90   /**
91    * Returns the kind of this object. Must be redefined in all objects of known type.
92    */
93   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
94
95   /**
96    * Dump Image object to Python script representation.
97    */
98   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
99                                                      MapOfTreatedObjects& theTreatedObjects ) const;
100
101   /**
102    * Updates object state.
103    * Reimplemented to update an Image object in the data structure.
104    * Call this method whenever you made changes for operator or reference objects.
105    * If it is changed, sets "MustBeUpdated" flag to other depended images.
106    */
107   HYDRODATA_EXPORT virtual void Update();
108
109   /**
110    * Checks that object has 2D presentation. Reimlemented to retun true.
111    */
112   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
113
114   /**
115    * Returns data of object wrapped to QVariant.
116    * Reimplemented to wrap and return saved image.
117    * Transformation are applied to result image.
118    */
119   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
120
121   /**
122    * Returns the list of all reference objects of this object.
123    */
124   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
125
126
127   /**
128    * Stores the image
129    * \param theImage new image
130    */
131   HYDRODATA_EXPORT void SetImage(const QImage& theImage);
132
133   /**
134    * Load the image from file
135    * \param theFilePath path to image
136    */
137   HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
138
139   /**
140    * Load the ECW image from file
141    * \param theFilePath path to image
142    */
143   HYDRODATA_EXPORT bool LoadImageECW( const QString& theFilePath );
144
145
146   HYDRODATA_EXPORT static bool OpenECW(char* theFileName, QImage& theImage, ECW_FileInfo* theECWInfo);
147
148   /**
149    * Returns the kept image
150    */
151   HYDRODATA_EXPORT QImage Image();
152
153   /**
154    * Stores the image file path
155    * \param theFilePath image file path
156    */
157   HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
158
159   /**
160    * Returns uploaded image file path
161    */
162   HYDRODATA_EXPORT QString GetFilePath() const;
163
164   /**
165    * Stores the image transformation
166    * \param theTrsf new transformation
167    */
168   HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
169
170   /**
171    * Returns the kept transformation, or "identity" if not yet stored
172    */
173   HYDRODATA_EXPORT QTransform Trsf() const;
174
175   /**
176    * Updates the matrix of transformation in accordance with reference points.
177    * \param theTrsf new transformation
178    */
179   HYDRODATA_EXPORT void UpdateTrsf();
180
181
182   /**
183    * Returns true if transformation is done by two points only
184    */
185   HYDRODATA_EXPORT bool IsByTwoPoints() const;
186
187
188   /**
189    * Removes all references from this image.
190    */
191   HYDRODATA_EXPORT bool HasReferences() const;
192
193   /**
194    * Removes all references from this image.
195    */
196   HYDRODATA_EXPORT void RemoveAllReferences();
197
198
199   /**
200    * Stores the transformation points in local cs of image
201    * \param thePointA point A
202    * \param thePointB point B
203    * \param thePointC point C
204    */
205   HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
206                                         const QPoint& thePointB,
207                                         const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
208                                         const bool    theIsUpdate = true );
209
210   /**
211    * Returns the transformation points in local cs of image
212    * \param thePointA point A
213    * \param thePointB point B
214    * \param thePointC point C
215    * \return true if all parameters has been set before
216    */
217   HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
218                                         QPoint& thePointB,
219                                         QPoint& thePointC ) const;
220
221   /**
222    * Returns true if local points has been set before
223    */
224   HYDRODATA_EXPORT bool HasLocalPoints() const;
225
226
227   /**
228    * Stores the transformation points in global cs
229    * \param theMode transformation mode
230    * \param thePointA point A
231    * \param thePointB point B
232    * \param thePointC point C
233    */
234   HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
235                                          const QPointF&            thePointA,
236                                          const QPointF&            thePointB,
237                                          const QPointF&            thePointC = QPoint( INT_MIN, INT_MIN ),
238                                          const bool                theIsUpdate = true  );
239
240   /**
241    * Returns the transformation points in global cs
242    * \param theMode transformation mode
243    * \param thePointA point A
244    * \param thePointB point B
245    * \param thePointC point C
246    * \return true if all parameters has been set before
247    */
248   HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
249                                          QPointF&            thePointA,
250                                          QPointF&            thePointB,
251                                          QPointF&            thePointC ) const;
252
253   /**
254    * Get transformation points from the file and stores them in global cs
255    * \param theFileName the image georeferencement file name
256    * \return true in case of success
257    */
258   HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
259
260   /**
261    * Returns true if global points has been set before
262    */
263   HYDRODATA_EXPORT bool HasGlobalPoints() const;
264
265
266   /**
267    * Stores the transformation points in reference image local cs
268    * \param theRefImage reference image
269    * \param thePointA point A
270    * \param thePointB point B
271    * \param thePointC point C
272    */
273   HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
274                                             const QPointF&                 thePointA,
275                                             const QPointF&                 thePointB,
276                                             const QPointF&                 thePointC = QPoint( INT_MIN, INT_MIN ),
277                                             const bool                     theIsUpdate = true );
278
279   /**
280    * Returns the transformation points in reference image local cs
281    * \param theRefImage reference image
282    * \param thePointA point A
283    * \param thePointB point B
284    * \param thePointC point C
285    * \return true if all parameters has been set correctly
286    */
287   HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
288                                             QPointF&                 thePointA,
289                                             QPointF&                 thePointB,
290                                             QPointF&                 thePointC ) const;
291
292   /**
293    * Returns true if reference points has been set before
294    */
295   HYDRODATA_EXPORT bool HasReferencePoints() const;
296
297
298   /**
299    * Stores the reference image for transformation
300    * \param theRefImage reference image
301    */
302   HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
303
304   /**
305    * Returns the reference image for transformation
306    */
307   HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
308
309   /**
310    * Removes the reference image for transformation
311    */
312   HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
313
314
315   /**
316    * Stores the transformation mode
317    */
318   HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
319
320   /**
321    * Returns the transformation mode
322    */
323   HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
324
325
326   /**
327    * Returns the number of referenced objects
328    * \return zero if there is no references
329    */
330   HYDRODATA_EXPORT int NbReferences() const;
331
332   /**
333    * Appends reference to other object (image or polyline).
334    * \param theReferenced the object referenced by this
335    */
336   HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
337
338   /**
339    * Returns reference by index.
340    * \param theIndex number of reference [0; NbReference)
341    * \returns the referenced object, or Null if index is invalid
342    */
343   HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
344
345   /**
346    * Updates reference by index. If index is one-bigger than \a NbReferences, 
347    * this method appends it to the end (NbReferences is incremented).
348    * \param theIndex number of reference [0; NbReference]
349    * \param theReferenced the object referenced by this
350    */
351   HYDRODATA_EXPORT void ChangeReference(
352     const int theIndex, Handle(HYDROData_Entity) theReferenced);
353
354   /**
355    * Removes reference by index
356    * \param theIndex number of reference [0; NbReference)
357    */
358   HYDRODATA_EXPORT void RemoveReference(const int theIndex);
359
360   /**
361    * Removes all references.
362    */
363   HYDRODATA_EXPORT void ClearReferences();
364
365
366   /**
367    * Stores the operator name
368    * \param theOpName name of the operator that must be executed for image update
369    */
370   HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
371
372   /**
373    * Returns the operator name
374    * \returns the name of the operator that must be executed for image update
375    */
376   HYDRODATA_EXPORT QString OperatorName() const;
377
378   /**
379    * Stores the operator arguments
380    * \param theArgs array that stores the operator arguments, needed for execution
381    */
382   HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
383
384   /**
385    * Returns the operator arguments
386    * \returns array that stores the operator arguments, needed for execution
387    */
388   HYDRODATA_EXPORT QByteArray Args() const;
389   
390
391   /**
392    * Marks the image as self-split.
393    * \param theFlag is true for self-plit image
394    */
395   HYDRODATA_EXPORT void SetIsSelfSplit(bool theFlag);
396
397   /**
398    * Checks that the image is self-split.
399    * \returns true if image is self-split
400    */
401   HYDRODATA_EXPORT bool IsSelfSplit() const;
402
403 private:
404
405   QPointF generateThirdPoint( const QPointF& thePointA,
406                               const QPointF& thePointB,
407                               const bool&    theIsLocal ) const;
408
409 protected:
410
411   friend class HYDROData_Iterator;
412
413   /**
414    * Creates new object in the internal data structure. Use higher level objects 
415    * to create objects with real content.
416    */
417   HYDRODATA_EXPORT HYDROData_Image();
418
419   /**
420    * Destructs properties of the object and object itself, removes it from the document.
421    */
422   HYDRODATA_EXPORT ~HYDROData_Image();
423
424 };
425
426 #endif