Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DD4hep
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cepc
externals
mirroring
DD4hep
Commits
7334afbd
Commit
7334afbd
authored
10 years ago
by
Frank Gaede
Browse files
Options
Downloads
Patches
Plain Diff
- added BooleanShape plugin for creating generic boolean
shapes (subtraction, union or intersection )
parent
4fc37c2d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DDCore/src/plugins/ShapePlugins.cpp
+88
-0
88 additions, 0 deletions
DDCore/src/plugins/ShapePlugins.cpp
with
88 additions
and
0 deletions
DDCore/src/plugins/ShapePlugins.cpp
+
88
−
0
View file @
7334afbd
...
...
@@ -132,3 +132,91 @@ static Ref_t create_EightPointSolid(lcdd_t&, xml_h element) {
}
DECLARE_XMLELEMENT
(
EightPointSolid__shape_constructor
,
create_EightPointSolid
)
/** Plugin function for creating a boolean solid from an xml element <shape type=\"BooleanShape\"/>.
* Expects exactly two child elements <shape/> and a string attribute 'operation', which is one of
* 'subtraction', 'union' or 'intersection'. Optionally <position/> and/or <rotation/> can be specified.
* More complex boolean solids can be created by nesting the xml elements accordingly.
*
* @date 03/2015
* @author F.Gaede, CERN/DESY
*/
static
Ref_t
create_BooleanShape
(
lcdd_t
&
,
xml_h
element
)
{
xml_det_t
e
(
element
);
// get the two shape elements
xml_coll_t
c
(
e
,
_U
(
shape
))
;
xml_comp_t
x_shape1
(
c
)
;
++
c
;
xml_comp_t
x_shape2
(
c
)
;
// and create solids
Solid
solid1
(
xml_comp_t
(
x_shape1
).
createShape
())
;
Solid
solid2
(
xml_comp_t
(
x_shape2
).
createShape
())
;
std
::
string
op
=
e
.
attr
<
std
::
string
>
(
DD4hep
::
XML
::
Strng_t
(
"operation"
)
)
;
std
::
transform
(
op
.
begin
(),
op
.
end
(),
op
.
begin
(),
::
tolower
);
Solid
resultSolid
;
bool
useRot
(
false
),
usePos
(
false
)
;
Position
pos
;
RotationZYX
rot
;
if
(
e
.
hasChild
(
_U
(
position
)
)
)
{
usePos
=
true
;
xml_comp_t
x_pos
=
e
.
position
();
pos
=
Position
(
x_pos
.
x
(),
x_pos
.
y
(),
x_pos
.
z
()
);
}
if
(
e
.
hasChild
(
_U
(
rotation
)
)
)
{
useRot
=
true
;
xml_comp_t
x_rot
=
e
.
rotation
();
rot
=
RotationZYX
(
x_rot
.
z
(),
x_rot
.
y
(),
x_rot
.
x
()
)
;
}
if
(
op
==
"subtraction"
)
{
if
(
useRot
&&
usePos
)
resultSolid
=
SubtractionSolid
(
solid1
,
solid2
,
Transform3D
(
rot
,
pos
)
);
else
if
(
useRot
)
resultSolid
=
SubtractionSolid
(
solid1
,
solid2
,
rot
);
else
if
(
usePos
)
resultSolid
=
SubtractionSolid
(
solid1
,
solid2
,
pos
);
else
resultSolid
=
SubtractionSolid
(
solid1
,
solid2
)
;
}
else
if
(
op
==
"union"
)
{
if
(
useRot
&&
usePos
)
resultSolid
=
UnionSolid
(
solid1
,
solid2
,
Transform3D
(
rot
,
pos
)
);
else
if
(
useRot
)
resultSolid
=
UnionSolid
(
solid1
,
solid2
,
rot
);
else
if
(
usePos
)
resultSolid
=
UnionSolid
(
solid1
,
solid2
,
pos
);
else
resultSolid
=
UnionSolid
(
solid1
,
solid2
)
;
}
else
if
(
op
==
"intersection"
)
{
if
(
useRot
&&
usePos
)
resultSolid
=
IntersectionSolid
(
solid1
,
solid2
,
Transform3D
(
rot
,
pos
)
);
else
if
(
useRot
)
resultSolid
=
IntersectionSolid
(
solid1
,
solid2
,
rot
);
else
if
(
usePos
)
resultSolid
=
IntersectionSolid
(
solid1
,
solid2
,
pos
);
else
resultSolid
=
IntersectionSolid
(
solid1
,
solid2
)
;
}
else
{
throw
std
::
runtime_error
(
std
::
string
(
" create_BooleanShape - unknown operation given: "
)
+
op
+
std
::
string
(
" - needs to be one of 'subtraction','union' or 'intersection' "
)
)
;
}
return
resultSolid
;
}
DECLARE_XMLELEMENT
(
BooleanShape__shape_constructor
,
create_BooleanShape
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment