1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/processor3d/cutfindprocessor3d.hxx>
21 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
22 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
23 #include <primitive3d/hatchtextureprimitive3d.hxx>
24 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
25 #include <basegfx/polygon/b3dpolygon.hxx>
26 #include <basegfx/polygon/b3dpolygontools.hxx>
27 #include <basegfx/polygon/b3dpolypolygontools.hxx>
28 #include <primitive3d/hiddengeometryprimitive3d.hxx>
31 namespace drawinglayer::processor3d
33 CutFindProcessor::CutFindProcessor(const geometry::ViewInformation3D
& rViewInformation
,
34 const basegfx::B3DPoint
& rFront
,
35 const basegfx::B3DPoint
& rBack
,
37 : BaseProcessor3D(rViewInformation
),
44 void CutFindProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D
& rCandidate
)
46 if(mbAnyHit
&& !maResult
.empty())
48 // stop processing as soon as a hit was recognized
52 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
53 switch(rCandidate
.getPrimitive3DID())
55 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
:
58 const primitive3d::TransformPrimitive3D
& rPrimitive
= static_cast< const primitive3d::TransformPrimitive3D
& >(rCandidate
);
60 // remember old and transform front, back to object coordinates
61 const basegfx::B3DPoint
aLastFront(maFront
);
62 const basegfx::B3DPoint
aLastBack(maBack
);
63 basegfx::B3DHomMatrix
aInverseTrans(rPrimitive
.getTransformation());
64 aInverseTrans
.invert();
65 maFront
*= aInverseTrans
;
66 maBack
*= aInverseTrans
;
68 // remember current and create new transformation; add new object transform from right side
69 const geometry::ViewInformation3D
aLastViewInformation3D(getViewInformation3D());
70 const geometry::ViewInformation3D
aNewViewInformation3D(
71 aLastViewInformation3D
.getObjectTransformation() * rPrimitive
.getTransformation(),
72 aLastViewInformation3D
.getOrientation(),
73 aLastViewInformation3D
.getProjection(),
74 aLastViewInformation3D
.getDeviceToView(),
75 aLastViewInformation3D
.getViewTime(),
76 aLastViewInformation3D
.getExtendedInformationSequence());
77 updateViewInformation(aNewViewInformation3D
);
79 // #i102956# remember needed back-transform for found cuts (combine from right side)
80 const basegfx::B3DHomMatrix
aLastCombinedTransform(maCombinedTransform
);
81 maCombinedTransform
= maCombinedTransform
* rPrimitive
.getTransformation();
84 process(rPrimitive
.getChildren());
86 // restore transformations and front, back
87 maCombinedTransform
= aLastCombinedTransform
;
88 updateViewInformation(aLastViewInformation3D
);
93 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
:
95 // PolygonHairlinePrimitive3D, not used for hit test with planes, ignore. This
96 // means that also thick line expansion will not be hit-tested as
97 // PolyPolygonMaterialPrimitive3D
100 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D
:
103 // For HatchTexturePrimitive3D, do not use the decomposition since it will produce
104 // clipped hatch lines in 3D. It can be used when the hatch also has a filling, but for
105 // simplicity, just use the children which are the PolyPolygonMaterialPrimitive3D
106 // which define the hatched areas anyways; for HitTest this is more than adequate
107 const primitive3d::HatchTexturePrimitive3D
& rPrimitive
= static_cast< const primitive3d::HatchTexturePrimitive3D
& >(rCandidate
);
108 process(rPrimitive
.getChildren());
111 case PRIMITIVE3D_ID_HIDDENGEOMETRYPRIMITIVE3D
:
113 // HiddenGeometryPrimitive3D; the default decomposition would return an empty sequence,
114 // so force this primitive to process its children directly if the switch is set
115 // (which is the default). Else, ignore invisible content
116 const primitive3d::HiddenGeometryPrimitive3D
& rHiddenGeometry(static_cast< const primitive3d::HiddenGeometryPrimitive3D
& >(rCandidate
));
117 const primitive3d::Primitive3DContainer
& rChildren
= rHiddenGeometry
.getChildren();
119 if(!rChildren
.empty())
126 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D
:
128 const primitive3d::UnifiedTransparenceTexturePrimitive3D
& rPrimitive
= static_cast< const primitive3d::UnifiedTransparenceTexturePrimitive3D
& >(rCandidate
);
129 const primitive3d::Primitive3DContainer
& rChildren
= rPrimitive
.getChildren();
131 if(!rChildren
.empty())
138 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
:
140 // PolyPolygonMaterialPrimitive3D
141 const primitive3d::PolyPolygonMaterialPrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D
& >(rCandidate
);
143 if(!maFront
.equal(maBack
))
145 const basegfx::B3DPolyPolygon
& rPolyPolygon
= rPrimitive
.getB3DPolyPolygon();
146 const sal_uInt32
nPolyCount(rPolyPolygon
.count());
150 const basegfx::B3DPolygon
& aPolygon(rPolyPolygon
.getB3DPolygon(0));
151 const sal_uInt32
nPointCount(aPolygon
.count());
155 const basegfx::B3DVector
aPlaneNormal(aPolygon
.getNormal());
157 if(!aPlaneNormal
.equalZero())
159 const basegfx::B3DPoint
aPointOnPlane(aPolygon
.getB3DPoint(0));
162 if(basegfx::utils::getCutBetweenLineAndPlane(aPlaneNormal
, aPointOnPlane
, maFront
, maBack
, fCut
))
164 const basegfx::B3DPoint
aCutPoint(basegfx::interpolate(maFront
, maBack
, fCut
));
166 if(basegfx::utils::isInside(rPolyPolygon
, aCutPoint
))
168 // #i102956# add result. Do not forget to do this in the coordinate
169 // system the processor get started with, so use the collected
170 // combined transformation from processed TransformPrimitive3D's
171 maResult
.push_back(maCombinedTransform
* aCutPoint
);
183 // process recursively
184 process(rCandidate
.get3DDecomposition(getViewInformation3D()));
190 } // end of namespace
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */