UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DynamicGraph3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6
7#include "BoxTypes.h"
8#include "DynamicGraph.h"
9#include "SegmentTypes.h"
10#include "Util/DynamicVector.h"
11#include "Util/IndexUtil.h"
12#include "Util/IteratorUtil.h"
13#include "Util/RefCountVector.h"
14#include "Util/SmallListSet.h"
15#include "VectorTypes.h"
16#include "VectorUtil.h"
17
18namespace UE
19{
20namespace Geometry
21{
22
23using namespace UE::Math;
24
25template <typename T>
27{
28 TDynamicVectorN<T, 3> Vertices;
29
30public:
32 {
33 return TVector<T>(TNumericLimits<T>::Max(), 0, 0);
34 }
35
36 TVector<T> GetVertex(int VID) const
37 {
38 return vertices_refcount.IsValid(VID) ? Vertices.AsVector3(VID) : InvalidVertex();
39 }
40
42 {
43 check(VectorUtil::IsFinite(VNewPos)); // this will really catch a lot of bugs...
45 {
46 Vertices.SetVector3(VID, VNewPos);
47 updateTimeStamp(true);
48 }
49 }
50
52 bool GetEdgeV(int EID, TVector<T>& A, TVector<T>& B) const
53 {
55 {
56 A = Vertices.AsVector3(edges[EID].A);
57 B = Vertices.AsVector3(edges[EID].B);
58 return true;
59 }
60 return false;
61 }
62
64 {
65 checkfSlow(edges_refcount.IsValid(EID), TEXT("FDynamicGraph2.GetEdgeSegment: invalid segment with id %d"), EID);
66 const FEdge& e = edges[EID];
67 return TSegment3<T>(
68 Vertices.AsVector3(e.A),
69 Vertices.AsVector3(e.B));
70 }
71
73 {
74 checkfSlow(edges_refcount.IsValid(EID), TEXT("FDynamicGraph3.GetEdgeCenter: invalid segment with id %d"), EID);
75 const FEdge& e = edges[EID];
76 return 0.5 * (Vertices.AsVector3(e.A) + Vertices.AsVector3(e.B));
77 }
78
80 {
81 int vid = append_vertex_internal();
82 Vertices.InsertAt({{V.X, V.Y, V.Z}}, vid);
83 return vid;
84 }
85
90 {
91 // For now we desided not to add the "bUnsafe" optimization machinery like the similar method in
92 // FDynamicMesh3. It is not needed if InsertVertex is used just for creating a graph with non compact
93 // Vids, where we would presumably still iterate through the source indices in increasing order, and
94 // so never have to worry about the performance cost of removing from the free list.
95
97 {
98 return false;
99 }
100 Vertices.InsertAt({ {V.X, V.Y, V.Z} }, Vid);
101
102 return true;
103 }
104
109
112 {
114 [&, this](int vid) {
115 return Vertices.template AsVector3<T>(vid);
116 });
117 }
118
119
120 // compute vertex bounding box
122 {
124 for (const TVector<T>& V : Vertices())
125 {
126 AABB.Contain(V);
127 }
128 return AABB;
129 }
130
131
132protected:
133 // internal used in SplitEdge
134 virtual int append_new_split_vertex(int A, int B) override
135 {
136 TVector<T> vNew = 0.5 * (GetVertex(A) + GetVertex(B));
137 int f = AppendVertex(vNew);
138 return f;
139 }
140
141 virtual void subclass_validity_checks(TFunction<void(bool)> CheckOrFailF) const override
142 {
143 for (int VID : VertexIndices())
144 {
145 TVector<T> V = GetVertex(VID);
147 }
148 }
149};
150
152
153
154} // end namespace UE::Geometry
155} // end namespace UE
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define check(expr)
Definition AssertionMacros.h:314
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition AndroidPlatformMisc.h:14
Definition DynamicGraph3.h:27
FRefCountVector::IndexEnumerable VertexIndicesItr() const
Definition DynamicGraph3.h:105
virtual int append_new_split_vertex(int A, int B) override
Definition DynamicGraph3.h:134
value_iteration< TVector< T > > VerticesItr() const
Definition DynamicGraph3.h:111
virtual void subclass_validity_checks(TFunction< void(bool)> CheckOrFailF) const override
Definition DynamicGraph3.h:141
int AppendVertex(TVector< T > V)
Definition DynamicGraph3.h:79
void SetVertex(int VID, TVector< T > VNewPos)
Definition DynamicGraph3.h:41
static TVector< T > InvalidVertex()
Definition DynamicGraph3.h:31
FAxisAlignedBox2d GetBounds() const
Definition DynamicGraph3.h:121
bool InsertVertex(int32 Vid, TVector< T > V)
Definition DynamicGraph3.h:89
TVector< T > GetEdgeCenter(int EID) const
Definition DynamicGraph3.h:72
bool GetEdgeV(int EID, TVector< T > &A, TVector< T > &B) const
Definition DynamicGraph3.h:52
TVector< T > GetVertex(int VID) const
Definition DynamicGraph3.h:36
TSegment3< T > GetEdgeSegment(int EID) const
Definition DynamicGraph3.h:63
Definition DynamicGraph.h:25
bool insert_vertex_internal(int32 Vid)
Definition DynamicGraph.h:192
void updateTimeStamp(bool bShapeChange)
Definition DynamicGraph.h:68
FRefCountVector edges_refcount
Definition DynamicGraph.h:49
FIndex2i GetEdgeV(int EID) const
Definition DynamicGraph.h:152
int append_vertex_internal()
Definition DynamicGraph.h:184
TDynamicVector< FEdge > edges
Definition DynamicGraph.h:50
vertex_iterator VertexIndices() const
Definition DynamicGraph.h:275
FRefCountVector vertices_refcount
Definition DynamicGraph.h:45
Definition RefCountVector.h:445
MappedEnumerable< ToType > MappedIndices(TFunction< ToType(int)> MapFunc) const
Definition RefCountVector.h:497
bool IsValid(int Index) const
Definition RefCountVector.h:66
IndexEnumerable Indices() const
Definition RefCountVector.h:458
Definition DynamicVector.h:427
TVector< Type > AsVector3(unsigned int TopIndex) const
Definition DynamicVector.h:529
void SetVector3(unsigned int TopIndex, const TVector< Type > &V)
Definition DynamicVector.h:514
void InsertAt(const ElementVectorN &AddData, unsigned int Index)
Definition DynamicVector.h:491
bool IsFinite(const TVector2< RealType > &V)
Definition VectorUtil.h:42
FDynamicGraph3< double > FDynamicGraph3d
Definition DynamicGraph3.h:151
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition NumericLimits.h:41
Definition DynamicGraph.h:31
int A
Definition DynamicGraph.h:32
int B
Definition DynamicGraph.h:32
Definition BoxTypes.h:637
void Contain(const TVector2< RealType > &V)
Definition BoxTypes.h:738
Definition SegmentTypes.h:447
Definition Vector.h:51
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62