MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / clone

Function clone

extern/partio/src/lib/core/Particle.cpp:95–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95ParticlesDataMutable*
96clone(const ParticlesData& other, bool particles)
97{
98 ParticlesDataMutable* p = create();
99 // Fixed attributes
100 FixedAttribute srcFixedAttr, dstFixedAttr;
101 for (int i(0), iend(other.numFixedAttributes()); i < iend; ++i) {
102 other.fixedAttributeInfo(i, srcFixedAttr);
103
104 dstFixedAttr = p->addFixedAttribute(
105 srcFixedAttr.name.c_str(), srcFixedAttr.type, srcFixedAttr.count);
106 assert(srcFixedAttr.type == dstFixedAttr.type);
107 assert(srcFixedAttr.count == dstFixedAttr.count);
108 // Register indexed strings
109 if (srcFixedAttr.type == Partio::INDEXEDSTR) {
110 const std::vector<std::string>& values = other.fixedIndexedStrs(srcFixedAttr);
111 for (int j = 0, jend = values.size(); j < jend; ++j) {
112 p->registerFixedIndexedStr(dstFixedAttr, values[j].c_str());
113 }
114 }
115 // Copy fixed data
116 const void* src = other.fixedData<void>(srcFixedAttr);
117 void* dst = p->fixedDataWrite<void>(dstFixedAttr);
118 size_t size = Partio::TypeSize(dstFixedAttr.type) * dstFixedAttr.count;
119 std::memcpy(dst, src, size);
120 }
121 if (!particles) {
122 return p;
123 }
124 // Particle data
125 Partio::ParticleAttribute srcAttr, dstAttr;
126 const int numAttributes = other.numAttributes();
127 const size_t numParticles = other.numParticles();
128 std::vector<Partio::ParticleAttribute> dstAttrs;
129
130 p->addParticles(numParticles);
131
132 // We can't assume that the particle backend stores data contiguously, so
133 // we copy one particle at a time. A bulk memcpy would be faster.
134 for (int i = 0; i < numAttributes; ++i) {
135 other.attributeInfo(i, srcAttr);
136 // Register indexed strings
137 if (srcAttr.type == Partio::INDEXEDSTR) {
138 const std::vector<std::string>& values = other.indexedStrs(srcAttr);
139 for (int m = 0, mend = values.size(); m < mend; ++m) {
140 p->registerIndexedStr(dstAttr, values[m].c_str());
141 }
142 }
143 size_t size = Partio::TypeSize(srcAttr.type) * srcAttr.count;
144 dstAttr = p->addAttribute(srcAttr.name.c_str(), srcAttr.type, srcAttr.count);
145
146 for (Partio::ParticleIndex j = 0; j < numParticles; ++j) {
147 const void *src = other.data<void>(srcAttr, j);
148 void *dst = p->dataWrite<void>(dstAttr, j);
149 std::memcpy(dst, src, size);
150 }
151 }
152

Callers 1

standard_valueClass · 0.85

Calls 7

TypeSizeFunction · 0.85
numParticlesMethod · 0.80
createFunction · 0.70
c_strMethod · 0.45
sizeMethod · 0.45
registerIndexedStrMethod · 0.45
addAttributeMethod · 0.45

Tested by

no test coverage detected