Macro Texture

From FreeCAD Documentation
Revision as of 23:00, 24 February 2014 by FuzzyBot (talk | contribs) (Importing a new version from external source)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

File:Text-x-python Macro_FCTexture

Description
Creates an image 3D from a BMP image.

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

This small macro allows you to build a project 3D very easily from a bitmap image 256 levels of gray.

I hope that this macro will revolutionize the way of thinking the CAD and CNC any image when what can be converted to object 3D without any intervention.

Everything becomes possible regardless of the complexity of the image !


Texture 004 Honda

Use

This macro need an image in 256 gray levels (0-255) therefore before using the macro, convert your image into grayscale (black and white) Lowe. The number of colors is detected automatically, if the image is more than 256 colors another function is expected (to come). Each color (gray level) is regarded as a deep, white (255) the level high and black (0) the lowest level (deep).

Configuration is done before the opening of the file, default values are the settings provided to get a project's dimensions:

  • width of the image in points in the coordinate X,
  • height of the image in points in the coordinate Y,
  • depth or thickness of the project leaked 10 mm (in raw mode, on 256 mm) in the coordinate Z.

The image file unfolds like a scanner x1 x2 x3 ... in 1 mm increments in FreeCAD similarly to the value y of 1 mm at a time. The value of z is given by the value of the color. These values are configurable in the macro.

Attention: depending on the size of the image, the project can become very big! for the record an image of 100 px wide and 100 px in height gives 100 x 100 = 10000 points 'and as each point corresponds to a coordinate, so 10000 coordinates XYZ there.

The interface

Texture 002
Texture 002
  • Coordinate X: X coordinate of position of the object, default: 0.
  • Coordinate Y: Y coordinate of position of the object, default: 0.
  • Coordinate Z: coordinate Z position of the object, default: 0.
  • Stetching X: narrowing or enlargement of the length of the object, default: 0.
  • Stetching Y: narrowing or enlargement of the height of the object, default: 0.
  • Stetching Z: narrowing or enlargement of the depth of the object, default: 0.
  • Raw mode: to adjust the number of colors (depth). The default mode is 0-19 (which constitutes a filter and to obtain more details according to the complexity of the image) once the checked the mode is 0 to 255 (the entire range of colors).
  • Capping: the capping function can be made on the choice of colours, white (default) or black. The degrees of capping rule 19 to 0 (or 255 to 0) if the checkbox is set on W (unchecked) or 0 to 19 (or 0 to 255) if the checkbox is set on B (checked).

The beginning of the operation value automatically adapts to the selected function: 0 if the setting is on black (B lack) 255 or 19 if the setting is white (W hite)

  • Wire: build your line (vector) in the form of Wire.
  • Bspline: build your line (vector) in the form of Bspline.
  • Point: creates a point at each pixel (vector).
  • Inversion X: reverse coordinates X image.
  • Inversion Y: reverse coordinates Y image.
  • Inversion Z: reverse coordinates Z image.
  • Draft: not yet used.
  • Plan: not yet used.
  • Backgr. : not yet used.
  • File and lauch: opens the image file and launches the conversion.
  • Quit: exits the function.

Script

FCTexture.FCMacro

# -*- coding: utf-8 -*-
"""
***************************************************************************
*   Copyright (c) 2014 <mario52>                                          *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU  General Public License (GPL)           *
*   as published by the Free Software Foundation; either version 3 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software 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 Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
# pour faire une texture de votre image, l'image doit être en 256 niveaux de gris (N/B)
# une image de 16 millons de couleurs fait l'objet d'une autre procédure d'affichage
# http://forum.freecadweb.org/viewtopic.php?f=24&t=5893&sid=c5f8d32c22e1d1a883741b70b1fea2dc
# ver 0.1 24/02/2014

__title__= "FCTexture"
__author__ = "mario52"

import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD, PyQt4
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base

import os, time
import os.path
import time

from PyQt4 import QtGui ,QtCore

from PyQt4.QtGui import *
from PyQt4.QtCore import *

def errorDialog(msg):
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
    diag.setWindowModality(QtCore.Qt.ApplicationModal)
    diag.exec_()

def decobit(b0 = 0, b1 = 0, b2 = 0, b3 = 0):
    b0 = int(ord(b0))
    b1 = int(ord(b1))
    if b2 == 0:
        return b0 + (b1*256)
    else:
        b2 = int(ord(b2))
        b3 = int(ord(b3))
        return b0 + (b1*256) + (b2*65536) + (b3*16777216)

global position_X   ; position_X  = 0.0
global position_Y   ; position_Y  = 0.0
global position_Z   ; position_Z  = 0.0
global etirement_X  ; etirement_X = 1.0
global etirement_Y  ; etirement_Y = 1.0
global etirement_Z  ; etirement_Z = 1.0
global modeBrut     ; modeBrut    = 0
global modeColor    ; modeColor   = 0
global ecreter      ; ecreter     = 19
global avecLigne    ; avecLigne   = 1
global typeligne    ; typeligne   = 0
global inversion_X  ; inversion_X = 0
global inversion_Y  ; inversion_Y = 0
global inversion_Z  ; inversion_Z = 0
global plan         ; plan        = 0
global fond         ; fond        = 0
global path         ; path = FreeCAD.ConfigGet("AppHomePath")
#                     path = FreeCAD.ConfigGet("UserAppData")

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):

    def __init__(self, MainWindow):
        self.window = MainWindow
        path = FreeCAD.ConfigGet("AppHomePath")
        global position_X
        global position_Y
        global position_Z
        global etirement_X
        global etirement_Y
        global etirement_Z
        global modeBrut
        global modeColor
        global ecreter
        global typeligne
        global avecLigne
        global inversion_X
        global inversion_Y
        global inversion_Z
        global plan
        global fond

        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(263, 500)
        self.centralWidget = QtGui.QWidget(MainWindow)
        self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
        self.frame = QtGui.QFrame(self.centralWidget)
        self.frame.setGeometry(QtCore.QRect(10, 11, 241, 101))
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName(_fromUtf8("frame"))

        self.doubleSpinBox_01 = QtGui.QDoubleSpinBox(self.frame)
        self.doubleSpinBox_01.setGeometry(QtCore.QRect(120, 10, 111, 22))
        self.doubleSpinBox_01.setDecimals(7)
        self.doubleSpinBox_01.setMinimum(-9999999.0)
        self.doubleSpinBox_01.setMaximum(9999999.99)
        self.doubleSpinBox_01.setSingleStep(0.0000001)
        self.doubleSpinBox_01.setObjectName(_fromUtf8("doubleSpinBox_01"))
        position_X = 0
        self.doubleSpinBox_01.setToolTip(_translate("MainWindow",u"Coordinate placement X.", None))
        self.doubleSpinBox_01.valueChanged.connect(self.on_doubleSpinBox_01_valueChanged) #position_X connection doubleSpinBox_01

        self.doubleSpinBox_02 = QtGui.QDoubleSpinBox(self.frame)
        self.doubleSpinBox_02.setGeometry(QtCore.QRect(120, 40, 111, 22))
        self.doubleSpinBox_02.setDecimals(7)
        self.doubleSpinBox_02.setMinimum(-9999999.0)
        self.doubleSpinBox_02.setMaximum(9999999.99)
        self.doubleSpinBox_02.setSingleStep(0.0000001)
        self.doubleSpinBox_02.setObjectName(_fromUtf8("doubleSpinBox_02"))
        position_Y = 0
        self.doubleSpinBox_02.setToolTip(_translate("MainWindow",u"Coordinate placement Y.", None))
        self.doubleSpinBox_02.valueChanged.connect(self.on_doubleSpinBox_02_valueChanged) #position_Y connection doubleSpinBox_02

        self.doubleSpinBox_03 = QtGui.QDoubleSpinBox(self.frame)
        self.doubleSpinBox_03.setGeometry(QtCore.QRect(120, 70, 111, 22))
        self.doubleSpinBox_03.setDecimals(7)
        self.doubleSpinBox_03.setMinimum(-9999999.0)
        self.doubleSpinBox_03.setMaximum(9999999.99)
        self.doubleSpinBox_03.setSingleStep(0.0000001)
        self.doubleSpinBox_03.setObjectName(_fromUtf8("doubleSpinBox_03"))
        position_Z = 0
        self.doubleSpinBox_03.setToolTip(_translate("MainWindow",u"Coordinate placement Z.", None))
        self.doubleSpinBox_03.valueChanged.connect(self.on_doubleSpinBox_03_valueChanged) #position_Z connection doubleSpinBox_03

        self.label = QtGui.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(10, 10, 81, 16))
        self.label.setObjectName(_fromUtf8("label"))
        self.label_2 = QtGui.QLabel(self.frame)
        self.label_2.setGeometry(QtCore.QRect(12, 40, 81, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.label_3 = QtGui.QLabel(self.frame)
        self.label_3.setGeometry(QtCore.QRect(12, 70, 81, 20))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.frame_2 = QtGui.QFrame(self.centralWidget)
        self.frame_2.setGeometry(QtCore.QRect(10, 120, 241, 101))
        self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_2.setObjectName(_fromUtf8("frame_2"))

        self.doubleSpinBox_1 = QtGui.QDoubleSpinBox(self.frame_2)
        self.doubleSpinBox_1.setGeometry(QtCore.QRect(120, 10, 111, 22))
        self.doubleSpinBox_1.setDecimals(7)
        self.doubleSpinBox_1.setMinimum(-9999999.0)
        self.doubleSpinBox_1.setMaximum(9999999.99)
        self.doubleSpinBox_1.setSingleStep(0.0000001)
        self.doubleSpinBox_1.setObjectName(_fromUtf8("doubleSpinBox_1"))
        etirement_X = 1.0
        self.doubleSpinBox_1.setToolTip(_translate("MainWindow",u"Stretching X.", None))
        self.doubleSpinBox_1.valueChanged.connect(self.on_doubleSpinBox_1_valueChanged) #etirement_X connection doubleSpinBox_1

        self.doubleSpinBox_2 = QtGui.QDoubleSpinBox(self.frame_2)
        self.doubleSpinBox_2.setGeometry(QtCore.QRect(120, 40, 111, 22))
        self.doubleSpinBox_2.setDecimals(7)
        self.doubleSpinBox_2.setMinimum(-9999999.0)
        self.doubleSpinBox_2.setMaximum(9999999.99)
        self.doubleSpinBox_2.setSingleStep(0.0000001)
        self.doubleSpinBox_2.setObjectName(_fromUtf8("doubleSpinBox_2"))
        etirement_Y = 1.0
        self.doubleSpinBox_2.setToolTip(_translate("MainWindow",u"Stretching Y.", None))
        self.doubleSpinBox_2.valueChanged.connect(self.on_doubleSpinBox_2_valueChanged) #etirement_Y connection doubleSpinBox_2

        self.doubleSpinBox_3 = QtGui.QDoubleSpinBox(self.frame_2)
        self.doubleSpinBox_3.setGeometry(QtCore.QRect(120, 70, 111, 22))
        self.doubleSpinBox_3.setDecimals(7)
        self.doubleSpinBox_3.setMinimum(-9999999.0)
        self.doubleSpinBox_3.setMaximum(9999999.99)
        self.doubleSpinBox_3.setSingleStep(0.0000001)
        self.doubleSpinBox_3.setObjectName(_fromUtf8("doubleSpinBox_3"))
        etirement_Z = 1.0
        self.doubleSpinBox_3.setToolTip(_translate("MainWindow",u"Strtcing Z.", None))
        self.doubleSpinBox_3.valueChanged.connect(self.on_doubleSpinBox_3_valueChanged) #etirement_Z connection doubleSpinBox_3

        self.label_4 = QtGui.QLabel(self.frame_2)
        self.label_4.setGeometry(QtCore.QRect(10, 10, 101, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.frame_2)
        self.label_5.setGeometry(QtCore.QRect(10, 40, 101, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.label_6 = QtGui.QLabel(self.frame_2)
        self.label_6.setGeometry(QtCore.QRect(10, 70, 81, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.frame_3 = QtGui.QFrame(self.centralWidget)
        self.frame_3.setGeometry(QtCore.QRect(10, 230, 241, 61))
        self.frame_3.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_3.setObjectName(_fromUtf8("frame_3"))
        self.label_7 = QtGui.QLabel(self.frame_3)
        self.label_7.setGeometry(QtCore.QRect(10, 30, 101, 16))
        self.label_7.setObjectName(_fromUtf8("label_7"))

        self.checkBox_5 = QtGui.QCheckBox(self.frame_3)
        self.checkBox_5.setGeometry(QtCore.QRect(120, 10, 81, 20))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.checkBox_5.sizePolicy().hasHeightForWidth())
        self.checkBox_5.setSizePolicy(sizePolicy)
        self.checkBox_5.setBaseSize(QtCore.QSize(0, 0))
        self.checkBox_5.setAccessibleName(_fromUtf8(""))
        self.checkBox_5.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.checkBox_5.setAutoFillBackground(False)
        self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
        self.checkBox_5.setToolTip(_translate("MainWindow",u"Raw mode 256 colors or 19 colors", None))
        self.checkBox_5.clicked.connect(self.on_checkBox_5_clicked)        #connection checkBox_5 mode brut

        self.checkBox_6 = QtGui.QCheckBox(self.frame_3)
        self.checkBox_6.setGeometry(QtCore.QRect(120, 30, 81, 20))
        self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
        self.checkBox_6.setToolTip(_translate("MainWindow",u"Capping color White or Black", None))
        self.checkBox_6.clicked.connect(self.on_checkBox_6_clicked)        #connection checkBox_6 mode W or B

        self.label_8 = QtGui.QLabel(self.frame_3)
        self.label_8.setGeometry(QtCore.QRect(10, 10, 71, 16))
        self.label_8.setObjectName(_fromUtf8("label_8"))

        self.spinBox = QtGui.QSpinBox(self.frame_3)
        self.spinBox.setGeometry(QtCore.QRect(170, 30, 61, 22))
        self.spinBox.setMinimum(0)
        self.spinBox.setMaximum(19)
        self.spinBox.setProperty("value", 19)
        self.spinBox.setObjectName(_fromUtf8("spinBox"))
        ecreter      = 19
        self.spinBox.setToolTip(_translate("MainWindow",u"Capping 0 to 19 or 0 to 255", None))
        self.spinBox.valueChanged.connect(self.on_spinBox_valueChanged) # ecreter connection spinBox

        self.frame_4 = QtGui.QFrame(self.centralWidget)
        self.frame_4.setGeometry(QtCore.QRect(10, 300, 241, 61))
        self.frame_4.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_4.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_4.setObjectName(_fromUtf8("frame_4"))

        self.radioButton_3 = QtGui.QRadioButton(self.frame_4)
        self.radioButton_3.setGeometry(QtCore.QRect(10, 10, 95, 20))
        self.radioButton_3.setChecked(True)
        self.radioButton_3.setObjectName(_fromUtf8("radioButton_3"))
        avecLigne = 1   # 0=self.points   1=makeWire
        typeligne = 0   # 0=makeWire 1=BSpline
        self.radioButton_3.clicked.connect(self.on_radioButton_3_clicked) #connection radioButton_3 type makeWire

        self.radioButton_4 = QtGui.QRadioButton(self.frame_4)
        self.radioButton_4.setGeometry(QtCore.QRect(140, 10, 95, 20))
        self.radioButton_4.setObjectName(_fromUtf8("radioButton_4"))
        self.radioButton_4.clicked.connect(self.on_radioButton_4_clicked) #connection radioButton_4 type BSpline

        self.radioButton_2 = QtGui.QRadioButton(self.frame_4)
        self.radioButton_2.setGeometry(QtCore.QRect(10, 30, 95, 20))
        self.radioButton_2.setObjectName(_fromUtf8("radioButton_2"))
        self.radioButton_2.clicked.connect(self.on_radioButton_2_clicked) #connection radioButton_2 mode point

        self.frame_6 = QtGui.QFrame(self.centralWidget)
        self.frame_6.setGeometry(QtCore.QRect(10, 370, 111, 81))
        self.frame_6.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_6.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_6.setObjectName(_fromUtf8("frame_6"))

        self.checkBox_1 = QtGui.QCheckBox(self.frame_6)
        self.checkBox_1.setGeometry(QtCore.QRect(10, 10, 111, 20))
        self.checkBox_1.setObjectName(_fromUtf8("checkBox_1"))
        inversion_X  = 0
        self.checkBox_1.setToolTip(_translate("MainWindow",u"Inversion coordinate X", None))
        self.checkBox_1.clicked.connect(self.on_checkBox_1_clicked)        #connection checkBox_1 X

        self.checkBox_2 = QtGui.QCheckBox(self.frame_6)
        self.checkBox_2.setGeometry(QtCore.QRect(10, 30, 111, 20))
        self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
        inversion_Y  = 0
        self.checkBox_1.setToolTip(_translate("MainWindow",u"Inversion coordinate Y", None))
        self.checkBox_2.clicked.connect(self.on_checkBox_2_clicked)        #connection checkBox_2 Y

        self.checkBox_3 = QtGui.QCheckBox(self.frame_6)
        self.checkBox_3.setGeometry(QtCore.QRect(10, 50, 101, 20))
        self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
        inversion_Z  = 0
        self.checkBox_3.setToolTip(_translate("MainWindow",u"Inversion coordinate Z", None))
        self.checkBox_3.clicked.connect(self.on_checkBox_3_clicked)        #connection checkBox_3 Z

        self.pushButton = QtGui.QPushButton(self.centralWidget)
        self.pushButton.setGeometry(QtCore.QRect(10, 460, 111, 28))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton.clicked.connect(self.on_pushButton_En_clicked)     # load file

        self.pushButton_2 = QtGui.QPushButton(self.centralWidget)
        self.pushButton_2.setGeometry(QtCore.QRect(140, 460, 111, 28))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_2.clicked.connect(self.on_pushButton_Quit_clicked) # quit

        self.frame_7 = QtGui.QFrame(self.centralWidget)
        self.frame_7.setGeometry(QtCore.QRect(140, 370, 111, 80))
        self.frame_7.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_7.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_7.setObjectName(_fromUtf8("frame_7"))

        self.radioButton_5 = QtGui.QRadioButton(self.frame_7)
        self.radioButton_5.setGeometry(QtCore.QRect(10, 10, 95, 20))
        self.radioButton_5.setChecked(True)
        self.radioButton_5.setObjectName(_fromUtf8("radioButton_5"))
        plan = 0
        self.radioButton_5.clicked.connect(self.on_radioButton_5_clicked)  #connection radioButton_5 Draw

        self.radioButton_6 = QtGui.QRadioButton(self.frame_7)
        self.radioButton_6.setGeometry(QtCore.QRect(10, 30, 95, 20))
        self.radioButton_6.setObjectName(_fromUtf8("radioButton_6"))
        self.radioButton_6.clicked.connect(self.on_radioButton_6_clicked)  #connection radioButton_6 Plan

        self.checkBox_4 = QtGui.QCheckBox(self.frame_7)
        self.checkBox_4.setGeometry(QtCore.QRect(10, 50, 101, 20))
        self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
        fond = 0
        self.checkBox_4.clicked.connect(self.on_checkBox_4_clicked) #connection checkBox_4 Background

        MainWindow.setCentralWidget(self.centralWidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "FCTexture", None))
        MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint)  # cette fonction met la fenêtre en avant
        self.label.setText(_translate("MainWindow", "Coordinate  X", None))
        self.label_2.setText(_translate("MainWindow", "Coordinate  Y", None))
        self.label_3.setText(_translate("MainWindow", "Coordinate  Z", None))
        self.label_6.setText(_translate("MainWindow", "Stretching  Z", None))
        self.label_4.setText(_translate("MainWindow", "Stretching  X", None))
        self.label_5.setText(_translate("MainWindow", "Stretching  Y", None))
        self.label_7.setText(_translate("MainWindow", "Capping", None))
        self.radioButton_2.setText(_translate("MainWindow", "Point", None))
        self.radioButton_4.setText(_translate("MainWindow", "BSpline", None))
        self.radioButton_3.setText(_translate("MainWindow", "Wire", None))
        self.checkBox_1.setText(_translate("MainWindow", "Inversion X", None))
        self.checkBox_2.setText(_translate("MainWindow", "Inversion Y", None))
        self.checkBox_3.setText(_translate("MainWindow", "Inversion Z", None))
        self.radioButton_5.setText(_translate("MainWindow", "Draft", None))
        self.radioButton_6.setText(_translate("MainWindow", "Plan", None))
        self.checkBox_4.setText(_translate("MainWindow", "Backgr. (B)", None))
        self.checkBox_5.setText(_translate("MainWindow", "19", None))
        self.checkBox_6.setText(_translate("MainWindow", "W", None))
        self.label_8.setText(_translate("MainWindow", "Raw mode", None))
        self.pushButton.setText(_translate("MainWindow", "File and launch", None))
        self.pushButton_2.setText(_translate("MainWindow", "Quit", None))

    def on_doubleSpinBox_01_valueChanged(self,value): # connection doubleSpinBox_01
        global position_X
        position_X = value

    def on_doubleSpinBox_02_valueChanged(self,value): # connection doubleSpinBox_02
        global position_Y
        position_Y = value

    def on_doubleSpinBox_03_valueChanged(self,value): # connection doubleSpinBox_03
        global position_Z
        position_Z = value

    def on_doubleSpinBox_1_valueChanged(self,value):  # connection doubleSpinBox_1
        global etirement_X
        etirement_X = value

    def on_doubleSpinBox_2_valueChanged(self,value):  # connection doubleSpinBox_2
        global etirement_Y
        etirement_Y = value

    def on_doubleSpinBox_3_valueChanged(self,value):  # connection doubleSpinBox_3
        global etirement_Z
        etirement_Z = value

    def on_checkBox_5_clicked(self):                  # if checked mode brut
        global modeBrut
        global ecreter
        if self.checkBox_5.isChecked():
            modeBrut = 1                              # if checked mode brut = 255 colors
            self.spinBox.setMaximum(255)
            self.spinBox.setProperty("value", 255)
            self.spinBox.setObjectName(_fromUtf8("spinBox"))
            self.checkBox_5.setText(_translate("MainWindow", "255", None))
            ecreter  = 255
        else:
            modeBrut = 0                              # if nochecked White mode brut = 19 colors
            self.spinBox.setMaximum(19)
            self.spinBox.setProperty("value", 19)
            self.spinBox.setObjectName(_fromUtf8("spinBox"))
            self.checkBox_5.setText(_translate("MainWindow", "19", None))
            ecreter  = 19

    def on_checkBox_6_clicked(self):                  # if checked ecreter Black else White
        global modeColor
        if self.checkBox_6.isChecked():
            modeColor = 1                              # if checked mode Black
            self.checkBox_6.setText(_translate("MainWindow", "B", None))
            self.spinBox.setProperty("value", 0)
            self.spinBox.setObjectName(_fromUtf8("spinBox"))
        else:
            modeColor = 0                              # if nochecked mode White
            self.checkBox_6.setText(_translate("MainWindow", "W", None))
            if self.checkBox_5.isChecked():
                self.spinBox.setProperty("value", 255)
            else:
                self.spinBox.setProperty("value", 19)

    def on_spinBox_valueChanged(self,value):           # ecreter
        global ecreter
        ecreter = value

    def on_radioButton_3_clicked(self):                # if checked then 0=makeWire
        global typeligne
        global avecLigne
        typeligne = 0
        avecLigne = 1

    def on_radioButton_4_clicked(self):                # if no checked then 1=BSpline
        global typeligne
        global avecLigne
        typeligne = 1
        avecLigne = 1

    def on_radioButton_2_clicked(self):                # if checked then mode point
        global avecLigne
        avecLigne = 0

    def on_checkBox_1_clicked(self):                   # if checked inverse X
        global inversion_X
        if self.checkBox_1.isChecked():
            inversion_X  = 1
        else:
            inversion_X  = 0

    def on_checkBox_2_clicked(self):                   # if checked inverse X
        global inversion_Y
        if self.checkBox_2.isChecked():
            inversion_Y  = 1
        else:
            inversion_Y  = 0

    def on_checkBox_3_clicked(self):                   # if checked inverse X
        global inversion_Z
        if self.checkBox_3.isChecked():
            inversion_Z  = 1
        else:
            inversion_Z  = 0

    def on_radioButton_5_clicked(self):                # if checked then Draw
        global plan
        plan = 0

    def on_radioButton_6_clicked(self):                # if checked then  plan
        global plan
        plan = 1

    def on_checkBox_4_clicked(self):                   # if checked fond Black else White
        global fond
        if self.checkBox_4.isChecked():
            fond = 1                                   # if checked Black
            self.checkBox_4.setText(_translate("MainWindow", "Backgr. (W)", None))
        else:
            fond = 0                                   # if nochecked White
            self.checkBox_4.setText(_translate("MainWindow", "Backgr. (B)", None))

    def on_pushButton_Quit_clicked(self):
        App.Console.PrintMessage("Terminé\r\n")
        self.window.hide()

    def on_pushButton_En_clicked(self):
        global position_X
        global position_Y
        global position_Z
        global etirement_X
        global etirement_Y
        global etirement_Z
        global modeBrut
        global modeColor
        global ecreter
        global typeligne
        global avecLigne
        global inversion_X
        global inversion_Y
        global inversion_Z
        global plan
        global fond

#        App.Console.PrintMessage("position_X  : "+str(position_X)+"\n")
#        App.Console.PrintMessage("position_Y  : "+str(position_Y)+"\n")
#        App.Console.PrintMessage("position_Z  : "+str(position_Z)+"\n")
#        App.Console.PrintMessage("etirement_X : "+str(etirement_X)+"\n")
#        App.Console.PrintMessage("etirement_Y : "+str(etirement_Y)+"\n")
#        App.Console.PrintMessage("etirement_Z : "+str(etirement_Z)+"\n")
#        App.Console.PrintMessage("ecreter     : "+str(ecreter)+"\n")
#        App.Console.PrintMessage("wire        : "+str(avecLigne)+"\n")
#        App.Console.PrintMessage("typeligne   : "+str(typeligne)+"\n")
#        App.Console.PrintMessage("point       : "+str(avecLigne)+"\n")
#        App.Console.PrintMessage("inversion_X : "+str(inversion_X)+"\n")
#        App.Console.PrintMessage("inversion_Y : "+str(inversion_Y)+"\n")
#        App.Console.PrintMessage("inversion_Z : "+str(inversion_Z)+"\n")
#        App.Console.PrintMessage("plan        : "+str(plan)+"\n")
#        App.Console.PrintMessage("fond        : "+str(fond)+"\n")

        OpenName = ""
        OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Lire un fichier image"),path,"*.Bmp *.dat")
        try:
            if OpenName != "":
                App.Console.PrintMessage("Lecture du fichier "+OpenName+"\n")
                f = open(OpenName, "rb")
                length = os.path.getsize(OpenName)
                bytes = f.read(2)# Signature du fichier. BM=Bitmap windows, BA= Bitmap
#                App.Console.PrintMessage(str(bytes[0]) + str(bytes[1])+"\n")
                bytes = f.read(4)# Taille totale du fichier en octets
                bytes = f.read(4)# Champ réservé

                bytes = f.read(4)# Adresse de la zone de définition de l’image 
                adresse = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
#                App.Console.PrintMessage(str(adresse)+" adresse \n")

                bytes = f.read(4)# Taille en octets de cet en-tête BITMAPINFOHEADER
                entete = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
#                App.Console.PrintMessage(str(entete)+" entete \n")

                bytes = f.read(4)# Largeur de l’image en pixels
                Largeur = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
                App.Console.PrintMessage(str(Largeur)+" Largeur \n")

                bytes = f.read(4)# Hauteur de l’image en pixels
                hauteur = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
                App.Console.PrintMessage(str(hauteur)+" hauteur \n")

                bytes = f.read(2)# Nombre de plans
                plans = decobit(bytes[0],bytes[1])
#                App.Console.PrintMessage(str(plans)+" plans \n")
                bytes = f.read(2)# Nombre de bits par pixel
                bits_pixel = decobit(bytes[0],bytes[1])
#                App.Console.PrintMessage(str(bits_pixel)+" bits_pixel \n")
                bytes = f.read(4)# Type de compression : 0=pas de compression,1=compressé à 8 bits par pixel, 2=4bits par pixel.

                bytes = f.read(4)# Taille en octets des données de l’image
                tailleDonnees = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
                App.Console.PrintMessage(str(tailleDonnees)+" tailleDonnees \n")

                bytes = f.read(4)# Résolution horizontale en pixels par mètre
                bytes = f.read(4)# Résolution verticale en pixels par mètre

                bytes = f.read(4)# Nombre de couleurs dans l’image : 0=maximum possible. Si une palette est utilisée, ce nombre indique le nombre de couleurs de la palette
                couleurs = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
                App.Console.PrintMessage(str(couleurs)+" couleurs \n")

                bytes = f.read(4)# Nombre de couleurs importantes. 0= toutes importantes 

                App.Console.PrintMessage("_________________________\n")
                f.seek(adresse, 0) # seek(position, 0=defaut 1=à la position courante 2=à partir de la fin du fichier)

                self.coor_X       = 0.0
                self.coor_Y       = 0.0
                self.coor_Z       = 0.0
##########256 couleurs début#####################################
                if couleurs == 256:
                    completion = Largeur % 4
                    ii = 0
                    pnts = []
                    points = []
                    del pnts[:]
                    del points[:]

                    for Y in range(tailleDonnees):
                        ii += 1
                        try:
                            bytes = ord(f.read(1))
                            pnts.append(str(bytes))
                        except:
                            None
                        try:
                            if ((ii % Largeur) == 0) and (completion > 0):
                                if completion == 3:
                                    bytes = ord(f.read(1))
                                    Y += 1
                                elif completion == 2:
                                    bytes = ord(f.read(2))
                                    Y += 2
                                elif completion == 1:
                                    bytes = ord(f.read(3))
                                    Y += 3
                        except:
                            None

                    f.close()
                    ii = 0
                    for Y in range(hauteur):
                        for X in range(Largeur):
                            if X > Largeur:
                                del points[:]
                            else:
                                if modeBrut == 0:
                                    if  float(pnts[ii])  > 225:  # 19
                                        pnts[ii] = "10"
                                    elif float(pnts[ii]) > 212:  # 18
                                        pnts[ii] = "9.5"
                                    elif float(pnts[ii]) > 200:  # 17
                                        pnts[ii] = "9"
                                    elif float(pnts[ii]) > 187:  # 16
                                        pnts[ii] = "8.5"
                                    elif float(pnts[ii]) > 175:  # 15
                                        pnts[ii] = "8"
                                    elif float(pnts[ii]) > 162:  # 14
                                        pnts[ii] = "7.5"
                                    elif float(pnts[ii]) > 150:  # 13
                                        pnts[ii] = "7"
                                    elif float(pnts[ii]) > 137:  # 12
                                        pnts[ii] = "6.5"
                                    elif float(pnts[ii]) > 125:  # 11
                                        pnts[ii] = "6"
                                    elif float(pnts[ii]) > 112:  # 10
                                        pnts[ii] = "5.5"
                                    elif float(pnts[ii]) > 100:  # 9
                                        pnts[ii] = "5"
                                    elif float(pnts[ii]) > 87:   # 8
                                        pnts[ii] = "4.5"
                                    elif float(pnts[ii]) > 75:   # 7
                                        pnts[ii] = "4"
                                    elif float(pnts[ii]) > 62:   # 6
                                        pnts[ii] = "3.5"
                                    elif float(pnts[ii]) > 50:   # 5
                                        pnts[ii] = "3"
                                    elif float(pnts[ii]) > 37:   # 4
                                        pnts[ii] = "2.5"
                                    elif float(pnts[ii]) > 25:   # 3
                                        pnts[ii] = "2"
                                    elif float(pnts[ii]) > 12:   # 2
                                        pnts[ii] = "1.5"
                                    elif float(pnts[ii]) > 1:    # 1
                                        pnts[ii] = "1"
                                    else :
                                        pnts[ii] = "0"           # 0

                                if modeBrut == 0:                                 # ecreter 19 colors
                                    if modeColor == 0:
                                        if float(pnts[ii]) > ((ecreter + 1) / 2): # ecreter White
                                            pnts[ii] = str((ecreter + 1) / 2)
                                    else:
                                        if float(pnts[ii]) < ((ecreter + 1) / 2): # ecreter Black
                                            pnts[ii] = str((ecreter + 1) / 2)
                                else:                                             # ecreter 255 colors
                                    if modeColor == 0:
                                        if float(pnts[ii]) > ecreter:             # ecreter White
                                            pnts[ii] = str(ecreter)
                                    else:
                                        if float(pnts[ii]) < ecreter:             # ecreter Black
                                            pnts[ii] = str(ecreter)

                                coor_X = (X * etirement_X) + position_X
                                coor_Y = (Y * etirement_Y) + position_Y
                                coor_Z = (float(pnts[ii]) * etirement_Z) + position_Z

                                if inversion_X > 0:
                                    coor_X = (-coor_X)
                                if inversion_Y > 0:
                                    coor_Y = (-coor_Y)
                                if inversion_Z > 0:
                                    coor_Z = (-coor_Z)

                                if avecLigne == 1:                                   # 0=point 1=Ligne
                                    points += [FreeCAD.Vector(coor_X,coor_Y,coor_Z)]
                                else:
                                    Draft.makePoint(coor_X,coor_Y,coor_Z)
                                ii += 1
                        if avecLigne == 1:
                            if typeligne == 0:                                       # 0=makeWire
                                Draft.makeWire(points,closed=False,face=False,support=None)
                            else:
                                Draft.makeBSpline(points,closed=False)               # 0=makeBSpline 
                        del points[:]
##########256 couleurs fin#####################################
                else:
                    App.Console.PrintMessage("16 millions colors")

                App.Console.PrintMessage("_________________________\n")

        except:
            App.Console.PrintMessage("Erreur en lecture du fichier "+OpenName+"\n")
            errorDialog(u"Erreur en lecture du fichier "+OpenName)

MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow(MainWindow)
MainWindow.show()

Example

The images were inclined to enhance the 3D effect.




Links

The discussion on the forum to give your impressions or contact me.