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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROData_Image_HeaderFile
20 #define HYDROData_Image_HeaderFile
22 #include <HYDROData_Entity.h>
25 #pragma warning ( disable: 4251 )
32 #pragma warning ( default: 4251 )
35 /**\class HYDROData_Image
36 * \brief Class that stores/retreives information about the image.
38 * Keeps image as binary array, transformation and other properties
39 * of image with correspondent API for forkind wit hthese properties.
41 class HYDROData_Image : public HYDROData_Entity
46 enum TransformationMode
56 ECW_CellUnits_Meters = 1,
57 ECW_CellUnits_Deg = 2,
58 ECW_CellUnits_Feet = 3,
59 ECW_CellUnits_Unknown = -1
64 ECW_CellUnits myCellSizeUnits;
65 double myCellIncrementX;
66 double myCellIncrementY;
75 * Enumeration of tags corresponding to the persistent object parameters.
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
88 DEFINE_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity);
91 * Returns the kind of this object. Must be redefined in all objects of known type.
93 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
96 * Dump Image object to Python script representation.
98 HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
99 MapOfTreatedObjects& theTreatedObjects ) const;
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.
107 HYDRODATA_EXPORT virtual void Update();
110 * Checks that object has 2D presentation. Reimlemented to retun true.
112 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
115 * Returns data of object wrapped to QVariant.
116 * Reimplemented to wrap and return saved image.
117 * Transformation are applied to result image.
119 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
122 * Returns the list of all reference objects of this object.
124 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
129 * \param theImage new image
131 HYDRODATA_EXPORT void SetImage(const QImage& theImage);
134 * Load the image from file
135 * \param theFilePath path to image
137 HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
140 * Load the ECW image from file
141 * \param theFilePath path to image
143 HYDRODATA_EXPORT bool LoadImageECW( const QString& theFilePath );
146 HYDRODATA_EXPORT static bool OpenECW(char* theFileName, QImage& theImage, ECW_FileInfo* theECWInfo);
149 * Returns the kept image
151 HYDRODATA_EXPORT QImage Image();
154 * Stores the image file path
155 * \param theFilePath image file path
157 HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
160 * Returns uploaded image file path
162 HYDRODATA_EXPORT QString GetFilePath() const;
165 * Stores the image transformation
166 * \param theTrsf new transformation
168 HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
171 * Returns the kept transformation, or "identity" if not yet stored
173 HYDRODATA_EXPORT QTransform Trsf() const;
176 * Updates the matrix of transformation in accordance with reference points.
177 * \param theTrsf new transformation
179 HYDRODATA_EXPORT void UpdateTrsf();
183 * Returns true if transformation is done by two points only
185 HYDRODATA_EXPORT bool IsByTwoPoints() const;
189 * Removes all references from this image.
191 HYDRODATA_EXPORT bool HasReferences() const;
194 * Removes all references from this image.
196 HYDRODATA_EXPORT void RemoveAllReferences();
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
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 );
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
217 HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
219 QPoint& thePointC ) const;
222 * Returns true if local points has been set before
224 HYDRODATA_EXPORT bool HasLocalPoints() const;
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
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 );
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
248 HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
251 QPointF& thePointC ) const;
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
258 HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
261 * Returns true if global points has been set before
263 HYDRODATA_EXPORT bool HasGlobalPoints() const;
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
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 );
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
287 HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
290 QPointF& thePointC ) const;
293 * Returns true if reference points has been set before
295 HYDRODATA_EXPORT bool HasReferencePoints() const;
299 * Stores the reference image for transformation
300 * \param theRefImage reference image
302 HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
305 * Returns the reference image for transformation
307 HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
310 * Removes the reference image for transformation
312 HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
316 * Stores the transformation mode
318 HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
321 * Returns the transformation mode
323 HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
327 * Returns the number of referenced objects
328 * \return zero if there is no references
330 HYDRODATA_EXPORT int NbReferences() const;
333 * Appends reference to other object (image or polyline).
334 * \param theReferenced the object referenced by this
336 HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
339 * Returns reference by index.
340 * \param theIndex number of reference [0; NbReference)
341 * \returns the referenced object, or Null if index is invalid
343 HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
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
351 HYDRODATA_EXPORT void ChangeReference(
352 const int theIndex, Handle(HYDROData_Entity) theReferenced);
355 * Removes reference by index
356 * \param theIndex number of reference [0; NbReference)
358 HYDRODATA_EXPORT void RemoveReference(const int theIndex);
361 * Removes all references.
363 HYDRODATA_EXPORT void ClearReferences();
367 * Stores the operator name
368 * \param theOpName name of the operator that must be executed for image update
370 HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
373 * Returns the operator name
374 * \returns the name of the operator that must be executed for image update
376 HYDRODATA_EXPORT QString OperatorName() const;
379 * Stores the operator arguments
380 * \param theArgs array that stores the operator arguments, needed for execution
382 HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
385 * Returns the operator arguments
386 * \returns array that stores the operator arguments, needed for execution
388 HYDRODATA_EXPORT QByteArray Args() const;
392 * Marks the image as self-split.
393 * \param theFlag is true for self-plit image
395 HYDRODATA_EXPORT void SetIsSelfSplit(bool theFlag);
398 * Checks that the image is self-split.
399 * \returns true if image is self-split
401 HYDRODATA_EXPORT bool IsSelfSplit() const;
405 QPointF generateThirdPoint( const QPointF& thePointA,
406 const QPointF& thePointB,
407 const bool& theIsLocal ) const;
411 friend class HYDROData_Iterator;
414 * Creates new object in the internal data structure. Use higher level objects
415 * to create objects with real content.
417 HYDRODATA_EXPORT HYDROData_Image();
420 * Destructs properties of the object and object itself, removes it from the document.
422 HYDRODATA_EXPORT ~HYDROData_Image();