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

Function writeRIB

extern/partio/src/lib/io/RIB.cpp:39–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37using namespace std;
38
39bool writeRIB(const char* filename, const ParticlesData& p, const bool compressed,std::ostream* errorStream)
40{
41 unique_ptr<ostream> output(
42 compressed ? Gzip_Out(filename, ios::out | ios::binary)
43 : new ofstream(filename, ios::out | ios::binary));
44
45 ParticleAttribute dummy;
46 bool foundP = p.attributeInfo("position", dummy) || p.attributeInfo("P", dummy);
47 bool foundP2 = p.attributeInfo("position2", dummy) || p.attributeInfo("P2", dummy);
48 bool foundWidth = p.attributeInfo("radius", dummy) || p.attributeInfo("width", dummy) || p.attributeInfo("radiusPP", dummy);
49
50 if (!foundP)
51 {
52 if(errorStream) *errorStream << "Partio: failed to find attr 'position' or 'P' for RIB output" << endl;
53 return false;
54 }
55
56 if (!foundWidth)
57 if(errorStream) *errorStream << "Partio: failed to find attr 'width','radius', or 'radiusPP' for RIB output, using constantwidth = 1" << endl;
58
59 *output << "version 3.04" << endl;
60
61 if (foundP2)
62 *output << "GeometricApproximation \"motionfactor\" 1.0" << endl;
63
64 *output << "AttributeBegin" << endl;
65 *output << " ResourceBegin" << endl;
66 *output << " Attribute \"identifier\" \"name\" [\"|partioParticle1|partioParticleShape1\"]" << endl;
67
68 int numPasses = foundP2 ? 2 : 1;
69
70 if (foundP2)
71 *output << " MotionBegin [0.0 1.0]" << endl;
72
73 for (int passIndex = 0; passIndex < numPasses; ++passIndex)
74 {
75 *output << (foundP2 ? " " : "") << " Points ";
76
77 for (int attrIndex = 0; attrIndex < p.numAttributes(); ++attrIndex)
78 {
79 ParticleAttribute attr;
80 p.attributeInfo(attrIndex, attr);
81
82 if ((passIndex == 0 && (attr.name == "P2" || attr.name == "position2")) ||
83 (passIndex == 1 && (attr.name == "P" || attr.name == "position"))) continue;
84
85 string attrname = (attr.name == "position" || attr.name == "position2" || attr.name == "P" || attr.name == "P2")
86 ? "P"
87 : (attr.name == "radius" ? "width" : attr.name);
88
89 *output << "\"" << attrname << "\" [ ";
90 int spaceCount = 0;
91 switch (attr.type)
92 {
93 case Partio::FLOAT:
94 case Partio::VECTOR:
95 {
96 for (int particleIndex = 0; particleIndex < p.numParticles(); ++particleIndex)

Callers

nothing calls this directly

Calls 2

Gzip_OutFunction · 0.85
numParticlesMethod · 0.80

Tested by

no test coverage detected