FreeCAD

Форк
0
/
ViewProviderDefects.cpp 
795 строк · 26.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <Inventor/nodes/SoBaseColor.h>
26
#include <Inventor/nodes/SoCoordinate3.h>
27
#include <Inventor/nodes/SoDrawStyle.h>
28
#include <Inventor/nodes/SoFaceSet.h>
29
#include <Inventor/nodes/SoLineSet.h>
30
#include <Inventor/nodes/SoMarkerSet.h>
31
#include <Inventor/nodes/SoSeparator.h>
32
#include <Inventor/nodes/SoShapeHints.h>
33
#endif
34

35
#include <App/Application.h>
36
#include <Base/Parameter.h>
37
#include <Gui/Inventor/MarkerBitmaps.h>
38
#include <Mod/Mesh/App/MeshFeature.h>
39
#include <Mod/Mesh/App/Core/Degeneration.h>
40
#include <Mod/Mesh/App/Core/Iterator.h>
41

42
#include "ViewProviderDefects.h"
43

44

45
using namespace Mesh;
46
using namespace MeshGui;
47

48

49
PROPERTY_SOURCE_ABSTRACT(MeshGui::ViewProviderMeshDefects, Gui::ViewProviderDocumentObject)
50
PROPERTY_SOURCE(MeshGui::ViewProviderMeshOrientation, MeshGui::ViewProviderMeshDefects)
51
PROPERTY_SOURCE(MeshGui::ViewProviderMeshNonManifolds, MeshGui::ViewProviderMeshDefects)
52
PROPERTY_SOURCE(MeshGui::ViewProviderMeshNonManifoldPoints, MeshGui::ViewProviderMeshDefects)
53
PROPERTY_SOURCE(MeshGui::ViewProviderMeshDuplicatedFaces, MeshGui::ViewProviderMeshDefects)
54
PROPERTY_SOURCE(MeshGui::ViewProviderMeshDuplicatedPoints, MeshGui::ViewProviderMeshDefects)
55
PROPERTY_SOURCE(MeshGui::ViewProviderMeshDegenerations, MeshGui::ViewProviderMeshDefects)
56
PROPERTY_SOURCE(MeshGui::ViewProviderMeshIndices, MeshGui::ViewProviderMeshDefects)
57
PROPERTY_SOURCE(MeshGui::ViewProviderMeshSelfIntersections, MeshGui::ViewProviderMeshDefects)
58
PROPERTY_SOURCE(MeshGui::ViewProviderMeshFolds, MeshGui::ViewProviderMeshDefects)
59

60
ViewProviderMeshDefects::ViewProviderMeshDefects()
61
{
62
    ADD_PROPERTY(LineWidth, (2.0F));
63

64
    pcCoords = new SoCoordinate3();
65
    pcCoords->ref();
66
    pcDrawStyle = new SoDrawStyle();
67
    pcDrawStyle->ref();
68
    pcDrawStyle->style = SoDrawStyle::LINES;
69
    pcDrawStyle->lineWidth = LineWidth.getValue();
70
}
71

72
ViewProviderMeshDefects::~ViewProviderMeshDefects()
73
{
74
    pcCoords->unref();
75
    pcDrawStyle->unref();
76
}
77

78
void ViewProviderMeshDefects::onChanged(const App::Property* prop)
79
{
80
    if (prop == &LineWidth) {
81
        pcDrawStyle->lineWidth = LineWidth.getValue();
82
    }
83
    // Visibility changes must be handled here because in the base class it changes the attribute of
84
    // the feature and thus affects the visibility of the mesh view provider which is undesired
85
    // behaviour
86
    else if (prop == &Visibility) {
87
        Visibility.getValue() ? show() : hide();
88
    }
89
    else {
90
        ViewProviderDocumentObject::onChanged(prop);
91
    }
92
}
93

94
// ----------------------------------------------------------------------
95

96
ViewProviderMeshOrientation::ViewProviderMeshOrientation()
97
{
98
    // NOLINTBEGIN
99
    pcFaces = new SoFaceSet;
100
    pcFaces->ref();
101
    // NOLINTEND
102
}
103

104
ViewProviderMeshOrientation::~ViewProviderMeshOrientation()
105
{
106
    pcFaces->unref();
107
}
108

109
void ViewProviderMeshOrientation::attach(App::DocumentObject* pcFeat)
110
{
111
    ViewProviderDocumentObject::attach(pcFeat);
112

113
    SoGroup* pcFaceRoot = new SoGroup();
114

115
    SoDrawStyle* pcFlatStyle = new SoDrawStyle();
116
    pcFlatStyle->style = SoDrawStyle::FILLED;
117
    pcFaceRoot->addChild(pcFlatStyle);
118

119
    SoShapeHints* flathints = new SoShapeHints;
120
    flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
121
    flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
122
    pcFaceRoot->addChild(flathints);
123

124
    // Draw faces
125
    SoSeparator* linesep = new SoSeparator;
126
    SoBaseColor* basecol = new SoBaseColor;
127
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
128
    linesep->addChild(basecol);
129
    linesep->addChild(pcCoords);
130
    linesep->addChild(pcFaces);
131

132
    // Draw markers
133
    SoBaseColor* markcol = new SoBaseColor;
134
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
135
    SoMarkerSet* marker = new SoMarkerSet;
136
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
137
        "PLUS",
138
        App::GetApplication()
139
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
140
            ->GetInt("MarkerSize", 7));
141
    linesep->addChild(markcol);
142
    linesep->addChild(marker);
143

144
    pcFaceRoot->addChild(linesep);
145

146
    addDisplayMaskMode(pcFaceRoot, "Face");
147
}
148

149
void ViewProviderMeshOrientation::showDefects(const std::vector<Mesh::ElementIndex>& inds)
150
{
151
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
152
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
153

154
    pcCoords->point.deleteValues(0);
155
    pcCoords->point.setNum(3 * inds.size());
156
    MeshCore::MeshFacetIterator cF(rMesh);
157
    int i = 0;
158
    int j = 0;
159
    for (Mesh::ElementIndex ind : inds) {
160
        cF.Set(ind);
161
        for (auto cP : cF->_aclPoints) {
162
            // move a bit in opposite normal direction to overlay the original faces
163
            cP -= 0.001F * cF->GetNormal();
164
            pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z);
165
        }
166
        pcFaces->numVertices.set1Value(j++, 3);
167
    }
168

169
    setDisplayMaskMode("Face");
170
}
171

172
// ----------------------------------------------------------------------
173

174
ViewProviderMeshNonManifolds::ViewProviderMeshNonManifolds()
175
{
176
    // NOLINTBEGIN
177
    pcLines = new SoLineSet;
178
    pcLines->ref();
179
    // NOLINTEND
180
}
181

182
ViewProviderMeshNonManifolds::~ViewProviderMeshNonManifolds()
183
{
184
    pcLines->unref();
185
}
186

187
void ViewProviderMeshNonManifolds::attach(App::DocumentObject* pcFeat)
188
{
189
    ViewProviderDocumentObject::attach(pcFeat);
190

191
    SoGroup* pcLineRoot = new SoGroup();
192
    pcDrawStyle->lineWidth = 3;
193
    pcLineRoot->addChild(pcDrawStyle);
194

195
    // Draw lines
196
    SoSeparator* linesep = new SoSeparator;
197
    SoBaseColor* basecol = new SoBaseColor;
198
    basecol->rgb.setValue(1.0F, 0.0F, 0.0F);
199
    linesep->addChild(basecol);
200
    linesep->addChild(pcCoords);
201
    linesep->addChild(pcLines);
202
    pcLineRoot->addChild(linesep);
203

204
    // Draw markers
205
    SoBaseColor* markcol = new SoBaseColor;
206
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
207
    SoMarkerSet* marker = new SoMarkerSet;
208
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
209
        "PLUS",
210
        App::GetApplication()
211
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
212
            ->GetInt("MarkerSize", 7));
213
    linesep->addChild(markcol);
214
    linesep->addChild(marker);
215

216
    addDisplayMaskMode(pcLineRoot, "Line");
217
}
218

219
void ViewProviderMeshNonManifolds::showDefects(const std::vector<Mesh::ElementIndex>& inds)
220
{
221
    if ((inds.size() % 2) != 0) {
222
        return;
223
    }
224
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
225
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
226

227
    pcCoords->point.deleteValues(0);
228
    pcCoords->point.setNum(inds.size());
229
    MeshCore::MeshPointIterator cP(rMesh);
230
    int i = 0;
231
    int j = 0;
232
    for (std::vector<Mesh::ElementIndex>::const_iterator it = inds.begin(); it != inds.end();
233
         ++it) {
234
        cP.Set(*it);
235
        pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z);
236
        ++it;  // go to end point
237
        cP.Set(*it);
238
        pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z);
239
        pcLines->numVertices.set1Value(j++, 2);
240
    }
241

242
    setDisplayMaskMode("Line");
243
}
244

245
// ----------------------------------------------------------------------
246

247
ViewProviderMeshNonManifoldPoints::ViewProviderMeshNonManifoldPoints()
248
{
249
    // NOLINTBEGIN
250
    pcPoints = new SoPointSet;
251
    pcPoints->ref();
252
    // NOLINTEND
253
}
254

255
ViewProviderMeshNonManifoldPoints::~ViewProviderMeshNonManifoldPoints()
256
{
257
    pcPoints->unref();
258
}
259

260
void ViewProviderMeshNonManifoldPoints::attach(App::DocumentObject* pcFeat)
261
{
262
    ViewProviderDocumentObject::attach(pcFeat);
263

264
    SoGroup* pcPointRoot = new SoGroup();
265
    pcDrawStyle->pointSize = 3;
266
    pcPointRoot->addChild(pcDrawStyle);
267

268
    // Draw points
269
    SoSeparator* pointsep = new SoSeparator;
270
    SoBaseColor* basecol = new SoBaseColor;
271
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
272
    pointsep->addChild(basecol);
273
    pointsep->addChild(pcCoords);
274
    pointsep->addChild(pcPoints);
275
    pcPointRoot->addChild(pointsep);
276

277
    // Draw markers
278
    SoBaseColor* markcol = new SoBaseColor;
279
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
280
    SoMarkerSet* marker = new SoMarkerSet;
281
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
282
        "PLUS",
283
        App::GetApplication()
284
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
285
            ->GetInt("MarkerSize", 7));
286
    pointsep->addChild(markcol);
287
    pointsep->addChild(marker);
288

289
    addDisplayMaskMode(pcPointRoot, "Point");
290
}
291

292
void ViewProviderMeshNonManifoldPoints::showDefects(const std::vector<Mesh::ElementIndex>& inds)
293
{
294
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
295
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
296
    pcCoords->point.deleteValues(0);
297
    pcCoords->point.setNum(inds.size());
298
    MeshCore::MeshPointIterator cP(rMesh);
299
    int i = 0;
300
    for (Mesh::ElementIndex ind : inds) {
301
        cP.Set(ind);
302
        pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z);
303
    }
304

305
    setDisplayMaskMode("Point");
306
}
307

308
// ----------------------------------------------------------------------
309

310
ViewProviderMeshDuplicatedFaces::ViewProviderMeshDuplicatedFaces()
311
{
312
    // NOLINTBEGIN
313
    pcFaces = new SoFaceSet;
314
    pcFaces->ref();
315
    // NOLINTEND
316
}
317

318
ViewProviderMeshDuplicatedFaces::~ViewProviderMeshDuplicatedFaces()
319
{
320
    pcFaces->unref();
321
}
322

323
void ViewProviderMeshDuplicatedFaces::attach(App::DocumentObject* pcFeat)
324
{
325
    ViewProviderDocumentObject::attach(pcFeat);
326

327
    SoGroup* pcFaceRoot = new SoGroup();
328

329
    SoDrawStyle* pcFlatStyle = new SoDrawStyle();
330
    pcFlatStyle->style = SoDrawStyle::FILLED;
331
    pcFaceRoot->addChild(pcFlatStyle);
332

333
    SoShapeHints* flathints = new SoShapeHints;
334
    flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
335
    flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
336
    pcFaceRoot->addChild(flathints);
337

338
    // Draw lines
339
    SoSeparator* linesep = new SoSeparator;
340
    SoBaseColor* basecol = new SoBaseColor;
341
    basecol->rgb.setValue(1.0F, 0.0F, 0.0F);
342
    linesep->addChild(basecol);
343
    linesep->addChild(pcCoords);
344
    linesep->addChild(pcFaces);
345
    pcFaceRoot->addChild(linesep);
346

347
    // Draw markers
348
    SoBaseColor* markcol = new SoBaseColor;
349
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
350
    SoMarkerSet* marker = new SoMarkerSet;
351
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
352
        "PLUS",
353
        App::GetApplication()
354
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
355
            ->GetInt("MarkerSize", 7));
356
    linesep->addChild(markcol);
357
    linesep->addChild(marker);
358

359
    addDisplayMaskMode(pcFaceRoot, "Face");
360
}
361

362
void ViewProviderMeshDuplicatedFaces::showDefects(const std::vector<Mesh::ElementIndex>& inds)
363
{
364
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
365
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
366

367
    pcCoords->point.deleteValues(0);
368
    pcCoords->point.setNum(3 * inds.size());
369
    MeshCore::MeshFacetIterator cF(rMesh);
370
    int i = 0;
371
    int j = 0;
372
    for (Mesh::ElementIndex ind : inds) {
373
        cF.Set(ind);
374
        for (auto cP : cF->_aclPoints) {
375
            // move a bit in normal direction to overlay the original faces
376
            cP += 0.001F * cF->GetNormal();
377
            pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z);
378
        }
379
        pcFaces->numVertices.set1Value(j++, 3);
380
    }
381

382
    setDisplayMaskMode("Face");
383
}
384

385
// ----------------------------------------------------------------------
386

387
ViewProviderMeshDuplicatedPoints::ViewProviderMeshDuplicatedPoints()
388
{
389
    // NOLINTBEGIN
390
    pcPoints = new SoPointSet;
391
    pcPoints->ref();
392
    // NOLINTEND
393
}
394

395
ViewProviderMeshDuplicatedPoints::~ViewProviderMeshDuplicatedPoints()
396
{
397
    pcPoints->unref();
398
}
399

400
void ViewProviderMeshDuplicatedPoints::attach(App::DocumentObject* pcFeat)
401
{
402
    ViewProviderDocumentObject::attach(pcFeat);
403

404
    SoGroup* pcPointRoot = new SoGroup();
405
    pcDrawStyle->pointSize = 3;
406
    pcPointRoot->addChild(pcDrawStyle);
407

408
    // Draw points
409
    SoSeparator* pointsep = new SoSeparator;
410
    SoBaseColor* basecol = new SoBaseColor;
411
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
412
    pointsep->addChild(basecol);
413
    pointsep->addChild(pcCoords);
414
    pointsep->addChild(pcPoints);
415
    pcPointRoot->addChild(pointsep);
416

417
    // Draw markers
418
    SoBaseColor* markcol = new SoBaseColor;
419
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
420
    SoMarkerSet* marker = new SoMarkerSet;
421
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
422
        "PLUS",
423
        App::GetApplication()
424
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
425
            ->GetInt("MarkerSize", 7));
426
    pointsep->addChild(markcol);
427
    pointsep->addChild(marker);
428

429
    addDisplayMaskMode(pcPointRoot, "Point");
430
}
431

432
void ViewProviderMeshDuplicatedPoints::showDefects(const std::vector<Mesh::ElementIndex>& inds)
433
{
434
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
435
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
436
    pcCoords->point.deleteValues(0);
437
    pcCoords->point.setNum(inds.size());
438
    MeshCore::MeshPointIterator cP(rMesh);
439
    int i = 0;
440
    for (Mesh::ElementIndex ind : inds) {
441
        cP.Set(ind);
442
        pcCoords->point.set1Value(i++, cP->x, cP->y, cP->z);
443
    }
444

445
    setDisplayMaskMode("Point");
446
}
447

448
// ----------------------------------------------------------------------
449

450
ViewProviderMeshDegenerations::ViewProviderMeshDegenerations()
451
{
452
    // NOLINTBEGIN
453
    pcLines = new SoLineSet;
454
    pcLines->ref();
455
    // NOLINTEND
456
}
457

458
ViewProviderMeshDegenerations::~ViewProviderMeshDegenerations()
459
{
460
    pcLines->unref();
461
}
462

463
void ViewProviderMeshDegenerations::attach(App::DocumentObject* pcFeat)
464
{
465
    ViewProviderDocumentObject::attach(pcFeat);
466

467
    SoGroup* pcLineRoot = new SoGroup();
468
    pcDrawStyle->lineWidth = 3;
469
    pcLineRoot->addChild(pcDrawStyle);
470

471
    // Draw lines
472
    SoSeparator* linesep = new SoSeparator;
473
    SoBaseColor* basecol = new SoBaseColor;
474
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
475
    linesep->addChild(basecol);
476
    linesep->addChild(pcCoords);
477
    linesep->addChild(pcLines);
478
    pcLineRoot->addChild(linesep);
479

480
    // Draw markers
481
    SoBaseColor* markcol = new SoBaseColor;
482
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
483
    SoMarkerSet* marker = new SoMarkerSet;
484
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
485
        "PLUS",
486
        App::GetApplication()
487
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
488
            ->GetInt("MarkerSize", 7));
489
    linesep->addChild(markcol);
490
    linesep->addChild(marker);
491

492
    addDisplayMaskMode(pcLineRoot, "Line");
493
}
494

495
void ViewProviderMeshDegenerations::showDefects(const std::vector<Mesh::ElementIndex>& inds)
496
{
497
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
498
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
499

500
    pcCoords->point.deleteValues(0);
501
    pcCoords->point.setNum(2 * inds.size());
502
    MeshCore::MeshFacetIterator cF(rMesh);
503
    int i = 0;
504
    int j = 0;
505
    for (Mesh::ElementIndex ind : inds) {
506
        cF.Set(ind);
507
        const MeshCore::MeshPoint& rE0 = cF->_aclPoints[0];
508
        const MeshCore::MeshPoint& rE1 = cF->_aclPoints[1];
509
        const MeshCore::MeshPoint& rE2 = cF->_aclPoints[2];
510

511
        // check if the points are coincident
512
        if (rE0 == rE1 && rE0 == rE2) {
513
            // set a small tolerance to get a non-degenerated line
514
            float eps = 0.005F;
515
            Base::Vector3f cP1, cP2;
516
            cP1.Set(rE1.x + eps, rE1.y + eps, rE1.z + eps);
517
            cP2.Set(rE2.x - eps, rE2.y - eps, rE2.z - eps);
518
            pcCoords->point.set1Value(i++, cP1.x, cP1.y, cP1.z);
519
            pcCoords->point.set1Value(i++, cP2.x, cP2.y, cP2.z);
520
        }
521
        else if (rE0 == rE1) {
522
            pcCoords->point.set1Value(i++, rE1.x, rE1.y, rE1.z);
523
            pcCoords->point.set1Value(i++, rE2.x, rE2.y, rE2.z);
524
        }
525
        else if (rE1 == rE2) {
526
            pcCoords->point.set1Value(i++, rE2.x, rE2.y, rE2.z);
527
            pcCoords->point.set1Value(i++, rE0.x, rE0.y, rE0.z);
528
        }
529
        else if (rE2 == rE0) {
530
            pcCoords->point.set1Value(i++, rE0.x, rE0.y, rE0.z);
531
            pcCoords->point.set1Value(i++, rE1.x, rE1.y, rE1.z);
532
        }
533
        else {
534
            for (int j = 0; j < 3; j++) {
535
                Base::Vector3f cVec1 = cF->_aclPoints[(j + 1) % 3] - cF->_aclPoints[j];
536
                Base::Vector3f cVec2 = cF->_aclPoints[(j + 2) % 3] - cF->_aclPoints[j];
537

538
                // adjust the neighbourhoods and point indices
539
                if (cVec1 * cVec2 < 0.0F) {
540
                    pcCoords->point.set1Value(i++,
541
                                              cF->_aclPoints[(j + 1) % 3].x,
542
                                              cF->_aclPoints[(j + 1) % 3].y,
543
                                              cF->_aclPoints[(j + 1) % 3].z);
544
                    pcCoords->point.set1Value(i++,
545
                                              cF->_aclPoints[(j + 2) % 3].x,
546
                                              cF->_aclPoints[(j + 2) % 3].y,
547
                                              cF->_aclPoints[(j + 2) % 3].z);
548
                    break;
549
                }
550
            }
551
        }
552

553
        pcLines->numVertices.set1Value(j++, 2);
554
    }
555

556
    setDisplayMaskMode("Line");
557
}
558

559
// ----------------------------------------------------------------------
560

561
ViewProviderMeshIndices::ViewProviderMeshIndices()
562
{
563
    // NOLINTBEGIN
564
    pcFaces = new SoFaceSet;
565
    pcFaces->ref();
566
    // NOLINTEND
567
}
568

569
ViewProviderMeshIndices::~ViewProviderMeshIndices()
570
{
571
    pcFaces->unref();
572
}
573

574
void ViewProviderMeshIndices::attach(App::DocumentObject* pcFeat)
575
{
576
    ViewProviderDocumentObject::attach(pcFeat);
577

578
    SoGroup* pcFaceRoot = new SoGroup();
579

580
    SoDrawStyle* pcFlatStyle = new SoDrawStyle();
581
    pcFlatStyle->style = SoDrawStyle::FILLED;
582
    pcFaceRoot->addChild(pcFlatStyle);
583

584
    SoShapeHints* flathints = new SoShapeHints;
585
    flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
586
    flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
587
    pcFaceRoot->addChild(flathints);
588

589
    // Draw lines
590
    SoSeparator* linesep = new SoSeparator;
591
    SoBaseColor* basecol = new SoBaseColor;
592
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
593
    linesep->addChild(basecol);
594
    linesep->addChild(pcCoords);
595
    linesep->addChild(pcFaces);
596
    pcFaceRoot->addChild(linesep);
597

598
    // Draw markers
599
    SoBaseColor* markcol = new SoBaseColor;
600
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
601
    SoMarkerSet* marker = new SoMarkerSet;
602
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
603
        "PLUS",
604
        App::GetApplication()
605
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
606
            ->GetInt("MarkerSize", 7));
607
    linesep->addChild(markcol);
608
    linesep->addChild(marker);
609

610
    addDisplayMaskMode(pcFaceRoot, "Face");
611
}
612

613
void ViewProviderMeshIndices::showDefects(const std::vector<Mesh::ElementIndex>& inds)
614
{
615
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
616
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
617

618
    if (!inds.empty()) {
619
        pcCoords->point.deleteValues(0);
620
        pcCoords->point.setNum(3 * inds.size());
621
        MeshCore::MeshFacetIterator cF(rMesh);
622
        int i = 0;
623
        int j = 0;
624
        for (Mesh::ElementIndex ind : inds) {
625
            cF.Set(ind);
626
            for (auto cP : cF->_aclPoints) {
627
                // move a bit in opposite normal direction to overlay the original faces
628
                cP -= 0.001F * cF->GetNormal();
629
                pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z);
630
            }
631
            pcFaces->numVertices.set1Value(j++, 3);
632
        }
633

634
        setDisplayMaskMode("Face");
635
    }
636
}
637

638
// ----------------------------------------------------------------------
639

640
ViewProviderMeshSelfIntersections::ViewProviderMeshSelfIntersections()
641
{
642
    // NOLINTBEGIN
643
    pcLines = new SoLineSet;
644
    pcLines->ref();
645
    // NOLINTEND
646
}
647

648
ViewProviderMeshSelfIntersections::~ViewProviderMeshSelfIntersections()
649
{
650
    pcLines->unref();
651
}
652

653
void ViewProviderMeshSelfIntersections::attach(App::DocumentObject* pcFeat)
654
{
655
    ViewProviderDocumentObject::attach(pcFeat);
656

657
    SoGroup* pcLineRoot = new SoGroup();
658
    pcDrawStyle->lineWidth = 3;
659
    pcLineRoot->addChild(pcDrawStyle);
660

661
    // Draw lines
662
    SoSeparator* linesep = new SoSeparator;
663
    SoBaseColor* basecol = new SoBaseColor;
664
    basecol->rgb.setValue(1.0F, 0.5F, 0.0F);
665
    linesep->addChild(basecol);
666
    linesep->addChild(pcCoords);
667
    linesep->addChild(pcLines);
668
    pcLineRoot->addChild(linesep);
669

670
    // Draw markers
671
    SoBaseColor* markcol = new SoBaseColor;
672
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
673
    SoMarkerSet* marker = new SoMarkerSet;
674
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
675
        "PLUS",
676
        App::GetApplication()
677
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
678
            ->GetInt("MarkerSize", 7));
679
    linesep->addChild(markcol);
680
    linesep->addChild(marker);
681

682
    addDisplayMaskMode(pcLineRoot, "Line");
683
}
684

685
void ViewProviderMeshSelfIntersections::showDefects(const std::vector<Mesh::ElementIndex>& indices)
686
{
687
    if (indices.size() % 2 != 0) {
688
        return;
689
    }
690
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
691
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
692
    MeshCore::MeshEvalSelfIntersection eval(rMesh);
693

694
    std::vector<std::pair<Mesh::ElementIndex, Mesh::ElementIndex>> intersection;
695
    std::vector<Mesh::ElementIndex>::const_iterator it;
696
    for (it = indices.begin(); it != indices.end();) {
697
        Mesh::ElementIndex id1 = *it;
698
        ++it;
699
        Mesh::ElementIndex id2 = *it;
700
        ++it;
701
        intersection.emplace_back(id1, id2);
702
    }
703

704
    std::vector<std::pair<Base::Vector3f, Base::Vector3f>> lines;
705
    eval.GetIntersections(intersection, lines);
706

707
    pcCoords->point.deleteValues(0);
708
    pcCoords->point.setNum(2 * lines.size());
709
    int i = 0;
710
    int j = 0;
711
    for (const auto& line : lines) {
712
        pcCoords->point.set1Value(i++, line.first.x, line.first.y, line.first.z);
713
        pcCoords->point.set1Value(i++, line.second.x, line.second.y, line.second.z);
714
        pcLines->numVertices.set1Value(j++, 2);
715
    }
716

717
    setDisplayMaskMode("Line");
718
}
719

720
// ----------------------------------------------------------------------
721

722
ViewProviderMeshFolds::ViewProviderMeshFolds()
723
{
724
    // NOLINTBEGIN
725
    pcFaces = new SoFaceSet;
726
    pcFaces->ref();
727
    // NOLINTEND
728
}
729

730
ViewProviderMeshFolds::~ViewProviderMeshFolds()
731
{
732
    pcFaces->unref();
733
}
734

735
void ViewProviderMeshFolds::attach(App::DocumentObject* pcFeat)
736
{
737
    ViewProviderDocumentObject::attach(pcFeat);
738

739
    SoGroup* pcFaceRoot = new SoGroup();
740

741
    SoDrawStyle* pcFlatStyle = new SoDrawStyle();
742
    pcFlatStyle->style = SoDrawStyle::FILLED;
743
    pcFaceRoot->addChild(pcFlatStyle);
744

745
    SoShapeHints* flathints = new SoShapeHints;
746
    flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
747
    flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
748
    pcFaceRoot->addChild(flathints);
749

750
    // Draw lines
751
    SoSeparator* linesep = new SoSeparator;
752
    SoBaseColor* basecol = new SoBaseColor;
753
    basecol->rgb.setValue(1.0F, 0.0F, 0.0F);
754
    linesep->addChild(basecol);
755
    linesep->addChild(pcCoords);
756
    linesep->addChild(pcFaces);
757
    pcFaceRoot->addChild(linesep);
758

759
    // Draw markers
760
    SoBaseColor* markcol = new SoBaseColor;
761
    markcol->rgb.setValue(1.0F, 1.0F, 0.0F);
762
    SoMarkerSet* marker = new SoMarkerSet;
763
    marker->markerIndex = Gui::Inventor::MarkerBitmaps::getMarkerIndex(
764
        "PLUS",
765
        App::GetApplication()
766
            .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
767
            ->GetInt("MarkerSize", 7));
768
    linesep->addChild(markcol);
769
    linesep->addChild(marker);
770

771
    addDisplayMaskMode(pcFaceRoot, "Face");
772
}
773

774
void ViewProviderMeshFolds::showDefects(const std::vector<Mesh::ElementIndex>& inds)
775
{
776
    Mesh::Feature* f = static_cast<Mesh::Feature*>(pcObject);
777
    const MeshCore::MeshKernel& rMesh = f->Mesh.getValue().getKernel();
778

779
    pcCoords->point.deleteValues(0);
780
    pcCoords->point.setNum(3 * inds.size());
781
    MeshCore::MeshFacetIterator cF(rMesh);
782
    int i = 0;
783
    int j = 0;
784
    for (Mesh::ElementIndex ind : inds) {
785
        cF.Set(ind);
786
        for (auto cP : cF->_aclPoints) {
787
            // move a bit in normal direction to overlay the original faces
788
            cP += 0.001F * cF->GetNormal();
789
            pcCoords->point.set1Value(i++, cP.x, cP.y, cP.z);
790
        }
791
        pcFaces->numVertices.set1Value(j++, 3);
792
    }
793

794
    setDisplayMaskMode("Face");
795
}
796

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.