PeriDyno 0.8.2
ParticleWriterABC.cpp
Go to the documentation of this file.
1#include "ParticleWriterABC.h"
2
3#include <Alembic/AbcGeom/All.h>
4#include <Alembic/AbcCoreOgawa/All.h>
5#include <Alembic/AbcCoreAbstract/Tests/Assert.h>
6
7#include <sstream>
8#include <iostream>
9#include <fstream>
10#include <string>
11
12#include <ImathRandom.h>
13
14namespace dyno
15{
16 IMPLEMENT_TCLASS(ParticleWriterABC, TDataType)
17
18 template<typename TDataType>
20 : OutputModule()
21 {
22 }
23
24 template<typename TDataType>
26 {
27 }
28
29 template<typename TDataType>
31 {
32 if (time_idx % 8 != 0)
33 {
34 time_idx++;
35 return;
36 }
37 time_idx++;
38
39 auto& inPos = this->inPointSet()->getDataPtr()->getPoints();
40 auto& inColor = this->inColor()->getData();
41
42 assert(inPos.size() == inColor.size());
43
44 std::stringstream ss; ss << m_output_index;
45 std::string filename = this->varOutputPath()->getData() + std::string("fluid_pos_") + ss.str() + std::string(".abc");
46
47 Alembic::AbcGeom::OArchive archive(Alembic::AbcCoreOgawa::WriteArchive(),
48 filename);
49 Alembic::AbcGeom::OObject topObj(archive, Alembic::AbcGeom::kTop);
50 Alembic::AbcGeom::OPoints ptsObj(topObj, "somePoints");
51
52 int total_num = inPos.size();
53 CArray<Coord> host_position;
54 CArray<Real> host_mapping;
55 host_position.resize(total_num);
56 host_mapping.resize(total_num);
57
58 host_position.assign(inPos);
59 host_mapping.assign(inColor);
60
61
62
63 std::vector< Alembic::AbcGeom::V3f > positions;
64 std::vector< Alembic::AbcGeom::V3f > velocities;
65 std::vector< Alembic::Util::uint64_t > ids;
66 std::vector< Alembic::Util::float32_t > widths;
67
68 for (int i = 0; i < total_num; i++)
69 {
70 positions.push_back(Alembic::AbcGeom::V3f(host_position[i][0], host_position[i][1], host_position[i][2]));
71 velocities.push_back(Alembic::AbcGeom::V3f(0, 0, 0));
72 ids.push_back(i);
73 widths.push_back(host_mapping[i]);
74 //if(i % 100000 == 0)
75 //printf("pressure: %.3lf\n", host_mapping[i]);
76 }
77 Alembic::AbcGeom::OFloatGeomParam::Sample widthSamp;
78 widthSamp.setScope(Alembic::AbcGeom::kVertexScope);
79 widthSamp.setVals(Alembic::AbcGeom::FloatArraySample(widths));
80
81 Alembic::AbcGeom::OPointsSchema::Sample psamp(Alembic::AbcGeom::V3fArraySample(positions),
82 Alembic::AbcGeom::UInt64ArraySample(ids), Alembic::AbcGeom::V3fArraySample(velocities),
83 widthSamp);
84
85 ptsObj.getSchema().set(psamp);
86
87 host_position.clear();
88 host_mapping.clear();
89
90 m_output_index++;
91 }
92
93
95}
assert(queueCount >=1)
void assign(const T &val)
Definition: Array.h:128
This is an implementation of AdditiveCCD based on peridyno.
Definition: Array.h:24
IMPLEMENT_TCLASS(FloatingNumber, TDataType)
DEFINE_CLASS(CircularEmitter)