RuntimeMeshInternalUtilities.h
Go to the documentation of this file.
1 // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved.
2 
3 #pragma once
4 
5 #include "CoreMinimal.h"
6 
8 {
9  float Value;
10  int32 Index;
11 
13 
14  FRuntimeMeshVertexSortingElement(int32 InIndex, FVector Vector)
15  {
16  Value = 0.30f * Vector.X + 0.33f * Vector.Y + 0.37f * Vector.Z;
17  Index = InIndex;
18  }
19 };
20 
22 {
23  FORCEINLINE bool operator()(FRuntimeMeshVertexSortingElement const& Left, FRuntimeMeshVertexSortingElement const& Right) const
24  {
25  return Left.Value < Right.Value;
26  }
27 };
28 
29 
30 
31 
33 {
34  static TMultiMap<uint32, uint32> FindDuplicateVerticesMap(TFunction<FVector(int32)> VertexAccessor, int32 NumVertices, float Tollerance = 0.0)
35  {
36  TArray<FRuntimeMeshVertexSortingElement> VertexSorter;
37  VertexSorter.Empty(NumVertices);
38  for (int32 Index = 0; Index < NumVertices; Index++)
39  {
40  new (VertexSorter)FRuntimeMeshVertexSortingElement(Index, VertexAccessor(Index));
41  }
42 
43  // Sort the list
44  VertexSorter.Sort(FRuntimeMeshVertexSortingFunction());
45 
46  // Clear the index map.
47  TMultiMap<uint32, uint32> IndexMap;
48 
49  // Map out the duplicates.
50  for (int32 Index = 0; Index < NumVertices; Index++)
51  {
52  uint32 SrcVertIdx = VertexSorter[Index].Index;
53  float Value = VertexSorter[Index].Value;
54 
55  // Search forward adding pairs both ways
56  for (int32 SubIndex = Index + 1; SubIndex < NumVertices; SubIndex++)
57  {
58  if (FMath::Abs(VertexSorter[SubIndex].Value - Value) > THRESH_POINTS_ARE_SAME * 4.01f)
59  {
60  // No more possible duplicates
61  break;
62  }
63 
64  uint32 OtherVertIdx = VertexSorter[SubIndex].Index;
65  if (VertexAccessor(SrcVertIdx).Equals(VertexAccessor(OtherVertIdx), Tollerance))
66  {
67  IndexMap.AddUnique(SrcVertIdx, OtherVertIdx);
68  IndexMap.AddUnique(OtherVertIdx, SrcVertIdx);
69  }
70  }
71  }
72 
73  return IndexMap;
74  }
75 
76  static TMultiMap<uint32, uint32> FindDuplicateVerticesMap(const TArray<FVector>& Vertices, float Tollerance = 0.0)
77  {
78  int32 NumVertices = Vertices.Num();
79 
80  TArray<FRuntimeMeshVertexSortingElement> VertexSorter;
81  VertexSorter.Empty(NumVertices);
82  for (int32 Index = 0; Index < NumVertices; Index++)
83  {
84  new (VertexSorter)FRuntimeMeshVertexSortingElement(Index, Vertices[Index]);
85  }
86 
87  // Sort the list
88  VertexSorter.Sort(FRuntimeMeshVertexSortingFunction());
89 
90  // Clear the index map.
91  TMultiMap<uint32, uint32> IndexMap;
92 
93  // Map out the duplicates.
94  for (int32 Index = 0; Index < NumVertices; Index++)
95  {
96  uint32 SrcVertIdx = VertexSorter[Index].Index;
97  float Value = VertexSorter[Index].Value;
98 
99  // Search forward adding pairs both ways
100  for (int32 SubIndex = Index + 1; SubIndex < NumVertices; SubIndex++)
101  {
102  if (FMath::Abs(VertexSorter[SubIndex].Value - Value) > THRESH_POINTS_ARE_SAME * 4.01f)
103  {
104  // No more possible duplicates
105  break;
106  }
107 
108  uint32 OtherVertIdx = VertexSorter[SubIndex].Index;
109  if (Vertices[SrcVertIdx].Equals(Vertices[OtherVertIdx], Tollerance))
110  {
111  IndexMap.AddUnique(SrcVertIdx, OtherVertIdx);
112  IndexMap.AddUnique(OtherVertIdx, SrcVertIdx);
113  }
114  }
115  }
116 
117  return IndexMap;
118  }
119 
120  static TArray<uint32> FindDuplicateVertices(const TArray<FVector>& Vertices, float Tollerance = 0.0)
121  {
122  int32 NumVertices = Vertices.Num();
123 
124  TArray<FRuntimeMeshVertexSortingElement> VertexSorter;
125  VertexSorter.Empty(NumVertices);
126  for (int32 Index = 0; Index < NumVertices; Index++)
127  {
128  new (VertexSorter)FRuntimeMeshVertexSortingElement(Index, Vertices[Index]);
129  }
130 
131  // Sort the list
132  VertexSorter.Sort(FRuntimeMeshVertexSortingFunction());
133 
134  // Clear the index map.
135  TArray<uint32> IndexMap;
136  IndexMap.AddUninitialized(NumVertices);
137  FMemory::Memset(IndexMap.GetData(), 0xFF, NumVertices * sizeof(uint32));
138 
139  // Map out the duplicates.
140  for (int32 Index = 0; Index < NumVertices; Index++)
141  {
142  uint32 SrcVertIdx = VertexSorter[Index].Index;
143  float Value = VertexSorter[Index].Value;
144  IndexMap[SrcVertIdx] = FMath::Min(IndexMap[SrcVertIdx], SrcVertIdx);
145 
146  // Search forward adding pairs both ways
147  for (int32 SubIndex = Index + 1; SubIndex < NumVertices; SubIndex++)
148  {
149  if (FMath::Abs(VertexSorter[SubIndex].Value - Value) > THRESH_POINTS_ARE_SAME * 4.01f)
150  {
151  // No more possible duplicates
152  break;
153  }
154 
155  uint32 OtherVertIdx = VertexSorter[SubIndex].Index;
156  if (Vertices[SrcVertIdx].Equals(Vertices[OtherVertIdx], Tollerance))
157  {
158  IndexMap[SrcVertIdx] = FMath::Min(IndexMap[SrcVertIdx], OtherVertIdx);
159  IndexMap[OtherVertIdx] = FMath::Min(IndexMap[OtherVertIdx], SrcVertIdx);
160  }
161  }
162  }
163 
164  return IndexMap;
165  }
166 };
static TArray< uint32 > FindDuplicateVertices(const TArray< FVector > &Vertices, float Tollerance=0.0)
FORCEINLINE bool operator()(FRuntimeMeshVertexSortingElement const &Left, FRuntimeMeshVertexSortingElement const &Right) const
StdString::EqualsMatcher Equals(std::string const &str, CaseSensitive::Choice caseSensitivity=CaseSensitive::Yes)
static TMultiMap< uint32, uint32 > FindDuplicateVerticesMap(TFunction< FVector(int32)> VertexAccessor, int32 NumVertices, float Tollerance=0.0)
GLdouble f
static TMultiMap< uint32, uint32 > FindDuplicateVerticesMap(const TArray< FVector > &Vertices, float Tollerance=0.0)
FRuntimeMeshVertexSortingElement(int32 InIndex, FVector Vector)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41