Macro Texture
File:FCTexture Macro FCTexture |
Description |
---|
Creates an image 3D from a BMP image. Author: Mario52 |
Author |
Mario52 |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
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 !
The macro Macro_FCCreaLoft for automate the multi loft
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
- 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 (Black) 255 or 19 if the setting is white (White)
- 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). (the procedure can be long)
- Nuance: If the shade option is checked the color of the point is represented as a picture
- Inversion X: reverse coordinates X image.
- Inversion Y: reverse coordinates Y image.
- Inversion Z: reverse coordinates Z image.
- Photo: the photo mode is automatically activated when a 32-bit image is detected. (the procedure can be long)
- Plan: the plan allows you to import a 32-bit image and ignore the background of the plan. By default the map background is black to ignore colors are adjustable with the Capping command. If White is checked, the bottom has ignore will be white. (the procedure can be long)
- File and lauch: opens the image file and launches the conversion.
- Quit: exits the function.
Script
Macro_FCTexture.FCMacro
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* 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.7 03/09/2014 PyQt4 and PySide 0.8 16/03/2016
###############################################original modifie bouton colore et remplacer App par FreeCAD
__title__ = "FCTexture"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "0.8"
__date__ = "16/03/2016"
try:
import PyQt4
from PyQt4 import QtGui ,QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
except Exception:
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base
import os, time, sys
import os.path
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 nuance ; nuance = 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 bits_pixel ; bits_pixel = 0
global tailleDonnees; tailleDonnees = 0
#global path ; path = FreeCAD.ConfigGet("AppHomePath")
global path ; 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
global path
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 nuance
global avecLigne
global inversion_X
global inversion_Y
global inversion_Z
global plan
global fond
global bits_pixel
global tailleDonnees
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(263, 536)
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.Box)
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"))
self.doubleSpinBox_01.setToolTip(u"Coordinate placement Axis X.")
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"))
self.doubleSpinBox_02.setToolTip(u"Coordinate placement Axis Y.")
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"))
self.doubleSpinBox_03.setToolTip(u"Coordinate placement Axis Z.")
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.Box)
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"))
self.doubleSpinBox_1.setToolTip(u"Stretching Axis X.")
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"))
self.doubleSpinBox_2.setToolTip(u"Stretching Axis Y.")
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"))
self.doubleSpinBox_3.setToolTip(u"Stretching Axis Z.")
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.Box)
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.setLayoutDirection(QtCore.Qt.LeftToRight)
self.checkBox_5.setAutoFillBackground(False)
self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
self.checkBox_5.setToolTip(u"Raw mode 256 colors or 19 colors")
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, 61, 20))
self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
self.checkBox_6.setToolTip(u"Capping color White or Black")
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(180, 30, 51, 22))
self.spinBox.setMinimum(0)
self.spinBox.setMaximum(19)
self.spinBox.setValue(19)
# self.spinBox.setProperty("value", 19)
self.spinBox.setObjectName(_fromUtf8("spinBox"))
self.spinBox.setToolTip(u"Capping [0 to 19 (black) 19 to 0 (white) normal mode] or [0 to 255 (black) 255 to 0 (white) Raw mode]")
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.Box)
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"))
self.radioButton_3.setToolTip(u"Make a Wire")
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.setToolTip(u"Make a BSpline")
self.radioButton_4.clicked.connect(self.on_radioButton_4_clicked) #connection radioButton_4 type BSpline
self.checkBox_4 = QtGui.QCheckBox(self.frame_4)
self.checkBox_4.setGeometry(QtCore.QRect(140, 30, 81, 20))
self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
self.checkBox_4.setEnabled(False)
self.checkBox_4.setToolTip(u"To display items in mode photo with shade of gray 19 or 256 shades of gray if Raw mode is set 255")
self.checkBox_4.clicked.connect(self.on_checkBox_4_clicked) #connection checkBox_4 nuance
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.setToolTip(u"Make a Point (the procedure can be long)")
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.Box)
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"))
self.checkBox_1.setToolTip(u"Inversion coordinate X")
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"))
self.checkBox_2.setToolTip(u"Inversion coordinate Y")
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"))
self.checkBox_3.setToolTip(u"Inversion coordinate Z")
self.checkBox_3.clicked.connect(self.on_checkBox_3_clicked) #connection checkBox_3 Z
# section progressBar 1
self.PBA_progressBar = QtGui.QProgressBar(self.centralWidget) #
self.PBA_progressBar.setGeometry(QtCore.QRect(10, 480, 241, 12))
self.PBA_progressBar.setValue(0)
self.PBA_progressBar.setVisible(True)
self.PBA_progressBar.setOrientation(QtCore.Qt.Horizontal)
self.PBA_progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.PBA_progressBar.setObjectName(_fromUtf8("PBA_progressBar"))
# self.PBA_progressBar.setToolTip(_translate("MainWindow", " ", None))
self.pushButton = QtGui.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(10, 500, 113, 28))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton.setToolTip(u"Load the file and launch the process")
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, 500, 113, 28))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.pushButton_2.setToolTip(u"Quit FCTexture")
self.pushButton_2.clicked.connect(self.on_pushButton_Quit_clicked) # quit
self.label_9 = QtGui.QLabel(self.centralWidget)
self.label_9.setGeometry(QtCore.QRect(10, 460, 241, 16))
self.label_9.setObjectName(_fromUtf8("label_9"))
self.frame_7 = QtGui.QFrame(self.centralWidget)
self.frame_7.setGeometry(QtCore.QRect(140, 370, 111, 80))
self.frame_7.setFrameShape(QtGui.QFrame.Box)
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"))
self.radioButton_5.setToolTip(u"The photo mode is automatically activated when a 32-bit image is detected. (the procedure can be long)")
self.radioButton_5.clicked.connect(self.on_radioButton_5_clicked) #connection radioButton_5 Photo
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.setToolTip(u"The plan mode is possible when a 32-bit image and ignore the background of the plan. (the procedure can be long)")
self.radioButton_6.clicked.connect(self.on_radioButton_6_clicked) #connection radioButton_6 Plan
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle("FCTexture")
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant
self.label.setText("Coordinate X")
self.label_2.setText("Coordinate Y")
self.label_3.setText("Coordinate Z")
self.label_6.setText("Stretching Z")
self.label_4.setText("Stretching X")
self.label_5.setText("Stretching Y")
self.label_7.setText("Capping")
self.radioButton_2.setText("Point")
self.radioButton_4.setText("BSpline")
self.radioButton_3.setText("Wire")
self.checkBox_1.setText("Inversion X")
self.checkBox_2.setText("Inversion Y")
self.checkBox_3.setText("Inversion Z")
self.radioButton_5.setText("Photo")
self.radioButton_6.setText("Plan")
self.checkBox_4.setText("Nuance")
self.checkBox_5.setText("19")
self.checkBox_6.setText("White")
self.label_8.setText("Raw mode")
self.pushButton.setText("File and launch")
self.pushButton_2.setText("Quit")
self.label_9.setText("File :")
self.label_9.setToolTip(u"Gives informations about the file (Bits_pixel, Size data, Length, Height)")
def on_doubleSpinBox_01_valueChanged(self,value): # connection doubleSpinBox_01 Coordinate X
global position_X
position_X = value
def on_doubleSpinBox_02_valueChanged(self,value): # connection doubleSpinBox_02 Coordinate Y
global position_Y
position_Y = value
def on_doubleSpinBox_03_valueChanged(self,value): # connection doubleSpinBox_03 Coordinate Z
global position_Z
position_Z = value
def on_doubleSpinBox_1_valueChanged(self,value): # connection doubleSpinBox_1 Stretching X
global etirement_X
etirement_X = value
def on_doubleSpinBox_2_valueChanged(self,value): # connection doubleSpinBox_2 Stretching Y
global etirement_Y
etirement_Y = value
def on_doubleSpinBox_3_valueChanged(self,value): # connection doubleSpinBox_3 Stretching Z
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.checkBox_5.setText("255")
if self.checkBox_6.isChecked(): # if Black
self.spinBox.setValue(0)
ecreter = 0
else:
self.spinBox.setValue(255)
ecreter = 255
else:
modeBrut = 0 # if nochecked White mode brut = 19 colors
self.spinBox.setMaximum(19)
self.checkBox_5.setText("19")
if self.checkBox_6.isChecked(): # if Black
self.spinBox.setValue(0)
ecreter = 0
else:
self.spinBox.setValue(19) # if White
ecreter = 19
def on_checkBox_6_clicked(self): # if checked ecreter Black else White
global modeColor
global ecreter
if self.checkBox_6.isChecked():
modeColor = 1 # if checked mode Black
self.checkBox_6.setText("Black")
self.spinBox.setValue(0)
self.spinBox.setObjectName(_fromUtf8("spinBox"))
else:
modeColor = 0 # if nochecked mode White
self.checkBox_6.setText("White")
if self.checkBox_5.isChecked():
self.spinBox.setValue(255)
else:
self.spinBox.setValue(19)
def on_spinBox_valueChanged(self,value): # ecreter
global ecreter
ecreter = value
def on_radioButton_3_clicked(self): # if checked then 0=makeWire N/B
global typeligne
global avecLigne
typeligne = 0
avecLigne = 1
self.checkBox_4.setChecked(False)
self.checkBox_4.setEnabled(False)
def on_radioButton_4_clicked(self): # if no checked then 1=BSpline N/B
global typeligne
global avecLigne
typeligne = 1
avecLigne = 1
self.checkBox_4.setChecked(False)
self.checkBox_4.setEnabled(False)
def on_radioButton_2_clicked(self): # if checked then mode point N/B
global avecLigne
avecLigne = 0
self.checkBox_4.setEnabled(True)
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 Photo colors
global plan
plan = 0
def on_radioButton_6_clicked(self): # if checked then Plan colors
global plan
global modeBrut
global ecreter
plan = 1
modeBrut = 1 # if checked mode brut = 255 colors
ecreter = 255
self.spinBox.setObjectName(_fromUtf8("spinBox"))
self.spinBox.setMaximum(255)
self.spinBox.setValue(255)
self.checkBox_6.setText("White")
self.checkBox_5.setText("255")
self.checkBox_5.setChecked(True)
FreeCAD.Console.PrintMessage("checkBox_5 ecreter : "+str(ecreter)+"\n") # ici
def on_checkBox_4_clicked(self): # if checked fond Black else White
global nuance
if self.checkBox_4.isChecked():
nuance = 1 # if checked Nuance ok
else:
nuance = 0 # if nochecked Nuance Ko
def on_pushButton_Quit_clicked(self):
FreeCAD.Console.PrintMessage("Terminé"+"\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
global bits_pixel
global tailleDonnees
# Configuration FCTexture
# FreeCAD.Console.PrintMessage("position_X : "+str(position_X)+"\n")
# FreeCAD.Console.PrintMessage("position_Y : "+str(position_Y)+"\n")
# FreeCAD.Console.PrintMessage("position_Z : "+str(position_Z)+"\n")
# FreeCAD.Console.PrintMessage("etirement_X : "+str(etirement_X)+"\n")
# FreeCAD.Console.PrintMessage("etirement_Y : "+str(etirement_Y)+"\n")
# FreeCAD.Console.PrintMessage("etirement_Z : "+str(etirement_Z)+"\n")
# FreeCAD.Console.PrintMessage("ecreter : "+str(ecreter)+"\n")
# FreeCAD.Console.PrintMessage("wire : "+str(avecLigne)+"\n")
# FreeCAD.Console.PrintMessage("typeligne : "+str(typeligne)+"\n")
# FreeCAD.Console.PrintMessage("point : "+str(avecLigne)+"\n")
# FreeCAD.Console.PrintMessage("inversion_X : "+str(inversion_X)+"\n")
# FreeCAD.Console.PrintMessage("inversion_Y : "+str(inversion_Y)+"\n")
# FreeCAD.Console.PrintMessage("inversion_Z : "+str(inversion_Z)+"\n")
# FreeCAD.Console.PrintMessage("plan : "+str(plan)+"\n")
# FreeCAD.Console.PrintMessage("fond : "+str(fond)+"\n")
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
self.pushButton.setStyleSheet("background-color: QPalette.Base") # origin system
self.label_9.setText("File :")
OpenName = ""
try:
OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Read an image file"),path,"*.Bmp") # PyQt4
except Exception:
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read an image file", path, "*.Bmp")#PySide
try:
if OpenName != "":
depart = time.clock()
FreeCAD.Console.PrintMessage("Read the file "+OpenName+"\n")
f = open(OpenName, "rb")
length = os.path.getsize(OpenName)
# decode header file
bytes = f.read(2)# Signature du fichier. BM=Bitmap windows, BA= Bitmap
# FreeCAD.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])
# FreeCAD.Console.PrintMessage(str(adresse)+" adresse "+"\n")
bytes = f.read(4)# Taille en octets de l'en-tête BITMAPINFOHEADER
entete = decobit(bytes[0],bytes[1],bytes[2],bytes[3])
# FreeCAD.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])
# FreeCAD.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])
# FreeCAD.Console.PrintMessage(str(hauteur)+" hauteur "+"\n")
bytes = f.read(2)# Nombre de plans
plans = decobit(bytes[0],bytes[1])
# FreeCAD.Console.PrintMessage(str(plans)+" plans "+"\n")
bytes = f.read(2)# Nombre de bits par pixel
bits_pixel = decobit(bytes[0],bytes[1])
FreeCAD.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])
# FreeCAD.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])
# FreeCAD.Console.PrintMessage(str(couleurs)+" couleurs "+"\n")
bytes = f.read(4)# Nombre de couleurs importantes. 0= toutes importantes
self.label_9.setText("File: "+str(bits_pixel)+":bits " +str(tailleDonnees)+":data ("+str(Largeur)+" x "+str(hauteur)+")")
Gui.updateGui() # rafraichi l'ecran
f.seek(adresse, 0) # seek(position, 0=defaut 1=à la position courante 2=à partir de la fin du fichier)
coor_X = 0.0
coor_Y = 0.0
coor_Z = 0.0
###########256 couleurs début#####################################
if couleurs == 256:
completion = Largeur % 4
ii = 0
pnts = []
points = []
del pnts[:]
del points[:]
self.PBA_progressBar.setMaximum(tailleDonnees)
for Y in range(tailleDonnees):
self.PBA_progressBar.setValue(Y)
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 = (f.read(1))
Y += 1
elif completion == 2:
bytes = (f.read(2))
Y += 2
elif completion == 1:
bytes = (f.read(3))
Y += 3
ii = 0
except:
None
f.close()
ii = 0
self.PBA_progressBar.setMaximum(hauteur)
for Y in range(hauteur):
self.PBA_progressBar.setValue(Y)
for X in range(Largeur):
if X > Largeur:
del points[:]
else:
if modeBrut == 0:
if float(pnts[ii]) > 225: # 19 Filter
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)
try:
if avecLigne == 1: # 0=point 1=Ligne
points += [FreeCAD.Vector(coor_X,coor_Y,coor_Z)]
else:
if nuance == 1: # 1 = nuance
a = Draft.makePoint(coor_X,coor_Y,coor_Z)
FreeCADGui.activeDocument().getObject(a.Label).PointColor = (coor_Z*0.00392157,coor_Z*0.00392157,coor_Z*0.00392157)
else:
Draft.makePoint(coor_X,coor_Y,coor_Z)
except:
FreeCAD.Console.PrintError("Not ActiveDocument detected "+"\n") #errorDialog("Not ActiveDocument detected")
break
ii += 1
try:
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
except:
FreeCAD.Console.PrintError("Not ActiveDocument detected "+"\n") #errorDialog("Not ActiveDocument detected")
break
del points[:]
##256 couleurs fin#####################################
#
###########16 millions couleurs debut###########################
elif bits_pixel == 32: #if couleurs == 0: # 16 millions couleurs pour 32 bits mode 1 bit
if adresse == 138: # mode 2 bits
bytes = (f.read(1))
completion = Largeur % 4
ii = 0
ic = 0
r_color = 0.0
v_color = 0.0
b_color = 0.0
pnts = []
points = []
del pnts[:]
del points[:]
self.PBA_progressBar.setMaximum(tailleDonnees)
for Y in range(tailleDonnees):
self.PBA_progressBar.setValue(Y)
ii = 0
for ic in range(3):
ii += 1
try:
bytes = ord(f.read(1))
pnts.append(str(bytes))
except:
None
f.read(1)
ii += 1
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
self.PBA_progressBar.setMaximum(hauteur)
for Y in range(hauteur):
self.PBA_progressBar.setValue(Y)
for X in range(Largeur):
if X > Largeur:
del points[:]
else:
coor_X = (X * etirement_X) + position_X
coor_Y = (Y * etirement_Y) + position_Y
coor_Z = ( 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)
b_color = float(pnts[ii])*0.00392157
ii += 1
v_color = float(pnts[ii])*0.00392157
ii += 1
r_color = float(pnts[ii])*0.00392157
ii += 1
try:
if plan == 0: # 0=Photo
a = Draft.makePoint(coor_X,coor_Y,coor_Z) # ok pour 32 bits mode
FreeCADGui.activeDocument().getObject(a.Label).PointColor = (r_color,v_color,b_color)
else: # 1=Plan
if modeColor == 0: # white background
if (r_color < (ecreter*0.00392157)) and (r_color < (ecreter*0.00392157)) and (r_color < (ecreter*0.00392157)): # ecreter White
a = Draft.makePoint(coor_X,coor_Y,coor_Z)
FreeCADGui.activeDocument().getObject(a.Label).PointColor = (r_color,v_color,b_color)
else: # black background
if (r_color > (ecreter*0.00392157)) and (r_color > (ecreter*0.00392157)) and (r_color > (ecreter*0.00392157)): # ecreter Black
a = Draft.makePoint(coor_X,coor_Y,coor_Z)
FreeCADGui.activeDocument().getObject(a.Label).PointColor = (r_color,v_color,b_color)
except:
FreeCAD.Console.PrintError("Not ActiveDocument detected "+"\n")
break
del points[:]
###########16 millions couleurs fin#####################################
else:
FreeCAD.Console.PrintError("Bits_pixel "+str(bits_pixel)+" unrecognized format"+"\n")
arrivee = time.clock()
self.pushButton.setStyleSheet("background-color: green") # This function gives a color button
FreeCAD.Console.PrintMessage("Time : "+str("%.2f" % ((arrivee - depart)/60))+" min"+"\n")
FreeCAD.Console.PrintMessage("_End FCTexture_____________"+"\n")
except:
self.pushButton.setStyleSheet("background-color: red") # This function gives a color button
FreeCAD.Console.PrintMessage("Error in reading the file "+OpenName+"\n")
errorDialog(u"Error in reading the file "+OpenName)
self.PBA_progressBar.setValue(0)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow(MainWindow)
MainWindow.show()
Example
The images were inclined to enhance the 3D effect.
-
Honda
-
Here an example of a bmp image converted to points and restoring picture the width of the image is 6.5 nm
thanks for the permission of Yorik -
Here an example of a bmp image converted to object 3D of 6.7 nm width.
thanks for the permission of Yorik
-
The logo of FreeCAD.
-
A portion of the screen FreeCAD. The file.
-
A portion of a tablecloth.
-
A diamond plate.
-
Mode Plan: the image on the left the white background has been ignored in the right image the colour black has been ignored (an example on the forum)
-
Topography from a drawing or each level is represented with a degrees of different color.
-
Image converted in ASCII caracter.
-
Procedure for create solid:
1: Create loft with the tools or with the Macro_FCCreaLoft
2: Select all and extrude with the tools
3A: For Linux Download GMSHMesh (author psicofil) Macro_GMSH Wiki page
3B: For Windows Download GmshMesh2.zip unzip the file and install it in your Mod directory (author ulrich1a)
4: Create your Mesh file and use it
-
Convert solid in mesh with GmshMesh.
Links
The discussion on the forum to give your impressions or contact me.
The macro Macro_FCCreaLoft for automate the multi loft
How to handle pdf import properly and feasibly?
Revision
- ver 0.8 : 16/03/2016 adding progressBar
- ver 0.7 : 03/09/2014 Delete "translate" forgotten and bug fix discovered by the passage of PyQt to Pyside !
- ver 0.6 : 26/08/2014 Delete all "_translate"
- ver 0.5 : 25/08/2014 Delete "_translate (" MainWindow "," Stretching X ", None)" that prevented the display of tooltip with PySide (Windows Vista)
- ver 0.4 : 08/08/2014 PyQt4 PySide
- ver 0.3 : 28/03/2014 :comment out the line "# self.checkBox_5.setAccessibleName(_fromUtf8(""))"
that causes an error with the version FreeCAD : Version: 0.14.3343 (Git), Python version: 2.7.6, Qt version: 4.8.5