Material Clustering Benchmark
DispatcherKM.cs
Go to the documentation of this file.
1
using
UnityEngine;
2
3
namespace
ClusteringAlgorithms
4
{
5
public
class
DispatcherKM
:
ASimpleDispatcer
6
{
7
public
DispatcherKM
(
8
ComputeShader
computeShader
,
9
int
numIterations
,
10
bool
doRandomizeEmptyClusters
,
11
bool
useFullResTexRef
,
12
ClusteringRTsAndBuffers
clusteringRTsAndBuffers
13
)
14
: base(
15
computeShader
:
computeShader
,
16
numIterations
:
numIterations
,
17
doRandomizeEmptyClusters
:
doRandomizeEmptyClusters
,
18
useFullResTexRef
:
useFullResTexRef
,
19
clusteringRTsAndBuffers
:
clusteringRTsAndBuffers
20
) { }
21
22
public
override
string
name
=>
"KM"
;
23
24
public
override
bool
doesReadback
=>
false
;
25
26
/// <summary>
27
/// Each iteration first attributes pixels to clusters,
28
/// then updates cluster centers.
29
/// In order to use the resulting cluster centers,
30
/// one final cluster attribution is required!
31
/// </summary>
32
public
override
void
RunClustering
(
ClusteringTextures
clusteringTextures)
33
{
34
for
(
int
i = 0; i < this.
numIterations
; i++)
35
{
36
this.
KMiteration
(clusteringTextures, rejectOld:
false
);
37
}
38
}
39
40
/// <summary>
41
/// First attributes pixels to clusters.
42
/// Then updates cluster centers.
43
/// In order to use the resulting cluster centers,
44
/// one final cluster attribution is required!
45
/// </summary>
46
protected
void
KMiteration
(
ClusteringTextures
textures,
bool
rejectOld)
47
{
48
this.
AttributeClustersKM
(textures);
49
this.
UpdateClusterCenters
(textures, rejectOld);
50
}
51
52
public
override
void
SingleIteration
(
ClusteringTextures
textures)
53
{
54
this.
computeShader
.SetBool(
55
"do_random_sample_empty_clusters"
,
56
this.
doRandomizeEmptyClusters
57
);
58
this.
computeShader
.SetInt(
"num_clusters"
, this.
clusteringRTsAndBuffers
.
numClusters
);
59
60
this.
KMiteration
(textures, rejectOld:
false
);
61
}
62
}
63
}
ClusteringAlgorithms.ADispatcher.numIterations
int numIterations
Definition:
ADispatcher.cs:10
ClusteringAlgorithms.ADispatcher.useFullResTexRef
bool useFullResTexRef
Definition:
ADispatcher.cs:150
ClusteringAlgorithms.ADispatcher.clusteringRTsAndBuffers
ClusteringRTsAndBuffers clusteringRTsAndBuffers
Definition:
ADispatcher.cs:11
ClusteringAlgorithms.ADispatcher.AttributeClustersKM
void AttributeClustersKM(ClusteringTextures clusteringTextures)
Definition:
ADispatcher.cs:87
ClusteringAlgorithms.ADispatcher.doRandomizeEmptyClusters
bool doRandomizeEmptyClusters
Definition:
ADispatcher.cs:9
ClusteringAlgorithms.ADispatcher.UpdateClusterCenters
void UpdateClusterCenters(ClusteringTextures clusteringTextures, bool rejectOld)
Definition:
ADispatcher.cs:55
ClusteringAlgorithms.ADispatcher.computeShader
readonly ComputeShader computeShader
Definition:
ADispatcher.cs:28
ClusteringAlgorithms.ASimpleDispatcer
Definition:
ASimpleDispatcher.cs:6
ClusteringAlgorithms.ClusteringRTsAndBuffers
Call Allocate before using and Dispose after using.
Definition:
ClusteringRTsAndBuffers.cs:11
ClusteringAlgorithms.ClusteringRTsAndBuffers.numClusters
readonly int numClusters
Definition:
ClusteringRTsAndBuffers.cs:20
ClusteringAlgorithms.DispatcherKM
Definition:
DispatcherKM.cs:6
ClusteringAlgorithms.DispatcherKM.doesReadback
override bool doesReadback
Definition:
DispatcherKM.cs:24
ClusteringAlgorithms.DispatcherKM.name
override string name
Definition:
DispatcherKM.cs:22
ClusteringAlgorithms.DispatcherKM.SingleIteration
override void SingleIteration(ClusteringTextures textures)
Definition:
DispatcherKM.cs:52
ClusteringAlgorithms.DispatcherKM.RunClustering
override void RunClustering(ClusteringTextures clusteringTextures)
Each iteration first attributes pixels to clusters, then updates cluster centers. In order to use the...
Definition:
DispatcherKM.cs:32
ClusteringAlgorithms.DispatcherKM.KMiteration
void KMiteration(ClusteringTextures textures, bool rejectOld)
First attributes pixels to clusters. Then updates cluster centers. In order to use the resulting clus...
Definition:
DispatcherKM.cs:46
ClusteringAlgorithms.DispatcherKM.DispatcherKM
DispatcherKM(ComputeShader computeShader, int numIterations, bool doRandomizeEmptyClusters, bool useFullResTexRef, ClusteringRTsAndBuffers clusteringRTsAndBuffers)
Definition:
DispatcherKM.cs:7
ClusteringTextures
Call Dispose after using.
Definition:
ClusteringTextures.cs:7
ClusteringAlgorithms
Definition:
ADispatcher.cs:5
Assets
Code
ClusteringTest
ClusteringAlgorithms
Concrete
Simple
Concrete
DispatcherKM.cs
Generated by
1.9.4