[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1300] trunk/py/scripts/addons: commit latest version of the IMG converter for Tim Spriggs.

Stephen Swaney sswaney at centurytel.net
Wed Dec 22 09:34:12 CET 2010


Revision: 1300
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1300
Author:   stiv
Date:     2010-12-22 09:34:11 +0100 (Wed, 22 Dec 2010)

Log Message:
-----------
commit latest version of the IMG converter for Tim Spriggs.
from [#24897] Import a HiRISE DTM formatted as a PDS IMG file

Do we have this named correctly now?

Added Paths:
-----------
    trunk/py/scripts/addons/io_convert_image_to_mesh_img/
    trunk/py/scripts/addons/io_convert_image_to_mesh_img/__init__.py
    trunk/py/scripts/addons/io_convert_image_to_mesh_img/import_img.py

Added: trunk/py/scripts/addons/io_convert_image_to_mesh_img/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_convert_image_to_mesh_img/__init__.py	                        (rev 0)
+++ trunk/py/scripts/addons/io_convert_image_to_mesh_img/__init__.py	2010-12-22 08:34:11 UTC (rev 1300)
@@ -0,0 +1,127 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# Revision History:
+# 0.1.1 - make default import 12x12 bin (fast) to not consume too much memory
+#         by default (TJS - 2010-12-07)
+# 0.1.2 - included into svn under the tree:
+#         trunk/py/scripts/addons/io_convert_image_to_mesh_img
+#         may be moved out to contrib once the blender downloader works well
+#         (TJS - 2010-12-14)
+
+bl_addon_info = {
+    "name": "HiRISE DTM from PDS IMG",
+    "author": "Tim Spriggs (tims at uahirise.org)",
+    "version": (0,1,2),
+    "blender": (2,5,3),
+    "api": 31998,
+    "location": "File > Import > HiRISE DTM from PDS IMG (.IMG)",
+    "description": "Import a HiRISE DTM formatted as a PDS IMG file",
+    "warning": "This is beta quality code and the final product may consume a lot of memory",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
+        "Scripts/File_I-O/HiRISE_DTM_from_PDS_IMG",
+    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
+        "func=detail&aid=24897&group_id=153&atid=467",
+    "category": "Import/Export"}
+
+import bpy
+from bpy.props import *
+from io_utils import ImportHelper
+
+try:
+    init_data
+    reload( io_convert_image_to_mesh_img.import_img )
+except:
+    import io_convert_image_to_mesh_img.import_img
+
+init_data = True
+
+class ImportHiRISEIMGDTM(bpy.types.Operator, ImportHelper):
+    '''Import a HiRISE DTM formatted as a PDS IMG file'''
+    bl_idname = "import_shape.img"
+    bl_label  = "Import HiRISE DTM from PDS IMG"
+
+    filename_ext = ".IMG"
+    filter_glob = StringProperty(default="*.IMG", options={'HIDDEN'})
+
+    scale = FloatProperty(
+                          name="Scale",
+			  description="Scale the IMG by this value",
+			  min=0.0001,
+			  max=10.0,
+			  soft_min=0.001,
+			  soft_max=100.0,
+			  default=0.01)
+
+    bin_mode = EnumProperty(items=(
+                                   ('NONE', "None", "Don't bin the image"),
+                                   ('BIN2', "2x2", "use 2x2 binning to import the mesh"),
+                                   ('BIN6', "6x6", "use 6x6 binning to import the mesh"),
+                                   ('BIN6-FAST', "6x6 Fast", "use one sample per 6x6 region"),
+                                   ('BIN12', "12x12", "use 12x12 binning to import the mesh"),
+                                   ('BIN12-FAST', "12x12 Fast", "use one sample per 12x12 region"),
+                                  ),
+                            name="Binning",
+                            description="Import Binning.",
+                            default='BIN12-FAST'
+			    )
+
+    #red_material = BoolProperty(name="Mars Red Mesh",
+    #                            description="Set the mesh as a 'Mars' red value",
+    #                            default=True
+    #			        )
+
+    ## TODO: add support for cropping on import when the checkbox is checked
+    # do_crop = BoolProperty(name="Crop Image", description="Crop the image during import", ... )
+    ## we only want these visible when the above is "true"
+    # crop_x = IntProperty(name="X", description="Offset from left side of image")
+    # crop_y = IntProperty(name="Y", description="Offset from top of image")
+    # crop_w = IntProperty(name="Width", description="width of cropped operation")
+    # crop_h = IntProperty(name="Height", description="height of cropped region")
+    ## This is also a bit ugly and maybe an anti-pattern. The problem is that
+    ## importing a HiRISE DTM at full resolution will likely kill any mortal user with
+    ## less than 16 GB RAM and getting at specific features in a DTM at full res
+    ## may prove beneficial. Someday most mortals will have 16GB RAM.
+    ## -TJS 2010-11-23
+
+    def execute(self, context):
+      filepath = self.filepath
+      filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
+
+      return import_img.load(self, context,
+                             filepath=self.filepath,
+                             scale=self.scale,
+                             bin_mode=self.bin_mode,
+                             cropVars=False,
+                             # marsRed=self.red_material
+                             marsRed=False
+                             )
+
+## How to register the script inside of Blender
+
+def menu_import(self, context):
+    self.layout.operator(ImportHiRISEIMGDTM.bl_idname, text="HiRISE DTM from PDS IMG (*.IMG)")
+
+def register():
+    bpy.types.INFO_MT_file_import.append(menu_import)
+
+def unregister():
+    bpy.types.INFO_MT_file_import.remove(menu_import)
+
+if __name__ == "__main__":
+    register()

Added: trunk/py/scripts/addons/io_convert_image_to_mesh_img/import_img.py
===================================================================
--- trunk/py/scripts/addons/io_convert_image_to_mesh_img/import_img.py	                        (rev 0)
+++ trunk/py/scripts/addons/io_convert_image_to_mesh_img/import_img.py	2010-12-22 08:34:11 UTC (rev 1300)
@@ -0,0 +1,786 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+"""
+This script can import a HiRISE DTM .IMG file.
+"""
+
+import bpy
+from bpy.props import *
+
+from struct import pack, unpack, unpack_from
+import os
+import queue, threading
+
+class image_props:
+    ''' keeps track of image attributes throughout the hirise_dtm_helper class '''
+    def __init__(self, name, dimensions, pixel_scale):
+      self.name( name )
+      self.dims( dimensions )
+      self.processed_dims( dimensions )
+      self.pixel_scale( pixel_scale )
+
+    def dims(self, dims=None):
+      if dims is not None:
+        self.__dims = dims
+      return self.__dims
+
+    def processed_dims(self, processed_dims=None):
+      if processed_dims is not None:
+        self.__processed_dims = processed_dims
+      return self.__processed_dims
+
+    def name(self, name=None):
+      if name is not None:
+        self.__name = name
+      return self.__name
+
+    def pixel_scale(self, pixel_scale=None):
+      if pixel_scale is not None:
+        self.__pixel_scale = pixel_scale
+      return self.__pixel_scale
+
+class hirise_dtm_helper(object):
+    ''' methods to understand/import a HiRISE DTM formatted as a PDS .IMG '''
+
+    def __init__(self, context, filepath):
+      self.__context = context
+      self.__filepath = filepath
+      self.__ignore_value = 0x00000000
+      self.__bin_mode = 'BIN6'
+      self.scale( 1.0 )
+      self.__cropXY = False
+      self.marsRed(False)
+
+    def bin_mode(self, bin_mode=None):
+      if bin_mode != None:
+        self.__bin_mode = bin_mode
+      return self.__bin_mode
+
+    def scale(self, scale=None):
+      if scale is not None:
+        self.__scale = scale
+      return self.__scale
+
+    def crop(self, widthX, widthY, offX, offY):
+      self.__cropXY = [ widthX, widthY, offX, offY ]
+      return self.__cropXY
+
+    def marsRed(self, marsRed=None):
+      if marsRed is not None:
+        self.__marsRed = marsRed
+      return self.__marsRed
+
+    def dbg(self, mesg):
+      print(mesg)
+
+    ############################################################################
+    ## PDS Label Operations
+    ############################################################################
+
+    def parsePDSLabel(self, labelIter, currentObjectName=None, level = ""):
+      # Let's parse this thing... semi-recursively
+      ## I started writing this caring about everything in the PDS standard but ...
+      ## it's a mess and I only need a few things -- thar be hacks below
+      ## Mostly I just don't care about continued data from previous lines
+      label_structure = []
+
+      # When are we done with this level?
+      endStr = "END"
+      if not currentObjectName == None:
+        endStr = "END_OBJECT = %s" % currentObjectName
+      line = ""
+
+      while not line.rstrip() == endStr:
+        line = next(labelIter)
+
+        # Get rid of comments
+        comment = line.find("/*")
+        if comment > -1:
+          line = line[:comment]
+
+        # Take notice of objects
+        if line[:8] == "OBJECT =":
+          objName = line[8:].rstrip()
+          label_structure.append(
+            (
+             objName.lstrip().rstrip(),
+             self.parsePDSLabel(labelIter, objName.lstrip().rstrip(), level + "  ")
+            )
+          )
+        elif line.find("END_OBJECT =") > -1:
+          pass
+        elif len(line.rstrip().lstrip()) > 0:
+          key_val = line.split(" = ", 2)
+          if len(key_val) == 2:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list