[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1368] contrib/py/scripts/addons/ io_import_LRO_Lola_MGS_Mola_img.py: Added Img importer to contrib/py/ scripts/addons/
Valter Battioli
valter31 at interfree.it
Sat Jan 8 17:19:07 CET 2011
Revision: 1368
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1368
Author: valtervb
Date: 2011-01-08 16:19:06 +0000 (Sat, 08 Jan 2011)
Log Message:
-----------
Added Img importer to contrib/py/scripts/addons/
Added Paths:
-----------
contrib/py/scripts/addons/io_import_LRO_Lola_MGS_Mola_img.py
Added: contrib/py/scripts/addons/io_import_LRO_Lola_MGS_Mola_img.py
===================================================================
--- contrib/py/scripts/addons/io_import_LRO_Lola_MGS_Mola_img.py (rev 0)
+++ contrib/py/scripts/addons/io_import_LRO_Lola_MGS_Mola_img.py 2011-01-08 16:19:06 UTC (rev 1368)
@@ -0,0 +1,556 @@
+# ##### 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 #####
+
+bl_addon_info = {
+ "name": "LRO Lola & MGS Mola img Importer",
+ "author": "ValterVB",
+ "version": (1, 1, 3),
+ "blender": (2, 5, 6),
+ "api": 34043,
+ "location": "3D window > Tool Shelf",
+ "description": "Import DTM from LRO Lola and MGS Mola",
+ "warning": "May consume a lot of memory",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/NASA_IMG_Importer",
+ "tracker_url":"http://projects.blender.org/tracker/index.php?func=detail&aid=25462&group_id=153&atid=468",
+ "category": "Import-Export"}
+
+#***********************************************************************
+#ver. 0.0.1: -First version
+#ver. 0.0.2: -Add check on path and file
+# -Check on selected coordinates more complete
+#ver. 1.1.0: -Optimized for less memory
+#ver. 1.1.1: -Correct bug for real value of the High (bad error).
+# now it's less artistic, bat more real Always possible use
+# the old formula. check Magnify (x4)
+# -Correct the bug for directory with dot in the name
+# -Add some warning and more information
+# -Add slider for the scale and info on it
+#ver. 1.1.2: -Word correction
+# -Correct the problem for Unix (Upper lower case)
+# If the Ext of the file selected from user is upper
+# than the second file is Upper and Viceversa.
+# (I can't verify because i have Win)
+#ver. 1.1.3: -Little fix for previous fix on upper/lower case
+#************************************************************************
+
+import bpy
+import os.path
+import math, array, mathutils
+from mathutils import *
+
+TO_RAD=math.pi/180 #From degrees to radians
+
+# turning off relative path - it causes an error if it was true
+if bpy.context.user_preferences.filepaths.use_relative_paths == True:
+ bpy.context.user_preferences.filepaths.use_relative_paths = False
+
+# A very simple "bridge" tool.
+# Connects two equally long vertex rows with faces.
+# Returns a list of the new faces (list of lists)
+#
+# vertIdx1 ... First vertex list (list of vertex indices).
+# vertIdx2 ... Second vertex list (list of vertex indices).
+# closed ... Creates a loop (first & last are closed).
+# flipped ... Invert the normal of the face(s).
+#
+# Note: You can set vertIdx1 to a single vertex index to create a fan/star of faces.
+# Note: If both vertex idx list are the same length they have to have at least 2 vertices.
+def createFaces(vertIdx1, vertIdx2, closed=False, flipped=False):
+ faces = []
+
+ if not vertIdx1 or not vertIdx2:
+ return None
+
+ if len(vertIdx1) < 2 and len(vertIdx2) < 2:
+ return None
+
+ fan = False
+ if (len(vertIdx1) != len(vertIdx2)):
+ if (len(vertIdx1) == 1 and len(vertIdx2) > 1):
+ fan = True
+ else:
+ return None
+
+ total = len(vertIdx2)
+
+ if closed:
+ # Bridge the start with the end.
+ if flipped:
+ face = [
+ vertIdx1[0],
+ vertIdx2[0],
+ vertIdx2[total - 1]]
+ if not fan:
+ face.append(vertIdx1[total - 1])
+ faces.append(face)
+
+ else:
+ face = [vertIdx2[0], vertIdx1[0]]
+ if not fan:
+ face.append(vertIdx1[total - 1])
+ face.append(vertIdx2[total - 1])
+ faces.append(face)
+
+ # Bridge the rest of the faces.
+ for num in range(total - 1):
+ if flipped:
+ if fan:
+ face = [vertIdx2[num], vertIdx1[0], vertIdx2[num + 1]]
+ else:
+ face = [vertIdx2[num], vertIdx1[num],
+ vertIdx1[num + 1], vertIdx2[num + 1]]
+ faces.append(face)
+ else:
+ if fan:
+ face = [vertIdx1[0], vertIdx2[num], vertIdx2[num + 1]]
+ else:
+ face = [vertIdx1[num], vertIdx2[num],
+ vertIdx2[num + 1], vertIdx1[num + 1]]
+ faces.append(face)
+ return faces
+
+#Utility Function ********************************************************
+#
+#Input: Latitude Output: Number of the line (1 to n)
+def LatToLine(Latitude):
+ tmpLines=round((MAXIMUM_LATITUDE-Latitude)*MAP_RESOLUTION+1.0)
+ if tmpLines>LINES:tmpLines=LINES
+ return tmpLines
+
+#Input: Number of the line (1 to n) Output: Latitude
+def LineToLat(Line):
+ if MAP_RESOLUTION==0:
+ return 0
+ else:
+ return float(MAXIMUM_LATITUDE-(Line-1)/MAP_RESOLUTION)
+
+#Input: Longitude Output: Number of the point (1 to n)
+def LongToPoint(Longitude):
+ tmpPoints=round((Longitude-WESTERNMOST_LONGITUDE)*MAP_RESOLUTION+1.0)
+ if tmpPoints>LINE_SAMPLES:tmpPoints=LINE_SAMPLES
+ return tmpPoints
+
+#Input: Number of the Point (1 to n) Output: Longitude
+def PointToLong(Point):
+ if MAP_RESOLUTION==0:
+ return 0
+ else:
+ return float(WESTERNMOST_LONGITUDE+(Point-1)/MAP_RESOLUTION)
+
+#Input: Latitude Output: Neareast real Latitude on grid
+def RealLat(Latitude):
+ return float(LineToLat(LatToLine(Latitude)))
+
+#Input: Longitude Output: Neareast real Longitude on grid
+def RealLong(Longitude):
+ return float(PointToLong(LongToPoint(Longitude)))
+#**************************************************************************
+
+
+#Read the LBL file
+def ReadLabel(FileName):
+ global FileAndPath
+ global LINES, LINE_SAMPLES, SAMPLE_TYPE, SAMPLE_BITS, UNIT, MAP_RESOLUTION, MAXIMUM_LATITUDE, MINIMUM_LATITUDE
+ global WESTERNMOST_LONGITUDE, EASTERNMOST_LONGITUDE, SCALING_FACTOR,OFFSET, RadiusUM, TARGET_NAME
+ global Message
+
+ if FileName=='':
+ LINES=LINE_SAMPLES=SAMPLE_BITS=MAP_RESOLUTION=0
+ MAXIMUM_LATITUDE=MINIMUM_LATITUDE=WESTERNMOST_LONGITUDE=EASTERNMOST_LONGITUDE=OFFSET=SCALING_FACTOR=0.0
+ SAMPLE_TYPE=UNIT=TARGET_NAME=RadiusUM=Message=""
+ return
+
+ FileAndPath=FileName
+ FileAndExt=os.path.splitext(FileAndPath)
+ try:
+ #Check for UNIX that is case sensitive
+ #If the Ext of the file selected from user is Upper, than the second file is Upper and Viceversa
+ if FileAndExt[1].isupper():
+ f = open(FileAndExt[0] + ".LBL", 'r') #Open the label file
+ else:
+ f = open(FileAndExt[0] + ".lbl", 'r') #Open the label file
+ Message=""
+ except:
+ Message="FILE LBL NOT AVAILABLE OR YOU HAVEN'T SELECTED A FILE"
+ return
+
+ block=""
+ OFFSET=0
+ for line in f:
+ tmp=line.split("=")
+ if tmp[0].strip()=="OBJECT" and tmp[1].strip()=="IMAGE":
+ block="IMAGE"
+ elif tmp[0].strip()=="OBJECT" and tmp[1].strip()=="IMAGE_MAP_PROJECTION":
+ block="IMAGE_MAP_PROJECTION"
+ elif tmp[0].strip()=="END_OBJECT" and tmp[1].strip()=="IMAGE":
+ block=""
+ elif tmp[0].strip()=="END_OBJECT" and tmp[1].strip()=="IMAGE_MAP_PROJECTION":
+ block=""
+ elif tmp[0].strip()=="TARGET_NAME":
+ block=""
+ TARGET_NAME=tmp[1].strip()
+ if block=="IMAGE":
+ if line.find("LINES") !=-1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ LINES=int(tmp[1].strip())
+ elif line.find("LINE_SAMPLES") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ LINE_SAMPLES=int(tmp[1].strip())
+ elif line.find("UNIT") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ UNIT=tmp[1].strip()
+ elif line.find("SAMPLE_TYPE") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ SAMPLE_TYPE=tmp[1].strip()
+ elif line.find("SAMPLE_BITS") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ SAMPLE_BITS=int(tmp[1].strip())
+ elif line.find("SCALING_FACTOR") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ tmp=tmp[1].split("<")
+ SCALING_FACTOR=float(tmp[0].replace(" ", ""))
+ elif line.find("OFFSET") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ if tmp[0].find("OFFSET")!=-1 and len(tmp) > 1:
+ tmp=tmp[1].split("<")
+ tmp[0]=tmp[0].replace(".", "")
+ OFFSET=float(tmp[0].replace(" ", ""))
+ elif block=="IMAGE_MAP_PROJECTION":
+ if line.find("A_AXIS_RADIUS") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ tmp=tmp[1].split("<")
+ A_AXIS_RADIUS=float(tmp[0].replace(" ", ""))
+ RadiusUM=tmp[1].rstrip().replace(">","")
+ elif line.find("B_AXIS_RADIUS") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ tmp=tmp[1].split("<")
+ B_AXIS_RADIUS=float(tmp[0].replace(" ", ""))
+ elif line.find("C_AXIS_RADIUS") != -1 and not(line.startswith("/*")):
+ tmp=line.split("=")
+ tmp=tmp[1].split("<")
+ C_AXIS_RADIUS=float(tmp[0].replace(" ", ""))
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list