Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / drawinglayer / source / processor3d / cutfindprocessor3d.cxx
blob0127c6a8268fe07f70d096eed51bca4cb7deea36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <drawinglayer/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 <drawinglayer/primitive3d/hiddengeometryprimitive3d.hxx>
31 namespace drawinglayer
33 namespace processor3d
35 CutFindProcessor::CutFindProcessor(const geometry::ViewInformation3D& rViewInformation,
36 const basegfx::B3DPoint& rFront,
37 const basegfx::B3DPoint& rBack,
38 bool bAnyHit)
39 : BaseProcessor3D(rViewInformation),
40 maFront(rFront),
41 maBack(rBack),
42 maResult(),
43 maCombinedTransform(),
44 mbAnyHit(bAnyHit)
48 void CutFindProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
50 if(mbAnyHit && !maResult.empty())
52 // stop processing as soon as a hit was recognized
53 return;
56 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
57 switch(rCandidate.getPrimitive3DID())
59 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
61 // transform group.
62 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
64 // remember old and transform front, back to object coordinates
65 const basegfx::B3DPoint aLastFront(maFront);
66 const basegfx::B3DPoint aLastBack(maBack);
67 basegfx::B3DHomMatrix aInverseTrans(rPrimitive.getTransformation());
68 aInverseTrans.invert();
69 maFront *= aInverseTrans;
70 maBack *= aInverseTrans;
72 // remember current and create new transformation; add new object transform from right side
73 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
74 const geometry::ViewInformation3D aNewViewInformation3D(
75 aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
76 aLastViewInformation3D.getOrientation(),
77 aLastViewInformation3D.getProjection(),
78 aLastViewInformation3D.getDeviceToView(),
79 aLastViewInformation3D.getViewTime(),
80 aLastViewInformation3D.getExtendedInformationSequence());
81 updateViewInformation(aNewViewInformation3D);
83 // #i102956# remember needed back-transform for found cuts (combine from right side)
84 const basegfx::B3DHomMatrix aLastCombinedTransform(maCombinedTransform);
85 maCombinedTransform = maCombinedTransform * rPrimitive.getTransformation();
87 // let break down
88 process(rPrimitive.getChildren());
90 // restore transformations and front, back
91 maCombinedTransform = aLastCombinedTransform;
92 updateViewInformation(aLastViewInformation3D);
93 maFront = aLastFront;
94 maBack = aLastBack;
95 break;
97 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
99 // PolygonHairlinePrimitive3D, not used for hit test with planes, ignore. This
100 // means that also thick line expansion will not be hit-tested as
101 // PolyPolygonMaterialPrimitive3D
102 break;
104 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
106 // #i97321#
107 // For HatchTexturePrimitive3D, do not use the decomposition since it will produce
108 // clipped hatch lines in 3D. It can be used when the hatch also has a filling, but for
109 // simplicity, just use the children which are the PolyPolygonMaterialPrimitive3D
110 // which define the hatched areas anyways; for HitTest this is more than adequate
111 const primitive3d::HatchTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::HatchTexturePrimitive3D& >(rCandidate);
112 process(rPrimitive.getChildren());
113 break;
115 case PRIMITIVE3D_ID_HIDDENGEOMETRYPRIMITIVE3D :
117 // HiddenGeometryPrimitive3D; the default decomposition would return an empty sequence,
118 // so force this primitive to process its children directly if the switch is set
119 // (which is the default). Else, ignore invisible content
120 const primitive3d::HiddenGeometryPrimitive3D& rHiddenGeometry(static_cast< const primitive3d::HiddenGeometryPrimitive3D& >(rCandidate));
121 const primitive3d::Primitive3DContainer& rChildren = rHiddenGeometry.getChildren();
123 if(!rChildren.empty())
125 process(rChildren);
128 break;
130 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D :
132 const primitive3d::UnifiedTransparenceTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::UnifiedTransparenceTexturePrimitive3D& >(rCandidate);
133 const primitive3d::Primitive3DContainer& rChildren = rPrimitive.getChildren();
135 if(!rChildren.empty())
137 process(rChildren);
140 break;
142 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
144 // PolyPolygonMaterialPrimitive3D
145 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
147 if(!maFront.equal(maBack))
149 const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
150 const sal_uInt32 nPolyCount(rPolyPolygon.count());
152 if(nPolyCount)
154 const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(0));
155 const sal_uInt32 nPointCount(aPolygon.count());
157 if(nPointCount > 2)
159 const basegfx::B3DVector aPlaneNormal(aPolygon.getNormal());
161 if(!aPlaneNormal.equalZero())
163 const basegfx::B3DPoint aPointOnPlane(aPolygon.getB3DPoint(0));
164 double fCut(0.0);
166 if(basegfx::utils::getCutBetweenLineAndPlane(aPlaneNormal, aPointOnPlane, maFront, maBack, fCut))
168 const basegfx::B3DPoint aCutPoint(basegfx::interpolate(maFront, maBack, fCut));
170 if(basegfx::utils::isInside(rPolyPolygon, aCutPoint))
172 // #i102956# add result. Do not forget to do this in the coordinate
173 // system the processor get started with, so use the collected
174 // combined transformation from processed TransformPrimitive3D's
175 maResult.push_back(maCombinedTransform * aCutPoint);
183 break;
185 default :
187 // process recursively
188 process(rCandidate.get3DDecomposition(getViewInformation3D()));
189 break;
193 } // end of namespace processor3d
194 } // end of namespace drawinglayer
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */