LibreOffice Module drawinglayer (master) 1
cutfindprocessor3d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
29
30
32{
34 const basegfx::B3DPoint& rFront,
35 const basegfx::B3DPoint& rBack,
36 bool bAnyHit)
37 : BaseProcessor3D(rViewInformation),
38 maFront(rFront),
39 maBack(rBack),
40 mbAnyHit(bAnyHit)
41 {
42 }
43
45 {
46 if(mbAnyHit && !maResult.empty())
47 {
48 // stop processing as soon as a hit was recognized
49 return;
50 }
51
52 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
53 switch(rCandidate.getPrimitive3DID())
54 {
56 {
57 // transform group.
58 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
59
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;
67
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);
78
79 // #i102956# remember needed back-transform for found cuts (combine from right side)
80 const basegfx::B3DHomMatrix aLastCombinedTransform(maCombinedTransform);
82
83 // let break down
84 process(rPrimitive.getChildren());
85
86 // restore transformations and front, back
87 maCombinedTransform = aLastCombinedTransform;
88 updateViewInformation(aLastViewInformation3D);
89 maFront = aLastFront;
90 maBack = aLastBack;
91 break;
92 }
94 {
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
98 break;
99 }
101 {
102 // #i97321#
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());
109 break;
110 }
112 {
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();
118
119 if(!rChildren.empty())
120 {
121 process(rChildren);
122 }
123
124 break;
125 }
127 {
129 const primitive3d::Primitive3DContainer& rChildren = rPrimitive.getChildren();
130
131 if(!rChildren.empty())
132 {
133 process(rChildren);
134 }
135
136 break;
137 }
139 {
140 // PolyPolygonMaterialPrimitive3D
141 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
142
143 if(!maFront.equal(maBack))
144 {
145 const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
146 const sal_uInt32 nPolyCount(rPolyPolygon.count());
147
148 if(nPolyCount)
149 {
150 const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(0));
151 const sal_uInt32 nPointCount(aPolygon.count());
152
153 if(nPointCount > 2)
154 {
155 const basegfx::B3DVector aPlaneNormal(aPolygon.getNormal());
156
157 if(!aPlaneNormal.equalZero())
158 {
159 const basegfx::B3DPoint aPointOnPlane(aPolygon.getB3DPoint(0));
160 double fCut(0.0);
161
162 if(basegfx::utils::getCutBetweenLineAndPlane(aPlaneNormal, aPointOnPlane, maFront, maBack, fCut))
163 {
164 const basegfx::B3DPoint aCutPoint(basegfx::interpolate(maFront, maBack, fCut));
165
166 if(basegfx::utils::isInside(rPolyPolygon, aCutPoint))
167 {
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);
172 }
173 }
174 }
175 }
176 }
177 }
178
179 break;
180 }
181 default :
182 {
183 // process recursively
185 break;
186 }
187 }
188 }
189
190} // end of namespace
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 count() const
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
B3DPoint const & getB3DPoint(sal_uInt32 nIndex) const
sal_uInt32 count() const
B3DVector const & getNormal() const
bool equalZero() const
bool equal(const B3DTuple &rTup) const
const css::uno::Sequence< css::beans::PropertyValue > & getExtendedInformationSequence() const
Get the uno::Sequence< beans::PropertyValue > which contains only ViewInformation not offered directl...
const basegfx::B3DHomMatrix & getDeviceToView() const
const basegfx::B3DHomMatrix & getObjectTransformation() const
data access
const basegfx::B3DHomMatrix & getProjection() const
const basegfx::B3DHomMatrix & getOrientation() const
virtual Primitive3DContainer get3DDecomposition(const geometry::ViewInformation3D &rViewInformation) const
The default implementation returns an empty sequence.
virtual sal_uInt32 getPrimitive3DID() const =0
provide unique ID for fast identifying of known primitive implementations in renderers.
const Primitive3DContainer & getChildren() const
data read access
const basegfx::B3DPolyPolygon & getB3DPolyPolygon() const
data read access
const basegfx::B3DHomMatrix & getTransformation() const
data read access
void process(const primitive3d::Primitive3DContainer &rSource)
const geometry::ViewInformation3D & getViewInformation3D() const
void updateViewInformation(const geometry::ViewInformation3D &rViewInformation3D)
basegfx::B3DPoint maFront
the start and stop point for the cut vector
CutFindProcessor(const geometry::ViewInformation3D &rViewInformation, const basegfx::B3DPoint &rFront, const basegfx::B3DPoint &rBack, bool bAnyHit)
::std::vector< basegfx::B3DPoint > maResult
the found cut points
virtual void processBasePrimitive3D(const primitive3d::BasePrimitive3D &rCandidate) override
#define PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
#define PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
#define PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
#define PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D
#define PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D
#define PRIMITIVE3D_ID_HIDDENGEOMETRYPRIMITIVE3D
bool getCutBetweenLineAndPlane(const B3DVector &rPlaneNormal, const B3DPoint &rPlanePoint, const B3DPoint &rEdgeStart, const B3DPoint &rEdgeEnd, double &fCut)
bool isInside(const B2DPolygon &rCandidate, const B2DPoint &rPoint, bool bWithBorder)
B2DTuple interpolate(const B2DTuple &rOld1, const B2DTuple &rOld2, double t)