Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/processor3d/cutfindprocessor3d.cxx
Line
Count
Source
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
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>
29
30
31
namespace drawinglayer::processor3d
32
{
33
        CutFindProcessor::CutFindProcessor(const geometry::ViewInformation3D& rViewInformation,
34
            const basegfx::B3DPoint& rFront,
35
            const basegfx::B3DPoint& rBack,
36
            bool bAnyHit)
37
0
        :   BaseProcessor3D(rViewInformation),
38
0
            maFront(rFront),
39
0
            maBack(rBack),
40
0
            mbAnyHit(bAnyHit)
41
0
        {
42
0
        }
43
44
        void CutFindProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
45
0
        {
46
0
            if(mbAnyHit && !maResult.empty())
47
0
            {
48
                // stop processing as soon as a hit was recognized
49
0
                return;
50
0
            }
51
52
            // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
53
0
            switch(rCandidate.getPrimitive3DID())
54
0
            {
55
0
                case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
56
0
                {
57
                    // transform group.
58
0
                    const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
59
60
                    // remember old and transform front, back to object coordinates
61
0
                    const basegfx::B3DPoint aLastFront(maFront);
62
0
                    const basegfx::B3DPoint aLastBack(maBack);
63
0
                    basegfx::B3DHomMatrix aInverseTrans(rPrimitive.getTransformation());
64
0
                    aInverseTrans.invert();
65
0
                    maFront *= aInverseTrans;
66
0
                    maBack *= aInverseTrans;
67
68
                    // remember current and create new transformation; add new object transform from right side
69
0
                    const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
70
0
                    const geometry::ViewInformation3D aNewViewInformation3D(
71
0
                        aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
72
0
                        aLastViewInformation3D.getOrientation(),
73
0
                        aLastViewInformation3D.getProjection(),
74
0
                        aLastViewInformation3D.getDeviceToView(),
75
0
                        aLastViewInformation3D.getViewTime(),
76
0
                        aLastViewInformation3D.getExtendedInformationSequence());
77
0
                    setViewInformation3D(aNewViewInformation3D);
78
79
                    // #i102956# remember needed back-transform for found cuts (combine from right side)
80
0
                    const basegfx::B3DHomMatrix aLastCombinedTransform(maCombinedTransform);
81
0
                    maCombinedTransform = maCombinedTransform * rPrimitive.getTransformation();
82
83
                    // let break down
84
0
                    process(rPrimitive.getChildren());
85
86
                    // restore transformations and front, back
87
0
                    maCombinedTransform = aLastCombinedTransform;
88
0
                    setViewInformation3D(aLastViewInformation3D);
89
0
                    maFront = aLastFront;
90
0
                    maBack = aLastBack;
91
0
                    break;
92
0
                }
93
0
                case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
94
0
                {
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
0
                    break;
99
0
                }
100
0
                case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
101
0
                {
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
0
                    const primitive3d::HatchTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::HatchTexturePrimitive3D& >(rCandidate);
108
0
                    process(rPrimitive.getChildren());
109
0
                    break;
110
0
                }
111
0
                case PRIMITIVE3D_ID_HIDDENGEOMETRYPRIMITIVE3D :
112
0
                {
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
0
                    const primitive3d::HiddenGeometryPrimitive3D& rHiddenGeometry(static_cast< const primitive3d::HiddenGeometryPrimitive3D& >(rCandidate));
117
0
                    const primitive3d::Primitive3DContainer& rChildren = rHiddenGeometry.getChildren();
118
119
0
                    if(!rChildren.empty())
120
0
                    {
121
0
                            process(rChildren);
122
0
                    }
123
124
0
                    break;
125
0
                }
126
0
                case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D :
127
0
                {
128
0
                    const primitive3d::UnifiedTransparenceTexturePrimitive3D& rPrimitive = static_cast< const primitive3d::UnifiedTransparenceTexturePrimitive3D& >(rCandidate);
129
0
                    const primitive3d::Primitive3DContainer& rChildren = rPrimitive.getChildren();
130
131
0
                    if(!rChildren.empty())
132
0
                    {
133
0
                        process(rChildren);
134
0
                    }
135
136
0
                    break;
137
0
                }
138
0
                case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
139
0
                {
140
                    // PolyPolygonMaterialPrimitive3D
141
0
                    const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
142
143
0
                    if(!maFront.equal(maBack))
144
0
                    {
145
0
                        const basegfx::B3DPolyPolygon& rPolyPolygon = rPrimitive.getB3DPolyPolygon();
146
0
                        const sal_uInt32 nPolyCount(rPolyPolygon.count());
147
148
0
                        if(nPolyCount)
149
0
                        {
150
0
                            const basegfx::B3DPolygon& aPolygon(rPolyPolygon.getB3DPolygon(0));
151
0
                            const sal_uInt32 nPointCount(aPolygon.count());
152
153
0
                            if(nPointCount > 2)
154
0
                            {
155
0
                                const basegfx::B3DVector aPlaneNormal(aPolygon.getNormal());
156
157
0
                                if(!aPlaneNormal.equalZero())
158
0
                                {
159
0
                                    const basegfx::B3DPoint aPointOnPlane(aPolygon.getB3DPoint(0));
160
0
                                    double fCut(0.0);
161
162
0
                                    if(basegfx::utils::getCutBetweenLineAndPlane(aPlaneNormal, aPointOnPlane, maFront, maBack, fCut))
163
0
                                    {
164
0
                                        const basegfx::B3DPoint aCutPoint(basegfx::interpolate(maFront, maBack, fCut));
165
166
0
                                        if(basegfx::utils::isInside(rPolyPolygon, aCutPoint))
167
0
                                        {
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
0
                                            maResult.push_back(maCombinedTransform * aCutPoint);
172
0
                                        }
173
0
                                    }
174
0
                                }
175
0
                            }
176
0
                        }
177
0
                    }
178
179
0
                    break;
180
0
                }
181
0
                default :
182
0
                {
183
                    // process recursively
184
0
                    process(rCandidate.get3DDecomposition(getViewInformation3D()));
185
0
                    break;
186
0
                }
187
0
            }
188
0
        }
189
190
} // end of namespace
191
192
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */