wolfhece 2.2.33__py3-none-any.whl → 2.2.35__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wolfhece/wolf_texture.py CHANGED
@@ -48,12 +48,32 @@ class genericImagetexture(Element_To_Draw):
48
48
  which: str,
49
49
  label: str,
50
50
  mapviewer,
51
- xmin, xmax, ymin, ymax,
52
- imageFile="",
53
- imageObj=None,
51
+ xmin:float, xmax:float, ymin:float, ymax:float,
52
+ imageFile:str = "",
53
+ imageObj = None,
54
54
  transparent_color = None,
55
55
  tolerance:int = 3,
56
- replace_color = None) -> None:
56
+ replace_color = None,
57
+ drawing_scale:float = 1.0,
58
+ offset:list[float, float] = [0.,0.]) -> None:
59
+
60
+ """ Initialize the image texture
61
+
62
+ :param which: Type of image (e.g., 'satellite', 'map', etc.)
63
+ :param label: Label for the texture
64
+ :param mapviewer: The map viewer object to which this texture belongs
65
+ :param xmin: Minimum X coordinate for the texture
66
+ :param xmax: Maximum X coordinate for the texture
67
+ :param ymin: Minimum Y coordinate for the texture
68
+ :param ymax: Maximum Y coordinate for the texture
69
+ :param imageFile: Optional file path to load the image from
70
+ :param imageObj: Optional PIL Image object to use instead of loading from file
71
+ :param transparent_color: Color to treat as transparent in the image
72
+ :param tolerance: Tolerance for color matching when replacing transparent color
73
+ :param replace_color: Color to replace the transparent color with
74
+ :param drawing_scale: Scale factor for the image
75
+ :param offset: Offset to apply to the texture position
76
+ """
57
77
 
58
78
  super().__init__(label, True, mapviewer, False)
59
79
 
@@ -61,6 +81,7 @@ class genericImagetexture(Element_To_Draw):
61
81
  self.mapviewer.canvas.SetCurrent(mapviewer.context)
62
82
  except:
63
83
  logging.error(_('Opengl setcurrent -- Do you have a active canvas ?'))
84
+ return
64
85
 
65
86
  self.time = None
66
87
  self.xmin = xmin
@@ -82,6 +103,9 @@ class genericImagetexture(Element_To_Draw):
82
103
  self.imageFile = imageFile
83
104
  self.myImage = imageObj
84
105
 
106
+ self.drawing_scale = drawing_scale
107
+ self.offset = offset
108
+
85
109
  if imageFile != "":
86
110
  if exists(imageFile):
87
111
  try:
@@ -142,6 +166,11 @@ class genericImagetexture(Element_To_Draw):
142
166
  del self.myImage
143
167
 
144
168
  def load(self, imageFile=""):
169
+ """ Load the image texture into OpenGL
170
+
171
+ :param imageFile: Optional file path to load the image from
172
+ """
173
+
145
174
  if self.width == -99999 or self.height == -99999:
146
175
  return
147
176
 
@@ -167,6 +196,7 @@ class genericImagetexture(Element_To_Draw):
167
196
  'Opengl setcurrent -- maybe a conflict with an existing opengl32.dll file - please rename the opengl32.dll in the libs directory and retry')
168
197
 
169
198
  def update_minmax(self):
199
+ """ Update the spatial extent of the texture based on its size """
170
200
 
171
201
  if self.myImage is None:
172
202
  return
@@ -181,7 +211,7 @@ class genericImagetexture(Element_To_Draw):
181
211
 
182
212
  self.ymax = self.ymin + dx *scale
183
213
 
184
- def reload(self,xmin=-99999,xmax=-99999,ymin=-99999,ymax=-99999):
214
+ def reload(self, xmin=-99999, xmax=-99999, ymin=-99999, ymax=-99999):
185
215
 
186
216
  if xmin !=-99999:
187
217
  self.xmin = xmin
@@ -210,7 +240,28 @@ class genericImagetexture(Element_To_Draw):
210
240
  # Nothing to do, set during initialization phase
211
241
  pass
212
242
 
243
+ def uv(self, x: float, y: float) -> tuple[float, float]:
244
+ """ Convert coordinates to texture coordinates taking into account the texture's spatial extent,
245
+ the scaleing factor, and the offset.
246
+
247
+ :param x: X coordinate in pixels
248
+ :param y: Y coordinate in pixels
249
+ :return: Tuple of (u, v) texture coordinates
250
+ """
251
+ if self.width == -99999 or self.height == -99999:
252
+ return 0.0, 0.0
253
+
254
+ u = (x - self.offset[0] - self.xmin) / ((self.xmax - self.xmin) * self.drawing_scale)
255
+ v = 1.0 - (y - self.offset[1] - self.ymin) / ((self.ymax - self.ymin) * self.drawing_scale)
256
+
257
+ # Ensure u and v are within the range [0, 1]
258
+ u = max(0.0, min(1.0, u))
259
+ v = max(0.0, min(1.0, v))
260
+
261
+ return u, v
262
+
213
263
  def paint(self):
264
+ """ Paint the image texture on the OpenGL canvas """
214
265
 
215
266
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
216
267
 
@@ -222,14 +273,31 @@ class genericImagetexture(Element_To_Draw):
222
273
  glBindTexture(GL_TEXTURE_2D, self.idtexture[0])
223
274
 
224
275
  glBegin(GL_QUADS)
225
- glTexCoord2f(0.0, 0.0)
226
- glVertex2f(self.xmin, self.ymax)
227
- glTexCoord2f(1.0, 0.0)
228
- glVertex2f(self.xmax, self.ymax)
229
- glTexCoord2f(1.0, 1.0)
230
- glVertex2f(self.xmax, self.ymin)
231
- glTexCoord2f(0.0, 1.0)
232
- glVertex2f(self.xmin, self.ymin)
276
+
277
+ # Draw a quad with texture coordinates
278
+ xy = [[self.xmin, self.ymax],
279
+ [self.xmax, self.ymax],
280
+ [self.xmax, self.ymin],
281
+ [self.xmin, self.ymin]]
282
+ uv = [self.uv(x,y) for x,y in xy]
283
+
284
+ glTexCoord2f(uv[0][0], uv[0][1])
285
+ glVertex2f(xy[0][0], xy[0][1])
286
+ glTexCoord2f(uv[1][0], uv[1][1])
287
+ glVertex2f(xy[1][0], xy[1][1])
288
+ glTexCoord2f(uv[2][0], uv[2][1])
289
+ glVertex2f(xy[2][0], xy[2][1])
290
+ glTexCoord2f(uv[3][0], uv[3][1])
291
+ glVertex2f(xy[3][0], xy[3][1])
292
+
293
+ # glTexCoord2f(0.0, 0.0)
294
+ # glVertex2f(self.xmin, self.ymax)
295
+ # glTexCoord2f(1.0, 0.0)
296
+ # glVertex2f(self.xmax, self.ymax)
297
+ # glTexCoord2f(1.0, 1.0)
298
+ # glVertex2f(self.xmax, self.ymin)
299
+ # glTexCoord2f(0.0, 1.0)
300
+ # glVertex2f(self.xmin, self.ymin)
233
301
  glEnd()
234
302
  glDisable(GL_TEXTURE_2D)
235
303
  glDisable(GL_BLEND)