Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
d80a3d65
Commit
d80a3d65
authored
Mar 15, 2015
by
Mario Luzeiro
Committed by
jean-pierre charras
Mar 15, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3d-viewer: fixes and enhancements.
parent
5c263819
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
582 additions
and
180 deletions
+582
-180
3d_canvas.h
3d-viewer/3d_canvas.h
+2
-2
3d_draw.cpp
3d-viewer/3d_draw.cpp
+72
-165
3d_draw_basic_functions.cpp
3d-viewer/3d_draw_basic_functions.cpp
+4
-4
3d_draw_helper_functions.cpp
3d-viewer/3d_draw_helper_functions.cpp
+2
-2
3d_material.cpp
3d-viewer/3d_material.cpp
+0
-2
3d_mesh_model.cpp
3d-viewer/3d_mesh_model.cpp
+10
-0
CImage.cpp
3d-viewer/CImage.cpp
+395
-0
CImage.h
3d-viewer/CImage.h
+94
-0
CMakeLists.txt
3d-viewer/CMakeLists.txt
+1
-0
info3d_visu.h
3d-viewer/info3d_visu.h
+2
-5
No files found.
3d-viewer/3d_canvas.h
View file @
d80a3d65
...
...
@@ -196,13 +196,13 @@ private:
* Helper function SetGLEpoxyColor
* Initialize the color to draw the epoxy body board in realistic mode.
*/
void
setGLEpoxyColor
(
double
aTransparency
=
1
.
0
);
void
setGLEpoxyColor
(
float
aTransparency
=
1
.
0
);
/**
* Helper function SetGLSolderMaskColor
* Initialize the color to draw the solder mask layers in realistic mode.
*/
void
setGLSolderMaskColor
(
double
aTransparency
=
1
.
0
);
void
setGLSolderMaskColor
(
float
aTransparency
=
1
.
0
);
/**
* Function BuildBoard3DView
...
...
3d-viewer/3d_draw.cpp
View file @
d80a3d65
This diff is collapsed.
Click to expand it.
3d-viewer/3d_draw_basic_functions.cpp
View file @
d80a3d65
...
...
@@ -129,10 +129,10 @@ void SetGLColor( EDA_COLOR_T color, double alpha )
{
const
StructColors
&
colordata
=
g_ColorRefs
[
ColorGetBase
(
color
)];
double
red
=
colordata
.
m_Red
/
255.0
;
double
blue
=
colordata
.
m_Blue
/
255.0
;
double
green
=
colordata
.
m_Green
/
255.0
;
glColor4f
(
red
,
green
,
blue
,
alpha
);
float
red
=
colordata
.
m_Red
/
255.0
;
float
blue
=
colordata
.
m_Blue
/
255.0
;
float
green
=
colordata
.
m_Green
/
255.0
;
glColor4f
(
red
,
green
,
blue
,
(
float
)
alpha
);
}
...
...
3d-viewer/3d_draw_helper_functions.cpp
View file @
d80a3d65
...
...
@@ -113,7 +113,7 @@ void EDA_3D_CANVAS::setGLCopperColor()
// Helper function: initialize the color to draw the epoxy
// body board in realistic mode.
void
EDA_3D_CANVAS
::
setGLEpoxyColor
(
double
aTransparency
)
void
EDA_3D_CANVAS
::
setGLEpoxyColor
(
float
aTransparency
)
{
// Generates an epoxy color, near board color
SetGLColor
(
GetPrm3DVisu
().
m_BoardBodyColor
,
aTransparency
);
...
...
@@ -126,7 +126,7 @@ void EDA_3D_CANVAS::setGLEpoxyColor( double aTransparency )
// Helper function: initialize the color to draw the
// solder mask layers in realistic mode.
void
EDA_3D_CANVAS
::
setGLSolderMaskColor
(
double
aTransparency
)
void
EDA_3D_CANVAS
::
setGLSolderMaskColor
(
float
aTransparency
)
{
// Generates a solder mask color
SetGLColor
(
GetPrm3DVisu
().
m_SolderMaskColor
,
aTransparency
);
...
...
3d-viewer/3d_material.cpp
View file @
d80a3d65
...
...
@@ -73,8 +73,6 @@ void SetOpenGlDefaultMaterial()
bool
S3D_MATERIAL
::
SetOpenGLMaterial
(
unsigned
int
aMaterialIndex
,
bool
aUseMaterial
)
{
S3D_MASTER
*
s3dParent
=
(
S3D_MASTER
*
)
GetParent
();
if
(
aUseMaterial
)
{
float
transparency_value
=
0.0
f
;
...
...
3d-viewer/3d_mesh_model.cpp
View file @
d80a3d65
...
...
@@ -113,6 +113,11 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects,
if
(
!
isTransparent
&&
aIsRenderingJustTransparentObjects
)
return
;
if
(
useMaterial
)
if
(
m_Materials
->
m_Transparency
.
size
()
>
0
)
if
(
m_Materials
->
m_Transparency
[
0
]
>=
1.0
f
)
return
;
}
glPushMatrix
();
...
...
@@ -146,6 +151,11 @@ void S3D_MESH::openGL_Render( bool aIsRenderingJustNonTransparentObjects,
if
(
!
isTransparent
&&
aIsRenderingJustTransparentObjects
)
continue
;
if
(
useMaterial
)
if
(
m_Materials
->
m_Transparency
.
size
()
>
idx
)
if
(
m_Materials
->
m_Transparency
[
idx
]
>=
1.0
f
)
return
;
}
else
{
...
...
3d-viewer/CImage.cpp
0 → 100644
View file @
d80a3d65
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Mario Luzeiro <mrluzeiro@gmail.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "CImage.h"
#define CLAMP(n, min, max) {if (n < min) n=min; else if (n > max) n = max;}
CIMAGE
::
CIMAGE
(
unsigned
int
xsize
,
unsigned
int
ysize
)
{
m_pixels
=
(
unsigned
char
*
)
malloc
(
xsize
*
ysize
);
m_width
=
xsize
;
m_height
=
ysize
;
m_wxh
=
xsize
*
ysize
;
m_wraping
=
(
E_WRAP
)
WRAP_CLAMP
;
}
CIMAGE
::~
CIMAGE
()
{
free
(
m_pixels
);
}
bool
CIMAGE
::
wrapCoords
(
int
*
xo
,
int
*
yo
)
{
int
x
=
*
xo
;
int
y
=
*
yo
;
switch
(
m_wraping
)
{
case
WRAP_CLAMP
:
x
=
(
x
<
0
)
?
0
:
x
;
x
=
(
x
>=
(
int
)(
m_width
-
1
))
?
(
m_width
-
1
)
:
x
;
y
=
(
y
<
0
)
?
0
:
y
;
y
=
(
y
>=
(
int
)(
m_height
-
1
))
?
(
m_height
-
1
)
:
y
;
break
;
case
WRAP_WRAP
:
x
=
(
x
<
0
)
?
((
m_width
-
1
)
+
x
)
:
x
;
x
=
(
x
>=
(
int
)(
m_width
-
1
))
?
(
x
-
m_width
)
:
x
;
y
=
(
y
<
0
)
?
((
m_height
-
1
)
+
y
)
:
y
;
y
=
(
y
>=
(
int
)(
m_height
-
1
))
?
(
y
-
m_height
)
:
y
;
break
;
default
:
break
;
}
if
(
(
x
<
0
)
||
(
x
>=
(
int
)
m_width
)
||
(
y
<
0
)
||
(
y
>=
(
int
)
m_height
))
return
false
;
*
xo
=
x
;
*
yo
=
y
;
return
true
;
}
void
CIMAGE
::
setpixel
(
int
x
,
int
y
,
unsigned
char
value
)
{
if
(
wrapCoords
(
&
x
,
&
y
)
)
m_pixels
[
x
+
y
*
m_width
]
=
value
;
}
unsigned
char
CIMAGE
::
getpixel
(
int
x
,
int
y
)
{
if
(
wrapCoords
(
&
x
,
&
y
)
)
return
m_pixels
[
x
+
y
*
m_width
];
else
return
0
;
}
void
CIMAGE
::
invert
()
{
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
m_pixels
[
it
]
=
255
-
m_pixels
[
it
];
}
void
CIMAGE
::
copyFull
(
const
CIMAGE
*
aImgA
,
const
CIMAGE
*
aImgB
,
E_IMAGE_OP
aOperation
)
{
int
aV
,
bV
;
if
(
aOperation
==
COPY_RAW
)
{
if
(
aImgA
==
NULL
)
return
;
}
else
{
if
(
(
aImgA
==
NULL
)
||
(
aImgB
==
NULL
)
)
return
;
}
switch
(
aOperation
)
{
case
COPY_RAW
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
m_pixels
[
it
]
=
aImgA
->
m_pixels
[
it
];
break
;
case
COPY_ADD
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
aV
=
(
aV
+
bV
);
aV
=
(
aV
>
255
)
?
255
:
aV
;
m_pixels
[
it
]
=
aV
;
}
break
;
case
COPY_SUB
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
aV
=
(
aV
-
bV
);
aV
=
(
aV
<
0
)
?
0
:
aV
;
m_pixels
[
it
]
=
aV
;
}
break
;
case
COPY_DIF
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
m_pixels
[
it
]
=
abs
(
aV
-
bV
);
}
break
;
case
COPY_MUL
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
m_pixels
[
it
]
=
(
unsigned
char
)((((
float
)
aV
/
255.0
f
)
*
((
float
)
bV
/
255.0
f
))
*
255
);
}
break
;
case
COPY_AND
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
m_pixels
[
it
]
=
aImgA
->
m_pixels
[
it
]
&
aImgB
->
m_pixels
[
it
];
}
break
;
case
COPY_OR
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
m_pixels
[
it
]
=
aImgA
->
m_pixels
[
it
]
|
aImgB
->
m_pixels
[
it
];
}
break
;
case
COPY_XOR
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
m_pixels
[
it
]
=
aImgA
->
m_pixels
[
it
]
^
aImgB
->
m_pixels
[
it
];
}
break
;
case
COPY_BLEND50
:
break
;
case
COPY_MIN
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
m_pixels
[
it
]
=
(
aV
<
bV
)
?
aV
:
bV
;
}
break
;
case
COPY_MAX
:
for
(
unsigned
int
it
=
0
;
it
<
m_wxh
;
it
++
)
{
aV
=
aImgA
->
m_pixels
[
it
];
bV
=
aImgB
->
m_pixels
[
it
];
m_pixels
[
it
]
=
(
aV
>
bV
)
?
aV
:
bV
;
}
break
;
}
}
S_FILTER
FILTERS
[
9
]
=
{
// Hi Pass
{
{
{
0
,
-
1
,
-
1
,
-
1
,
0
},
{
-
1
,
2
,
-
4
,
2
,
-
1
},
{
-
1
,
-
4
,
13
,
-
4
,
-
1
},
{
-
1
,
2
,
-
4
,
2
,
-
1
},
{
0
,
-
1
,
-
1
,
-
1
,
0
}
},
7
,
255
},
// Blur
{
{
{
3
,
5
,
7
,
5
,
3
},
{
4
,
9
,
12
,
9
,
5
},
{
7
,
12
,
20
,
12
,
7
},
{
4
,
9
,
12
,
9
,
5
},
{
3
,
5
,
7
,
5
,
3
}
},
180
,
0
},
// KS 01
{
{
{
0
,
2
,
4
,
2
,
0
},
{
2
,
-
2
,
1
,
-
2
,
2
},
{
4
,
1
,
-
8
,
1
,
4
},
{
2
,
-
2
,
1
,
-
2
,
2
},
{
0
,
2
,
4
,
2
,
0
}
},
20
,
0
},
// Cartoon
{
{
{
-
1
,
-
1
,
-
1
,
-
1
,
0
},
{
-
1
,
0
,
0
,
0
,
0
},
{
-
1
,
0
,
4
,
0
,
0
},
{
0
,
0
,
0
,
1
,
0
},
{
0
,
0
,
0
,
0
,
4
}
},
3
,
0
},
// Emboss
{
{
{
-
1
,
-
1
,
-
1
,
-
1
,
0
},
{
-
1
,
-
1
,
-
1
,
0
,
1
},
{
-
1
,
-
1
,
0
,
1
,
1
},
{
-
1
,
0
,
1
,
1
,
1
},
{
0
,
1
,
1
,
1
,
1
}
},
1
,
128
},
// Sharpen
{
{
{
-
1
,
-
1
,
-
1
,
-
1
,
-
1
},
{
-
1
,
2
,
2
,
2
,
-
1
},
{
-
1
,
2
,
8
,
2
,
-
1
},
{
-
1
,
2
,
2
,
2
,
-
1
},
{
-
1
,
-
1
,
-
1
,
-
1
,
-
1
}
},
8
,
0
},
// Melt
{
{
{
4
,
2
,
6
,
8
,
1
},
{
1
,
2
,
5
,
4
,
2
},
{
0
,
-
1
,
1
,
-
1
,
0
},
{
0
,
0
,
-
2
,
0
,
0
},
{
0
,
0
,
0
,
0
,
0
}
},
32
,
0
},
// Sobel Gx
{
{
{
0
,
0
,
0
,
0
,
0
},
{
0
,
-
1
,
0
,
1
,
0
},
{
0
,
-
2
,
0
,
2
,
0
},
{
0
,
-
1
,
0
,
1
,
0
},
{
0
,
0
,
0
,
0
,
0
}
},
1
,
0
},
// Sobel Gy
{
{
{
1
,
2
,
4
,
2
,
1
},
{
-
1
,
-
1
,
0
,
1
,
1
},
{
-
2
,
-
2
,
0
,
2
,
2
},
{
-
1
,
-
1
,
0
,
1
,
1
},
{
-
1
,
-
2
,
-
4
,
-
2
,
-
1
},
},
1
,
0
}
};
// Filters
void
CIMAGE
::
efxFilter
(
CIMAGE
*
aInImg
,
float
aGain
,
E_FILTER
aFilterType
)
{
S_FILTER
filter
=
FILTERS
[
aFilterType
];
aInImg
->
m_wraping
=
WRAP_CLAMP
;
m_wraping
=
WRAP_CLAMP
;
for
(
int
iy
=
0
;
iy
<
(
int
)
m_height
;
iy
++
)
{
for
(
int
ix
=
0
;
ix
<
(
int
)
m_width
;
ix
++
)
{
int
v
=
filter
.
offset
;
for
(
int
sy
=
0
;
sy
<
5
;
sy
++
)
{
for
(
int
sx
=
0
;
sx
<
5
;
sx
++
)
{
int
factor
=
filter
.
kernel
[
sx
][
sy
];
unsigned
char
pixelv
=
aInImg
->
getpixel
(
ix
+
sx
-
2
,
iy
+
sy
-
2
);
v
+=
pixelv
*
factor
;
}
}
v
/=
filter
.
div
;
CLAMP
(
v
,
0
,
255
);
m_pixels
[
ix
+
iy
*
m_width
]
=
v
;
}
}
}
void
CIMAGE
::
setPixelsFromNormalizedFloat
(
const
float
*
aNormalizedFloatArray
)
{
for
(
unsigned
int
i
=
0
;
i
<
m_wxh
;
i
++
)
{
int
v
=
aNormalizedFloatArray
[
i
]
*
255
;
CLAMP
(
v
,
0
,
255
);
m_pixels
[
i
]
=
v
;
}
}
void
CIMAGE
::
saveAsPNG
(
wxString
aFileName
)
{
unsigned
char
*
pixelbuffer
=
(
unsigned
char
*
)
malloc
(
m_wxh
*
3
);
//unsigned char* alphabuffer = (unsigned char*) malloc( m_width * aHeight );
wxImage
image
(
m_width
,
m_height
);
for
(
unsigned
int
i
=
0
;
i
<
m_wxh
;
i
++
)
{
unsigned
char
v
=
m_pixels
[
i
];
pixelbuffer
[
i
*
3
+
0
]
=
v
;
pixelbuffer
[
i
*
3
+
1
]
=
v
;
pixelbuffer
[
i
*
3
+
2
]
=
v
;
//alphabuffer[i * 1 + 0] = aRGBABufferImage[i * 4 + 3];
}
image
.
SetData
(
pixelbuffer
);
//image.SetAlpha( alphabuffer );
image
=
image
.
Mirror
(
false
);
image
.
SaveFile
(
aFileName
+
".png"
,
wxBITMAP_TYPE_PNG
);
image
.
Destroy
();
}
3d-viewer/CImage.h
0 → 100644
View file @
d80a3d65
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Mario Luzeiro <mrluzeiro@gmail.com>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CImage_h
#define CImage_h
#include <wx/image.h>
enum
E_IMAGE_OP
{
COPY_RAW
,
COPY_ADD
,
COPY_SUB
,
COPY_DIF
,
COPY_MUL
,
COPY_AND
,
COPY_OR
,
COPY_XOR
,
COPY_BLEND50
,
COPY_MIN
,
COPY_MAX
};
enum
E_WRAP
{
WRAP_ZERO
,
///< Coords that wraps are not evaluated
WRAP_CLAMP
,
WRAP_WRAP
///< Coords are wrapped arround
};
enum
E_FILTER
{
FILTER_HIPASS
,
FILTER_BLUR
};
typedef
struct
{
signed
char
kernel
[
5
][
5
];
unsigned
char
div
;
unsigned
char
offset
;
}
S_FILTER
;
class
CIMAGE
{
public
:
CIMAGE
(
unsigned
int
xsize
,
unsigned
int
ysize
);
~
CIMAGE
();
void
setpixel
(
int
x
,
int
y
,
unsigned
char
value
);
unsigned
char
getpixel
(
int
x
,
int
y
);
void
copyFull
(
const
CIMAGE
*
aImgA
,
const
CIMAGE
*
aImgB
,
E_IMAGE_OP
aOperation
);
void
invert
();
void
efxFilter
(
CIMAGE
*
aInImg
,
float
aGain
,
E_FILTER
aFilterType
);
void
saveAsPNG
(
wxString
aFileName
);
void
setPixelsFromNormalizedFloat
(
const
float
*
aNormalizedFloatArray
);
private
:
bool
wrapCoords
(
int
*
xo
,
int
*
yo
);
public
:
unsigned
char
*
m_pixels
;
unsigned
int
m_width
;
unsigned
int
m_height
;
unsigned
int
m_wxh
;
E_WRAP
m_wraping
;
};
#endif
3d-viewer/CMakeLists.txt
View file @
d80a3d65
...
...
@@ -30,6 +30,7 @@ set(3D-VIEWER_SRCS
vrml_v1_modelparser.cpp
vrml_v2_modelparser.cpp
x3dmodelparser.cpp
CImage.cpp
)
add_library
(
3d-viewer STATIC
${
3D-VIEWER_SRCS
}
)
...
...
3d-viewer/info3d_visu.h
View file @
d80a3d65
...
...
@@ -183,9 +183,7 @@ public: INFO3D_VISU();
*/
int
GetNonCopperLayerThicknessBIU
()
const
{
bool
use_thickness
=
GetFlag
(
FL_USE_COPPER_THICKNESS
)
// || GetFlag( FL_USE_REALISTIC_MODE )
;
bool
use_thickness
=
GetFlag
(
FL_USE_COPPER_THICKNESS
);
return
use_thickness
?
KiROUND
(
m_nonCopperLayerThickness
/
m_BiuTo3Dunits
)
:
0
;
...
...
@@ -202,8 +200,7 @@ public: INFO3D_VISU();
{
return
IsCopperLayer
(
aLayerId
)
?
GetCopperThicknessBIU
()
:
GetNonCopperLayerThicknessBIU
()
;
GetNonCopperLayerThicknessBIU
();
}
bool
IsRealisticMode
()
{
return
GetFlag
(
FL_USE_REALISTIC_MODE
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment